Browse Source

fix:優化xunji/detail

jimmyyem 4 weeks ago
parent
commit
090cd6de39
7 changed files with 323 additions and 21 deletions
  1. 4 4
      ent/migrate/schema.go
  2. 76 0
      ent/mutation.go
  3. 4 4
      ent/schema/xunji.go
  4. 40 0
      ent/xunji/where.go
  5. 112 12
      ent/xunji_create.go
  6. 72 0
      ent/xunji_update.go
  7. 15 1
      internal/logic/xunji/get_xunji_logic.go

+ 4 - 4
ent/migrate/schema.go

@@ -1419,10 +1419,10 @@ var (
 		{Name: "updated_at", Type: field.TypeTime, Comment: "Update Time | 修改日期"},
 		{Name: "status", Type: field.TypeUint8, Nullable: true, Comment: "Status 1: normal 2: ban | 状态 1 正常 2 禁用", Default: 1},
 		{Name: "deleted_at", Type: field.TypeTime, Nullable: true, Comment: "Delete Time | 删除日期"},
-		{Name: "app_key", Type: field.TypeString, Comment: "AppKey"},
-		{Name: "app_secret", Type: field.TypeString, Comment: "AppSecret"},
-		{Name: "token", Type: field.TypeString, Comment: "Token"},
-		{Name: "encoding_key", Type: field.TypeString, Comment: "加密key"},
+		{Name: "app_key", Type: field.TypeString, Nullable: true, Comment: "AppKey"},
+		{Name: "app_secret", Type: field.TypeString, Nullable: true, Comment: "AppSecret"},
+		{Name: "token", Type: field.TypeString, Nullable: true, Comment: "Token"},
+		{Name: "encoding_key", Type: field.TypeString, Nullable: true, Comment: "加密key"},
 		{Name: "organization_id", Type: field.TypeUint64, Comment: "organization_id | 租户ID"},
 	}
 	// XunjiTable holds the schema information for the "xunji" table.

+ 76 - 0
ent/mutation.go

@@ -50381,9 +50381,22 @@ func (m *XunjiMutation) OldAppKey(ctx context.Context) (v string, err error) {
 	return oldValue.AppKey, nil
 }
 
+// ClearAppKey clears the value of the "app_key" field.
+func (m *XunjiMutation) ClearAppKey() {
+	m.app_key = nil
+	m.clearedFields[xunji.FieldAppKey] = struct{}{}
+}
+
+// AppKeyCleared returns if the "app_key" field was cleared in this mutation.
+func (m *XunjiMutation) AppKeyCleared() bool {
+	_, ok := m.clearedFields[xunji.FieldAppKey]
+	return ok
+}
+
 // ResetAppKey resets all changes to the "app_key" field.
 func (m *XunjiMutation) ResetAppKey() {
 	m.app_key = nil
+	delete(m.clearedFields, xunji.FieldAppKey)
 }
 
 // SetAppSecret sets the "app_secret" field.
@@ -50417,9 +50430,22 @@ func (m *XunjiMutation) OldAppSecret(ctx context.Context) (v string, err error)
 	return oldValue.AppSecret, nil
 }
 
+// ClearAppSecret clears the value of the "app_secret" field.
+func (m *XunjiMutation) ClearAppSecret() {
+	m.app_secret = nil
+	m.clearedFields[xunji.FieldAppSecret] = struct{}{}
+}
+
+// AppSecretCleared returns if the "app_secret" field was cleared in this mutation.
+func (m *XunjiMutation) AppSecretCleared() bool {
+	_, ok := m.clearedFields[xunji.FieldAppSecret]
+	return ok
+}
+
 // ResetAppSecret resets all changes to the "app_secret" field.
 func (m *XunjiMutation) ResetAppSecret() {
 	m.app_secret = nil
+	delete(m.clearedFields, xunji.FieldAppSecret)
 }
 
 // SetToken sets the "token" field.
@@ -50453,9 +50479,22 @@ func (m *XunjiMutation) OldToken(ctx context.Context) (v string, err error) {
 	return oldValue.Token, nil
 }
 
+// ClearToken clears the value of the "token" field.
+func (m *XunjiMutation) ClearToken() {
+	m.token = nil
+	m.clearedFields[xunji.FieldToken] = struct{}{}
+}
+
+// TokenCleared returns if the "token" field was cleared in this mutation.
+func (m *XunjiMutation) TokenCleared() bool {
+	_, ok := m.clearedFields[xunji.FieldToken]
+	return ok
+}
+
 // ResetToken resets all changes to the "token" field.
 func (m *XunjiMutation) ResetToken() {
 	m.token = nil
+	delete(m.clearedFields, xunji.FieldToken)
 }
 
 // SetEncodingKey sets the "encoding_key" field.
@@ -50489,9 +50528,22 @@ func (m *XunjiMutation) OldEncodingKey(ctx context.Context) (v string, err error
 	return oldValue.EncodingKey, nil
 }
 
+// ClearEncodingKey clears the value of the "encoding_key" field.
+func (m *XunjiMutation) ClearEncodingKey() {
+	m.encoding_key = nil
+	m.clearedFields[xunji.FieldEncodingKey] = struct{}{}
+}
+
+// EncodingKeyCleared returns if the "encoding_key" field was cleared in this mutation.
+func (m *XunjiMutation) EncodingKeyCleared() bool {
+	_, ok := m.clearedFields[xunji.FieldEncodingKey]
+	return ok
+}
+
 // ResetEncodingKey resets all changes to the "encoding_key" field.
 func (m *XunjiMutation) ResetEncodingKey() {
 	m.encoding_key = nil
+	delete(m.clearedFields, xunji.FieldEncodingKey)
 }
 
 // SetOrganizationID sets the "organization_id" field.
@@ -50800,6 +50852,18 @@ func (m *XunjiMutation) ClearedFields() []string {
 	if m.FieldCleared(xunji.FieldDeletedAt) {
 		fields = append(fields, xunji.FieldDeletedAt)
 	}
+	if m.FieldCleared(xunji.FieldAppKey) {
+		fields = append(fields, xunji.FieldAppKey)
+	}
+	if m.FieldCleared(xunji.FieldAppSecret) {
+		fields = append(fields, xunji.FieldAppSecret)
+	}
+	if m.FieldCleared(xunji.FieldToken) {
+		fields = append(fields, xunji.FieldToken)
+	}
+	if m.FieldCleared(xunji.FieldEncodingKey) {
+		fields = append(fields, xunji.FieldEncodingKey)
+	}
 	return fields
 }
 
@@ -50820,6 +50884,18 @@ func (m *XunjiMutation) ClearField(name string) error {
 	case xunji.FieldDeletedAt:
 		m.ClearDeletedAt()
 		return nil
+	case xunji.FieldAppKey:
+		m.ClearAppKey()
+		return nil
+	case xunji.FieldAppSecret:
+		m.ClearAppSecret()
+		return nil
+	case xunji.FieldToken:
+		m.ClearToken()
+		return nil
+	case xunji.FieldEncodingKey:
+		m.ClearEncodingKey()
+		return nil
 	}
 	return fmt.Errorf("unknown Xunji nullable field %s", name)
 }

+ 4 - 4
ent/schema/xunji.go

@@ -17,10 +17,10 @@ type Xunji struct {
 
 func (Xunji) Fields() []ent.Field {
 	return []ent.Field{
-		field.String("app_key").Comment("AppKey"),
-		field.String("app_secret").Comment("AppSecret"),
-		field.String("token").Comment("Token"),
-		field.String("encoding_key").Comment("加密key"),
+		field.String("app_key").Optional().Comment("AppKey"),
+		field.String("app_secret").Optional().Comment("AppSecret"),
+		field.String("token").Optional().Comment("Token"),
+		field.String("encoding_key").Optional().Comment("加密key"),
 		field.Uint64("organization_id").Positive().Comment("organization_id | 租户ID"),
 	}
 }

+ 40 - 0
ent/xunji/where.go

@@ -334,6 +334,16 @@ func AppKeyHasSuffix(v string) predicate.Xunji {
 	return predicate.Xunji(sql.FieldHasSuffix(FieldAppKey, v))
 }
 
+// AppKeyIsNil applies the IsNil predicate on the "app_key" field.
+func AppKeyIsNil() predicate.Xunji {
+	return predicate.Xunji(sql.FieldIsNull(FieldAppKey))
+}
+
+// AppKeyNotNil applies the NotNil predicate on the "app_key" field.
+func AppKeyNotNil() predicate.Xunji {
+	return predicate.Xunji(sql.FieldNotNull(FieldAppKey))
+}
+
 // AppKeyEqualFold applies the EqualFold predicate on the "app_key" field.
 func AppKeyEqualFold(v string) predicate.Xunji {
 	return predicate.Xunji(sql.FieldEqualFold(FieldAppKey, v))
@@ -399,6 +409,16 @@ func AppSecretHasSuffix(v string) predicate.Xunji {
 	return predicate.Xunji(sql.FieldHasSuffix(FieldAppSecret, v))
 }
 
+// AppSecretIsNil applies the IsNil predicate on the "app_secret" field.
+func AppSecretIsNil() predicate.Xunji {
+	return predicate.Xunji(sql.FieldIsNull(FieldAppSecret))
+}
+
+// AppSecretNotNil applies the NotNil predicate on the "app_secret" field.
+func AppSecretNotNil() predicate.Xunji {
+	return predicate.Xunji(sql.FieldNotNull(FieldAppSecret))
+}
+
 // AppSecretEqualFold applies the EqualFold predicate on the "app_secret" field.
 func AppSecretEqualFold(v string) predicate.Xunji {
 	return predicate.Xunji(sql.FieldEqualFold(FieldAppSecret, v))
@@ -464,6 +484,16 @@ func TokenHasSuffix(v string) predicate.Xunji {
 	return predicate.Xunji(sql.FieldHasSuffix(FieldToken, v))
 }
 
+// TokenIsNil applies the IsNil predicate on the "token" field.
+func TokenIsNil() predicate.Xunji {
+	return predicate.Xunji(sql.FieldIsNull(FieldToken))
+}
+
+// TokenNotNil applies the NotNil predicate on the "token" field.
+func TokenNotNil() predicate.Xunji {
+	return predicate.Xunji(sql.FieldNotNull(FieldToken))
+}
+
 // TokenEqualFold applies the EqualFold predicate on the "token" field.
 func TokenEqualFold(v string) predicate.Xunji {
 	return predicate.Xunji(sql.FieldEqualFold(FieldToken, v))
@@ -529,6 +559,16 @@ func EncodingKeyHasSuffix(v string) predicate.Xunji {
 	return predicate.Xunji(sql.FieldHasSuffix(FieldEncodingKey, v))
 }
 
+// EncodingKeyIsNil applies the IsNil predicate on the "encoding_key" field.
+func EncodingKeyIsNil() predicate.Xunji {
+	return predicate.Xunji(sql.FieldIsNull(FieldEncodingKey))
+}
+
+// EncodingKeyNotNil applies the NotNil predicate on the "encoding_key" field.
+func EncodingKeyNotNil() predicate.Xunji {
+	return predicate.Xunji(sql.FieldNotNull(FieldEncodingKey))
+}
+
 // EncodingKeyEqualFold applies the EqualFold predicate on the "encoding_key" field.
 func EncodingKeyEqualFold(v string) predicate.Xunji {
 	return predicate.Xunji(sql.FieldEqualFold(FieldEncodingKey, v))

+ 112 - 12
ent/xunji_create.go

@@ -84,24 +84,56 @@ func (xc *XunjiCreate) SetAppKey(s string) *XunjiCreate {
 	return xc
 }
 
+// SetNillableAppKey sets the "app_key" field if the given value is not nil.
+func (xc *XunjiCreate) SetNillableAppKey(s *string) *XunjiCreate {
+	if s != nil {
+		xc.SetAppKey(*s)
+	}
+	return xc
+}
+
 // SetAppSecret sets the "app_secret" field.
 func (xc *XunjiCreate) SetAppSecret(s string) *XunjiCreate {
 	xc.mutation.SetAppSecret(s)
 	return xc
 }
 
+// SetNillableAppSecret sets the "app_secret" field if the given value is not nil.
+func (xc *XunjiCreate) SetNillableAppSecret(s *string) *XunjiCreate {
+	if s != nil {
+		xc.SetAppSecret(*s)
+	}
+	return xc
+}
+
 // SetToken sets the "token" field.
 func (xc *XunjiCreate) SetToken(s string) *XunjiCreate {
 	xc.mutation.SetToken(s)
 	return xc
 }
 
+// SetNillableToken sets the "token" field if the given value is not nil.
+func (xc *XunjiCreate) SetNillableToken(s *string) *XunjiCreate {
+	if s != nil {
+		xc.SetToken(*s)
+	}
+	return xc
+}
+
 // SetEncodingKey sets the "encoding_key" field.
 func (xc *XunjiCreate) SetEncodingKey(s string) *XunjiCreate {
 	xc.mutation.SetEncodingKey(s)
 	return xc
 }
 
+// SetNillableEncodingKey sets the "encoding_key" field if the given value is not nil.
+func (xc *XunjiCreate) SetNillableEncodingKey(s *string) *XunjiCreate {
+	if s != nil {
+		xc.SetEncodingKey(*s)
+	}
+	return xc
+}
+
 // SetOrganizationID sets the "organization_id" field.
 func (xc *XunjiCreate) SetOrganizationID(u uint64) *XunjiCreate {
 	xc.mutation.SetOrganizationID(u)
@@ -180,18 +212,6 @@ func (xc *XunjiCreate) check() error {
 	if _, ok := xc.mutation.UpdatedAt(); !ok {
 		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Xunji.updated_at"`)}
 	}
-	if _, ok := xc.mutation.AppKey(); !ok {
-		return &ValidationError{Name: "app_key", err: errors.New(`ent: missing required field "Xunji.app_key"`)}
-	}
-	if _, ok := xc.mutation.AppSecret(); !ok {
-		return &ValidationError{Name: "app_secret", err: errors.New(`ent: missing required field "Xunji.app_secret"`)}
-	}
-	if _, ok := xc.mutation.Token(); !ok {
-		return &ValidationError{Name: "token", err: errors.New(`ent: missing required field "Xunji.token"`)}
-	}
-	if _, ok := xc.mutation.EncodingKey(); !ok {
-		return &ValidationError{Name: "encoding_key", err: errors.New(`ent: missing required field "Xunji.encoding_key"`)}
-	}
 	if _, ok := xc.mutation.OrganizationID(); !ok {
 		return &ValidationError{Name: "organization_id", err: errors.New(`ent: missing required field "Xunji.organization_id"`)}
 	}
@@ -387,6 +407,12 @@ func (u *XunjiUpsert) UpdateAppKey() *XunjiUpsert {
 	return u
 }
 
+// ClearAppKey clears the value of the "app_key" field.
+func (u *XunjiUpsert) ClearAppKey() *XunjiUpsert {
+	u.SetNull(xunji.FieldAppKey)
+	return u
+}
+
 // SetAppSecret sets the "app_secret" field.
 func (u *XunjiUpsert) SetAppSecret(v string) *XunjiUpsert {
 	u.Set(xunji.FieldAppSecret, v)
@@ -399,6 +425,12 @@ func (u *XunjiUpsert) UpdateAppSecret() *XunjiUpsert {
 	return u
 }
 
+// ClearAppSecret clears the value of the "app_secret" field.
+func (u *XunjiUpsert) ClearAppSecret() *XunjiUpsert {
+	u.SetNull(xunji.FieldAppSecret)
+	return u
+}
+
 // SetToken sets the "token" field.
 func (u *XunjiUpsert) SetToken(v string) *XunjiUpsert {
 	u.Set(xunji.FieldToken, v)
@@ -411,6 +443,12 @@ func (u *XunjiUpsert) UpdateToken() *XunjiUpsert {
 	return u
 }
 
+// ClearToken clears the value of the "token" field.
+func (u *XunjiUpsert) ClearToken() *XunjiUpsert {
+	u.SetNull(xunji.FieldToken)
+	return u
+}
+
 // SetEncodingKey sets the "encoding_key" field.
 func (u *XunjiUpsert) SetEncodingKey(v string) *XunjiUpsert {
 	u.Set(xunji.FieldEncodingKey, v)
@@ -423,6 +461,12 @@ func (u *XunjiUpsert) UpdateEncodingKey() *XunjiUpsert {
 	return u
 }
 
+// ClearEncodingKey clears the value of the "encoding_key" field.
+func (u *XunjiUpsert) ClearEncodingKey() *XunjiUpsert {
+	u.SetNull(xunji.FieldEncodingKey)
+	return u
+}
+
 // SetOrganizationID sets the "organization_id" field.
 func (u *XunjiUpsert) SetOrganizationID(v uint64) *XunjiUpsert {
 	u.Set(xunji.FieldOrganizationID, v)
@@ -569,6 +613,13 @@ func (u *XunjiUpsertOne) UpdateAppKey() *XunjiUpsertOne {
 	})
 }
 
+// ClearAppKey clears the value of the "app_key" field.
+func (u *XunjiUpsertOne) ClearAppKey() *XunjiUpsertOne {
+	return u.Update(func(s *XunjiUpsert) {
+		s.ClearAppKey()
+	})
+}
+
 // SetAppSecret sets the "app_secret" field.
 func (u *XunjiUpsertOne) SetAppSecret(v string) *XunjiUpsertOne {
 	return u.Update(func(s *XunjiUpsert) {
@@ -583,6 +634,13 @@ func (u *XunjiUpsertOne) UpdateAppSecret() *XunjiUpsertOne {
 	})
 }
 
+// ClearAppSecret clears the value of the "app_secret" field.
+func (u *XunjiUpsertOne) ClearAppSecret() *XunjiUpsertOne {
+	return u.Update(func(s *XunjiUpsert) {
+		s.ClearAppSecret()
+	})
+}
+
 // SetToken sets the "token" field.
 func (u *XunjiUpsertOne) SetToken(v string) *XunjiUpsertOne {
 	return u.Update(func(s *XunjiUpsert) {
@@ -597,6 +655,13 @@ func (u *XunjiUpsertOne) UpdateToken() *XunjiUpsertOne {
 	})
 }
 
+// ClearToken clears the value of the "token" field.
+func (u *XunjiUpsertOne) ClearToken() *XunjiUpsertOne {
+	return u.Update(func(s *XunjiUpsert) {
+		s.ClearToken()
+	})
+}
+
 // SetEncodingKey sets the "encoding_key" field.
 func (u *XunjiUpsertOne) SetEncodingKey(v string) *XunjiUpsertOne {
 	return u.Update(func(s *XunjiUpsert) {
@@ -611,6 +676,13 @@ func (u *XunjiUpsertOne) UpdateEncodingKey() *XunjiUpsertOne {
 	})
 }
 
+// ClearEncodingKey clears the value of the "encoding_key" field.
+func (u *XunjiUpsertOne) ClearEncodingKey() *XunjiUpsertOne {
+	return u.Update(func(s *XunjiUpsert) {
+		s.ClearEncodingKey()
+	})
+}
+
 // SetOrganizationID sets the "organization_id" field.
 func (u *XunjiUpsertOne) SetOrganizationID(v uint64) *XunjiUpsertOne {
 	return u.Update(func(s *XunjiUpsert) {
@@ -926,6 +998,13 @@ func (u *XunjiUpsertBulk) UpdateAppKey() *XunjiUpsertBulk {
 	})
 }
 
+// ClearAppKey clears the value of the "app_key" field.
+func (u *XunjiUpsertBulk) ClearAppKey() *XunjiUpsertBulk {
+	return u.Update(func(s *XunjiUpsert) {
+		s.ClearAppKey()
+	})
+}
+
 // SetAppSecret sets the "app_secret" field.
 func (u *XunjiUpsertBulk) SetAppSecret(v string) *XunjiUpsertBulk {
 	return u.Update(func(s *XunjiUpsert) {
@@ -940,6 +1019,13 @@ func (u *XunjiUpsertBulk) UpdateAppSecret() *XunjiUpsertBulk {
 	})
 }
 
+// ClearAppSecret clears the value of the "app_secret" field.
+func (u *XunjiUpsertBulk) ClearAppSecret() *XunjiUpsertBulk {
+	return u.Update(func(s *XunjiUpsert) {
+		s.ClearAppSecret()
+	})
+}
+
 // SetToken sets the "token" field.
 func (u *XunjiUpsertBulk) SetToken(v string) *XunjiUpsertBulk {
 	return u.Update(func(s *XunjiUpsert) {
@@ -954,6 +1040,13 @@ func (u *XunjiUpsertBulk) UpdateToken() *XunjiUpsertBulk {
 	})
 }
 
+// ClearToken clears the value of the "token" field.
+func (u *XunjiUpsertBulk) ClearToken() *XunjiUpsertBulk {
+	return u.Update(func(s *XunjiUpsert) {
+		s.ClearToken()
+	})
+}
+
 // SetEncodingKey sets the "encoding_key" field.
 func (u *XunjiUpsertBulk) SetEncodingKey(v string) *XunjiUpsertBulk {
 	return u.Update(func(s *XunjiUpsert) {
@@ -968,6 +1061,13 @@ func (u *XunjiUpsertBulk) UpdateEncodingKey() *XunjiUpsertBulk {
 	})
 }
 
+// ClearEncodingKey clears the value of the "encoding_key" field.
+func (u *XunjiUpsertBulk) ClearEncodingKey() *XunjiUpsertBulk {
+	return u.Update(func(s *XunjiUpsert) {
+		s.ClearEncodingKey()
+	})
+}
+
 // SetOrganizationID sets the "organization_id" field.
 func (u *XunjiUpsertBulk) SetOrganizationID(v uint64) *XunjiUpsertBulk {
 	return u.Update(func(s *XunjiUpsert) {

+ 72 - 0
ent/xunji_update.go

@@ -95,6 +95,12 @@ func (xu *XunjiUpdate) SetNillableAppKey(s *string) *XunjiUpdate {
 	return xu
 }
 
+// ClearAppKey clears the value of the "app_key" field.
+func (xu *XunjiUpdate) ClearAppKey() *XunjiUpdate {
+	xu.mutation.ClearAppKey()
+	return xu
+}
+
 // SetAppSecret sets the "app_secret" field.
 func (xu *XunjiUpdate) SetAppSecret(s string) *XunjiUpdate {
 	xu.mutation.SetAppSecret(s)
@@ -109,6 +115,12 @@ func (xu *XunjiUpdate) SetNillableAppSecret(s *string) *XunjiUpdate {
 	return xu
 }
 
+// ClearAppSecret clears the value of the "app_secret" field.
+func (xu *XunjiUpdate) ClearAppSecret() *XunjiUpdate {
+	xu.mutation.ClearAppSecret()
+	return xu
+}
+
 // SetToken sets the "token" field.
 func (xu *XunjiUpdate) SetToken(s string) *XunjiUpdate {
 	xu.mutation.SetToken(s)
@@ -123,6 +135,12 @@ func (xu *XunjiUpdate) SetNillableToken(s *string) *XunjiUpdate {
 	return xu
 }
 
+// ClearToken clears the value of the "token" field.
+func (xu *XunjiUpdate) ClearToken() *XunjiUpdate {
+	xu.mutation.ClearToken()
+	return xu
+}
+
 // SetEncodingKey sets the "encoding_key" field.
 func (xu *XunjiUpdate) SetEncodingKey(s string) *XunjiUpdate {
 	xu.mutation.SetEncodingKey(s)
@@ -137,6 +155,12 @@ func (xu *XunjiUpdate) SetNillableEncodingKey(s *string) *XunjiUpdate {
 	return xu
 }
 
+// ClearEncodingKey clears the value of the "encoding_key" field.
+func (xu *XunjiUpdate) ClearEncodingKey() *XunjiUpdate {
+	xu.mutation.ClearEncodingKey()
+	return xu
+}
+
 // SetOrganizationID sets the "organization_id" field.
 func (xu *XunjiUpdate) SetOrganizationID(u uint64) *XunjiUpdate {
 	xu.mutation.ResetOrganizationID()
@@ -248,15 +272,27 @@ func (xu *XunjiUpdate) sqlSave(ctx context.Context) (n int, err error) {
 	if value, ok := xu.mutation.AppKey(); ok {
 		_spec.SetField(xunji.FieldAppKey, field.TypeString, value)
 	}
+	if xu.mutation.AppKeyCleared() {
+		_spec.ClearField(xunji.FieldAppKey, field.TypeString)
+	}
 	if value, ok := xu.mutation.AppSecret(); ok {
 		_spec.SetField(xunji.FieldAppSecret, field.TypeString, value)
 	}
+	if xu.mutation.AppSecretCleared() {
+		_spec.ClearField(xunji.FieldAppSecret, field.TypeString)
+	}
 	if value, ok := xu.mutation.Token(); ok {
 		_spec.SetField(xunji.FieldToken, field.TypeString, value)
 	}
+	if xu.mutation.TokenCleared() {
+		_spec.ClearField(xunji.FieldToken, field.TypeString)
+	}
 	if value, ok := xu.mutation.EncodingKey(); ok {
 		_spec.SetField(xunji.FieldEncodingKey, field.TypeString, value)
 	}
+	if xu.mutation.EncodingKeyCleared() {
+		_spec.ClearField(xunji.FieldEncodingKey, field.TypeString)
+	}
 	if value, ok := xu.mutation.OrganizationID(); ok {
 		_spec.SetField(xunji.FieldOrganizationID, field.TypeUint64, value)
 	}
@@ -350,6 +386,12 @@ func (xuo *XunjiUpdateOne) SetNillableAppKey(s *string) *XunjiUpdateOne {
 	return xuo
 }
 
+// ClearAppKey clears the value of the "app_key" field.
+func (xuo *XunjiUpdateOne) ClearAppKey() *XunjiUpdateOne {
+	xuo.mutation.ClearAppKey()
+	return xuo
+}
+
 // SetAppSecret sets the "app_secret" field.
 func (xuo *XunjiUpdateOne) SetAppSecret(s string) *XunjiUpdateOne {
 	xuo.mutation.SetAppSecret(s)
@@ -364,6 +406,12 @@ func (xuo *XunjiUpdateOne) SetNillableAppSecret(s *string) *XunjiUpdateOne {
 	return xuo
 }
 
+// ClearAppSecret clears the value of the "app_secret" field.
+func (xuo *XunjiUpdateOne) ClearAppSecret() *XunjiUpdateOne {
+	xuo.mutation.ClearAppSecret()
+	return xuo
+}
+
 // SetToken sets the "token" field.
 func (xuo *XunjiUpdateOne) SetToken(s string) *XunjiUpdateOne {
 	xuo.mutation.SetToken(s)
@@ -378,6 +426,12 @@ func (xuo *XunjiUpdateOne) SetNillableToken(s *string) *XunjiUpdateOne {
 	return xuo
 }
 
+// ClearToken clears the value of the "token" field.
+func (xuo *XunjiUpdateOne) ClearToken() *XunjiUpdateOne {
+	xuo.mutation.ClearToken()
+	return xuo
+}
+
 // SetEncodingKey sets the "encoding_key" field.
 func (xuo *XunjiUpdateOne) SetEncodingKey(s string) *XunjiUpdateOne {
 	xuo.mutation.SetEncodingKey(s)
@@ -392,6 +446,12 @@ func (xuo *XunjiUpdateOne) SetNillableEncodingKey(s *string) *XunjiUpdateOne {
 	return xuo
 }
 
+// ClearEncodingKey clears the value of the "encoding_key" field.
+func (xuo *XunjiUpdateOne) ClearEncodingKey() *XunjiUpdateOne {
+	xuo.mutation.ClearEncodingKey()
+	return xuo
+}
+
 // SetOrganizationID sets the "organization_id" field.
 func (xuo *XunjiUpdateOne) SetOrganizationID(u uint64) *XunjiUpdateOne {
 	xuo.mutation.ResetOrganizationID()
@@ -533,15 +593,27 @@ func (xuo *XunjiUpdateOne) sqlSave(ctx context.Context) (_node *Xunji, err error
 	if value, ok := xuo.mutation.AppKey(); ok {
 		_spec.SetField(xunji.FieldAppKey, field.TypeString, value)
 	}
+	if xuo.mutation.AppKeyCleared() {
+		_spec.ClearField(xunji.FieldAppKey, field.TypeString)
+	}
 	if value, ok := xuo.mutation.AppSecret(); ok {
 		_spec.SetField(xunji.FieldAppSecret, field.TypeString, value)
 	}
+	if xuo.mutation.AppSecretCleared() {
+		_spec.ClearField(xunji.FieldAppSecret, field.TypeString)
+	}
 	if value, ok := xuo.mutation.Token(); ok {
 		_spec.SetField(xunji.FieldToken, field.TypeString, value)
 	}
+	if xuo.mutation.TokenCleared() {
+		_spec.ClearField(xunji.FieldToken, field.TypeString)
+	}
 	if value, ok := xuo.mutation.EncodingKey(); ok {
 		_spec.SetField(xunji.FieldEncodingKey, field.TypeString, value)
 	}
+	if xuo.mutation.EncodingKeyCleared() {
+		_spec.ClearField(xunji.FieldEncodingKey, field.TypeString)
+	}
 	if value, ok := xuo.mutation.OrganizationID(); ok {
 		_spec.SetField(xunji.FieldOrganizationID, field.TypeUint64, value)
 	}

+ 15 - 1
internal/logic/xunji/get_xunji_logic.go

@@ -34,7 +34,21 @@ func (l *GetXunjiLogic) GetXunji() (resp *types.XunjiInfoResp, err error) {
 		xunji.OrganizationID(organizationId),
 	).Order(ent.Desc(xunji.FieldCreatedAt)).First(l.ctx)
 	if err != nil {
-		return nil, dberrorhandler.DefaultEntError(l.Logger, err, nil)
+		// 如果记录为空则插入一条默认值的记录
+		if ent.IsNotFound(err) {
+			_, err = l.svcCtx.DB.Xunji.Create().
+				SetStatus(2).
+				SetOrganizationID(organizationId).
+				Save(l.ctx)
+			if err != nil {
+				return nil, dberrorhandler.DefaultEntError(l.Logger, err, nil)
+			}
+			data, _ = l.svcCtx.DB.Xunji.Query().Where(
+				xunji.OrganizationID(organizationId),
+			).Order(ent.Desc(xunji.FieldCreatedAt)).First(l.ctx)
+		} else {
+			return nil, dberrorhandler.DefaultEntError(l.Logger, err, nil)
+		}
 	}
 
 	return &types.XunjiInfoResp{