@ -4,6 +4,7 @@ import (
"appPlatform/api/version1/customerform"
datacenter "appPlatform/api/version1/dataCenter"
"appPlatform/api/version1/workWechat"
"appPlatform/middleware/grocerystore"
"appPlatform/models/customerForm"
"appPlatform/models/modelAppPlatform"
"appPlatform/models/modelshr"
@ -975,8 +976,16 @@ func (a *ApiMethod) AddCustomerForm(c *gin.Context) {
json . Unmarshal ( [ ] byte ( formCont . ListJson ) , & sendMsgInterface )
var sendMsgInfo SendMsgInfo
sendMsgInfo . SendMsg ( sendMsgInterface . SendMsg , userCont , taskCont . Title , cureeTime , masterField , masterUnitList )
sendMsgInfo = sendMsgInterface . SendMsg
msgid , _ := sendMsgInfo . SendMsg ( userCont , taskCont . Title , uuid , cureeTime , masterField , masterUnitList )
fmt . Printf ( "发送返回信息------------->%v\n\n\n" , msgid )
if msgid != "" {
//设定redis Key名称
redisKey := fmt . Sprintf ( "SendMsg:Work_WeChat_%v" , uuid )
redisClient := grocerystore . RunRedis ( overall . CONSTANT_REDIS3 )
redisClient . SetRedisTime ( 86400 )
redisClient . Set ( redisKey , msgid )
}
// sendConfig := sendMsgInterface.SendMsg
// if sendConfig.Open {
// msgTitle := taskCont.Title
@ -1008,27 +1017,29 @@ func (a *ApiMethod) AddCustomerForm(c *gin.Context) {
@ 返回值
#
# msgid 消息id , 用于撤回应用消息
# err 信息
@ 方法原型
#
* /
func ( s * SendMsgInfo ) SendMsg ( sendConfig SendMsgInfo , userCont modelshr . ManCont , msgTitle string , cureeTime int64 , fieldVal map [ string ] interface { } , subUnit map [ string ] customerform . MasterStruct ) bool {
if sendConfig . Open { //开启发送信息
func ( s * SendMsgInfo ) SendMsg ( userCont modelshr . ManCont , msgTitle string , uuid , cureeTime int64 , fieldVal map [ string ] interface { } , subUnit map [ string ] customerform . MasterStruct ) ( msgid string , err error ) {
if s . Open { //开启发送信息
var sendMsg workWechat . SendMessage
sendUserCount := 0
var sendUserAll [ ] string
isSend := true
//Step 1: 获取消息的发送范围
switch sendConfig . SendRange {
switch s . SendRange {
case 1 : //全集团
sendMsg . Touser = "@all"
case 2 : //本公司
var myCompany modelshr . AdministrativeOrganization
myCompany . GetCont ( map [ string ] interface { } { "id" : userCont . Company } , "`schoole `" )
if myCompany . Schoole != 0 {
sendMsg . Toparty = strconv . FormatInt ( myCompany . Schoole , 10 )
myCompany . GetCont ( map [ string ] interface { } { "id" : userCont . Company } , "`wechat_organization_id `" )
if myCompany . WechatOrganizationId != 0 {
sendMsg . Toparty = strconv . FormatInt ( myCompany . WechatOrganizationId , 10 )
} else {
if userCont . Company != 0 {
//获取该组织得所以下级
@ -1056,9 +1067,9 @@ func (s *SendMsgInfo) SendMsg(sendConfig SendMsgInfo, userCont modelshr.ManCont,
case 3 : //本部门
if userCont . MainDeparment != 0 {
var myCompany modelshr . AdministrativeOrganization
myCompany . GetCont ( map [ string ] interface { } { "id" : userCont . MainDeparment } , "`schoole `" )
if myCompany . Schoole != 0 {
sendMsg . Toparty = strconv . FormatInt ( myCompany . Schoole , 10 )
myCompany . GetCont ( map [ string ] interface { } { "id" : userCont . MainDeparment } , "`wechat_organization_id `" )
if myCompany . WechatOrganizationId != 0 {
sendMsg . Toparty = strconv . FormatInt ( myCompany . WechatOrganizationId , 10 )
} else {
//获取该组织得所以下级
sendUserAll = GainOrgManWechat ( userCont . MainDeparment )
@ -1085,9 +1096,9 @@ func (s *SendMsgInfo) SendMsg(sendConfig SendMsgInfo, userCont modelshr.ManCont,
case 4 : //本行政组织
if userCont . AdminOrg != 0 {
var myCompany modelshr . AdministrativeOrganization
myCompany . GetCont ( map [ string ] interface { } { "id" : userCont . AdminOrg } , "`schoole `" )
if myCompany . Schoole != 0 {
sendMsg . Toparty = strconv . FormatInt ( myCompany . Schoole , 10 )
myCompany . GetCont ( map [ string ] interface { } { "id" : userCont . AdminOrg } , "`wechat_organization_id `" )
if myCompany . WechatOrganizationId != 0 {
sendMsg . Toparty = strconv . FormatInt ( myCompany . WechatOrganizationId , 10 )
} else {
//获取该组织得所以下级
sendUserAll = GainOrgManWechat ( userCont . AdminOrg )
@ -1122,13 +1133,382 @@ func (s *SendMsgInfo) SendMsg(sendConfig SendMsgInfo, userCont modelshr.ManCont,
}
}
case 6 : //自定义
sendUserAll = s . CustomizeSendMsg ( )
sendUserCount = len ( sendUserAll )
if sendUserCount <= 1000 && sendUserCount > 0 {
sendMsg . Touser = strings . Join ( sendUserAll , "|" )
} else {
if sendUserCount == 0 {
isSend = false
}
}
default :
isSend = false
}
if isSend {
switch s . Types {
case "textcard" :
sendMsg . Msgtype = "textcard"
sendMsg . Textcard . Title = s . SendMsgInfo ( s . Title , msgTitle , fieldVal , subUnit )
sendMsg . Textcard . Description = fmt . Sprintf ( "<div class='gray'>%v</div> <div class='normal'>%v</div><div class='highlight'>请尽快阅读此信息</div>" , publicmethod . UnixTimeToDay ( time . Now ( ) . Unix ( ) , 11 ) , s . SendMsgInfo ( s . Content , msgTitle , fieldVal , subUnit ) )
sendMsg . Textcard . Url = fmt . Sprintf ( "%v/#/work_wechat?masters_key=%v" , overall . CONSTANT_CONFIG . Appsetup . WebKpiUrl , uuid )
sendMsg . Textcard . Btntxt = "前往查看"
case "news" :
sendMsg . Msgtype = "news"
//图文内容
var imgMsgInfo workWechat . ArticlesList
imgMsgInfo . Title = s . SendMsgInfo ( s . Title , msgTitle , fieldVal , subUnit )
imgMsgInfo . Description = s . SendMsgInfo ( s . Content , msgTitle , fieldVal , subUnit )
imgMsgInfo . Url = fmt . Sprintf ( "%v/#/work_wechat?masters_key=%v" , overall . CONSTANT_CONFIG . Appsetup . WebKpiUrl , uuid )
imgMsgInfo . PicUrl = s . GainOneField ( s . Icon , msgTitle , fieldVal , subUnit )
sendMsg . NewsMsg . Articles = append ( sendMsg . NewsMsg . Articles , imgMsgInfo )
// sendMsg.NewsMsg.Articles = s.SendMsgInfo(s.Title, msgTitle, fieldVal, subUnit)
default :
sendMsg . Msgtype = "text"
sendMsg . TextMsg . Content = s . SendMsgInfo ( s . Content , msgTitle , fieldVal , subUnit )
}
sendInitInfouser , _ := json . Marshal ( sendUserAll )
fmt . Printf ( "\n\n这是查看接收人信息-----》%v\n\n" , string ( sendInitInfouser ) )
sendInitInfo , _ := json . Marshal ( sendMsg )
fmt . Printf ( "\n\n这是查看输入信息-----》%v\n\n" , string ( sendInitInfo ) )
//判断当前人数是否曹组
if sendUserCount >= 1000 {
var msgidAry [ ] string
var msgToUser [ ] string
for i , v := range sendUserAll {
if ( i + 1 ) % 1000 == 0 {
if len ( msgToUser ) > 0 {
sendMsg . Touser = strings . Join ( msgToUser , "|" )
msgidSte , errStr := sendMsg . SendMsg ( "stzl" , 1 )
msgToUser = [ ] string { }
msgidAry = append ( msgidAry , msgidSte )
if errStr != nil {
err = errStr
}
}
} else {
msgToUser = append ( msgToUser , v )
}
}
if len ( msgToUser ) > 0 {
sendMsg . Touser = strings . Join ( msgToUser , "|" )
msgidSte , errStr := sendMsg . SendMsg ( "stzl" , 1 )
msgToUser = [ ] string { }
msgidAry = append ( msgidAry , msgidSte )
if errStr != nil {
err = errStr
}
}
if len ( msgidAry ) > 0 {
msgid = strings . Join ( msgidAry , "," )
}
} else {
msgid , err = sendMsg . SendMsg ( "stzl" , 1 )
}
}
} else {
err = nil
}
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 03 - 31 13 : 54 : 38
@ 功能 : 获取单一字段的数据
* /
func ( s * SendMsgInfo ) GainOneField ( fields string , msgTitle string , fieldVal map [ string ] interface { } , subUnit map [ string ] customerform . MasterStruct ) string {
var sendData interface { }
if val , isOk := fieldVal [ fields ] ; isOk {
sendData = val
}
unitCont := GainFieldType ( fields , subUnit )
switch unitCont . Type {
case "input" , "password" , "lowcodeImage" : //单行文本
msgTitle = publicmethod . TypeToInterface ( sendData )
case "textarea" , "tinymce" : //多行文本,富文本
msgTitle = publicmethod . TypeToInterface ( sendData )
case "radio" , "select" : //单选框组、下拉选择框
val := publicmethod . TypeToInterface ( sendData )
if len ( unitCont . Options ) > 0 {
for _ , uv := range unitCont . Options {
if uv . Value == val {
msgTitle = uv . Label
}
}
}
case "checkbox" , "cascader" , "treeSelect" , "upload" : //checkbox,级联选择器,树形控件,图片/文件: ,
if valMap , isOk := sendData . ( [ ] int ) ; isOk {
if len ( valMap ) > 0 && len ( unitCont . Options ) > 0 {
var titalMap [ ] string
for _ , v := range valMap {
for _ , uv := range unitCont . Options {
if uv . Value == strconv . Itoa ( v ) {
titalMap = append ( titalMap , uv . Label )
}
}
}
msgTitle = fmt . Sprintf ( "\"%v\"" , strings . Join ( titalMap , "、" ) )
}
}
case "expand-user" : //选择用户
val := publicmethod . TypeToInterface ( sendData )
var userNumber [ ] string
ruleSet := regexp . MustCompile ( ` \(([^)]+)\) ` )
valMap := ruleSet . FindAllStringSubmatch ( val , - 1 )
if len ( valMap ) > 0 {
for _ , v := range valMap {
vLen := len ( v )
if vLen > 0 {
if ! publicmethod . IsInTrue ( v [ vLen - 1 ] , userNumber ) {
userNumber = append ( userNumber , fmt . Sprintf ( "%v(%v)" , v [ 0 ] , v [ vLen - 1 ] ) )
}
}
}
}
msgTitle = fmt . Sprintf ( "\"%v\"" , strings . Join ( userNumber , "、" ) )
case "datePicker" : //日期选择器
if strVal , ok := sendData . ( [ ] interface { } ) ; ok {
strValLen := len ( strVal )
if strValLen > 1 {
startTimg , _ := publicmethod . StringToInt64 ( strVal [ 0 ] )
endTime , _ := publicmethod . StringToInt64 ( strVal [ strValLen - 1 ] )
msgTitle = fmt . Sprintf ( "%v 至 %v" , publicmethod . TypeToClass ( startTimg / 1000 , 14 ) , publicmethod . TypeToClass ( endTime / 1000 , 14 ) )
} else if strValLen == 1 {
startTimg , _ := publicmethod . StringToInt64 ( strVal [ 0 ] )
msgTitle = publicmethod . TypeToClass ( startTimg / 1000 , 14 )
}
} else {
startTimg , _ := publicmethod . StringToInt64 ( sendData )
msgTitle = publicmethod . TypeToClass ( startTimg , 14 )
}
case "timePicker" , "inputNumber" : //时间选择器,计数器
if strVal , ok := sendData . ( [ ] interface { } ) ; ok {
strValLen := len ( strVal )
if strValLen > 1 {
startTimg , _ := publicmethod . StringToInt64 ( strVal [ 0 ] )
endTime , _ := publicmethod . StringToInt64 ( strVal [ strValLen - 1 ] )
msgTitle = fmt . Sprintf ( "%v 至 %v" , publicmethod . TypeToClass ( startTimg / 1000 , 14 ) , publicmethod . TypeToClass ( endTime / 1000 , 14 ) )
} else if strValLen == 1 {
startTimg , _ := publicmethod . StringToInt64 ( strVal [ 0 ] )
msgTitle = publicmethod . TypeToClass ( startTimg / 1000 , 14 )
}
} else {
startTimg , _ := publicmethod . StringToInt64 ( sendData )
msgTitle = publicmethod . TypeToClass ( startTimg , 14 )
}
case "colorPicker" : //取色器
msgTitle = publicmethod . TypeToInterface ( sendData )
case "switch" : //开关
startTimg , _ := publicmethod . StringToInt64 ( sendData )
if startTimg == 1 {
msgTitle = "是"
} else {
msgTitle = "否"
}
case "rate" , "slider" : //评分,滑块
msgTitle = publicmethod . TypeToInterface ( sendData )
case "txt" , "button" , "title" , "table" , "grid" , "tabs" , "card" , "flex" , "divider" , "div" : //文本,按钮,标题,表格,格栅,标签,卡片布局,弹性布局,分割线,容器
msgTitle = publicmethod . TypeToInterface ( sendData )
case "component" : //自定义组件 (格式待定)
msgTitle = publicmethod . TypeToInterface ( sendData )
default :
msgTitle = publicmethod . TypeToInterface ( sendData )
}
return msgTitle
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 03 - 28 15 : 48 : 28
@ 功能 : 获取发送标题
* /
func ( s * SendMsgInfo ) SendMsgInfo ( fields [ ] string , msgTitle string , fieldVal map [ string ] interface { } , subUnit map [ string ] customerform . MasterStruct ) string {
fmt . Printf ( "\n\n应获取的字段--->%v\n\n" , fields )
if len ( fields ) > 0 {
biaotiYUneirong := ""
for _ , v := range fields {
var sendData interface { }
if val , isOk := fieldVal [ v ] ; isOk {
sendData = val
}
unitCont := GainFieldType ( v , subUnit )
fmt . Printf ( "\n\n应获取的字段--1->%v--->%v\n\n" , unitCont . Type , sendData )
switch unitCont . Type {
case "input" , "password" , "lowcodeImage" : //单行文本
biaotiYUneirong = publicmethod . TypeToInterface ( sendData )
case "textarea" , "tinymce" : //多行文本,富文本
biaotiYUneirong = publicmethod . TypeToInterface ( sendData )
case "radio" , "select" : //单选框组、下拉选择框
val := publicmethod . TypeToInterface ( sendData )
if len ( unitCont . Options ) > 0 {
for _ , uv := range unitCont . Options {
if uv . Value == val {
biaotiYUneirong = uv . Label
}
}
}
case "checkbox" , "cascader" , "treeSelect" , "upload" : //checkbox,级联选择器,树形控件,图片/文件: ,
if valMap , isOk := sendData . ( [ ] int ) ; isOk {
if len ( valMap ) > 0 && len ( unitCont . Options ) > 0 {
var titalMap [ ] string
for _ , v := range valMap {
for _ , uv := range unitCont . Options {
if uv . Value == strconv . Itoa ( v ) {
titalMap = append ( titalMap , uv . Label )
}
}
}
biaotiYUneirong = fmt . Sprintf ( "\"%v\"" , strings . Join ( titalMap , "、" ) )
}
}
case "expand-user" : //选择用户
val := publicmethod . TypeToInterface ( sendData )
var userNumber [ ] string
ruleSet := regexp . MustCompile ( ` \(([^)]+)\) ` )
valMap := ruleSet . FindAllStringSubmatch ( val , - 1 )
if len ( valMap ) > 0 {
for _ , v := range valMap {
vLen := len ( v )
if vLen > 0 {
if ! publicmethod . IsInTrue ( v [ vLen - 1 ] , userNumber ) {
userNumber = append ( userNumber , fmt . Sprintf ( "%v(%v)" , v [ 0 ] , v [ vLen - 1 ] ) )
}
}
}
}
biaotiYUneirong = fmt . Sprintf ( "\"%v\"" , strings . Join ( userNumber , "、" ) )
case "datePicker" : //日期选择器
if strVal , ok := sendData . ( [ ] interface { } ) ; ok {
strValLen := len ( strVal )
if strValLen > 1 {
startTimg , _ := publicmethod . StringToInt64 ( strVal [ 0 ] )
endTime , _ := publicmethod . StringToInt64 ( strVal [ strValLen - 1 ] )
biaotiYUneirong = fmt . Sprintf ( "%v 至 %v" , publicmethod . TypeToClass ( startTimg / 1000 , 14 ) , publicmethod . TypeToClass ( endTime / 1000 , 14 ) )
} else if strValLen == 1 {
startTimg , _ := publicmethod . StringToInt64 ( strVal [ 0 ] )
biaotiYUneirong = publicmethod . TypeToClass ( startTimg / 1000 , 14 )
}
} else {
startTimg , _ := publicmethod . StringToInt64 ( sendData )
biaotiYUneirong = publicmethod . TypeToClass ( startTimg , 14 )
}
case "timePicker" , "inputNumber" : //时间选择器,计数器
if strVal , ok := sendData . ( [ ] interface { } ) ; ok {
strValLen := len ( strVal )
if strValLen > 1 {
startTimg , _ := publicmethod . StringToInt64 ( strVal [ 0 ] )
endTime , _ := publicmethod . StringToInt64 ( strVal [ strValLen - 1 ] )
biaotiYUneirong = fmt . Sprintf ( "%v 至 %v" , publicmethod . TypeToClass ( startTimg / 1000 , 14 ) , publicmethod . TypeToClass ( endTime / 1000 , 14 ) )
} else if strValLen == 1 {
startTimg , _ := publicmethod . StringToInt64 ( strVal [ 0 ] )
biaotiYUneirong = publicmethod . TypeToClass ( startTimg / 1000 , 14 )
}
} else {
startTimg , _ := publicmethod . StringToInt64 ( sendData )
biaotiYUneirong = publicmethod . TypeToClass ( startTimg , 14 )
}
case "colorPicker" : //取色器
biaotiYUneirong = publicmethod . TypeToInterface ( sendData )
case "switch" : //开关
startTimg , _ := publicmethod . StringToInt64 ( sendData )
if startTimg == 1 {
biaotiYUneirong = "是"
} else {
biaotiYUneirong = "否"
}
case "rate" , "slider" : //评分,滑块
biaotiYUneirong = publicmethod . TypeToInterface ( sendData )
case "txt" , "button" , "title" , "table" , "grid" , "tabs" , "card" , "flex" , "divider" , "div" : //文本,按钮,标题,表格,格栅,标签,卡片布局,弹性布局,分割线,容器
biaotiYUneirong = publicmethod . TypeToInterface ( sendData )
case "component" : //自定义组件 (格式待定)
biaotiYUneirong = publicmethod . TypeToInterface ( sendData )
default :
biaotiYUneirong = publicmethod . TypeToInterface ( sendData )
}
}
fmt . Printf ( "\n\n应获取的字段-3-->%v\n\n" , biaotiYUneirong )
return biaotiYUneirong
}
return false
return msgTitle
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 03 - 28 15 : 52 : 29
@ 功能 : 获取字段类型
* /
func GainFieldType ( fields string , subUnit map [ string ] customerform . MasterStruct ) ( unitInfo customerform . MasterStruct ) {
if fields != "" {
if val , isOk := subUnit [ fields ] ; isOk {
unitInfo = val
}
}
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 03 - 28 15 : 10 : 14
@ 功能 : 处理自定义人员
* /
func ( s * SendMsgInfo ) CustomizeSendMsg ( ) ( wechatMap [ ] string ) {
if len ( s . SendRangeList ) > 0 {
var Recipient [ ] string
var orgAry [ ] string
var userAry [ ] string
for _ , v := range s . SendRangeList {
if v . Types == "masterOrg" {
if ! publicmethod . IsInTrue [ string ] ( v . Id , orgAry ) {
orgAry = append ( orgAry , v . Id )
}
} else {
if ! publicmethod . IsInTrue [ string ] ( v . Id , userAry ) {
userAry = append ( userAry , v . Id )
}
}
}
if len ( orgAry ) > 0 {
for _ , ov := range orgAry {
val , _ := publicmethod . StringToInt64 ( ov )
if val != 0 {
//获取该组织得所以下级
Recipient = append ( Recipient , GainOrgManWechat ( val ) ... )
}
}
}
if len ( userAry ) > 0 {
var orgManList [ ] modelshr . PersonArchives
overall . CONSTANT_DB_HR . Model ( & modelshr . PersonArchives { } ) . Select ( "`wechat`,`work_wechat`" ) . Where ( "`emp_type` BETWEEN 1 AND 10" ) . Where ( "`state` = 1 AND `id` IN ?" , userAry ) . Find ( & orgManList )
if len ( orgManList ) > 0 {
for _ , v := range orgManList {
if v . Wechat != "" && ! publicmethod . IsInTrue [ string ] ( v . Wechat , Recipient ) {
Recipient = append ( Recipient , v . Wechat )
}
if v . WorkWechat != "" && ! publicmethod . IsInTrue [ string ] ( v . WorkWechat , Recipient ) {
Recipient = append ( Recipient , v . WorkWechat )
}
}
}
}
//人员去重
if len ( Recipient ) > 0 {
for _ , v := range Recipient {
if ! publicmethod . IsInTrue [ string ] ( v , wechatMap ) {
wechatMap = append ( wechatMap , v )
}
}
}
}
return
}
/ *
@ -1415,3 +1795,42 @@ func WriteSunDatabaseSoucer(sqlDb *gorm.DB, uuid, creater, createrTime int64, ma
}
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 04 - 01 13 : 11 : 07
@ 功能 : 撤回发送的信息
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) RecalSendMsg ( c * gin . Context ) {
var requestData publicmethod . PublicId
err := c . ShouldBindJSON ( & requestData )
if err != nil || requestData . Id == "" {
publicmethod . Result ( 10001 , err , c )
return
}
redisKey := fmt . Sprintf ( "SendMsg:Work_WeChat_%v" , requestData . Id )
redisClient := grocerystore . RunRedis ( overall . CONSTANT_REDIS3 )
isTrue , msgId := redisClient . Get ( redisKey )
if ! isTrue {
publicmethod . Result ( 1 , err , c , "数据撤回失败!" )
return
}
if workWechat . RecallWorkWechatMsg ( "stzl" , msgId ) {
redisClient . DelKey ( redisKey )
publicmethod . Result ( 0 , err , c )
} else {
publicmethod . Result ( 1 , err , c , "数据撤回失败!" )
}
}