38e040af07
CI / changes (push) Successful in 37s
CI / ad (push) Successful in 29s
CI / admin (push) Successful in 17s
CI / bff (push) Successful in 13s
CI / chore (push) Successful in 15s
CI / equipment (push) Successful in 14s
CI / express (push) Successful in 14s
CI / product (push) Successful in 13s
CI / record (push) Successful in 13s
CI / sale (push) Successful in 13s
CI / task (push) Successful in 13s
CI / user (push) Successful in 14s
CI / wecom (push) Successful in 13s
77 lines
1.7 KiB
Go
77 lines
1.7 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/services/chore/internal/dao"
|
|
"lone-services/services/chore/internal/model"
|
|
"lone-services/services/chore/validator"
|
|
"strconv"
|
|
|
|
"lone-services/rpc/chore/pb"
|
|
"lone-services/services/chore/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type SystemEditLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewSystemEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemEditLogic {
|
|
return &SystemEditLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *SystemEditLogic) SystemEdit(in *chore.SystemEditReq) (*chore.Response, error) {
|
|
var v validator.SystemEditValidator
|
|
if fail := l.checkParams(in, &v); fail != nil {
|
|
return fail, nil
|
|
}
|
|
adminInfo := utils.GetUserFromCtx(l.ctx)
|
|
if adminInfo.ID < utils.NumberOne {
|
|
return l.fail(utils.ErrorNoLoginInfo)
|
|
}
|
|
|
|
var info dao.System
|
|
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(v.Type))}}
|
|
err := model.SystemModel{}.Init().GetOne(w, &info)
|
|
if err != nil {
|
|
return l.fail(utils.ErrorNotFund)
|
|
}
|
|
if info.Id < utils.NumberOne {
|
|
return l.fail(utils.ErrorNotFund)
|
|
}
|
|
action := utils.ActionAdd{
|
|
OldContent: info,
|
|
Type: utils.LogActionTypeEdit,
|
|
ModuleName: utils.LogActionModuleSystem,
|
|
}
|
|
|
|
info.AdminId = adminInfo.ID
|
|
info.AdminName = adminInfo.Name
|
|
|
|
info.Type = in.Type
|
|
info.Content = in.Content
|
|
|
|
row, err := model.SystemModel{}.Init().Edit(w, &info)
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.Fail)
|
|
}
|
|
|
|
if row > utils.NumberZero {
|
|
action.NewContent = info
|
|
utils.SetActionLog(adminInfo, action)
|
|
}
|
|
|
|
return l.ok(info.Id)
|
|
}
|