chore: seed migration objects batch 5
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
package sys
|
||||
|
||||
import (
|
||||
"context"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
const imFeedbackConfigTable = "im_feedback_config"
|
||||
|
||||
type sSysImFeedbackConfig struct{}
|
||||
|
||||
func NewSysImFeedbackConfig() *sSysImFeedbackConfig { return &sSysImFeedbackConfig{} }
|
||||
|
||||
func init() {
|
||||
service.RegisterSysImFeedbackConfig(NewSysImFeedbackConfig())
|
||||
}
|
||||
|
||||
func (s *sSysImFeedbackConfig) Get(ctx context.Context, in *sysin.ImFeedbackConfigGetInp) (res *sysin.ImFeedbackConfigModel, err error) {
|
||||
if err = in.Filter(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
db, tenant, err := resolveImTenantDB(ctx, in.TenantId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = s.ensureDefault(ctx, db); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = s.model(ctx, db).OrderAsc("id").Limit(1).Scan(&res); err != nil {
|
||||
return nil, gerror.Wrap(err, "获取IM意见反馈配置失败,请稍后重试!")
|
||||
}
|
||||
if res != nil {
|
||||
res.TenantId = tenant.Id
|
||||
res.TenantName = tenant.Name
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sSysImFeedbackConfig) Update(ctx context.Context, in *sysin.ImFeedbackConfigUpdateInp) (err error) {
|
||||
if err = in.Filter(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
db, tenant, err := resolveImTenantDB(ctx, in.TenantId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = s.ensureDefault(ctx, db); err != nil {
|
||||
return err
|
||||
}
|
||||
categories := `["bug","suggestion","complaint","other"]`
|
||||
if in.Categories != nil && in.Categories.String() != "" && in.Categories.String() != "null" {
|
||||
categories = in.Categories.String()
|
||||
}
|
||||
attachmentPolicy := `{"max_files":5,"purpose":"feedback"}`
|
||||
if in.AttachmentPolicy != nil && in.AttachmentPolicy.String() != "" && in.AttachmentPolicy.String() != "null" {
|
||||
attachmentPolicy = in.AttachmentPolicy.String()
|
||||
}
|
||||
if _, err = db.Model(imFeedbackConfigTable).Safe().Ctx(ctx).Where("id", 1).Data(g.Map{
|
||||
"categories": categories,
|
||||
"max_length": in.MaxLength,
|
||||
"attachment_policy": attachmentPolicy,
|
||||
"allow_contact": in.AllowContact,
|
||||
"diagnostics_notice": in.DiagnosticsNotice,
|
||||
"updated_at": gtime.Now(),
|
||||
}).Update(); err != nil {
|
||||
return gerror.Wrap(err, "更新IM意见反馈配置失败,请稍后重试!")
|
||||
}
|
||||
_ = writeImAdminAudit(ctx, tenant.Id, "im_feedback_config_update", "im_feedback_config", 1, "success", g.Map{"allow_contact": in.AllowContact})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *sSysImFeedbackConfig) model(ctx context.Context, db gdb.DB) *gdb.Model {
|
||||
return db.Model(imFeedbackConfigTable).Safe().Ctx(ctx).Fields(
|
||||
"id",
|
||||
"CAST(categories AS CHAR) categories",
|
||||
"max_length",
|
||||
"CAST(attachment_policy AS CHAR) attachment_policy",
|
||||
"allow_contact",
|
||||
"diagnostics_notice",
|
||||
"updated_at",
|
||||
)
|
||||
}
|
||||
|
||||
func (s *sSysImFeedbackConfig) ensureDefault(ctx context.Context, db gdb.DB) (err error) {
|
||||
var count int
|
||||
if count, err = db.Model(imFeedbackConfigTable).Safe().Ctx(ctx).Where("id", 1).Count(); err != nil {
|
||||
return gerror.Wrap(err, "检查IM意见反馈默认配置失败,请稍后重试!")
|
||||
}
|
||||
if count > 0 {
|
||||
return nil
|
||||
}
|
||||
_, err = db.Model(imFeedbackConfigTable).Safe().Ctx(ctx).Data(g.Map{
|
||||
"id": 1,
|
||||
"categories": `["bug","suggestion","complaint","other"]`,
|
||||
"max_length": 1000,
|
||||
"attachment_policy": `{"max_files":5,"purpose":"feedback"}`,
|
||||
"allow_contact": 1,
|
||||
"diagnostics_notice": "仅在你同意时上传脱敏诊断信息。",
|
||||
"created_at": gtime.Now(),
|
||||
"updated_at": gtime.Now(),
|
||||
}).Insert()
|
||||
if err != nil {
|
||||
return gerror.Wrap(err, "初始化IM意见反馈默认配置失败,请稍后重试!")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user