Selaa lähdekoodia

fix:add token/api/list

jimmyyem 3 kuukautta sitten
vanhempi
commit
683a4e7b18

+ 3 - 0
desc/wechat/sop_stage.api

@@ -75,6 +75,9 @@ type (
 
         // 组织ID
         OrganizationId *uint64 `json:"organizationId,optional"`
+
+		// Token
+		Token *string `json:"token"`
     }
 
     // The response data of sop node information | SopNode信息

+ 4 - 0
desc/wechat/token.api

@@ -140,6 +140,10 @@ service Wechat {
 	@handler getTokenList
 	post /token/third/list (TokenListReq) returns (TokenListResp)
 
+	// Get token list | 获取Token列表
+	@handler getApiTokenList
+	post /token/api/list (TokenListReq) returns (TokenListResp)
+
 	// Get token by ID | 通过ID获取Token
 	@handler getTokenById
 	post /token/third/detail (IDReq) returns (TokenInfoResp)

+ 6 - 0
ent/migrate/schema.go

@@ -616,6 +616,7 @@ var (
 		{Name: "plan_end_time", Type: field.TypeTime, Nullable: true, Comment: "任务计划结束时间"},
 		{Name: "creator_id", Type: field.TypeString, Nullable: true, Comment: "创建者 id"},
 		{Name: "organization_id", Type: field.TypeUint64, Nullable: true, Comment: "机构 ID", Default: 1},
+		{Name: "token", Type: field.TypeString, Nullable: true, Comment: "Token", Default: ""},
 	}
 	// SopTaskTable holds the schema information for the "sop_task" table.
 	SopTaskTable = &schema.Table{
@@ -628,6 +629,11 @@ var (
 				Unique:  false,
 				Columns: []*schema.Column{SopTaskColumns[5]},
 			},
+			{
+				Name:    "soptask_token",
+				Unique:  false,
+				Columns: []*schema.Column{SopTaskColumns[12]},
+			},
 		},
 	}
 	// TokenColumns holds the columns for the "token" table.

+ 74 - 1
ent/mutation.go

@@ -21080,6 +21080,7 @@ type SopTaskMutation struct {
 	creator_id          *string
 	organization_id     *uint64
 	addorganization_id  *int64
+	token               *string
 	clearedFields       map[string]struct{}
 	task_stages         map[uint64]struct{}
 	removedtask_stages  map[uint64]struct{}
@@ -21758,6 +21759,55 @@ func (m *SopTaskMutation) ResetOrganizationID() {
 	delete(m.clearedFields, soptask.FieldOrganizationID)
 }
 
+// SetToken sets the "token" field.
+func (m *SopTaskMutation) SetToken(s string) {
+	m.token = &s
+}
+
+// Token returns the value of the "token" field in the mutation.
+func (m *SopTaskMutation) Token() (r string, exists bool) {
+	v := m.token
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldToken returns the old "token" field's value of the SopTask entity.
+// If the SopTask 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 *SopTaskMutation) OldToken(ctx context.Context) (v string, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldToken is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldToken requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldToken: %w", err)
+	}
+	return oldValue.Token, nil
+}
+
+// ClearToken clears the value of the "token" field.
+func (m *SopTaskMutation) ClearToken() {
+	m.token = nil
+	m.clearedFields[soptask.FieldToken] = struct{}{}
+}
+
+// TokenCleared returns if the "token" field was cleared in this mutation.
+func (m *SopTaskMutation) TokenCleared() bool {
+	_, ok := m.clearedFields[soptask.FieldToken]
+	return ok
+}
+
+// ResetToken resets all changes to the "token" field.
+func (m *SopTaskMutation) ResetToken() {
+	m.token = nil
+	delete(m.clearedFields, soptask.FieldToken)
+}
+
 // AddTaskStageIDs adds the "task_stages" edge to the SopStage entity by ids.
 func (m *SopTaskMutation) AddTaskStageIDs(ids ...uint64) {
 	if m.task_stages == nil {
@@ -21846,7 +21896,7 @@ func (m *SopTaskMutation) Type() string {
 // order to get all numeric fields that were incremented/decremented, call
 // AddedFields().
 func (m *SopTaskMutation) Fields() []string {
-	fields := make([]string, 0, 11)
+	fields := make([]string, 0, 12)
 	if m.created_at != nil {
 		fields = append(fields, soptask.FieldCreatedAt)
 	}
@@ -21880,6 +21930,9 @@ func (m *SopTaskMutation) Fields() []string {
 	if m.organization_id != nil {
 		fields = append(fields, soptask.FieldOrganizationID)
 	}
+	if m.token != nil {
+		fields = append(fields, soptask.FieldToken)
+	}
 	return fields
 }
 
@@ -21910,6 +21963,8 @@ func (m *SopTaskMutation) Field(name string) (ent.Value, bool) {
 		return m.CreatorID()
 	case soptask.FieldOrganizationID:
 		return m.OrganizationID()
+	case soptask.FieldToken:
+		return m.Token()
 	}
 	return nil, false
 }
@@ -21941,6 +21996,8 @@ func (m *SopTaskMutation) OldField(ctx context.Context, name string) (ent.Value,
 		return m.OldCreatorID(ctx)
 	case soptask.FieldOrganizationID:
 		return m.OldOrganizationID(ctx)
+	case soptask.FieldToken:
+		return m.OldToken(ctx)
 	}
 	return nil, fmt.Errorf("unknown SopTask field %s", name)
 }
@@ -22027,6 +22084,13 @@ func (m *SopTaskMutation) SetField(name string, value ent.Value) error {
 		}
 		m.SetOrganizationID(v)
 		return nil
+	case soptask.FieldToken:
+		v, ok := value.(string)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetToken(v)
+		return nil
 	}
 	return fmt.Errorf("unknown SopTask field %s", name)
 }
@@ -22117,6 +22181,9 @@ func (m *SopTaskMutation) ClearedFields() []string {
 	if m.FieldCleared(soptask.FieldOrganizationID) {
 		fields = append(fields, soptask.FieldOrganizationID)
 	}
+	if m.FieldCleared(soptask.FieldToken) {
+		fields = append(fields, soptask.FieldToken)
+	}
 	return fields
 }
 
@@ -22152,6 +22219,9 @@ func (m *SopTaskMutation) ClearField(name string) error {
 	case soptask.FieldOrganizationID:
 		m.ClearOrganizationID()
 		return nil
+	case soptask.FieldToken:
+		m.ClearToken()
+		return nil
 	}
 	return fmt.Errorf("unknown SopTask nullable field %s", name)
 }
@@ -22193,6 +22263,9 @@ func (m *SopTaskMutation) ResetField(name string) error {
 	case soptask.FieldOrganizationID:
 		m.ResetOrganizationID()
 		return nil
+	case soptask.FieldToken:
+		m.ResetToken()
+		return nil
 	}
 	return fmt.Errorf("unknown SopTask field %s", name)
 }

+ 4 - 0
ent/runtime/runtime.go

@@ -820,6 +820,10 @@ func init() {
 	soptaskDescOrganizationID := soptaskFields[6].Descriptor()
 	// soptask.DefaultOrganizationID holds the default value on creation for the organization_id field.
 	soptask.DefaultOrganizationID = soptaskDescOrganizationID.Default.(uint64)
+	// soptaskDescToken is the schema descriptor for token field.
+	soptaskDescToken := soptaskFields[7].Descriptor()
+	// soptask.DefaultToken holds the default value on creation for the token field.
+	soptask.DefaultToken = soptaskDescToken.Default.(string)
 	tokenMixin := schema.Token{}.Mixin()
 	tokenMixinHooks1 := tokenMixin[1].Hooks()
 	token.Hooks[0] = tokenMixinHooks1[0]

+ 4 - 0
ent/schema/sop_task.go

@@ -39,6 +39,9 @@ func (SopTask) Fields() []ent.Field {
 		field.Uint64("organization_id").Optional().Default(1).
 			Comment("机构 ID").
 			Annotations(entsql.WithComments(true)),
+		field.String("token").Optional().Default("").
+			Comment("Token").
+			Annotations(entsql.WithComments(true)),
 	}
 }
 
@@ -53,6 +56,7 @@ func (SopTask) Mixin() []ent.Mixin {
 func (SopTask) Indexes() []ent.Index {
 	return []ent.Index{
 		index.Fields("name"),
+		index.Fields("token"),
 	}
 }
 

+ 24 - 0
ent/set_not_nil.go

@@ -4688,6 +4688,30 @@ func (st *SopTaskCreate) SetNotNilOrganizationID(value *uint64) *SopTaskCreate {
 }
 
 // set field if value's pointer is not nil.
+func (st *SopTaskUpdate) SetNotNilToken(value *string) *SopTaskUpdate {
+	if value != nil {
+		return st.SetToken(*value)
+	}
+	return st
+}
+
+// set field if value's pointer is not nil.
+func (st *SopTaskUpdateOne) SetNotNilToken(value *string) *SopTaskUpdateOne {
+	if value != nil {
+		return st.SetToken(*value)
+	}
+	return st
+}
+
+// set field if value's pointer is not nil.
+func (st *SopTaskCreate) SetNotNilToken(value *string) *SopTaskCreate {
+	if value != nil {
+		return st.SetToken(*value)
+	}
+	return st
+}
+
+// set field if value's pointer is not nil.
 func (t *TokenUpdate) SetNotNilUpdatedAt(value *time.Time) *TokenUpdate {
 	if value != nil {
 		return t.SetUpdatedAt(*value)

+ 12 - 1
ent/soptask.go

@@ -40,6 +40,8 @@ type SopTask struct {
 	CreatorID string `json:"creator_id,omitempty"`
 	// 机构 ID
 	OrganizationID uint64 `json:"organization_id,omitempty"`
+	// Token
+	Token string `json:"token,omitempty"`
 	// Edges holds the relations/edges for other nodes in the graph.
 	// The values are being populated by the SopTaskQuery when eager-loading is set.
 	Edges        SopTaskEdges `json:"edges"`
@@ -73,7 +75,7 @@ func (*SopTask) scanValues(columns []string) ([]any, error) {
 			values[i] = new([]byte)
 		case soptask.FieldID, soptask.FieldStatus, soptask.FieldType, soptask.FieldOrganizationID:
 			values[i] = new(sql.NullInt64)
-		case soptask.FieldName, soptask.FieldCreatorID:
+		case soptask.FieldName, soptask.FieldCreatorID, soptask.FieldToken:
 			values[i] = new(sql.NullString)
 		case soptask.FieldCreatedAt, soptask.FieldUpdatedAt, soptask.FieldDeletedAt, soptask.FieldPlanStartTime, soptask.FieldPlanEndTime:
 			values[i] = new(sql.NullTime)
@@ -166,6 +168,12 @@ func (st *SopTask) assignValues(columns []string, values []any) error {
 			} else if value.Valid {
 				st.OrganizationID = uint64(value.Int64)
 			}
+		case soptask.FieldToken:
+			if value, ok := values[i].(*sql.NullString); !ok {
+				return fmt.Errorf("unexpected type %T for field token", values[i])
+			} else if value.Valid {
+				st.Token = value.String
+			}
 		default:
 			st.selectValues.Set(columns[i], values[i])
 		}
@@ -239,6 +247,9 @@ func (st *SopTask) String() string {
 	builder.WriteString(", ")
 	builder.WriteString("organization_id=")
 	builder.WriteString(fmt.Sprintf("%v", st.OrganizationID))
+	builder.WriteString(", ")
+	builder.WriteString("token=")
+	builder.WriteString(st.Token)
 	builder.WriteByte(')')
 	return builder.String()
 }

+ 10 - 0
ent/soptask/soptask.go

@@ -37,6 +37,8 @@ const (
 	FieldCreatorID = "creator_id"
 	// FieldOrganizationID holds the string denoting the organization_id field in the database.
 	FieldOrganizationID = "organization_id"
+	// FieldToken holds the string denoting the token field in the database.
+	FieldToken = "token"
 	// EdgeTaskStages holds the string denoting the task_stages edge name in mutations.
 	EdgeTaskStages = "task_stages"
 	// Table holds the table name of the soptask in the database.
@@ -64,6 +66,7 @@ var Columns = []string{
 	FieldPlanEndTime,
 	FieldCreatorID,
 	FieldOrganizationID,
+	FieldToken,
 }
 
 // ValidColumn reports if the column name is valid (part of the table columns).
@@ -98,6 +101,8 @@ var (
 	DefaultType int
 	// DefaultOrganizationID holds the default value on creation for the "organization_id" field.
 	DefaultOrganizationID uint64
+	// DefaultToken holds the default value on creation for the "token" field.
+	DefaultToken string
 )
 
 // OrderOption defines the ordering options for the SopTask queries.
@@ -158,6 +163,11 @@ func ByOrganizationID(opts ...sql.OrderTermOption) OrderOption {
 	return sql.OrderByField(FieldOrganizationID, opts...).ToFunc()
 }
 
+// ByToken orders the results by the token field.
+func ByToken(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldToken, opts...).ToFunc()
+}
+
 // ByTaskStagesCount orders the results by task_stages count.
 func ByTaskStagesCount(opts ...sql.OrderTermOption) OrderOption {
 	return func(s *sql.Selector) {

+ 80 - 0
ent/soptask/where.go

@@ -105,6 +105,11 @@ func OrganizationID(v uint64) predicate.SopTask {
 	return predicate.SopTask(sql.FieldEQ(FieldOrganizationID, v))
 }
 
+// Token applies equality check predicate on the "token" field. It's identical to TokenEQ.
+func Token(v string) predicate.SopTask {
+	return predicate.SopTask(sql.FieldEQ(FieldToken, v))
+}
+
 // CreatedAtEQ applies the EQ predicate on the "created_at" field.
 func CreatedAtEQ(v time.Time) predicate.SopTask {
 	return predicate.SopTask(sql.FieldEQ(FieldCreatedAt, v))
@@ -625,6 +630,81 @@ func OrganizationIDNotNil() predicate.SopTask {
 	return predicate.SopTask(sql.FieldNotNull(FieldOrganizationID))
 }
 
+// TokenEQ applies the EQ predicate on the "token" field.
+func TokenEQ(v string) predicate.SopTask {
+	return predicate.SopTask(sql.FieldEQ(FieldToken, v))
+}
+
+// TokenNEQ applies the NEQ predicate on the "token" field.
+func TokenNEQ(v string) predicate.SopTask {
+	return predicate.SopTask(sql.FieldNEQ(FieldToken, v))
+}
+
+// TokenIn applies the In predicate on the "token" field.
+func TokenIn(vs ...string) predicate.SopTask {
+	return predicate.SopTask(sql.FieldIn(FieldToken, vs...))
+}
+
+// TokenNotIn applies the NotIn predicate on the "token" field.
+func TokenNotIn(vs ...string) predicate.SopTask {
+	return predicate.SopTask(sql.FieldNotIn(FieldToken, vs...))
+}
+
+// TokenGT applies the GT predicate on the "token" field.
+func TokenGT(v string) predicate.SopTask {
+	return predicate.SopTask(sql.FieldGT(FieldToken, v))
+}
+
+// TokenGTE applies the GTE predicate on the "token" field.
+func TokenGTE(v string) predicate.SopTask {
+	return predicate.SopTask(sql.FieldGTE(FieldToken, v))
+}
+
+// TokenLT applies the LT predicate on the "token" field.
+func TokenLT(v string) predicate.SopTask {
+	return predicate.SopTask(sql.FieldLT(FieldToken, v))
+}
+
+// TokenLTE applies the LTE predicate on the "token" field.
+func TokenLTE(v string) predicate.SopTask {
+	return predicate.SopTask(sql.FieldLTE(FieldToken, v))
+}
+
+// TokenContains applies the Contains predicate on the "token" field.
+func TokenContains(v string) predicate.SopTask {
+	return predicate.SopTask(sql.FieldContains(FieldToken, v))
+}
+
+// TokenHasPrefix applies the HasPrefix predicate on the "token" field.
+func TokenHasPrefix(v string) predicate.SopTask {
+	return predicate.SopTask(sql.FieldHasPrefix(FieldToken, v))
+}
+
+// TokenHasSuffix applies the HasSuffix predicate on the "token" field.
+func TokenHasSuffix(v string) predicate.SopTask {
+	return predicate.SopTask(sql.FieldHasSuffix(FieldToken, v))
+}
+
+// TokenIsNil applies the IsNil predicate on the "token" field.
+func TokenIsNil() predicate.SopTask {
+	return predicate.SopTask(sql.FieldIsNull(FieldToken))
+}
+
+// TokenNotNil applies the NotNil predicate on the "token" field.
+func TokenNotNil() predicate.SopTask {
+	return predicate.SopTask(sql.FieldNotNull(FieldToken))
+}
+
+// TokenEqualFold applies the EqualFold predicate on the "token" field.
+func TokenEqualFold(v string) predicate.SopTask {
+	return predicate.SopTask(sql.FieldEqualFold(FieldToken, v))
+}
+
+// TokenContainsFold applies the ContainsFold predicate on the "token" field.
+func TokenContainsFold(v string) predicate.SopTask {
+	return predicate.SopTask(sql.FieldContainsFold(FieldToken, v))
+}
+
 // HasTaskStages applies the HasEdge predicate on the "task_stages" edge.
 func HasTaskStages() predicate.SopTask {
 	return predicate.SopTask(func(s *sql.Selector) {

+ 82 - 0
ent/soptask_create.go

@@ -161,6 +161,20 @@ func (stc *SopTaskCreate) SetNillableOrganizationID(u *uint64) *SopTaskCreate {
 	return stc
 }
 
+// SetToken sets the "token" field.
+func (stc *SopTaskCreate) SetToken(s string) *SopTaskCreate {
+	stc.mutation.SetToken(s)
+	return stc
+}
+
+// SetNillableToken sets the "token" field if the given value is not nil.
+func (stc *SopTaskCreate) SetNillableToken(s *string) *SopTaskCreate {
+	if s != nil {
+		stc.SetToken(*s)
+	}
+	return stc
+}
+
 // SetID sets the "id" field.
 func (stc *SopTaskCreate) SetID(u uint64) *SopTaskCreate {
 	stc.mutation.SetID(u)
@@ -245,6 +259,10 @@ func (stc *SopTaskCreate) defaults() error {
 		v := soptask.DefaultOrganizationID
 		stc.mutation.SetOrganizationID(v)
 	}
+	if _, ok := stc.mutation.Token(); !ok {
+		v := soptask.DefaultToken
+		stc.mutation.SetToken(v)
+	}
 	return nil
 }
 
@@ -344,6 +362,10 @@ func (stc *SopTaskCreate) createSpec() (*SopTask, *sqlgraph.CreateSpec) {
 		_spec.SetField(soptask.FieldOrganizationID, field.TypeUint64, value)
 		_node.OrganizationID = value
 	}
+	if value, ok := stc.mutation.Token(); ok {
+		_spec.SetField(soptask.FieldToken, field.TypeString, value)
+		_node.Token = value
+	}
 	if nodes := stc.mutation.TaskStagesIDs(); len(nodes) > 0 {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.O2M,
@@ -592,6 +614,24 @@ func (u *SopTaskUpsert) ClearOrganizationID() *SopTaskUpsert {
 	return u
 }
 
+// SetToken sets the "token" field.
+func (u *SopTaskUpsert) SetToken(v string) *SopTaskUpsert {
+	u.Set(soptask.FieldToken, v)
+	return u
+}
+
+// UpdateToken sets the "token" field to the value that was provided on create.
+func (u *SopTaskUpsert) UpdateToken() *SopTaskUpsert {
+	u.SetExcluded(soptask.FieldToken)
+	return u
+}
+
+// ClearToken clears the value of the "token" field.
+func (u *SopTaskUpsert) ClearToken() *SopTaskUpsert {
+	u.SetNull(soptask.FieldToken)
+	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:
 //
@@ -853,6 +893,27 @@ func (u *SopTaskUpsertOne) ClearOrganizationID() *SopTaskUpsertOne {
 	})
 }
 
+// SetToken sets the "token" field.
+func (u *SopTaskUpsertOne) SetToken(v string) *SopTaskUpsertOne {
+	return u.Update(func(s *SopTaskUpsert) {
+		s.SetToken(v)
+	})
+}
+
+// UpdateToken sets the "token" field to the value that was provided on create.
+func (u *SopTaskUpsertOne) UpdateToken() *SopTaskUpsertOne {
+	return u.Update(func(s *SopTaskUpsert) {
+		s.UpdateToken()
+	})
+}
+
+// ClearToken clears the value of the "token" field.
+func (u *SopTaskUpsertOne) ClearToken() *SopTaskUpsertOne {
+	return u.Update(func(s *SopTaskUpsert) {
+		s.ClearToken()
+	})
+}
+
 // Exec executes the query.
 func (u *SopTaskUpsertOne) Exec(ctx context.Context) error {
 	if len(u.create.conflict) == 0 {
@@ -1280,6 +1341,27 @@ func (u *SopTaskUpsertBulk) ClearOrganizationID() *SopTaskUpsertBulk {
 	})
 }
 
+// SetToken sets the "token" field.
+func (u *SopTaskUpsertBulk) SetToken(v string) *SopTaskUpsertBulk {
+	return u.Update(func(s *SopTaskUpsert) {
+		s.SetToken(v)
+	})
+}
+
+// UpdateToken sets the "token" field to the value that was provided on create.
+func (u *SopTaskUpsertBulk) UpdateToken() *SopTaskUpsertBulk {
+	return u.Update(func(s *SopTaskUpsert) {
+		s.UpdateToken()
+	})
+}
+
+// ClearToken clears the value of the "token" field.
+func (u *SopTaskUpsertBulk) ClearToken() *SopTaskUpsertBulk {
+	return u.Update(func(s *SopTaskUpsert) {
+		s.ClearToken()
+	})
+}
+
 // Exec executes the query.
 func (u *SopTaskUpsertBulk) Exec(ctx context.Context) error {
 	if u.create.err != nil {

+ 52 - 0
ent/soptask_update.go

@@ -223,6 +223,26 @@ func (stu *SopTaskUpdate) ClearOrganizationID() *SopTaskUpdate {
 	return stu
 }
 
+// SetToken sets the "token" field.
+func (stu *SopTaskUpdate) SetToken(s string) *SopTaskUpdate {
+	stu.mutation.SetToken(s)
+	return stu
+}
+
+// SetNillableToken sets the "token" field if the given value is not nil.
+func (stu *SopTaskUpdate) SetNillableToken(s *string) *SopTaskUpdate {
+	if s != nil {
+		stu.SetToken(*s)
+	}
+	return stu
+}
+
+// ClearToken clears the value of the "token" field.
+func (stu *SopTaskUpdate) ClearToken() *SopTaskUpdate {
+	stu.mutation.ClearToken()
+	return stu
+}
+
 // AddTaskStageIDs adds the "task_stages" edge to the SopStage entity by IDs.
 func (stu *SopTaskUpdate) AddTaskStageIDs(ids ...uint64) *SopTaskUpdate {
 	stu.mutation.AddTaskStageIDs(ids...)
@@ -393,6 +413,12 @@ func (stu *SopTaskUpdate) sqlSave(ctx context.Context) (n int, err error) {
 	if stu.mutation.OrganizationIDCleared() {
 		_spec.ClearField(soptask.FieldOrganizationID, field.TypeUint64)
 	}
+	if value, ok := stu.mutation.Token(); ok {
+		_spec.SetField(soptask.FieldToken, field.TypeString, value)
+	}
+	if stu.mutation.TokenCleared() {
+		_spec.ClearField(soptask.FieldToken, field.TypeString)
+	}
 	if stu.mutation.TaskStagesCleared() {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.O2M,
@@ -651,6 +677,26 @@ func (stuo *SopTaskUpdateOne) ClearOrganizationID() *SopTaskUpdateOne {
 	return stuo
 }
 
+// SetToken sets the "token" field.
+func (stuo *SopTaskUpdateOne) SetToken(s string) *SopTaskUpdateOne {
+	stuo.mutation.SetToken(s)
+	return stuo
+}
+
+// SetNillableToken sets the "token" field if the given value is not nil.
+func (stuo *SopTaskUpdateOne) SetNillableToken(s *string) *SopTaskUpdateOne {
+	if s != nil {
+		stuo.SetToken(*s)
+	}
+	return stuo
+}
+
+// ClearToken clears the value of the "token" field.
+func (stuo *SopTaskUpdateOne) ClearToken() *SopTaskUpdateOne {
+	stuo.mutation.ClearToken()
+	return stuo
+}
+
 // AddTaskStageIDs adds the "task_stages" edge to the SopStage entity by IDs.
 func (stuo *SopTaskUpdateOne) AddTaskStageIDs(ids ...uint64) *SopTaskUpdateOne {
 	stuo.mutation.AddTaskStageIDs(ids...)
@@ -851,6 +897,12 @@ func (stuo *SopTaskUpdateOne) sqlSave(ctx context.Context) (_node *SopTask, err
 	if stuo.mutation.OrganizationIDCleared() {
 		_spec.ClearField(soptask.FieldOrganizationID, field.TypeUint64)
 	}
+	if value, ok := stuo.mutation.Token(); ok {
+		_spec.SetField(soptask.FieldToken, field.TypeString, value)
+	}
+	if stuo.mutation.TokenCleared() {
+		_spec.ClearField(soptask.FieldToken, field.TypeString)
+	}
 	if stuo.mutation.TaskStagesCleared() {
 		edge := &sqlgraph.EdgeSpec{
 			Rel:     sqlgraph.O2M,

+ 1 - 1
go.mod

@@ -14,7 +14,6 @@ require (
 	github.com/go-resty/resty/v2 v2.14.0
 	github.com/gofrs/uuid/v5 v5.0.0
 	github.com/golang-jwt/jwt/v5 v5.2.1
-	github.com/golang/protobuf v1.5.4
 	github.com/imroc/req/v3 v3.43.1
 	github.com/redis/go-redis/v9 v9.6.1
 	github.com/robfig/cron/v3 v3.0.1
@@ -72,6 +71,7 @@ require (
 	github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
 	github.com/gogo/protobuf v1.3.2 // indirect
 	github.com/golang/mock v1.6.0 // indirect
+	github.com/golang/protobuf v1.5.4 // indirect
 	github.com/google/gnostic-models v0.6.8 // indirect
 	github.com/google/go-cmp v0.6.0 // indirect
 	github.com/google/gofuzz v1.2.0 // indirect

+ 4 - 0
go.sum

@@ -443,6 +443,7 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
 github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
 github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
 github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
+github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
 github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
 github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
 github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
@@ -476,6 +477,7 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
 github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
 github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
 github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
+github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
 github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
 github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
@@ -572,6 +574,8 @@ github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkU
 github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
 github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
 github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
+github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
+github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
 github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
 github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
 github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=

+ 5 - 0
internal/handler/routes.go

@@ -979,6 +979,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 				},
 				{
 					Method:  http.MethodPost,
+					Path:    "/token/api/list",
+					Handler: token.GetApiTokenListHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
 					Path:    "/token/third/detail",
 					Handler: token.GetTokenByIdHandler(serverCtx),
 				},

+ 44 - 0
internal/handler/token/get_api_token_list_handler.go

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

+ 12 - 0
internal/logic/sop_task/update_sop_task_logic.go

@@ -3,6 +3,8 @@ package sop_task
 import (
 	"context"
 	"fmt"
+	"github.com/zeromicro/go-zero/core/errorx"
+	"wechat-api/ent"
 	"wechat-api/ent/soptask"
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
@@ -34,6 +36,12 @@ func (l *UpdateSopTaskLogic) UpdateSopTask(req *types.SopTaskInfo) (*types.BaseM
 		return nil, dberrorhandler.DefaultEntError(l.Logger, fmt.Errorf("planEndTime must be greater than planStartTime"), req)
 	}
 
+	var token *string
+	if req.Token != nil {
+		token = req.Token
+		req.BotWxidList = nil
+	}
+
 	err := l.svcCtx.DB.SopTask.UpdateOneID(*req.Id).
 		Where(soptask.StatusEQ(1), soptask.OrganizationID(organizationId)).
 		SetNotNilStatus(req.Status).
@@ -43,9 +51,13 @@ func (l *UpdateSopTaskLogic) UpdateSopTask(req *types.SopTaskInfo) (*types.BaseM
 		SetNotNilPlanStartTime(pointy.GetTimeMilliPointer(req.PlanStartTime)).
 		SetNotNilPlanEndTime(pointy.GetTimeMilliPointer(req.PlanEndTime)).
 		SetNotNilCreatorID(req.CreatorId).
+		SetNotNilToken(token).
 		Exec(l.ctx)
 
 	if err != nil {
+		if ent.IsNotFound(err) {
+			return nil, errorx.NewInvalidArgumentError("未发布状态的SOP才可以编辑")
+		}
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 

+ 69 - 0
internal/logic/token/get_api_token_list_logic.go

@@ -0,0 +1,69 @@
+package token
+
+import (
+	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/utils/pointy"
+	"wechat-api/ent/predicate"
+	"wechat-api/ent/token"
+	"wechat-api/internal/utils/dberrorhandler"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetApiTokenListLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGetApiTokenListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetApiTokenListLogic {
+	return &GetApiTokenListLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *GetApiTokenListLogic) GetApiTokenList(req *types.TokenListReq) (*types.TokenListResp, error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
+
+	var predicates []predicate.Token
+	predicates = append(predicates, token.OrganizationID(organizationId))
+
+	data, err := l.svcCtx.DB.Token.Query().Where(predicates...).WithAgent().Page(l.ctx, req.Page, req.PageSize)
+
+	if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
+
+	resp := &types.TokenListResp{}
+	resp.Msg = errormsg.Success
+	resp.Data.Total = data.PageDetails.Total
+
+	for _, v := range data.List {
+		expireAtStr := v.ExpireAt.Format("2006-01-02 15:04:05")
+		resp.Data.Data = append(resp.Data.Data,
+			types.TokenInfo{
+				BaseIDInfo: types.BaseIDInfo{
+					Id:        &v.ID,
+					CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
+					UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
+				},
+				ExpireAt:        pointy.GetUnixMilliPointer(v.ExpireAt.UnixMilli()),
+				ExpireAtStr:     &expireAtStr,
+				Token:           &v.Token,
+				Mac:             &v.MAC,
+				OrganizationId:  &v.OrganizationID,
+				AgentId:         &v.AgentID,
+				CustomAgentBase: &v.CustomAgentBase,
+				CustomAgentKey:  &v.CustomAgentKey,
+				OpenaiBase:      &v.OpenaiBase,
+				OpenaiKey:       &v.OpenaiKey,
+			})
+	}
+
+	return resp, nil
+}

+ 2 - 0
internal/types/types.go

@@ -1281,6 +1281,8 @@ type SopTaskInfo struct {
 	StageList []SopStageInfo `json:"stageList,optional"`
 	// 组织ID
 	OrganizationId *uint64 `json:"organizationId,optional"`
+	// Token
+	Token *string `json:"token"`
 }
 
 // The response data of sop node information | SopNode信息