Files
lone-services/services/wecom/internal/logic/message/utils/helper.go
T

49 lines
1.0 KiB
Go

package utils
import (
"fmt"
"lone-services/pkg/utils"
"lone-services/pkg/wecom/message"
)
func GetMapString(data map[string]interface{}, key string) string {
val, ok := data[key]
if !ok || val == nil {
return utils.StringEmpty
}
return fmt.Sprintf("%v", val)
}
func GetExtString(ext map[string]any, key string) string {
v, ok := ext[key].(string)
if !ok || v == "" {
return "无"
}
return v
}
func BuildContent(kvPairs ...struct{ Key, Value string }) []message.HorizontalContent {
const maxTotal = 6
const fixedItems = 1
maxInput := maxTotal - fixedItems
inputCount := len(kvPairs)
if inputCount > maxInput {
inputCount = maxInput
}
content := make([]message.HorizontalContent, 0, inputCount+fixedItems)
for i := 0; i < inputCount; i++ {
content = append(content, message.HorizontalContent{
KeyName: kvPairs[i].Key,
Value: kvPairs[i].Value,
})
}
content = append(content, message.HorizontalContent{
KeyName: "审核时间",
Value: utils.Now().Format(),
})
return content
}