You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
252 lines
8.9 KiB
252 lines
8.9 KiB
package flowchart
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"key_performance_indicators/api/workflow/currency_recipe"
|
|
"key_performance_indicators/api/workwechat"
|
|
"key_performance_indicators/models/modelshr"
|
|
"key_performance_indicators/models/modelskpi"
|
|
"key_performance_indicators/overall"
|
|
"key_performance_indicators/overall/publicmethod"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-04-23 14:29:55
|
|
@ 功能: 统一发送信息
|
|
@ 参数
|
|
|
|
#orderId 审批记录编号
|
|
#nodeCont 节点内容
|
|
#operate 操作(1:通过;2:驳回;3:抄送)
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func SendTogetherMsg(orderId int64, nodeCont currency_recipe.NodeCont, operate int) (callbackMsgStr string, err error) {
|
|
if orderId == 0 {
|
|
return
|
|
}
|
|
if len(nodeCont.UserList) <= 0 {
|
|
return
|
|
}
|
|
var recipient []string //接收人
|
|
for _, v := range nodeCont.UserList { //获取接收人得微信或企业微信Openid用作发送消息的唯一识别码
|
|
if v.Wechat != "" {
|
|
if !publicmethod.IsInTrue[string](v.Wechat, recipient) {
|
|
recipient = append(recipient, v.Wechat)
|
|
}
|
|
} else {
|
|
var userCont modelshr.PersonArchives
|
|
userCont.GetCont(map[string]interface{}{"`key`": v.Id}, "`wechat`", "`work_wechat`")
|
|
if userCont.Wechat != "" {
|
|
if !publicmethod.IsInTrue[string](userCont.Wechat, recipient) {
|
|
recipient = append(recipient, userCont.Wechat)
|
|
}
|
|
}
|
|
if userCont.WorkWechat != "" {
|
|
if !publicmethod.IsInTrue[string](userCont.WorkWechat, recipient) {
|
|
recipient = append(recipient, userCont.WorkWechat)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if len(recipient) <= 0 {
|
|
return
|
|
}
|
|
var workflowCont modelskpi.EvaluationProcess
|
|
err = workflowCont.GetCont(map[string]interface{}{"ep_order_key": orderId})
|
|
if err != nil {
|
|
return
|
|
}
|
|
//开始组装消息内容
|
|
var sendMsg workwechat.SentMiniMessage
|
|
sendMsg.ToUser = strings.Join(recipient, "|") //收件人配置
|
|
var templateCard workwechat.TemplateCardMsgContMini //模版卡片主体
|
|
//头部左标题部分
|
|
nodeType := publicmethod.GetSetpNodeName(nodeCont.Type)
|
|
templateCard.Source.Desc = fmt.Sprintf("%v-%v", nodeCont.NodeName, nodeType)
|
|
//任务id,同一个应用任务id不能重复,只能由数字、字母和“_-@”组成
|
|
uuid := publicmethod.GetUUid(7) //上报数据唯一识别码
|
|
templateCard.TaskId = fmt.Sprintf("kpi_ratify_%v", uuid)
|
|
if workflowCont.TypeClass == 1 { //定性操作
|
|
msgCont, errs := SendMsgDingXing(orderId)
|
|
if errs != nil {
|
|
return
|
|
}
|
|
templateCard.MainTitle.Title = msgCont.DimeContTitle
|
|
templateCard.MainTitle.Desc = msgCont.TargetContTitle
|
|
templateCard.QuoteArea.Title = msgCont.BylawsContTitle
|
|
templateCard.QuoteArea.QuoteText = msgCont.QuoteText
|
|
} else { //定量操作
|
|
msgCont, errs := SendMsgDingLiang(workflowCont)
|
|
if errs != nil {
|
|
return
|
|
}
|
|
templateCard.MainTitle.Title = msgCont.OccurrenceTime
|
|
templateCard.QuoteArea.QuoteText = msgCont.QuoteText
|
|
}
|
|
//二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6
|
|
var userRecarCont modelshr.PersonArchives
|
|
userRecarCont.GetCont(map[string]interface{}{"`key`": workflowCont.Creater}, "`number`", "`name`", "`wechat`", "`work_wechat`", "`maindeparment`")
|
|
recipientWechat := userRecarCont.Wechat
|
|
if userRecarCont.WorkWechat != "" {
|
|
recipientWechat = userRecarCont.WorkWechat
|
|
}
|
|
var orgContInfo modelshr.AdministrativeOrganization
|
|
orgContInfo.GetCont(map[string]interface{}{"`id`": userRecarCont.MainDeparment}, "name")
|
|
var hcListCont1 workwechat.HorizontalContentListCont
|
|
hcListCont1.Type = 0
|
|
hcListCont1.Keyname = "提报部门:"
|
|
hcListCont1.Value = orgContInfo.Name
|
|
templateCard.HorizontalContentList = append(templateCard.HorizontalContentList, hcListCont1)
|
|
var hcListCont3 workwechat.HorizontalContentListCont
|
|
hcListCont3.Keyname = "提报人:"
|
|
hcListCont3.Value = fmt.Sprintf("%v(%v)", userRecarCont.Name, userRecarCont.Number)
|
|
if recipientWechat != "" {
|
|
hcListCont3.Type = 3
|
|
hcListCont3.UserId = recipientWechat
|
|
} else {
|
|
hcListCont3.Type = 0
|
|
}
|
|
templateCard.HorizontalContentList = append(templateCard.HorizontalContentList, hcListCont3)
|
|
//审批详情访问地址
|
|
jumpUrl := fmt.Sprintf("%v/#/pages/approval/departworkflowcont?id=%v", overall.CONSTANT_CONFIG.Appsetup.WebUrl, workflowCont.Id)
|
|
//跳转指引样式的列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过3
|
|
var jmpCont1 workwechat.JumpListCont
|
|
jmpCont1.Type = 1
|
|
jmpCont1.Title = "前往处理"
|
|
jmpCont1.Url = jumpUrl
|
|
templateCard.JumpList = append(templateCard.JumpList, jmpCont1)
|
|
//整体卡片的点击跳转事件,text_notice必填本字段
|
|
templateCard.CardAction.Url = jumpUrl
|
|
sendMsg.TemplateCard = templateCard
|
|
callbackMsg, err := sendMsg.InitMes().SendMessage()
|
|
callbackMsgStr = string(callbackMsg)
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-04-23 15:09:41
|
|
@ 功能:
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func SendMsgDingLiang(workflowCont modelskpi.EvaluationProcess) (msgCont CallBackSendMsgContLiang, err error) {
|
|
msgCont.OccurrenceTime = fmt.Sprintf("考核周期:%v", publicmethod.UnixTimeToDay(workflowCont.HappenTime, 15))
|
|
var flowLogCont modelskpi.FlowLog
|
|
err = flowLogCont.GetCont(map[string]interface{}{"fl_key": workflowCont.OrderKey}, "fl_baseline")
|
|
if err != nil {
|
|
return
|
|
}
|
|
var allZreoConfig []FlowLogAllZreo
|
|
json.Unmarshal([]byte(flowLogCont.Baseline), &allZreoConfig)
|
|
var flogDataList []modelskpi.FlowLogData
|
|
err = overall.CONSTANT_DB_KPI.Where("fld_flow_log = ?", workflowCont.OrderKey).Find(&flogDataList).Error
|
|
if err != nil || len(flogDataList) < 1 {
|
|
return
|
|
}
|
|
var yinYongWenXian []string
|
|
for _, v := range flogDataList {
|
|
var targetCont modelskpi.EvaluationTarget
|
|
targetCont.GetCont(map[string]interface{}{"`et_id`": v.TargetId}, "`et_id`", "`et_title`")
|
|
|
|
var lsZeroprize float64
|
|
var lsAllprize float64
|
|
var lsCapping float64
|
|
var targetWeight int64
|
|
for _, cv := range allZreoConfig {
|
|
tarStrId := strconv.FormatInt(v.TargetId, 10)
|
|
if cv.TargetId == tarStrId {
|
|
lsZeroprize = cv.Zeroprize
|
|
lsAllprize = cv.Allprize
|
|
lsCapping = cv.Capping
|
|
targetWeight = cv.TargetWeight
|
|
}
|
|
}
|
|
|
|
scoreVal, _, _, _, _ := publicmethod.CalculateScore(targetWeight, float64(v.Score), lsAllprize, lsZeroprize, lsCapping, 2)
|
|
if v.ScoringMethod == 1 {
|
|
yinYongWenXian = append(yinYongWenXian, fmt.Sprintf("指标:%v\n实际值:%v\n达成率:%v\n得分:%v", targetCont.Title, publicmethod.DecimalEs(float64(v.Score)/100, 2), v.Content, scoreVal))
|
|
} else {
|
|
|
|
yinYongWenXian = append(yinYongWenXian, fmt.Sprintf("指标:%v\n实际值:%v\n达成率:%v\n得分:%v\n手动分:%v\n原因:%v", targetCont.Title, publicmethod.DecimalEs(float64(v.Score)/100, 2), v.Content, scoreVal, publicmethod.DecimalEs(float64(v.ScoringScore)/100, 2), v.Content))
|
|
}
|
|
|
|
}
|
|
msgCont.QuoteText = strings.Join(yinYongWenXian, "\n")
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-04-23 15:07:43
|
|
@ 功能: 定性操作
|
|
@ 参数
|
|
|
|
#orderId 流程ID
|
|
|
|
@ 返回值
|
|
|
|
#msgCont 返回值
|
|
#err 错误信息
|
|
|
|
@ 方法原型
|
|
|
|
#func SendMsgDingXing(orderId int64) (msgCont CallBackSendMsgCont, err error)
|
|
*/
|
|
func SendMsgDingXing(orderId int64) (msgCont CallBackSendMsgCont, err error) {
|
|
var scoreFlowCont modelskpi.ScoreFlow
|
|
err = scoreFlowCont.GetCont(map[string]interface{}{"sf_key": orderId})
|
|
if err != nil {
|
|
//指标
|
|
var targetCont modelskpi.EvaluationTarget
|
|
targetCont.GetCont(map[string]interface{}{"`et_id`": scoreFlowCont.TargetId}, "`et_id`", "`et_title`")
|
|
msgCont.TargetContTitle = targetCont.Title
|
|
var dimeCont modelskpi.DutyClass
|
|
dimeCont.GetCont(map[string]interface{}{"`id`": targetCont.Id}, "`title`")
|
|
msgCont.DimeContTitle = dimeCont.Title
|
|
var bylawsCont modelskpi.DetailedTarget
|
|
bylawsCont.GetCont(map[string]interface{}{"`dt_id`": scoreFlowCont.DetailedId}, "`dt_title`")
|
|
msgCont.BylawsContTitle = bylawsCont.Title
|
|
|
|
//1:加分;2:减分"`
|
|
if scoreFlowCont.PlusReduceScore == 1 {
|
|
if scoreFlowCont.Reason != "" {
|
|
msgCont.QuoteText = fmt.Sprintf("奖励: %v 分\n原因:%v\n发生时间:%v", publicmethod.DecimalEs(float64(scoreFlowCont.Score)/100, 2), scoreFlowCont.Reason, publicmethod.UnixTimeToDay(scoreFlowCont.HappenTime, 12))
|
|
} else {
|
|
msgCont.QuoteText = fmt.Sprintf("奖励: %v 分\n发生时间:%v", publicmethod.DecimalEs(float64(scoreFlowCont.Score)/100, 2), publicmethod.UnixTimeToDay(scoreFlowCont.HappenTime, 12))
|
|
}
|
|
} else {
|
|
if scoreFlowCont.Reason != "" {
|
|
msgCont.QuoteText = fmt.Sprintf("扣除: %v 分\n原因:%v\n发生时间:%v", publicmethod.DecimalEs(float64(scoreFlowCont.Score)/100, 2), scoreFlowCont.Reason, publicmethod.UnixTimeToDay(scoreFlowCont.HappenTime, 12))
|
|
} else {
|
|
msgCont.QuoteText = fmt.Sprintf("扣除: %v 分\n发生时间:%v", publicmethod.DecimalEs(float64(scoreFlowCont.Score)/100, 2), publicmethod.UnixTimeToDay(scoreFlowCont.HappenTime, 12))
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//
|
|
|