feat: 初次启动
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
// 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"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type CreateDictLogic struct {
|
||||
@@ -21,9 +19,8 @@ func NewCreateDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Create
|
||||
}
|
||||
|
||||
func (l *CreateDictLogic) CreateDict(req *types.DictReq) error {
|
||||
dict := sysModel.SundynixDict{Type: req.Type, Label: req.Label, Value: req.Value, Sort: req.Sort, Desc: req.Desc}
|
||||
if err := l.svcCtx.DB.Create(&dict).Error; err != nil {
|
||||
return fmt.Errorf("创建字典失败")
|
||||
}
|
||||
return nil
|
||||
_, err := l.svcCtx.SystemRpc.CreateDict(l.ctx, &system.DictReq{
|
||||
Type: req.Type, Label: req.Label, Value: req.Value, Sort: int32(req.Sort), Desc: req.Desc,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// 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"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type DeleteDictLogic struct {
|
||||
@@ -21,8 +19,6 @@ func NewDeleteDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delete
|
||||
}
|
||||
|
||||
func (l *DeleteDictLogic) DeleteDict(req *types.IdsReq) error {
|
||||
if err := l.svcCtx.DB.Where("id IN ?", req.Ids).Delete(&sysModel.SundynixDict{}).Error; err != nil {
|
||||
return fmt.Errorf("删除字典失败")
|
||||
}
|
||||
return nil
|
||||
_, err := l.svcCtx.SystemRpc.DeleteDict(l.ctx, &system.IdsReq{Ids: req.Ids})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// 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"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type GetDictListLogic struct {
|
||||
@@ -20,23 +18,12 @@ func NewGetDictListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDi
|
||||
return &GetDictListLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetDictListLogic) GetDictList(req *types.DictListReq) (resp interface{}, err error) {
|
||||
var dicts []sysModel.SundynixDict
|
||||
var total int64
|
||||
db := l.svcCtx.DB.Model(&sysModel.SundynixDict{})
|
||||
if req.Type != "" {
|
||||
db = db.Where("type = ?", req.Type)
|
||||
func (l *GetDictListLogic) GetDictList(req *types.DictListReq) (interface{}, error) {
|
||||
resp, err := l.svcCtx.SystemRpc.GetDictList(l.ctx, &system.DictListReq{
|
||||
Current: int32(req.Current), PageSize: int32(req.PageSize), Type: req.Type,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
db.Count(&total)
|
||||
current, pageSize := req.Current, req.PageSize
|
||||
if current <= 0 {
|
||||
current = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
if err := db.Offset((current - 1) * pageSize).Limit(pageSize).Order("sort").Find(&dicts).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询字典列表失败")
|
||||
}
|
||||
return map[string]interface{}{"list": dicts, "total": total, "current": current, "size": pageSize}, nil
|
||||
return map[string]interface{}{"list": resp.List, "total": resp.Total}, nil
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// 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"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type UpdateDictLogic struct {
|
||||
@@ -21,26 +19,8 @@ func NewUpdateDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Update
|
||||
}
|
||||
|
||||
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
|
||||
_, err := l.svcCtx.SystemRpc.UpdateDict(l.ctx, &system.DictUpdateReq{
|
||||
Id: req.Id, Type: req.Type, Label: req.Label, Value: req.Value, Sort: int32(req.Sort), Desc: req.Desc,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user