package workwechat
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"
)
// 发送文本通知消息
func ( s * SentMessage ) SendMessage ( ) ( callBackByte [ ] byte , err error ) {
sendUrl , token , err := wechatstatice . GetSendMsgTokenUrl ( "kpi" , "send" )
if err != nil {
return
}
fmt . Printf ( "%v---------sendUrl, token----------->%v\n" , sendUrl , token )
sendDate , _ := json . Marshal ( s )
callBackByte = publicmethod . CurlPostJosn ( sendUrl , sendDate )
return
}
// 发送迷你信息设定
func ( sendMsg * SentSmallMessage ) InitMes ( ) * SentSmallMessage {
sendMsg . MsgType = "template_card"
sendMsg . AgentId = 1000036
sendMsg . EnableIdTrans = 0
sendMsg . EnableDuplicateCheck = 0
sendMsg . DuplicateCheckInterval = 1800
// var templateCard TemplateCardMsgContMini
sendMsg . TemplateCard . CardType = "text_notice"
//头部左标题部分
sendMsg . TemplateCard . Source . IconUrl = "https://docu.hxgk.group/images/2022_01/3f7a1120a559e9bee3991b85eb34d103.png"
sendMsg . TemplateCard . Source . DescColor = 1
//引用文献样式
sendMsg . TemplateCard . QuoteArea . Type = 0
//整体卡片的点击跳转事件,text_notice必填本字段
sendMsg . TemplateCard . CardAction . Type = 1
// sendMsg.TemplateCard = templateCard
return sendMsg
}
// 发送迷你信息设定
func ( sendMsg * SentMiniMessage ) InitMes ( ) * SentMiniMessage {
sendMsg . MsgType = "template_card"
sendMsg . AgentId = 1000036
sendMsg . EnableIdTrans = 0
sendMsg . EnableDuplicateCheck = 0
sendMsg . DuplicateCheckInterval = 1800
// var templateCard TemplateCardMsgContMini
sendMsg . TemplateCard . CardType = "text_notice"
//头部左标题部分
sendMsg . TemplateCard . Source . IconUrl = "https://docu.hxgk.group/images/2022_01/3f7a1120a559e9bee3991b85eb34d103.png"
sendMsg . TemplateCard . Source . DescColor = 1
//引用文献样式
sendMsg . TemplateCard . QuoteArea . Type = 0
//整体卡片的点击跳转事件,text_notice必填本字段
sendMsg . TemplateCard . CardAction . Type = 1
// sendMsg.TemplateCard = templateCard
return sendMsg
}
// 发送迷你文本通知消息
func ( s * SentMiniMessage ) SendMessage ( ) ( callBackByte [ ] byte , err error ) {
sendUrl , token , err := wechatstatice . GetSendMsgTokenUrl ( "kpi" , "send" )
if err != nil {
return
}
fmt . Printf ( "%v---------sendUrl, token----------->%v\n" , sendUrl , token )
sendDate , _ := json . Marshal ( s )
callBackByte = publicmethod . CurlPostJosn ( sendUrl , sendDate )
return
}
// 发送迷你文本通知消息
func ( s * SentSmallMessage ) SendMessage ( ) ( callBackByte [ ] byte , err error ) {
sendUrl , token , err := wechatstatice . GetSendMsgTokenUrl ( "kpi" , "send" )
if err != nil {
return
}
fmt . Printf ( "%v---------sendUrl, token----------->%v\n" , sendUrl , token )
sendDate , _ := json . Marshal ( s )
callBackByte = publicmethod . CurlPostJosn ( sendUrl , sendDate )
return
}
// 更新文本通知消息
func ( s * UpdateMessage ) UpdateMessage ( ) ( 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 ( s )
callBackByte = publicmethod . CurlPostJosn ( sendUrl , sendDate )
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
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 04 - 24 0 8 : 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 )
* /
func WriteUpdateWechatTempmsg ( wechatCallBack [ ] byte , sendMsg SentMiniMessage , typeClass int , ordeeId int64 , enforcer [ ] string ) ( err error ) {
var weChatCallBack publicmethod . WechatCallBack
err = json . Unmarshal ( wechatCallBack , & weChatCallBack )
if err != nil {
return
}
if weChatCallBack . Errcode != 0 {
return
}
sendMsgJson , err := json . Marshal ( sendMsg )
if err != nil {
return
}
var insetCont modelskpi . UpdateWechatTempmsg
insetCont . Type = typeClass //类型(1:文本通知型;2:图文展示型;3:按钮交互型;4:投票选择型;5:多项选择型)"`
insetCont . Sendmsgcont = string ( sendMsgJson ) //发送文件信息"`
insetCont . Msgid = weChatCallBack . MsgId //消息id,用于撤回应用消息"`
insetCont . ResponseCode = weChatCallBack . ResponseCode //仅消息类型为“按钮交互型”,“投票选择型”和“多项选择型”的模板卡片消息返回,应用可使用response_code调用更新模版卡片消息接口,72小时内有效,且只能使用一次"`
insetCont . Orderkey = ordeeId //流程id"`
insetCont . Enforcer = strings . Join ( enforcer , "," ) //执行人"`
insetCont . State = 2 //状态(1:已执行更新;2:未执行更新)"`
insetCont . TaskId = sendMsg . TemplateCard . TaskId //任务id,同一个应用任务id不能重复,只能由数字、字母和“_-@”组成,最长128字节,填了action_menu字段的话本字段必填"`
insetCont . Time = time . Now ( ) . Unix ( ) //写入时间"`
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 ( "`sate` = 2 AND `type` = ? AND `orderkey` = ? AND FIND_IN_SET(?,`enforcer`)" , typeClass , orderkey , enforcer ) . Find ( & updateWechatCont ) . Error
if err != nil || len ( updateWechatCont ) < 1 {
return
}
for _ , uv := range updateWechatCont {
sendUpdateMsg := publicmethod . MapOut [ string ] ( )
var weChatMsgCont SentMiniMessage
json . Unmarshal ( [ ] byte ( uv . 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 ( uv . 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" ] = uv . 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`" : uv . Id } , editCont )
}
return
}