feat: wecom message init
This commit is contained in:
@@ -3,9 +3,10 @@ package apply
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/redis"
|
||||
"lone-services/pkg/rpcclient"
|
||||
"lone-services/pkg/utils"
|
||||
chorepb "lone-services/rpc/chore/pb"
|
||||
"lone-services/services/product/internal/dao"
|
||||
"lone-services/services/product/internal/model"
|
||||
"lone-services/services/product/internal/wecom"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -66,8 +67,7 @@ func Del(ctx context.Context, uId, objId int) error {
|
||||
return redis.Client.Del(ctx, redisKey(uId, objId)).Err()
|
||||
}
|
||||
|
||||
// Set 发起编辑申请:写 Redis + action_apply_log,企微消息预留
|
||||
func Set(ctx context.Context, uId, objId int, reason string) error {
|
||||
func Set(ctx context.Context, choreSvcName string, uId, objId int, reason string) error {
|
||||
data := Data{
|
||||
Uid: uId,
|
||||
Id: objId,
|
||||
@@ -82,15 +82,7 @@ func Set(ctx context.Context, uId, objId int, reason string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
add := dao.ActionApplyLogCreate{
|
||||
AdminId: uId,
|
||||
ObjId: objId,
|
||||
Type: dao.EditLogTypeProduct,
|
||||
Reason: reason,
|
||||
Status: dao.ApplyStatusWaitPass,
|
||||
}
|
||||
err = model.ActionApplyLogModel{}.Init().Create(&add)
|
||||
if err != nil {
|
||||
if err = createApplyLog(ctx, choreSvcName, uId, objId, dao.EditLogTypeProduct, dao.ApplyStatusWaitPass, reason); err != nil {
|
||||
_ = Del(ctx, uId, objId)
|
||||
logx.WithContext(ctx).Errorf("action apply log create: %v", err)
|
||||
return err
|
||||
@@ -128,7 +120,6 @@ func saveRedis(ctx context.Context, data *Data) (string, error) {
|
||||
return md5, nil
|
||||
}
|
||||
|
||||
// CanEdit 是否已获编辑权限(申请通过)
|
||||
func CanEdit(ctx context.Context, uId, objId int) bool {
|
||||
data, err := Get(ctx, uId, objId)
|
||||
if err != nil {
|
||||
@@ -138,8 +129,7 @@ func CanEdit(ctx context.Context, uId, objId int) bool {
|
||||
return data.Status == dao.ApplyStatusDone
|
||||
}
|
||||
|
||||
// Pass 临时:将编辑申请置为通过(企微审批对接后删除)
|
||||
func Pass(ctx context.Context, uId, objId int) error {
|
||||
func Pass(ctx context.Context, choreSvcName string, uId, objId int) error {
|
||||
data, err := Get(ctx, uId, objId)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -171,15 +161,7 @@ func Pass(ctx context.Context, uId, objId int) error {
|
||||
return err
|
||||
}
|
||||
|
||||
add := dao.ActionApplyLogCreate{
|
||||
AdminId: uId,
|
||||
ObjId: objId,
|
||||
Type: dao.EditLogTypeProduct,
|
||||
Reason: reason,
|
||||
Status: dao.ApplyStatusDone,
|
||||
}
|
||||
err = model.ActionApplyLogModel{}.Init().Create(&add)
|
||||
if err != nil {
|
||||
if err = createApplyLog(ctx, choreSvcName, uId, objId, dao.EditLogTypeProduct, dao.ApplyStatusDone, reason); err != nil {
|
||||
logx.WithContext(ctx).Errorf("action apply log pass: %v", err)
|
||||
return err
|
||||
}
|
||||
@@ -194,6 +176,21 @@ func Pass(ctx context.Context, uId, objId int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func createApplyLog(ctx context.Context, choreSvcName string, adminId, objId int, typ, status uint8, reason string) error {
|
||||
cli, err := rpcclient.Get(choreSvcName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = chorepb.NewChoreClient(cli.Conn()).InternalActionApplyLogCreate(ctx, &chorepb.InternalActionApplyLogCreateReq{
|
||||
AdminId: int64(adminId),
|
||||
ObjId: int64(objId),
|
||||
Type: uint32(typ),
|
||||
Reason: reason,
|
||||
Status: uint32(status),
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
// errAlreadyHandled 申请已驳回等不可再通过
|
||||
var errAlreadyHandled = errApply("申请状态不可通过")
|
||||
|
||||
|
||||
@@ -23,12 +23,3 @@ type EditLogCreate struct {
|
||||
AdminId int `gorm:"column:admin_id"`
|
||||
AdminName string `gorm:"column:admin_name"`
|
||||
}
|
||||
|
||||
type ActionApplyLogCreate struct {
|
||||
Id int `gorm:"column:id;primaryKey;autoIncrement"`
|
||||
AdminId int `gorm:"column:admin_id"`
|
||||
ObjId int `gorm:"column:obj_id"`
|
||||
Type uint8 `gorm:"column:type"`
|
||||
Reason string `gorm:"column:reason"`
|
||||
Status uint8 `gorm:"column:status"`
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ func (l *EditApplyLogic) EditApply(in *product.EditApplyReq) (*product.Response,
|
||||
return outResponse(utils.Fail, "已经申请过"), nil
|
||||
}
|
||||
|
||||
if err = apply.Set(l.ctx, adminId, int(req.Id), req.Reason); err != nil {
|
||||
if err = apply.Set(l.ctx, l.svcCtx.ChoreSvcName, adminId, int(req.Id), req.Reason); err != nil {
|
||||
l.Errorf("edit apply set: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func (l *EditApplyLogic) EditApplyPass(in *product.EditApplyPassReq) (*product.R
|
||||
}
|
||||
adminId := int(adminInfo.ID)
|
||||
|
||||
if err = apply.Pass(l.ctx, adminId, int(req.Id)); err != nil {
|
||||
if err = apply.Pass(l.ctx, l.svcCtx.ChoreSvcName, adminId, int(req.Id)); err != nil {
|
||||
if apply.IsAlreadyHandled(err) {
|
||||
return outResponse(utils.Fail, err.Error()), nil
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/services/product/internal/dao"
|
||||
)
|
||||
|
||||
type ActionApplyLogModel struct {
|
||||
modelbase.Base
|
||||
}
|
||||
|
||||
func (m ActionApplyLogModel) TableName() string {
|
||||
return modelbase.Prefix() + "action_apply_log"
|
||||
}
|
||||
|
||||
func (m ActionApplyLogModel) Init() ActionApplyLogModel {
|
||||
m.Table = m.TableName()
|
||||
return m
|
||||
}
|
||||
|
||||
func (m ActionApplyLogModel) Create(data *dao.ActionApplyLogCreate) error {
|
||||
return m.Base.Create(data)
|
||||
}
|
||||
@@ -4,19 +4,26 @@ import (
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/product/internal/config"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
DB *gorm.DB
|
||||
Prefix string
|
||||
Config config.Config
|
||||
DB *gorm.DB
|
||||
Prefix string
|
||||
ChoreSvcName string
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext {
|
||||
choreSvc := utils.GetConfigString("services.chore")
|
||||
if choreSvc == utils.StringEmpty {
|
||||
logx.Error("config services.chore empty")
|
||||
}
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
DB: db,
|
||||
Prefix: utils.GetConfigString("mysql.prefix"),
|
||||
Config: c,
|
||||
DB: db,
|
||||
Prefix: utils.GetConfigString("mysql.prefix"),
|
||||
ChoreSvcName: choreSvc,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user