factory worker post
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
"lone-services/services/factory/internal/dao"
|
||||
"lone-services/services/factory/internal/model"
|
||||
"strconv"
|
||||
|
||||
"lone-services/rpc/factory/pb"
|
||||
"lone-services/services/factory/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type PostStatusLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewPostStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PostStatusLogic {
|
||||
return &PostStatusLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *PostStatusLogic) PostStatus(in *factory.StatusRequest) (*factory.Response, error) {
|
||||
var v validate.StatusValidator
|
||||
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 action = utils.ActionAdd{}
|
||||
var info dao.PostStatus
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}}
|
||||
modelObj := model.PostModel{}.Init()
|
||||
err := modelObj.GetOne(w, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
action.OldContent = info
|
||||
info.Status = in.Status
|
||||
info.Reason = in.Reason
|
||||
info.AdminName = adminInfo.Name
|
||||
info.AdminId = adminInfo.ID
|
||||
row, editErr := modelObj.Edit(w, info)
|
||||
if editErr != nil {
|
||||
l.Logger.Error(editErr)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
if row > utils.NumberZero {
|
||||
action.NewContent = info
|
||||
action.Reason = in.Reason
|
||||
action.Type = utils.LogActionTypeStatus
|
||||
action.ModuleName = utils.LogActionModuleFactoryPost
|
||||
utils.SetActionLog(adminInfo, action)
|
||||
}
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
Reference in New Issue
Block a user