Files
sundynix-micro-be/app/system/api/internal/logic/dict/updateDictLogic.go
T
2026-04-27 00:02:18 +08:00

47 lines
1.1 KiB
Go

// Code scaffolded by goctl. Safe to edit.
package dict
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/logx"
"sundynix-micro-go/app/system/api/internal/svc"
"sundynix-micro-go/app/system/api/internal/types"
sysModel "sundynix-micro-go/app/system/model"
)
type UpdateDictLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUpdateDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateDictLogic {
return &UpdateDictLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
}
func (l *UpdateDictLogic) UpdateDict(req *types.DictUpdateReq) error {
updates := map[string]interface{}{}
if req.Type != "" {
updates["type"] = req.Type
}
if req.Label != "" {
updates["label"] = req.Label
}
if req.Value != "" {
updates["value"] = req.Value
}
if req.Sort > 0 {
updates["sort"] = req.Sort
}
if req.Desc != "" {
updates["desc"] = req.Desc
}
if len(updates) > 0 {
if err := l.svcCtx.DB.Model(&sysModel.SundynixDict{}).Where("id = ?", req.Id).Updates(updates).Error; err != nil {
return fmt.Errorf("更新字典失败")
}
}
return nil
}