diff --git a/api/shiyan/maptostruct/sendwechat.go b/api/shiyan/maptostruct/sendwechat.go index 1a4f0c0..48d6138 100644 --- a/api/shiyan/maptostruct/sendwechat.go +++ b/api/shiyan/maptostruct/sendwechat.go @@ -4,8 +4,12 @@ import ( "encoding/json" "fmt" "key_performance_indicators/api/workwechat" + "key_performance_indicators/models/modelshr" + "key_performance_indicators/models/modelskpi" "key_performance_indicators/overall" "key_performance_indicators/overall/publicmethod" + "strings" + "time" "github.com/gin-gonic/gin" ) @@ -300,3 +304,101 @@ func (a *ApiMethod) SendMessageMini(c *gin.Context) { outPut["workwechatErr"] = workwechatErr publicmethod.Result(0, outPut, c) } + +// 更新卡片mini +func (a *ApiMethod) UpdateMiniCard(c *gin.Context) { + var receivedValue UpdateMiniTemp + err := c.ShouldBindJSON(&receivedValue) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if receivedValue.Type == 0 { + receivedValue.Type = 1 + } + if receivedValue.Orderkey == "" { + publicmethod.Result(1, err, c, "未知参数") + return + } + if receivedValue.Enforcer == "" { + publicmethod.Result(1, err, c, "未知参数") + return + } + var updateWechatCont modelskpi.UpdateWechatTempmsg + err = overall.CONSTANT_DB_KPI.Where("`type` = ? AND `orderkey` = ? AND FIND_IN_SET(?,`enforcer`)", receivedValue.Type, receivedValue.Orderkey, receivedValue.Enforcer).Find(&updateWechatCont).Error + if err != nil || updateWechatCont.Sendmsgcont == "" || updateWechatCont.ResponseCode == "" || updateWechatCont.State == 1 { + publicmethod.Result(105, err, c) + return + } + + sendUpdateMsg := publicmethod.MapOut[string]() + var weChatMsgCont workwechat.SentMiniMessage + json.Unmarshal([]byte(updateWechatCont.Sendmsgcont), &weChatMsgCont) + + templateCardCont := publicmethod.MapOut[string]() + templateCardCont["card_type"] = weChatMsgCont.TemplateCard.CardType + templateCardCont["source"] = weChatMsgCont.TemplateCard.Source + templateCardCont["main_title"] = weChatMsgCont.TemplateCard.MainTitle + templateCardCont["task_id"] = weChatMsgCont.TemplateCard.TaskId + templateCardCont["action_menu"] = weChatMsgCont.TemplateCard.ActionMenu + templateCardCont["quote_area"] = weChatMsgCont.TemplateCard.QuoteArea + templateCardCont["horizontal_content_list"] = weChatMsgCont.TemplateCard.HorizontalContentList + templateCardCont["card_action"] = weChatMsgCont.TemplateCard.CardAction + + var userCont modelshr.PersonArchives + userCont.GetCont(map[string]interface{}{"`key`": receivedValue.Enforcer}, "`name`") + titleStr := fmt.Sprintf("%v已处理,查看详情", userCont.Name) + for i, v := range weChatMsgCont.TemplateCard.JumpList { + if v.Type == 1 { + weChatMsgCont.TemplateCard.JumpList[i].Title = titleStr + } + } + templateCardCont["jump_list"] = weChatMsgCont.TemplateCard.JumpList + + receiveMsgMan := strings.Split(updateWechatCont.Enforcer, ",") + if len(receiveMsgMan) < 1 { + publicmethod.Result(105, err, c) + return + } + var weCahtOpenId []string + for _, v := range receiveMsgMan { + var userContWechat modelshr.PersonArchives + userContWechat.GetCont(map[string]interface{}{"`key`": v}, "`wechat`", "`work_wechat`") + if userContWechat.Wechat != "" { + if !publicmethod.IsInTrue[string](userContWechat.Wechat, weCahtOpenId) { + weCahtOpenId = append(weCahtOpenId, userContWechat.Wechat) + } + } + if userContWechat.WorkWechat != "" { + if !publicmethod.IsInTrue[string](userContWechat.WorkWechat, weCahtOpenId) { + weCahtOpenId = append(weCahtOpenId, userContWechat.WorkWechat) + } + } + + } + if len(weCahtOpenId) < 1 { + publicmethod.Result(105, err, c) + return + } + sendUpdateMsg["userids"] = weCahtOpenId + sendUpdateMsg["agentid"] = weChatMsgCont.AgentId + sendUpdateMsg["response_code"] = updateWechatCont.ResponseCode + sendUpdateMsg["enable_id_trans"] = 1 + sendUpdateMsg["template_card"] = templateCardCont + + UpDateCont, err := workwechat.UpdateMessageMap(sendUpdateMsg) + + var editUpdateWechatCont modelskpi.UpdateWechatTempmsg + editCont := publicmethod.MapOut[string]() + editCont["`sate`"] = 1 + editCont["`time`"] = time.Now().Unix() + editErr := editUpdateWechatCont.EiteCont(map[string]interface{}{"`id`": updateWechatCont.Id}, editCont) + + outPut := publicmethod.MapOut[string]() + outPut["UpDateCont"] = UpDateCont + outPut["err"] = err + outPut["editErr"] = editErr + outPut["sendUpdateMsg"] = sendUpdateMsg + + publicmethod.Result(0, outPut, c) +} diff --git a/api/shiyan/maptostruct/type.go b/api/shiyan/maptostruct/type.go index 92362f4..7e2281c 100644 --- a/api/shiyan/maptostruct/type.go +++ b/api/shiyan/maptostruct/type.go @@ -70,3 +70,10 @@ type hrUsernameAndPassword struct { type XiaoZengTime struct { DateTime string `json"datetime"` } + +// 更新mini文本模板 +type UpdateMiniTemp struct { + Type int `json:"type"` //'类型(1:文本通知型;2:图文展示型;3:按钮交互型;4:投票选择型;5:多项选择型)' + Orderkey string `json:"orderkey"` //流程识别符 + Enforcer string `json:"enforcer"` //执行人 +} diff --git a/api/version1/departmentseting/departmentpc/ding_xing.go b/api/version1/departmentseting/departmentpc/ding_xing.go index 7d51b41..e6d429a 100644 --- a/api/version1/departmentseting/departmentpc/ding_xing.go +++ b/api/version1/departmentseting/departmentpc/ding_xing.go @@ -458,6 +458,7 @@ func (a *ApiMethod) SubmitQualityAssess(c *gin.Context) { evalProFlowErr := gormDb.Create(&evalProFlowView).Error flowLogContErr := gormDb.Create(&flowLogCont).Error var callbackMsg []byte // + var workwechatErr error if scoreFlowErr == nil && evalProFlowErr == nil && flowLogContErr == nil { addErr := gormDb.Commit().Error if addErr == nil { @@ -469,7 +470,11 @@ func (a *ApiMethod) SubmitQualityAssess(c *gin.Context) { if nextNodeStr != "" { //判断下个节点是否为空 if len(haveWorkflow.NextNodeCont.UserList) > 0 { //判断下个节点是够有审批人 var recipient []string + var sendWechatUserKey []string for _, v := range haveWorkflow.NextNodeCont.UserList { //获取接收人得微信或企业微信Openid用作发送消息的唯一识别码 + if !publicmethod.IsInTrue[string](v.Id, sendWechatUserKey) { + sendWechatUserKey = append(sendWechatUserKey, v.Id) + } if v.Wechat != "" { if !publicmethod.IsInTrue[string](v.Wechat, recipient) { recipient = append(recipient, v.Wechat) @@ -562,12 +567,36 @@ func (a *ApiMethod) SubmitQualityAssess(c *gin.Context) { templateCard.CardAction.Url = jumpUrl sendMsg.TemplateCard = templateCard callbackMsg, err = sendMsg.InitMes().SendMessage() + + workwechatErr = workwechat.WriteUpdateWechatTempmsg(callbackMsg, sendMsg, 1, uuid, sendWechatUserKey) + /* + * + @ 作者: 秦东 + @ 时间: 2023-04-24 08:22:22 + @ 功能: 写入企业微信模版信息发送回调 + @ 参数 + + #wechatCallBack 文本发送回调 + #sendMsg 发送文本信息 + #typeClass 类型(1:文本通知型;2:图文展示型;3:按钮交互型;4:投票选择型;5:多项选择型) + #ordeeId 审批记录Id + #enforcer 接收人 + + @ 返回值 + + #err + + @ 方法原型 + + #func WriteUpdateWechatTempmsg(wechatCallBack []byte, sendMsg SentMiniMessage, typeClass int, ordeeId int64, enforcer []string) (err error) + */ } } } outErr := publicmethod.MapOut[string]() outErr["addErr"] = addErr outErr["err"] = err + outErr["workwechatErr"] = workwechatErr outErr["callbackMsg"] = string(callbackMsg) publicmethod.Result(0, addErr, c) } else { diff --git a/api/version1/departmentseting/departmentpc/dingliang.go b/api/version1/departmentseting/departmentpc/dingliang.go index 658cc35..8881046 100644 --- a/api/version1/departmentseting/departmentpc/dingliang.go +++ b/api/version1/departmentseting/departmentpc/dingliang.go @@ -726,6 +726,7 @@ func (a *ApiMethod) SubmitQuantifyTarget(c *gin.Context) { flowLogContErr := gormDb.Create(&flowLogCont).Error var callbackMsg []byte // var err error + var workwechatErr error if evalProFlowViewErr == nil && workFlowLogContErr == nil && addFlowDataListErr == nil && flowLogContErr == nil { addErr := gormDb.Commit().Error if addErr == nil { @@ -733,8 +734,12 @@ func (a *ApiMethod) SubmitQuantifyTarget(c *gin.Context) { //下一个节点内容 if nextNodeStr != "" { //判断下个节点是否为空 if len(haveWorkflow.NextNodeCont.UserList) > 0 { //判断下个节点是够有审批人 - var recipient []string //接收人 + var recipient []string //接收人 + var sendWechatUserKey []string for _, v := range haveWorkflow.NextNodeCont.UserList { //获取接收人得微信或企业微信Openid用作发送消息的唯一识别码 + if !publicmethod.IsInTrue[string](v.Id, sendWechatUserKey) { + sendWechatUserKey = append(sendWechatUserKey, v.Id) + } if v.Wechat != "" { if !publicmethod.IsInTrue[string](v.Wechat, recipient) { recipient = append(recipient, v.Wechat) @@ -826,7 +831,7 @@ func (a *ApiMethod) SubmitQuantifyTarget(c *gin.Context) { templateCard.CardAction.Url = jumpUrl sendMsg.TemplateCard = templateCard callbackMsg, err = sendMsg.InitMes().SendMessage() - + workwechatErr = workwechat.WriteUpdateWechatTempmsg(callbackMsg, sendMsg, 1, uuid, sendWechatUserKey) var callbackCont publicmethod.WechatCallBack json.Unmarshal(callbackMsg, &callbackCont) } @@ -835,6 +840,7 @@ func (a *ApiMethod) SubmitQuantifyTarget(c *gin.Context) { outErr := publicmethod.MapOut[string]() outErr["addErr"] = addErr outErr["err"] = err + outErr["workwechatErr"] = workwechatErr outErr["callbackMsg"] = string(callbackMsg) publicmethod.Result(0, outErr, c) } else { diff --git a/api/version1/flowchart/myworkflow.go b/api/version1/flowchart/myworkflow.go index 21dea99..9ceab40 100644 --- a/api/version1/flowchart/myworkflow.go +++ b/api/version1/flowchart/myworkflow.go @@ -4,6 +4,7 @@ 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" @@ -769,7 +770,7 @@ func (w *WorkFlowRuning) ProcessOperation() { w.RunNode = v w.WriteFlowLog() if v.Type != 2 { //判断当前节点是不是操作 - //不是抄送节点 + workwechat.UpdateWechatMsgCont(1, w.YesOrNo, w.OrderKey, userKey) //判断同意还是驳回 if w.YesOrNo == 2 { w.NodeYes(total) @@ -907,6 +908,7 @@ func (w *WorkFlowRuning) NodeYes(total int) { w.NextExecutor = nextZhiXingRen msgkkk, ksgEr := SendTogetherMsg(w.OrderKey, v, 1) fmt.Printf("NodeYes--->%v\n--->%v\n", msgkkk, ksgEr) + if writeLog { w.RunNode = v w.WriteFlowLog() diff --git a/api/version1/flowchart/sendmsg.go b/api/version1/flowchart/sendmsg.go index e37e666..02ffa3b 100644 --- a/api/version1/flowchart/sendmsg.go +++ b/api/version1/flowchart/sendmsg.go @@ -39,8 +39,12 @@ func SendTogetherMsg(orderId int64, nodeCont currency_recipe.NodeCont, operate i if len(nodeCont.UserList) <= 0 { return } - var recipient []string //接收人 + var recipient []string //接收人 + var sendWechatUserKey []string for _, v := range nodeCont.UserList { //获取接收人得微信或企业微信Openid用作发送消息的唯一识别码 + if !publicmethod.IsInTrue[string](v.Id, sendWechatUserKey) { + sendWechatUserKey = append(sendWechatUserKey, v.Id) + } if v.Wechat != "" { if !publicmethod.IsInTrue[string](v.Wechat, recipient) { recipient = append(recipient, v.Wechat) @@ -132,6 +136,8 @@ func SendTogetherMsg(orderId int64, nodeCont currency_recipe.NodeCont, operate i sendMsg.TemplateCard = templateCard callbackMsg, err := sendMsg.InitMes().SendMessage() callbackMsgStr = string(callbackMsg) + + workwechat.WriteUpdateWechatTempmsg(callbackMsg, sendMsg, 1, orderId, sendWechatUserKey) return } diff --git a/api/workwechat/message.go b/api/workwechat/message.go index eb09529..15ab36a 100644 --- a/api/workwechat/message.go +++ b/api/workwechat/message.go @@ -4,7 +4,9 @@ import ( "encoding/json" "fmt" "key_performance_indicators/middleware/wechatapp/wechatstatice" + "key_performance_indicators/models/modelshr" "key_performance_indicators/models/modelskpi" + "key_performance_indicators/overall" "key_performance_indicators/overall/publicmethod" "strings" "time" @@ -104,6 +106,18 @@ func (s *UpdateMessage) UpdateMessage() (callBackByte []byte, err error) { return } +// 更新文本通知(map类型) +func UpdateMessageMap(mapAry map[string]interface{}) (callBackByte []byte, err error) { + sendUrl, token, err := wechatstatice.GetSendMsgTokenUrl("kpi", "update") + if err != nil { + return + } + fmt.Printf("%v---------sendUrl, token----------->%v\n", sendUrl, token) + sendDate, _ := json.Marshal(mapAry) + callBackByte = publicmethod.CurlPostJosn(sendUrl, sendDate) + return +} + /* * @ 作者: 秦东 @@ -151,3 +165,113 @@ func WriteUpdateWechatTempmsg(wechatCallBack []byte, sendMsg SentMiniMessage, ty err = insetCont.AddCont() return } + +/* +* +@ 作者: 秦东 +@ 时间: 2023-04-24 13:29:27 +@ 功能: 更新卡片 +@ 参数 + + #typeClass 类型(1:文本通知型;2:图文展示型;3:按钮交互型;4:投票选择型;5:多项选择型)' + #attribute 1:未操作,2:同意;3:驳回 + #orderkey 流程识别符 + #enforcer 执行人 + +@ 返回值 + + #UpDateCont 更新信息 + #err 信息提示 + +@ 方法原型 + + #func UpdateWechatMsgCont(typeClass int, orderkey, enforcer string) (UpDateCont []byte, err error) +*/ +func UpdateWechatMsgCont(typeClass, attribute int, orderkey int64, enforcer string) (UpDateCont []byte, err error) { + if typeClass == 0 { + typeClass = 1 + } + if orderkey == 0 || enforcer == "" { + return + } + var updateWechatCont modelskpi.UpdateWechatTempmsg + err = overall.CONSTANT_DB_KPI.Where("`type` = ? AND `orderkey` = ? AND FIND_IN_SET(?,`enforcer`)", typeClass, orderkey, enforcer).Find(&updateWechatCont).Error + if err != nil || updateWechatCont.Sendmsgcont == "" || updateWechatCont.ResponseCode == "" || updateWechatCont.State == 1 { + return + } + + sendUpdateMsg := publicmethod.MapOut[string]() + var weChatMsgCont SentMiniMessage + json.Unmarshal([]byte(updateWechatCont.Sendmsgcont), &weChatMsgCont) + + templateCardCont := publicmethod.MapOut[string]() + templateCardCont["card_type"] = weChatMsgCont.TemplateCard.CardType + templateCardCont["source"] = weChatMsgCont.TemplateCard.Source + templateCardCont["main_title"] = weChatMsgCont.TemplateCard.MainTitle + templateCardCont["task_id"] = weChatMsgCont.TemplateCard.TaskId + templateCardCont["action_menu"] = weChatMsgCont.TemplateCard.ActionMenu + templateCardCont["quote_area"] = weChatMsgCont.TemplateCard.QuoteArea + templateCardCont["horizontal_content_list"] = weChatMsgCont.TemplateCard.HorizontalContentList + templateCardCont["card_action"] = weChatMsgCont.TemplateCard.CardAction + + var userCont modelshr.PersonArchives + userCont.GetCont(map[string]interface{}{"`key`": enforcer}, "`name`") + attributeTitle := "同意申请" + switch attribute { + case 2: + attributeTitle = "同意申请" + case 3: + attributeTitle = "驳回申请" + default: + attributeTitle = "操作申请" + } + titleStr := fmt.Sprintf("%v已%v,查看详情", userCont.Name, attributeTitle) + for i, v := range weChatMsgCont.TemplateCard.JumpList { + if v.Type == 1 { + weChatMsgCont.TemplateCard.JumpList[i].Title = titleStr + } + } + templateCardCont["jump_list"] = weChatMsgCont.TemplateCard.JumpList + + receiveMsgMan := strings.Split(updateWechatCont.Enforcer, ",") + if len(receiveMsgMan) < 1 { + + return + } + var weCahtOpenId []string + for _, v := range receiveMsgMan { + var userContWechat modelshr.PersonArchives + userContWechat.GetCont(map[string]interface{}{"`key`": v}, "`wechat`", "`work_wechat`") + if userContWechat.Wechat != "" { + if !publicmethod.IsInTrue[string](userContWechat.Wechat, weCahtOpenId) { + weCahtOpenId = append(weCahtOpenId, userContWechat.Wechat) + } + } + if userContWechat.WorkWechat != "" { + if !publicmethod.IsInTrue[string](userContWechat.WorkWechat, weCahtOpenId) { + weCahtOpenId = append(weCahtOpenId, userContWechat.WorkWechat) + } + } + + } + if len(weCahtOpenId) < 1 { + + return + } + sendUpdateMsg["userids"] = weCahtOpenId + sendUpdateMsg["agentid"] = weChatMsgCont.AgentId + sendUpdateMsg["response_code"] = updateWechatCont.ResponseCode + sendUpdateMsg["enable_id_trans"] = 1 + sendUpdateMsg["template_card"] = templateCardCont + + UpDateCont, err = UpdateMessageMap(sendUpdateMsg) + if err != nil { + return + } + var editUpdateWechatCont modelskpi.UpdateWechatTempmsg + editCont := publicmethod.MapOut[string]() + editCont["`sate`"] = 1 + editCont["`time`"] = time.Now().Unix() + err = editUpdateWechatCont.EiteCont(map[string]interface{}{"`id`": updateWechatCont.Id}, editCont) + return +} diff --git a/apirouter/apishiyan/maptostruct.go b/apirouter/apishiyan/maptostruct.go index 0a13bc6..57dff64 100644 --- a/apirouter/apishiyan/maptostruct.go +++ b/apirouter/apishiyan/maptostruct.go @@ -40,5 +40,7 @@ func (a *ApiRouter) RouterGroup(router *gin.RouterGroup) { apiRouter.POST("send_message", methodBinding.SendMessage) //发送文本信息 apiRouter.POST("update_textmessage", methodBinding.UpdateTextMsg) //更新文本信息 apiRouter.POST("send_message_mini", methodBinding.SendMessageMini) //发送文本信息迷你消息 + + apiRouter.POST("update_mini_card", methodBinding.UpdateMiniCard) //更新文本信息迷你消息 } }