This commit is contained in:
1
2026-01-21 20:46:05 +00:00
parent 97f70731b5
commit 0a0e1bf8c0
26 changed files with 236 additions and 227 deletions

View File

@@ -19,7 +19,7 @@ func init() {
&cool.Controller{
Prefix: "/admin/dict/info",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
Service: service.DictInfoServiceS,
Service: service.NewDictInfoService(),
},
}
// 注册路由
@@ -34,7 +34,7 @@ type DictInfoDataReq struct {
// Data 方法 获得字典数据
func (c *DictInfoController) Data(ctx context.Context, req *DictInfoDataReq) (res *cool.BaseRes, err error) {
service := service.DictInfoServiceS
service := service.NewDictInfoService()
data, err := service.Data(ctx, req.Types)
res = cool.Ok(data)
return

View File

@@ -11,7 +11,7 @@ type DictInfo struct {
*cool.Model
TypeID int32 `gorm:"column:typeId;type:int;not null" json:"typeId"` // 类型ID
Name string `gorm:"column:name;type:varchar(255);not null" json:"name"` // 名称
ordernum int32 `gorm:"column:ordernum;type:int;not null" json:"ordernum"` // 排序
Ordernum int32 `gorm:"column:ordernum;type:int;not null" json:"ordernum"` // 排序
Remark *string `gorm:"column:remark;type:varchar(255)" json:"remark"` // 备注
Value int32 `gorm:"column:value;type:int;not null" json:"value"`
ParentID *int32 `gorm:"column:parentId;type:int" json:"parentId"` // 父ID

View File

@@ -87,11 +87,27 @@ func (s *DictInfoService) GetData(types string) (data map[uint32]model.DictInfo)
})
return fusions
}
func (s *DictInfoService) GetMax(value uint32) (max uint32) {
m := cool.DBM(s.Model)
var ress *model.DictInfo
m.Where("value", value).Cache(gdb.CacheOption{
// Duration: time.Hour,
Force: false,
}).Scan(&ress)
if ress == nil {
return 0
}
return uint32(ress.Ordernum)
}
// ModifyAfter 修改后
func (s *DictInfoService) ModifyAfter(ctx context.Context, method string, param map[string]interface{}) (err error) {
defer s.Service.ModifyAfter(ctx, method, param)
if method == "Delete" {
// 删除后,同时删除子节点
ids, ok := param["ids"]
@@ -128,8 +144,6 @@ func delChildDict(id int64) error {
return err
}
var DictInfoServiceS = NewDictInfoService()
// NewDictInfoService 初始化 DictInfoService
func NewDictInfoService() *DictInfoService {
return &DictInfoService{