feat: completed development wecom message
This commit is contained in:
@@ -1,77 +1,103 @@
|
||||
package handlers
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"base-service/app/dao"
|
||||
"base-service/app/models"
|
||||
"base-service/app/services/wecom/message/builder"
|
||||
"base-service/pkg/wecom/message"
|
||||
"base-service/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/wecom/message"
|
||||
"lone-services/services/wecom/internal/dao"
|
||||
"lone-services/services/wecom/internal/logic/message/builder"
|
||||
msgutil "lone-services/services/wecom/internal/logic/message/utils"
|
||||
)
|
||||
|
||||
type AddressNotifySecondHandler struct {
|
||||
}
|
||||
type AddressNotifySecondHandler struct{}
|
||||
|
||||
func (h AddressNotifySecondHandler) Build(job dao.WeComJob) ([]*message.SendRequest, error) {
|
||||
|
||||
logInfo := dao.EditLogInfo{}
|
||||
|
||||
models.EditLogModel{}.Init().GetOne(models.Params{
|
||||
Eq: map[string]string{
|
||||
"obj_id": strconv.Itoa(job.ObjId),
|
||||
"obj_type": strconv.Itoa(int(job.ObjType)),
|
||||
},
|
||||
Order: "id desc",
|
||||
}, &logInfo)
|
||||
|
||||
if logInfo.Id == dao.NumberZero {
|
||||
return nil, fmt.Errorf("edit log not found")
|
||||
}
|
||||
|
||||
// 需要返回的字段
|
||||
fields := []dao.FieldConfig{
|
||||
{
|
||||
Field: "type_name",
|
||||
Label: "门店名称",
|
||||
},
|
||||
{
|
||||
Field: "name",
|
||||
Label: "收货人",
|
||||
},
|
||||
{
|
||||
Field: "address",
|
||||
Label: "地址",
|
||||
},
|
||||
{
|
||||
Field: "district",
|
||||
Label: "地区",
|
||||
},
|
||||
{
|
||||
Field: "mobile",
|
||||
Label: "收货人电话",
|
||||
},
|
||||
}
|
||||
|
||||
content, err := BuildAddressDiff(logInfo.Content, fields)
|
||||
func (h AddressNotifySecondHandler) Build(ctx context.Context, job dao.WeComJob) ([]*message.SendRequest, error) {
|
||||
change, err := msgutil.GetLatestReviewChange(job.BizType, int64(job.BizId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
crad := builder.TextCardParams{
|
||||
fields := []dao.FieldConfig{
|
||||
{Field: "type_name", Label: "门店名称"},
|
||||
{Field: "name", Label: "收货人"},
|
||||
{Field: "address", Label: "地址"},
|
||||
{Field: "district", Label: "地区"},
|
||||
{Field: "mobile", Label: "收货人电话"},
|
||||
}
|
||||
|
||||
content, err := BuildAddressDiff(msgutil.DiffContent(change), fields)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
card := builder.TextCardParams{
|
||||
ToUser: utils.GetConfigString("wecom.address_reviewer_ids"),
|
||||
Desc: "地址通知",
|
||||
Title: "地址审核通知",
|
||||
Content: content,
|
||||
}
|
||||
|
||||
req, err := builder.TextCard(crad)
|
||||
|
||||
req, err := builder.TextCard(card)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return []*message.SendRequest{
|
||||
req,
|
||||
}, nil
|
||||
return []*message.SendRequest{req}, nil
|
||||
}
|
||||
|
||||
func BuildAddressDiff(content string, fields []dao.FieldConfig) ([]message.HorizontalContent, error) {
|
||||
var data struct {
|
||||
Old map[string]interface{} `json:"old"`
|
||||
New map[string]interface{} `json:"new"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(content), &data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make([]message.HorizontalContent, 0)
|
||||
districtOld := msgutil.GetMapString(data.Old, "district")
|
||||
districtNew := msgutil.GetMapString(data.New, "district")
|
||||
|
||||
for _, field := range fields {
|
||||
if field.Field == "district" {
|
||||
continue
|
||||
}
|
||||
|
||||
oldValue := msgutil.GetMapString(data.Old, field.Field)
|
||||
newValue := msgutil.GetMapString(data.New, field.Field)
|
||||
|
||||
if field.Field == "type_name" && newValue == utils.StringEmpty {
|
||||
newValue = oldValue
|
||||
}
|
||||
|
||||
if field.Field == "address" {
|
||||
if districtOld != utils.StringEmpty {
|
||||
oldValue = districtOld + oldValue
|
||||
}
|
||||
if districtNew != utils.StringEmpty {
|
||||
newValue = districtNew + newValue
|
||||
}
|
||||
}
|
||||
|
||||
if field.Field == "mobile" && oldValue != utils.StringEmpty {
|
||||
if decryptOld, err := utils.Decrypt(oldValue); err == nil {
|
||||
oldValue = decryptOld
|
||||
}
|
||||
}
|
||||
|
||||
value := newValue
|
||||
if oldValue != utils.StringEmpty &&
|
||||
oldValue != utils.StringZero &&
|
||||
oldValue != newValue {
|
||||
value = fmt.Sprintf("%s → %s", oldValue, newValue)
|
||||
}
|
||||
|
||||
result = append(result, message.HorizontalContent{
|
||||
KeyName: field.Label,
|
||||
Value: value,
|
||||
})
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user