ce7aa18477
CI / changes (push) Successful in 12s
CI / ad (push) Successful in 1s
CI / admin (push) Successful in 0s
CI / bff (push) Failing after 25s
CI / chore (push) Successful in 1s
CI / express (push) Successful in 0s
CI / product (push) Successful in 27s
CI / sale (push) Successful in 0s
CI / user (push) Successful in 0s
CI / wecom (push) Successful in 25s
131 lines
2.6 KiB
Go
131 lines
2.6 KiB
Go
package logic
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/services/wecom/internal/dao"
|
|
"lone-services/services/wecom/internal/model"
|
|
|
|
jsoniter "github.com/json-iterator/go"
|
|
)
|
|
|
|
func departmentID() int {
|
|
id := utils.GetConfigInt("wecom.department_id")
|
|
if id < utils.NumberOne {
|
|
return utils.NumberOne
|
|
}
|
|
return id
|
|
}
|
|
|
|
func statusEnable(status uint8) int {
|
|
if status == dao.StatusDisabled {
|
|
return utils.NumberZero
|
|
}
|
|
return utils.NumberOne
|
|
}
|
|
|
|
func typeText(t uint8) string {
|
|
switch t {
|
|
case dao.UserTypeAdmin:
|
|
return "管理员"
|
|
case dao.UserTypeSale:
|
|
return "销售"
|
|
default:
|
|
return utils.StringEmpty
|
|
}
|
|
}
|
|
|
|
func userTypeOptions() []dao.UserTypeOption {
|
|
return []dao.UserTypeOption{
|
|
{ID: dao.UserTypeAdmin, Name: "管理员"},
|
|
{ID: dao.UserTypeSale, Name: "销售"},
|
|
}
|
|
}
|
|
|
|
func resolveStatus(reqStatus uint32, current uint8) uint8 {
|
|
if reqStatus == uint32(dao.StatusEnabled) || reqStatus == uint32(dao.StatusDisabled) {
|
|
return uint8(reqStatus)
|
|
}
|
|
if current > utils.NumberZero {
|
|
return current
|
|
}
|
|
return dao.StatusEnabled
|
|
}
|
|
|
|
func buildAgentsJSON(ids []int64) (string, error) {
|
|
ids = cleanAgentIds(ids)
|
|
if len(ids) == 0 {
|
|
return "", fmt.Errorf("应用不能为空")
|
|
}
|
|
|
|
idStrs := make([]string, 0, len(ids))
|
|
for _, id := range ids {
|
|
idStrs = append(idStrs, strconv.FormatInt(id, utils.NumberTen))
|
|
}
|
|
|
|
var rows []dao.WecomAgent
|
|
am := model.AgentModel{}.Init()
|
|
if err := am.Items(modelbase.Params{
|
|
In: map[string][]string{"id in ?": idStrs},
|
|
}, &rows); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
byID := make(map[int64]dao.WecomAgent, len(rows))
|
|
for _, row := range rows {
|
|
byID[row.Id] = row
|
|
}
|
|
|
|
items := make([]dao.UserAgentItem, 0, len(ids))
|
|
for _, id := range ids {
|
|
row, ok := byID[id]
|
|
if !ok {
|
|
return "", fmt.Errorf("应用不存在: %d", id)
|
|
}
|
|
items = append(items, dao.UserAgentItem{
|
|
Id: row.Id,
|
|
AgentId: row.AgentId,
|
|
Name: row.Name,
|
|
})
|
|
}
|
|
|
|
buf, err := jsoniter.Marshal(items)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(buf), nil
|
|
}
|
|
|
|
func parseAgents(raw string) []dao.UserAgentItem {
|
|
if raw == utils.StringEmpty {
|
|
return []dao.UserAgentItem{}
|
|
}
|
|
var items []dao.UserAgentItem
|
|
if err := jsoniter.Unmarshal([]byte(raw), &items); err != nil {
|
|
return []dao.UserAgentItem{}
|
|
}
|
|
if items == nil {
|
|
return []dao.UserAgentItem{}
|
|
}
|
|
return items
|
|
}
|
|
|
|
func cleanAgentIds(ids []int64) []int64 {
|
|
out := make([]int64, 0, len(ids))
|
|
seen := make(map[int64]struct{}, len(ids))
|
|
for _, id := range ids {
|
|
if id < utils.NumberOne {
|
|
continue
|
|
}
|
|
if _, ok := seen[id]; ok {
|
|
continue
|
|
}
|
|
seen[id] = struct{}{}
|
|
out = append(out, id)
|
|
}
|
|
return out
|
|
}
|