feat: completed development wecom message

This commit is contained in:
zzw
2026-09-18 17:39:48 +08:00
parent dd460f6be2
commit 1ca44d25df
57 changed files with 1754 additions and 1412 deletions
+11 -11
View File
@@ -5,9 +5,9 @@ import (
"lone-services/pkg/redis"
"lone-services/pkg/rpcclient"
"lone-services/pkg/utils"
"lone-services/pkg/wecomrpc"
chorepb "lone-services/rpc/chore/pb"
"lone-services/services/product/internal/dao"
"lone-services/services/product/internal/wecom"
"strconv"
"time"
@@ -67,7 +67,7 @@ func Del(ctx context.Context, uId, objId int) error {
return redis.Client.Del(ctx, redisKey(uId, objId)).Err()
}
func Set(ctx context.Context, choreSvcName string, uId, objId int, reason string) error {
func Set(ctx context.Context, choreSvcName, wecomSvcName string, uId, objId int, reason string) error {
data := Data{
Uid: uId,
Id: objId,
@@ -88,10 +88,10 @@ func Set(ctx context.Context, choreSvcName string, uId, objId int, reason string
return err
}
wecom.NotifyProduct(wecom.NotifyJob{
ObjId: objId,
ObjType: dao.EditLogTypeProduct,
Type: wecom.ProductApplyReview,
wecomrpc.SendMessage(ctx, wecomSvcName, wecomrpc.SendMessageJob{
BizId: objId,
BizType: wecomrpc.BizTypeProduct,
Type: wecomrpc.ProductApplyReview,
Reason: reason,
Key: md5,
})
@@ -129,7 +129,7 @@ func CanEdit(ctx context.Context, uId, objId int) bool {
return data.Status == dao.ApplyStatusDone
}
func Pass(ctx context.Context, choreSvcName string, uId, objId int) error {
func Pass(ctx context.Context, choreSvcName, wecomSvcName string, uId, objId int) error {
data, err := Get(ctx, uId, objId)
if err != nil {
return err
@@ -166,10 +166,10 @@ func Pass(ctx context.Context, choreSvcName string, uId, objId int) error {
return err
}
wecom.NotifyProduct(wecom.NotifyJob{
ObjId: objId,
ObjType: dao.EditLogTypeProduct,
Type: wecom.ProductNeedReview,
wecomrpc.SendMessage(ctx, wecomSvcName, wecomrpc.SendMessageJob{
BizId: objId,
BizType: wecomrpc.BizTypeProduct,
Type: wecomrpc.ProductNeedReview,
Action: dao.ApplyStatusDone,
Reason: reason,
})
+7 -5
View File
@@ -1,11 +1,13 @@
package dao
// 编辑日志对象类型
import "lone-services/pkg/wecomrpc"
// 编辑对象类型(与 wecomrpc.BizType* 一致,供申请日志等非企微场景复用)
const (
EditLogTypeProduct uint8 = 1 // 产品
EditLogTypeStore uint8 = 2 // 门店
EditLogTypeAddress uint8 = 3 // 地址
EditLogTypeSales uint8 = 4 // 销售
EditLogTypeProduct = wecomrpc.BizTypeProduct
EditLogTypeStore = wecomrpc.BizTypeStore
EditLogTypeAddress = wecomrpc.BizTypeAddress
EditLogTypeSales = wecomrpc.BizTypeSales
)
// 编辑申请状态(Redis / action_apply_log)
@@ -63,7 +63,7 @@ func (l *EditApplyLogic) EditApply(in *product.EditApplyReq) (*product.Response,
return outResponse(utils.Fail, "已经申请过"), nil
}
if err = apply.Set(l.ctx, l.svcCtx.ChoreSvcName, adminId, int(req.Id), req.Reason); err != nil {
if err = apply.Set(l.ctx, l.svcCtx.ChoreSvcName, l.svcCtx.WecomSvcName, 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, l.svcCtx.ChoreSvcName, adminId, int(req.Id)); err != nil {
if err = apply.Pass(l.ctx, l.svcCtx.ChoreSvcName, l.svcCtx.WecomSvcName, adminId, int(req.Id)); err != nil {
if apply.IsAlreadyHandled(err) {
return outResponse(utils.Fail, err.Error()), nil
}
@@ -5,12 +5,12 @@ import (
"lone-services/pkg/modelbase"
"lone-services/pkg/utils"
"lone-services/pkg/validate"
"lone-services/pkg/wecomrpc"
product "lone-services/rpc/product/pb"
"lone-services/services/product/internal/apply"
"lone-services/services/product/internal/dao"
"lone-services/services/product/internal/model"
"lone-services/services/product/internal/svc"
"lone-services/services/product/internal/wecom"
"lone-services/services/product/validator"
"strconv"
"time"
@@ -115,11 +115,18 @@ func (l *EditBaseLogic) EditBase(in *product.EditBaseReq) (*product.Response, er
return failResponse(utils.Fail), nil
}
addEditLog(int(req.Id), dao.EditLogTypeProduct, adminId, adminName, data, old)
wecom.NotifyProduct(wecom.NotifyJob{
ObjId: int(req.Id),
ObjType: dao.EditLogTypeProduct,
Type: wecom.ProductOrdinaryReview,
wecomrpc.CreateReviewChange(l.ctx, l.svcCtx.WecomSvcName, wecomrpc.ReviewChange{
Type: wecomrpc.BizTypeProduct,
BizId: req.Id,
BeforeData: utils.StructToJson(old),
AfterData: utils.StructToJson(data),
AdminId: int64(adminId),
AdminName: adminName,
})
wecomrpc.SendMessage(l.ctx, l.svcCtx.WecomSvcName, wecomrpc.SendMessageJob{
BizId: int(req.Id),
BizType: wecomrpc.BizTypeProduct,
Type: wecomrpc.ProductOrdinaryReview,
})
_ = apply.Del(l.ctx, adminId, int(req.Id))
@@ -1,27 +0,0 @@
package logic
import (
"lone-services/pkg/utils"
"lone-services/services/product/internal/dao"
"lone-services/services/product/internal/model"
"github.com/zeromicro/go-zero/core/logx"
)
func addEditLog(objId int, objType uint8, adminId int, adminName string, data, oldData interface{}) {
content := map[string]interface{}{
"new": data,
"old": oldData,
}
add := dao.EditLogCreate{
ObjId: objId,
ObjType: objType,
Content: utils.StructToJson(content),
AdminId: adminId,
AdminName: adminName,
}
err := model.EditLogModel{}.Init().Create(&add)
if err != nil {
logx.Errorf("edit log create: %v", err)
}
}
@@ -5,12 +5,12 @@ import (
"lone-services/pkg/modelbase"
"lone-services/pkg/utils"
"lone-services/pkg/validate"
"lone-services/pkg/wecomrpc"
product "lone-services/rpc/product/pb"
"lone-services/services/product/internal/apply"
"lone-services/services/product/internal/dao"
"lone-services/services/product/internal/model"
"lone-services/services/product/internal/svc"
"lone-services/services/product/internal/wecom"
"lone-services/services/product/validator"
"strconv"
@@ -119,11 +119,18 @@ func (l *EditSusceptibleLogic) EditSusceptible(in *product.EditSusceptibleReq) (
return failResponse(utils.Fail), nil
}
addEditLog(int(req.Id), dao.EditLogTypeProduct, adminId, adminName, data, old)
wecom.NotifyProduct(wecom.NotifyJob{
ObjId: int(req.Id),
ObjType: dao.EditLogTypeProduct,
Type: wecom.ProductSubmitReview,
wecomrpc.CreateReviewChange(l.ctx, l.svcCtx.WecomSvcName, wecomrpc.ReviewChange{
Type: wecomrpc.BizTypeProduct,
BizId: req.Id,
BeforeData: utils.StructToJson(old),
AfterData: utils.StructToJson(data),
AdminId: int64(adminId),
AdminName: adminName,
})
wecomrpc.SendMessage(l.ctx, l.svcCtx.WecomSvcName, wecomrpc.SendMessageJob{
BizId: int(req.Id),
BizType: wecomrpc.BizTypeProduct,
Type: wecomrpc.ProductSubmitReview,
})
_ = apply.Del(l.ctx, adminId, int(req.Id))
@@ -6,11 +6,11 @@ import (
"lone-services/pkg/modelbase"
"lone-services/pkg/utils"
"lone-services/pkg/validate"
"lone-services/pkg/wecomrpc"
product "lone-services/rpc/product/pb"
"lone-services/services/product/internal/dao"
"lone-services/services/product/internal/model"
"lone-services/services/product/internal/svc"
"lone-services/services/product/internal/wecom"
"lone-services/services/product/validator"
"strconv"
"time"
@@ -170,14 +170,14 @@ func (l *VerifyStatusLogic) verifyStatus(expectStatus uint8, in *product.VerifyS
return failResponse(utils.Fail), nil
}
notifyType := wecom.ProductFirstReview
notifyType := wecomrpc.ProductFirstReview
if expectStatus == dao.VerifyStatusSecond {
notifyType = wecom.ProductSecondReview
notifyType = wecomrpc.ProductSecondReview
}
objID, _ := strconv.Atoi(info.VerifyId)
wecom.NotifyProduct(wecom.NotifyJob{
ObjId: objID,
ObjType: dao.VerifyTypeProduct,
wecomrpc.SendMessage(l.ctx, l.svcCtx.WecomSvcName, wecomrpc.SendMessageJob{
BizId: objID,
BizType: wecomrpc.BizTypeProduct,
Type: notifyType,
Action: uint8(req.Status),
Reason: reason,
@@ -1,23 +0,0 @@
package model
import (
"lone-services/pkg/modelbase"
"lone-services/services/product/internal/dao"
)
type EditLogModel struct {
modelbase.Base
}
func (m EditLogModel) TableName() string {
return modelbase.Prefix() + "edit_log"
}
func (m EditLogModel) Init() EditLogModel {
m.Table = m.TableName()
return m
}
func (m EditLogModel) Create(data *dao.EditLogCreate) error {
return m.Base.Create(data)
}
@@ -13,6 +13,7 @@ type ServiceContext struct {
DB *gorm.DB
Prefix string
ChoreSvcName string
WecomSvcName string
}
func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext {
@@ -20,10 +21,15 @@ func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext {
if choreSvc == utils.StringEmpty {
logx.Error("config services.chore empty")
}
wecomSvc := utils.GetConfigString("services.wecom")
if wecomSvc == utils.StringEmpty {
logx.Error("config services.wecom empty")
}
return &ServiceContext{
Config: c,
DB: db,
Prefix: utils.GetConfigString("mysql.prefix"),
ChoreSvcName: choreSvc,
WecomSvcName: wecomSvc,
}
}
-26
View File
@@ -1,26 +0,0 @@
package wecom
import "github.com/zeromicro/go-zero/core/logx"
const (
ProductApplyReview uint8 = 1 // 编辑申请按钮卡片
ProductNeedReview uint8 = 2 // 编辑申请结果通知申请人
ProductSubmitReview uint8 = 3 // 提交敏感字段变更 → 通知一审
ProductFirstReview uint8 = 4 // 一审结果通知
ProductSecondReview uint8 = 5 // 二审结果通知
ProductOrdinaryReview uint8 = 6 // 基础信息变更 diff 通知
)
type NotifyJob struct {
ObjId int
ObjType uint8
Type uint8
Action uint8 // 1: 通过, 2: 驳回
Reason string
Key string // 编辑申请 Redis MD5 key,企微回调用
}
func NotifyProduct(job NotifyJob) {
logx.Infof("wecom stub skip: type=%d objId=%d action=%d reason=%s key=%s",
job.Type, job.ObjId, job.Action, job.Reason, job.Key)
}