package shiyan
import (
"encoding/json"
"encoding/xml"
"fmt"
"math"
"os"
"strconv"
"time"
"github.com/flipped-aurora/gin-vue-admin/server/api/textcomparison"
"github.com/flipped-aurora/gin-vue-admin/server/api/wechatapp/sendmessage"
"github.com/flipped-aurora/gin-vue-admin/server/commonus"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/approvalprocess"
"github.com/flipped-aurora/gin-vue-admin/server/model/assessmentmodel"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
"github.com/flipped-aurora/gin-vue-admin/server/model/testpage"
"github.com/flipped-aurora/gin-vue-admin/server/model/wechat"
"github.com/flipped-aurora/gin-vue-admin/server/utils/redishandel"
"github.com/gin-gonic/gin"
"github.com/mitchellh/mapstructure"
)
type ShiyanApi struct {
}
func ( a * ShiyanApi ) AddBaseMenu ( c * gin . Context ) {
var answerMap testpage . Answer
err := global . GVA_DB_Master . First ( & answerMap )
if err != nil {
}
fmt . Printf ( "%v\n" , answerMap )
response . Ok ( c )
}
//get请求获参
func ( a * ShiyanApi ) GetRequestOperation ( c * gin . Context ) {
id := c . Query ( "id" )
fmt . Printf ( "====>%v\n" , id )
// strconv.Atoi(id)
idint , _ := strconv . Atoi ( id )
GetNextMonth ( idint )
response . Ok ( c )
}
func GetNextMonth ( dataSet int ) {
dataSet = dataSet * - 1
now := time . Now ( )
lastMonthFirstDay := now . AddDate ( 0 , dataSet , - now . Day ( ) + 1 )
lastMonthStart := time . Date ( lastMonthFirstDay . Year ( ) , lastMonthFirstDay . Month ( ) , lastMonthFirstDay . Day ( ) , 0 , 0 , 0 , 0 , now . Location ( ) ) . Unix ( )
lastMonthEndDay := lastMonthFirstDay . AddDate ( 0 , 1 , - 1 )
lastMonthEnd := time . Date ( lastMonthEndDay . Year ( ) , lastMonthEndDay . Month ( ) , lastMonthEndDay . Day ( ) , 23 , 59 , 59 , 0 , now . Location ( ) ) . Unix ( )
monthData := commonus . TimeStampToDate ( lastMonthStart , 11 )
monthDatas := commonus . TimeStampToDate ( lastMonthEnd , 11 )
fmt . Printf ( "%v------------------->%v------------------->%v------------------->%v------------------->%v\n" , dataSet , lastMonthStart , lastMonthEnd , monthData , monthDatas )
}
//get请求获参
type postGroupCanshu struct {
Id int ` json:"id" from:"id" `
}
func ( a * ShiyanApi ) PostRequestOperation ( c * gin . Context ) {
var ids postGroupCanshu
_ = c . ShouldBindJSON ( & ids )
// name := c.Query("id")
fmt . Printf ( "====>%v\n" , ids . Id )
response . Ok ( c )
}
func Round ( val float64 , precision int ) float64 {
p := math . Pow10 ( precision )
return math . Floor ( val * p + 0.5 ) / p
}
//实验递归
func ( s * ShiyanApi ) DiGui ( c * gin . Context ) {
// var group []wechat.GroupForm
// listErr := global.GVA_DB_WatchDate.Find(&group).Error
// if listErr == nil {
// }
sdf := Round ( 19.2365233642256 , 2 )
response . Result ( 0 , sdf , "查询成功" , c )
return
var ids wechat . GroupForm
_ = c . ShouldBindJSON ( & ids )
var setid int64
setid = 51
if ids . Id != 0 {
setid = ids . Id
}
redisClient := redishandel . RunRedis ( )
redisClient . SetRedisDb ( 2 )
redisClient . Set ( "cesi" , "ccccc" )
_ , connn , _ := commonus . GetOfficeWork ( 16118387069540343 , setid )
response . Result ( 0 , connn , "查询成功" , c )
return
// var parentId []int64
// var dd Ddigui
// dd.faherDigui(81, group, parentId)
// dd.Date = commonus.BubbleSort(dd.Date)
// var dd commonus.ErgodicStruct
// dd.ParentId = 1
// dd.ErgodicParentClassGroup(setid, group)
// dd.Date = append(dd.Date, setid)
// dd.Date = commonus.BubbleSort(dd.Date)
// setidIntString := strconv.FormatInt(setid, 10)
// setidInt, _ := strconv.Atoi(setidIntString)
// depart, isTrue := commonus.GetDepartment(setidInt)
// dateary := commonus.MapOut()
// dateary["data"] = depart
// dateary["istrue"] = isTrue
// dateary["digui"] = dd.Date
// response.Result(0, dateary, "查询失败", c)
}
type Ddigui struct {
Date [ ] int64
}
//递归递归函数
func ( d * Ddigui ) faherDigui ( id int64 , groupStruct [ ] wechat . GroupForm , parentId [ ] int64 ) [ ] int64 {
var parentIds [ ] int64
// parentId = append(parentId, id)
for _ , v := range groupStruct {
if v . Id == id {
d . Date = append ( d . Date , v . Parentid )
d . faherDigui ( v . Parentid , groupStruct , parentId )
// parentId = append(parentId, v.Parentid)
// fmt.Printf("%v==========>%v*******%v\n", id, v.Parentid, parentId)
// parentIds = parentId
// parentIds = faherDigui(v.Parentid, groupStruct, parentIds)
// parentId = append(parentId, v.Parentid)
// fmt.Printf("%v==========>%v*******%v\n", id, v.Parentid, parentId)
}
}
// parentId = parentIds
// fmt.Printf("%v==========>*******\n", parentIds)
return parentIds
}
//实验结果保存到数组
func ( s * ShiyanApi ) GormToMap ( c * gin . Context ) {
// returnData := commonus.MapOut()
// var returnData []map[string]interface{}
// tableName := "groupform"
// global.GVA_DB_WatchDate.Table(tableName).Find(&returnData)
var pGorm commonus . GormTopMap
pGorm . Db = global . GVA_DB_WatchDate
pGorm . TableName = "groupform"
returnData := commonus . MapOut ( )
returnData [ "ary" ] = pGorm . PublicOrmToMap ( )
returnData [ "one" ] = pGorm . PublicOrmToMapOne ( )
response . Result ( 0 , returnData , "查询成功" , c )
}
type PersonInfo struct {
DefinitIons interface { } ` json:"definitions" `
}
//读取json文件解析
func ( s * ShiyanApi ) ReadJsonFiles ( c * gin . Context ) {
filePtr , err := os . Open ( "conf/forkflow.json" )
defer filePtr . Close ( )
if err != nil {
dfg := fmt . Sprintf ( "Open file failed [Err:%s]" , err . Error ( ) )
// fmt.Println("Open file failed [Err:%s]", err.Error())
response . Result ( 0 , dfg , "查询成功" , c )
return
}
decoder := json . NewDecoder ( filePtr )
var person [ ] PersonInfo
err = decoder . Decode ( & person )
if err != nil {
fmt . Println ( "Decoder failed" , err . Error ( ) )
}
fmt . Println ( "Open file failed [Err:%s]" , person )
returnData := commonus . MapOut ( )
returnData [ "json" ] = person
response . Result ( 0 , returnData , "查询成功" , c )
}
//XML转换处理
/ *
* XML结构体
* /
type Definitions struct {
XMLName xml . Name ` xml:"definitions" json:"definitions" `
Text string ` xml:",chardata" json:"chardata" `
Bpmn2 string ` xml:"bpmn2,attr" json:"bpmn2" `
Xsi string ` xml:"xsi,attr" json:"xsi" `
Bpmndi string ` xml:"bpmndi,attr" json:"bpmndi" `
Dc string ` xml:"dc,attr" json:"dc" `
Flowable string ` xml:"flowable,attr" json:"flowable" `
Di string ` xml:"di,attr" json:"di" `
ID string ` xml:"id,attr" json:"id" `
TargetNamespace string ` xml:"targetNamespace,attr" json:"targetNamespace" `
SchemaLocation string ` xml:"schemaLocation,attr" json:"schemaLocation" `
Process ProcessStruct ` xml:"process" json:"process" ` //工作流过程
BPMNDiagram BPMNDiagramStruct ` xml:"BPMNDiagram" json:"BPMNDiagram" ` //BPMN图结构
}
//工作流过程
type ProcessStruct struct {
TextAndIdStruct
NameStruct
Documentation Documentationstruct ` xml:"documentation" json:"documentation" ` //结构描述
StartEvent StartEventStruct ` xml:"startEvent" json:"startEvent" ` //开始事件
UserTask [ ] UserTaskStruct ` xml:"userTask" json:"userTask" ` //流程主体(用户任务)
EndEvent EndEventStruct ` xml:"endEvent" json:"endEvent" ` //结束事件
SequenceFlow [ ] SequenceFlowStruct ` xml:"sequenceFlow" json:"sequenceFlow" ` //序列流
}
//text结构体
type TextStruct struct {
Text string ` xml:",chardata" json:",text" `
}
//name结构体
type NameStruct struct {
Name string ` xml:"name,attr" json:"name" `
}
//Text与ID 结构
type TextAndIdStruct struct {
TextStruct
ID string ` xml:"id,attr" json:"id" `
}
type Documentationstruct struct {
TextStruct
}
//工作流开始事件
type StartEventStruct struct {
TextAndIdStruct
NameStruct
Outgoing [ ] OutgoingStruct ` xml:"outgoing" json:"outgoing" ` //流程出口
}
//流程出口结构
type OutgoingStruct struct {
TextStruct
}
//流程主体(用户任务)
type UserTaskStruct struct {
TextAndIdStruct
NameStruct
Assignee string ` xml:"assignee,attr" json:"assignee" ` //处理人
CandidateGroups string ` xml:"candidateGroups,attr" json:"candidateGroups" ` //处理角色
CandidateUsers string ` xml:"candidateUsers,attr" json:"candidateUsers" ` //处理人
Incoming [ ] IncomingStruct ` xml:"incoming" json:"incoming" ` //来源
Outgoing [ ] OutgoingStruct ` xml:"outgoing" json:"outgoing" ` //流程去向(下一个节点)
}
//本节点来源
type IncomingStruct struct {
TextStruct
}
//结束事件
type EndEventStruct struct {
TextAndIdStruct
NameStruct
Incoming [ ] IncomingStruct ` xml:"incoming" json:"incoming" ` //来源
}
//序列流
type SequenceFlowStruct struct {
TextAndIdStruct
NameStruct
SourceRef string ` xml:"sourceRef,attr" json:"sourceRef" ` //源
TargetRef string ` xml:"targetRef,attr" json:"targetRef" ` //流向
ConditionExpression ConditionExpressionStruct ` xml:"conditionExpression" json:"conditionExpression" ` //条件表达式
}
//条件表达式
type ConditionExpressionStruct struct {
TextStruct
Type string ` xml:"type,attr" json:"type" `
}
//BPMN图结构
type BPMNDiagramStruct struct {
TextAndIdStruct
BPMNPlane BPMNPlaneStruct ` xml:"BPMNPlane" json:"BPMNPlane" `
}
//图平面坐标参数
type BPMNPlaneStruct struct {
TextAndIdStruct
BpmnElement string ` xml:"bpmnElement,attr" json:"bpmnElement" ` //Bpmn元素
BPMNShape [ ] BPMNShapeStruct ` xml:"BPMNShape" json:"BPMNShape" ` //Bpmn 坐标参数
BPMNEdge [ ] BPMNEdgeStruct ` xml:"BPMNEdge" json:"BPMNEdge" ` //Bpmn界限
}
//Bpmn 坐标参数
type BPMNShapeStruct struct {
TextAndIdStruct
BpmnElement string ` xml:"bpmnElement,attr" json:"bpmnElement" `
Bounds BoundsStruct ` xml:"Bounds" json:"Bounds" ` //图形元素坐标
BPMNLabel BPMNLabelStruct ` xml:"BPMNLabel" json:"BPMNLabel" ` //BPMN标签
}
//图形元素坐标
type BoundsStruct struct {
TextStruct
X string ` xml:"x,attr" json:"x" `
Y string ` xml:"y,attr" json:"y" `
Width string ` xml:"width,attr" json:"width" `
Height string ` xml:"height,attr" json:"height" `
}
//BPMN标签
type BPMNLabelStruct struct {
TextStruct
Bounds BoundsStruct ` xml:"Bounds" json:"Bounds" ` //图形元素坐标
}
//Bpmn界限
type BPMNEdgeStruct struct {
TextAndIdStruct
BpmnElement string ` xml:"bpmnElement,attr" json:"bpmnElement" `
Waypoint [ ] WaypointStruct ` xml:"waypoint" json:"waypoint" ` //线路径坐标
}
//线路径坐标
type WaypointStruct struct {
TextStruct
X string ` xml:"x,attr" json:"x" `
Y string ` xml:"y,attr" json:"y" `
}
//接收参数
type XmlCanShu struct {
ProcessKey string ` json:"processKey" `
ProcessName string ` json:"processName" `
ResourceName string ` json:"resourceName" `
Xml string ` json:"xml" `
Svg string ` json:"svg" `
JsonStr string ` json:"jsonstr" `
}
//工作流XML解析
func ( s * ShiyanApi ) XmlToJson ( c * gin . Context ) {
var xmlToStruct Definitions
var reportAnswer XmlCanShu
err := c . ShouldBindJSON ( & reportAnswer )
// if err != nil {
// response.Result(101, err, "参数错误!", c)
// return
// }
if reportAnswer . Xml == "" {
response . Result ( 102 , err , "参数错误!" , c )
return
}
errs := xml . Unmarshal ( [ ] byte ( reportAnswer . Xml ) , & xmlToStruct )
if nil != errs {
fmt . Println ( "Unmarshal fail" )
} else {
fmt . Println ( "struct" , xmlToStruct )
}
returnData := commonus . MapOut ( )
returnData [ "reportAnswer" ] = reportAnswer
returnData [ "xmlToStruct" ] = xmlToStruct
var approvalProcess approvalprocess . ApprovalProcess
processMap := commonus . MapOut ( )
processId := commonus . GetFileNumberEs ( )
approvalProcess . Id = processId
processMap [ "id" ] = processId
approvalProcess . Name = xmlToStruct . Process . Name
processMap [ "name" ] = xmlToStruct . Process . Name
result , jsonErr := json . Marshal ( xmlToStruct )
if jsonErr == nil {
approvalProcess . Flow = string ( result )
processMap [ "flow" ] = string ( result )
} else {
processMap [ "flow" ] = ""
}
approvalProcess . FlowJson = reportAnswer . JsonStr
processMap [ "flowjson" ] = reportAnswer . JsonStr
approvalProcess . FlowXml = reportAnswer . Xml
processMap [ "flowxml" ] = reportAnswer . Xml
approvalProcess . FlowSvg = reportAnswer . Svg
processMap [ "flowsvg" ] = reportAnswer . Svg
resultPro , jsonErrPro := json . Marshal ( xmlToStruct . Process )
if jsonErrPro == nil {
approvalProcess . GetFlowJson = string ( resultPro )
processMap [ "getflowjson" ] = string ( resultPro )
} else {
processMap [ "getflowjson" ] = ""
}
approvalProcess . Time = time . Now ( ) . Unix ( )
approvalProcess . EiteTime = time . Now ( ) . Unix ( )
approvalProcess . Sate = 1
processMap [ "sate" ] = 1
batchNum := commonus . GetFileNumberEs ( )
approvalProcess . Batch = batchNum
processMap [ "batchnum" ] = batchNum
approvalProcess . EditionNum = "V1.0"
processMap [ "editionnum" ] = "V1.0"
returnData [ "approvalProcess" ] = approvalProcess
// writeRedisData := map[string]interface{}{
// "name": xmlToStruct.Process.Name,
// "flow": string(result),
// "flowjson": reportAnswer.JsonStr,
// "flowxml": reportAnswer.Xml,
// "flowsvg": reportAnswer.Svg,
// "getflowjson": string(resultPro),
// "sate": 1,
// "batchnum": batchNum,
// "editionnum": "V1.0",
// }
// addProcess := global.GVA_DB_ApprovalProcess.Create(&approvalProcess)
// if addProcess.Error != nil {
// response.Result(104, addProcess.Error, "流程创建失败", c)
// return
// }
redisClient := redishandel . RunRedis ( )
redisClient . SetRedisTime ( 0 )
kks := redisClient . HashMsetAdd ( "Process:ApprovalProcess_" + global . GVA_CONFIG . RedisPrefix . Alias + "_" + strconv . FormatInt ( batchNum , 10 ) , processMap )
response . Result ( 103 , kks , "参数错误!" , c )
}
type ExamineApprove struct {
ProcessId int64 ` json:"processId" ` //流程批次
ExamineApproveId int64 ` json:"examineApproveId" ` //正在执行的流程
Type int ` json:"type" ` //状态(1:同意;2:驳回;3:暂存)
Condition string ` json:"condition" ` //判断条件
State int ` json:"state" ` //状态
}
//审批记录Redis过度
type ApprovalProcessLogRedis struct {
Id string ` json:"id" `
Process string ` json:"process" `
CurrentNode string ` json:"currentNode" `
Title string ` json:"title" `
Time string ` json:"time" `
EiteTime string ` json:"eiteTime" `
ProcessNum string ` json:"processNum" `
IsEnd string ` json:"isEnd" `
State string ` json:"state" `
}
//创建及审批
func ( s * ShiyanApi ) EstablishApprove ( c * gin . Context ) {
var examineApprove ExamineApprove
err := c . ShouldBindJSON ( & examineApprove )
if err != nil {
response . Result ( 101 , err , "参数错误!" , c )
return
}
if examineApprove . ProcessId == 0 || examineApprove . ExamineApproveId == 0 {
response . Result ( 102 , examineApprove , "参数错误!" , c )
return
}
if examineApprove . Type == 0 {
examineApprove . Type = 2
}
//正在执行的流程
var runApprovalProcess approvalprocess . ApprovalProcessLog
//缓存设置
redisClient := redishandel . RunRedis ( )
approvalProcessRedis , isTrue := redisClient . HashGetAll ( "Process:RunApprovalProcess_" + global . GVA_CONFIG . RedisPrefix . Alias + "_" + strconv . FormatInt ( examineApprove . ExamineApproveId , 10 ) )
if isTrue != true { //判断是否存在缓存
runProcessMap := commonus . MapOut ( )
appProLogErr := global . GVA_DB_ApprovalProcess . Where ( "`apl_id` = ?" , examineApprove . ExamineApproveId ) . First ( & runApprovalProcess ) . Error
if appProLogErr != nil {
var getApprovalProcess approvalprocess . ApprovalProcess
getProLogErr := global . GVA_DB_ApprovalProcess . Where ( "`ap_batch` = ? AND `ap_state` = 1" , examineApprove . ProcessId ) . First ( & getApprovalProcess ) . Error
if getProLogErr != nil {
response . Result ( 103 , getApprovalProcess , "对不起该流程不存在" , c )
return
}
runApprovalProcess . Process = getApprovalProcess . GetFlowJson
runProcessMap [ "process" ] = getApprovalProcess . GetFlowJson
//流程json转为struct
var process ProcessStruct
jsonErrPro := json . Unmarshal ( [ ] byte ( getApprovalProcess . GetFlowJson ) , & process )
if jsonErrPro == nil {
runApprovalProcess . CurrentNode = process . StartEvent . ID
runApprovalProcess . Title = process . StartEvent . Name
runApprovalProcess . ProcessNum = getApprovalProcess . Batch
runProcessMap [ "currentNode" ] = process . StartEvent . ID
runProcessMap [ "title" ] = process . StartEvent . Name
runProcessMap [ "processNum" ] = getApprovalProcess . Batch
} else {
runApprovalProcess . CurrentNode = ""
runApprovalProcess . Title = ""
runApprovalProcess . ProcessNum = 0
runProcessMap [ "currentNode" ] = ""
runProcessMap [ "title" ] = ""
runProcessMap [ "processNum" ] = 0
}
runApprovalProcess . Time = time . Now ( ) . Unix ( )
runApprovalProcess . EiteTime = time . Now ( ) . Unix ( )
runApprovalProcess . IsEnd = 1
runProcessMap [ "isend" ] = 1
if examineApprove . State == 0 {
runApprovalProcess . Sate = 1
runProcessMap [ "state" ] = 1
} else {
runApprovalProcess . Sate = examineApprove . State
runProcessMap [ "state" ] = examineApprove . State
}
runProcessMap [ "time" ] = time . Now ( ) . Unix ( )
runProcessMap [ "eiteTime" ] = time . Now ( ) . Unix ( )
addProcess := global . GVA_DB_ApprovalProcess . Create ( & runApprovalProcess ) . Error
if addProcess != nil {
response . Result ( 104 , getApprovalProcess , "对不起该流程启用失败" , c )
return
}
runProcessMap [ "id" ] = runApprovalProcess . Id
redisClient . SetRedisTime ( 0 )
redisClient . HashMsetAdd ( "Process:RunApprovalProcess_" + global . GVA_CONFIG . RedisPrefix . Alias + "_" + strconv . FormatInt ( runApprovalProcess . Id , 10 ) , runProcessMap )
} else {
runProcessMap [ "process" ] = runApprovalProcess . Process
runProcessMap [ "currentNode" ] = runApprovalProcess . CurrentNode
runProcessMap [ "title" ] = runApprovalProcess . Title
runProcessMap [ "processNum" ] = runApprovalProcess . ProcessNum
runProcessMap [ "time" ] = runApprovalProcess . Time
runProcessMap [ "eiteTime" ] = runApprovalProcess . EiteTime
runProcessMap [ "id" ] = runApprovalProcess . Id
runProcessMap [ "isend" ] = runApprovalProcess . IsEnd
runProcessMap [ "state" ] = runApprovalProcess . Sate
if runApprovalProcess . IsEnd == 1 {
redisClient . SetRedisTime ( 0 )
} else {
redisClient . SetRedisTime ( 604800 )
}
redisClient . HashMsetAdd ( "Process:RunApprovalProcess_" + global . GVA_CONFIG . RedisPrefix . Alias + "_" + strconv . FormatInt ( runApprovalProcess . Id , 10 ) , runProcessMap )
if runApprovalProcess . IsEnd != 1 {
response . Result ( 105 , runApprovalProcess , "该流程已经结束!请不要重复执行!" , c )
return
}
}
} else {
// fmt.Printf("Redis====》%v\n", runApprovalProcess)
var approvalProcessLogRedis ApprovalProcessLogRedis
err := mapstructure . Decode ( approvalProcessRedis , & approvalProcessLogRedis )
if err != nil {
response . Result ( 104 , err , "对不起该流程启用失败" , c )
return
// return departmentlist, false
}
appId , appIdErr := strconv . ParseInt ( approvalProcessLogRedis . Id , 10 , 64 )
if appIdErr == nil {
runApprovalProcess . Id = appId
}
// fmt.Printf("审批ID==Redis==》%v-------------%v\n", approvalProcessLogRedis.Id, appId)
processNum , processNumErr := strconv . ParseInt ( approvalProcessLogRedis . ProcessNum , 10 , 64 )
if processNumErr == nil {
runApprovalProcess . ProcessNum = processNum
}
timeVal , timeErr := strconv . ParseInt ( approvalProcessLogRedis . Time , 10 , 64 )
if timeErr == nil {
runApprovalProcess . Time = timeVal
}
eiteTime , eiteTimeErr := strconv . ParseInt ( approvalProcessLogRedis . EiteTime , 10 , 64 )
if eiteTimeErr == nil {
runApprovalProcess . EiteTime = eiteTime
}
isEnd , isEndErr := strconv . Atoi ( approvalProcessLogRedis . IsEnd )
if isEndErr == nil {
runApprovalProcess . IsEnd = isEnd
} else {
response . Result ( 107 , runApprovalProcess , "对不起该流程启用失败!" , c )
return
}
sateSet , sateErr := strconv . Atoi ( approvalProcessLogRedis . State )
if sateErr == nil {
runApprovalProcess . Sate = sateSet
} else {
response . Result ( 108 , sateErr , "对不起该流程启用失败!" , c )
return
}
runApprovalProcess . Process = approvalProcessLogRedis . Process
runApprovalProcess . CurrentNode = approvalProcessLogRedis . CurrentNode
runApprovalProcess . Title = approvalProcessLogRedis . Title
if runApprovalProcess . IsEnd != 1 {
response . Result ( 106 , runApprovalProcess , "该流程已经结束!请不要重复执行!" , c )
return
}
}
// fmt.Printf("数据结构===========>%v\n", runApprovalProcess)
switch examineApprove . Type {
case 1 : //批准
ApproveOperation ( runApprovalProcess , examineApprove )
case 3 : //暂存
default : //驳回
}
}
//批准操作
func ApproveOperation ( runApprovalProcess approvalprocess . ApprovalProcessLog , examineApprove ExamineApprove ) ( isTrue bool ) {
// fmt.Printf("审批ID==Redis==》%v-------------%v\n", runApprovalProcess.Id, runApprovalProcess)
isTrue = false
// fmt.Printf("结果====》%v\n", runApprovalProcess)
var process ProcessStruct
jsonErrPro := json . Unmarshal ( [ ] byte ( runApprovalProcess . Process ) , & process )
if jsonErrPro != nil {
fmt . Printf ( "转换失败====》%v\n" , process )
return
}
if runApprovalProcess . CurrentNode == process . EndEvent . ID {
fmt . Printf ( "执行结束节点====》%v\n" , process . EndEvent . ID )
return
}
if runApprovalProcess . CurrentNode == process . StartEvent . ID {
fmt . Printf ( "执行开始节点====》%v\n" , process . StartEvent . ID )
if len ( process . StartEvent . Outgoing ) > 1 {
fmt . Printf ( "执行开始节点====有条件》%v\n" , process . StartEvent . ID )
currentId := runApprovalProcess . CurrentNode
appId , appTitle , appIsTrue , isEnd := ApprovalCriteria ( 1 , process , examineApprove , runApprovalProcess . CurrentNode )
fmt . Printf ( "执行审批节点==11111==下一个节点》%v----%v-----%v\n" , appId , appTitle , appIsTrue )
if appIsTrue != true {
return
}
isTrue = true
currentId = appId
// for _, outGoing := range process.StartEvent.Outgoing {
// for _, seqFlow := range process.SequenceFlow {
// if outGoing.Text == seqFlow.ID {
// // fmt.Printf("条件(%v)====》对比条件-----%v\n", seqFlow.ConditionExpression.Text, examineApprove.Condition)
// if seqFlow.ConditionExpression.Text == examineApprove.Condition {
// isTrue = true
// currentId = seqFlow.TargetRef
// fmt.Printf("执行节点====》%v\n", seqFlow.TargetRef)
// }
// }
// }
// }
runApprovalProcess . CurrentNode = currentId
runApprovalProcess . Title = appTitle
runApprovalProcess . EiteTime = time . Now ( ) . Unix ( )
runProcessMap := commonus . MapOut ( )
runProcessMap [ "process" ] = runApprovalProcess . Process
runProcessMap [ "currentNode" ] = currentId
runProcessMap [ "processNum" ] = runApprovalProcess . ProcessNum
runProcessMap [ "time" ] = time . Now ( ) . Unix ( )
runProcessMap [ "title" ] = appTitle
runProcessMap [ "eiteTime" ] = time . Now ( ) . Unix ( )
if isEnd == true {
runApprovalProcess . IsEnd = 2
runProcessMap [ "isend" ] = 2
}
//缓存设置
redisClient := redishandel . RunRedis ( )
redisClient . SetRedisTime ( 604800 )
redisClient . HashMsetAdd ( "Process:RunApprovalProcess_" + global . GVA_CONFIG . RedisPrefix . Alias + "_" + strconv . FormatInt ( runApprovalProcess . Id , 10 ) , runProcessMap )
fmt . Printf ( "审批ID==22222==》%v\n" , runApprovalProcess . Id )
eiteProcess := global . GVA_DB_ApprovalProcess . Where ( "`apl_id` = ?" , runApprovalProcess . Id ) . Updates ( & runApprovalProcess ) . Error
if eiteProcess == nil {
fmt . Printf ( "更新成功====》%v\n" , runApprovalProcess )
} else {
fmt . Printf ( "更新失败====》%v\n" , runApprovalProcess )
}
return
} else if len ( process . StartEvent . Outgoing ) < 1 {
fmt . Printf ( "执行开始节点====未知下个节点》%v\n" , process . StartEvent . ID )
} else {
fmt . Printf ( "执行开始节点====直接到审批》%v\n" , process . StartEvent . ID )
}
}
for _ , taskVal := range process . UserTask {
if runApprovalProcess . CurrentNode == taskVal . ID {
fmt . Printf ( "执行审批节点====》%v\n" , taskVal . ID )
appId , appTitle , appIsTrue , isEnd := ApprovalCriteria ( 3 , process , examineApprove , runApprovalProcess . CurrentNode )
fmt . Printf ( "执行审批节点====下一个节点》%v----%v-----%v\n" , appId , appTitle , appIsTrue )
currentId := runApprovalProcess . CurrentNode
if appIsTrue != true {
return
}
isTrue = true
currentId = appId
runApprovalProcess . CurrentNode = currentId
runApprovalProcess . Title = appTitle
runApprovalProcess . EiteTime = time . Now ( ) . Unix ( )
runProcessMap := commonus . MapOut ( )
runProcessMap [ "process" ] = runApprovalProcess . Process
runProcessMap [ "currentNode" ] = currentId
runProcessMap [ "processNum" ] = runApprovalProcess . ProcessNum
runProcessMap [ "time" ] = time . Now ( ) . Unix ( )
runProcessMap [ "title" ] = appTitle
runProcessMap [ "eiteTime" ] = time . Now ( ) . Unix ( )
if isEnd == true {
runApprovalProcess . IsEnd = 2
runProcessMap [ "isend" ] = 2
}
//缓存设置
redisClient := redishandel . RunRedis ( )
redisClient . SetRedisTime ( 604800 )
redisClient . HashMsetAdd ( "Process:RunApprovalProcess_" + global . GVA_CONFIG . RedisPrefix . Alias + "_" + strconv . FormatInt ( runApprovalProcess . Id , 10 ) , runProcessMap )
fmt . Printf ( "审批ID====》%v\n" , runApprovalProcess . Id )
eiteProcess := global . GVA_DB_ApprovalProcess . Where ( "`apl_id` = ?" , runApprovalProcess . Id ) . Updates ( & runApprovalProcess ) . Error
if eiteProcess == nil {
fmt . Printf ( "更新成功uis====》%v\n" , runApprovalProcess )
} else {
fmt . Printf ( "更新失败uis====》%v\n" , runApprovalProcess )
}
return
}
}
return
}
//审批条件解析
/ *
@ execStatus 执行状态 1 : 开始 ; 2 : 结束 ; 3 : 审批
* /
func ApprovalCriteria ( execStatus int , process ProcessStruct , examineApprove ExamineApprove , currentNode string ) ( currentId , nextTitle string , isTrue , isEnd bool ) {
isTrue = false
isEnd = false
//解析条件判断,获取出下个节点的ID
switch execStatus {
case 1 :
fmt . Printf ( "State ----------> %v\n" , execStatus )
for _ , outGoing := range process . StartEvent . Outgoing {
for _ , seqFlow := range process . SequenceFlow {
if outGoing . Text == seqFlow . ID {
fmt . Printf ( "条件(%v)====》对比条件-----%v\n" , seqFlow . ConditionExpression . Text , examineApprove . Condition )
if seqFlow . ConditionExpression . Text == examineApprove . Condition {
isTrue = true
currentId = seqFlow . TargetRef
fmt . Printf ( "执行节点====》%v\n" , seqFlow . TargetRef )
}
}
}
}
case 2 :
fmt . Printf ( "State ----------> %v\n" , execStatus )
default :
fmt . Printf ( "State ----------> %v\n" , execStatus )
for _ , taskVal := range process . UserTask {
if taskVal . ID == currentNode {
for _ , outGoing := range taskVal . Outgoing {
for _ , seqFlow := range process . SequenceFlow {
if outGoing . Text == seqFlow . ID {
fmt . Printf ( "条件(%v)====》对比条件-----%v\n" , seqFlow . ConditionExpression . Text , examineApprove . Condition )
if seqFlow . ConditionExpression . Text == examineApprove . Condition {
isTrue = true
currentId = seqFlow . TargetRef
fmt . Printf ( "执行节点====》%v\n" , seqFlow . TargetRef )
}
}
}
}
}
// for _, seqFlow := range process.SequenceFlow {
// fmt.Printf("条件(%v)====》对比条件-----%v\n", taskVal.ID, seqFlow.ID)
// if taskVal.ID == seqFlow.ID {
// if seqFlow.ConditionExpression.Text == examineApprove.Condition {
// isTrue = true
// currentId = seqFlow.TargetRef
// fmt.Printf("执行节点====》%v\n", seqFlow.TargetRef)
// }
// }
// }
}
}
nextNameIsTrue := false
//获取审批节点名称
for _ , taskVal := range process . UserTask {
if taskVal . ID == currentId {
nextTitle = taskVal . Name
nextNameIsTrue = true
}
}
if nextNameIsTrue != true {
if currentId == process . EndEvent . ID {
nextTitle = process . EndEvent . Name
nextNameIsTrue = true
isEnd = true
return
}
if currentId == process . StartEvent . ID {
nextTitle = process . StartEvent . Name
nextNameIsTrue = true
}
}
return
}
//实验发送按钮交互模板
func ( s * ShiyanApi ) SendButtonMsg ( c * gin . Context ) {
// var sendMsg commonus.ButtonTemplateAll
var sendMsg commonus . ButtonTemplate
sendMsg . Touser = "KaiXinGuo"
sendMsg . MsgType = "template_card"
appId , _ := strconv . ParseInt ( global . GVA_CONFIG . WorkWechatSchool . AgentId , 10 , 64 )
sendMsg . AgentId = appId
sendMsg . EnableIdTrans = 0
sendMsg . EnableDuplicateCheck = 0
sendMsg . DuplicateCheckInterval = 1800
//模板卡片类型,按钮交互型卡片填写"button_interaction" (必填)
sendMsg . TemplateCard . CardType = "button_interaction"
//卡片来源样式信息,不需要来源样式可不填写(非必填)
sendMsg . TemplateCard . Source . IconUrl = "https://docu.hxgk.group/images/2022_01/3f7a1120a559e9bee3991b85eb34d103.png"
sendMsg . TemplateCard . Source . Desc = "知行学院"
sendMsg . TemplateCard . Source . DescColor = 2
//卡片右上角更多操作按钮 (非必填)
// sendMsg.TemplateCard.ActionMenu =
// sendMsg.TemplateCard.ActionMenu.Desc = "卡片副交互辅助文本说明"
// var actionList []commonus.ActionListStruct
// var actionCont commonus.ActionListStruct
// actionCont.Text = "接受推送"
// actionCont.Key = "A"
// actionList = append(actionList, actionCont)
// actionCont.Text = "不再推"
// actionCont.Key = "b"
// actionList = append(actionList, actionCont)
// sendMsg.TemplateCard.ActionMenu.ActionList = actionList
//一级标题,建议不超过36个字,(支持id转译)
sendMsg . TemplateCard . MainTitle . Title = "公务用车审批"
sendMsg . TemplateCard . MainTitle . Desc = "请你认真查询审批内容!" //标题辅助信息,建议不超过44个字,(支持id转译)
//引用文献样式
sendMsg . TemplateCard . QuoteArea . Type = 1
sendMsg . TemplateCard . QuoteArea . Url = "http://www.hxgk.group"
sendMsg . TemplateCard . QuoteArea . Title = "用车编号"
sendMsg . TemplateCard . QuoteArea . QuoteText = "用车理由:\n工作需要 \n目的地:宁阳"
//二级普通文本,建议不超过160个字(非必填)
// sendMsg.TemplateCard.SubTitleText = "二级普通文本,下载企业微信还能抢红包!"
//二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6(非必填)
var htalConListStrMap [ ] commonus . HorizontalContentListStruct
var htalConListStrCon commonus . HorizontalContentListStruct
htalConListStrCon . Type = 3
htalConListStrCon . KeyName = "申请人"
htalConListStrCon . Value = "秦东"
htalConListStrCon . UserId = "KaiXinGuo"
htalConListStrMap = append ( htalConListStrMap , htalConListStrCon )
// htalConListStrCon.Type = 1
// htalConListStrCon.KeyName = "企业微信官网"
// htalConListStrCon.Value = "点击访问"
// htalConListStrCon.Url = "http://admin.hxgk.group"
// htalConListStrMap = append(htalConListStrMap, htalConListStrCon)
htalConListStrCon . Type = 3
htalConListStrCon . KeyName = "乘车人"
htalConListStrCon . Value = "秦东"
htalConListStrCon . UserId = "KaiXinGuo"
htalConListStrMap = append ( htalConListStrMap , htalConListStrCon )
sendMsg . TemplateCard . HorizontalContentList = htalConListStrMap
//整体卡片的点击跳转事件 (非必填)
sendMsg . TemplateCard . CardAction . Type = 1
sendMsg . TemplateCard . CardAction . Url = "http://admin.hxgk.group"
//任务id,同一个应用任务id不能重复,只能由数字、字母和“_-@”组成,最长128字节 (必填)
taskId := commonus . GetFileNumberEs ( )
sendMsg . TemplateCard . TaskId = strconv . FormatInt ( taskId , 10 )
//下拉式的选择器 (未知是否必填)
// questionKey := commonus.GetFileNumberEs()
// sendMsg.TemplateCard.ButtonSelection.QuestionKey = strconv.FormatInt(questionKey, 10)
// sendMsg.TemplateCard.ButtonSelection.Title = "下拉标题"
// //下拉内容设置
// var optionListMap []commonus.OptionListStructes
// var optionListCont commonus.OptionListStructes
// optionListCont.Id = "btn_selection_id1"
// optionListCont.Text = "100分"
// optionListMap = append(optionListMap, optionListCont)
// optionListCont.Id = "btn_selection_id2"
// optionListCont.Text = "110分"
// optionListMap = append(optionListMap, optionListCont)
// sendMsg.TemplateCard.ButtonSelection.OptionList = optionListMap
// sendMsg.TemplateCard.ButtonSelection.SelectedId = "btn_selection_id1"
//按钮列表,列表长度不超过6(必填)
var buttonMap [ ] commonus . ButtonListStruct
var buttonCont commonus . ButtonListStruct
buttonCont . Type = 0
buttonCont . Text = "批准"
buttonCont . Style = 1
buttonCont . Key = "button_key_1"
buttonMap = append ( buttonMap , buttonCont )
buttonCont . Type = 0
buttonCont . Text = "驳回"
buttonCont . Style = 3
buttonCont . Key = "button_key_2"
buttonMap = append ( buttonMap , buttonCont )
sendMsg . TemplateCard . ButtonList = buttonMap
response . Result ( 0 , sendMsg , "查询成功" , c )
callbakcMsg , isTrueCall , callBackCont := sendMsg . SendButtonMessage ( )
fmt . Printf ( "发送信息返回:%v-----------%v----------->%v\n" , string ( callbakcMsg ) , isTrueCall , callBackCont )
}
func ( s * ShiyanApi ) SendButtonMessageAll ( c * gin . Context ) {
var sendMsg commonus . ButtonTemplateAll
// var sendMsg commonus.ButtonTemplate
sendMsg . Touser = "KaiXinGuo"
sendMsg . MsgType = "template_card"
appId , _ := strconv . ParseInt ( global . GVA_CONFIG . WorkWechatSchool . AgentId , 10 , 64 )
sendMsg . AgentId = appId
sendMsg . EnableIdTrans = 0
sendMsg . EnableDuplicateCheck = 0
sendMsg . DuplicateCheckInterval = 1800
//模板卡片类型,按钮交互型卡片填写"button_interaction" (必填)
sendMsg . TemplateCard . CardType = "button_interaction"
//卡片来源样式信息,不需要来源样式可不填写(非必填)
sendMsg . TemplateCard . Source . IconUrl = "https://docu.hxgk.group/images/2022_01/3f7a1120a559e9bee3991b85eb34d103.png"
sendMsg . TemplateCard . Source . Desc = "知行学院"
sendMsg . TemplateCard . Source . DescColor = 2
//卡片右上角更多操作按钮 (非必填)
// sendMsg.TemplateCard.ActionMenu =
sendMsg . TemplateCard . ActionMenu . Desc = "卡片副交互辅助文本说明"
var actionList [ ] commonus . ActionListStruct
var actionCont commonus . ActionListStruct
actionCont . Text = "接受推送"
actionCont . Key = "A"
actionList = append ( actionList , actionCont )
actionCont . Text = "不再推"
actionCont . Key = "b"
actionList = append ( actionList , actionCont )
sendMsg . TemplateCard . ActionMenu . ActionList = actionList
//一级标题,建议不超过36个字,(支持id转译)
sendMsg . TemplateCard . MainTitle . Title = "公务用车审批"
sendMsg . TemplateCard . MainTitle . Desc = "请你认真查询审批内容!" //标题辅助信息,建议不超过44个字,(支持id转译)
//引用文献样式
sendMsg . TemplateCard . QuoteArea . Type = 1
sendMsg . TemplateCard . QuoteArea . Url = "http://www.hxgk.group"
sendMsg . TemplateCard . QuoteArea . Title = "用车编号"
sendMsg . TemplateCard . QuoteArea . QuoteText = "用车理由:\n工作需要 \n目的地:宁阳"
//二级普通文本,建议不超过160个字(非必填)
sendMsg . TemplateCard . SubTitleText = "二级普通文本,下载企业微信还能抢红包!"
//二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6(非必填)
var htalConListStrMap [ ] commonus . HorizontalContentListStruct
var htalConListStrCon commonus . HorizontalContentListStruct
htalConListStrCon . Type = 3
htalConListStrCon . KeyName = "申请人"
htalConListStrCon . Value = "秦东"
htalConListStrCon . UserId = "KaiXinGuo"
htalConListStrMap = append ( htalConListStrMap , htalConListStrCon )
htalConListStrCon . Type = 1
htalConListStrCon . KeyName = "企业微信官网"
htalConListStrCon . Value = "点击访问"
htalConListStrCon . Url = "tel:15069130853"
htalConListStrMap = append ( htalConListStrMap , htalConListStrCon )
htalConListStrCon . Type = 3
htalConListStrCon . KeyName = "乘车人"
htalConListStrCon . Value = "秦东"
htalConListStrCon . UserId = "KaiXinGuo"
htalConListStrMap = append ( htalConListStrMap , htalConListStrCon )
sendMsg . TemplateCard . HorizontalContentList = htalConListStrMap
//整体卡片的点击跳转事件 (非必填)
sendMsg . TemplateCard . CardAction . Type = 1
sendMsg . TemplateCard . CardAction . Url = "http://admin.hxgk.group"
//任务id,同一个应用任务id不能重复,只能由数字、字母和“_-@”组成,最长128字节 (必填)
taskId := commonus . GetFileNumberEs ( )
sendMsg . TemplateCard . TaskId = strconv . FormatInt ( taskId , 10 )
//下拉式的选择器 (未知是否必填)
questionKey := commonus . GetFileNumberEs ( )
sendMsg . TemplateCard . ButtonSelection . QuestionKey = strconv . FormatInt ( questionKey , 10 )
sendMsg . TemplateCard . ButtonSelection . Title = "下拉标题"
// //下拉内容设置
var optionListMap [ ] commonus . OptionListStructes
var optionListCont commonus . OptionListStructes
optionListCont . Id = "btn_selection_id1"
optionListCont . Text = "100分"
optionListMap = append ( optionListMap , optionListCont )
optionListCont . Id = "btn_selection_id2"
optionListCont . Text = "110分"
optionListMap = append ( optionListMap , optionListCont )
sendMsg . TemplateCard . ButtonSelection . OptionList = optionListMap
sendMsg . TemplateCard . ButtonSelection . SelectedId = "btn_selection_id1"
//按钮列表,列表长度不超过6(必填)
var buttonMap [ ] commonus . ButtonListStruct
var buttonCont commonus . ButtonListStruct
buttonCont . Type = 0
buttonCont . Text = "批准"
buttonCont . Style = 1
buttonCont . Key = "button_key_1"
buttonMap = append ( buttonMap , buttonCont )
buttonCont . Type = 0
buttonCont . Text = "驳回"
buttonCont . Style = 3
buttonCont . Key = "button_key_2"
buttonMap = append ( buttonMap , buttonCont )
sendMsg . TemplateCard . ButtonList = buttonMap
response . Result ( 0 , sendMsg , "查询成功" , c )
callbakcMsg , isTrueCall , callBackCont := sendMsg . SendButtonMessage ( )
fmt . Printf ( "发送信息返回:%v-----------%v----------->%v\n" , string ( callbakcMsg ) , isTrueCall , callBackCont )
}
//模板卡片消息
//文本通知型
func ( s * ShiyanApi ) SendTextMessageAll ( c * gin . Context ) {
// var sendTextMsg commonus.TextNotice
var sendTextMsg sendmessage . TextNoticeTemplateMedium
// var sendTextMsg sendmessage.TextNoticeTemplateSimplify
sendTextMsg . Touser = "KaiXinGuo"
sendTextMsg . MsgType = "template_card"
appId , _ := strconv . ParseInt ( global . GVA_CONFIG . WorkWechatSchool . AgentId , 10 , 64 )
sendTextMsg . AgentId = appId
sendTextMsg . EnableIdTrans = 0
sendTextMsg . EnableDuplicateCheck = 0
sendTextMsg . DuplicateCheckInterval = 1800
sendTextMsg . TemplateCard . CardType = "text_notice"
//卡片来源样式信息,不需要来源样式可不填写(非必填)
sendTextMsg . TemplateCard . Source . IconUrl = "https://docu.hxgk.group/images/2022_01/3f7a1120a559e9bee3991b85eb34d103.png"
sendTextMsg . TemplateCard . Source . Desc = "知行学院"
sendTextMsg . TemplateCard . Source . DescColor = 2
// sendTextMsg.TemplateCard.ActionMenu.Desc = "是否继续关注"
// var actionList []commonus.ActionListStruct
// var actionCont commonus.ActionListStruct
// actionCont.Text = "接受推送"
// actionCont.Key = "A"
// actionList = append(actionList, actionCont)
// actionCont.Text = "不再推"
// actionCont.Key = "b"
// actionList = append(actionList, actionCont)
// sendTextMsg.TemplateCard.ActionMenu.ActionList = actionList
//任务id,同一个应用任务id不能重复,只能由数字、字母和“_-@”组成,最长128字节 (必填)
taskId := commonus . GetFileNumberEs ( )
sendTextMsg . TemplateCard . TaskId = strconv . FormatInt ( taskId , 10 )
sendTextMsg . TemplateCard . MainTitle . Title = "公务用车审批"
sendTextMsg . TemplateCard . MainTitle . Desc = "请你认真查询审批内容!" //标题辅助信息,建议不超过44个字,(支持id转译)
//引用文献样式
sendTextMsg . TemplateCard . QuoteArea . Type = 0
// sendTextMsg.TemplateCard.QuoteArea.Url = "http://www.hxgk.group"
sendTextMsg . TemplateCard . QuoteArea . Title = "用车编号"
sendTextMsg . TemplateCard . QuoteArea . QuoteText = "用车理由:\n工作需要 \n目的地:宁阳"
// sendTextMsg.TemplateCard.EmphasisContent.Title = "100"
// sendTextMsg.TemplateCard.EmphasisContent.DescStruct.Desc = "核心数据"
//二级普通文本,建议不超过160个字(非必填)
// sendTextMsg.TemplateCard.SubTitleText = "二级普通文本,下载企业微信还能抢红包!"
//二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6(非必填)
var htalConListStrMap [ ] sendmessage . HorizontalContentListType
var htalConListStrCon sendmessage . HorizontalContentListType
// htalConListStrCon.Type = 3
htalConListStrCon . KeyName = "申请人"
htalConListStrCon . Value = "秦东"
// htalConListStrCon.UserId = "KaiXinGuo"
htalConListStrMap = append ( htalConListStrMap , htalConListStrCon )
// htalConListStrCon.Type = 1
// htalConListStrCon.KeyName = "企业微信官网"
// htalConListStrCon.Value = "点击访问"
// htalConListStrCon.Url = "tel:15069130853"
// htalConListStrMap = append(htalConListStrMap, htalConListStrCon)
htalConListStrCon . Type = 3
htalConListStrCon . KeyName = "乘车人"
htalConListStrCon . Value = "秦东"
htalConListStrCon . UserId = "KaiXinGuo"
htalConListStrMap = append ( htalConListStrMap , htalConListStrCon )
sendTextMsg . TemplateCard . HorizontalContentList = htalConListStrMap
var jumpListStruct sendmessage . JumpListType
jumpListStruct . Type = 1
jumpListStruct . Title = "查看详情"
jumpListStruct . Url = "http://www.hxgk.group"
sendTextMsg . TemplateCard . JumpList = append ( sendTextMsg . TemplateCard . JumpList , jumpListStruct )
sendTextMsg . TemplateCard . CardAction . Type = 1
sendTextMsg . TemplateCard . CardAction . Url = "http://admin.hxgk.group"
callbakcMsg , isTrueCall , callBackCont := sendTextMsg . SendMessage ( "school" )
outData := commonus . MapOut ( )
outData [ "callbakcMsg" ] = string ( callbakcMsg )
outData [ "isTrueCall" ] = isTrueCall
outData [ "callBackCont" ] = callBackCont
response . Result ( 0 , outData , "查询成功" , c )
}
//图文展示型
func ( s * ShiyanApi ) SendImageMessageAll ( c * gin . Context ) {
// var sendTextMsg commonus.ImageTextTemplate
var sendTextMsg sendmessage . ImgTextTemplate
sendTextMsg . Touser = "KaiXinGuo"
sendTextMsg . MsgType = "template_card"
appId , _ := strconv . ParseInt ( global . GVA_CONFIG . WorkWechatSchool . AgentId , 10 , 64 )
sendTextMsg . AgentId = appId
sendTextMsg . EnableIdTrans = 0
sendTextMsg . EnableDuplicateCheck = 0
sendTextMsg . DuplicateCheckInterval = 1800
sendTextMsg . TemplateCard . CardType = "news_notice"
//卡片来源样式信息,不需要来源样式可不填写(非必填)
sendTextMsg . TemplateCard . Source . IconUrl = "https://docu.hxgk.group/images/2022_01/3f7a1120a559e9bee3991b85eb34d103.png"
sendTextMsg . TemplateCard . Source . Desc = "知行学院"
sendTextMsg . TemplateCard . Source . DescColor = 2
sendTextMsg . TemplateCard . ActionMenu . Desc = "是否继续关注"
var actionList [ ] sendmessage . ActionListType
var actionCont sendmessage . ActionListType
actionCont . Text = "接受推送"
actionCont . Key = "A"
actionList = append ( actionList , actionCont )
actionCont . Text = "不再推"
actionCont . Key = "b"
actionList = append ( actionList , actionCont )
sendTextMsg . TemplateCard . ActionMenu . ActionList = actionList
//任务id,同一个应用任务id不能重复,只能由数字、字母和“_-@”组成,最长128字节 (必填)
taskId := commonus . GetFileNumberEs ( )
sendTextMsg . TemplateCard . TaskId = strconv . FormatInt ( taskId , 10 )
sendTextMsg . TemplateCard . MainTitle . Title = "公务用车审批"
sendTextMsg . TemplateCard . MainTitle . Desc = "请你认真查询审批内容!" //标题辅助信息,建议不超过44个字,(支持id转译)
//引用文献样式
sendTextMsg . TemplateCard . QuoteArea . Type = 1
sendTextMsg . TemplateCard . QuoteArea . Url = "http://www.hxgk.group"
sendTextMsg . TemplateCard . QuoteArea . Title = "用车编号"
sendTextMsg . TemplateCard . QuoteArea . QuoteText = "用车理由:\n工作需要 \n目的地:宁阳"
sendTextMsg . TemplateCard . ImageTextArea . Type = 1
sendTextMsg . TemplateCard . ImageTextArea . Url = "http://www.baidu.com"
sendTextMsg . TemplateCard . ImageTextArea . Title = "企业微信的左图右文样式"
sendTextMsg . TemplateCard . ImageTextArea . Desc = "企业微信真好用呀真好用"
sendTextMsg . TemplateCard . ImageTextArea . ImageUrl = "https://img.iplaysoft.com/wp-content/uploads/2019/free-images/free_stock_photo_2x.jpg"
sendTextMsg . TemplateCard . CardImage . Url = "https://docu.hxgk.group/images/2022_01/3f7a1120a559e9bee3991b85eb34d103.png"
sendTextMsg . TemplateCard . CardImage . AspectRatio = 1.3
var verCont sendmessage . EmphasisContentType
verCont . Title = "惊喜红包等你来拿"
verCont . Desc = "下载企业微信还能抢红包!"
sendTextMsg . TemplateCard . VerticalContentList = append ( sendTextMsg . TemplateCard . VerticalContentList , verCont )
verCont . Title = "====>惊喜红包等你来拿"
verCont . Desc = "====>下载企业微信还能抢红包!"
sendTextMsg . TemplateCard . VerticalContentList = append ( sendTextMsg . TemplateCard . VerticalContentList , verCont )
var htalConListStrCon sendmessage . HorizontalContentListType
htalConListStrCon . Type = 3
htalConListStrCon . KeyName = "申请人"
htalConListStrCon . Value = "秦东"
htalConListStrCon . UserId = "KaiXinGuo"
sendTextMsg . TemplateCard . HorizontalContentList = append ( sendTextMsg . TemplateCard . HorizontalContentList , htalConListStrCon )
htalConListStrCon . Type = 1
htalConListStrCon . KeyName = "企业微信官网"
htalConListStrCon . Value = "点击访问"
htalConListStrCon . Url = "tel:15069130853"
sendTextMsg . TemplateCard . HorizontalContentList = append ( sendTextMsg . TemplateCard . HorizontalContentList , htalConListStrCon )
htalConListStrCon . Type = 3
htalConListStrCon . KeyName = "乘车人"
htalConListStrCon . Value = "秦东"
htalConListStrCon . UserId = "KaiXinGuo"
sendTextMsg . TemplateCard . HorizontalContentList = append ( sendTextMsg . TemplateCard . HorizontalContentList , htalConListStrCon )
var jumpListStruct sendmessage . JumpListType
jumpListStruct . Type = 1
jumpListStruct . Title = "知行学院官网"
jumpListStruct . Url = "http://www.hxgk.group"
sendTextMsg . TemplateCard . JumpList = append ( sendTextMsg . TemplateCard . JumpList , jumpListStruct )
jumpListStruct . Type = 1
jumpListStruct . Title = "知行学院官网====>"
jumpListStruct . Url = "http://www.hxgk.group"
sendTextMsg . TemplateCard . JumpList = append ( sendTextMsg . TemplateCard . JumpList , jumpListStruct )
sendTextMsg . TemplateCard . CardAction . Type = 1
sendTextMsg . TemplateCard . CardAction . Url = "http://admin.hxgk.group"
callbakcMsg , isTrueCall , callBackCont := sendTextMsg . SendMessage ( "school" )
outData := commonus . MapOut ( )
outData [ "callbakcMsg" ] = string ( callbakcMsg )
outData [ "isTrueCall" ] = isTrueCall
outData [ "callBackCont" ] = callBackCont
outData [ "sendTextMsg" ] = sendTextMsg
response . Result ( 0 , outData , "查询成功" , c )
}
//获取审批模板详情
func ( s * ShiyanApi ) GetEatilTemplate ( c * gin . Context ) {
var requestData sendmessage . TemplatedEtailType
err := c . ShouldBindJSON ( & requestData )
if err != nil {
response . Result ( 101 , err , "参数错误!请重新提交!" , c )
return
}
// msgbtye, isTrue, msg := requestData.GetTemplatedeTail("school")
msgbtyees , isTruees , msges := sendmessage . JsSdkSignAlgorithm ( "school" , 1 )
noncestr := commonus . GetFileNumberEs ( )
timestamp := time . Now ( ) . Unix ( )
url := "http://gin.admin.net/shiyan/geteatiltemplate"
jiamistr := fmt . Sprintf ( "jsapi_ticket=%v&noncestr=%v×tamp=%v&url=%v" , msges , noncestr , timestamp , url )
// jiamistr = "jsapi_ticket=sM4AOVdWfPE4DxkXGEs8VMCPGGVi4C3VM0P37wVUCFvkVAy_90u5h9nbSlYy3-Sl-HhTdfl2fzFy1AOcHKP7qg&noncestr=Wm3WZYTPz0wzccnW×tamp=1414587457&url=http://mp.weixin.qq.com?params=value"
jiamistrHa1 := commonus . Sha1Encryption ( jiamistr )
outData := commonus . MapOut ( )
// outData["msgbtye"] = msgbtye
// outData["isTrue"] = isTrue
// outData["msg"] = msg
outData [ "msgbtyees" ] = msgbtyees
outData [ "isTruees" ] = isTruees
outData [ "msges" ] = msges
outData [ "jiamistr" ] = jiamistr
outData [ "jiamistrHa1" ] = jiamistrHa1
response . Result ( 0 , outData , "查询成功" , c )
}
type timeDataType struct {
Time int64 ` json:"time" `
Type int ` json:"type" `
}
//时间日期实现
func ( s * ShiyanApi ) DateTime ( c * gin . Context ) {
var requestData timeDataType
err := c . ShouldBindJSON ( & requestData )
if err != nil {
}
if requestData . Time == 0 {
requestData . Time = time . Now ( ) . Unix ( )
}
if requestData . Type == 0 {
requestData . Type = 1
}
quer := commonus . ComputingTime ( requestData . Time , requestData . Type )
response . Result ( 0 , quer , "查询成功" , c )
}
//校正权重
func ( s * ShiyanApi ) CorrectionWeight ( c * gin . Context ) {
var ddwList assessmentmodel . DepartmentDimensionWeight
err := global . GVA_DB_Performanceappraisal . Find ( & ddwList )
if err != nil {
fmt . Println ( )
return
}
}
//考核方案去重
func ( s * ShiyanApi ) DeltDutyChongfu ( c * gin . Context ) {
var list [ ] assessmentmodel . QualitativeEvaluation
err := global . GVA_DB_Performanceappraisal . Find ( & list ) . Error
if err != nil {
response . Result ( 0 , err , "没有数据" , c )
return
}
for _ , v := range list {
DelteGroup ( v . Group , v . AcceptEvaluation , v . Dimension , v . Target , v . TargetSun , v . DetailedTarget , v . DepartmentId )
}
}
//执行去重删除操作
func DelteGroup ( group , depart , dime , target , suntar , detaid int64 , runDepart string ) {
var countId [ ] int64
err := global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . QualitativeEvaluation { } ) . Select ( "qe_id" ) . Where ( "`qe_group` = ? AND `qe_accept_evaluation` = ? AND `qe_dimension` = ? AND `qe_target` = ? AND `qe_target_sun` = ? AND `qe_detailed_target` = ? AND `qe_department_id` = ?" , group , depart , dime , target , suntar , detaid , runDepart ) . Find ( & countId ) . Error
if err != nil {
return
}
if len ( countId ) < 2 {
return
}
for i , v := range countId {
if i != 0 {
fmt . Printf ( "%v\n" , v )
global . GVA_DB_Performanceappraisal . Where ( "`qe_id` = ?" , v ) . Delete ( & assessmentmodel . QualitativeEvaluation { } )
}
}
}
//文本实验 textcomparison
func ( s * ShiyanApi ) TextShiyan ( c * gin . Context ) {
participle := textcomparison . NewGoJieba ( )
//去除文本Html标签
srcStr := textcomparison . RemoveHtml ( "关于区块链和数字货币的关系,很多人或多或少都存在疑惑。简单来说,区块链是比特币的底层运用,而比特币只是区块链的一个小应用而已。" +
"数字货币即虚拟货币,最早的数字货币诞生于2009年,其发明者中本聪为了应对经济危机对于实体货币经济的冲击。比特币是最早的数字货币,后来出现了以太币、火币以及莱特币等虚拟货币,这些虚拟货币是不能用来交易的。" +
"狭义来讲,区块链是一种按照时间顺序将数据区块以顺序相连的方式组合成的一种链式数据结构, 并以密码学方式保证的不可篡改和不可伪造的分布式账本。" +
"广义来讲,区块链技术是利用块链式数据结构来验证与存储数据、利用分布式节点共识算法来生成和更新数据、利用密码学的方式保证数据传输和访问的安全、利用由自动化脚本代码组成的智能合约来编程和操作数据的一种全新的分布式基础架构与计算方式。" )
dstStr := textcomparison . RemoveHtml ( "区块链技术为我们的信息防伪与数据追踪提供了革新手段。区块链中的数据区块顺序相连构成了一个不可篡改的数据链条,时间戳为所有的交易行为贴上了一套不讲课伪造的真是标签,这对于人们在现实生活中打击假冒伪劣产品大有裨益; " +
"市场分析指出,整体而言,区块链技术目前在十大金融领域显示出应用前景,分别是资产证券化、保险、供应链金融、场外市场、资产托管、大宗商品交易、风险信息共享机制、贸易融资、银团贷款、股权交易交割。" +
"这些金融场景有三大共性:参与节点多、验真成本高、交易流程长,而区块链的分布式记账、不可篡改、内置合约等特性可以为这些金融业务中的痛点提供解决方案。" +
"传统的工业互联网模式是由一个中心化的机构收集和管理所有的数据信息,容易产生因设备生命周期和安全等方面的缺陷引起的数据丢失、篡改等问题。区块链技术可以在无需任何信任单个节点的同时构建整个网络的信任共识,从而很好的解决目前工业互联网技术领域的一些缺陷,让物与物之间能够实现更好的连接." )
srcWordsWeight := participle . C . ExtractWithWeight ( srcStr , 30 )
dstWordsWeight := participle . C . ExtractWithWeight ( dstStr , 30 )
fmt . Printf ( "srcWordsWeight: %v\n" , srcWordsWeight )
fmt . Printf ( "dstWordsWeight: %v\n" , dstWordsWeight )
srcWords := make ( [ ] textcomparison . WordWeight , len ( srcWordsWeight ) )
dstWords := make ( [ ] textcomparison . WordWeight , len ( dstWordsWeight ) )
for i , ww := range srcWordsWeight {
word := textcomparison . WordWeight { Word : ww . Word , Weight : ww . Weight }
srcWords [ i ] = word
}
for i , ww := range dstWordsWeight {
word := textcomparison . WordWeight { Word : ww . Word , Weight : ww . Weight }
dstWords [ i ] = word
}
fmt . Printf ( "srcWords:%v\n" , srcWords )
fmt . Printf ( "dstWords:%v\n" , dstWords )
distance , err := textcomparison . SimHashSimilar ( srcWords , dstWords )
if err != nil {
// t.Errorf("failed: %v", err.Error())
fmt . Printf ( "failed:%v\n" , c . Errors )
}
fmt . Printf ( "SimHashSimilar distance:%v\n" , distance )
// t.Logf("SimHashSimilar distance: %v", distance)
}
type jimishiyan struct {
KeyStr string ` json:"key" `
Number string ` json:"number" `
Password string ` json:"password" `
}
//加密实验
func ( s * ShiyanApi ) JiaMi ( c * gin . Context ) {
var user jimishiyan
_ = c . ShouldBindJSON ( & user )
userAgent := "250"
var md5JiaMi commonus . Md5Encryption
md5JiaMi . Md5EncryptionInit ( userAgent )
md5Token := md5JiaMi . Md5EncryptionAlgorithm ( )
// response.Result(101, md5Token, "加密实验!", c)
sha1Str := user . KeyStr + user . Number + user . Password + md5Token
sha1Token := commonus . Sha1Encryption ( sha1Str )
outMap := commonus . MapOut ( )
outMap [ "md5Token" ] = md5Token
outMap [ "sha1Token" ] = sha1Token
response . Result ( 101 , outMap , "sha1Token加密实验!" , c )
}
//处理子栏目归属
func ( s * ShiyanApi ) SunTar ( c * gin . Context ) {
var sunList [ ] assessmentmodel . QualitativeTarget
err := global . GVA_DB_Performanceappraisal . Find ( & sunList ) . Error
if err != nil {
return
}
for _ , v := range sunList {
departStr := GetGuishuDepart ( v . ParentId )
eiteCont := commonus . MapOut ( )
eiteCont [ "q_depart" ] = departStr
eiteCont [ "q_time" ] = time . Now ( ) . Unix ( )
global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . QualitativeTarget { } ) . Where ( "`q_id` = ?" , v . Id ) . Updates ( eiteCont )
fmt . Printf ( "%v\n" , v . Id )
}
}
//获取指标归属分厂
func GetGuishuDepart ( targetId int64 ) ( departStr string ) {
var targetCont assessmentmodel . EvaluationTarget
err := global . GVA_DB_Performanceappraisal . Where ( "et_id = ?" , targetId ) . First ( & targetCont ) . Error
if err == nil {
departStr = targetCont . RelevantDepartments
}
return
}