feat: wecom curd
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
wecomuser "lone-services/pkg/wecom/user"
|
||||
wecom "lone-services/rpc/wecom/pb"
|
||||
"lone-services/services/wecom/internal/client"
|
||||
"lone-services/services/wecom/internal/dao"
|
||||
"lone-services/services/wecom/internal/model"
|
||||
"lone-services/services/wecom/internal/svc"
|
||||
"lone-services/services/wecom/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type StatusUserLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewStatusUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatusUserLogic {
|
||||
return &StatusUserLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *StatusUserLogic) StatusUser(in *wecom.StatusUserReq) (*wecom.Response, error) {
|
||||
var req validator.StatusUserValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
m := model.UserModel{}.Init()
|
||||
var row dao.WecomUser
|
||||
if err := m.GetOne(modelbase.Params{
|
||||
Eq: map[string]string{"id": strconv.FormatInt(req.Id, utils.NumberTen)},
|
||||
}, &row); err != nil {
|
||||
l.Errorf("wecom status user get: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
if row.Id < utils.NumberOne {
|
||||
return failResponse(utils.ErrorNotFund), nil
|
||||
}
|
||||
|
||||
userStatus := uint8(req.Status)
|
||||
plainMobile, err := utils.DecryptPhone(row.Mobile)
|
||||
if err != nil {
|
||||
l.Errorf("wecom status decrypt mobile: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
if !utils.GetConfigBool("wecom.skip") {
|
||||
updateReq := wecomuser.UpdateRequest{
|
||||
UserId: row.WecomUserId,
|
||||
Name: row.Name,
|
||||
Mobile: plainMobile,
|
||||
Enable: statusEnable(userStatus),
|
||||
}
|
||||
if row.Avatar != utils.StringEmpty {
|
||||
updateReq.AvatarMediaID = row.Avatar
|
||||
}
|
||||
if err := client.NewContactClient().Update(l.ctx, updateReq); err != nil {
|
||||
l.Errorf("wecom http status user: %v", err)
|
||||
return failWecomHTTP(), nil
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := m.Edit(modelbase.Params{
|
||||
Eq: map[string]string{"id": strconv.FormatInt(row.Id, utils.NumberTen)},
|
||||
}, map[string]interface{}{
|
||||
"status": userStatus,
|
||||
"updated_at": utils.Now(),
|
||||
}); err != nil {
|
||||
l.Errorf("wecom status user db: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
return okResponse(nil), nil
|
||||
}
|
||||
Reference in New Issue
Block a user