feat: completed development wecom message
This commit is contained in:
@@ -1,149 +1,96 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"base-service/app/dao"
|
||||
"base-service/app/models"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/wecom/internal/dao"
|
||||
"lone-services/services/wecom/internal/model"
|
||||
)
|
||||
|
||||
// ActionUser 审核相关操作人(姓名来自变更快照)
|
||||
type ActionUser struct {
|
||||
Id int64
|
||||
Name string
|
||||
}
|
||||
|
||||
func GetApplicantUser(objId int, objType uint8, career uint8) (*dao.WecomUser, error) {
|
||||
|
||||
w := models.Params{
|
||||
Eq: map[string]string{
|
||||
"obj_id": strconv.Itoa(objId),
|
||||
"obj_type": strconv.Itoa(int(objType)),
|
||||
},
|
||||
Order: "id desc",
|
||||
}
|
||||
|
||||
editLog := dao.EditLogInfo{}
|
||||
err := models.EditLogModel{}.Init().GetOne(w, &editLog)
|
||||
change, err := GetLatestReviewChange(objType, int64(objId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
uw := models.Params{
|
||||
Eq: map[string]string{
|
||||
"obj_id": strconv.Itoa(editLog.AdminId),
|
||||
"obj_type": strconv.Itoa(int(career)),
|
||||
"status": strconv.Itoa(int(dao.StatusOk)),
|
||||
},
|
||||
}
|
||||
|
||||
user := dao.WecomUser{}
|
||||
err = models.WecomUserModel{}.Init().GetOne(uw, &user)
|
||||
err = model.UserModel{}.Init().GetOne(modelbase.Params{
|
||||
Eq: map[string]string{
|
||||
"user_id": strconv.FormatInt(change.AdminId, 10),
|
||||
"type": strconv.FormatUint(uint64(career), 10),
|
||||
"status": strconv.Itoa(int(dao.StatusEnabled)),
|
||||
},
|
||||
}, &user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
func GetAdminUser(objId int, objType uint8) (*dao.Admin, error) {
|
||||
|
||||
w := models.Params{
|
||||
Eq: map[string]string{
|
||||
"obj_id": strconv.Itoa(objId),
|
||||
"obj_type": strconv.Itoa(int(objType)),
|
||||
},
|
||||
Order: "id desc",
|
||||
}
|
||||
|
||||
editLog := dao.EditLogInfo{}
|
||||
err := models.EditLogModel{}.Init().GetOne(w, &editLog)
|
||||
func GetActionUser(objId int, objType uint8) (*ActionUser, error) {
|
||||
change, err := GetLatestReviewChange(objType, int64(objId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user := dao.Admin{}
|
||||
|
||||
err = models.AdminUserModel{}.Init().GetOne(models.Params{
|
||||
Eq: map[string]string{
|
||||
"id": strconv.Itoa(editLog.AdminId),
|
||||
},
|
||||
}, &user)
|
||||
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
func GetActionUser(objId int, objType uint8) (*dao.Admin, error) {
|
||||
|
||||
w := models.Params{
|
||||
Eq: map[string]string{
|
||||
"obj_id": strconv.Itoa(objId),
|
||||
"type": strconv.Itoa(int(objType)),
|
||||
},
|
||||
Order: "id desc",
|
||||
}
|
||||
|
||||
apply := dao.ActionApplyLogInfo{}
|
||||
err := models.ActionApplyLogModel{}.Init().GetOne(w, &apply)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user := dao.Admin{}
|
||||
|
||||
err = models.AdminUserModel{}.Init().GetOne(models.Params{
|
||||
Eq: map[string]string{
|
||||
"id": strconv.Itoa(apply.AdminId),
|
||||
},
|
||||
}, &user)
|
||||
|
||||
return &user, nil
|
||||
return &ActionUser{
|
||||
Id: change.AdminId,
|
||||
Name: change.AdminName,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func GetActionWecomUser(objId int, objType uint8) (*dao.WecomUser, error) {
|
||||
|
||||
w := models.Params{
|
||||
Eq: map[string]string{
|
||||
"obj_id": strconv.Itoa(objId),
|
||||
"type": strconv.Itoa(int(objType)),
|
||||
},
|
||||
Order: "id desc",
|
||||
}
|
||||
|
||||
apply := dao.ActionApplyLogInfo{}
|
||||
err := models.ActionApplyLogModel{}.Init().GetOne(w, &apply)
|
||||
change, err := GetLatestReviewChange(objType, int64(objId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user := dao.Admin{}
|
||||
|
||||
err = models.AdminUserModel{}.Init().GetOne(models.Params{
|
||||
user := dao.WecomUser{}
|
||||
err = model.UserModel{}.Init().GetOne(modelbase.Params{
|
||||
Eq: map[string]string{
|
||||
"id": strconv.Itoa(apply.AdminId),
|
||||
"user_id": strconv.FormatInt(change.AdminId, 10),
|
||||
"type": strconv.Itoa(int(dao.UserTypeAdmin)),
|
||||
"status": strconv.Itoa(int(dao.StatusEnabled)),
|
||||
},
|
||||
}, &user)
|
||||
|
||||
uw := models.Params{
|
||||
Eq: map[string]string{
|
||||
"obj_id": strconv.Itoa(user.Id),
|
||||
"obj_type": strconv.Itoa(dao.NumberTwo),
|
||||
"status": strconv.Itoa(int(dao.StatusOk)),
|
||||
},
|
||||
}
|
||||
|
||||
wecom := dao.WecomUser{}
|
||||
err = models.WecomUserModel{}.Init().GetOne(uw, &wecom)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &wecom, nil
|
||||
if user.Id < 1 {
|
||||
// 再试销售类型
|
||||
err = model.UserModel{}.Init().GetOne(modelbase.Params{
|
||||
Eq: map[string]string{
|
||||
"user_id": strconv.FormatInt(change.AdminId, 10),
|
||||
"type": strconv.Itoa(int(dao.UserTypeSale)),
|
||||
"status": strconv.Itoa(int(dao.StatusEnabled)),
|
||||
},
|
||||
}, &user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if user.Id < 1 {
|
||||
return nil, fmt.Errorf("wecom user not found for admin_id=%d", change.AdminId)
|
||||
}
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
func JoinWecomUsers(users ...string) string {
|
||||
|
||||
result := make([]string, 0)
|
||||
|
||||
result := make([]string, 0, len(users))
|
||||
for _, user := range users {
|
||||
|
||||
if user == "" {
|
||||
if user == utils.StringEmpty {
|
||||
continue
|
||||
}
|
||||
|
||||
result = append(result, user)
|
||||
}
|
||||
|
||||
return strings.Join(result, "|")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user