Explorar o código

fix:submit code

jimmyyem hai 3 meses
pai
achega
701b830f84
Modificáronse 56 ficheiros con 6006 adicións e 28 borrados
  1. 2 1
      desc/all.api
  2. 80 0
      desc/wechat/alloc_agent.api
  3. 55 0
      desc/wechat/chat_records.api
  4. 31 0
      desc/wechat/user.api
  5. 177 0
      ent/allocagent.go
  6. 117 0
      ent/allocagent/allocagent.go
  7. 405 0
      ent/allocagent/where.go
  8. 965 0
      ent/allocagent_create.go
  9. 88 0
      ent/allocagent_delete.go
  10. 526 0
      ent/allocagent_query.go
  11. 539 0
      ent/allocagent_update.go
  12. 157 14
      ent/client.go
  13. 2 0
      ent/ent.go
  14. 12 0
      ent/hook/hook.go
  15. 30 0
      ent/intercept/intercept.go
  16. 33 0
      ent/migrate/schema.go
  17. 824 0
      ent/mutation.go
  18. 82 0
      ent/pagination.go
  19. 3 0
      ent/predicate/predicate.go
  20. 34 0
      ent/runtime/runtime.go
  21. 50 0
      ent/schema/alloc_agent.go
  22. 144 0
      ent/set_not_nil.go
  23. 3 0
      ent/tx.go
  24. 8 0
      hook/dify/chat.go
  25. 93 0
      hook/dify/dify.go
  26. 44 0
      internal/handler/User/do_gpts_user_login_handler.go
  27. 33 0
      internal/handler/User/get_gpts_user_info_handler.go
  28. 46 0
      internal/handler/User/update_gpts_user_pwd_handler.go
  29. 44 0
      internal/handler/allocagent/create_alloc_agent_handler.go
  30. 44 0
      internal/handler/allocagent/delete_alloc_agent_handler.go
  31. 44 0
      internal/handler/allocagent/get_alloc_agent_by_id_handler.go
  32. 44 0
      internal/handler/allocagent/get_alloc_agent_list_handler.go
  33. 44 0
      internal/handler/allocagent/update_alloc_agent_handler.go
  34. 45 0
      internal/handler/chatrecords/gpts_get_api_message_handler.go
  35. 45 0
      internal/handler/chatrecords/gpts_get_api_session_handler.go
  36. 44 0
      internal/handler/chatrecords/gpts_submit_api_chat_handler.go
  37. 3 2
      internal/handler/employee/get_employee_search_handler.go
  38. 70 0
      internal/handler/routes.go
  39. 96 0
      internal/logic/User/do_gpts_user_login_logic.go
  40. 50 0
      internal/logic/User/get_gpts_user_info_logic.go
  41. 63 0
      internal/logic/User/update_gpts_user_pwd_logic.go
  42. 51 0
      internal/logic/allocagent/create_alloc_agent_logic.go
  43. 37 0
      internal/logic/allocagent/delete_alloc_agent_logic.go
  44. 52 0
      internal/logic/allocagent/get_alloc_agent_by_id_logic.go
  45. 58 0
      internal/logic/allocagent/get_alloc_agent_list_logic.go
  46. 40 0
      internal/logic/allocagent/update_alloc_agent_logic.go
  47. 62 0
      internal/logic/base/init_api_data.go
  48. 63 0
      internal/logic/chatrecords/gpts_get_api_message_logic.go
  49. 61 0
      internal/logic/chatrecords/gpts_get_api_session_logic.go
  50. 154 0
      internal/logic/chatrecords/gpts_submit_api_chat_logic.go
  51. 2 0
      internal/logic/chatrecords/submit_api_chat_logic.go
  52. 46 11
      internal/logic/employee/get_employee_search_logic.go
  53. 1 0
      internal/middleware/authority_middleware.go
  54. 119 0
      internal/types/types.go
  55. 29 0
      internal/utils/encrypt.go
  56. 12 0
      internal/utils/status.go

+ 2 - 1
desc/all.api

@@ -32,4 +32,5 @@ import "./wechat/avatar.api"
 import "./wechat/aliyun_avatar.api"
 import "./wechat/workphone.api"
 import "./wechat/usage_detail.api"
-import "./wechat/usage_total.api"
+import "./wechat/usage_total.api"
+import "./wechat/alloc_agent.api"

+ 80 - 0
desc/wechat/alloc_agent.api

@@ -0,0 +1,80 @@
+import "../base.api"
+
+type (
+    // The data of alloc agent information | AllocAgent信息
+    AllocAgentInfo {
+        BaseIDInfo
+
+        // user_id | 前台用户ID 
+        UserId  *string `json:"userId,optional"`
+
+        // organization_id | 租户ID 
+        OrganizationId  *uint64 `json:"organizationId,optional"`
+
+        // agents | 分配的智能体IDs 
+        Agents  []uint64 `json:"agents,optional"`
+
+        // status | 状态 1-正常 2-禁用 
+        Status  *int `json:"status,optional"`
+    }
+
+    // The response data of alloc agent list | AllocAgent列表数据
+    AllocAgentListResp {
+        BaseDataInfo
+
+        // AllocAgent list data | AllocAgent列表数据
+        Data AllocAgentListInfo `json:"data"`
+    }
+
+    // AllocAgent list data | AllocAgent列表数据
+    AllocAgentListInfo {
+        BaseListInfo
+
+        // The API list data | AllocAgent列表数据
+        Data  []AllocAgentInfo  `json:"data"`
+    }
+
+    // Get alloc agent list request params | AllocAgent列表请求参数
+    AllocAgentListReq {
+        PageInfo
+
+        // agents | 分配的智能体IDs 
+        Agents  *string `json:"agents,optional"`
+    }
+
+    // AllocAgent information response | AllocAgent信息返回体
+    AllocAgentInfoResp {
+        BaseDataInfo
+
+        // AllocAgent information | AllocAgent数据
+        Data AllocAgentInfo `json:"data"`
+    }
+)
+
+@server(
+    jwt: Auth
+    group: allocagent
+    middleware: Authority
+)
+
+service Wechat {
+    // Create alloc agent information | 创建AllocAgent
+    @handler createAllocAgent
+    post /alloc_agent/create (AllocAgentInfo) returns (BaseMsgResp)
+
+    // Update alloc agent information | 更新AllocAgent
+    @handler updateAllocAgent
+    post /alloc_agent/update (AllocAgentInfo) returns (BaseMsgResp)
+
+    // Delete alloc agent information | 删除AllocAgent信息
+    @handler deleteAllocAgent
+    post /alloc_agent/delete (IDsReq) returns (BaseMsgResp)
+
+    // Get alloc agent list | 获取AllocAgent列表
+    @handler getAllocAgentList
+    post /alloc_agent/list (AllocAgentListReq) returns (AllocAgentListResp)
+
+    // Get alloc agent by ID | 通过ID获取AllocAgent
+    @handler getAllocAgentById
+    post /alloc_agent (IDReq) returns (AllocAgentInfoResp)
+}

+ 55 - 0
desc/wechat/chat_records.api

@@ -88,8 +88,63 @@ type (
 		BaseDataInfo
 		Data *string `json:"data"`
 	}
+
+	GptChatReq{
+		ConversationId *string `json:"conversationId,optional"`
+		Content *string `json:"content"`
+	}
+	GptMessageReq {
+		ConversationId *string `json:"conversationId,optional"`
+		FirstId *string `json:"firstId,optional"`
+		Limit *int `json:"limit"`
+	}
+	GptMessageResp {
+		BaseDataInfo
+		Data []Message `json:"data"`
+	}
+	Message {
+		Id *string `json:"id"`
+		ConversationId *string `json:"conversationId,optional"`
+		Query *string `json:"query"`
+		Answer *string `json:"answer"`
+		Inputs interface{} `json:"inputs"`
+		CreatedAt *int `json:"createdAt"`
+	}
+	GptsSessionReq {
+		Limit *int `json:"limit"`
+		LastId *string `json:"lastId,optional"`
+	}
+	GptsSessionResp {
+		BaseDataInfo
+		Data []Session `json:"data"`
+	}
+	Session {
+		Id *string `json:"id"`
+		Name *string `json:"name"`
+		Status *string `json:"status"`
+		CreatedAt *int `json:"createdAt"`
+		Inputs interface{} `json:"inputs"`
+	}
+)
+
+@server(
+	group: chatrecords
 )
 
+service Wechat {
+	// Create chat records information | 创建ChatRecords
+	@handler gptsSubmitApiChat
+	post /gpts/chat/submit (GptChatReq)
+
+	// Create chat records information | 创建ChatRecords
+	@handler gptsGetApiMessage
+	post /gpts/chat/message (GptMessageReq) returns (GptMessageResp)
+
+	// Create chat records information | 创建ChatRecords
+	@handler gptsGetApiSession
+	post /gpts/chat/session (GptsSessionReq) returns (GptsSessionResp)
+}
+
 @server(
 	jwt: Auth
 	group: chatrecords

+ 31 - 0
desc/wechat/user.api

@@ -97,6 +97,25 @@ type (
 		Data UserToken `json:"data,optional"`
 	}
 
+	GptsUserLoginReq {
+		Username *string `json:"username"`
+		Password *string `json:"password"`
+	}
+	GptsUserLoginResp {
+		BaseDataInfo
+		Data GptsUserToken `json:"data,optional"`
+	}
+	GptsUserToken {
+		ID string `json:"id,optional"`
+		Token string `json:"token,optional"`
+		Username string `json:"username,optional"`
+		ExpireTime uint64 `json:"expireTime,optional"`
+	}
+	PasswordReq {
+		Password *string `json:"password"`
+		Password2 *string `json:"password2"`
+	}
+
 	UserToken {
 		Token *string `json:"token,optional"`
 		ID *uint64 `json:"id,optional"`
@@ -124,6 +143,18 @@ service Wechat {
 	// Get user basic information | 获取用户基本信息
 	@handler doApiUserLogin
 	post /api/user/login (UserLoginReq) returns (UserLoginResp)
+
+	// Get user basic information | 获取用户基本信息
+	@handler doGptsUserLogin
+	post /gpts/user/login (GptsUserLoginReq) returns (GptsUserLoginResp)
+
+	// Get user basic information | 获取用户基本信息
+	@handler getGptsUserInfo
+	post /gpts/user/info () returns (UserInfoResp)
+
+	// Get user basic information | 获取用户基本信息
+	@handler updateGptsUserPwd
+	post /gpts/user/password (PasswordReq) returns (BaseDataInfo)
 }
 
 @server(

+ 177 - 0
ent/allocagent.go

@@ -0,0 +1,177 @@
+// Code generated by ent, DO NOT EDIT.
+
+package ent
+
+import (
+	"encoding/json"
+	"fmt"
+	"strings"
+	"time"
+	"wechat-api/ent/allocagent"
+
+	"entgo.io/ent"
+	"entgo.io/ent/dialect/sql"
+)
+
+// AllocAgent is the model entity for the AllocAgent schema.
+type AllocAgent struct {
+	config `json:"-"`
+	// ID of the ent.
+	ID uint64 `json:"id,omitempty"`
+	// Create Time | 创建日期
+	CreatedAt time.Time `json:"created_at,omitempty"`
+	// Update Time | 修改日期
+	UpdatedAt time.Time `json:"updated_at,omitempty"`
+	// Delete Time | 删除日期
+	DeletedAt time.Time `json:"deleted_at,omitempty"`
+	// user_id | 前台用户ID
+	UserID string `json:"user_id,omitempty"`
+	// organization_id | 租户ID
+	OrganizationID uint64 `json:"organization_id,omitempty"`
+	// agents | 分配的智能体IDs
+	Agents []uint64 `json:"agents,omitempty"`
+	// status | 状态 1-正常 2-禁用
+	Status       int `json:"status,omitempty"`
+	selectValues sql.SelectValues
+}
+
+// scanValues returns the types for scanning values from sql.Rows.
+func (*AllocAgent) scanValues(columns []string) ([]any, error) {
+	values := make([]any, len(columns))
+	for i := range columns {
+		switch columns[i] {
+		case allocagent.FieldAgents:
+			values[i] = new([]byte)
+		case allocagent.FieldID, allocagent.FieldOrganizationID, allocagent.FieldStatus:
+			values[i] = new(sql.NullInt64)
+		case allocagent.FieldUserID:
+			values[i] = new(sql.NullString)
+		case allocagent.FieldCreatedAt, allocagent.FieldUpdatedAt, allocagent.FieldDeletedAt:
+			values[i] = new(sql.NullTime)
+		default:
+			values[i] = new(sql.UnknownType)
+		}
+	}
+	return values, nil
+}
+
+// assignValues assigns the values that were returned from sql.Rows (after scanning)
+// to the AllocAgent fields.
+func (aa *AllocAgent) assignValues(columns []string, values []any) error {
+	if m, n := len(values), len(columns); m < n {
+		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
+	}
+	for i := range columns {
+		switch columns[i] {
+		case allocagent.FieldID:
+			value, ok := values[i].(*sql.NullInt64)
+			if !ok {
+				return fmt.Errorf("unexpected type %T for field id", value)
+			}
+			aa.ID = uint64(value.Int64)
+		case allocagent.FieldCreatedAt:
+			if value, ok := values[i].(*sql.NullTime); !ok {
+				return fmt.Errorf("unexpected type %T for field created_at", values[i])
+			} else if value.Valid {
+				aa.CreatedAt = value.Time
+			}
+		case allocagent.FieldUpdatedAt:
+			if value, ok := values[i].(*sql.NullTime); !ok {
+				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
+			} else if value.Valid {
+				aa.UpdatedAt = value.Time
+			}
+		case allocagent.FieldDeletedAt:
+			if value, ok := values[i].(*sql.NullTime); !ok {
+				return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
+			} else if value.Valid {
+				aa.DeletedAt = value.Time
+			}
+		case allocagent.FieldUserID:
+			if value, ok := values[i].(*sql.NullString); !ok {
+				return fmt.Errorf("unexpected type %T for field user_id", values[i])
+			} else if value.Valid {
+				aa.UserID = value.String
+			}
+		case allocagent.FieldOrganizationID:
+			if value, ok := values[i].(*sql.NullInt64); !ok {
+				return fmt.Errorf("unexpected type %T for field organization_id", values[i])
+			} else if value.Valid {
+				aa.OrganizationID = uint64(value.Int64)
+			}
+		case allocagent.FieldAgents:
+			if value, ok := values[i].(*[]byte); !ok {
+				return fmt.Errorf("unexpected type %T for field agents", values[i])
+			} else if value != nil && len(*value) > 0 {
+				if err := json.Unmarshal(*value, &aa.Agents); err != nil {
+					return fmt.Errorf("unmarshal field agents: %w", err)
+				}
+			}
+		case allocagent.FieldStatus:
+			if value, ok := values[i].(*sql.NullInt64); !ok {
+				return fmt.Errorf("unexpected type %T for field status", values[i])
+			} else if value.Valid {
+				aa.Status = int(value.Int64)
+			}
+		default:
+			aa.selectValues.Set(columns[i], values[i])
+		}
+	}
+	return nil
+}
+
+// Value returns the ent.Value that was dynamically selected and assigned to the AllocAgent.
+// This includes values selected through modifiers, order, etc.
+func (aa *AllocAgent) Value(name string) (ent.Value, error) {
+	return aa.selectValues.Get(name)
+}
+
+// Update returns a builder for updating this AllocAgent.
+// Note that you need to call AllocAgent.Unwrap() before calling this method if this AllocAgent
+// was returned from a transaction, and the transaction was committed or rolled back.
+func (aa *AllocAgent) Update() *AllocAgentUpdateOne {
+	return NewAllocAgentClient(aa.config).UpdateOne(aa)
+}
+
+// Unwrap unwraps the AllocAgent entity that was returned from a transaction after it was closed,
+// so that all future queries will be executed through the driver which created the transaction.
+func (aa *AllocAgent) Unwrap() *AllocAgent {
+	_tx, ok := aa.config.driver.(*txDriver)
+	if !ok {
+		panic("ent: AllocAgent is not a transactional entity")
+	}
+	aa.config.driver = _tx.drv
+	return aa
+}
+
+// String implements the fmt.Stringer.
+func (aa *AllocAgent) String() string {
+	var builder strings.Builder
+	builder.WriteString("AllocAgent(")
+	builder.WriteString(fmt.Sprintf("id=%v, ", aa.ID))
+	builder.WriteString("created_at=")
+	builder.WriteString(aa.CreatedAt.Format(time.ANSIC))
+	builder.WriteString(", ")
+	builder.WriteString("updated_at=")
+	builder.WriteString(aa.UpdatedAt.Format(time.ANSIC))
+	builder.WriteString(", ")
+	builder.WriteString("deleted_at=")
+	builder.WriteString(aa.DeletedAt.Format(time.ANSIC))
+	builder.WriteString(", ")
+	builder.WriteString("user_id=")
+	builder.WriteString(aa.UserID)
+	builder.WriteString(", ")
+	builder.WriteString("organization_id=")
+	builder.WriteString(fmt.Sprintf("%v", aa.OrganizationID))
+	builder.WriteString(", ")
+	builder.WriteString("agents=")
+	builder.WriteString(fmt.Sprintf("%v", aa.Agents))
+	builder.WriteString(", ")
+	builder.WriteString("status=")
+	builder.WriteString(fmt.Sprintf("%v", aa.Status))
+	builder.WriteByte(')')
+	return builder.String()
+}
+
+// AllocAgents is a parsable slice of AllocAgent.
+type AllocAgents []*AllocAgent

+ 117 - 0
ent/allocagent/allocagent.go

@@ -0,0 +1,117 @@
+// Code generated by ent, DO NOT EDIT.
+
+package allocagent
+
+import (
+	"time"
+
+	"entgo.io/ent"
+	"entgo.io/ent/dialect/sql"
+)
+
+const (
+	// Label holds the string label denoting the allocagent type in the database.
+	Label = "alloc_agent"
+	// FieldID holds the string denoting the id field in the database.
+	FieldID = "id"
+	// FieldCreatedAt holds the string denoting the created_at field in the database.
+	FieldCreatedAt = "created_at"
+	// FieldUpdatedAt holds the string denoting the updated_at field in the database.
+	FieldUpdatedAt = "updated_at"
+	// FieldDeletedAt holds the string denoting the deleted_at field in the database.
+	FieldDeletedAt = "deleted_at"
+	// FieldUserID holds the string denoting the user_id field in the database.
+	FieldUserID = "user_id"
+	// FieldOrganizationID holds the string denoting the organization_id field in the database.
+	FieldOrganizationID = "organization_id"
+	// FieldAgents holds the string denoting the agents field in the database.
+	FieldAgents = "agents"
+	// FieldStatus holds the string denoting the status field in the database.
+	FieldStatus = "status"
+	// Table holds the table name of the allocagent in the database.
+	Table = "alloc_agent"
+)
+
+// Columns holds all SQL columns for allocagent fields.
+var Columns = []string{
+	FieldID,
+	FieldCreatedAt,
+	FieldUpdatedAt,
+	FieldDeletedAt,
+	FieldUserID,
+	FieldOrganizationID,
+	FieldAgents,
+	FieldStatus,
+}
+
+// ValidColumn reports if the column name is valid (part of the table columns).
+func ValidColumn(column string) bool {
+	for i := range Columns {
+		if column == Columns[i] {
+			return true
+		}
+	}
+	return false
+}
+
+// Note that the variables below are initialized by the runtime
+// package on the initialization of the application. Therefore,
+// it should be imported in the main as follows:
+//
+//	import _ "wechat-api/ent/runtime"
+var (
+	Hooks        [1]ent.Hook
+	Interceptors [1]ent.Interceptor
+	// DefaultCreatedAt holds the default value on creation for the "created_at" field.
+	DefaultCreatedAt func() time.Time
+	// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
+	DefaultUpdatedAt func() time.Time
+	// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
+	UpdateDefaultUpdatedAt func() time.Time
+	// DefaultUserID holds the default value on creation for the "user_id" field.
+	DefaultUserID string
+	// DefaultOrganizationID holds the default value on creation for the "organization_id" field.
+	DefaultOrganizationID uint64
+	// DefaultStatus holds the default value on creation for the "status" field.
+	DefaultStatus int
+	// StatusValidator is a validator for the "status" field. It is called by the builders before save.
+	StatusValidator func(int) error
+)
+
+// OrderOption defines the ordering options for the AllocAgent queries.
+type OrderOption func(*sql.Selector)
+
+// ByID orders the results by the id field.
+func ByID(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldID, opts...).ToFunc()
+}
+
+// ByCreatedAt orders the results by the created_at field.
+func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
+}
+
+// ByUpdatedAt orders the results by the updated_at field.
+func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
+}
+
+// ByDeletedAt orders the results by the deleted_at field.
+func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldDeletedAt, opts...).ToFunc()
+}
+
+// ByUserID orders the results by the user_id field.
+func ByUserID(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldUserID, opts...).ToFunc()
+}
+
+// ByOrganizationID orders the results by the organization_id field.
+func ByOrganizationID(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldOrganizationID, opts...).ToFunc()
+}
+
+// ByStatus orders the results by the status field.
+func ByStatus(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldStatus, opts...).ToFunc()
+}

+ 405 - 0
ent/allocagent/where.go

@@ -0,0 +1,405 @@
+// Code generated by ent, DO NOT EDIT.
+
+package allocagent
+
+import (
+	"time"
+	"wechat-api/ent/predicate"
+
+	"entgo.io/ent/dialect/sql"
+)
+
+// ID filters vertices based on their ID field.
+func ID(id uint64) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldEQ(FieldID, id))
+}
+
+// IDEQ applies the EQ predicate on the ID field.
+func IDEQ(id uint64) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldEQ(FieldID, id))
+}
+
+// IDNEQ applies the NEQ predicate on the ID field.
+func IDNEQ(id uint64) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldNEQ(FieldID, id))
+}
+
+// IDIn applies the In predicate on the ID field.
+func IDIn(ids ...uint64) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldIn(FieldID, ids...))
+}
+
+// IDNotIn applies the NotIn predicate on the ID field.
+func IDNotIn(ids ...uint64) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldNotIn(FieldID, ids...))
+}
+
+// IDGT applies the GT predicate on the ID field.
+func IDGT(id uint64) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldGT(FieldID, id))
+}
+
+// IDGTE applies the GTE predicate on the ID field.
+func IDGTE(id uint64) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldGTE(FieldID, id))
+}
+
+// IDLT applies the LT predicate on the ID field.
+func IDLT(id uint64) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldLT(FieldID, id))
+}
+
+// IDLTE applies the LTE predicate on the ID field.
+func IDLTE(id uint64) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldLTE(FieldID, id))
+}
+
+// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
+func CreatedAt(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldEQ(FieldCreatedAt, v))
+}
+
+// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
+func UpdatedAt(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldEQ(FieldUpdatedAt, v))
+}
+
+// DeletedAt applies equality check predicate on the "deleted_at" field. It's identical to DeletedAtEQ.
+func DeletedAt(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldEQ(FieldDeletedAt, v))
+}
+
+// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
+func UserID(v string) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldEQ(FieldUserID, v))
+}
+
+// OrganizationID applies equality check predicate on the "organization_id" field. It's identical to OrganizationIDEQ.
+func OrganizationID(v uint64) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldEQ(FieldOrganizationID, v))
+}
+
+// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
+func Status(v int) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldEQ(FieldStatus, v))
+}
+
+// CreatedAtEQ applies the EQ predicate on the "created_at" field.
+func CreatedAtEQ(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldEQ(FieldCreatedAt, v))
+}
+
+// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
+func CreatedAtNEQ(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldNEQ(FieldCreatedAt, v))
+}
+
+// CreatedAtIn applies the In predicate on the "created_at" field.
+func CreatedAtIn(vs ...time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldIn(FieldCreatedAt, vs...))
+}
+
+// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
+func CreatedAtNotIn(vs ...time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldNotIn(FieldCreatedAt, vs...))
+}
+
+// CreatedAtGT applies the GT predicate on the "created_at" field.
+func CreatedAtGT(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldGT(FieldCreatedAt, v))
+}
+
+// CreatedAtGTE applies the GTE predicate on the "created_at" field.
+func CreatedAtGTE(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldGTE(FieldCreatedAt, v))
+}
+
+// CreatedAtLT applies the LT predicate on the "created_at" field.
+func CreatedAtLT(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldLT(FieldCreatedAt, v))
+}
+
+// CreatedAtLTE applies the LTE predicate on the "created_at" field.
+func CreatedAtLTE(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldLTE(FieldCreatedAt, v))
+}
+
+// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
+func UpdatedAtEQ(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldEQ(FieldUpdatedAt, v))
+}
+
+// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
+func UpdatedAtNEQ(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldNEQ(FieldUpdatedAt, v))
+}
+
+// UpdatedAtIn applies the In predicate on the "updated_at" field.
+func UpdatedAtIn(vs ...time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldIn(FieldUpdatedAt, vs...))
+}
+
+// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
+func UpdatedAtNotIn(vs ...time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldNotIn(FieldUpdatedAt, vs...))
+}
+
+// UpdatedAtGT applies the GT predicate on the "updated_at" field.
+func UpdatedAtGT(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldGT(FieldUpdatedAt, v))
+}
+
+// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
+func UpdatedAtGTE(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldGTE(FieldUpdatedAt, v))
+}
+
+// UpdatedAtLT applies the LT predicate on the "updated_at" field.
+func UpdatedAtLT(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldLT(FieldUpdatedAt, v))
+}
+
+// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
+func UpdatedAtLTE(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldLTE(FieldUpdatedAt, v))
+}
+
+// DeletedAtEQ applies the EQ predicate on the "deleted_at" field.
+func DeletedAtEQ(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldEQ(FieldDeletedAt, v))
+}
+
+// DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field.
+func DeletedAtNEQ(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldNEQ(FieldDeletedAt, v))
+}
+
+// DeletedAtIn applies the In predicate on the "deleted_at" field.
+func DeletedAtIn(vs ...time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldIn(FieldDeletedAt, vs...))
+}
+
+// DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field.
+func DeletedAtNotIn(vs ...time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldNotIn(FieldDeletedAt, vs...))
+}
+
+// DeletedAtGT applies the GT predicate on the "deleted_at" field.
+func DeletedAtGT(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldGT(FieldDeletedAt, v))
+}
+
+// DeletedAtGTE applies the GTE predicate on the "deleted_at" field.
+func DeletedAtGTE(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldGTE(FieldDeletedAt, v))
+}
+
+// DeletedAtLT applies the LT predicate on the "deleted_at" field.
+func DeletedAtLT(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldLT(FieldDeletedAt, v))
+}
+
+// DeletedAtLTE applies the LTE predicate on the "deleted_at" field.
+func DeletedAtLTE(v time.Time) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldLTE(FieldDeletedAt, v))
+}
+
+// DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field.
+func DeletedAtIsNil() predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldIsNull(FieldDeletedAt))
+}
+
+// DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field.
+func DeletedAtNotNil() predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldNotNull(FieldDeletedAt))
+}
+
+// UserIDEQ applies the EQ predicate on the "user_id" field.
+func UserIDEQ(v string) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldEQ(FieldUserID, v))
+}
+
+// UserIDNEQ applies the NEQ predicate on the "user_id" field.
+func UserIDNEQ(v string) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldNEQ(FieldUserID, v))
+}
+
+// UserIDIn applies the In predicate on the "user_id" field.
+func UserIDIn(vs ...string) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldIn(FieldUserID, vs...))
+}
+
+// UserIDNotIn applies the NotIn predicate on the "user_id" field.
+func UserIDNotIn(vs ...string) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldNotIn(FieldUserID, vs...))
+}
+
+// UserIDGT applies the GT predicate on the "user_id" field.
+func UserIDGT(v string) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldGT(FieldUserID, v))
+}
+
+// UserIDGTE applies the GTE predicate on the "user_id" field.
+func UserIDGTE(v string) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldGTE(FieldUserID, v))
+}
+
+// UserIDLT applies the LT predicate on the "user_id" field.
+func UserIDLT(v string) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldLT(FieldUserID, v))
+}
+
+// UserIDLTE applies the LTE predicate on the "user_id" field.
+func UserIDLTE(v string) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldLTE(FieldUserID, v))
+}
+
+// UserIDContains applies the Contains predicate on the "user_id" field.
+func UserIDContains(v string) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldContains(FieldUserID, v))
+}
+
+// UserIDHasPrefix applies the HasPrefix predicate on the "user_id" field.
+func UserIDHasPrefix(v string) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldHasPrefix(FieldUserID, v))
+}
+
+// UserIDHasSuffix applies the HasSuffix predicate on the "user_id" field.
+func UserIDHasSuffix(v string) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldHasSuffix(FieldUserID, v))
+}
+
+// UserIDIsNil applies the IsNil predicate on the "user_id" field.
+func UserIDIsNil() predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldIsNull(FieldUserID))
+}
+
+// UserIDNotNil applies the NotNil predicate on the "user_id" field.
+func UserIDNotNil() predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldNotNull(FieldUserID))
+}
+
+// UserIDEqualFold applies the EqualFold predicate on the "user_id" field.
+func UserIDEqualFold(v string) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldEqualFold(FieldUserID, v))
+}
+
+// UserIDContainsFold applies the ContainsFold predicate on the "user_id" field.
+func UserIDContainsFold(v string) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldContainsFold(FieldUserID, v))
+}
+
+// OrganizationIDEQ applies the EQ predicate on the "organization_id" field.
+func OrganizationIDEQ(v uint64) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldEQ(FieldOrganizationID, v))
+}
+
+// OrganizationIDNEQ applies the NEQ predicate on the "organization_id" field.
+func OrganizationIDNEQ(v uint64) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldNEQ(FieldOrganizationID, v))
+}
+
+// OrganizationIDIn applies the In predicate on the "organization_id" field.
+func OrganizationIDIn(vs ...uint64) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldIn(FieldOrganizationID, vs...))
+}
+
+// OrganizationIDNotIn applies the NotIn predicate on the "organization_id" field.
+func OrganizationIDNotIn(vs ...uint64) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldNotIn(FieldOrganizationID, vs...))
+}
+
+// OrganizationIDGT applies the GT predicate on the "organization_id" field.
+func OrganizationIDGT(v uint64) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldGT(FieldOrganizationID, v))
+}
+
+// OrganizationIDGTE applies the GTE predicate on the "organization_id" field.
+func OrganizationIDGTE(v uint64) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldGTE(FieldOrganizationID, v))
+}
+
+// OrganizationIDLT applies the LT predicate on the "organization_id" field.
+func OrganizationIDLT(v uint64) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldLT(FieldOrganizationID, v))
+}
+
+// OrganizationIDLTE applies the LTE predicate on the "organization_id" field.
+func OrganizationIDLTE(v uint64) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldLTE(FieldOrganizationID, v))
+}
+
+// OrganizationIDIsNil applies the IsNil predicate on the "organization_id" field.
+func OrganizationIDIsNil() predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldIsNull(FieldOrganizationID))
+}
+
+// OrganizationIDNotNil applies the NotNil predicate on the "organization_id" field.
+func OrganizationIDNotNil() predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldNotNull(FieldOrganizationID))
+}
+
+// StatusEQ applies the EQ predicate on the "status" field.
+func StatusEQ(v int) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldEQ(FieldStatus, v))
+}
+
+// StatusNEQ applies the NEQ predicate on the "status" field.
+func StatusNEQ(v int) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldNEQ(FieldStatus, v))
+}
+
+// StatusIn applies the In predicate on the "status" field.
+func StatusIn(vs ...int) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldIn(FieldStatus, vs...))
+}
+
+// StatusNotIn applies the NotIn predicate on the "status" field.
+func StatusNotIn(vs ...int) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldNotIn(FieldStatus, vs...))
+}
+
+// StatusGT applies the GT predicate on the "status" field.
+func StatusGT(v int) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldGT(FieldStatus, v))
+}
+
+// StatusGTE applies the GTE predicate on the "status" field.
+func StatusGTE(v int) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldGTE(FieldStatus, v))
+}
+
+// StatusLT applies the LT predicate on the "status" field.
+func StatusLT(v int) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldLT(FieldStatus, v))
+}
+
+// StatusLTE applies the LTE predicate on the "status" field.
+func StatusLTE(v int) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldLTE(FieldStatus, v))
+}
+
+// StatusIsNil applies the IsNil predicate on the "status" field.
+func StatusIsNil() predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldIsNull(FieldStatus))
+}
+
+// StatusNotNil applies the NotNil predicate on the "status" field.
+func StatusNotNil() predicate.AllocAgent {
+	return predicate.AllocAgent(sql.FieldNotNull(FieldStatus))
+}
+
+// And groups predicates with the AND operator between them.
+func And(predicates ...predicate.AllocAgent) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.AndPredicates(predicates...))
+}
+
+// Or groups predicates with the OR operator between them.
+func Or(predicates ...predicate.AllocAgent) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.OrPredicates(predicates...))
+}
+
+// Not applies the not operator on the given predicate.
+func Not(p predicate.AllocAgent) predicate.AllocAgent {
+	return predicate.AllocAgent(sql.NotPredicates(p))
+}

+ 965 - 0
ent/allocagent_create.go

@@ -0,0 +1,965 @@
+// Code generated by ent, DO NOT EDIT.
+
+package ent
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	"time"
+	"wechat-api/ent/allocagent"
+
+	"entgo.io/ent/dialect/sql"
+	"entgo.io/ent/dialect/sql/sqlgraph"
+	"entgo.io/ent/schema/field"
+)
+
+// AllocAgentCreate is the builder for creating a AllocAgent entity.
+type AllocAgentCreate struct {
+	config
+	mutation *AllocAgentMutation
+	hooks    []Hook
+	conflict []sql.ConflictOption
+}
+
+// SetCreatedAt sets the "created_at" field.
+func (aac *AllocAgentCreate) SetCreatedAt(t time.Time) *AllocAgentCreate {
+	aac.mutation.SetCreatedAt(t)
+	return aac
+}
+
+// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
+func (aac *AllocAgentCreate) SetNillableCreatedAt(t *time.Time) *AllocAgentCreate {
+	if t != nil {
+		aac.SetCreatedAt(*t)
+	}
+	return aac
+}
+
+// SetUpdatedAt sets the "updated_at" field.
+func (aac *AllocAgentCreate) SetUpdatedAt(t time.Time) *AllocAgentCreate {
+	aac.mutation.SetUpdatedAt(t)
+	return aac
+}
+
+// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
+func (aac *AllocAgentCreate) SetNillableUpdatedAt(t *time.Time) *AllocAgentCreate {
+	if t != nil {
+		aac.SetUpdatedAt(*t)
+	}
+	return aac
+}
+
+// SetDeletedAt sets the "deleted_at" field.
+func (aac *AllocAgentCreate) SetDeletedAt(t time.Time) *AllocAgentCreate {
+	aac.mutation.SetDeletedAt(t)
+	return aac
+}
+
+// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
+func (aac *AllocAgentCreate) SetNillableDeletedAt(t *time.Time) *AllocAgentCreate {
+	if t != nil {
+		aac.SetDeletedAt(*t)
+	}
+	return aac
+}
+
+// SetUserID sets the "user_id" field.
+func (aac *AllocAgentCreate) SetUserID(s string) *AllocAgentCreate {
+	aac.mutation.SetUserID(s)
+	return aac
+}
+
+// SetNillableUserID sets the "user_id" field if the given value is not nil.
+func (aac *AllocAgentCreate) SetNillableUserID(s *string) *AllocAgentCreate {
+	if s != nil {
+		aac.SetUserID(*s)
+	}
+	return aac
+}
+
+// SetOrganizationID sets the "organization_id" field.
+func (aac *AllocAgentCreate) SetOrganizationID(u uint64) *AllocAgentCreate {
+	aac.mutation.SetOrganizationID(u)
+	return aac
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (aac *AllocAgentCreate) SetNillableOrganizationID(u *uint64) *AllocAgentCreate {
+	if u != nil {
+		aac.SetOrganizationID(*u)
+	}
+	return aac
+}
+
+// SetAgents sets the "agents" field.
+func (aac *AllocAgentCreate) SetAgents(u []uint64) *AllocAgentCreate {
+	aac.mutation.SetAgents(u)
+	return aac
+}
+
+// SetStatus sets the "status" field.
+func (aac *AllocAgentCreate) SetStatus(i int) *AllocAgentCreate {
+	aac.mutation.SetStatus(i)
+	return aac
+}
+
+// SetNillableStatus sets the "status" field if the given value is not nil.
+func (aac *AllocAgentCreate) SetNillableStatus(i *int) *AllocAgentCreate {
+	if i != nil {
+		aac.SetStatus(*i)
+	}
+	return aac
+}
+
+// SetID sets the "id" field.
+func (aac *AllocAgentCreate) SetID(u uint64) *AllocAgentCreate {
+	aac.mutation.SetID(u)
+	return aac
+}
+
+// Mutation returns the AllocAgentMutation object of the builder.
+func (aac *AllocAgentCreate) Mutation() *AllocAgentMutation {
+	return aac.mutation
+}
+
+// Save creates the AllocAgent in the database.
+func (aac *AllocAgentCreate) Save(ctx context.Context) (*AllocAgent, error) {
+	if err := aac.defaults(); err != nil {
+		return nil, err
+	}
+	return withHooks(ctx, aac.sqlSave, aac.mutation, aac.hooks)
+}
+
+// SaveX calls Save and panics if Save returns an error.
+func (aac *AllocAgentCreate) SaveX(ctx context.Context) *AllocAgent {
+	v, err := aac.Save(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return v
+}
+
+// Exec executes the query.
+func (aac *AllocAgentCreate) Exec(ctx context.Context) error {
+	_, err := aac.Save(ctx)
+	return err
+}
+
+// ExecX is like Exec, but panics if an error occurs.
+func (aac *AllocAgentCreate) ExecX(ctx context.Context) {
+	if err := aac.Exec(ctx); err != nil {
+		panic(err)
+	}
+}
+
+// defaults sets the default values of the builder before save.
+func (aac *AllocAgentCreate) defaults() error {
+	if _, ok := aac.mutation.CreatedAt(); !ok {
+		if allocagent.DefaultCreatedAt == nil {
+			return fmt.Errorf("ent: uninitialized allocagent.DefaultCreatedAt (forgotten import ent/runtime?)")
+		}
+		v := allocagent.DefaultCreatedAt()
+		aac.mutation.SetCreatedAt(v)
+	}
+	if _, ok := aac.mutation.UpdatedAt(); !ok {
+		if allocagent.DefaultUpdatedAt == nil {
+			return fmt.Errorf("ent: uninitialized allocagent.DefaultUpdatedAt (forgotten import ent/runtime?)")
+		}
+		v := allocagent.DefaultUpdatedAt()
+		aac.mutation.SetUpdatedAt(v)
+	}
+	if _, ok := aac.mutation.UserID(); !ok {
+		v := allocagent.DefaultUserID
+		aac.mutation.SetUserID(v)
+	}
+	if _, ok := aac.mutation.OrganizationID(); !ok {
+		v := allocagent.DefaultOrganizationID
+		aac.mutation.SetOrganizationID(v)
+	}
+	if _, ok := aac.mutation.Status(); !ok {
+		v := allocagent.DefaultStatus
+		aac.mutation.SetStatus(v)
+	}
+	return nil
+}
+
+// check runs all checks and user-defined validators on the builder.
+func (aac *AllocAgentCreate) check() error {
+	if _, ok := aac.mutation.CreatedAt(); !ok {
+		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "AllocAgent.created_at"`)}
+	}
+	if _, ok := aac.mutation.UpdatedAt(); !ok {
+		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "AllocAgent.updated_at"`)}
+	}
+	if _, ok := aac.mutation.Agents(); !ok {
+		return &ValidationError{Name: "agents", err: errors.New(`ent: missing required field "AllocAgent.agents"`)}
+	}
+	if v, ok := aac.mutation.Status(); ok {
+		if err := allocagent.StatusValidator(v); err != nil {
+			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "AllocAgent.status": %w`, err)}
+		}
+	}
+	return nil
+}
+
+func (aac *AllocAgentCreate) sqlSave(ctx context.Context) (*AllocAgent, error) {
+	if err := aac.check(); err != nil {
+		return nil, err
+	}
+	_node, _spec := aac.createSpec()
+	if err := sqlgraph.CreateNode(ctx, aac.driver, _spec); err != nil {
+		if sqlgraph.IsConstraintError(err) {
+			err = &ConstraintError{msg: err.Error(), wrap: err}
+		}
+		return nil, err
+	}
+	if _spec.ID.Value != _node.ID {
+		id := _spec.ID.Value.(int64)
+		_node.ID = uint64(id)
+	}
+	aac.mutation.id = &_node.ID
+	aac.mutation.done = true
+	return _node, nil
+}
+
+func (aac *AllocAgentCreate) createSpec() (*AllocAgent, *sqlgraph.CreateSpec) {
+	var (
+		_node = &AllocAgent{config: aac.config}
+		_spec = sqlgraph.NewCreateSpec(allocagent.Table, sqlgraph.NewFieldSpec(allocagent.FieldID, field.TypeUint64))
+	)
+	_spec.OnConflict = aac.conflict
+	if id, ok := aac.mutation.ID(); ok {
+		_node.ID = id
+		_spec.ID.Value = id
+	}
+	if value, ok := aac.mutation.CreatedAt(); ok {
+		_spec.SetField(allocagent.FieldCreatedAt, field.TypeTime, value)
+		_node.CreatedAt = value
+	}
+	if value, ok := aac.mutation.UpdatedAt(); ok {
+		_spec.SetField(allocagent.FieldUpdatedAt, field.TypeTime, value)
+		_node.UpdatedAt = value
+	}
+	if value, ok := aac.mutation.DeletedAt(); ok {
+		_spec.SetField(allocagent.FieldDeletedAt, field.TypeTime, value)
+		_node.DeletedAt = value
+	}
+	if value, ok := aac.mutation.UserID(); ok {
+		_spec.SetField(allocagent.FieldUserID, field.TypeString, value)
+		_node.UserID = value
+	}
+	if value, ok := aac.mutation.OrganizationID(); ok {
+		_spec.SetField(allocagent.FieldOrganizationID, field.TypeUint64, value)
+		_node.OrganizationID = value
+	}
+	if value, ok := aac.mutation.Agents(); ok {
+		_spec.SetField(allocagent.FieldAgents, field.TypeJSON, value)
+		_node.Agents = value
+	}
+	if value, ok := aac.mutation.Status(); ok {
+		_spec.SetField(allocagent.FieldStatus, field.TypeInt, value)
+		_node.Status = value
+	}
+	return _node, _spec
+}
+
+// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
+// of the `INSERT` statement. For example:
+//
+//	client.AllocAgent.Create().
+//		SetCreatedAt(v).
+//		OnConflict(
+//			// Update the row with the new values
+//			// the was proposed for insertion.
+//			sql.ResolveWithNewValues(),
+//		).
+//		// Override some of the fields with custom
+//		// update values.
+//		Update(func(u *ent.AllocAgentUpsert) {
+//			SetCreatedAt(v+v).
+//		}).
+//		Exec(ctx)
+func (aac *AllocAgentCreate) OnConflict(opts ...sql.ConflictOption) *AllocAgentUpsertOne {
+	aac.conflict = opts
+	return &AllocAgentUpsertOne{
+		create: aac,
+	}
+}
+
+// OnConflictColumns calls `OnConflict` and configures the columns
+// as conflict target. Using this option is equivalent to using:
+//
+//	client.AllocAgent.Create().
+//		OnConflict(sql.ConflictColumns(columns...)).
+//		Exec(ctx)
+func (aac *AllocAgentCreate) OnConflictColumns(columns ...string) *AllocAgentUpsertOne {
+	aac.conflict = append(aac.conflict, sql.ConflictColumns(columns...))
+	return &AllocAgentUpsertOne{
+		create: aac,
+	}
+}
+
+type (
+	// AllocAgentUpsertOne is the builder for "upsert"-ing
+	//  one AllocAgent node.
+	AllocAgentUpsertOne struct {
+		create *AllocAgentCreate
+	}
+
+	// AllocAgentUpsert is the "OnConflict" setter.
+	AllocAgentUpsert struct {
+		*sql.UpdateSet
+	}
+)
+
+// SetUpdatedAt sets the "updated_at" field.
+func (u *AllocAgentUpsert) SetUpdatedAt(v time.Time) *AllocAgentUpsert {
+	u.Set(allocagent.FieldUpdatedAt, v)
+	return u
+}
+
+// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
+func (u *AllocAgentUpsert) UpdateUpdatedAt() *AllocAgentUpsert {
+	u.SetExcluded(allocagent.FieldUpdatedAt)
+	return u
+}
+
+// SetDeletedAt sets the "deleted_at" field.
+func (u *AllocAgentUpsert) SetDeletedAt(v time.Time) *AllocAgentUpsert {
+	u.Set(allocagent.FieldDeletedAt, v)
+	return u
+}
+
+// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
+func (u *AllocAgentUpsert) UpdateDeletedAt() *AllocAgentUpsert {
+	u.SetExcluded(allocagent.FieldDeletedAt)
+	return u
+}
+
+// ClearDeletedAt clears the value of the "deleted_at" field.
+func (u *AllocAgentUpsert) ClearDeletedAt() *AllocAgentUpsert {
+	u.SetNull(allocagent.FieldDeletedAt)
+	return u
+}
+
+// SetUserID sets the "user_id" field.
+func (u *AllocAgentUpsert) SetUserID(v string) *AllocAgentUpsert {
+	u.Set(allocagent.FieldUserID, v)
+	return u
+}
+
+// UpdateUserID sets the "user_id" field to the value that was provided on create.
+func (u *AllocAgentUpsert) UpdateUserID() *AllocAgentUpsert {
+	u.SetExcluded(allocagent.FieldUserID)
+	return u
+}
+
+// ClearUserID clears the value of the "user_id" field.
+func (u *AllocAgentUpsert) ClearUserID() *AllocAgentUpsert {
+	u.SetNull(allocagent.FieldUserID)
+	return u
+}
+
+// SetOrganizationID sets the "organization_id" field.
+func (u *AllocAgentUpsert) SetOrganizationID(v uint64) *AllocAgentUpsert {
+	u.Set(allocagent.FieldOrganizationID, v)
+	return u
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *AllocAgentUpsert) UpdateOrganizationID() *AllocAgentUpsert {
+	u.SetExcluded(allocagent.FieldOrganizationID)
+	return u
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *AllocAgentUpsert) AddOrganizationID(v uint64) *AllocAgentUpsert {
+	u.Add(allocagent.FieldOrganizationID, v)
+	return u
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *AllocAgentUpsert) ClearOrganizationID() *AllocAgentUpsert {
+	u.SetNull(allocagent.FieldOrganizationID)
+	return u
+}
+
+// SetAgents sets the "agents" field.
+func (u *AllocAgentUpsert) SetAgents(v []uint64) *AllocAgentUpsert {
+	u.Set(allocagent.FieldAgents, v)
+	return u
+}
+
+// UpdateAgents sets the "agents" field to the value that was provided on create.
+func (u *AllocAgentUpsert) UpdateAgents() *AllocAgentUpsert {
+	u.SetExcluded(allocagent.FieldAgents)
+	return u
+}
+
+// SetStatus sets the "status" field.
+func (u *AllocAgentUpsert) SetStatus(v int) *AllocAgentUpsert {
+	u.Set(allocagent.FieldStatus, v)
+	return u
+}
+
+// UpdateStatus sets the "status" field to the value that was provided on create.
+func (u *AllocAgentUpsert) UpdateStatus() *AllocAgentUpsert {
+	u.SetExcluded(allocagent.FieldStatus)
+	return u
+}
+
+// AddStatus adds v to the "status" field.
+func (u *AllocAgentUpsert) AddStatus(v int) *AllocAgentUpsert {
+	u.Add(allocagent.FieldStatus, v)
+	return u
+}
+
+// ClearStatus clears the value of the "status" field.
+func (u *AllocAgentUpsert) ClearStatus() *AllocAgentUpsert {
+	u.SetNull(allocagent.FieldStatus)
+	return u
+}
+
+// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
+// Using this option is equivalent to using:
+//
+//	client.AllocAgent.Create().
+//		OnConflict(
+//			sql.ResolveWithNewValues(),
+//			sql.ResolveWith(func(u *sql.UpdateSet) {
+//				u.SetIgnore(allocagent.FieldID)
+//			}),
+//		).
+//		Exec(ctx)
+func (u *AllocAgentUpsertOne) UpdateNewValues() *AllocAgentUpsertOne {
+	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
+	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
+		if _, exists := u.create.mutation.ID(); exists {
+			s.SetIgnore(allocagent.FieldID)
+		}
+		if _, exists := u.create.mutation.CreatedAt(); exists {
+			s.SetIgnore(allocagent.FieldCreatedAt)
+		}
+	}))
+	return u
+}
+
+// Ignore sets each column to itself in case of conflict.
+// Using this option is equivalent to using:
+//
+//	client.AllocAgent.Create().
+//	    OnConflict(sql.ResolveWithIgnore()).
+//	    Exec(ctx)
+func (u *AllocAgentUpsertOne) Ignore() *AllocAgentUpsertOne {
+	u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
+	return u
+}
+
+// DoNothing configures the conflict_action to `DO NOTHING`.
+// Supported only by SQLite and PostgreSQL.
+func (u *AllocAgentUpsertOne) DoNothing() *AllocAgentUpsertOne {
+	u.create.conflict = append(u.create.conflict, sql.DoNothing())
+	return u
+}
+
+// Update allows overriding fields `UPDATE` values. See the AllocAgentCreate.OnConflict
+// documentation for more info.
+func (u *AllocAgentUpsertOne) Update(set func(*AllocAgentUpsert)) *AllocAgentUpsertOne {
+	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
+		set(&AllocAgentUpsert{UpdateSet: update})
+	}))
+	return u
+}
+
+// SetUpdatedAt sets the "updated_at" field.
+func (u *AllocAgentUpsertOne) SetUpdatedAt(v time.Time) *AllocAgentUpsertOne {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.SetUpdatedAt(v)
+	})
+}
+
+// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
+func (u *AllocAgentUpsertOne) UpdateUpdatedAt() *AllocAgentUpsertOne {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.UpdateUpdatedAt()
+	})
+}
+
+// SetDeletedAt sets the "deleted_at" field.
+func (u *AllocAgentUpsertOne) SetDeletedAt(v time.Time) *AllocAgentUpsertOne {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.SetDeletedAt(v)
+	})
+}
+
+// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
+func (u *AllocAgentUpsertOne) UpdateDeletedAt() *AllocAgentUpsertOne {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.UpdateDeletedAt()
+	})
+}
+
+// ClearDeletedAt clears the value of the "deleted_at" field.
+func (u *AllocAgentUpsertOne) ClearDeletedAt() *AllocAgentUpsertOne {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.ClearDeletedAt()
+	})
+}
+
+// SetUserID sets the "user_id" field.
+func (u *AllocAgentUpsertOne) SetUserID(v string) *AllocAgentUpsertOne {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.SetUserID(v)
+	})
+}
+
+// UpdateUserID sets the "user_id" field to the value that was provided on create.
+func (u *AllocAgentUpsertOne) UpdateUserID() *AllocAgentUpsertOne {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.UpdateUserID()
+	})
+}
+
+// ClearUserID clears the value of the "user_id" field.
+func (u *AllocAgentUpsertOne) ClearUserID() *AllocAgentUpsertOne {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.ClearUserID()
+	})
+}
+
+// SetOrganizationID sets the "organization_id" field.
+func (u *AllocAgentUpsertOne) SetOrganizationID(v uint64) *AllocAgentUpsertOne {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.SetOrganizationID(v)
+	})
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *AllocAgentUpsertOne) AddOrganizationID(v uint64) *AllocAgentUpsertOne {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.AddOrganizationID(v)
+	})
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *AllocAgentUpsertOne) UpdateOrganizationID() *AllocAgentUpsertOne {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.UpdateOrganizationID()
+	})
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *AllocAgentUpsertOne) ClearOrganizationID() *AllocAgentUpsertOne {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.ClearOrganizationID()
+	})
+}
+
+// SetAgents sets the "agents" field.
+func (u *AllocAgentUpsertOne) SetAgents(v []uint64) *AllocAgentUpsertOne {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.SetAgents(v)
+	})
+}
+
+// UpdateAgents sets the "agents" field to the value that was provided on create.
+func (u *AllocAgentUpsertOne) UpdateAgents() *AllocAgentUpsertOne {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.UpdateAgents()
+	})
+}
+
+// SetStatus sets the "status" field.
+func (u *AllocAgentUpsertOne) SetStatus(v int) *AllocAgentUpsertOne {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.SetStatus(v)
+	})
+}
+
+// AddStatus adds v to the "status" field.
+func (u *AllocAgentUpsertOne) AddStatus(v int) *AllocAgentUpsertOne {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.AddStatus(v)
+	})
+}
+
+// UpdateStatus sets the "status" field to the value that was provided on create.
+func (u *AllocAgentUpsertOne) UpdateStatus() *AllocAgentUpsertOne {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.UpdateStatus()
+	})
+}
+
+// ClearStatus clears the value of the "status" field.
+func (u *AllocAgentUpsertOne) ClearStatus() *AllocAgentUpsertOne {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.ClearStatus()
+	})
+}
+
+// Exec executes the query.
+func (u *AllocAgentUpsertOne) Exec(ctx context.Context) error {
+	if len(u.create.conflict) == 0 {
+		return errors.New("ent: missing options for AllocAgentCreate.OnConflict")
+	}
+	return u.create.Exec(ctx)
+}
+
+// ExecX is like Exec, but panics if an error occurs.
+func (u *AllocAgentUpsertOne) ExecX(ctx context.Context) {
+	if err := u.create.Exec(ctx); err != nil {
+		panic(err)
+	}
+}
+
+// Exec executes the UPSERT query and returns the inserted/updated ID.
+func (u *AllocAgentUpsertOne) ID(ctx context.Context) (id uint64, err error) {
+	node, err := u.create.Save(ctx)
+	if err != nil {
+		return id, err
+	}
+	return node.ID, nil
+}
+
+// IDX is like ID, but panics if an error occurs.
+func (u *AllocAgentUpsertOne) IDX(ctx context.Context) uint64 {
+	id, err := u.ID(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return id
+}
+
+// AllocAgentCreateBulk is the builder for creating many AllocAgent entities in bulk.
+type AllocAgentCreateBulk struct {
+	config
+	err      error
+	builders []*AllocAgentCreate
+	conflict []sql.ConflictOption
+}
+
+// Save creates the AllocAgent entities in the database.
+func (aacb *AllocAgentCreateBulk) Save(ctx context.Context) ([]*AllocAgent, error) {
+	if aacb.err != nil {
+		return nil, aacb.err
+	}
+	specs := make([]*sqlgraph.CreateSpec, len(aacb.builders))
+	nodes := make([]*AllocAgent, len(aacb.builders))
+	mutators := make([]Mutator, len(aacb.builders))
+	for i := range aacb.builders {
+		func(i int, root context.Context) {
+			builder := aacb.builders[i]
+			builder.defaults()
+			var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
+				mutation, ok := m.(*AllocAgentMutation)
+				if !ok {
+					return nil, fmt.Errorf("unexpected mutation type %T", m)
+				}
+				if err := builder.check(); err != nil {
+					return nil, err
+				}
+				builder.mutation = mutation
+				var err error
+				nodes[i], specs[i] = builder.createSpec()
+				if i < len(mutators)-1 {
+					_, err = mutators[i+1].Mutate(root, aacb.builders[i+1].mutation)
+				} else {
+					spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
+					spec.OnConflict = aacb.conflict
+					// Invoke the actual operation on the latest mutation in the chain.
+					if err = sqlgraph.BatchCreate(ctx, aacb.driver, spec); err != nil {
+						if sqlgraph.IsConstraintError(err) {
+							err = &ConstraintError{msg: err.Error(), wrap: err}
+						}
+					}
+				}
+				if err != nil {
+					return nil, err
+				}
+				mutation.id = &nodes[i].ID
+				if specs[i].ID.Value != nil && nodes[i].ID == 0 {
+					id := specs[i].ID.Value.(int64)
+					nodes[i].ID = uint64(id)
+				}
+				mutation.done = true
+				return nodes[i], nil
+			})
+			for i := len(builder.hooks) - 1; i >= 0; i-- {
+				mut = builder.hooks[i](mut)
+			}
+			mutators[i] = mut
+		}(i, ctx)
+	}
+	if len(mutators) > 0 {
+		if _, err := mutators[0].Mutate(ctx, aacb.builders[0].mutation); err != nil {
+			return nil, err
+		}
+	}
+	return nodes, nil
+}
+
+// SaveX is like Save, but panics if an error occurs.
+func (aacb *AllocAgentCreateBulk) SaveX(ctx context.Context) []*AllocAgent {
+	v, err := aacb.Save(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return v
+}
+
+// Exec executes the query.
+func (aacb *AllocAgentCreateBulk) Exec(ctx context.Context) error {
+	_, err := aacb.Save(ctx)
+	return err
+}
+
+// ExecX is like Exec, but panics if an error occurs.
+func (aacb *AllocAgentCreateBulk) ExecX(ctx context.Context) {
+	if err := aacb.Exec(ctx); err != nil {
+		panic(err)
+	}
+}
+
+// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
+// of the `INSERT` statement. For example:
+//
+//	client.AllocAgent.CreateBulk(builders...).
+//		OnConflict(
+//			// Update the row with the new values
+//			// the was proposed for insertion.
+//			sql.ResolveWithNewValues(),
+//		).
+//		// Override some of the fields with custom
+//		// update values.
+//		Update(func(u *ent.AllocAgentUpsert) {
+//			SetCreatedAt(v+v).
+//		}).
+//		Exec(ctx)
+func (aacb *AllocAgentCreateBulk) OnConflict(opts ...sql.ConflictOption) *AllocAgentUpsertBulk {
+	aacb.conflict = opts
+	return &AllocAgentUpsertBulk{
+		create: aacb,
+	}
+}
+
+// OnConflictColumns calls `OnConflict` and configures the columns
+// as conflict target. Using this option is equivalent to using:
+//
+//	client.AllocAgent.Create().
+//		OnConflict(sql.ConflictColumns(columns...)).
+//		Exec(ctx)
+func (aacb *AllocAgentCreateBulk) OnConflictColumns(columns ...string) *AllocAgentUpsertBulk {
+	aacb.conflict = append(aacb.conflict, sql.ConflictColumns(columns...))
+	return &AllocAgentUpsertBulk{
+		create: aacb,
+	}
+}
+
+// AllocAgentUpsertBulk is the builder for "upsert"-ing
+// a bulk of AllocAgent nodes.
+type AllocAgentUpsertBulk struct {
+	create *AllocAgentCreateBulk
+}
+
+// UpdateNewValues updates the mutable fields using the new values that
+// were set on create. Using this option is equivalent to using:
+//
+//	client.AllocAgent.Create().
+//		OnConflict(
+//			sql.ResolveWithNewValues(),
+//			sql.ResolveWith(func(u *sql.UpdateSet) {
+//				u.SetIgnore(allocagent.FieldID)
+//			}),
+//		).
+//		Exec(ctx)
+func (u *AllocAgentUpsertBulk) UpdateNewValues() *AllocAgentUpsertBulk {
+	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
+	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
+		for _, b := range u.create.builders {
+			if _, exists := b.mutation.ID(); exists {
+				s.SetIgnore(allocagent.FieldID)
+			}
+			if _, exists := b.mutation.CreatedAt(); exists {
+				s.SetIgnore(allocagent.FieldCreatedAt)
+			}
+		}
+	}))
+	return u
+}
+
+// Ignore sets each column to itself in case of conflict.
+// Using this option is equivalent to using:
+//
+//	client.AllocAgent.Create().
+//		OnConflict(sql.ResolveWithIgnore()).
+//		Exec(ctx)
+func (u *AllocAgentUpsertBulk) Ignore() *AllocAgentUpsertBulk {
+	u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
+	return u
+}
+
+// DoNothing configures the conflict_action to `DO NOTHING`.
+// Supported only by SQLite and PostgreSQL.
+func (u *AllocAgentUpsertBulk) DoNothing() *AllocAgentUpsertBulk {
+	u.create.conflict = append(u.create.conflict, sql.DoNothing())
+	return u
+}
+
+// Update allows overriding fields `UPDATE` values. See the AllocAgentCreateBulk.OnConflict
+// documentation for more info.
+func (u *AllocAgentUpsertBulk) Update(set func(*AllocAgentUpsert)) *AllocAgentUpsertBulk {
+	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
+		set(&AllocAgentUpsert{UpdateSet: update})
+	}))
+	return u
+}
+
+// SetUpdatedAt sets the "updated_at" field.
+func (u *AllocAgentUpsertBulk) SetUpdatedAt(v time.Time) *AllocAgentUpsertBulk {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.SetUpdatedAt(v)
+	})
+}
+
+// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
+func (u *AllocAgentUpsertBulk) UpdateUpdatedAt() *AllocAgentUpsertBulk {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.UpdateUpdatedAt()
+	})
+}
+
+// SetDeletedAt sets the "deleted_at" field.
+func (u *AllocAgentUpsertBulk) SetDeletedAt(v time.Time) *AllocAgentUpsertBulk {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.SetDeletedAt(v)
+	})
+}
+
+// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
+func (u *AllocAgentUpsertBulk) UpdateDeletedAt() *AllocAgentUpsertBulk {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.UpdateDeletedAt()
+	})
+}
+
+// ClearDeletedAt clears the value of the "deleted_at" field.
+func (u *AllocAgentUpsertBulk) ClearDeletedAt() *AllocAgentUpsertBulk {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.ClearDeletedAt()
+	})
+}
+
+// SetUserID sets the "user_id" field.
+func (u *AllocAgentUpsertBulk) SetUserID(v string) *AllocAgentUpsertBulk {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.SetUserID(v)
+	})
+}
+
+// UpdateUserID sets the "user_id" field to the value that was provided on create.
+func (u *AllocAgentUpsertBulk) UpdateUserID() *AllocAgentUpsertBulk {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.UpdateUserID()
+	})
+}
+
+// ClearUserID clears the value of the "user_id" field.
+func (u *AllocAgentUpsertBulk) ClearUserID() *AllocAgentUpsertBulk {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.ClearUserID()
+	})
+}
+
+// SetOrganizationID sets the "organization_id" field.
+func (u *AllocAgentUpsertBulk) SetOrganizationID(v uint64) *AllocAgentUpsertBulk {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.SetOrganizationID(v)
+	})
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *AllocAgentUpsertBulk) AddOrganizationID(v uint64) *AllocAgentUpsertBulk {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.AddOrganizationID(v)
+	})
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *AllocAgentUpsertBulk) UpdateOrganizationID() *AllocAgentUpsertBulk {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.UpdateOrganizationID()
+	})
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (u *AllocAgentUpsertBulk) ClearOrganizationID() *AllocAgentUpsertBulk {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.ClearOrganizationID()
+	})
+}
+
+// SetAgents sets the "agents" field.
+func (u *AllocAgentUpsertBulk) SetAgents(v []uint64) *AllocAgentUpsertBulk {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.SetAgents(v)
+	})
+}
+
+// UpdateAgents sets the "agents" field to the value that was provided on create.
+func (u *AllocAgentUpsertBulk) UpdateAgents() *AllocAgentUpsertBulk {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.UpdateAgents()
+	})
+}
+
+// SetStatus sets the "status" field.
+func (u *AllocAgentUpsertBulk) SetStatus(v int) *AllocAgentUpsertBulk {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.SetStatus(v)
+	})
+}
+
+// AddStatus adds v to the "status" field.
+func (u *AllocAgentUpsertBulk) AddStatus(v int) *AllocAgentUpsertBulk {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.AddStatus(v)
+	})
+}
+
+// UpdateStatus sets the "status" field to the value that was provided on create.
+func (u *AllocAgentUpsertBulk) UpdateStatus() *AllocAgentUpsertBulk {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.UpdateStatus()
+	})
+}
+
+// ClearStatus clears the value of the "status" field.
+func (u *AllocAgentUpsertBulk) ClearStatus() *AllocAgentUpsertBulk {
+	return u.Update(func(s *AllocAgentUpsert) {
+		s.ClearStatus()
+	})
+}
+
+// Exec executes the query.
+func (u *AllocAgentUpsertBulk) Exec(ctx context.Context) error {
+	if u.create.err != nil {
+		return u.create.err
+	}
+	for i, b := range u.create.builders {
+		if len(b.conflict) != 0 {
+			return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the AllocAgentCreateBulk instead", i)
+		}
+	}
+	if len(u.create.conflict) == 0 {
+		return errors.New("ent: missing options for AllocAgentCreateBulk.OnConflict")
+	}
+	return u.create.Exec(ctx)
+}
+
+// ExecX is like Exec, but panics if an error occurs.
+func (u *AllocAgentUpsertBulk) ExecX(ctx context.Context) {
+	if err := u.create.Exec(ctx); err != nil {
+		panic(err)
+	}
+}

+ 88 - 0
ent/allocagent_delete.go

@@ -0,0 +1,88 @@
+// Code generated by ent, DO NOT EDIT.
+
+package ent
+
+import (
+	"context"
+	"wechat-api/ent/allocagent"
+	"wechat-api/ent/predicate"
+
+	"entgo.io/ent/dialect/sql"
+	"entgo.io/ent/dialect/sql/sqlgraph"
+	"entgo.io/ent/schema/field"
+)
+
+// AllocAgentDelete is the builder for deleting a AllocAgent entity.
+type AllocAgentDelete struct {
+	config
+	hooks    []Hook
+	mutation *AllocAgentMutation
+}
+
+// Where appends a list predicates to the AllocAgentDelete builder.
+func (aad *AllocAgentDelete) Where(ps ...predicate.AllocAgent) *AllocAgentDelete {
+	aad.mutation.Where(ps...)
+	return aad
+}
+
+// Exec executes the deletion query and returns how many vertices were deleted.
+func (aad *AllocAgentDelete) Exec(ctx context.Context) (int, error) {
+	return withHooks(ctx, aad.sqlExec, aad.mutation, aad.hooks)
+}
+
+// ExecX is like Exec, but panics if an error occurs.
+func (aad *AllocAgentDelete) ExecX(ctx context.Context) int {
+	n, err := aad.Exec(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return n
+}
+
+func (aad *AllocAgentDelete) sqlExec(ctx context.Context) (int, error) {
+	_spec := sqlgraph.NewDeleteSpec(allocagent.Table, sqlgraph.NewFieldSpec(allocagent.FieldID, field.TypeUint64))
+	if ps := aad.mutation.predicates; len(ps) > 0 {
+		_spec.Predicate = func(selector *sql.Selector) {
+			for i := range ps {
+				ps[i](selector)
+			}
+		}
+	}
+	affected, err := sqlgraph.DeleteNodes(ctx, aad.driver, _spec)
+	if err != nil && sqlgraph.IsConstraintError(err) {
+		err = &ConstraintError{msg: err.Error(), wrap: err}
+	}
+	aad.mutation.done = true
+	return affected, err
+}
+
+// AllocAgentDeleteOne is the builder for deleting a single AllocAgent entity.
+type AllocAgentDeleteOne struct {
+	aad *AllocAgentDelete
+}
+
+// Where appends a list predicates to the AllocAgentDelete builder.
+func (aado *AllocAgentDeleteOne) Where(ps ...predicate.AllocAgent) *AllocAgentDeleteOne {
+	aado.aad.mutation.Where(ps...)
+	return aado
+}
+
+// Exec executes the deletion query.
+func (aado *AllocAgentDeleteOne) Exec(ctx context.Context) error {
+	n, err := aado.aad.Exec(ctx)
+	switch {
+	case err != nil:
+		return err
+	case n == 0:
+		return &NotFoundError{allocagent.Label}
+	default:
+		return nil
+	}
+}
+
+// ExecX is like Exec, but panics if an error occurs.
+func (aado *AllocAgentDeleteOne) ExecX(ctx context.Context) {
+	if err := aado.Exec(ctx); err != nil {
+		panic(err)
+	}
+}

+ 526 - 0
ent/allocagent_query.go

@@ -0,0 +1,526 @@
+// Code generated by ent, DO NOT EDIT.
+
+package ent
+
+import (
+	"context"
+	"fmt"
+	"math"
+	"wechat-api/ent/allocagent"
+	"wechat-api/ent/predicate"
+
+	"entgo.io/ent/dialect/sql"
+	"entgo.io/ent/dialect/sql/sqlgraph"
+	"entgo.io/ent/schema/field"
+)
+
+// AllocAgentQuery is the builder for querying AllocAgent entities.
+type AllocAgentQuery struct {
+	config
+	ctx        *QueryContext
+	order      []allocagent.OrderOption
+	inters     []Interceptor
+	predicates []predicate.AllocAgent
+	// intermediate query (i.e. traversal path).
+	sql  *sql.Selector
+	path func(context.Context) (*sql.Selector, error)
+}
+
+// Where adds a new predicate for the AllocAgentQuery builder.
+func (aaq *AllocAgentQuery) Where(ps ...predicate.AllocAgent) *AllocAgentQuery {
+	aaq.predicates = append(aaq.predicates, ps...)
+	return aaq
+}
+
+// Limit the number of records to be returned by this query.
+func (aaq *AllocAgentQuery) Limit(limit int) *AllocAgentQuery {
+	aaq.ctx.Limit = &limit
+	return aaq
+}
+
+// Offset to start from.
+func (aaq *AllocAgentQuery) Offset(offset int) *AllocAgentQuery {
+	aaq.ctx.Offset = &offset
+	return aaq
+}
+
+// Unique configures the query builder to filter duplicate records on query.
+// By default, unique is set to true, and can be disabled using this method.
+func (aaq *AllocAgentQuery) Unique(unique bool) *AllocAgentQuery {
+	aaq.ctx.Unique = &unique
+	return aaq
+}
+
+// Order specifies how the records should be ordered.
+func (aaq *AllocAgentQuery) Order(o ...allocagent.OrderOption) *AllocAgentQuery {
+	aaq.order = append(aaq.order, o...)
+	return aaq
+}
+
+// First returns the first AllocAgent entity from the query.
+// Returns a *NotFoundError when no AllocAgent was found.
+func (aaq *AllocAgentQuery) First(ctx context.Context) (*AllocAgent, error) {
+	nodes, err := aaq.Limit(1).All(setContextOp(ctx, aaq.ctx, "First"))
+	if err != nil {
+		return nil, err
+	}
+	if len(nodes) == 0 {
+		return nil, &NotFoundError{allocagent.Label}
+	}
+	return nodes[0], nil
+}
+
+// FirstX is like First, but panics if an error occurs.
+func (aaq *AllocAgentQuery) FirstX(ctx context.Context) *AllocAgent {
+	node, err := aaq.First(ctx)
+	if err != nil && !IsNotFound(err) {
+		panic(err)
+	}
+	return node
+}
+
+// FirstID returns the first AllocAgent ID from the query.
+// Returns a *NotFoundError when no AllocAgent ID was found.
+func (aaq *AllocAgentQuery) FirstID(ctx context.Context) (id uint64, err error) {
+	var ids []uint64
+	if ids, err = aaq.Limit(1).IDs(setContextOp(ctx, aaq.ctx, "FirstID")); err != nil {
+		return
+	}
+	if len(ids) == 0 {
+		err = &NotFoundError{allocagent.Label}
+		return
+	}
+	return ids[0], nil
+}
+
+// FirstIDX is like FirstID, but panics if an error occurs.
+func (aaq *AllocAgentQuery) FirstIDX(ctx context.Context) uint64 {
+	id, err := aaq.FirstID(ctx)
+	if err != nil && !IsNotFound(err) {
+		panic(err)
+	}
+	return id
+}
+
+// Only returns a single AllocAgent entity found by the query, ensuring it only returns one.
+// Returns a *NotSingularError when more than one AllocAgent entity is found.
+// Returns a *NotFoundError when no AllocAgent entities are found.
+func (aaq *AllocAgentQuery) Only(ctx context.Context) (*AllocAgent, error) {
+	nodes, err := aaq.Limit(2).All(setContextOp(ctx, aaq.ctx, "Only"))
+	if err != nil {
+		return nil, err
+	}
+	switch len(nodes) {
+	case 1:
+		return nodes[0], nil
+	case 0:
+		return nil, &NotFoundError{allocagent.Label}
+	default:
+		return nil, &NotSingularError{allocagent.Label}
+	}
+}
+
+// OnlyX is like Only, but panics if an error occurs.
+func (aaq *AllocAgentQuery) OnlyX(ctx context.Context) *AllocAgent {
+	node, err := aaq.Only(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return node
+}
+
+// OnlyID is like Only, but returns the only AllocAgent ID in the query.
+// Returns a *NotSingularError when more than one AllocAgent ID is found.
+// Returns a *NotFoundError when no entities are found.
+func (aaq *AllocAgentQuery) OnlyID(ctx context.Context) (id uint64, err error) {
+	var ids []uint64
+	if ids, err = aaq.Limit(2).IDs(setContextOp(ctx, aaq.ctx, "OnlyID")); err != nil {
+		return
+	}
+	switch len(ids) {
+	case 1:
+		id = ids[0]
+	case 0:
+		err = &NotFoundError{allocagent.Label}
+	default:
+		err = &NotSingularError{allocagent.Label}
+	}
+	return
+}
+
+// OnlyIDX is like OnlyID, but panics if an error occurs.
+func (aaq *AllocAgentQuery) OnlyIDX(ctx context.Context) uint64 {
+	id, err := aaq.OnlyID(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return id
+}
+
+// All executes the query and returns a list of AllocAgents.
+func (aaq *AllocAgentQuery) All(ctx context.Context) ([]*AllocAgent, error) {
+	ctx = setContextOp(ctx, aaq.ctx, "All")
+	if err := aaq.prepareQuery(ctx); err != nil {
+		return nil, err
+	}
+	qr := querierAll[[]*AllocAgent, *AllocAgentQuery]()
+	return withInterceptors[[]*AllocAgent](ctx, aaq, qr, aaq.inters)
+}
+
+// AllX is like All, but panics if an error occurs.
+func (aaq *AllocAgentQuery) AllX(ctx context.Context) []*AllocAgent {
+	nodes, err := aaq.All(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return nodes
+}
+
+// IDs executes the query and returns a list of AllocAgent IDs.
+func (aaq *AllocAgentQuery) IDs(ctx context.Context) (ids []uint64, err error) {
+	if aaq.ctx.Unique == nil && aaq.path != nil {
+		aaq.Unique(true)
+	}
+	ctx = setContextOp(ctx, aaq.ctx, "IDs")
+	if err = aaq.Select(allocagent.FieldID).Scan(ctx, &ids); err != nil {
+		return nil, err
+	}
+	return ids, nil
+}
+
+// IDsX is like IDs, but panics if an error occurs.
+func (aaq *AllocAgentQuery) IDsX(ctx context.Context) []uint64 {
+	ids, err := aaq.IDs(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return ids
+}
+
+// Count returns the count of the given query.
+func (aaq *AllocAgentQuery) Count(ctx context.Context) (int, error) {
+	ctx = setContextOp(ctx, aaq.ctx, "Count")
+	if err := aaq.prepareQuery(ctx); err != nil {
+		return 0, err
+	}
+	return withInterceptors[int](ctx, aaq, querierCount[*AllocAgentQuery](), aaq.inters)
+}
+
+// CountX is like Count, but panics if an error occurs.
+func (aaq *AllocAgentQuery) CountX(ctx context.Context) int {
+	count, err := aaq.Count(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return count
+}
+
+// Exist returns true if the query has elements in the graph.
+func (aaq *AllocAgentQuery) Exist(ctx context.Context) (bool, error) {
+	ctx = setContextOp(ctx, aaq.ctx, "Exist")
+	switch _, err := aaq.FirstID(ctx); {
+	case IsNotFound(err):
+		return false, nil
+	case err != nil:
+		return false, fmt.Errorf("ent: check existence: %w", err)
+	default:
+		return true, nil
+	}
+}
+
+// ExistX is like Exist, but panics if an error occurs.
+func (aaq *AllocAgentQuery) ExistX(ctx context.Context) bool {
+	exist, err := aaq.Exist(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return exist
+}
+
+// Clone returns a duplicate of the AllocAgentQuery builder, including all associated steps. It can be
+// used to prepare common query builders and use them differently after the clone is made.
+func (aaq *AllocAgentQuery) Clone() *AllocAgentQuery {
+	if aaq == nil {
+		return nil
+	}
+	return &AllocAgentQuery{
+		config:     aaq.config,
+		ctx:        aaq.ctx.Clone(),
+		order:      append([]allocagent.OrderOption{}, aaq.order...),
+		inters:     append([]Interceptor{}, aaq.inters...),
+		predicates: append([]predicate.AllocAgent{}, aaq.predicates...),
+		// clone intermediate query.
+		sql:  aaq.sql.Clone(),
+		path: aaq.path,
+	}
+}
+
+// GroupBy is used to group vertices by one or more fields/columns.
+// It is often used with aggregate functions, like: count, max, mean, min, sum.
+//
+// Example:
+//
+//	var v []struct {
+//		CreatedAt time.Time `json:"created_at,omitempty"`
+//		Count int `json:"count,omitempty"`
+//	}
+//
+//	client.AllocAgent.Query().
+//		GroupBy(allocagent.FieldCreatedAt).
+//		Aggregate(ent.Count()).
+//		Scan(ctx, &v)
+func (aaq *AllocAgentQuery) GroupBy(field string, fields ...string) *AllocAgentGroupBy {
+	aaq.ctx.Fields = append([]string{field}, fields...)
+	grbuild := &AllocAgentGroupBy{build: aaq}
+	grbuild.flds = &aaq.ctx.Fields
+	grbuild.label = allocagent.Label
+	grbuild.scan = grbuild.Scan
+	return grbuild
+}
+
+// Select allows the selection one or more fields/columns for the given query,
+// instead of selecting all fields in the entity.
+//
+// Example:
+//
+//	var v []struct {
+//		CreatedAt time.Time `json:"created_at,omitempty"`
+//	}
+//
+//	client.AllocAgent.Query().
+//		Select(allocagent.FieldCreatedAt).
+//		Scan(ctx, &v)
+func (aaq *AllocAgentQuery) Select(fields ...string) *AllocAgentSelect {
+	aaq.ctx.Fields = append(aaq.ctx.Fields, fields...)
+	sbuild := &AllocAgentSelect{AllocAgentQuery: aaq}
+	sbuild.label = allocagent.Label
+	sbuild.flds, sbuild.scan = &aaq.ctx.Fields, sbuild.Scan
+	return sbuild
+}
+
+// Aggregate returns a AllocAgentSelect configured with the given aggregations.
+func (aaq *AllocAgentQuery) Aggregate(fns ...AggregateFunc) *AllocAgentSelect {
+	return aaq.Select().Aggregate(fns...)
+}
+
+func (aaq *AllocAgentQuery) prepareQuery(ctx context.Context) error {
+	for _, inter := range aaq.inters {
+		if inter == nil {
+			return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
+		}
+		if trv, ok := inter.(Traverser); ok {
+			if err := trv.Traverse(ctx, aaq); err != nil {
+				return err
+			}
+		}
+	}
+	for _, f := range aaq.ctx.Fields {
+		if !allocagent.ValidColumn(f) {
+			return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
+		}
+	}
+	if aaq.path != nil {
+		prev, err := aaq.path(ctx)
+		if err != nil {
+			return err
+		}
+		aaq.sql = prev
+	}
+	return nil
+}
+
+func (aaq *AllocAgentQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*AllocAgent, error) {
+	var (
+		nodes = []*AllocAgent{}
+		_spec = aaq.querySpec()
+	)
+	_spec.ScanValues = func(columns []string) ([]any, error) {
+		return (*AllocAgent).scanValues(nil, columns)
+	}
+	_spec.Assign = func(columns []string, values []any) error {
+		node := &AllocAgent{config: aaq.config}
+		nodes = append(nodes, node)
+		return node.assignValues(columns, values)
+	}
+	for i := range hooks {
+		hooks[i](ctx, _spec)
+	}
+	if err := sqlgraph.QueryNodes(ctx, aaq.driver, _spec); err != nil {
+		return nil, err
+	}
+	if len(nodes) == 0 {
+		return nodes, nil
+	}
+	return nodes, nil
+}
+
+func (aaq *AllocAgentQuery) sqlCount(ctx context.Context) (int, error) {
+	_spec := aaq.querySpec()
+	_spec.Node.Columns = aaq.ctx.Fields
+	if len(aaq.ctx.Fields) > 0 {
+		_spec.Unique = aaq.ctx.Unique != nil && *aaq.ctx.Unique
+	}
+	return sqlgraph.CountNodes(ctx, aaq.driver, _spec)
+}
+
+func (aaq *AllocAgentQuery) querySpec() *sqlgraph.QuerySpec {
+	_spec := sqlgraph.NewQuerySpec(allocagent.Table, allocagent.Columns, sqlgraph.NewFieldSpec(allocagent.FieldID, field.TypeUint64))
+	_spec.From = aaq.sql
+	if unique := aaq.ctx.Unique; unique != nil {
+		_spec.Unique = *unique
+	} else if aaq.path != nil {
+		_spec.Unique = true
+	}
+	if fields := aaq.ctx.Fields; len(fields) > 0 {
+		_spec.Node.Columns = make([]string, 0, len(fields))
+		_spec.Node.Columns = append(_spec.Node.Columns, allocagent.FieldID)
+		for i := range fields {
+			if fields[i] != allocagent.FieldID {
+				_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
+			}
+		}
+	}
+	if ps := aaq.predicates; len(ps) > 0 {
+		_spec.Predicate = func(selector *sql.Selector) {
+			for i := range ps {
+				ps[i](selector)
+			}
+		}
+	}
+	if limit := aaq.ctx.Limit; limit != nil {
+		_spec.Limit = *limit
+	}
+	if offset := aaq.ctx.Offset; offset != nil {
+		_spec.Offset = *offset
+	}
+	if ps := aaq.order; len(ps) > 0 {
+		_spec.Order = func(selector *sql.Selector) {
+			for i := range ps {
+				ps[i](selector)
+			}
+		}
+	}
+	return _spec
+}
+
+func (aaq *AllocAgentQuery) sqlQuery(ctx context.Context) *sql.Selector {
+	builder := sql.Dialect(aaq.driver.Dialect())
+	t1 := builder.Table(allocagent.Table)
+	columns := aaq.ctx.Fields
+	if len(columns) == 0 {
+		columns = allocagent.Columns
+	}
+	selector := builder.Select(t1.Columns(columns...)...).From(t1)
+	if aaq.sql != nil {
+		selector = aaq.sql
+		selector.Select(selector.Columns(columns...)...)
+	}
+	if aaq.ctx.Unique != nil && *aaq.ctx.Unique {
+		selector.Distinct()
+	}
+	for _, p := range aaq.predicates {
+		p(selector)
+	}
+	for _, p := range aaq.order {
+		p(selector)
+	}
+	if offset := aaq.ctx.Offset; offset != nil {
+		// limit is mandatory for offset clause. We start
+		// with default value, and override it below if needed.
+		selector.Offset(*offset).Limit(math.MaxInt32)
+	}
+	if limit := aaq.ctx.Limit; limit != nil {
+		selector.Limit(*limit)
+	}
+	return selector
+}
+
+// AllocAgentGroupBy is the group-by builder for AllocAgent entities.
+type AllocAgentGroupBy struct {
+	selector
+	build *AllocAgentQuery
+}
+
+// Aggregate adds the given aggregation functions to the group-by query.
+func (aagb *AllocAgentGroupBy) Aggregate(fns ...AggregateFunc) *AllocAgentGroupBy {
+	aagb.fns = append(aagb.fns, fns...)
+	return aagb
+}
+
+// Scan applies the selector query and scans the result into the given value.
+func (aagb *AllocAgentGroupBy) Scan(ctx context.Context, v any) error {
+	ctx = setContextOp(ctx, aagb.build.ctx, "GroupBy")
+	if err := aagb.build.prepareQuery(ctx); err != nil {
+		return err
+	}
+	return scanWithInterceptors[*AllocAgentQuery, *AllocAgentGroupBy](ctx, aagb.build, aagb, aagb.build.inters, v)
+}
+
+func (aagb *AllocAgentGroupBy) sqlScan(ctx context.Context, root *AllocAgentQuery, v any) error {
+	selector := root.sqlQuery(ctx).Select()
+	aggregation := make([]string, 0, len(aagb.fns))
+	for _, fn := range aagb.fns {
+		aggregation = append(aggregation, fn(selector))
+	}
+	if len(selector.SelectedColumns()) == 0 {
+		columns := make([]string, 0, len(*aagb.flds)+len(aagb.fns))
+		for _, f := range *aagb.flds {
+			columns = append(columns, selector.C(f))
+		}
+		columns = append(columns, aggregation...)
+		selector.Select(columns...)
+	}
+	selector.GroupBy(selector.Columns(*aagb.flds...)...)
+	if err := selector.Err(); err != nil {
+		return err
+	}
+	rows := &sql.Rows{}
+	query, args := selector.Query()
+	if err := aagb.build.driver.Query(ctx, query, args, rows); err != nil {
+		return err
+	}
+	defer rows.Close()
+	return sql.ScanSlice(rows, v)
+}
+
+// AllocAgentSelect is the builder for selecting fields of AllocAgent entities.
+type AllocAgentSelect struct {
+	*AllocAgentQuery
+	selector
+}
+
+// Aggregate adds the given aggregation functions to the selector query.
+func (aas *AllocAgentSelect) Aggregate(fns ...AggregateFunc) *AllocAgentSelect {
+	aas.fns = append(aas.fns, fns...)
+	return aas
+}
+
+// Scan applies the selector query and scans the result into the given value.
+func (aas *AllocAgentSelect) Scan(ctx context.Context, v any) error {
+	ctx = setContextOp(ctx, aas.ctx, "Select")
+	if err := aas.prepareQuery(ctx); err != nil {
+		return err
+	}
+	return scanWithInterceptors[*AllocAgentQuery, *AllocAgentSelect](ctx, aas.AllocAgentQuery, aas, aas.inters, v)
+}
+
+func (aas *AllocAgentSelect) sqlScan(ctx context.Context, root *AllocAgentQuery, v any) error {
+	selector := root.sqlQuery(ctx)
+	aggregation := make([]string, 0, len(aas.fns))
+	for _, fn := range aas.fns {
+		aggregation = append(aggregation, fn(selector))
+	}
+	switch n := len(*aas.selector.flds); {
+	case n == 0 && len(aggregation) > 0:
+		selector.Select(aggregation...)
+	case n != 0 && len(aggregation) > 0:
+		selector.AppendSelect(aggregation...)
+	}
+	rows := &sql.Rows{}
+	query, args := selector.Query()
+	if err := aas.driver.Query(ctx, query, args, rows); err != nil {
+		return err
+	}
+	defer rows.Close()
+	return sql.ScanSlice(rows, v)
+}

+ 539 - 0
ent/allocagent_update.go

@@ -0,0 +1,539 @@
+// Code generated by ent, DO NOT EDIT.
+
+package ent
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	"time"
+	"wechat-api/ent/allocagent"
+	"wechat-api/ent/predicate"
+
+	"entgo.io/ent/dialect/sql"
+	"entgo.io/ent/dialect/sql/sqlgraph"
+	"entgo.io/ent/dialect/sql/sqljson"
+	"entgo.io/ent/schema/field"
+)
+
+// AllocAgentUpdate is the builder for updating AllocAgent entities.
+type AllocAgentUpdate struct {
+	config
+	hooks    []Hook
+	mutation *AllocAgentMutation
+}
+
+// Where appends a list predicates to the AllocAgentUpdate builder.
+func (aau *AllocAgentUpdate) Where(ps ...predicate.AllocAgent) *AllocAgentUpdate {
+	aau.mutation.Where(ps...)
+	return aau
+}
+
+// SetUpdatedAt sets the "updated_at" field.
+func (aau *AllocAgentUpdate) SetUpdatedAt(t time.Time) *AllocAgentUpdate {
+	aau.mutation.SetUpdatedAt(t)
+	return aau
+}
+
+// SetDeletedAt sets the "deleted_at" field.
+func (aau *AllocAgentUpdate) SetDeletedAt(t time.Time) *AllocAgentUpdate {
+	aau.mutation.SetDeletedAt(t)
+	return aau
+}
+
+// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
+func (aau *AllocAgentUpdate) SetNillableDeletedAt(t *time.Time) *AllocAgentUpdate {
+	if t != nil {
+		aau.SetDeletedAt(*t)
+	}
+	return aau
+}
+
+// ClearDeletedAt clears the value of the "deleted_at" field.
+func (aau *AllocAgentUpdate) ClearDeletedAt() *AllocAgentUpdate {
+	aau.mutation.ClearDeletedAt()
+	return aau
+}
+
+// SetUserID sets the "user_id" field.
+func (aau *AllocAgentUpdate) SetUserID(s string) *AllocAgentUpdate {
+	aau.mutation.SetUserID(s)
+	return aau
+}
+
+// SetNillableUserID sets the "user_id" field if the given value is not nil.
+func (aau *AllocAgentUpdate) SetNillableUserID(s *string) *AllocAgentUpdate {
+	if s != nil {
+		aau.SetUserID(*s)
+	}
+	return aau
+}
+
+// ClearUserID clears the value of the "user_id" field.
+func (aau *AllocAgentUpdate) ClearUserID() *AllocAgentUpdate {
+	aau.mutation.ClearUserID()
+	return aau
+}
+
+// SetOrganizationID sets the "organization_id" field.
+func (aau *AllocAgentUpdate) SetOrganizationID(u uint64) *AllocAgentUpdate {
+	aau.mutation.ResetOrganizationID()
+	aau.mutation.SetOrganizationID(u)
+	return aau
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (aau *AllocAgentUpdate) SetNillableOrganizationID(u *uint64) *AllocAgentUpdate {
+	if u != nil {
+		aau.SetOrganizationID(*u)
+	}
+	return aau
+}
+
+// AddOrganizationID adds u to the "organization_id" field.
+func (aau *AllocAgentUpdate) AddOrganizationID(u int64) *AllocAgentUpdate {
+	aau.mutation.AddOrganizationID(u)
+	return aau
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (aau *AllocAgentUpdate) ClearOrganizationID() *AllocAgentUpdate {
+	aau.mutation.ClearOrganizationID()
+	return aau
+}
+
+// SetAgents sets the "agents" field.
+func (aau *AllocAgentUpdate) SetAgents(u []uint64) *AllocAgentUpdate {
+	aau.mutation.SetAgents(u)
+	return aau
+}
+
+// AppendAgents appends u to the "agents" field.
+func (aau *AllocAgentUpdate) AppendAgents(u []uint64) *AllocAgentUpdate {
+	aau.mutation.AppendAgents(u)
+	return aau
+}
+
+// SetStatus sets the "status" field.
+func (aau *AllocAgentUpdate) SetStatus(i int) *AllocAgentUpdate {
+	aau.mutation.ResetStatus()
+	aau.mutation.SetStatus(i)
+	return aau
+}
+
+// SetNillableStatus sets the "status" field if the given value is not nil.
+func (aau *AllocAgentUpdate) SetNillableStatus(i *int) *AllocAgentUpdate {
+	if i != nil {
+		aau.SetStatus(*i)
+	}
+	return aau
+}
+
+// AddStatus adds i to the "status" field.
+func (aau *AllocAgentUpdate) AddStatus(i int) *AllocAgentUpdate {
+	aau.mutation.AddStatus(i)
+	return aau
+}
+
+// ClearStatus clears the value of the "status" field.
+func (aau *AllocAgentUpdate) ClearStatus() *AllocAgentUpdate {
+	aau.mutation.ClearStatus()
+	return aau
+}
+
+// Mutation returns the AllocAgentMutation object of the builder.
+func (aau *AllocAgentUpdate) Mutation() *AllocAgentMutation {
+	return aau.mutation
+}
+
+// Save executes the query and returns the number of nodes affected by the update operation.
+func (aau *AllocAgentUpdate) Save(ctx context.Context) (int, error) {
+	if err := aau.defaults(); err != nil {
+		return 0, err
+	}
+	return withHooks(ctx, aau.sqlSave, aau.mutation, aau.hooks)
+}
+
+// SaveX is like Save, but panics if an error occurs.
+func (aau *AllocAgentUpdate) SaveX(ctx context.Context) int {
+	affected, err := aau.Save(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return affected
+}
+
+// Exec executes the query.
+func (aau *AllocAgentUpdate) Exec(ctx context.Context) error {
+	_, err := aau.Save(ctx)
+	return err
+}
+
+// ExecX is like Exec, but panics if an error occurs.
+func (aau *AllocAgentUpdate) ExecX(ctx context.Context) {
+	if err := aau.Exec(ctx); err != nil {
+		panic(err)
+	}
+}
+
+// defaults sets the default values of the builder before save.
+func (aau *AllocAgentUpdate) defaults() error {
+	if _, ok := aau.mutation.UpdatedAt(); !ok {
+		if allocagent.UpdateDefaultUpdatedAt == nil {
+			return fmt.Errorf("ent: uninitialized allocagent.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
+		}
+		v := allocagent.UpdateDefaultUpdatedAt()
+		aau.mutation.SetUpdatedAt(v)
+	}
+	return nil
+}
+
+// check runs all checks and user-defined validators on the builder.
+func (aau *AllocAgentUpdate) check() error {
+	if v, ok := aau.mutation.Status(); ok {
+		if err := allocagent.StatusValidator(v); err != nil {
+			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "AllocAgent.status": %w`, err)}
+		}
+	}
+	return nil
+}
+
+func (aau *AllocAgentUpdate) sqlSave(ctx context.Context) (n int, err error) {
+	if err := aau.check(); err != nil {
+		return n, err
+	}
+	_spec := sqlgraph.NewUpdateSpec(allocagent.Table, allocagent.Columns, sqlgraph.NewFieldSpec(allocagent.FieldID, field.TypeUint64))
+	if ps := aau.mutation.predicates; len(ps) > 0 {
+		_spec.Predicate = func(selector *sql.Selector) {
+			for i := range ps {
+				ps[i](selector)
+			}
+		}
+	}
+	if value, ok := aau.mutation.UpdatedAt(); ok {
+		_spec.SetField(allocagent.FieldUpdatedAt, field.TypeTime, value)
+	}
+	if value, ok := aau.mutation.DeletedAt(); ok {
+		_spec.SetField(allocagent.FieldDeletedAt, field.TypeTime, value)
+	}
+	if aau.mutation.DeletedAtCleared() {
+		_spec.ClearField(allocagent.FieldDeletedAt, field.TypeTime)
+	}
+	if value, ok := aau.mutation.UserID(); ok {
+		_spec.SetField(allocagent.FieldUserID, field.TypeString, value)
+	}
+	if aau.mutation.UserIDCleared() {
+		_spec.ClearField(allocagent.FieldUserID, field.TypeString)
+	}
+	if value, ok := aau.mutation.OrganizationID(); ok {
+		_spec.SetField(allocagent.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if value, ok := aau.mutation.AddedOrganizationID(); ok {
+		_spec.AddField(allocagent.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if aau.mutation.OrganizationIDCleared() {
+		_spec.ClearField(allocagent.FieldOrganizationID, field.TypeUint64)
+	}
+	if value, ok := aau.mutation.Agents(); ok {
+		_spec.SetField(allocagent.FieldAgents, field.TypeJSON, value)
+	}
+	if value, ok := aau.mutation.AppendedAgents(); ok {
+		_spec.AddModifier(func(u *sql.UpdateBuilder) {
+			sqljson.Append(u, allocagent.FieldAgents, value)
+		})
+	}
+	if value, ok := aau.mutation.Status(); ok {
+		_spec.SetField(allocagent.FieldStatus, field.TypeInt, value)
+	}
+	if value, ok := aau.mutation.AddedStatus(); ok {
+		_spec.AddField(allocagent.FieldStatus, field.TypeInt, value)
+	}
+	if aau.mutation.StatusCleared() {
+		_spec.ClearField(allocagent.FieldStatus, field.TypeInt)
+	}
+	if n, err = sqlgraph.UpdateNodes(ctx, aau.driver, _spec); err != nil {
+		if _, ok := err.(*sqlgraph.NotFoundError); ok {
+			err = &NotFoundError{allocagent.Label}
+		} else if sqlgraph.IsConstraintError(err) {
+			err = &ConstraintError{msg: err.Error(), wrap: err}
+		}
+		return 0, err
+	}
+	aau.mutation.done = true
+	return n, nil
+}
+
+// AllocAgentUpdateOne is the builder for updating a single AllocAgent entity.
+type AllocAgentUpdateOne struct {
+	config
+	fields   []string
+	hooks    []Hook
+	mutation *AllocAgentMutation
+}
+
+// SetUpdatedAt sets the "updated_at" field.
+func (aauo *AllocAgentUpdateOne) SetUpdatedAt(t time.Time) *AllocAgentUpdateOne {
+	aauo.mutation.SetUpdatedAt(t)
+	return aauo
+}
+
+// SetDeletedAt sets the "deleted_at" field.
+func (aauo *AllocAgentUpdateOne) SetDeletedAt(t time.Time) *AllocAgentUpdateOne {
+	aauo.mutation.SetDeletedAt(t)
+	return aauo
+}
+
+// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
+func (aauo *AllocAgentUpdateOne) SetNillableDeletedAt(t *time.Time) *AllocAgentUpdateOne {
+	if t != nil {
+		aauo.SetDeletedAt(*t)
+	}
+	return aauo
+}
+
+// ClearDeletedAt clears the value of the "deleted_at" field.
+func (aauo *AllocAgentUpdateOne) ClearDeletedAt() *AllocAgentUpdateOne {
+	aauo.mutation.ClearDeletedAt()
+	return aauo
+}
+
+// SetUserID sets the "user_id" field.
+func (aauo *AllocAgentUpdateOne) SetUserID(s string) *AllocAgentUpdateOne {
+	aauo.mutation.SetUserID(s)
+	return aauo
+}
+
+// SetNillableUserID sets the "user_id" field if the given value is not nil.
+func (aauo *AllocAgentUpdateOne) SetNillableUserID(s *string) *AllocAgentUpdateOne {
+	if s != nil {
+		aauo.SetUserID(*s)
+	}
+	return aauo
+}
+
+// ClearUserID clears the value of the "user_id" field.
+func (aauo *AllocAgentUpdateOne) ClearUserID() *AllocAgentUpdateOne {
+	aauo.mutation.ClearUserID()
+	return aauo
+}
+
+// SetOrganizationID sets the "organization_id" field.
+func (aauo *AllocAgentUpdateOne) SetOrganizationID(u uint64) *AllocAgentUpdateOne {
+	aauo.mutation.ResetOrganizationID()
+	aauo.mutation.SetOrganizationID(u)
+	return aauo
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (aauo *AllocAgentUpdateOne) SetNillableOrganizationID(u *uint64) *AllocAgentUpdateOne {
+	if u != nil {
+		aauo.SetOrganizationID(*u)
+	}
+	return aauo
+}
+
+// AddOrganizationID adds u to the "organization_id" field.
+func (aauo *AllocAgentUpdateOne) AddOrganizationID(u int64) *AllocAgentUpdateOne {
+	aauo.mutation.AddOrganizationID(u)
+	return aauo
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (aauo *AllocAgentUpdateOne) ClearOrganizationID() *AllocAgentUpdateOne {
+	aauo.mutation.ClearOrganizationID()
+	return aauo
+}
+
+// SetAgents sets the "agents" field.
+func (aauo *AllocAgentUpdateOne) SetAgents(u []uint64) *AllocAgentUpdateOne {
+	aauo.mutation.SetAgents(u)
+	return aauo
+}
+
+// AppendAgents appends u to the "agents" field.
+func (aauo *AllocAgentUpdateOne) AppendAgents(u []uint64) *AllocAgentUpdateOne {
+	aauo.mutation.AppendAgents(u)
+	return aauo
+}
+
+// SetStatus sets the "status" field.
+func (aauo *AllocAgentUpdateOne) SetStatus(i int) *AllocAgentUpdateOne {
+	aauo.mutation.ResetStatus()
+	aauo.mutation.SetStatus(i)
+	return aauo
+}
+
+// SetNillableStatus sets the "status" field if the given value is not nil.
+func (aauo *AllocAgentUpdateOne) SetNillableStatus(i *int) *AllocAgentUpdateOne {
+	if i != nil {
+		aauo.SetStatus(*i)
+	}
+	return aauo
+}
+
+// AddStatus adds i to the "status" field.
+func (aauo *AllocAgentUpdateOne) AddStatus(i int) *AllocAgentUpdateOne {
+	aauo.mutation.AddStatus(i)
+	return aauo
+}
+
+// ClearStatus clears the value of the "status" field.
+func (aauo *AllocAgentUpdateOne) ClearStatus() *AllocAgentUpdateOne {
+	aauo.mutation.ClearStatus()
+	return aauo
+}
+
+// Mutation returns the AllocAgentMutation object of the builder.
+func (aauo *AllocAgentUpdateOne) Mutation() *AllocAgentMutation {
+	return aauo.mutation
+}
+
+// Where appends a list predicates to the AllocAgentUpdate builder.
+func (aauo *AllocAgentUpdateOne) Where(ps ...predicate.AllocAgent) *AllocAgentUpdateOne {
+	aauo.mutation.Where(ps...)
+	return aauo
+}
+
+// Select allows selecting one or more fields (columns) of the returned entity.
+// The default is selecting all fields defined in the entity schema.
+func (aauo *AllocAgentUpdateOne) Select(field string, fields ...string) *AllocAgentUpdateOne {
+	aauo.fields = append([]string{field}, fields...)
+	return aauo
+}
+
+// Save executes the query and returns the updated AllocAgent entity.
+func (aauo *AllocAgentUpdateOne) Save(ctx context.Context) (*AllocAgent, error) {
+	if err := aauo.defaults(); err != nil {
+		return nil, err
+	}
+	return withHooks(ctx, aauo.sqlSave, aauo.mutation, aauo.hooks)
+}
+
+// SaveX is like Save, but panics if an error occurs.
+func (aauo *AllocAgentUpdateOne) SaveX(ctx context.Context) *AllocAgent {
+	node, err := aauo.Save(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return node
+}
+
+// Exec executes the query on the entity.
+func (aauo *AllocAgentUpdateOne) Exec(ctx context.Context) error {
+	_, err := aauo.Save(ctx)
+	return err
+}
+
+// ExecX is like Exec, but panics if an error occurs.
+func (aauo *AllocAgentUpdateOne) ExecX(ctx context.Context) {
+	if err := aauo.Exec(ctx); err != nil {
+		panic(err)
+	}
+}
+
+// defaults sets the default values of the builder before save.
+func (aauo *AllocAgentUpdateOne) defaults() error {
+	if _, ok := aauo.mutation.UpdatedAt(); !ok {
+		if allocagent.UpdateDefaultUpdatedAt == nil {
+			return fmt.Errorf("ent: uninitialized allocagent.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
+		}
+		v := allocagent.UpdateDefaultUpdatedAt()
+		aauo.mutation.SetUpdatedAt(v)
+	}
+	return nil
+}
+
+// check runs all checks and user-defined validators on the builder.
+func (aauo *AllocAgentUpdateOne) check() error {
+	if v, ok := aauo.mutation.Status(); ok {
+		if err := allocagent.StatusValidator(v); err != nil {
+			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "AllocAgent.status": %w`, err)}
+		}
+	}
+	return nil
+}
+
+func (aauo *AllocAgentUpdateOne) sqlSave(ctx context.Context) (_node *AllocAgent, err error) {
+	if err := aauo.check(); err != nil {
+		return _node, err
+	}
+	_spec := sqlgraph.NewUpdateSpec(allocagent.Table, allocagent.Columns, sqlgraph.NewFieldSpec(allocagent.FieldID, field.TypeUint64))
+	id, ok := aauo.mutation.ID()
+	if !ok {
+		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AllocAgent.id" for update`)}
+	}
+	_spec.Node.ID.Value = id
+	if fields := aauo.fields; len(fields) > 0 {
+		_spec.Node.Columns = make([]string, 0, len(fields))
+		_spec.Node.Columns = append(_spec.Node.Columns, allocagent.FieldID)
+		for _, f := range fields {
+			if !allocagent.ValidColumn(f) {
+				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
+			}
+			if f != allocagent.FieldID {
+				_spec.Node.Columns = append(_spec.Node.Columns, f)
+			}
+		}
+	}
+	if ps := aauo.mutation.predicates; len(ps) > 0 {
+		_spec.Predicate = func(selector *sql.Selector) {
+			for i := range ps {
+				ps[i](selector)
+			}
+		}
+	}
+	if value, ok := aauo.mutation.UpdatedAt(); ok {
+		_spec.SetField(allocagent.FieldUpdatedAt, field.TypeTime, value)
+	}
+	if value, ok := aauo.mutation.DeletedAt(); ok {
+		_spec.SetField(allocagent.FieldDeletedAt, field.TypeTime, value)
+	}
+	if aauo.mutation.DeletedAtCleared() {
+		_spec.ClearField(allocagent.FieldDeletedAt, field.TypeTime)
+	}
+	if value, ok := aauo.mutation.UserID(); ok {
+		_spec.SetField(allocagent.FieldUserID, field.TypeString, value)
+	}
+	if aauo.mutation.UserIDCleared() {
+		_spec.ClearField(allocagent.FieldUserID, field.TypeString)
+	}
+	if value, ok := aauo.mutation.OrganizationID(); ok {
+		_spec.SetField(allocagent.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if value, ok := aauo.mutation.AddedOrganizationID(); ok {
+		_spec.AddField(allocagent.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if aauo.mutation.OrganizationIDCleared() {
+		_spec.ClearField(allocagent.FieldOrganizationID, field.TypeUint64)
+	}
+	if value, ok := aauo.mutation.Agents(); ok {
+		_spec.SetField(allocagent.FieldAgents, field.TypeJSON, value)
+	}
+	if value, ok := aauo.mutation.AppendedAgents(); ok {
+		_spec.AddModifier(func(u *sql.UpdateBuilder) {
+			sqljson.Append(u, allocagent.FieldAgents, value)
+		})
+	}
+	if value, ok := aauo.mutation.Status(); ok {
+		_spec.SetField(allocagent.FieldStatus, field.TypeInt, value)
+	}
+	if value, ok := aauo.mutation.AddedStatus(); ok {
+		_spec.AddField(allocagent.FieldStatus, field.TypeInt, value)
+	}
+	if aauo.mutation.StatusCleared() {
+		_spec.ClearField(allocagent.FieldStatus, field.TypeInt)
+	}
+	_node = &AllocAgent{config: aauo.config}
+	_spec.Assign = _node.assignValues
+	_spec.ScanValues = _node.scanValues
+	if err = sqlgraph.UpdateNode(ctx, aauo.driver, _spec); err != nil {
+		if _, ok := err.(*sqlgraph.NotFoundError); ok {
+			err = &NotFoundError{allocagent.Label}
+		} else if sqlgraph.IsConstraintError(err) {
+			err = &ConstraintError{msg: err.Error(), wrap: err}
+		}
+		return nil, err
+	}
+	aauo.mutation.done = true
+	return _node, nil
+}

+ 157 - 14
ent/client.go

@@ -14,6 +14,7 @@ import (
 	"wechat-api/ent/agent"
 	"wechat-api/ent/agentbase"
 	"wechat-api/ent/aliyunavatar"
+	"wechat-api/ent/allocagent"
 	"wechat-api/ent/batchmsg"
 	"wechat-api/ent/category"
 	"wechat-api/ent/chatrecords"
@@ -61,6 +62,8 @@ type Client struct {
 	AgentBase *AgentBaseClient
 	// AliyunAvatar is the client for interacting with the AliyunAvatar builders.
 	AliyunAvatar *AliyunAvatarClient
+	// AllocAgent is the client for interacting with the AllocAgent builders.
+	AllocAgent *AllocAgentClient
 	// BatchMsg is the client for interacting with the BatchMsg builders.
 	BatchMsg *BatchMsgClient
 	// Category is the client for interacting with the Category builders.
@@ -129,6 +132,7 @@ func (c *Client) init() {
 	c.Agent = NewAgentClient(c.config)
 	c.AgentBase = NewAgentBaseClient(c.config)
 	c.AliyunAvatar = NewAliyunAvatarClient(c.config)
+	c.AllocAgent = NewAllocAgentClient(c.config)
 	c.BatchMsg = NewBatchMsgClient(c.config)
 	c.Category = NewCategoryClient(c.config)
 	c.ChatRecords = NewChatRecordsClient(c.config)
@@ -251,6 +255,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
 		Agent:             NewAgentClient(cfg),
 		AgentBase:         NewAgentBaseClient(cfg),
 		AliyunAvatar:      NewAliyunAvatarClient(cfg),
+		AllocAgent:        NewAllocAgentClient(cfg),
 		BatchMsg:          NewBatchMsgClient(cfg),
 		Category:          NewCategoryClient(cfg),
 		ChatRecords:       NewChatRecordsClient(cfg),
@@ -300,6 +305,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
 		Agent:             NewAgentClient(cfg),
 		AgentBase:         NewAgentBaseClient(cfg),
 		AliyunAvatar:      NewAliyunAvatarClient(cfg),
+		AllocAgent:        NewAllocAgentClient(cfg),
 		BatchMsg:          NewBatchMsgClient(cfg),
 		Category:          NewCategoryClient(cfg),
 		ChatRecords:       NewChatRecordsClient(cfg),
@@ -356,8 +362,8 @@ func (c *Client) Close() error {
 // In order to add hooks to a specific client, call: `client.Node.Use(...)`.
 func (c *Client) Use(hooks ...Hook) {
 	for _, n := range []interface{ Use(...Hook) }{
-		c.Agent, c.AgentBase, c.AliyunAvatar, c.BatchMsg, c.Category, c.ChatRecords,
-		c.ChatSession, c.Contact, c.Employee, c.EmployeeConfig, c.Label,
+		c.Agent, c.AgentBase, c.AliyunAvatar, c.AllocAgent, c.BatchMsg, c.Category,
+		c.ChatRecords, c.ChatSession, c.Contact, c.Employee, c.EmployeeConfig, c.Label,
 		c.LabelRelationship, c.Message, c.MessageRecords, c.Msg, c.Server, c.SopNode,
 		c.SopStage, c.SopTask, c.Token, c.Tutorial, c.UsageDetail, c.UsageTotal,
 		c.WorkExperience, c.WpChatroom, c.WpChatroomMember, c.Wx, c.WxCard,
@@ -371,8 +377,8 @@ func (c *Client) Use(hooks ...Hook) {
 // In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
 func (c *Client) Intercept(interceptors ...Interceptor) {
 	for _, n := range []interface{ Intercept(...Interceptor) }{
-		c.Agent, c.AgentBase, c.AliyunAvatar, c.BatchMsg, c.Category, c.ChatRecords,
-		c.ChatSession, c.Contact, c.Employee, c.EmployeeConfig, c.Label,
+		c.Agent, c.AgentBase, c.AliyunAvatar, c.AllocAgent, c.BatchMsg, c.Category,
+		c.ChatRecords, c.ChatSession, c.Contact, c.Employee, c.EmployeeConfig, c.Label,
 		c.LabelRelationship, c.Message, c.MessageRecords, c.Msg, c.Server, c.SopNode,
 		c.SopStage, c.SopTask, c.Token, c.Tutorial, c.UsageDetail, c.UsageTotal,
 		c.WorkExperience, c.WpChatroom, c.WpChatroomMember, c.Wx, c.WxCard,
@@ -391,6 +397,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
 		return c.AgentBase.mutate(ctx, m)
 	case *AliyunAvatarMutation:
 		return c.AliyunAvatar.mutate(ctx, m)
+	case *AllocAgentMutation:
+		return c.AllocAgent.mutate(ctx, m)
 	case *BatchMsgMutation:
 		return c.BatchMsg.mutate(ctx, m)
 	case *CategoryMutation:
@@ -901,6 +909,141 @@ func (c *AliyunAvatarClient) mutate(ctx context.Context, m *AliyunAvatarMutation
 	}
 }
 
+// AllocAgentClient is a client for the AllocAgent schema.
+type AllocAgentClient struct {
+	config
+}
+
+// NewAllocAgentClient returns a client for the AllocAgent from the given config.
+func NewAllocAgentClient(c config) *AllocAgentClient {
+	return &AllocAgentClient{config: c}
+}
+
+// Use adds a list of mutation hooks to the hooks stack.
+// A call to `Use(f, g, h)` equals to `allocagent.Hooks(f(g(h())))`.
+func (c *AllocAgentClient) Use(hooks ...Hook) {
+	c.hooks.AllocAgent = append(c.hooks.AllocAgent, hooks...)
+}
+
+// Intercept adds a list of query interceptors to the interceptors stack.
+// A call to `Intercept(f, g, h)` equals to `allocagent.Intercept(f(g(h())))`.
+func (c *AllocAgentClient) Intercept(interceptors ...Interceptor) {
+	c.inters.AllocAgent = append(c.inters.AllocAgent, interceptors...)
+}
+
+// Create returns a builder for creating a AllocAgent entity.
+func (c *AllocAgentClient) Create() *AllocAgentCreate {
+	mutation := newAllocAgentMutation(c.config, OpCreate)
+	return &AllocAgentCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
+}
+
+// CreateBulk returns a builder for creating a bulk of AllocAgent entities.
+func (c *AllocAgentClient) CreateBulk(builders ...*AllocAgentCreate) *AllocAgentCreateBulk {
+	return &AllocAgentCreateBulk{config: c.config, builders: builders}
+}
+
+// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
+// a builder and applies setFunc on it.
+func (c *AllocAgentClient) MapCreateBulk(slice any, setFunc func(*AllocAgentCreate, int)) *AllocAgentCreateBulk {
+	rv := reflect.ValueOf(slice)
+	if rv.Kind() != reflect.Slice {
+		return &AllocAgentCreateBulk{err: fmt.Errorf("calling to AllocAgentClient.MapCreateBulk with wrong type %T, need slice", slice)}
+	}
+	builders := make([]*AllocAgentCreate, rv.Len())
+	for i := 0; i < rv.Len(); i++ {
+		builders[i] = c.Create()
+		setFunc(builders[i], i)
+	}
+	return &AllocAgentCreateBulk{config: c.config, builders: builders}
+}
+
+// Update returns an update builder for AllocAgent.
+func (c *AllocAgentClient) Update() *AllocAgentUpdate {
+	mutation := newAllocAgentMutation(c.config, OpUpdate)
+	return &AllocAgentUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
+}
+
+// UpdateOne returns an update builder for the given entity.
+func (c *AllocAgentClient) UpdateOne(aa *AllocAgent) *AllocAgentUpdateOne {
+	mutation := newAllocAgentMutation(c.config, OpUpdateOne, withAllocAgent(aa))
+	return &AllocAgentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
+}
+
+// UpdateOneID returns an update builder for the given id.
+func (c *AllocAgentClient) UpdateOneID(id uint64) *AllocAgentUpdateOne {
+	mutation := newAllocAgentMutation(c.config, OpUpdateOne, withAllocAgentID(id))
+	return &AllocAgentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
+}
+
+// Delete returns a delete builder for AllocAgent.
+func (c *AllocAgentClient) Delete() *AllocAgentDelete {
+	mutation := newAllocAgentMutation(c.config, OpDelete)
+	return &AllocAgentDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
+}
+
+// DeleteOne returns a builder for deleting the given entity.
+func (c *AllocAgentClient) DeleteOne(aa *AllocAgent) *AllocAgentDeleteOne {
+	return c.DeleteOneID(aa.ID)
+}
+
+// DeleteOneID returns a builder for deleting the given entity by its id.
+func (c *AllocAgentClient) DeleteOneID(id uint64) *AllocAgentDeleteOne {
+	builder := c.Delete().Where(allocagent.ID(id))
+	builder.mutation.id = &id
+	builder.mutation.op = OpDeleteOne
+	return &AllocAgentDeleteOne{builder}
+}
+
+// Query returns a query builder for AllocAgent.
+func (c *AllocAgentClient) Query() *AllocAgentQuery {
+	return &AllocAgentQuery{
+		config: c.config,
+		ctx:    &QueryContext{Type: TypeAllocAgent},
+		inters: c.Interceptors(),
+	}
+}
+
+// Get returns a AllocAgent entity by its id.
+func (c *AllocAgentClient) Get(ctx context.Context, id uint64) (*AllocAgent, error) {
+	return c.Query().Where(allocagent.ID(id)).Only(ctx)
+}
+
+// GetX is like Get, but panics if an error occurs.
+func (c *AllocAgentClient) GetX(ctx context.Context, id uint64) *AllocAgent {
+	obj, err := c.Get(ctx, id)
+	if err != nil {
+		panic(err)
+	}
+	return obj
+}
+
+// Hooks returns the client hooks.
+func (c *AllocAgentClient) Hooks() []Hook {
+	hooks := c.hooks.AllocAgent
+	return append(hooks[:len(hooks):len(hooks)], allocagent.Hooks[:]...)
+}
+
+// Interceptors returns the client interceptors.
+func (c *AllocAgentClient) Interceptors() []Interceptor {
+	inters := c.inters.AllocAgent
+	return append(inters[:len(inters):len(inters)], allocagent.Interceptors[:]...)
+}
+
+func (c *AllocAgentClient) mutate(ctx context.Context, m *AllocAgentMutation) (Value, error) {
+	switch m.Op() {
+	case OpCreate:
+		return (&AllocAgentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
+	case OpUpdate:
+		return (&AllocAgentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
+	case OpUpdateOne:
+		return (&AllocAgentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
+	case OpDelete, OpDeleteOne:
+		return (&AllocAgentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
+	default:
+		return nil, fmt.Errorf("ent: unknown AllocAgent mutation op: %q", m.Op())
+	}
+}
+
 // BatchMsgClient is a client for the BatchMsg schema.
 type BatchMsgClient struct {
 	config
@@ -4887,18 +5030,18 @@ func (c *WxCardVisitClient) mutate(ctx context.Context, m *WxCardVisitMutation)
 // hooks and interceptors per client, for fast access.
 type (
 	hooks struct {
-		Agent, AgentBase, AliyunAvatar, BatchMsg, Category, ChatRecords, ChatSession,
-		Contact, Employee, EmployeeConfig, Label, LabelRelationship, Message,
-		MessageRecords, Msg, Server, SopNode, SopStage, SopTask, Token, Tutorial,
-		UsageDetail, UsageTotal, WorkExperience, WpChatroom, WpChatroomMember, Wx,
-		WxCard, WxCardUser, WxCardVisit []ent.Hook
+		Agent, AgentBase, AliyunAvatar, AllocAgent, BatchMsg, Category, ChatRecords,
+		ChatSession, Contact, Employee, EmployeeConfig, Label, LabelRelationship,
+		Message, MessageRecords, Msg, Server, SopNode, SopStage, SopTask, Token,
+		Tutorial, UsageDetail, UsageTotal, WorkExperience, WpChatroom,
+		WpChatroomMember, Wx, WxCard, WxCardUser, WxCardVisit []ent.Hook
 	}
 	inters struct {
-		Agent, AgentBase, AliyunAvatar, BatchMsg, Category, ChatRecords, ChatSession,
-		Contact, Employee, EmployeeConfig, Label, LabelRelationship, Message,
-		MessageRecords, Msg, Server, SopNode, SopStage, SopTask, Token, Tutorial,
-		UsageDetail, UsageTotal, WorkExperience, WpChatroom, WpChatroomMember, Wx,
-		WxCard, WxCardUser, WxCardVisit []ent.Interceptor
+		Agent, AgentBase, AliyunAvatar, AllocAgent, BatchMsg, Category, ChatRecords,
+		ChatSession, Contact, Employee, EmployeeConfig, Label, LabelRelationship,
+		Message, MessageRecords, Msg, Server, SopNode, SopStage, SopTask, Token,
+		Tutorial, UsageDetail, UsageTotal, WorkExperience, WpChatroom,
+		WpChatroomMember, Wx, WxCard, WxCardUser, WxCardVisit []ent.Interceptor
 	}
 )
 

+ 2 - 0
ent/ent.go

@@ -11,6 +11,7 @@ import (
 	"wechat-api/ent/agent"
 	"wechat-api/ent/agentbase"
 	"wechat-api/ent/aliyunavatar"
+	"wechat-api/ent/allocagent"
 	"wechat-api/ent/batchmsg"
 	"wechat-api/ent/category"
 	"wechat-api/ent/chatrecords"
@@ -105,6 +106,7 @@ func checkColumn(table, column string) error {
 			agent.Table:             agent.ValidColumn,
 			agentbase.Table:         agentbase.ValidColumn,
 			aliyunavatar.Table:      aliyunavatar.ValidColumn,
+			allocagent.Table:        allocagent.ValidColumn,
 			batchmsg.Table:          batchmsg.ValidColumn,
 			category.Table:          category.ValidColumn,
 			chatrecords.Table:       chatrecords.ValidColumn,

+ 12 - 0
ent/hook/hook.go

@@ -44,6 +44,18 @@ func (f AliyunAvatarFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value
 	return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AliyunAvatarMutation", m)
 }
 
+// The AllocAgentFunc type is an adapter to allow the use of ordinary
+// function as AllocAgent mutator.
+type AllocAgentFunc func(context.Context, *ent.AllocAgentMutation) (ent.Value, error)
+
+// Mutate calls f(ctx, m).
+func (f AllocAgentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
+	if mv, ok := m.(*ent.AllocAgentMutation); ok {
+		return f(ctx, mv)
+	}
+	return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AllocAgentMutation", m)
+}
+
 // The BatchMsgFunc type is an adapter to allow the use of ordinary
 // function as BatchMsg mutator.
 type BatchMsgFunc func(context.Context, *ent.BatchMsgMutation) (ent.Value, error)

+ 30 - 0
ent/intercept/intercept.go

@@ -9,6 +9,7 @@ import (
 	"wechat-api/ent/agent"
 	"wechat-api/ent/agentbase"
 	"wechat-api/ent/aliyunavatar"
+	"wechat-api/ent/allocagent"
 	"wechat-api/ent/batchmsg"
 	"wechat-api/ent/category"
 	"wechat-api/ent/chatrecords"
@@ -178,6 +179,33 @@ func (f TraverseAliyunAvatar) Traverse(ctx context.Context, q ent.Query) error {
 	return fmt.Errorf("unexpected query type %T. expect *ent.AliyunAvatarQuery", q)
 }
 
+// The AllocAgentFunc type is an adapter to allow the use of ordinary function as a Querier.
+type AllocAgentFunc func(context.Context, *ent.AllocAgentQuery) (ent.Value, error)
+
+// Query calls f(ctx, q).
+func (f AllocAgentFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
+	if q, ok := q.(*ent.AllocAgentQuery); ok {
+		return f(ctx, q)
+	}
+	return nil, fmt.Errorf("unexpected query type %T. expect *ent.AllocAgentQuery", q)
+}
+
+// The TraverseAllocAgent type is an adapter to allow the use of ordinary function as Traverser.
+type TraverseAllocAgent func(context.Context, *ent.AllocAgentQuery) error
+
+// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
+func (f TraverseAllocAgent) Intercept(next ent.Querier) ent.Querier {
+	return next
+}
+
+// Traverse calls f(ctx, q).
+func (f TraverseAllocAgent) Traverse(ctx context.Context, q ent.Query) error {
+	if q, ok := q.(*ent.AllocAgentQuery); ok {
+		return f(ctx, q)
+	}
+	return fmt.Errorf("unexpected query type %T. expect *ent.AllocAgentQuery", q)
+}
+
 // The BatchMsgFunc type is an adapter to allow the use of ordinary function as a Querier.
 type BatchMsgFunc func(context.Context, *ent.BatchMsgQuery) (ent.Value, error)
 
@@ -916,6 +944,8 @@ func NewQuery(q ent.Query) (Query, error) {
 		return &query[*ent.AgentBaseQuery, predicate.AgentBase, agentbase.OrderOption]{typ: ent.TypeAgentBase, tq: q}, nil
 	case *ent.AliyunAvatarQuery:
 		return &query[*ent.AliyunAvatarQuery, predicate.AliyunAvatar, aliyunavatar.OrderOption]{typ: ent.TypeAliyunAvatar, tq: q}, nil
+	case *ent.AllocAgentQuery:
+		return &query[*ent.AllocAgentQuery, predicate.AllocAgent, allocagent.OrderOption]{typ: ent.TypeAllocAgent, tq: q}, nil
 	case *ent.BatchMsgQuery:
 		return &query[*ent.BatchMsgQuery, predicate.BatchMsg, batchmsg.OrderOption]{typ: ent.TypeBatchMsg, tq: q}, nil
 	case *ent.CategoryQuery:

+ 33 - 0
ent/migrate/schema.go

@@ -85,6 +85,35 @@ var (
 			},
 		},
 	}
+	// AllocAgentColumns holds the columns for the "alloc_agent" table.
+	AllocAgentColumns = []*schema.Column{
+		{Name: "id", Type: field.TypeUint64, Increment: true},
+		{Name: "created_at", Type: field.TypeTime, Comment: "Create Time | 创建日期"},
+		{Name: "updated_at", Type: field.TypeTime, Comment: "Update Time | 修改日期"},
+		{Name: "deleted_at", Type: field.TypeTime, Nullable: true, Comment: "Delete Time | 删除日期"},
+		{Name: "user_id", Type: field.TypeString, Nullable: true, Comment: "user_id | 前台用户ID", Default: ""},
+		{Name: "organization_id", Type: field.TypeUint64, Nullable: true, Comment: "organization_id | 租户ID", Default: 0},
+		{Name: "agents", Type: field.TypeJSON, Comment: "agents | 分配的智能体IDs"},
+		{Name: "status", Type: field.TypeInt, Nullable: true, Comment: "status | 状态 1-正常 2-禁用", Default: 1},
+	}
+	// AllocAgentTable holds the schema information for the "alloc_agent" table.
+	AllocAgentTable = &schema.Table{
+		Name:       "alloc_agent",
+		Columns:    AllocAgentColumns,
+		PrimaryKey: []*schema.Column{AllocAgentColumns[0]},
+		Indexes: []*schema.Index{
+			{
+				Name:    "allocagent_organization_id",
+				Unique:  false,
+				Columns: []*schema.Column{AllocAgentColumns[5]},
+			},
+			{
+				Name:    "allocagent_user_id",
+				Unique:  false,
+				Columns: []*schema.Column{AllocAgentColumns[4]},
+			},
+		},
+	}
 	// BatchMsgColumns holds the columns for the "batch_msg" table.
 	BatchMsgColumns = []*schema.Column{
 		{Name: "id", Type: field.TypeUint64, Increment: true},
@@ -1040,6 +1069,7 @@ var (
 		AgentTable,
 		AgentBaseTable,
 		AliyunAvatarTable,
+		AllocAgentTable,
 		BatchMsgTable,
 		CategoryTable,
 		ChatRecordsTable,
@@ -1080,6 +1110,9 @@ func init() {
 	AliyunAvatarTable.Annotation = &entsql.Annotation{
 		Table: "aliyun_avatar",
 	}
+	AllocAgentTable.Annotation = &entsql.Annotation{
+		Table: "alloc_agent",
+	}
 	BatchMsgTable.Annotation = &entsql.Annotation{
 		Table: "batch_msg",
 	}

+ 824 - 0
ent/mutation.go

@@ -11,6 +11,7 @@ import (
 	"wechat-api/ent/agent"
 	"wechat-api/ent/agentbase"
 	"wechat-api/ent/aliyunavatar"
+	"wechat-api/ent/allocagent"
 	"wechat-api/ent/batchmsg"
 	"wechat-api/ent/category"
 	"wechat-api/ent/chatrecords"
@@ -57,6 +58,7 @@ const (
 	TypeAgent             = "Agent"
 	TypeAgentBase         = "AgentBase"
 	TypeAliyunAvatar      = "AliyunAvatar"
+	TypeAllocAgent        = "AllocAgent"
 	TypeBatchMsg          = "BatchMsg"
 	TypeCategory          = "Category"
 	TypeChatRecords       = "ChatRecords"
@@ -3418,6 +3420,828 @@ func (m *AliyunAvatarMutation) ResetEdge(name string) error {
 	return fmt.Errorf("unknown AliyunAvatar edge %s", name)
 }
 
+// AllocAgentMutation represents an operation that mutates the AllocAgent nodes in the graph.
+type AllocAgentMutation struct {
+	config
+	op                 Op
+	typ                string
+	id                 *uint64
+	created_at         *time.Time
+	updated_at         *time.Time
+	deleted_at         *time.Time
+	user_id            *string
+	organization_id    *uint64
+	addorganization_id *int64
+	agents             *[]uint64
+	appendagents       []uint64
+	status             *int
+	addstatus          *int
+	clearedFields      map[string]struct{}
+	done               bool
+	oldValue           func(context.Context) (*AllocAgent, error)
+	predicates         []predicate.AllocAgent
+}
+
+var _ ent.Mutation = (*AllocAgentMutation)(nil)
+
+// allocagentOption allows management of the mutation configuration using functional options.
+type allocagentOption func(*AllocAgentMutation)
+
+// newAllocAgentMutation creates new mutation for the AllocAgent entity.
+func newAllocAgentMutation(c config, op Op, opts ...allocagentOption) *AllocAgentMutation {
+	m := &AllocAgentMutation{
+		config:        c,
+		op:            op,
+		typ:           TypeAllocAgent,
+		clearedFields: make(map[string]struct{}),
+	}
+	for _, opt := range opts {
+		opt(m)
+	}
+	return m
+}
+
+// withAllocAgentID sets the ID field of the mutation.
+func withAllocAgentID(id uint64) allocagentOption {
+	return func(m *AllocAgentMutation) {
+		var (
+			err   error
+			once  sync.Once
+			value *AllocAgent
+		)
+		m.oldValue = func(ctx context.Context) (*AllocAgent, error) {
+			once.Do(func() {
+				if m.done {
+					err = errors.New("querying old values post mutation is not allowed")
+				} else {
+					value, err = m.Client().AllocAgent.Get(ctx, id)
+				}
+			})
+			return value, err
+		}
+		m.id = &id
+	}
+}
+
+// withAllocAgent sets the old AllocAgent of the mutation.
+func withAllocAgent(node *AllocAgent) allocagentOption {
+	return func(m *AllocAgentMutation) {
+		m.oldValue = func(context.Context) (*AllocAgent, error) {
+			return node, nil
+		}
+		m.id = &node.ID
+	}
+}
+
+// Client returns a new `ent.Client` from the mutation. If the mutation was
+// executed in a transaction (ent.Tx), a transactional client is returned.
+func (m AllocAgentMutation) Client() *Client {
+	client := &Client{config: m.config}
+	client.init()
+	return client
+}
+
+// Tx returns an `ent.Tx` for mutations that were executed in transactions;
+// it returns an error otherwise.
+func (m AllocAgentMutation) Tx() (*Tx, error) {
+	if _, ok := m.driver.(*txDriver); !ok {
+		return nil, errors.New("ent: mutation is not running in a transaction")
+	}
+	tx := &Tx{config: m.config}
+	tx.init()
+	return tx, nil
+}
+
+// SetID sets the value of the id field. Note that this
+// operation is only accepted on creation of AllocAgent entities.
+func (m *AllocAgentMutation) SetID(id uint64) {
+	m.id = &id
+}
+
+// ID returns the ID value in the mutation. Note that the ID is only available
+// if it was provided to the builder or after it was returned from the database.
+func (m *AllocAgentMutation) ID() (id uint64, exists bool) {
+	if m.id == nil {
+		return
+	}
+	return *m.id, true
+}
+
+// IDs queries the database and returns the entity ids that match the mutation's predicate.
+// That means, if the mutation is applied within a transaction with an isolation level such
+// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
+// or updated by the mutation.
+func (m *AllocAgentMutation) IDs(ctx context.Context) ([]uint64, error) {
+	switch {
+	case m.op.Is(OpUpdateOne | OpDeleteOne):
+		id, exists := m.ID()
+		if exists {
+			return []uint64{id}, nil
+		}
+		fallthrough
+	case m.op.Is(OpUpdate | OpDelete):
+		return m.Client().AllocAgent.Query().Where(m.predicates...).IDs(ctx)
+	default:
+		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
+	}
+}
+
+// SetCreatedAt sets the "created_at" field.
+func (m *AllocAgentMutation) SetCreatedAt(t time.Time) {
+	m.created_at = &t
+}
+
+// CreatedAt returns the value of the "created_at" field in the mutation.
+func (m *AllocAgentMutation) CreatedAt() (r time.Time, exists bool) {
+	v := m.created_at
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldCreatedAt returns the old "created_at" field's value of the AllocAgent entity.
+// If the AllocAgent object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *AllocAgentMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldCreatedAt requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
+	}
+	return oldValue.CreatedAt, nil
+}
+
+// ResetCreatedAt resets all changes to the "created_at" field.
+func (m *AllocAgentMutation) ResetCreatedAt() {
+	m.created_at = nil
+}
+
+// SetUpdatedAt sets the "updated_at" field.
+func (m *AllocAgentMutation) SetUpdatedAt(t time.Time) {
+	m.updated_at = &t
+}
+
+// UpdatedAt returns the value of the "updated_at" field in the mutation.
+func (m *AllocAgentMutation) UpdatedAt() (r time.Time, exists bool) {
+	v := m.updated_at
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldUpdatedAt returns the old "updated_at" field's value of the AllocAgent entity.
+// If the AllocAgent object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *AllocAgentMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
+	}
+	return oldValue.UpdatedAt, nil
+}
+
+// ResetUpdatedAt resets all changes to the "updated_at" field.
+func (m *AllocAgentMutation) ResetUpdatedAt() {
+	m.updated_at = nil
+}
+
+// SetDeletedAt sets the "deleted_at" field.
+func (m *AllocAgentMutation) SetDeletedAt(t time.Time) {
+	m.deleted_at = &t
+}
+
+// DeletedAt returns the value of the "deleted_at" field in the mutation.
+func (m *AllocAgentMutation) DeletedAt() (r time.Time, exists bool) {
+	v := m.deleted_at
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldDeletedAt returns the old "deleted_at" field's value of the AllocAgent entity.
+// If the AllocAgent object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *AllocAgentMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldDeletedAt requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
+	}
+	return oldValue.DeletedAt, nil
+}
+
+// ClearDeletedAt clears the value of the "deleted_at" field.
+func (m *AllocAgentMutation) ClearDeletedAt() {
+	m.deleted_at = nil
+	m.clearedFields[allocagent.FieldDeletedAt] = struct{}{}
+}
+
+// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
+func (m *AllocAgentMutation) DeletedAtCleared() bool {
+	_, ok := m.clearedFields[allocagent.FieldDeletedAt]
+	return ok
+}
+
+// ResetDeletedAt resets all changes to the "deleted_at" field.
+func (m *AllocAgentMutation) ResetDeletedAt() {
+	m.deleted_at = nil
+	delete(m.clearedFields, allocagent.FieldDeletedAt)
+}
+
+// SetUserID sets the "user_id" field.
+func (m *AllocAgentMutation) SetUserID(s string) {
+	m.user_id = &s
+}
+
+// UserID returns the value of the "user_id" field in the mutation.
+func (m *AllocAgentMutation) UserID() (r string, exists bool) {
+	v := m.user_id
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldUserID returns the old "user_id" field's value of the AllocAgent entity.
+// If the AllocAgent object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *AllocAgentMutation) OldUserID(ctx context.Context) (v string, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldUserID is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldUserID requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldUserID: %w", err)
+	}
+	return oldValue.UserID, nil
+}
+
+// ClearUserID clears the value of the "user_id" field.
+func (m *AllocAgentMutation) ClearUserID() {
+	m.user_id = nil
+	m.clearedFields[allocagent.FieldUserID] = struct{}{}
+}
+
+// UserIDCleared returns if the "user_id" field was cleared in this mutation.
+func (m *AllocAgentMutation) UserIDCleared() bool {
+	_, ok := m.clearedFields[allocagent.FieldUserID]
+	return ok
+}
+
+// ResetUserID resets all changes to the "user_id" field.
+func (m *AllocAgentMutation) ResetUserID() {
+	m.user_id = nil
+	delete(m.clearedFields, allocagent.FieldUserID)
+}
+
+// SetOrganizationID sets the "organization_id" field.
+func (m *AllocAgentMutation) SetOrganizationID(u uint64) {
+	m.organization_id = &u
+	m.addorganization_id = nil
+}
+
+// OrganizationID returns the value of the "organization_id" field in the mutation.
+func (m *AllocAgentMutation) OrganizationID() (r uint64, exists bool) {
+	v := m.organization_id
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldOrganizationID returns the old "organization_id" field's value of the AllocAgent entity.
+// If the AllocAgent object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *AllocAgentMutation) OldOrganizationID(ctx context.Context) (v uint64, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldOrganizationID is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldOrganizationID requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldOrganizationID: %w", err)
+	}
+	return oldValue.OrganizationID, nil
+}
+
+// AddOrganizationID adds u to the "organization_id" field.
+func (m *AllocAgentMutation) AddOrganizationID(u int64) {
+	if m.addorganization_id != nil {
+		*m.addorganization_id += u
+	} else {
+		m.addorganization_id = &u
+	}
+}
+
+// AddedOrganizationID returns the value that was added to the "organization_id" field in this mutation.
+func (m *AllocAgentMutation) AddedOrganizationID() (r int64, exists bool) {
+	v := m.addorganization_id
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// ClearOrganizationID clears the value of the "organization_id" field.
+func (m *AllocAgentMutation) ClearOrganizationID() {
+	m.organization_id = nil
+	m.addorganization_id = nil
+	m.clearedFields[allocagent.FieldOrganizationID] = struct{}{}
+}
+
+// OrganizationIDCleared returns if the "organization_id" field was cleared in this mutation.
+func (m *AllocAgentMutation) OrganizationIDCleared() bool {
+	_, ok := m.clearedFields[allocagent.FieldOrganizationID]
+	return ok
+}
+
+// ResetOrganizationID resets all changes to the "organization_id" field.
+func (m *AllocAgentMutation) ResetOrganizationID() {
+	m.organization_id = nil
+	m.addorganization_id = nil
+	delete(m.clearedFields, allocagent.FieldOrganizationID)
+}
+
+// SetAgents sets the "agents" field.
+func (m *AllocAgentMutation) SetAgents(u []uint64) {
+	m.agents = &u
+	m.appendagents = nil
+}
+
+// Agents returns the value of the "agents" field in the mutation.
+func (m *AllocAgentMutation) Agents() (r []uint64, exists bool) {
+	v := m.agents
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldAgents returns the old "agents" field's value of the AllocAgent entity.
+// If the AllocAgent object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *AllocAgentMutation) OldAgents(ctx context.Context) (v []uint64, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldAgents is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldAgents requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldAgents: %w", err)
+	}
+	return oldValue.Agents, nil
+}
+
+// AppendAgents adds u to the "agents" field.
+func (m *AllocAgentMutation) AppendAgents(u []uint64) {
+	m.appendagents = append(m.appendagents, u...)
+}
+
+// AppendedAgents returns the list of values that were appended to the "agents" field in this mutation.
+func (m *AllocAgentMutation) AppendedAgents() ([]uint64, bool) {
+	if len(m.appendagents) == 0 {
+		return nil, false
+	}
+	return m.appendagents, true
+}
+
+// ResetAgents resets all changes to the "agents" field.
+func (m *AllocAgentMutation) ResetAgents() {
+	m.agents = nil
+	m.appendagents = nil
+}
+
+// SetStatus sets the "status" field.
+func (m *AllocAgentMutation) SetStatus(i int) {
+	m.status = &i
+	m.addstatus = nil
+}
+
+// Status returns the value of the "status" field in the mutation.
+func (m *AllocAgentMutation) Status() (r int, exists bool) {
+	v := m.status
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldStatus returns the old "status" field's value of the AllocAgent entity.
+// If the AllocAgent object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *AllocAgentMutation) OldStatus(ctx context.Context) (v int, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldStatus is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldStatus requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldStatus: %w", err)
+	}
+	return oldValue.Status, nil
+}
+
+// AddStatus adds i to the "status" field.
+func (m *AllocAgentMutation) AddStatus(i int) {
+	if m.addstatus != nil {
+		*m.addstatus += i
+	} else {
+		m.addstatus = &i
+	}
+}
+
+// AddedStatus returns the value that was added to the "status" field in this mutation.
+func (m *AllocAgentMutation) AddedStatus() (r int, exists bool) {
+	v := m.addstatus
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// ClearStatus clears the value of the "status" field.
+func (m *AllocAgentMutation) ClearStatus() {
+	m.status = nil
+	m.addstatus = nil
+	m.clearedFields[allocagent.FieldStatus] = struct{}{}
+}
+
+// StatusCleared returns if the "status" field was cleared in this mutation.
+func (m *AllocAgentMutation) StatusCleared() bool {
+	_, ok := m.clearedFields[allocagent.FieldStatus]
+	return ok
+}
+
+// ResetStatus resets all changes to the "status" field.
+func (m *AllocAgentMutation) ResetStatus() {
+	m.status = nil
+	m.addstatus = nil
+	delete(m.clearedFields, allocagent.FieldStatus)
+}
+
+// Where appends a list predicates to the AllocAgentMutation builder.
+func (m *AllocAgentMutation) Where(ps ...predicate.AllocAgent) {
+	m.predicates = append(m.predicates, ps...)
+}
+
+// WhereP appends storage-level predicates to the AllocAgentMutation builder. Using this method,
+// users can use type-assertion to append predicates that do not depend on any generated package.
+func (m *AllocAgentMutation) WhereP(ps ...func(*sql.Selector)) {
+	p := make([]predicate.AllocAgent, len(ps))
+	for i := range ps {
+		p[i] = ps[i]
+	}
+	m.Where(p...)
+}
+
+// Op returns the operation name.
+func (m *AllocAgentMutation) Op() Op {
+	return m.op
+}
+
+// SetOp allows setting the mutation operation.
+func (m *AllocAgentMutation) SetOp(op Op) {
+	m.op = op
+}
+
+// Type returns the node type of this mutation (AllocAgent).
+func (m *AllocAgentMutation) Type() string {
+	return m.typ
+}
+
+// Fields returns all fields that were changed during this mutation. Note that in
+// order to get all numeric fields that were incremented/decremented, call
+// AddedFields().
+func (m *AllocAgentMutation) Fields() []string {
+	fields := make([]string, 0, 7)
+	if m.created_at != nil {
+		fields = append(fields, allocagent.FieldCreatedAt)
+	}
+	if m.updated_at != nil {
+		fields = append(fields, allocagent.FieldUpdatedAt)
+	}
+	if m.deleted_at != nil {
+		fields = append(fields, allocagent.FieldDeletedAt)
+	}
+	if m.user_id != nil {
+		fields = append(fields, allocagent.FieldUserID)
+	}
+	if m.organization_id != nil {
+		fields = append(fields, allocagent.FieldOrganizationID)
+	}
+	if m.agents != nil {
+		fields = append(fields, allocagent.FieldAgents)
+	}
+	if m.status != nil {
+		fields = append(fields, allocagent.FieldStatus)
+	}
+	return fields
+}
+
+// Field returns the value of a field with the given name. The second boolean
+// return value indicates that this field was not set, or was not defined in the
+// schema.
+func (m *AllocAgentMutation) Field(name string) (ent.Value, bool) {
+	switch name {
+	case allocagent.FieldCreatedAt:
+		return m.CreatedAt()
+	case allocagent.FieldUpdatedAt:
+		return m.UpdatedAt()
+	case allocagent.FieldDeletedAt:
+		return m.DeletedAt()
+	case allocagent.FieldUserID:
+		return m.UserID()
+	case allocagent.FieldOrganizationID:
+		return m.OrganizationID()
+	case allocagent.FieldAgents:
+		return m.Agents()
+	case allocagent.FieldStatus:
+		return m.Status()
+	}
+	return nil, false
+}
+
+// OldField returns the old value of the field from the database. An error is
+// returned if the mutation operation is not UpdateOne, or the query to the
+// database failed.
+func (m *AllocAgentMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
+	switch name {
+	case allocagent.FieldCreatedAt:
+		return m.OldCreatedAt(ctx)
+	case allocagent.FieldUpdatedAt:
+		return m.OldUpdatedAt(ctx)
+	case allocagent.FieldDeletedAt:
+		return m.OldDeletedAt(ctx)
+	case allocagent.FieldUserID:
+		return m.OldUserID(ctx)
+	case allocagent.FieldOrganizationID:
+		return m.OldOrganizationID(ctx)
+	case allocagent.FieldAgents:
+		return m.OldAgents(ctx)
+	case allocagent.FieldStatus:
+		return m.OldStatus(ctx)
+	}
+	return nil, fmt.Errorf("unknown AllocAgent field %s", name)
+}
+
+// SetField sets the value of a field with the given name. It returns an error if
+// the field is not defined in the schema, or if the type mismatched the field
+// type.
+func (m *AllocAgentMutation) SetField(name string, value ent.Value) error {
+	switch name {
+	case allocagent.FieldCreatedAt:
+		v, ok := value.(time.Time)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetCreatedAt(v)
+		return nil
+	case allocagent.FieldUpdatedAt:
+		v, ok := value.(time.Time)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetUpdatedAt(v)
+		return nil
+	case allocagent.FieldDeletedAt:
+		v, ok := value.(time.Time)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetDeletedAt(v)
+		return nil
+	case allocagent.FieldUserID:
+		v, ok := value.(string)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetUserID(v)
+		return nil
+	case allocagent.FieldOrganizationID:
+		v, ok := value.(uint64)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetOrganizationID(v)
+		return nil
+	case allocagent.FieldAgents:
+		v, ok := value.([]uint64)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetAgents(v)
+		return nil
+	case allocagent.FieldStatus:
+		v, ok := value.(int)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetStatus(v)
+		return nil
+	}
+	return fmt.Errorf("unknown AllocAgent field %s", name)
+}
+
+// AddedFields returns all numeric fields that were incremented/decremented during
+// this mutation.
+func (m *AllocAgentMutation) AddedFields() []string {
+	var fields []string
+	if m.addorganization_id != nil {
+		fields = append(fields, allocagent.FieldOrganizationID)
+	}
+	if m.addstatus != nil {
+		fields = append(fields, allocagent.FieldStatus)
+	}
+	return fields
+}
+
+// AddedField returns the numeric value that was incremented/decremented on a field
+// with the given name. The second boolean return value indicates that this field
+// was not set, or was not defined in the schema.
+func (m *AllocAgentMutation) AddedField(name string) (ent.Value, bool) {
+	switch name {
+	case allocagent.FieldOrganizationID:
+		return m.AddedOrganizationID()
+	case allocagent.FieldStatus:
+		return m.AddedStatus()
+	}
+	return nil, false
+}
+
+// AddField adds the value to the field with the given name. It returns an error if
+// the field is not defined in the schema, or if the type mismatched the field
+// type.
+func (m *AllocAgentMutation) AddField(name string, value ent.Value) error {
+	switch name {
+	case allocagent.FieldOrganizationID:
+		v, ok := value.(int64)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.AddOrganizationID(v)
+		return nil
+	case allocagent.FieldStatus:
+		v, ok := value.(int)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.AddStatus(v)
+		return nil
+	}
+	return fmt.Errorf("unknown AllocAgent numeric field %s", name)
+}
+
+// ClearedFields returns all nullable fields that were cleared during this
+// mutation.
+func (m *AllocAgentMutation) ClearedFields() []string {
+	var fields []string
+	if m.FieldCleared(allocagent.FieldDeletedAt) {
+		fields = append(fields, allocagent.FieldDeletedAt)
+	}
+	if m.FieldCleared(allocagent.FieldUserID) {
+		fields = append(fields, allocagent.FieldUserID)
+	}
+	if m.FieldCleared(allocagent.FieldOrganizationID) {
+		fields = append(fields, allocagent.FieldOrganizationID)
+	}
+	if m.FieldCleared(allocagent.FieldStatus) {
+		fields = append(fields, allocagent.FieldStatus)
+	}
+	return fields
+}
+
+// FieldCleared returns a boolean indicating if a field with the given name was
+// cleared in this mutation.
+func (m *AllocAgentMutation) FieldCleared(name string) bool {
+	_, ok := m.clearedFields[name]
+	return ok
+}
+
+// ClearField clears the value of the field with the given name. It returns an
+// error if the field is not defined in the schema.
+func (m *AllocAgentMutation) ClearField(name string) error {
+	switch name {
+	case allocagent.FieldDeletedAt:
+		m.ClearDeletedAt()
+		return nil
+	case allocagent.FieldUserID:
+		m.ClearUserID()
+		return nil
+	case allocagent.FieldOrganizationID:
+		m.ClearOrganizationID()
+		return nil
+	case allocagent.FieldStatus:
+		m.ClearStatus()
+		return nil
+	}
+	return fmt.Errorf("unknown AllocAgent nullable field %s", name)
+}
+
+// ResetField resets all changes in the mutation for the field with the given name.
+// It returns an error if the field is not defined in the schema.
+func (m *AllocAgentMutation) ResetField(name string) error {
+	switch name {
+	case allocagent.FieldCreatedAt:
+		m.ResetCreatedAt()
+		return nil
+	case allocagent.FieldUpdatedAt:
+		m.ResetUpdatedAt()
+		return nil
+	case allocagent.FieldDeletedAt:
+		m.ResetDeletedAt()
+		return nil
+	case allocagent.FieldUserID:
+		m.ResetUserID()
+		return nil
+	case allocagent.FieldOrganizationID:
+		m.ResetOrganizationID()
+		return nil
+	case allocagent.FieldAgents:
+		m.ResetAgents()
+		return nil
+	case allocagent.FieldStatus:
+		m.ResetStatus()
+		return nil
+	}
+	return fmt.Errorf("unknown AllocAgent field %s", name)
+}
+
+// AddedEdges returns all edge names that were set/added in this mutation.
+func (m *AllocAgentMutation) AddedEdges() []string {
+	edges := make([]string, 0, 0)
+	return edges
+}
+
+// AddedIDs returns all IDs (to other nodes) that were added for the given edge
+// name in this mutation.
+func (m *AllocAgentMutation) AddedIDs(name string) []ent.Value {
+	return nil
+}
+
+// RemovedEdges returns all edge names that were removed in this mutation.
+func (m *AllocAgentMutation) RemovedEdges() []string {
+	edges := make([]string, 0, 0)
+	return edges
+}
+
+// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
+// the given name in this mutation.
+func (m *AllocAgentMutation) RemovedIDs(name string) []ent.Value {
+	return nil
+}
+
+// ClearedEdges returns all edge names that were cleared in this mutation.
+func (m *AllocAgentMutation) ClearedEdges() []string {
+	edges := make([]string, 0, 0)
+	return edges
+}
+
+// EdgeCleared returns a boolean which indicates if the edge with the given name
+// was cleared in this mutation.
+func (m *AllocAgentMutation) EdgeCleared(name string) bool {
+	return false
+}
+
+// ClearEdge clears the value of the edge with the given name. It returns an error
+// if that edge is not defined in the schema.
+func (m *AllocAgentMutation) ClearEdge(name string) error {
+	return fmt.Errorf("unknown AllocAgent unique edge %s", name)
+}
+
+// ResetEdge resets all changes to the edge with the given name in this mutation.
+// It returns an error if the edge is not defined in the schema.
+func (m *AllocAgentMutation) ResetEdge(name string) error {
+	return fmt.Errorf("unknown AllocAgent edge %s", name)
+}
+
 // BatchMsgMutation represents an operation that mutates the BatchMsg nodes in the graph.
 type BatchMsgMutation struct {
 	config

+ 82 - 0
ent/pagination.go

@@ -8,6 +8,7 @@ import (
 	"wechat-api/ent/agent"
 	"wechat-api/ent/agentbase"
 	"wechat-api/ent/aliyunavatar"
+	"wechat-api/ent/allocagent"
 	"wechat-api/ent/batchmsg"
 	"wechat-api/ent/category"
 	"wechat-api/ent/chatrecords"
@@ -326,6 +327,87 @@ func (aa *AliyunAvatarQuery) Page(
 	return ret, nil
 }
 
+type AllocAgentPager struct {
+	Order  allocagent.OrderOption
+	Filter func(*AllocAgentQuery) (*AllocAgentQuery, error)
+}
+
+// AllocAgentPaginateOption enables pagination customization.
+type AllocAgentPaginateOption func(*AllocAgentPager)
+
+// DefaultAllocAgentOrder is the default ordering of AllocAgent.
+var DefaultAllocAgentOrder = Desc(allocagent.FieldID)
+
+func newAllocAgentPager(opts []AllocAgentPaginateOption) (*AllocAgentPager, error) {
+	pager := &AllocAgentPager{}
+	for _, opt := range opts {
+		opt(pager)
+	}
+	if pager.Order == nil {
+		pager.Order = DefaultAllocAgentOrder
+	}
+	return pager, nil
+}
+
+func (p *AllocAgentPager) ApplyFilter(query *AllocAgentQuery) (*AllocAgentQuery, error) {
+	if p.Filter != nil {
+		return p.Filter(query)
+	}
+	return query, nil
+}
+
+// AllocAgentPageList is AllocAgent PageList result.
+type AllocAgentPageList struct {
+	List        []*AllocAgent `json:"list"`
+	PageDetails *PageDetails  `json:"pageDetails"`
+}
+
+func (aa *AllocAgentQuery) Page(
+	ctx context.Context, pageNum uint64, pageSize uint64, opts ...AllocAgentPaginateOption,
+) (*AllocAgentPageList, error) {
+
+	pager, err := newAllocAgentPager(opts)
+	if err != nil {
+		return nil, err
+	}
+
+	if aa, err = pager.ApplyFilter(aa); err != nil {
+		return nil, err
+	}
+
+	ret := &AllocAgentPageList{}
+
+	ret.PageDetails = &PageDetails{
+		Page: pageNum,
+		Size: pageSize,
+	}
+
+	query := aa.Clone()
+	query.ctx.Fields = nil
+	count, err := query.Count(ctx)
+
+	if err != nil {
+		return nil, err
+	}
+
+	ret.PageDetails.Total = uint64(count)
+
+	if pager.Order != nil {
+		aa = aa.Order(pager.Order)
+	} else {
+		aa = aa.Order(DefaultAllocAgentOrder)
+	}
+
+	aa = aa.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
+	list, err := aa.All(ctx)
+	if err != nil {
+		return nil, err
+	}
+	ret.List = list
+
+	return ret, nil
+}
+
 type BatchMsgPager struct {
 	Order  batchmsg.OrderOption
 	Filter func(*BatchMsgQuery) (*BatchMsgQuery, error)

+ 3 - 0
ent/predicate/predicate.go

@@ -15,6 +15,9 @@ type AgentBase func(*sql.Selector)
 // AliyunAvatar is the predicate function for aliyunavatar builders.
 type AliyunAvatar func(*sql.Selector)
 
+// AllocAgent is the predicate function for allocagent builders.
+type AllocAgent func(*sql.Selector)
+
 // BatchMsg is the predicate function for batchmsg builders.
 type BatchMsg func(*sql.Selector)
 

+ 34 - 0
ent/runtime/runtime.go

@@ -7,6 +7,7 @@ import (
 	"wechat-api/ent/agent"
 	"wechat-api/ent/agentbase"
 	"wechat-api/ent/aliyunavatar"
+	"wechat-api/ent/allocagent"
 	"wechat-api/ent/batchmsg"
 	"wechat-api/ent/category"
 	"wechat-api/ent/chatrecords"
@@ -147,6 +148,39 @@ func init() {
 	aliyunavatarDescSessionID := aliyunavatarFields[8].Descriptor()
 	// aliyunavatar.DefaultSessionID holds the default value on creation for the session_id field.
 	aliyunavatar.DefaultSessionID = aliyunavatarDescSessionID.Default.(string)
+	allocagentMixin := schema.AllocAgent{}.Mixin()
+	allocagentMixinHooks1 := allocagentMixin[1].Hooks()
+	allocagent.Hooks[0] = allocagentMixinHooks1[0]
+	allocagentMixinInters1 := allocagentMixin[1].Interceptors()
+	allocagent.Interceptors[0] = allocagentMixinInters1[0]
+	allocagentMixinFields0 := allocagentMixin[0].Fields()
+	_ = allocagentMixinFields0
+	allocagentFields := schema.AllocAgent{}.Fields()
+	_ = allocagentFields
+	// allocagentDescCreatedAt is the schema descriptor for created_at field.
+	allocagentDescCreatedAt := allocagentMixinFields0[1].Descriptor()
+	// allocagent.DefaultCreatedAt holds the default value on creation for the created_at field.
+	allocagent.DefaultCreatedAt = allocagentDescCreatedAt.Default.(func() time.Time)
+	// allocagentDescUpdatedAt is the schema descriptor for updated_at field.
+	allocagentDescUpdatedAt := allocagentMixinFields0[2].Descriptor()
+	// allocagent.DefaultUpdatedAt holds the default value on creation for the updated_at field.
+	allocagent.DefaultUpdatedAt = allocagentDescUpdatedAt.Default.(func() time.Time)
+	// allocagent.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
+	allocagent.UpdateDefaultUpdatedAt = allocagentDescUpdatedAt.UpdateDefault.(func() time.Time)
+	// allocagentDescUserID is the schema descriptor for user_id field.
+	allocagentDescUserID := allocagentFields[0].Descriptor()
+	// allocagent.DefaultUserID holds the default value on creation for the user_id field.
+	allocagent.DefaultUserID = allocagentDescUserID.Default.(string)
+	// allocagentDescOrganizationID is the schema descriptor for organization_id field.
+	allocagentDescOrganizationID := allocagentFields[1].Descriptor()
+	// allocagent.DefaultOrganizationID holds the default value on creation for the organization_id field.
+	allocagent.DefaultOrganizationID = allocagentDescOrganizationID.Default.(uint64)
+	// allocagentDescStatus is the schema descriptor for status field.
+	allocagentDescStatus := allocagentFields[3].Descriptor()
+	// allocagent.DefaultStatus holds the default value on creation for the status field.
+	allocagent.DefaultStatus = allocagentDescStatus.Default.(int)
+	// allocagent.StatusValidator is a validator for the "status" field. It is called by the builders before save.
+	allocagent.StatusValidator = allocagentDescStatus.Validators[0].(func(int) error)
 	batchmsgMixin := schema.BatchMsg{}.Mixin()
 	batchmsgMixinHooks1 := batchmsgMixin[1].Hooks()
 	batchmsg.Hooks[0] = batchmsgMixinHooks1[0]

+ 50 - 0
ent/schema/alloc_agent.go

@@ -0,0 +1,50 @@
+package schema
+
+import (
+	"entgo.io/ent/schema/index"
+	"wechat-api/ent/schema/localmixin"
+
+	"entgo.io/ent"
+	"entgo.io/ent/dialect/entsql"
+	"entgo.io/ent/schema"
+	"entgo.io/ent/schema/field"
+	"github.com/suyuan32/simple-admin-common/orm/ent/mixins"
+)
+
+type AllocAgent struct {
+	ent.Schema
+}
+
+func (AllocAgent) Fields() []ent.Field {
+	return []ent.Field{
+		field.String("user_id").Default("").Optional().Comment("user_id | 前台用户ID"),
+		field.Uint64("organization_id").Optional().Default(0).Comment("organization_id | 租户ID"),
+		field.JSON("agents", []uint64{}).Comment("agents | 分配的智能体IDs"),
+		field.Int("status").Optional().Range(1, 2).Default(1).Comment("status | 状态 1-正常 2-禁用"),
+	}
+}
+
+func (AllocAgent) Mixin() []ent.Mixin {
+	return []ent.Mixin{
+		mixins.IDMixin{},
+		localmixin.SoftDeleteMixin{},
+	}
+}
+
+func (AllocAgent) Edges() []ent.Edge {
+	return nil
+}
+
+func (AllocAgent) Indexes() []ent.Index {
+	return []ent.Index{
+		index.Fields("organization_id"),
+		index.Fields("user_id"),
+	}
+}
+
+func (AllocAgent) Annotations() []schema.Annotation {
+	return []schema.Annotation{
+		entsql.WithComments(true),
+		entsql.Annotation{Table: "alloc_agent"},
+	}
+}

+ 144 - 0
ent/set_not_nil.go

@@ -728,6 +728,150 @@ func (aa *AliyunAvatarCreate) SetNotNilSessionID(value *string) *AliyunAvatarCre
 }
 
 // set field if value's pointer is not nil.
+func (aa *AllocAgentUpdate) SetNotNilUpdatedAt(value *time.Time) *AllocAgentUpdate {
+	if value != nil {
+		return aa.SetUpdatedAt(*value)
+	}
+	return aa
+}
+
+// set field if value's pointer is not nil.
+func (aa *AllocAgentUpdateOne) SetNotNilUpdatedAt(value *time.Time) *AllocAgentUpdateOne {
+	if value != nil {
+		return aa.SetUpdatedAt(*value)
+	}
+	return aa
+}
+
+// set field if value's pointer is not nil.
+func (aa *AllocAgentCreate) SetNotNilUpdatedAt(value *time.Time) *AllocAgentCreate {
+	if value != nil {
+		return aa.SetUpdatedAt(*value)
+	}
+	return aa
+}
+
+// set field if value's pointer is not nil.
+func (aa *AllocAgentUpdate) SetNotNilDeletedAt(value *time.Time) *AllocAgentUpdate {
+	if value != nil {
+		return aa.SetDeletedAt(*value)
+	}
+	return aa
+}
+
+// set field if value's pointer is not nil.
+func (aa *AllocAgentUpdateOne) SetNotNilDeletedAt(value *time.Time) *AllocAgentUpdateOne {
+	if value != nil {
+		return aa.SetDeletedAt(*value)
+	}
+	return aa
+}
+
+// set field if value's pointer is not nil.
+func (aa *AllocAgentCreate) SetNotNilDeletedAt(value *time.Time) *AllocAgentCreate {
+	if value != nil {
+		return aa.SetDeletedAt(*value)
+	}
+	return aa
+}
+
+// set field if value's pointer is not nil.
+func (aa *AllocAgentUpdate) SetNotNilUserID(value *string) *AllocAgentUpdate {
+	if value != nil {
+		return aa.SetUserID(*value)
+	}
+	return aa
+}
+
+// set field if value's pointer is not nil.
+func (aa *AllocAgentUpdateOne) SetNotNilUserID(value *string) *AllocAgentUpdateOne {
+	if value != nil {
+		return aa.SetUserID(*value)
+	}
+	return aa
+}
+
+// set field if value's pointer is not nil.
+func (aa *AllocAgentCreate) SetNotNilUserID(value *string) *AllocAgentCreate {
+	if value != nil {
+		return aa.SetUserID(*value)
+	}
+	return aa
+}
+
+// set field if value's pointer is not nil.
+func (aa *AllocAgentUpdate) SetNotNilOrganizationID(value *uint64) *AllocAgentUpdate {
+	if value != nil {
+		return aa.SetOrganizationID(*value)
+	}
+	return aa
+}
+
+// set field if value's pointer is not nil.
+func (aa *AllocAgentUpdateOne) SetNotNilOrganizationID(value *uint64) *AllocAgentUpdateOne {
+	if value != nil {
+		return aa.SetOrganizationID(*value)
+	}
+	return aa
+}
+
+// set field if value's pointer is not nil.
+func (aa *AllocAgentCreate) SetNotNilOrganizationID(value *uint64) *AllocAgentCreate {
+	if value != nil {
+		return aa.SetOrganizationID(*value)
+	}
+	return aa
+}
+
+// set field if value's pointer is not nil.
+func (aa *AllocAgentUpdate) SetNotNilAgents(value []uint64) *AllocAgentUpdate {
+	if value != nil {
+		return aa.SetAgents(value)
+	}
+	return aa
+}
+
+// set field if value's pointer is not nil.
+func (aa *AllocAgentUpdateOne) SetNotNilAgents(value []uint64) *AllocAgentUpdateOne {
+	if value != nil {
+		return aa.SetAgents(value)
+	}
+	return aa
+}
+
+// set field if value's pointer is not nil.
+func (aa *AllocAgentCreate) SetNotNilAgents(value []uint64) *AllocAgentCreate {
+	if value != nil {
+		return aa.SetAgents(value)
+	}
+	return aa
+}
+
+// set field if value's pointer is not nil.
+func (aa *AllocAgentUpdate) SetNotNilStatus(value *int) *AllocAgentUpdate {
+	if value != nil {
+		return aa.SetStatus(*value)
+	}
+	return aa
+}
+
+// set field if value's pointer is not nil.
+func (aa *AllocAgentUpdateOne) SetNotNilStatus(value *int) *AllocAgentUpdateOne {
+	if value != nil {
+		return aa.SetStatus(*value)
+	}
+	return aa
+}
+
+// set field if value's pointer is not nil.
+func (aa *AllocAgentCreate) SetNotNilStatus(value *int) *AllocAgentCreate {
+	if value != nil {
+		return aa.SetStatus(*value)
+	}
+	return aa
+}
+
+// set field if value's pointer is not nil.
 func (bm *BatchMsgUpdate) SetNotNilUpdatedAt(value *time.Time) *BatchMsgUpdate {
 	if value != nil {
 		return bm.SetUpdatedAt(*value)

+ 3 - 0
ent/tx.go

@@ -20,6 +20,8 @@ type Tx struct {
 	AgentBase *AgentBaseClient
 	// AliyunAvatar is the client for interacting with the AliyunAvatar builders.
 	AliyunAvatar *AliyunAvatarClient
+	// AllocAgent is the client for interacting with the AllocAgent builders.
+	AllocAgent *AllocAgentClient
 	// BatchMsg is the client for interacting with the BatchMsg builders.
 	BatchMsg *BatchMsgClient
 	// Category is the client for interacting with the Category builders.
@@ -208,6 +210,7 @@ func (tx *Tx) init() {
 	tx.Agent = NewAgentClient(tx.config)
 	tx.AgentBase = NewAgentBaseClient(tx.config)
 	tx.AliyunAvatar = NewAliyunAvatarClient(tx.config)
+	tx.AllocAgent = NewAllocAgentClient(tx.config)
 	tx.BatchMsg = NewBatchMsgClient(tx.config)
 	tx.Category = NewCategoryClient(tx.config)
 	tx.ChatRecords = NewChatRecordsClient(tx.config)

+ 8 - 0
hook/dify/chat.go

@@ -32,3 +32,11 @@ type Metadata struct {
 func GetChatUrl() string {
 	return "/chat-messages"
 }
+
+func GetBaseUrl() string {
+	return "https://dify.gkscrm.com/v1"
+}
+
+func GetToken() string {
+	return "app-NhSN24G0AQV804gWtPfDnFZx"
+}

+ 93 - 0
hook/dify/dify.go

@@ -0,0 +1,93 @@
+package dify
+
+import (
+	"errors"
+	"github.com/go-resty/resty/v2"
+)
+
+type SessionResponse struct {
+	Limit   int            `json:"limit"`
+	HasMore bool           `json:"has_more"`
+	Data    []SessionDatum `json:"data"`
+}
+
+type SessionDatum struct {
+	ID        string `json:"id"`
+	Name      string `json:"name"`
+	Inputs    Inputs `json:"inputs"`
+	Status    string `json:"status"`
+	CreatedAt int64  `json:"created_at"`
+}
+
+type Inputs map[string]string
+
+type HistoryResponse struct {
+	Limit   int       `json:"limit"`
+	HasMore bool      `json:"has_more"`
+	Data    []History `json:"data"`
+}
+
+type History struct {
+	ID             string `json:"id"`
+	ConversationId string `json:"conversation_id"`
+	Inputs         Inputs `json:"inputs"`
+	Query          string `json:"query"`
+	Answer         string `json:"answer"`
+	CreatedAt      int64  `json:"created_at"`
+}
+
+// GetSessionList 获取会话列表
+func GetSessionList(user, lastId, limit string) (*SessionResponse, error) {
+	data := &SessionResponse{}
+	resp, err := NewResty().
+		R().
+		SetResult(&data).
+		SetQueryParam("user", user).
+		SetQueryParam("last_id", lastId).
+		SetQueryParam("limit", limit).
+		Get("/conversations")
+
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return data, nil
+}
+
+// GetChatHistory 获取历史会话
+func GetChatHistory(user, conversationId, firstId, limit string) (*HistoryResponse, error) {
+	data := &HistoryResponse{}
+	resp, err := NewResty().
+		R().
+		SetResult(&data).
+		SetQueryParam("user", user).
+		SetQueryParam("conversation_id", conversationId).
+		SetQueryParam("first_id", firstId).
+		SetQueryParam("limit", limit).
+		Get("/messages")
+
+	if err != nil {
+		return nil, err
+	}
+
+	if resp.IsError() {
+		return nil, errors.New(resp.String())
+	}
+
+	return data, nil
+}
+
+// NewResty 实例化dify实例
+func NewResty() *resty.Client {
+	client := resty.New()
+	client.SetRetryCount(2).
+		SetHeader("Content-Type", "application/json").
+		SetBaseURL("https://dify.gkscrm.com/v1").
+		SetHeader("Authorization", "Bearer "+GetToken())
+
+	return client
+}

+ 44 - 0
internal/handler/User/do_gpts_user_login_handler.go

@@ -0,0 +1,44 @@
+package User
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/User"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /gpts/user/login User DoGptsUserLogin
+//
+// Get user basic information | 获取用户基本信息
+//
+// Get user basic information | 获取用户基本信息
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: GptsUserLoginReq
+//
+// Responses:
+//  200: GptsUserLoginResp
+
+func DoGptsUserLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.GptsUserLoginReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := User.NewDoGptsUserLoginLogic(r.Context(), svcCtx)
+		resp, err := l.DoGptsUserLogin(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 33 - 0
internal/handler/User/get_gpts_user_info_handler.go

@@ -0,0 +1,33 @@
+package User
+
+import (
+	"net/http"
+	jwtutils "wechat-api/internal/utils/jwt"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/User"
+	"wechat-api/internal/svc"
+)
+
+// swagger:route post /gpts/user/info User GetGptsUserInfo
+//
+// Get user basic information | 获取用户基本信息
+//
+// Get user basic information | 获取用户基本信息
+//
+// Responses:
+//  200: BaseDataInfo
+
+func GetGptsUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		l := User.NewGetGptsUserInfoLogic(r.Context(), svcCtx)
+		tokenStr := jwtutils.StripBearerPrefixFromToken(r.Header.Get("Authorization"))
+		resp, err := l.GetGptsUserInfo(tokenStr)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 46 - 0
internal/handler/User/update_gpts_user_pwd_handler.go

@@ -0,0 +1,46 @@
+package User
+
+import (
+	"net/http"
+	jwtutils "wechat-api/internal/utils/jwt"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/User"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /gpts/user/password User UpdateGptsUserPwd
+//
+// Get user basic information | 获取用户基本信息
+//
+// Get user basic information | 获取用户基本信息
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: PasswordReq
+//
+// Responses:
+//  200: BaseDataInfo
+
+func UpdateGptsUserPwdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.PasswordReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		tokenStr := jwtutils.StripBearerPrefixFromToken(r.Header.Get("Authorization"))
+		l := User.NewUpdateGptsUserPwdLogic(r.Context(), svcCtx)
+		resp, err := l.UpdateGptsUserPwd(tokenStr, &req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/allocagent/create_alloc_agent_handler.go

@@ -0,0 +1,44 @@
+package allocagent
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/allocagent"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /alloc_agent/create allocagent CreateAllocAgent
+//
+// Create alloc agent information | 创建AllocAgent
+//
+// Create alloc agent information | 创建AllocAgent
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: AllocAgentInfo
+//
+// Responses:
+//  200: BaseMsgResp
+
+func CreateAllocAgentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.AllocAgentInfo
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := allocagent.NewCreateAllocAgentLogic(r.Context(), svcCtx)
+		resp, err := l.CreateAllocAgent(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/allocagent/delete_alloc_agent_handler.go

@@ -0,0 +1,44 @@
+package allocagent
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/allocagent"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /alloc_agent/delete allocagent DeleteAllocAgent
+//
+// Delete alloc agent information | 删除AllocAgent信息
+//
+// Delete alloc agent information | 删除AllocAgent信息
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: IDsReq
+//
+// Responses:
+//  200: BaseMsgResp
+
+func DeleteAllocAgentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.IDsReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := allocagent.NewDeleteAllocAgentLogic(r.Context(), svcCtx)
+		resp, err := l.DeleteAllocAgent(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/allocagent/get_alloc_agent_by_id_handler.go

@@ -0,0 +1,44 @@
+package allocagent
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/allocagent"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /alloc_agent allocagent GetAllocAgentById
+//
+// Get alloc agent by ID | 通过ID获取AllocAgent
+//
+// Get alloc agent by ID | 通过ID获取AllocAgent
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: IDReq
+//
+// Responses:
+//  200: AllocAgentInfoResp
+
+func GetAllocAgentByIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.IDReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := allocagent.NewGetAllocAgentByIdLogic(r.Context(), svcCtx)
+		resp, err := l.GetAllocAgentById(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/allocagent/get_alloc_agent_list_handler.go

@@ -0,0 +1,44 @@
+package allocagent
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/allocagent"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /alloc_agent/list allocagent GetAllocAgentList
+//
+// Get alloc agent list | 获取AllocAgent列表
+//
+// Get alloc agent list | 获取AllocAgent列表
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: AllocAgentListReq
+//
+// Responses:
+//  200: AllocAgentListResp
+
+func GetAllocAgentListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.AllocAgentListReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := allocagent.NewGetAllocAgentListLogic(r.Context(), svcCtx)
+		resp, err := l.GetAllocAgentList(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/allocagent/update_alloc_agent_handler.go

@@ -0,0 +1,44 @@
+package allocagent
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/allocagent"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /alloc_agent/update allocagent UpdateAllocAgent
+//
+// Update alloc agent information | 更新AllocAgent
+//
+// Update alloc agent information | 更新AllocAgent
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: AllocAgentInfo
+//
+// Responses:
+//  200: BaseMsgResp
+
+func UpdateAllocAgentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.AllocAgentInfo
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := allocagent.NewUpdateAllocAgentLogic(r.Context(), svcCtx)
+		resp, err := l.UpdateAllocAgent(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 45 - 0
internal/handler/chatrecords/gpts_get_api_message_handler.go

@@ -0,0 +1,45 @@
+package chatrecords
+
+import (
+	"net/http"
+	jwtutils "wechat-api/internal/utils/jwt"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/chatrecords"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /gpts/chat/message chatrecords GptsGetApiMessage
+//
+// Create chat records information | 创建ChatRecords
+//
+// Create chat records information | 创建ChatRecords
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: GptMessageReq
+//
+// Responses:
+//  200: GptMessageResp
+
+func GptsGetApiMessageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.GptMessageReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+		tokenStr := jwtutils.StripBearerPrefixFromToken(r.Header.Get("Authorization"))
+		l := chatrecords.NewGptsGetApiMessageLogic(r.Context(), svcCtx)
+		resp, err := l.GptsGetApiMessage(&req, tokenStr)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 45 - 0
internal/handler/chatrecords/gpts_get_api_session_handler.go

@@ -0,0 +1,45 @@
+package chatrecords
+
+import (
+	"net/http"
+	jwtutils "wechat-api/internal/utils/jwt"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/chatrecords"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /gpts/chat/session chatrecords GptsGetApiSession
+//
+// Create chat records information | 创建ChatRecords
+//
+// Create chat records information | 创建ChatRecords
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: GptsSessionReq
+//
+// Responses:
+//  200: GptsSessionResp
+
+func GptsGetApiSessionHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.GptsSessionReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+		tokenStr := jwtutils.StripBearerPrefixFromToken(r.Header.Get("Authorization"))
+		l := chatrecords.NewGptsGetApiSessionLogic(r.Context(), svcCtx)
+		resp, err := l.GptsGetApiSession(&req, tokenStr)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/chatrecords/gpts_submit_api_chat_handler.go

@@ -0,0 +1,44 @@
+package chatrecords
+
+import (
+	"net/http"
+	jwtutils "wechat-api/internal/utils/jwt"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/chatrecords"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /gpts/chat/submit chatrecords GptsSubmitApiChat
+//
+// Create chat records information | 创建ChatRecords
+//
+// Create chat records information | 创建ChatRecords
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: GptChatReq
+//
+
+func GptsSubmitApiChatHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.GptChatReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		tokenStr := jwtutils.StripBearerPrefixFromToken(r.Header.Get("Authorization"))
+		l := chatrecords.NewGptsSubmitApiChatLogic(r.Context(), svcCtx)
+		l.GptsSubmitApiChat(tokenStr, &req, w)
+		//if err != nil {
+		//	httpx.ErrorCtx(r.Context(), w, err)
+		//} else {
+		//	httpx.Ok(w)
+		//}
+	}
+}

+ 3 - 2
internal/handler/employee/get_employee_search_handler.go

@@ -2,6 +2,7 @@ package employee
 
 import (
 	"net/http"
+	jwtutils "wechat-api/internal/utils/jwt"
 
 	"github.com/zeromicro/go-zero/rest/httpx"
 
@@ -32,9 +33,9 @@ func GetEmployeeSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 			httpx.ErrorCtx(r.Context(), w, err)
 			return
 		}
-
+		tokenStr := jwtutils.StripBearerPrefixFromToken(r.Header.Get("Authorization"))
 		l := employee.NewGetEmployeeSearchLogic(r.Context(), svcCtx)
-		resp, err := l.GetEmployeeSearch(&req)
+		resp, err := l.GetEmployeeSearch(&req, tokenStr)
 		if err != nil {
 			httpx.ErrorCtx(r.Context(), w, err)
 		} else {

+ 70 - 0
internal/handler/routes.go

@@ -17,6 +17,7 @@ import (
 	agent "wechat-api/internal/handler/agent"
 	agent_base "wechat-api/internal/handler/agent_base"
 	aliyun_avatar "wechat-api/internal/handler/aliyun_avatar"
+	allocagent "wechat-api/internal/handler/allocagent"
 	avatar "wechat-api/internal/handler/avatar"
 	base "wechat-api/internal/handler/base"
 	batch_msg "wechat-api/internal/handler/batch_msg"
@@ -684,6 +685,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 				Path:    "/api/user/login",
 				Handler: User.DoApiUserLoginHandler(serverCtx),
 			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/gpts/user/login",
+				Handler: User.DoGptsUserLoginHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/gpts/user/info",
+				Handler: User.GetGptsUserInfoHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/gpts/user/password",
+				Handler: User.UpdateGptsUserPwdHandler(serverCtx),
+			},
 		},
 	)
 
@@ -1083,6 +1099,26 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 	)
 
 	server.AddRoutes(
+		[]rest.Route{
+			{
+				Method:  http.MethodPost,
+				Path:    "/gpts/chat/submit",
+				Handler: chatrecords.GptsSubmitApiChatHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/gpts/chat/message",
+				Handler: chatrecords.GptsGetApiMessageHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/gpts/chat/session",
+				Handler: chatrecords.GptsGetApiSessionHandler(serverCtx),
+			},
+		},
+	)
+
+	server.AddRoutes(
 		rest.WithMiddlewares(
 			[]rest.Middleware{serverCtx.Miniprogram},
 			[]rest.Route{
@@ -1471,4 +1507,38 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 		),
 		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
 	)
+
+	server.AddRoutes(
+		rest.WithMiddlewares(
+			[]rest.Middleware{serverCtx.Authority},
+			[]rest.Route{
+				{
+					Method:  http.MethodPost,
+					Path:    "/alloc_agent/create",
+					Handler: allocagent.CreateAllocAgentHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/alloc_agent/update",
+					Handler: allocagent.UpdateAllocAgentHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/alloc_agent/delete",
+					Handler: allocagent.DeleteAllocAgentHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/alloc_agent/list",
+					Handler: allocagent.GetAllocAgentListHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/alloc_agent",
+					Handler: allocagent.GetAllocAgentByIdHandler(serverCtx),
+				},
+			}...,
+		),
+		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
+	)
 }

+ 96 - 0
internal/logic/User/do_gpts_user_login_logic.go

@@ -0,0 +1,96 @@
+package User
+
+import (
+	"context"
+	"fmt"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/utils/pointy"
+	"github.com/suyuan32/simple-admin-core/rpc/types/core"
+	"github.com/zeromicro/go-zero/core/errorx"
+	"strings"
+	"time"
+	"wechat-api/internal/utils"
+	"wechat-api/internal/utils/jwt"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type DoGptsUserLoginLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewDoGptsUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DoGptsUserLoginLogic {
+	return &DoGptsUserLoginLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *DoGptsUserLoginLogic) DoGptsUserLogin(req *types.GptsUserLoginReq) (resp *types.GptsUserLoginResp, err error) {
+	user, err := l.svcCtx.CoreRpc.GetUserByUsername(l.ctx,
+		&core.UsernameReq{
+			Username: *req.Username,
+		})
+
+	if user.Status != nil && *user.Status != uint32(utils.StatusNormal) {
+		return nil, errorx.NewCodeInvalidArgumentError("login.userBanned")
+	}
+
+	if !utils.BcryptCheck(*req.Password, *user.Password) {
+		return nil, errorx.NewCodeInvalidArgumentError("login.wrongUsernameOrPassword")
+	}
+
+	department, err := l.svcCtx.CoreRpc.GetDepartmentById(l.ctx, &core.IDReq{
+		Id: *user.DepartmentId,
+	})
+	if err != nil {
+		return nil, err
+	}
+	fmt.Printf("department=%v\n", department)
+	if *department.Name != "前台用户" {
+		return nil, errorx.NewInvalidArgumentError("用户不允许登陆")
+	}
+
+	token, err := jwt.NewJwtToken(
+		l.svcCtx.Config.Auth.AccessSecret,
+		time.Now().Unix(),
+		l.svcCtx.Config.Auth.AccessExpire,
+		jwt.WithOption("userId", user.Id),
+		jwt.WithOption("roleId", strings.Join(user.RoleCodes, ",")),
+		jwt.WithOption("deptId", user.DepartmentId),
+	)
+	if err != nil {
+		return nil, err
+	}
+
+	// add token into database
+	expiredAt := time.Now().Add(time.Second * time.Duration(l.svcCtx.Config.Auth.AccessExpire)).UnixMilli()
+	_, err = l.svcCtx.CoreRpc.CreateToken(l.ctx, &core.TokenInfo{
+		Uuid:      user.Id,
+		Token:     pointy.GetPointer(token),
+		Source:    pointy.GetPointer("core_user"),
+		Status:    pointy.GetPointer(uint32(utils.StatusNormal)),
+		Username:  user.Username,
+		ExpiredAt: pointy.GetPointer(expiredAt),
+	})
+
+	if err != nil {
+		return nil, err
+	}
+
+	resp = &types.GptsUserLoginResp{
+		BaseDataInfo: types.BaseDataInfo{Msg: errormsg.Success},
+		Data: types.GptsUserToken{
+			ID:         *user.Id,
+			Token:      token,
+			Username:   *user.Username,
+			ExpireTime: uint64(expiredAt),
+		},
+	}
+	return resp, nil
+}

+ 50 - 0
internal/logic/User/get_gpts_user_info_logic.go

@@ -0,0 +1,50 @@
+package User
+
+import (
+	"context"
+	"github.com/suyuan32/simple-admin-core/rpc/types/core"
+	"github.com/zeromicro/go-zero/core/errorx"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+	jwtutils "wechat-api/internal/utils/jwt"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetGptsUserInfoLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGetGptsUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGptsUserInfoLogic {
+	return &GetGptsUserInfoLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *GetGptsUserInfoLogic) GetGptsUserInfo(tokenStr string) (*types.UserInfoResp, error) {
+	resp := types.UserInfoResp{}
+
+	claims, err := jwtutils.ParseJwtToken(l.svcCtx.Config.Auth.AccessSecret, tokenStr)
+	if err != nil {
+		return nil, errorx.NewInvalidArgumentError("用户未登录")
+	}
+
+	userId := claims["userId"].(string)
+	departmentId := claims["deptId"].(float64)
+
+	if userId == "" || departmentId != float64(15) {
+		return nil, errorx.NewInvalidArgumentError("用户需要登录")
+	}
+
+	userInfo, _ := l.svcCtx.CoreRpc.GetUserById(l.ctx, &core.UUIDReq{Id: userId})
+	//department, _ := l.svcCtx.CoreRpc.GetDepartmentById(l.ctx, &core.IDReq{Id: uint64(departmentId)})
+	//resp.Data = fmt.Sprintf("userId=%v departmentId=%v departmentName=%v ", userId, departmentId, *department.Name)
+	resp.Data.Username = userInfo.Username
+	resp.Data.Nickname = userInfo.Nickname
+	resp.Data.Id = &userId
+	resp.Data.Status = userInfo.Status
+	return &resp, nil
+}

+ 63 - 0
internal/logic/User/update_gpts_user_pwd_logic.go

@@ -0,0 +1,63 @@
+package User
+
+import (
+	"context"
+	"fmt"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-core/rpc/types/core"
+	"github.com/zeromicro/go-zero/core/errorx"
+	jwtutils "wechat-api/internal/utils/jwt"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type UpdateGptsUserPwdLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewUpdateGptsUserPwdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateGptsUserPwdLogic {
+	return &UpdateGptsUserPwdLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *UpdateGptsUserPwdLogic) UpdateGptsUserPwd(tokenStr string, req *types.PasswordReq) (*types.BaseDataInfo, error) {
+	claims, err := jwtutils.ParseJwtToken(l.svcCtx.Config.Auth.AccessSecret, tokenStr)
+	if err != nil {
+		return nil, errorx.NewInvalidArgumentError("用户未登录")
+	}
+
+	userId := claims["userId"].(string)
+	departmentId := claims["deptId"].(float64)
+	fmt.Printf("user=%v depid=%v \n", userId, departmentId)
+
+	if userId == "" || departmentId != float64(15) {
+		return nil, errorx.NewInvalidArgumentError("用户需要登录")
+	}
+
+	if req.Password2 == nil || req.Password == nil {
+		return nil, errorx.NewInvalidArgumentError("参数不能为空")
+	}
+	password := *req.Password
+	password2 := *req.Password2
+
+	if password == "" || password2 == "" || password != password2 {
+		return nil, errorx.NewInvalidArgumentError("2次密码需相同,不能为空")
+	}
+
+	_, err = l.svcCtx.CoreRpc.UpdateUser(l.ctx, &core.UserInfo{
+		Id:       &userId,
+		Password: &password,
+	})
+	if err != nil {
+		return nil, err
+	}
+
+	return &types.BaseDataInfo{Msg: errormsg.Success}, nil
+}

+ 51 - 0
internal/logic/allocagent/create_alloc_agent_logic.go

@@ -0,0 +1,51 @@
+package allocagent
+
+import (
+	"context"
+	"github.com/alibabacloud-go/tea/tea"
+	"github.com/zeromicro/go-zero/core/errorx"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+	"wechat-api/internal/utils/dberrorhandler"
+
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type CreateAllocAgentLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewCreateAllocAgentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAllocAgentLogic {
+	return &CreateAllocAgentLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *CreateAllocAgentLogic) CreateAllocAgent(req *types.AllocAgentInfo) (*types.BaseMsgResp, error) {
+	if len(req.Agents) == 0 {
+		return nil, errorx.NewInvalidArgumentError("智能体ID不能为空")
+	}
+	if req.OrganizationId == nil && req.UserId == nil {
+		return nil, errorx.NewInvalidArgumentError("租户ID和用户ID不能都为空")
+	}
+
+	_, err := l.svcCtx.DB.AllocAgent.Create().
+		SetNotNilUserID(req.UserId).
+		SetNotNilOrganizationID(req.OrganizationId).
+		SetNotNilAgents(req.Agents).
+		SetNotNilStatus(tea.Int(1)).
+		Save(l.ctx)
+
+	if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
+
+	return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
+}

+ 37 - 0
internal/logic/allocagent/delete_alloc_agent_logic.go

@@ -0,0 +1,37 @@
+package allocagent
+
+import (
+	"context"
+
+    "wechat-api/ent/allocagent"
+    "wechat-api/internal/svc"
+    "wechat-api/internal/types"
+    "wechat-api/internal/utils/dberrorhandler"
+
+    "github.com/suyuan32/simple-admin-common/msg/errormsg"
+    "github.com/zeromicro/go-zero/core/logx"
+)
+
+type DeleteAllocAgentLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewDeleteAllocAgentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteAllocAgentLogic {
+	return &DeleteAllocAgentLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *DeleteAllocAgentLogic) DeleteAllocAgent(req *types.IDsReq) (*types.BaseMsgResp, error) {
+	_, err := l.svcCtx.DB.AllocAgent.Delete().Where(allocagent.IDIn(req.Ids...)).Exec(l.ctx)
+
+    if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
+
+    return &types.BaseMsgResp{Msg: errormsg.DeleteSuccess}, nil
+}

+ 52 - 0
internal/logic/allocagent/get_alloc_agent_by_id_logic.go

@@ -0,0 +1,52 @@
+package allocagent
+
+import (
+	"context"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+	"wechat-api/internal/utils/dberrorhandler"
+
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+
+	"github.com/suyuan32/simple-admin-common/utils/pointy"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetAllocAgentByIdLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewGetAllocAgentByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAllocAgentByIdLogic {
+	return &GetAllocAgentByIdLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *GetAllocAgentByIdLogic) GetAllocAgentById(req *types.IDReq) (*types.AllocAgentInfoResp, error) {
+	data, err := l.svcCtx.DB.AllocAgent.Get(l.ctx, req.Id)
+	if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
+
+	return &types.AllocAgentInfoResp{
+		BaseDataInfo: types.BaseDataInfo{
+			Code: 0,
+			Msg:  errormsg.Success,
+		},
+		Data: types.AllocAgentInfo{
+			BaseIDInfo: types.BaseIDInfo{
+				Id:        &data.ID,
+				CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
+				UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
+			},
+			UserId:         &data.UserID,
+			OrganizationId: &data.OrganizationID,
+			Agents:         data.Agents,
+			Status:         &data.Status,
+		},
+	}, nil
+}

+ 58 - 0
internal/logic/allocagent/get_alloc_agent_list_logic.go

@@ -0,0 +1,58 @@
+package allocagent
+
+import (
+	"context"
+	"wechat-api/ent/predicate"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+	"wechat-api/internal/utils/dberrorhandler"
+
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+
+	"github.com/suyuan32/simple-admin-common/utils/pointy"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetAllocAgentListLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewGetAllocAgentListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAllocAgentListLogic {
+	return &GetAllocAgentListLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *GetAllocAgentListLogic) GetAllocAgentList(req *types.AllocAgentListReq) (*types.AllocAgentListResp, error) {
+	var predicates []predicate.AllocAgent
+	data, err := l.svcCtx.DB.AllocAgent.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
+
+	if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
+
+	resp := &types.AllocAgentListResp{}
+	resp.Msg = errormsg.Success
+	resp.Data.Total = data.PageDetails.Total
+
+	for _, v := range data.List {
+		resp.Data.Data = append(resp.Data.Data,
+			types.AllocAgentInfo{
+				BaseIDInfo: types.BaseIDInfo{
+					Id:        &v.ID,
+					CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
+					UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
+				},
+				UserId:         &v.UserID,
+				OrganizationId: &v.OrganizationID,
+				Agents:         v.Agents,
+				Status:         &v.Status,
+			})
+	}
+
+	return resp, nil
+}

+ 40 - 0
internal/logic/allocagent/update_alloc_agent_logic.go

@@ -0,0 +1,40 @@
+package allocagent
+
+import (
+	"context"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+	"wechat-api/internal/utils/dberrorhandler"
+
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type UpdateAllocAgentLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewUpdateAllocAgentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateAllocAgentLogic {
+	return &UpdateAllocAgentLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *UpdateAllocAgentLogic) UpdateAllocAgent(req *types.AllocAgentInfo) (*types.BaseMsgResp, error) {
+	err := l.svcCtx.DB.AllocAgent.UpdateOneID(*req.Id).
+		SetNotNilUserID(req.UserId).
+		SetNotNilOrganizationID(req.OrganizationId).
+		SetNotNilAgents(req.Agents).
+		SetNotNilStatus(req.Status).
+		Exec(l.ctx)
+
+	if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
+
+	return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
+}

+ 62 - 0
internal/logic/base/init_api_data.go

@@ -6,6 +6,68 @@ import (
 )
 
 func (l *InitDatabaseLogic) insertApiData() (err error) {
+	// AllocAgent
+
+	_, err = l.svcCtx.CoreRpc.CreateApi(l.ctx, &core.ApiInfo{
+		ServiceName: pointy.GetPointer("Wechat"),
+		Path:        pointy.GetPointer("/alloc_agent/create"),
+		Description: pointy.GetPointer("apiDesc.createAllocAgent"),
+		ApiGroup:    pointy.GetPointer("alloc_agent"),
+		Method:      pointy.GetPointer("POST"),
+	})
+
+	if err != nil {
+		return err
+	}
+
+	_, err = l.svcCtx.CoreRpc.CreateApi(l.ctx, &core.ApiInfo{
+		ServiceName: pointy.GetPointer("Wechat"),
+		Path:        pointy.GetPointer("/alloc_agent/update"),
+		Description: pointy.GetPointer("apiDesc.updateAllocAgent"),
+		ApiGroup:    pointy.GetPointer("alloc_agent"),
+		Method:      pointy.GetPointer("POST"),
+	})
+
+	if err != nil {
+		return err
+	}
+
+	_, err = l.svcCtx.CoreRpc.CreateApi(l.ctx, &core.ApiInfo{
+		ServiceName: pointy.GetPointer("Wechat"),
+		Path:        pointy.GetPointer("/alloc_agent/delete"),
+		Description: pointy.GetPointer("apiDesc.deleteAllocAgent"),
+		ApiGroup:    pointy.GetPointer("alloc_agent"),
+		Method:      pointy.GetPointer("POST"),
+	})
+
+	if err != nil {
+		return err
+	}
+
+	_, err = l.svcCtx.CoreRpc.CreateApi(l.ctx, &core.ApiInfo{
+		ServiceName: pointy.GetPointer("Wechat"),
+		Path:        pointy.GetPointer("/alloc_agent/list"),
+		Description: pointy.GetPointer("apiDesc.getAllocAgentList"),
+		ApiGroup:    pointy.GetPointer("alloc_agent"),
+		Method:      pointy.GetPointer("POST"),
+	})
+
+	if err != nil {
+		return err
+	}
+
+	_, err = l.svcCtx.CoreRpc.CreateApi(l.ctx, &core.ApiInfo{
+		ServiceName: pointy.GetPointer("Wechat"),
+		Path:        pointy.GetPointer("/alloc_agent"),
+		Description: pointy.GetPointer("apiDesc.getAllocAgentById"),
+		ApiGroup:    pointy.GetPointer("alloc_agent"),
+		Method:      pointy.GetPointer("POST"),
+	})
+
+	if err != nil {
+		return err
+	}
+
 	// AliyunAvatar
 
 	_, err = l.svcCtx.CoreRpc.CreateApi(l.ctx, &core.ApiInfo{

+ 63 - 0
internal/logic/chatrecords/gpts_get_api_message_logic.go

@@ -0,0 +1,63 @@
+package chatrecords
+
+import (
+	"context"
+	"github.com/alibabacloud-go/tea/tea"
+	"github.com/zeromicro/go-zero/core/errorx"
+	"strconv"
+	"wechat-api/hook/dify"
+	jwtutils "wechat-api/internal/utils/jwt"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GptsGetApiMessageLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGptsGetApiMessageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GptsGetApiMessageLogic {
+	return &GptsGetApiMessageLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *GptsGetApiMessageLogic) GptsGetApiMessage(req *types.GptMessageReq, tokenStr string) (*types.GptMessageResp, error) {
+	resp := types.GptMessageResp{}
+
+	claims, err := jwtutils.ParseJwtToken(l.svcCtx.Config.Auth.AccessSecret, tokenStr)
+	if err != nil {
+		return nil, errorx.NewInvalidArgumentError("用户未登录")
+	}
+	userId := claims["userId"].(string)
+
+	var firstId, limit string
+	if req.FirstId != nil && *req.FirstId != "" {
+		firstId = *req.FirstId
+	}
+	if req.Limit != nil && *req.Limit > 0 {
+		limit = strconv.Itoa(*req.Limit)
+	}
+	response, err := dify.GetChatHistory(userId, *req.ConversationId, firstId, limit)
+	if err != nil {
+		return nil, err
+	}
+
+	for _, v := range response.Data {
+		resp.Data = append(resp.Data, types.Message{
+			Id:             &v.ID,
+			ConversationId: &v.ConversationId,
+			Answer:         &v.Answer,
+			Query:          &v.Query,
+			Inputs:         &v.Inputs,
+			CreatedAt:      tea.Int(int(v.CreatedAt)),
+		})
+	}
+
+	return &resp, nil
+}

+ 61 - 0
internal/logic/chatrecords/gpts_get_api_session_logic.go

@@ -0,0 +1,61 @@
+package chatrecords
+
+import (
+	"context"
+	"fmt"
+	"github.com/alibabacloud-go/tea/tea"
+	"github.com/zeromicro/go-zero/core/errorx"
+	"strconv"
+	"wechat-api/hook/dify"
+	jwtutils "wechat-api/internal/utils/jwt"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GptsGetApiSessionLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGptsGetApiSessionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GptsGetApiSessionLogic {
+	return &GptsGetApiSessionLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *GptsGetApiSessionLogic) GptsGetApiSession(req *types.GptsSessionReq, tokenStr string) (*types.GptsSessionResp, error) {
+	resp := types.GptsSessionResp{}
+
+	claims, err := jwtutils.ParseJwtToken(l.svcCtx.Config.Auth.AccessSecret, tokenStr)
+	if err != nil {
+		return nil, errorx.NewInvalidArgumentError("用户未登录")
+	}
+	fmt.Printf("claims=%v \n", claims)
+	userId := claims["userId"].(string)
+
+	limit := strconv.Itoa(*req.Limit)
+	var lastId string
+	if req.LastId != nil && *req.LastId != "" {
+		lastId = *req.LastId
+	}
+	response, err := dify.GetSessionList(userId, lastId, limit)
+	if err != nil {
+		return nil, err
+	}
+
+	for _, v := range response.Data {
+		resp.Data = append(resp.Data, types.Session{
+			Id:        &v.ID,
+			Name:      &v.Name,
+			Inputs:    &v.Inputs,
+			CreatedAt: tea.Int(int(v.CreatedAt)),
+		})
+	}
+
+	return &resp, nil
+}

+ 154 - 0
internal/logic/chatrecords/gpts_submit_api_chat_logic.go

@@ -0,0 +1,154 @@
+package chatrecords
+
+import (
+	"bufio"
+	"bytes"
+	"context"
+	"encoding/json"
+	"fmt"
+	"io"
+	"net/http"
+	"strings"
+	"time"
+	"wechat-api/hook/dify"
+	jwtutils "wechat-api/internal/utils/jwt"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GptsSubmitApiChatLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGptsSubmitApiChatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GptsSubmitApiChatLogic {
+	return &GptsSubmitApiChatLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *GptsSubmitApiChatLogic) GptsSubmitApiChat(tokenStr string, req *types.GptChatReq, w http.ResponseWriter) {
+	flusher, ok := w.(http.Flusher)
+	if !ok {
+		return
+	}
+
+	claims, err := jwtutils.ParseJwtToken(l.svcCtx.Config.Auth.AccessSecret, tokenStr)
+	if err != nil {
+		jsonData := ChatMessage{}
+		jsonData.NeedLogin = true
+		jsonData.Finish = true
+		jsonDataStr, _ := json.Marshal(jsonData)
+		_, _ = fmt.Fprintf(w, "%s", "data: "+string(jsonDataStr)+"\r\n")
+		flusher.Flush()
+		return
+	}
+
+	userId := claims["userId"].(string) //用户的uuid
+	departmentId := claims["deptId"].(float64)
+	fmt.Println(userId, departmentId, departmentId == float64(15))
+	if departmentId == float64(15) {
+	} else {
+		jsonData := ChatMessage{}
+		jsonData.NeedPay = true
+		jsonData.Finish = true
+		jsonDataStr, _ := json.Marshal(jsonData)
+		_, _ = fmt.Fprintf(w, "%s", "data: "+string(jsonDataStr)+"\r\n")
+		flusher.Flush()
+		return
+	}
+
+	var chatReq dify.ChatReq
+	chatReq.ResponseMode = "streaming"
+	chatReq.Query = *req.Content
+	chatReq.User = userId
+
+	chatReq.ConversationId = *req.ConversationId
+
+	// 設置請求體 (這裡是一個簡單的範例,你可以根據需要調整)
+	jsonData, _ := json.Marshal(chatReq)
+	fmt.Printf("request data:%v\n", string(jsonData))
+
+	// 建立HTTP請求
+	url := dify.GetBaseUrl() + dify.GetChatUrl() // 替換為正確的FastGPT API端點
+	request, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
+	if err != nil {
+		fmt.Printf("Error creating request:%v", err)
+		return
+	}
+
+	// 設置請求頭
+	request.Header.Set("Content-Type", "application/json")
+	request.Header.Set("Authorization", "Bearer "+dify.GetToken())
+	request.Header.Set("Transfer-Encoding", "chunked")
+
+	// 發送請求
+	client := &http.Client{
+		Timeout: time.Second * 60,
+	}
+	response, err := client.Do(request)
+	defer response.Body.Close()
+
+	// 讀取響應
+	reader := bufio.NewReader(response.Body)
+
+	w.Header().Set("Content-Type", "text/event-stream;charset=utf-8")
+	w.Header().Set("Connection", "keep-alive")
+	w.Header().Set("Cache-Control", "no-cache")
+
+	for {
+		line, err := reader.ReadString('\n')
+		line = strings.Trim(line, " \n")
+
+		if err == io.EOF {
+			break
+		}
+
+		if len(line) > 6 {
+			line = line[6:]
+			chatData := dify.ChatResp{}
+			err = json.Unmarshal([]byte(line), &chatData)
+			if err != nil {
+				fmt.Printf("json unmarshall error:%v\n", err)
+				fmt.Printf("line:%v\n", line)
+				break
+			}
+
+			var finish bool
+			if chatData.Event == "message_end" {
+				finish = true
+			}
+
+			// 将 ConversationId 与 sessionId 建立关联关系
+			if chatData.ConversationId != "" {
+
+			}
+
+			jsonData := ChatMessage{}
+			jsonData.Id = chatData.Id
+			//jsonData.SessionId = c
+			jsonData.Answer = chatData.Answer
+			jsonData.MessageId = chatData.MessageId
+			jsonData.Finish = finish
+			jsonData.ConversationId = chatData.ConversationId
+			lineData, _ := json.Marshal(jsonData)
+
+			_, err = fmt.Fprintf(w, "%s", "data: "+string(lineData)+"\r\n")
+			fmt.Printf("response=%v\n", string(lineData))
+			if err != nil {
+				fmt.Printf("Error writing to client:%v \n", err)
+				break
+			}
+			flusher.Flush()
+
+			if finish {
+				break
+			}
+		}
+	}
+}

+ 2 - 0
internal/logic/chatrecords/submit_api_chat_logic.go

@@ -32,6 +32,8 @@ type ChatMessage struct {
 	ConversationId string `json:"conversation_id,optional"`
 	Answer         string `json:"answer"`
 	Finish         bool   `json:"finish"`
+	NeedPay        bool   `json:"need_pay"`
+	NeedLogin      bool   `json:"need_login"`
 }
 
 type SubmitApiChatLogic struct {

+ 46 - 11
internal/logic/employee/get_employee_search_logic.go

@@ -4,10 +4,14 @@ import (
 	"context"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"github.com/suyuan32/simple-admin-common/utils/pointy"
+	"github.com/zeromicro/go-zero/core/errorx"
+	"wechat-api/ent"
+	"wechat-api/ent/allocagent"
 	"wechat-api/ent/employee"
 	"wechat-api/ent/employeeconfig"
 	"wechat-api/ent/predicate"
 	"wechat-api/internal/utils/dberrorhandler"
+	jwtutils "wechat-api/internal/utils/jwt"
 
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
@@ -28,22 +32,53 @@ func NewGetEmployeeSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 		svcCtx: svcCtx}
 }
 
-func (l *GetEmployeeSearchLogic) GetEmployeeSearch(req *types.EmployeeListReq) (*types.EmployeeListResp, error) {
+func (l *GetEmployeeSearchLogic) GetEmployeeSearch(req *types.EmployeeListReq, tokenStr string) (*types.EmployeeListResp, error) {
 	//organizationId := l.ctx.Value("organizationId").(uint64)
 
-	var predicates []predicate.Employee
-	//predicates = append(predicates, employee.OrganizationIDEQ(organizationId))
-
-	if req.Title != nil && *req.Title != "" {
-		predicates = append(predicates, employee.TitleContains(*req.Title))
-	}
-	if req.CategoryId != nil && *req.CategoryId > 0 {
-		predicates = append(predicates, employee.CategoryIDEQ(*req.CategoryId))
+	var isLogin bool
+	claims, err := jwtutils.ParseJwtToken(l.svcCtx.Config.Auth.AccessSecret, tokenStr)
+	if err != nil {
+		isLogin = false
 	}
-	data, err := l.svcCtx.DB.Employee.Query().Where(predicates...).WithEmWorkExperiences().WithEmTutorial().Page(l.ctx, req.Page, req.PageSize)
 
+	userId := claims["userId"].(string)
+	departmentId := claims["deptId"].(float64)
+	organizationID := uint64(departmentId)
+	isLogin = true
+
+	employeeIds := make([]uint64, 0)
+	allocagent, err := l.svcCtx.DB.AllocAgent.Query().Where(
+		allocagent.UserIDEQ(userId),
+		allocagent.Or(
+			allocagent.OrganizationID(organizationID),
+		),
+	).Only(l.ctx)
 	if err != nil {
-		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+		if !ent.IsNotFound(err) {
+			return nil, errorx.NewApiInternalError("获取智能体信息失败")
+		}
+	} else {
+		employeeIds = append(employeeIds, allocagent.Agents...)
+	}
+
+	var data *ent.EmployeePageList
+	if !isLogin || len(employeeIds) == 0 {
+		var predicates []predicate.Employee
+		//predicates = append(predicates, employee.OrganizationIDEQ(organizationId))
+
+		if req.Title != nil && *req.Title != "" {
+			predicates = append(predicates, employee.TitleContains(*req.Title))
+		}
+		if req.CategoryId != nil && *req.CategoryId > 0 {
+			predicates = append(predicates, employee.CategoryIDEQ(*req.CategoryId))
+		}
+		data, err = l.svcCtx.DB.Employee.Query().Where(predicates...).WithEmWorkExperiences().WithEmTutorial().Page(l.ctx, req.Page, req.PageSize)
+
+		if err != nil {
+			return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+		}
+	} else {
+		data, err = l.svcCtx.DB.Employee.Query().Where(employee.IDIn(employeeIds...)).WithEmWorkExperiences().WithEmTutorial().Page(l.ctx, req.Page, req.PageSize)
 	}
 
 	resp := &types.EmployeeListResp{}

+ 1 - 0
internal/middleware/authority_middleware.go

@@ -67,6 +67,7 @@ func (m *AuthorityMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
 			}
 			// 将 data.DepartmentID 插入上下文,以供后续接口使用
 			//fmt.Printf("---------------departmentId----------------: %d\n\n", *data.DepartmentId)
+			r = r.WithContext(context.WithValue(r.Context(), "userIdStr", userIdStr))
 			r = r.WithContext(context.WithValue(r.Context(), "organizationId", *data.DepartmentId))
 			r = r.WithContext(context.WithValue(r.Context(), "isAdmin", stringInSlice(roleIds, []string{"001"})))
 			next(w, r)

+ 119 - 0
internal/types/types.go

@@ -1700,6 +1700,31 @@ type UserLoginResp struct {
 	Data UserToken `json:"data,optional"`
 }
 
+// swagger:model GptsUserLoginReq
+type GptsUserLoginReq struct {
+	Username *string `json:"username"`
+	Password *string `json:"password"`
+}
+
+// swagger:model GptsUserLoginResp
+type GptsUserLoginResp struct {
+	BaseDataInfo
+	Data GptsUserToken `json:"data,optional"`
+}
+
+type GptsUserToken struct {
+	ID         string `json:"id,optional"`
+	Token      string `json:"token,optional"`
+	Username   string `json:"username,optional"`
+	ExpireTime uint64 `json:"expireTime,optional"`
+}
+
+// swagger:model PasswordReq
+type PasswordReq struct {
+	Password  *string `json:"password"`
+	Password2 *string `json:"password2"`
+}
+
 type UserToken struct {
 	Token    *string `json:"token,optional"`
 	ID       *uint64 `json:"id,optional"`
@@ -2341,6 +2366,54 @@ type ChatAskResp struct {
 	Data *string `json:"data"`
 }
 
+// swagger:model GptChatReq
+type GptChatReq struct {
+	ConversationId *string `json:"conversationId,optional"`
+	Content        *string `json:"content"`
+}
+
+// swagger:model GptMessageReq
+type GptMessageReq struct {
+	ConversationId *string `json:"conversationId,optional"`
+	FirstId        *string `json:"firstId,optional"`
+	Limit          *int    `json:"limit"`
+}
+
+// swagger:model GptMessageResp
+type GptMessageResp struct {
+	BaseDataInfo
+	Data []Message `json:"data"`
+}
+
+type Message struct {
+	Id             *string     `json:"id"`
+	ConversationId *string     `json:"conversationId,optional"`
+	Query          *string     `json:"query"`
+	Answer         *string     `json:"answer"`
+	Inputs         interface{} `json:"inputs"`
+	CreatedAt      *int        `json:"createdAt"`
+}
+
+// swagger:model GptsSessionReq
+type GptsSessionReq struct {
+	Limit  *int    `json:"limit"`
+	LastId *string `json:"lastId,optional"`
+}
+
+// swagger:model GptsSessionResp
+type GptsSessionResp struct {
+	BaseDataInfo
+	Data []Session `json:"data"`
+}
+
+type Session struct {
+	Id        *string     `json:"id"`
+	Name      *string     `json:"name"`
+	Status    *string     `json:"status"`
+	CreatedAt *int        `json:"createdAt"`
+	Inputs    interface{} `json:"inputs"`
+}
+
 // The data of chat session information | ChatSession信息
 // swagger:model ChatSessionInfo
 type ChatSessionInfo struct {
@@ -2890,3 +2963,49 @@ type UsageTotalListReq struct {
 	// 租户id
 	OrganizationId *uint64 `json:"organizationId,optional"`
 }
+
+// The data of alloc agent information | AllocAgent信息
+// swagger:model AllocAgentInfo
+type AllocAgentInfo struct {
+	BaseIDInfo
+	// user_id | 前台用户ID
+	UserId *string `json:"userId,optional"`
+	// organization_id | 租户ID
+	OrganizationId *uint64 `json:"organizationId,optional"`
+	// agents | 分配的智能体IDs
+	Agents []uint64 `json:"agents,optional"`
+	// status | 状态 1-正常 2-禁用
+	Status *int `json:"status,optional"`
+}
+
+// The response data of alloc agent list | AllocAgent列表数据
+// swagger:model AllocAgentListResp
+type AllocAgentListResp struct {
+	BaseDataInfo
+	// AllocAgent list data | AllocAgent列表数据
+	Data AllocAgentListInfo `json:"data"`
+}
+
+// AllocAgent list data | AllocAgent列表数据
+// swagger:model AllocAgentListInfo
+type AllocAgentListInfo struct {
+	BaseListInfo
+	// The API list data | AllocAgent列表数据
+	Data []AllocAgentInfo `json:"data"`
+}
+
+// Get alloc agent list request params | AllocAgent列表请求参数
+// swagger:model AllocAgentListReq
+type AllocAgentListReq struct {
+	PageInfo
+	// agents | 分配的智能体IDs
+	Agents *string `json:"agents,optional"`
+}
+
+// AllocAgent information response | AllocAgent信息返回体
+// swagger:model AllocAgentInfoResp
+type AllocAgentInfoResp struct {
+	BaseDataInfo
+	// AllocAgent information | AllocAgent数据
+	Data AllocAgentInfo `json:"data"`
+}

+ 29 - 0
internal/utils/encrypt.go

@@ -0,0 +1,29 @@
+package utils
+
+// Copyright 2023 The Ryan SU Authors (https://github.com/suyuan32). All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import (
+	"golang.org/x/crypto/bcrypt"
+)
+
+func BcryptEncrypt(password string) string {
+	bytes, _ := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
+	return string(bytes)
+}
+
+func BcryptCheck(password, hash string) bool {
+	err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
+	return err == nil
+}

+ 12 - 0
internal/utils/status.go

@@ -0,0 +1,12 @@
+package utils
+
+const (
+	StatusNormal uint8 = 1
+	StatusBanned uint8 = 2
+)
+
+const (
+	DefaultParentId uint64 = 1000000
+	// DefaultInvalidRoleId used to judge whether the token belongs to core, if it is DefaultInvalidRoleId, it belongs to mms
+	DefaultInvalidRoleId uint64 = 1000000
+)