22 changed files with 1261 additions and 34 deletions
@ -0,0 +1,252 @@ |
|||
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 |
|||
} |
|||
|
|||
//
|
|||
@ -0,0 +1,71 @@ |
|||
package modelskpi |
|||
|
|||
import ( |
|||
"key_performance_indicators/overall" |
|||
"strings" |
|||
) |
|||
|
|||
// 企业微信模版信息发送回调
|
|||
type UpdateWechatTempmsg struct { |
|||
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id"` |
|||
Type int `json:"type" gorm:"column:type;type:int(1) ;default:1;comment:类型(1:文本通知型;2:图文展示型;3:按钮交互型;4:投票选择型;5:多项选择型)"` |
|||
Sendmsgcont string `json:"sendmsgcont" gorm:"column:sendmsgcont;type:longtext ;comment:发送文件信息"` |
|||
Msgid string `json:"msgid" gorm:"column:msgid;type:mediumtext;comment:消息id,用于撤回应用消息"` |
|||
ResponseCode string `json:"response_code" gorm:"column:response_code;type:mediumtext ;comment:仅消息类型为“按钮交互型”,“投票选择型”和“多项选择型”的模板卡片消息返回,应用可使用response_code调用更新模版卡片消息接口,72小时内有效,且只能使用一次"` |
|||
Orderkey int64 `json:"orderkey" gorm:"column:orderkey;type:bigint(20) unsigned;not null;default:0;comment:流程id"` |
|||
Enforcer string `json:"enforcer" gorm:"column:enforcer;type:mediumtext;comment:执行人"` |
|||
State int `json:"sate" gorm:"column:sate;type:int(1) unsigned;default:2;not null;comment:状态(1:已执行更新;2:未执行更新)"` |
|||
TaskId string `json:"task_id" gorm:"column:task_id;type:mediumtext;comment:任务id,同一个应用任务id不能重复,只能由数字、字母和“_-@”组成,最长128字节,填了action_menu字段的话本字段必填"` |
|||
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:写入时间"` |
|||
} |
|||
|
|||
func (UpdateWechatTempmsg *UpdateWechatTempmsg) TableName() string { |
|||
return "update_wechat_tempmsg" |
|||
} |
|||
|
|||
// 添加
|
|||
func (cont *UpdateWechatTempmsg) AddCont() (err error) { |
|||
err = overall.CONSTANT_DB_KPI.Create(&cont).Error |
|||
return |
|||
} |
|||
|
|||
// 编辑内容
|
|||
func (cont *UpdateWechatTempmsg) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_KPI.Model(&cont).Where(whereMap).Updates(saveData).Error |
|||
return |
|||
} |
|||
|
|||
// 获取内容
|
|||
func (cont *UpdateWechatTempmsg) GetCont(whereMap interface{}, field ...string) (err error) { |
|||
gormDb := overall.CONSTANT_DB_KPI.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
gormDb = gormDb.Where(whereMap) |
|||
err = gormDb.First(&cont).Error |
|||
return |
|||
} |
|||
|
|||
// 根据条件获取总数
|
|||
func (cont *UpdateWechatTempmsg) CountCont(whereMap interface{}) (countId int64) { |
|||
overall.CONSTANT_DB_KPI.Model(&cont).Where(whereMap).Count(&countId) |
|||
return |
|||
} |
|||
|
|||
// 读取全部信息
|
|||
func (cont *UpdateWechatTempmsg) ContMap(whereMap interface{}, field ...string) (countAry []UpdateWechatTempmsg, err error) { |
|||
gormDb := overall.CONSTANT_DB_KPI.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
err = gormDb.Where(whereMap).Order("sort ASC").Find(&countAry).Error |
|||
return |
|||
} |
|||
|
|||
// 删除内容
|
|||
func (cont *UpdateWechatTempmsg) DelCont(whereMap interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_KPI.Where(whereMap).Delete(&cont).Error |
|||
return |
|||
} |
|||
Loading…
Reference in new issue