You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1061 lines
32 KiB
1061 lines
32 KiB
package workflow
|
|
|
|
import (
|
|
"appPlatform/api/version1/customerform"
|
|
"appPlatform/api/version1/taskplatform/taskmanagement"
|
|
"appPlatform/api/version1/workWechat"
|
|
"appPlatform/models/modelAppPlatform"
|
|
"appPlatform/models/modelshr"
|
|
"appPlatform/overall"
|
|
"appPlatform/overall/publicmethod"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// 入口函数
|
|
func (a *ApiMethod) Index(c *gin.Context) {
|
|
outputCont := publicmethod.MapOut[string]()
|
|
outputCont["index"] = "工作流入口"
|
|
publicmethod.Result(0, outputCont, c)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-12 16:46:21
|
|
@ 功能: 执行工作流
|
|
@ 参数
|
|
|
|
#userKey //当前执行人
|
|
#AgreeToRefuse //同意或者驳回
|
|
#runCont //执行意见
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (r *RunWorkFlow) GainRunNodeNew(userKey string, runSetup, AgreeToRefuse int, runCont string) (currentStep, nextStep int) {
|
|
|
|
if len(r.FlowList) > 0 {
|
|
userkInt, _ := strconv.ParseInt(userKey, 10, 64) //将字符型转换成64位整型
|
|
for i := 0; i < r.TotalSteps; i++ { //循环比对获取出当前执行节点
|
|
if r.FlowList[i].Step == runSetup { //获取当前执行节点内容
|
|
fmt.Printf("执行工作流当前节点-1-r.FlowList[i].Step:%v\n---1--》r.Step:%v\n", r.FlowList[i].Step, runSetup)
|
|
r.FlowList[i].Status = AgreeToRefuse //节点状态
|
|
currentStep, nextStep = r.TallyPaceStepes(userKey, runSetup, r.FlowList[i])
|
|
fmt.Printf("执行工作流当前节点-2-currentStep:%v\n--2---》nextStep:%v\n", currentStep, nextStep)
|
|
//获取参与人几当前节点操作记录
|
|
operatorAry, nodeUser := CopeParticipantEnforcerLog(userKey, r.RunUid, AgreeToRefuse, r.FlowList[i].Operator, runCont)
|
|
r.FlowList[i].Operator = operatorAry //节点操作记录
|
|
r.Participant = append(r.Participant, nodeUser...) //参与人
|
|
// panic("中断一下")
|
|
switch r.FlowList[i].Types { //0:发起节点;1:审批节点;2:抄送;3:执行节点
|
|
case 0:
|
|
|
|
taskmanagement.FlowRunLog(r.Uuid, userkInt, AgreeToRefuse, r.FlowList[i].NodeKey, runCont, "")
|
|
|
|
//判断下一个节点是否满足自动审批条件
|
|
if r.ToNextNodeRunOrClose(userKey, nextStep) {
|
|
// r.Step = r.NextStep
|
|
fmt.Printf("执行下一节点--r.Step:%v\n----->r.NextStep:%v\n", r.Step, nextStep)
|
|
currentStep, nextStep = r.GainRunNodeNew(userKey, nextStep, AgreeToRefuse, "自动审批")
|
|
} else {
|
|
//判断是否向下一个节点的人发送信息
|
|
r.SendWecharMsgTopct(userKey, nextStep)
|
|
}
|
|
r.Step = currentStep
|
|
r.NextStep = nextStep
|
|
return
|
|
case 1, 3:
|
|
|
|
taskmanagement.FlowRunLog(r.Uuid, userkInt, AgreeToRefuse, r.FlowList[i].NodeKey, runCont, "")
|
|
fmt.Printf("执行下一节点-34324234-currentStep:%v\n----->nextStep:%v\n", currentStep, nextStep)
|
|
//判断下一个节点是否满足自动审批条件
|
|
if r.ToNextNodeRunOrClose(userKey, nextStep) {
|
|
// r.Step = r.NextStep
|
|
fmt.Printf("执行下一节点-34324234-r.Step:%v\n----->r.NextStep:%v\n", r.Step, r.NextStep)
|
|
currentStep, nextStep = r.GainRunNodeNew(userKey, nextStep, AgreeToRefuse, "自动审批")
|
|
} else {
|
|
//判断是否向下一个节点的人发送信息
|
|
r.SendWecharMsgTopct(userKey, nextStep)
|
|
}
|
|
r.Step = currentStep
|
|
r.NextStep = nextStep
|
|
return
|
|
case 2:
|
|
r.SendWecharMsgTopct("", r.NextStep)
|
|
if r.NextStep > 0 {
|
|
currentStep, nextStep = r.GainRunNodeNew(userKey, nextStep, AgreeToRefuse, "自动审批")
|
|
}
|
|
r.Step = currentStep
|
|
r.NextStep = nextStep
|
|
return
|
|
default:
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-14 13:37:04
|
|
@ 功能: 获取下一节点审批人
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#userKeyAry 节点审批人
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (r *RunWorkFlow) NextNodePeople() (userKeyAry []string) {
|
|
if r.NextStep > 0 {
|
|
for _, v := range r.FlowList {
|
|
if r.NextStep == v.Step {
|
|
for _, ov := range v.Operator {
|
|
if ov.Id != "" {
|
|
userKeyAry = append(userKeyAry, ov.Id)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-13 13:38:52
|
|
@ 功能: 向下一个节点人员发送消息
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (r *RunWorkFlow) SendWecharMsgTopct(userKey string, nextStep int) {
|
|
fmt.Printf("发射消息---->userKey: %v\n nextStep: %v\n", userKey, nextStep)
|
|
if nextStep > 0 {
|
|
var sendUserAry []string
|
|
nodeTitle := ""
|
|
for _, v := range r.FlowList {
|
|
if nextStep == v.Step {
|
|
nodeTitle = v.NodeName
|
|
if v.ExamineMode != 1 {
|
|
for _, ov := range v.Operator {
|
|
if userKey != "" {
|
|
if ov.Id != userKey && ov.Wechat != "" {
|
|
sendUserAry = append(sendUserAry, ov.Wechat)
|
|
}
|
|
} else {
|
|
if ov.Wechat != "" {
|
|
sendUserAry = append(sendUserAry, ov.Wechat)
|
|
}
|
|
}
|
|
|
|
}
|
|
} else {
|
|
uuidStr := strconv.FormatInt(r.Uuid, 10)
|
|
for _, ov := range v.Operator {
|
|
if len(ov.LogList) > 0 {
|
|
for _, lv := range ov.LogList {
|
|
if lv.UID != uuidStr {
|
|
if userKey != "" {
|
|
if ov.Id != userKey && ov.Wechat != "" {
|
|
sendUserAry = append(sendUserAry, ov.Wechat)
|
|
}
|
|
} else {
|
|
if ov.Wechat != "" {
|
|
sendUserAry = append(sendUserAry, ov.Wechat)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
if ov.Wechat != "" {
|
|
sendUserAry = append(sendUserAry, ov.Wechat)
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
fmt.Printf("发射消息--2-->sendUserAry: %v\n nextStep: %v\n", sendUserAry, nextStep)
|
|
if len(sendUserAry) > 0 {
|
|
taskId := publicmethod.GetUUid(1)
|
|
tableName, qouteTitle, contList := r.GainTitleAndCreate()
|
|
var sendMsg workWechat.SendMessage
|
|
sendMsg.Touser = strings.Join(sendUserAry, "|")
|
|
sendMsg.TemplateCard.Source.Desc = nodeTitle
|
|
sendMsg.TemplateCard.MainTitle.Title = tableName
|
|
sendMsg.TemplateCard.TaskId = strconv.FormatInt(taskId, 10)
|
|
sendMsg.TemplateCard.QuoteArea.Quote_text = qouteTitle
|
|
sendMsg.TemplateCard.HorizontalContentList = append(sendMsg.TemplateCard.HorizontalContentList, contList...)
|
|
var jumpInfo workWechat.Jump_list
|
|
jumpInfo.Title = "前往处理"
|
|
jumpInfo.Url = "wap.gyhlw.group"
|
|
jumpInfo.Type = 1
|
|
sendMsg.TemplateCard.JumpList = append(sendMsg.TemplateCard.JumpList, jumpInfo)
|
|
sendMsg.TemplateCard.CardAction.Type = 1
|
|
sendMsg.TemplateCard.CardAction.Url = "wap.gyhlw.group"
|
|
sendMsg.SendMsg("stzl", 1)
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-13 15:38:55
|
|
@ 功能: 获取指定标题和申请人相关信息
|
|
|
|
#tableName 一级标题
|
|
#qouteTitle 引用文件
|
|
#peopleInfoAry 发起人
|
|
*/
|
|
func (r *RunWorkFlow) GainTitleAndCreate() (tableName, qouteTitle string, peopleInfoAry []workWechat.Horizontal_content_list) {
|
|
var tableInFor modelAppPlatform.CustomerForm
|
|
tableInFor.GetCont(map[string]interface{}{"`signCode`": r.SendWecharMsg.TableKey}, "`name`", "`tablename`", "`listjson`")
|
|
tableName = tableInFor.Name
|
|
qouteTitle = tableInFor.Name
|
|
var ceraterInfo modelshr.PersonArchives
|
|
ceraterInfo.GetCont(map[string]interface{}{"`key`": r.SendWecharMsg.Creater}, "`name`", "`number`", "`wechat`", "`work_wechat`")
|
|
var peopleInfo workWechat.Horizontal_content_list
|
|
peopleInfo.Keyname = "申请人"
|
|
peopleInfo.Value = fmt.Sprintf("%v(%v)", ceraterInfo.Name, ceraterInfo.Number)
|
|
if ceraterInfo.WorkWechat != "" {
|
|
peopleInfo.Type = 3
|
|
peopleInfo.UserId = ceraterInfo.WorkWechat
|
|
} else if ceraterInfo.Wechat != "" {
|
|
peopleInfo.Type = 3
|
|
peopleInfo.UserId = ceraterInfo.Wechat
|
|
}
|
|
peopleInfoAry = append(peopleInfoAry, peopleInfo)
|
|
if tableInFor.ListJson != "" {
|
|
var listInfo customerform.ListPageFields
|
|
json.Unmarshal([]byte(tableInFor.ListJson), &listInfo)
|
|
if listView, isOk := listInfo.View["list"]; isOk {
|
|
if len(listView.Form.Title) > 0 {
|
|
tableForm := publicmethod.MapOut[string]()
|
|
overall.CONSTANT_DB_CustomerForm.Table(tableInFor.TableNames).Where("`masters_key` = ?", r.SendWecharMsg.MastersKey).Find(&tableForm)
|
|
var qouteTitleAry []string
|
|
// fmt.Printf("list表单:%v\n\n\n%v\n\n\n", listView.Form.Title, tableForm)
|
|
for _, v := range listView.Form.Title {
|
|
if formVal, isOk := tableForm[v]; isOk {
|
|
// fmt.Printf("list表单-----v----->:%v\n\n\n%v\n\n\n", formVal, publicmethod.TypeToInterface(formVal))
|
|
qouteTitleAry = append(qouteTitleAry, publicmethod.TypeToInterface(formVal))
|
|
}
|
|
}
|
|
if len(qouteTitleAry) > 0 {
|
|
qouteTitle = strings.Join(qouteTitleAry, "-")
|
|
}
|
|
}
|
|
} else if dateView, isOk := listInfo.View["date"]; isOk {
|
|
if len(dateView.Form.Title) > 0 {
|
|
tableForm := publicmethod.MapOut[string]()
|
|
overall.CONSTANT_DB_CustomerForm.Table(tableInFor.TableNames).Where("`masters_key` = ?", r.SendWecharMsg.MastersKey).Find(&tableForm)
|
|
var qouteTitleAry []string
|
|
// fmt.Printf("date表单:%v\n\n\n%v\n\n\n", dateView.Form.Title, tableForm)
|
|
for _, v := range dateView.Form.Title {
|
|
if formVal, isOk := tableForm[v]; isOk {
|
|
qouteTitleAry = append(qouteTitleAry, publicmethod.TypeToInterface(formVal))
|
|
}
|
|
}
|
|
if len(qouteTitleAry) > 0 {
|
|
qouteTitle = strings.Join(qouteTitleAry, "-")
|
|
}
|
|
}
|
|
} else if timeView, isOk := listInfo.View["time"]; isOk {
|
|
if len(timeView.Form.Title) > 0 {
|
|
tableForm := publicmethod.MapOut[string]()
|
|
overall.CONSTANT_DB_CustomerForm.Table(tableInFor.TableNames).Where("`masters_key` = ?", r.SendWecharMsg.MastersKey).Find(&tableForm)
|
|
var qouteTitleAry []string
|
|
// fmt.Printf("time表单:%v\n\n\n%v\n\n\n", timeView.Form.Title, tableForm)
|
|
for _, v := range timeView.Form.Title {
|
|
if formVal, isOk := tableForm[v]; isOk {
|
|
qouteTitleAry = append(qouteTitleAry, publicmethod.TypeToInterface(formVal))
|
|
}
|
|
}
|
|
if len(qouteTitleAry) > 0 {
|
|
qouteTitle = strings.Join(qouteTitleAry, "-")
|
|
}
|
|
}
|
|
} else if ganttView, isOk := listInfo.View["gantt"]; isOk {
|
|
if len(ganttView.Form.Title) > 0 {
|
|
tableForm := publicmethod.MapOut[string]()
|
|
overall.CONSTANT_DB_CustomerForm.Table(tableInFor.TableNames).Where("`masters_key` = ?", r.SendWecharMsg.MastersKey).Find(&tableForm)
|
|
var qouteTitleAry []string
|
|
// fmt.Printf("gantt表单:%v\n\n\n%v\n\n\n", ganttView.Form.Title, tableForm)
|
|
for _, v := range ganttView.Form.Title {
|
|
if formVal, isOk := tableForm[v]; isOk {
|
|
qouteTitleAry = append(qouteTitleAry, publicmethod.TypeToInterface(formVal))
|
|
}
|
|
}
|
|
if len(qouteTitleAry) > 0 {
|
|
qouteTitle = strings.Join(qouteTitleAry, "-")
|
|
}
|
|
}
|
|
} else if mapView, isOk := listInfo.View["map"]; isOk {
|
|
if len(mapView.Form.Title) > 0 {
|
|
tableForm := publicmethod.MapOut[string]()
|
|
overall.CONSTANT_DB_CustomerForm.Table(tableInFor.TableNames).Where("`masters_key` = ?", r.SendWecharMsg.MastersKey).Find(&tableForm)
|
|
var qouteTitleAry []string
|
|
// fmt.Printf("map表单:%v\n\n\n%v\n\n\n", mapView.Form.Title, tableForm)
|
|
for _, v := range mapView.Form.Title {
|
|
if formVal, isOk := tableForm[v]; isOk {
|
|
qouteTitleAry = append(qouteTitleAry, publicmethod.TypeToInterface(formVal))
|
|
}
|
|
}
|
|
if len(qouteTitleAry) > 0 {
|
|
qouteTitle = strings.Join(qouteTitleAry, "-")
|
|
}
|
|
}
|
|
} else if cardView, isOk := listInfo.View["card"]; isOk {
|
|
if len(cardView.Form.Title) > 0 {
|
|
tableForm := publicmethod.MapOut[string]()
|
|
overall.CONSTANT_DB_CustomerForm.Table(tableInFor.TableNames).Where("`masters_key` = ?", r.SendWecharMsg.MastersKey).Find(&tableForm)
|
|
var qouteTitleAry []string
|
|
// fmt.Printf("card表单:%v\n\n\n%v\n\n\n", cardView.Form.Title, tableForm)
|
|
for _, v := range cardView.Form.Title {
|
|
if formVal, isOk := tableForm[v]; isOk {
|
|
qouteTitleAry = append(qouteTitleAry, publicmethod.TypeToInterface(formVal))
|
|
}
|
|
}
|
|
if len(qouteTitleAry) > 0 {
|
|
qouteTitle = strings.Join(qouteTitleAry, "-")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// fmt.Printf("qouteTitle表单:%v\n\n\n", qouteTitle)
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-13 11:26:32
|
|
@ 功能: 判断下一个节点是否继续执行
|
|
@ 参数
|
|
|
|
#userKey 当前执行人
|
|
#nextStep 下一个节点
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (r *RunWorkFlow) ToNextNodeRunOrClose(userKey string, nextStep int) (isRun bool) {
|
|
isRun = false
|
|
if nextStep == 0 {
|
|
return isRun
|
|
}
|
|
runIdStr := strconv.FormatInt(r.RunUid, 10)
|
|
fmt.Printf("判断下一个节点是否继续执行:userKey:%v------->nextStep:%v\n", userKey, nextStep)
|
|
for _, v := range r.FlowList {
|
|
if nextStep == v.Step {
|
|
fmt.Printf("判断下一个节点是否继续执行:v.Step:%v----1--->v.Types:%v\n", v.Step, v.Types)
|
|
switch v.Types {
|
|
case 1, 3:
|
|
isMyTrue := false
|
|
optUserCount := len(v.Operator)
|
|
allPick := 0
|
|
for _, ov := range v.Operator {
|
|
if ov.Id == userKey {
|
|
isMyTrue = true
|
|
}
|
|
for _, ol := range ov.LogList {
|
|
if runIdStr == ol.UID {
|
|
allPick++
|
|
}
|
|
}
|
|
}
|
|
if isMyTrue {
|
|
if optUserCount > 1 {
|
|
switch v.ExamineMode {
|
|
case 1, 2:
|
|
if allPick == 0 {
|
|
isRun = true
|
|
} else {
|
|
if allPick == optUserCount {
|
|
isRun = true
|
|
} else {
|
|
isRun = false
|
|
}
|
|
}
|
|
|
|
default:
|
|
isRun = true
|
|
}
|
|
} else {
|
|
if optUserCount == 1 {
|
|
isRun = true
|
|
} else {
|
|
isRun = false
|
|
}
|
|
}
|
|
// isRun = true
|
|
}
|
|
fmt.Printf("判断下一个节点是否继续执行:isMyTrue:%v----3--->isRun:%v\n----3--->optUserCount:%v\n----3--->v.ExamineMode:%v\n", isMyTrue, isRun, optUserCount, v.ExamineMode)
|
|
case 2:
|
|
isRun = true
|
|
default:
|
|
isRun = false
|
|
}
|
|
}
|
|
}
|
|
return isRun
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-17 08:42:53
|
|
@ 功能: 判断是否执行下一步(副本)
|
|
@ 参数
|
|
|
|
#runSetup 当前要执行的步骤
|
|
#nodeInfo 当前节点状态
|
|
|
|
@ 返回值
|
|
|
|
#currentStep 计算后的当前节点
|
|
#nextStep 计算后的下一个节点
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (r *RunWorkFlow) TallyPaceStepes(userKey string, runSetup int, nodeInfo RunFlow) (currentStep, nextStep int) {
|
|
runIdStr := strconv.FormatInt(r.RunUid, 10)
|
|
nodeInfoJson, _ := json.Marshal(nodeInfo)
|
|
fmt.Printf("计步器runIdStr:%v---1-----runSetup:%v--------nodeInfo.Types:%v----------->nodeInfoJson:%v\n", runIdStr, runSetup, nodeInfo.Types, string(nodeInfoJson))
|
|
if nodeInfo.Types == 2 {
|
|
currentStep = runSetup
|
|
nextStep = runSetup + 1
|
|
return
|
|
} else {
|
|
|
|
optUserCount := len(nodeInfo.Operator) //此节点有几个人审批
|
|
jiBuQi := 0
|
|
for _, v := range nodeInfo.Operator {
|
|
for _, l := range v.LogList {
|
|
if l.UID == runIdStr {
|
|
jiBuQi++
|
|
}
|
|
}
|
|
// if v.Id == userKey {
|
|
// jiBuQi++
|
|
// }
|
|
}
|
|
fmt.Printf("计步器 optUserCount:%v---2-----runSetup:%v-----jiBuQi:%v\n", optUserCount, runSetup, jiBuQi)
|
|
if jiBuQi > 0 { //存在有人审批的情况
|
|
if jiBuQi >= optUserCount { //当前节点所有人已经审批则进入下一个节点
|
|
currentStep = runSetup
|
|
if currentStep >= r.TotalSteps {
|
|
currentStep = r.TotalSteps
|
|
nextStep = 0
|
|
} else {
|
|
nextStep = currentStep + 1
|
|
if nextStep >= r.TotalSteps {
|
|
nextStep = r.TotalSteps
|
|
}
|
|
}
|
|
} else { //有未参与审批的人员,根据节点属性进行判断
|
|
fmt.Printf("计步器 nodeInfo.ExamineMode :%v---3-----runSetup:%v-----r.TotalSteps:%v\n", nodeInfo.ExamineMode, runSetup, r.TotalSteps)
|
|
switch nodeInfo.ExamineMode { //多人审批时采用的审批方式。0:无操作 1依次审批 2会签 3:或签
|
|
case 1, 2:
|
|
if runSetup >= r.TotalSteps { //当前步数大于等于总步数时
|
|
currentStep = r.TotalSteps
|
|
nextStep = 0
|
|
} else {
|
|
currentStep = runSetup - 1
|
|
if currentStep <= 0 {
|
|
currentStep = 1
|
|
}
|
|
if currentStep >= r.TotalSteps {
|
|
currentStep = r.TotalSteps
|
|
nextStep = 0
|
|
} else {
|
|
nextStep = currentStep + 1
|
|
if nextStep >= r.TotalSteps {
|
|
nextStep = r.TotalSteps
|
|
}
|
|
}
|
|
}
|
|
case 3:
|
|
if runSetup >= r.TotalSteps { //当前步数大于等于总步数时
|
|
currentStep = r.TotalSteps
|
|
nextStep = 0
|
|
} else {
|
|
currentStep = runSetup
|
|
if currentStep >= r.TotalSteps {
|
|
currentStep = r.TotalSteps
|
|
nextStep = 0
|
|
} else {
|
|
nextStep = currentStep + 1
|
|
if nextStep >= r.TotalSteps {
|
|
nextStep = r.TotalSteps
|
|
}
|
|
}
|
|
}
|
|
default:
|
|
}
|
|
}
|
|
|
|
} else { //此节点没有人审批
|
|
fmt.Printf("计步器 r.TotalSteps:%v---4-----runSetup:%v-----jiBuQi:%v\n", r.TotalSteps, runSetup, jiBuQi)
|
|
if optUserCount > 1 {
|
|
currentStep = runSetup - 1
|
|
if currentStep >= r.TotalSteps {
|
|
currentStep = r.TotalSteps
|
|
nextStep = 0
|
|
} else {
|
|
nextStep = currentStep + 1
|
|
if nextStep >= r.TotalSteps {
|
|
nextStep = r.TotalSteps
|
|
}
|
|
}
|
|
} else {
|
|
currentStep = runSetup
|
|
if currentStep >= r.TotalSteps {
|
|
currentStep = r.TotalSteps
|
|
nextStep = 0
|
|
} else {
|
|
nextStep = currentStep + 1
|
|
if nextStep >= r.TotalSteps {
|
|
nextStep = r.TotalSteps
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-13 10:27:15
|
|
@ 功能: 判断是否执行下一步
|
|
#nodeInfo 当前执行节点内容
|
|
*/
|
|
func (r *RunWorkFlow) TallyPaceStep(runSetup int, nodeInfo RunFlow) (currentStep, nextStep int) {
|
|
nodeInfoJson, _ := json.Marshal(nodeInfo)
|
|
fmt.Printf("判断是否执行下一步runSetup:%v=============>r.TotalSteps:%v=============>nodeInfo.ExamineMode:%v=============>%v\n", runSetup, r.TotalSteps, nodeInfo.ExamineMode, string(nodeInfoJson))
|
|
switch nodeInfo.ExamineMode { //多人审批时采用的审批方式。0:无操作 1依次审批 2会签 3:或签
|
|
case 1, 2:
|
|
runIdStr := strconv.FormatInt(r.RunUid, 10)
|
|
optUserCount := len(nodeInfo.Operator)
|
|
jiBuQi := 0
|
|
for _, v := range nodeInfo.Operator {
|
|
for _, l := range v.LogList {
|
|
if l.UID == runIdStr {
|
|
jiBuQi++
|
|
}
|
|
}
|
|
}
|
|
fmt.Printf("计步器runIdStr:%v---1-----currentStep:%v--------optUserCount:%v----------->jiBuQi:%v\n", runIdStr, currentStep, optUserCount, jiBuQi)
|
|
if jiBuQi >= optUserCount { //会签人员全部签署
|
|
if runSetup >= r.TotalSteps { //当前步数大于等于总步数时
|
|
currentStep = r.TotalSteps
|
|
nextStep = 0
|
|
} else {
|
|
currentStep = runSetup
|
|
if currentStep >= r.TotalSteps {
|
|
currentStep = r.TotalSteps
|
|
nextStep = 0
|
|
} else {
|
|
nextStep = currentStep + 1
|
|
if nextStep >= r.TotalSteps {
|
|
nextStep = r.TotalSteps
|
|
}
|
|
}
|
|
}
|
|
} else { //会签中有人未签署
|
|
if runSetup >= r.TotalSteps { //当前步数大于等于总步数时
|
|
currentStep = r.TotalSteps
|
|
nextStep = 0
|
|
} else {
|
|
currentStep = runSetup
|
|
if currentStep >= r.TotalSteps {
|
|
currentStep = r.TotalSteps
|
|
nextStep = 0
|
|
} else {
|
|
nextStep = currentStep + 1
|
|
if nextStep >= r.TotalSteps {
|
|
nextStep = r.TotalSteps
|
|
}
|
|
}
|
|
}
|
|
}
|
|
case 3:
|
|
|
|
runIdStr := strconv.FormatInt(r.RunUid, 10)
|
|
jiBuQi := 0
|
|
for _, v := range nodeInfo.Operator {
|
|
for _, l := range v.LogList {
|
|
if l.UID == runIdStr {
|
|
jiBuQi++
|
|
}
|
|
}
|
|
}
|
|
|
|
fmt.Printf("计步器runIdStr:%v----2----currentStep:%v--------runSetup:%v----------->jiBuQi:%v\n", runIdStr, currentStep, runSetup, jiBuQi)
|
|
|
|
if jiBuQi > 0 { //或签中已有一人签署
|
|
if runSetup >= r.TotalSteps { //当前步数大于等于总步数时
|
|
currentStep = r.TotalSteps
|
|
nextStep = 0
|
|
} else {
|
|
currentStep = runSetup
|
|
if currentStep >= r.TotalSteps {
|
|
currentStep = r.TotalSteps
|
|
nextStep = 0
|
|
} else {
|
|
nextStep = currentStep + 1
|
|
if nextStep >= r.TotalSteps {
|
|
nextStep = r.TotalSteps
|
|
}
|
|
}
|
|
}
|
|
} else { //没有任何人签署
|
|
if runSetup >= r.TotalSteps { //当前步数大于等于总步数时
|
|
currentStep = r.TotalSteps
|
|
nextStep = 0
|
|
} else {
|
|
currentStep = runSetup
|
|
if currentStep >= r.TotalSteps {
|
|
currentStep = r.TotalSteps
|
|
nextStep = 0
|
|
} else {
|
|
nextStep = currentStep + 1
|
|
if nextStep >= r.TotalSteps {
|
|
nextStep = r.TotalSteps
|
|
}
|
|
}
|
|
}
|
|
}
|
|
default:
|
|
|
|
if runSetup >= r.TotalSteps { //当前步数大于等于总步数时
|
|
currentStep = r.TotalSteps
|
|
nextStep = 0
|
|
} else {
|
|
currentStep = runSetup
|
|
if currentStep >= r.TotalSteps {
|
|
currentStep = r.TotalSteps
|
|
nextStep = 0
|
|
} else {
|
|
nextStep = currentStep + 1
|
|
if nextStep >= r.TotalSteps {
|
|
nextStep = r.TotalSteps
|
|
}
|
|
}
|
|
}
|
|
fmt.Printf("计步器r.TotalSteps:%v----3----currentStep:%v--------runSetup:%v----------->jiBuQi:%v\n", r.TotalSteps, currentStep, runSetup, currentStep)
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-13 08:20:36
|
|
@ 功能: 处理执行节点参与人和执行人操作记录
|
|
@ 参数
|
|
|
|
#userKey 操作人
|
|
#runUid 执行Uid
|
|
#AgreeToRefuse 同意或者驳回
|
|
#operator 当前节点操作人
|
|
#suggest 审批意见
|
|
|
|
@ 返回值
|
|
|
|
#OperatorAry 节点操作记录
|
|
#nodeUser 节点参与人
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func CopeParticipantEnforcerLog(userKey string, runUid int64, AgreeToRefuse int, operator []OperatorList, suggest string) (OperatorAry []OperatorList, nodeUser []string) {
|
|
var logInfo LogList
|
|
logInfo.State = AgreeToRefuse //状态 1、未操作;2、通过;3、驳回
|
|
logInfo.TimeVal = publicmethod.UnixTimeToDay(time.Now().Unix(), 1) //操作时间
|
|
logInfo.UID = strconv.FormatInt(runUid, 10)
|
|
logInfo.Cause = suggest
|
|
isNewAdd := true //判断当前执行人是否再执行列表中
|
|
for _, v := range operator {
|
|
nodeUser = append(nodeUser, v.Id)
|
|
if v.Id == userKey {
|
|
v.LogList = append(v.LogList, logInfo)
|
|
isNewAdd = false
|
|
}
|
|
OperatorAry = append(OperatorAry, v)
|
|
}
|
|
if isNewAdd { //如果此人没有在此节点中,则增加此人
|
|
var myInfo modelshr.ManCont
|
|
myInfo.GetCont(map[string]interface{}{"`key`": userKey})
|
|
userKey := strconv.FormatInt(myInfo.Key, 10)
|
|
nodeUser = append(nodeUser, userKey)
|
|
nodeMan := TransformPublicUs(myInfo)
|
|
nodeMan.LogList = append(nodeMan.LogList, logInfo)
|
|
OperatorAry = append(OperatorAry, nodeMan)
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-11-15 11:37:00
|
|
@ 功能: 装通用执行人数据
|
|
@ 参数
|
|
|
|
#v 人员信息
|
|
|
|
@ 返回值
|
|
|
|
#userCont 统一操作人信息
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func TransformPublicUs(v modelshr.ManCont) (userCont OperatorList) {
|
|
userCont.Id = strconv.FormatInt(v.Key, 10)
|
|
userCont.Types = 1 //1:人员;2:角色;3:行政组织
|
|
userCont.Name = v.Name //操作人姓名
|
|
userCont.Number = v.Number //操作人工号
|
|
userCont.Icon = v.Icon //操作人头像
|
|
userCont.IconBase64 = v.IconPhpto //操作人头像
|
|
userCont.Wechat = v.Wechat //微信Openid、
|
|
userCont.Tel = v.Mobilephone
|
|
if v.WorkWechat != "" {
|
|
userCont.Wechat = v.WorkWechat //微信Openid
|
|
}
|
|
if v.Company != 0 {
|
|
var orgGroupCont modelshr.AdministrativeOrganization
|
|
orgGroupCont.GetCont(map[string]interface{}{"`id`": v.Company}, "`name`")
|
|
userCont.CompanyName = orgGroupCont.Name //公司名称
|
|
}
|
|
_, companyId, _, _, _ := publicmethod.GetOrgStructurees(v.AdminOrg)
|
|
userCont.DepartmentId = companyId //分厂Id
|
|
if companyId != 0 {
|
|
var orgCont modelshr.AdministrativeOrganization
|
|
orgCont.GetCont(map[string]interface{}{"`id`": companyId}, "`name`")
|
|
userCont.DepartmentName = orgCont.Name //分厂名称
|
|
}
|
|
//获取岗位
|
|
if v.Position != 0 {
|
|
var postCont modelshr.Position
|
|
postCont.GetCont(map[string]interface{}{"`id`": v.Position}, "`name`")
|
|
userCont.PostId = v.Position //职务Id
|
|
userCont.PostName = postCont.Name //职务名称
|
|
}
|
|
if v.TeamId != 0 {
|
|
var teamCont modelshr.TeamGroup
|
|
teamCont.GetCont(map[string]interface{}{"`id`": v.TeamId}, "`name`")
|
|
userCont.Tema = v.TeamId //班组Id
|
|
userCont.TemaName = teamCont.Name //班组名称
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-17 11:04:48
|
|
@ 功能: 执行工作流节点处理
|
|
@ 参数
|
|
|
|
#userKey 当前处理人
|
|
#AgreeToRefuse 1:同意,2:驳回
|
|
#Suggest 审批意见
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (r *RunWorkFlow) RunNodeHandle(userKey int64, AgreeToRefuse int, Suggest string) {
|
|
fmt.Printf("执行工作流节点处理------------->userKey=======>%v, AgreeToRefuse=======>%v, Suggest=======>%v, r.Step=======>%v\n", userKey, AgreeToRefuse, Suggest, r.Step)
|
|
//判断流程是否存在
|
|
if len(r.FlowList) < 1 {
|
|
return
|
|
}
|
|
userKeyStr := strconv.FormatInt(userKey, 10) //当前操作人识别符转字符类型
|
|
for i, v := range r.FlowList { //遍历流程步骤判断当前执行的哪一步
|
|
if v.Step == r.Step { //获取当前节点数据
|
|
switch v.Types { //0:发起节点;1:审批节点;2:抄送;3:执行节点
|
|
case 1, 3:
|
|
//判断操作人是有操作权限或是否已经操作过
|
|
r.IsRun, r.Msg = JudgeOperUser(userKey, r.RunUid, v.Operator) //判断操作人是有操作权限或是否已经操作过
|
|
if r.IsRun {
|
|
return
|
|
} else {
|
|
fmt.Printf("执行工作流节点处理-------1------>userKey=======>%v\n AgreeToRefuse=======>%v\n Suggest=======>%v\n\n", userKey, AgreeToRefuse, Suggest)
|
|
if AgreeToRefuse != 1 { //驳回操作
|
|
v.Status = 3 //驳回
|
|
operatorAry, nodeUser := CopeParticipantEnforcerLog(userKeyStr, r.RunUid, 3, v.Operator, Suggest)
|
|
r.FlowList[i].Operator = operatorAry
|
|
r.Participant = append(r.Participant, nodeUser...)
|
|
r.Step, r.NextStep, _ = r.CallBackToNode(v.GoBackNode)
|
|
fmt.Printf("执行工作流节点处理--------2----->userKey=======>%v\n AgreeToRefuse=======>%v\n Suggest=======>%v\n operatorAry=======>%v\n nodeUser=======>%v\n GoBackNode=======>%v\n r=======>%v\n\n", userKey, AgreeToRefuse, Suggest, operatorAry, nodeUser, v.GoBackNode, r)
|
|
r.SendWecharMsgTextCard(r.Step, "驳回", Suggest)
|
|
} else { //同意操作
|
|
v.Status = 2 //同意
|
|
operatorAry, nodeUser := CopeParticipantEnforcerLog(userKeyStr, r.RunUid, 2, v.Operator, Suggest)
|
|
r.FlowList[i].Operator = operatorAry
|
|
r.Participant = append(r.Participant, nodeUser...)
|
|
currentStep, nextStep := r.TallyPaceStepes(userKeyStr, r.Step, r.FlowList[i]) //获取执行步伐
|
|
fmt.Printf("执行工作流节点处理-------3------>userKey=======>%v\n AgreeToRefuse=======>%v\n Suggest=======>%v\n currentStep=======>%v\n nextStep=======>%v\n\n", userKey, AgreeToRefuse, Suggest, currentStep, nextStep)
|
|
if nextStep > 0 {
|
|
if r.ToNextNodeRunOrClose(userKeyStr, nextStep) {
|
|
r.Step = nextStep
|
|
// r.NextStep = nextStep
|
|
r.RunNodeHandle(userKey, AgreeToRefuse, Suggest)
|
|
} else {
|
|
userKeyStr := strconv.FormatInt(userKey, 10)
|
|
//判断是否向下一个节点的人发送信息
|
|
r.SendWecharMsgTopct(userKeyStr, nextStep)
|
|
}
|
|
}
|
|
r.Step = currentStep
|
|
r.NextStep = nextStep
|
|
taskmanagement.FlowRunLog(r.Uuid, userKey, AgreeToRefuse, v.NodeKey, Suggest, "")
|
|
}
|
|
}
|
|
return
|
|
case 2: //抄送
|
|
var sendUserAry []string
|
|
for _, ov := range v.Operator {
|
|
if !publicmethod.IsInTrue[string](ov.Id, r.MakeCopy) {
|
|
r.MakeCopy = append(r.MakeCopy, ov.Id)
|
|
}
|
|
if ov.Wechat != "" {
|
|
if !publicmethod.IsInTrue[string](ov.Wechat, sendUserAry) {
|
|
sendUserAry = append(sendUserAry, ov.Wechat)
|
|
}
|
|
}
|
|
userkIntId, _ := strconv.ParseInt(ov.Id, 10, 64)
|
|
title := fmt.Sprintf("向%v发送抄送数据", ov.Name)
|
|
taskmanagement.FlowRunLog(r.Uuid, userkIntId, AgreeToRefuse, v.NodeKey, title, "")
|
|
}
|
|
r.SendWecharMsgTopct(userKeyStr, r.Step)
|
|
currentStep, nextStep := r.TallyPaceStepes(userKeyStr, r.Step, r.FlowList[i])
|
|
if nextStep > 0 {
|
|
if r.ToNextNodeRunOrClose(userKeyStr, nextStep) {
|
|
r.Step = currentStep
|
|
r.NextStep = nextStep
|
|
r.RunNodeHandle(userKey, AgreeToRefuse, Suggest)
|
|
}
|
|
}
|
|
r.Step = currentStep
|
|
r.NextStep = nextStep
|
|
return
|
|
default:
|
|
v.Status = 2 //同意
|
|
operatorAry, nodeUser := CopeParticipantEnforcerLog(userKeyStr, r.RunUid, 2, v.Operator, "发起流程")
|
|
r.FlowList[i].Operator = operatorAry
|
|
r.Participant = append(r.Participant, nodeUser...)
|
|
currentStep, nextStep := r.TallyPaceStepes(userKeyStr, r.Step, r.FlowList[i]) //获取执行步伐
|
|
fmt.Printf("执行工作流节点处理-------4------>userKey=======>%v\n AgreeToRefuse=======>%v\n Suggest=======>%v\n currentStep=======>%v\n nextStep=======>%v\n\n", userKey, AgreeToRefuse, Suggest, currentStep, nextStep)
|
|
if nextStep > 0 {
|
|
if r.ToNextNodeRunOrClose(userKeyStr, nextStep) {
|
|
r.Step = currentStep
|
|
r.NextStep = nextStep
|
|
r.RunNodeHandle(userKey, AgreeToRefuse, "发起流程")
|
|
} else {
|
|
userKeyStr := strconv.FormatInt(userKey, 10)
|
|
//判断是否向下一个节点的人发送信息
|
|
r.SendWecharMsgTopct(userKeyStr, nextStep)
|
|
}
|
|
}
|
|
r.Step = currentStep
|
|
r.NextStep = nextStep
|
|
taskmanagement.FlowRunLog(r.Uuid, userKey, AgreeToRefuse, v.NodeKey, "发起流程", "")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-19 08:34:32
|
|
@ 功能: 驳回到指定节点
|
|
@ 参数
|
|
|
|
#nodeKey 返回的节点
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (r *RunWorkFlow) CallBackToNode(nodeKey string) (creeStep, nextStep int, isNew bool) {
|
|
if nodeKey == "beginnode" {
|
|
creeStep = 1
|
|
if len(r.FlowList) >= 2 {
|
|
nextStep = 2
|
|
isNew = false
|
|
} else {
|
|
nextStep = 0
|
|
isNew = true
|
|
}
|
|
r.Step = creeStep
|
|
r.NextStep = nextStep
|
|
} else {
|
|
creeStep = 1
|
|
nextStep = 0
|
|
for _, v := range r.FlowList {
|
|
if nodeKey == v.NodeKey {
|
|
creeStep = v.Step
|
|
nextStep := v.Step + 1
|
|
if nextStep <= len(r.FlowList) {
|
|
isNew = false
|
|
} else {
|
|
nextStep = 0
|
|
isNew = true
|
|
}
|
|
}
|
|
}
|
|
r.Step = creeStep
|
|
r.NextStep = nextStep
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-17 11:45:12
|
|
@ 功能: 判断操作人是否已经操作过或具备当前操作权限,并写入操作记录
|
|
@ 参数
|
|
|
|
#userKey 当前操作人
|
|
#runId 执行码
|
|
#ExamineMode 多人审批时采用的审批方式。0:无操作 1依次审批 2会签 3:非会签
|
|
#Operator 操作人
|
|
|
|
@ 返回值
|
|
|
|
#状态
|
|
#说明
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func JudgeOperUser(userKey, runId int64, Operator []OperatorList) (bool, string) {
|
|
if len(Operator) < 1 {
|
|
return true, "您不是此节点操作人!请不要提交!"
|
|
}
|
|
jsonval, _ := json.Marshal(Operator)
|
|
fmt.Printf("判断操作人是否已经操作过userKey:%v\n\n\n\n runId:%v\n\n\n\njsonval:%v\n\n\n\n", userKey, runId, string(jsonval))
|
|
caoZuoQuanXian := true
|
|
for _, v := range Operator {
|
|
if v.Id == strconv.FormatInt(userKey, 10) {
|
|
caoZuoQuanXian = false
|
|
if len(v.LogList) > 0 {
|
|
for _, m := range v.LogList {
|
|
if m.UID == strconv.FormatInt(runId, 10) {
|
|
return true, "您已经操作过此节点!请不要重复提交!"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if caoZuoQuanXian {
|
|
return true, "您不是此节点操作人!请不要提交!"
|
|
}
|
|
return false, ""
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-12-17 15:53:24
|
|
@ 功能: 发送文本卡片消息
|
|
@ 参数
|
|
|
|
#userKey 接收人
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (r *RunWorkFlow) SendWecharMsgTextCard(runStep int, nodeTitle, content string) {
|
|
if runStep == 0 {
|
|
runStep = 1
|
|
}
|
|
if runStep > len(r.FlowList) {
|
|
runStep = len(r.FlowList)
|
|
}
|
|
var sendUser []string
|
|
for _, v := range r.FlowList {
|
|
if v.Step == runStep {
|
|
for _, lv := range v.Operator {
|
|
if lv.Wechat != "" && !publicmethod.IsInTrue[string](lv.Wechat, sendUser) {
|
|
sendUser = append(sendUser, lv.Wechat)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// fmt.Printf("驳回数据接收人:%v", sendUser)
|
|
if len(sendUser) > 0 {
|
|
tableName, qouteTitle, _ := r.GainTitleAndCreate()
|
|
var sendMsg workWechat.SendMessage
|
|
sendMsg.Touser = strings.Join(sendUser, "|")
|
|
sendMsg.Msgtype = "textcard"
|
|
sendMsg.Textcard.Title = nodeTitle
|
|
sendMsg.Textcard.Description = fmt.Sprintf("<div class='gray'>%v</div> <div class='normal'>%v</div><div class='gray'>%v</div><div class='highlight'>驳回原因:%v</div>", publicmethod.UnixTimeToDay(time.Now().Unix(), 11), tableName, qouteTitle, content)
|
|
sendMsg.Textcard.Url = "wap.gyhlw.group"
|
|
sendMsg.Textcard.Btntxt = "前往查看"
|
|
fmt.Printf("驳回数据接收人2:%v", sendMsg)
|
|
sendMsg.SendMsg("stzl", 1)
|
|
}
|
|
}
|
|
|