package maptostruct
import (
"encoding/json"
"fmt"
"key_performance_indicators/api/workwechat"
"key_performance_indicators/middleware/grocerystore"
"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"
)
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 04 - 14 0 8 : 29 : 21
@ 功能 : 发送文本信息
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) SendMessage ( c * gin . Context ) {
var receivedValue publicmethod . PublicName
c . ShouldBindJSON ( & receivedValue )
if receivedValue . Name == "" {
receivedValue . Name = "KaiXinGuo"
}
var sendMsg workwechat . SentMessage
sendMsg . ToUser = receivedValue . Name
sendMsg . MsgType = "template_card"
sendMsg . AgentId = 1000036
sendMsg . EnableIdTrans = 0
sendMsg . EnableDuplicateCheck = 0
sendMsg . DuplicateCheckInterval = 1800
var templateCard workwechat . TemplateCardMsgCont
templateCard . CardType = "text_notice"
//头部左标题部分
templateCard . Source . IconUrl = "https://docu.hxgk.group/images/2022_01/3f7a1120a559e9bee3991b85eb34d103.png"
templateCard . Source . Desc = "恒信高科头部信息"
templateCard . Source . DescColor = 1
//头部下拉菜单部分
templateCard . ActionMenu . Desc = "头部下拉"
var actionContOne workwechat . ActionListCont
actionContOne . Text = "头部下拉选项一"
actionContOne . Key = "head_click_1"
templateCard . ActionMenu . ActionList = append ( templateCard . ActionMenu . ActionList , actionContOne )
var actionContTwo workwechat . ActionListCont
actionContTwo . Text = "头部下拉选项二"
actionContTwo . Key = "head_click_2"
templateCard . ActionMenu . ActionList = append ( templateCard . ActionMenu . ActionList , actionContTwo )
//任务id,同一个应用任务id不能重复,只能由数字、字母和“_-@”组成
templateCard . TaskId = fmt . Sprintf ( "task_%v" , publicmethod . GetUUid ( 5 ) )
//主内容框
templateCard . MainTitle . Title = "主内容标题"
templateCard . MainTitle . Desc = "主内容"
//引用文献样式
templateCard . QuoteArea . Type = 1
templateCard . QuoteArea . Url = "https://work.weixin.qq.com"
templateCard . QuoteArea . Title = "企业微信的引用样式标题"
templateCard . QuoteArea . QuoteText = "企业微信的引用样式内容"
//关键数据样式
templateCard . EmphasisContent . Title = "100"
templateCard . EmphasisContent . Desc = "核心数据"
//二级普通文本,建议不超过160个字
templateCard . SubTitleText = "二级普通文本,建议不超过160个字"
//二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6
var hcListCont1 workwechat . HorizontalContentListCont
hcListCont1 . Type = 0
hcListCont1 . Keyname = "姓名:"
hcListCont1 . Value = "秦东"
templateCard . HorizontalContentList = append ( templateCard . HorizontalContentList , hcListCont1 )
var hcListCont2 workwechat . HorizontalContentListCont
hcListCont2 . Type = 1
hcListCont2 . Keyname = "企业微信官网"
hcListCont2 . Value = "点击访问"
hcListCont2 . Url = "https://work.weixin.qq.com"
templateCard . HorizontalContentList = append ( templateCard . HorizontalContentList , hcListCont2 )
var hcListCont3 workwechat . HorizontalContentListCont
hcListCont3 . Type = 3
hcListCont3 . Keyname = "姓名"
hcListCont3 . Value = "开心果"
hcListCont3 . UserId = "KaiXinGuo"
templateCard . HorizontalContentList = append ( templateCard . HorizontalContentList , hcListCont3 )
//跳转指引样式的列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过3
var jmpCont1 workwechat . JumpListCont
jmpCont1 . Type = 1
jmpCont1 . Title = "跳转1"
jmpCont1 . Url = "https://work.weixin.qq.com"
templateCard . JumpList = append ( templateCard . JumpList , jmpCont1 )
var jmpCont2 workwechat . JumpListCont
jmpCont2 . Type = 0
jmpCont2 . Title = "不跳转2"
templateCard . JumpList = append ( templateCard . JumpList , jmpCont2 )
//整体卡片的点击跳转事件,text_notice必填本字段
templateCard . CardAction . Type = 1
templateCard . CardAction . Url = "https://www.baidu.com"
sendMsg . TemplateCard = templateCard
callbackID , err := sendMsg . SendMessage ( )
outPut := make ( map [ string ] interface { } )
outPut [ "callbackID" ] = string ( callbackID )
outPut [ "err" ] = err
outPut [ "sendMsg" ] = sendMsg
publicmethod . Result ( 0 , outPut , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 04 - 14 11 : 27 : 42
@ 功能 : 更新文本消息
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) UpdateTextMsg ( c * gin . Context ) {
var receivedValue publicmethod . PublicName
err := c . ShouldBindJSON ( & receivedValue )
if receivedValue . Name == "" {
publicmethod . Result ( 1 , err , c , "未知参数" )
return
}
var sendMsg workwechat . UpdateMessage
sendMsg . UserIds = append ( sendMsg . UserIds , "KaiXinGuo" )
sendMsg . AgentId = 1000036
sendMsg . ResponseCode = receivedValue . Name
sendMsg . EnableIdTrans = 0
var templateCard workwechat . UpdateTemplateCardMsgCont
templateCard . CardType = "text_notice"
//头部左标题部分
templateCard . Source . IconUrl = "https://docu.hxgk.group/images/2022_01/3f7a1120a559e9bee3991b85eb34d103.png"
templateCard . Source . Desc = "恒信高科头部信息-->1"
templateCard . Source . DescColor = 1
//头部下拉菜单部分
templateCard . ActionMenu . Desc = "头部下拉-->1"
var actionContOne workwechat . ActionListCont
actionContOne . Text = "头部下拉选项一-->1"
actionContOne . Key = "head_click_1"
templateCard . ActionMenu . ActionList = append ( templateCard . ActionMenu . ActionList , actionContOne )
var actionContTwo workwechat . ActionListCont
actionContTwo . Text = "头部下拉选项二-->1"
actionContTwo . Key = "head_click_2"
templateCard . ActionMenu . ActionList = append ( templateCard . ActionMenu . ActionList , actionContTwo )
//主内容框
templateCard . MainTitle . Title = "主内容标题-->1"
templateCard . MainTitle . Desc = "主内容-->1"
//引用文献样式
templateCard . QuoteArea . Type = 1
templateCard . QuoteArea . Url = "https://work.weixin.qq.com"
templateCard . QuoteArea . Title = "企业微信的引用样式标题-->1"
templateCard . QuoteArea . QuoteText = "企业微信的引用样式内容-->1"
//关键数据样式
templateCard . EmphasisContent . Title = "100-->1"
templateCard . EmphasisContent . Desc = "核心数据-->1"
//二级普通文本,建议不超过160个字
templateCard . SubTitleText = "二级普通文本,建议不超过160个字-->1"
//二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6
var hcListCont1 workwechat . HorizontalContentListCont
hcListCont1 . Type = 0
hcListCont1 . Keyname = "姓名:"
hcListCont1 . Value = "秦东-->1"
templateCard . HorizontalContentList = append ( templateCard . HorizontalContentList , hcListCont1 )
var hcListCont2 workwechat . HorizontalContentListCont
hcListCont2 . Type = 1
hcListCont2 . Keyname = "企业微信官网-->1"
hcListCont2 . Value = "点击访问-->1"
hcListCont2 . Url = "https://work.weixin.qq.com"
templateCard . HorizontalContentList = append ( templateCard . HorizontalContentList , hcListCont2 )
var hcListCont3 workwechat . HorizontalContentListCont
hcListCont3 . Type = 3
hcListCont3 . Keyname = "姓名-->1"
hcListCont3 . Value = "开心果-->1"
hcListCont3 . UserId = "KaiXinGuo"
templateCard . HorizontalContentList = append ( templateCard . HorizontalContentList , hcListCont3 )
//跳转指引样式的列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过3
var jmpCont1 workwechat . JumpListCont
jmpCont1 . Type = 1
jmpCont1 . Title = "跳转1-->1"
jmpCont1 . Url = "https://work.weixin.qq.com"
templateCard . JumpList = append ( templateCard . JumpList , jmpCont1 )
var jmpCont2 workwechat . JumpListCont
jmpCont2 . Type = 0
jmpCont2 . Title = "不跳转2-->1"
templateCard . JumpList = append ( templateCard . JumpList , jmpCont2 )
//整体卡片的点击跳转事件,text_notice必填本字段
templateCard . CardAction . Type = 1
templateCard . CardAction . Url = "https://www.baidu.com"
sendMsg . TemplateCard = templateCard
callbackID , err := sendMsg . UpdateMessage ( )
outPut := make ( map [ string ] interface { } )
outPut [ "callbackID" ] = string ( callbackID )
outPut [ "err" ] = err
publicmethod . Result ( 0 , outPut , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 04 - 23 10 : 22 : 02
@ 功能 : 发送迷你文本消息
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) SendMessageMini ( c * gin . Context ) {
var receivedValue publicmethod . PublicName
c . ShouldBindJSON ( & receivedValue )
if receivedValue . Name == "" {
receivedValue . Name = "KaiXinGuo"
}
var sendMsg workwechat . SentMiniMessage
//主题信息
sendMsg . ToUser = receivedValue . Name
var templateCard workwechat . TemplateCardMsgContMini
uuid := publicmethod . GetUUid ( 5 )
//头部左标题部分
templateCard . Source . Desc = "恒信高科头部信息"
//任务id,同一个应用任务id不能重复,只能由数字、字母和“_-@”组成
templateCard . TaskId = fmt . Sprintf ( "kpi_ratify_%v" , uuid )
templateCard . ActionMenu . Desc = "恒信高科"
var rightHand workwechat . ActionListCont
rightHand . Text = "恒信高科"
rightHand . Key = fmt . Sprintf ( "kpi_head_%v" , publicmethod . GetUUid ( 7 ) )
templateCard . ActionMenu . ActionList = append ( templateCard . ActionMenu . ActionList , rightHand )
//主内容框
templateCard . MainTitle . Title = "维度"
// templateCard.MainTitle.Desc = "指标"
//引用文献样式
// templateCard.QuoteArea.Title = "提报时间:2023-04-23 10:29"
setMsg := fmt . Sprintf ( "%v\n%v\n%v" , "扣除5分" , "原因:员工违规操作" , "提报时间:2023-04-23 10:29" )
templateCard . QuoteArea . QuoteText = setMsg
//二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6
var hcListCont1 workwechat . HorizontalContentListCont
hcListCont1 . Type = 0
hcListCont1 . Keyname = "提报部门:"
hcListCont1 . Value = "企管部"
templateCard . HorizontalContentList = append ( templateCard . HorizontalContentList , hcListCont1 )
var hcListCont3 workwechat . HorizontalContentListCont
hcListCont3 . Type = 3
hcListCont3 . Keyname = "提报人:"
hcListCont3 . Value = "秦东(300450)"
hcListCont3 . UserId = "KaiXinGuo"
templateCard . HorizontalContentList = append ( templateCard . HorizontalContentList , hcListCont3 )
//审批详情也米娜
jumpUrl := fmt . Sprintf ( "%v/#/pages/approval/departworkflowcont?id=%v" , overall . CONSTANT_CONFIG . Appsetup . WebUrl , 2190 )
//跳转指引样式的列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过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
callbackID , err := sendMsg . InitMes ( ) . SendMessage ( )
var enforcer [ ] string
enforcer = append ( enforcer , receivedValue . Name )
workwechatErr := workwechat . WriteUpdateWechatTempmsg ( callbackID , sendMsg , 1 , uuid , enforcer )
var callbackCont publicmethod . WechatCallBack
json . Unmarshal ( callbackID , & callbackCont )
outPut := make ( map [ string ] interface { } )
outPut [ "callbackID" ] = string ( callbackID )
outPut [ "err" ] = err
outPut [ "sendMsg" ] = sendMsg
outPut [ "callbackCont" ] = callbackCont
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 )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 05 - 0 9 0 8 : 44 : 15
@ 功能 : 实验读取哈希
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) GetHashGet ( c * gin . Context ) {
redisFileKey := fmt . Sprintf ( "ScanCode:Authentication:LoginApi_%v_%v" , overall . CONSTANT_CONFIG . RedisPrefixStr . Alias , "e3bfa398fe9d0e1ab78a00ff59eff788" )
redisClient := grocerystore . RunRedis ( overall . CONSTANT_REDIS5 )
userRedisToken , _ := redisClient . HashGetAll ( redisFileKey )
_ , userRedisTokens := redisClient . HashGet ( redisFileKey , "usertoken" )
outPut := publicmethod . MapOut [ string ] ( )
outPut [ "userRedisToken" ] = userRedisToken
outPut [ "userRedisTokens" ] = userRedisTokens
publicmethod . Result ( 0 , outPut , c )
}