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.
573 lines
14 KiB
573 lines
14 KiB
package taskflow
|
|
|
|
import (
|
|
"appPlatform/models/flowlog"
|
|
"appPlatform/models/modelAppPlatform"
|
|
"appPlatform/models/modelshr"
|
|
"appPlatform/overall"
|
|
"appPlatform/overall/publicmethod"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-11-22 16:13:21
|
|
@ 功能: 发起工作流
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) StartRunFlow(c *gin.Context) {
|
|
var requestData StartFlow
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
publicmethod.Result(10001, err, c)
|
|
return
|
|
}
|
|
if requestData.Id == "" {
|
|
publicmethod.Result(10001, err, c, "未知进程!不可执行")
|
|
return
|
|
}
|
|
if len(requestData.FlowList) < 1 {
|
|
publicmethod.Result(10001, err, c, "未知进程!不可执行")
|
|
return
|
|
}
|
|
if requestData.State == 0 {
|
|
requestData.State = 3
|
|
}
|
|
context, _ := c.Get(overall.MyContJwt)
|
|
var userCont modelshr.ManCont
|
|
userCont.GetLoginCont(context) //当前操作人
|
|
creetTime := time.Now().Unix() //当前时间
|
|
var taskInfo modelAppPlatform.Task
|
|
taskInfo.GetCont(map[string]interface{}{"`masters_key`": requestData.Id}, "`flow_key`", "`flow_run_sing`")
|
|
var flowVersionInfo modelAppPlatform.WorkFlowVersion
|
|
flowVersionInfo.GetCont(map[string]interface{}{"`id`": taskInfo.FlowRunSing}, "`content`")
|
|
var runFlowInfo modelAppPlatform.RunFlow
|
|
uuid := publicmethod.GetUUid(1)
|
|
runUuId := publicmethod.GetUUid(6)
|
|
runFlowInfo.Id = uuid
|
|
runFlowInfo.FlowKey, _ = strconv.ParseInt(requestData.Id, 10, 64) //统一识别符
|
|
// runFlowInfo.FlowKey = taskInfo.FlowKey //工作流主体
|
|
runFlowInfo.Version = strconv.FormatInt(taskInfo.FlowRunSing, 10) //工作流版本
|
|
runFlowInfo.VersionCont = flowVersionInfo.Content //当前工作流内容
|
|
|
|
runFlowInfo.Creater = userCont.Key //流程发起人
|
|
runFlowInfo.Status = requestData.State //状态:1、草稿;2:驳回;3:审批中;4:归档;5:删除
|
|
runFlowInfo.StartTime = creetTime //开始时间
|
|
runFlowInfo.UpdateTime = creetTime //更新时间
|
|
runFlowInfo.RunKey = runUuId //当前执行识别符
|
|
|
|
startUs := strconv.FormatInt(userCont.Key, 10) //当前操作人
|
|
|
|
//执行流程
|
|
var runFlow RunWorkFlow
|
|
runFlow.Step = 0 //执行第几部
|
|
runFlow.FlowList = requestData.FlowList
|
|
runFlow.Participant = append(runFlow.Participant, startUs)
|
|
runFlow.TotalSteps = len(requestData.FlowList) //流程总长度
|
|
runFlow.Uuid = uuid
|
|
runFlow.RunUid = runUuId
|
|
if requestData.State == 3 {
|
|
runFlow.GainRunNode(startUs, 2, "发起审批")
|
|
} else {
|
|
runFlow.GainRunNode(startUs, 1, "")
|
|
}
|
|
|
|
fmt.Printf("执行完毕--10->%v->%v\n", runFlow.Step, runFlow.NextStep)
|
|
|
|
flowJsonCont, _ := json.Marshal(runFlow.FlowList) //将步进流转化成json流
|
|
runFlowInfo.FlowCont = string(flowJsonCont) //流程执行体
|
|
if requestData.State == 3 {
|
|
runFlowInfo.CurrentStep = runFlow.Step
|
|
runFlowInfo.NextStep = runFlow.NextStep
|
|
//参与人去重
|
|
var parUser []string
|
|
for _, v := range runFlow.Participant {
|
|
if !publicmethod.IsInTrue[string](v, parUser) {
|
|
parUser = append(parUser, v)
|
|
}
|
|
}
|
|
runFlowInfo.Participants = strings.Join(parUser, ",")
|
|
nextRunUser := runFlow.NextRunNodeUser(1)
|
|
runFlowInfo.NextExecutor = strings.Join(nextRunUser, ",")
|
|
if runFlow.NextStep <= 0 {
|
|
runFlowInfo.Status = 4
|
|
}
|
|
}
|
|
|
|
// xie, _ := json.Marshal(runFlowInfo)
|
|
// fmt.Printf("写入数据--10->%v\n", string(xie))
|
|
err = runFlowInfo.WriteCont()
|
|
if err != nil {
|
|
publicmethod.Result(10001, err, c, "流程写入失败!请重新发起")
|
|
return
|
|
}
|
|
if runFlow.NextStep <= 0 {
|
|
var taskCont modelAppPlatform.Task
|
|
taskCont.EiteCont(map[string]interface{}{"`masters_key`": requestData.Id}, map[string]interface{}{"`status`": 4})
|
|
} else {
|
|
var taskCont modelAppPlatform.Task
|
|
taskCont.EiteCont(map[string]interface{}{"`masters_key`": requestData.Id}, map[string]interface{}{"`status`": requestData.State})
|
|
}
|
|
publicmethod.Result(0, err, c)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-11-23 10:05:43
|
|
@ 功能: 流程执行记录
|
|
@ 参数
|
|
|
|
#uuid 流程uuid
|
|
#userKey 操作人
|
|
#AgreeToRefuse 同意或者驳回
|
|
#nodeKey 操作得节点
|
|
#idea 意见
|
|
#annex 附件
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func FlowRunLog(uuid, userKey int64, AgreeToRefuse int, nodeKey, idea, annex string) {
|
|
creetTime := time.Now().Unix()
|
|
var flowRunLog flowlog.WorkFlowLog
|
|
flowRunLog.FlowId = uuid //执行的流程"`
|
|
flowRunLog.Creater = userKey //操作人"`
|
|
flowRunLog.Status = AgreeToRefuse //状态:1、草稿;2:驳回;3:通过;4:归档;5:删除"`
|
|
flowRunLog.Content = idea //审批意见"`
|
|
flowRunLog.Annex = annex //附件"`
|
|
flowRunLog.Time = creetTime //创建时间"`
|
|
flowRunLog.EditTime = creetTime //ault编辑时间"`
|
|
flowRunLog.NodeKey = nodeKey //操作得节点
|
|
flowRunLog.WriteCont()
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-11-23 08:59:16
|
|
@ 功能: 获取下一步执行人
|
|
@ 参数
|
|
|
|
#userAry 下一步执行人
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (r *RunWorkFlow) NextRunNodeUser(isTrue int) (userAry []string) {
|
|
if r.NextStep <= 0 {
|
|
return
|
|
}
|
|
if isTrue == 1 {
|
|
curStep := r.Step + 1
|
|
if curStep > r.TotalSteps {
|
|
curStep = r.TotalSteps
|
|
}
|
|
for _, v := range r.FlowList {
|
|
if v.Step == curStep {
|
|
for _, op := range v.Operator {
|
|
if !publicmethod.IsInTrue[string](op.Id, userAry) {
|
|
userAry = append(userAry, op.Id)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
if r.Step == 1 {
|
|
return
|
|
}
|
|
for _, v := range r.FlowList {
|
|
if v.Step == r.Step {
|
|
for _, op := range v.Operator {
|
|
if !publicmethod.IsInTrue[string](op.Id, userAry) {
|
|
userAry = append(userAry, op.Id)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-11-22 16:57:06
|
|
@ 功能: 执行工作流
|
|
@ 参数
|
|
|
|
#userKey //当前执行人
|
|
#AgreeToRefuse 同意或者驳回
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (r *RunWorkFlow) GainRunNode(userKey string, AgreeToRefuse int, runCont string) {
|
|
userkInt, _ := strconv.ParseInt(userKey, 10, 64)
|
|
curStep := 1
|
|
if r.Step != 0 {
|
|
curStep = r.Step
|
|
}
|
|
for i := 0; i < r.TotalSteps; i++ {
|
|
if r.FlowList[i].Step == curStep {
|
|
currentStep, nextStep := PaceStep(r.RunUid, r.Step, r.TotalSteps, r.FlowList[i])
|
|
operatorAry, nodeUser := FindOperator(userKey, r.RunUid, AgreeToRefuse, r.FlowList[i].Operator, runCont)
|
|
r.FlowList[i].Operator = operatorAry
|
|
r.FlowList[i].Status = AgreeToRefuse
|
|
r.Participant = append(r.Participant, nodeUser...)
|
|
switch r.FlowList[i].Types {
|
|
case 0:
|
|
r.Step = currentStep
|
|
r.NextStep = nextStep
|
|
FlowRunLog(r.Uuid, userkInt, AgreeToRefuse, r.FlowList[i].NodeKey, runCont, "")
|
|
if JudgeRunNode(currentStep, r.FlowList) {
|
|
r.GainRunNode(userKey, AgreeToRefuse, runCont)
|
|
}
|
|
return
|
|
case 1:
|
|
r.Step = currentStep
|
|
r.NextStep = nextStep
|
|
return
|
|
case 2:
|
|
r.Step = currentStep
|
|
r.NextStep = nextStep
|
|
// fmt.Printf("执行曹总--0->%v->%v\n", r.Step, r.NextStep)
|
|
for _, op := range r.FlowList[i].Operator {
|
|
userkIntId, _ := strconv.ParseInt(op.Id, 10, 64)
|
|
title := fmt.Sprintf("向%v发送抄送数据", op.Name)
|
|
FlowRunLog(r.Uuid, userkIntId, AgreeToRefuse, r.FlowList[i].NodeKey, title, "")
|
|
}
|
|
if r.NextStep > 0 {
|
|
r.GainRunNode(userKey, AgreeToRefuse, runCont)
|
|
}
|
|
return
|
|
case 3:
|
|
r.Step = currentStep
|
|
r.NextStep = nextStep
|
|
return
|
|
default:
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-11-23 08:46:38
|
|
@ 功能: 判断当前节点是否要继续执行
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func JudgeRunNode(step int, FlowList []RunFlow) (isRun bool) {
|
|
isRun = false
|
|
for _, v := range FlowList {
|
|
if v.Step == step {
|
|
if v.Types == 2 {
|
|
isRun = true
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-11-23 08:35:27
|
|
@ 功能: 计算步伐
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func PaceStep(runId int64, step, totalSteps int, nodeInfo RunFlow) (currentStep, nextStep int) {
|
|
fmt.Printf("计算步伐--1-->%v-->%v\n", step, nodeInfo.ExamineMode)
|
|
if nodeInfo.ExamineMode == 0 {
|
|
if step >= totalSteps {
|
|
currentStep = totalSteps
|
|
nextStep = 0
|
|
fmt.Printf("计算步伐--2-->%v-->%v\n", currentStep, nextStep)
|
|
return
|
|
}
|
|
|
|
currentStep = step + 1
|
|
if currentStep >= totalSteps {
|
|
currentStep = totalSteps
|
|
nextStep = 0
|
|
fmt.Printf("计算步伐--3-->%v-->%v\n", currentStep, nextStep)
|
|
return
|
|
}
|
|
|
|
nextStep = currentStep + 1
|
|
if nextStep >= totalSteps {
|
|
nextStep = totalSteps
|
|
}
|
|
} else if nodeInfo.ExamineMode == 3 {
|
|
if step >= totalSteps {
|
|
currentStep = totalSteps
|
|
nextStep = 0
|
|
fmt.Printf("计算步伐--21-->%v-->%v\n", currentStep, nextStep)
|
|
return
|
|
}
|
|
currentStep = step
|
|
if currentStep >= totalSteps {
|
|
currentStep = totalSteps
|
|
nextStep = 0
|
|
fmt.Printf("计算步伐--31-->%v-->%v\n", currentStep, nextStep)
|
|
return
|
|
}
|
|
|
|
nextStep = currentStep + 1
|
|
if nextStep >= totalSteps {
|
|
nextStep = totalSteps
|
|
}
|
|
fmt.Printf("计算步伐--34-->%v-->%v\n", currentStep, nextStep)
|
|
} else {
|
|
runIdStr := strconv.FormatInt(runId, 10)
|
|
allUser := len(nodeInfo.Operator)
|
|
jiBuQi := 1
|
|
for _, v := range nodeInfo.Operator {
|
|
for _, m := range v.LogList {
|
|
if m.UID == runIdStr {
|
|
jiBuQi++
|
|
}
|
|
}
|
|
}
|
|
fmt.Printf("计算步伐--4-->%v-->%v\n", allUser, jiBuQi)
|
|
if allUser <= jiBuQi {
|
|
if step >= totalSteps {
|
|
currentStep = totalSteps
|
|
nextStep = 0
|
|
fmt.Printf("计算步伐--6-->%v-->%v\n", currentStep, nextStep)
|
|
return
|
|
}
|
|
//
|
|
currentStep = step + 1
|
|
if currentStep >= totalSteps {
|
|
currentStep = totalSteps
|
|
nextStep = 0
|
|
fmt.Printf("计算步伐--7-->%v-->%v\n", currentStep, nextStep)
|
|
return
|
|
}
|
|
// fmt.Printf("计算步伐--3-->%v-->%v\n", currentStep, nextStep)
|
|
nextStep = currentStep + 1
|
|
if nextStep >= totalSteps {
|
|
nextStep = totalSteps
|
|
}
|
|
fmt.Printf("计算步伐--8-->%v-->%v\n", currentStep, nextStep)
|
|
} else {
|
|
currentStep = step - 1
|
|
if currentStep <= 0 {
|
|
currentStep = 1
|
|
}
|
|
if currentStep >= totalSteps {
|
|
currentStep = totalSteps
|
|
nextStep = 0
|
|
fmt.Printf("计算步伐--9-->%v-->%v\n", currentStep, nextStep)
|
|
return
|
|
}
|
|
// fmt.Printf("计算步伐--3-->%v-->%v\n", currentStep, nextStep)
|
|
nextStep = currentStep + 1
|
|
if nextStep >= totalSteps {
|
|
nextStep = totalSteps
|
|
}
|
|
fmt.Printf("计算步伐--10-->%v-->%v\n", currentStep, nextStep)
|
|
}
|
|
}
|
|
|
|
fmt.Printf("计算步伐--11-->%v-->%v\n", currentStep, nextStep)
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-11-23 08:21:52
|
|
@ 功能: 比对操作人
|
|
@ 参数
|
|
|
|
#userKey 操作人
|
|
#runUid 执行Uid
|
|
#AgreeToRefuse 同意或者驳回
|
|
#operator 当前节点操作人
|
|
#suggest 审批意见
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func FindOperator(userKey string, runUid int64, AgreeToRefuse int, operator []OperatorList, suggest string) (OperatorAry []OperatorList, nodeUser []string) {
|
|
// isOk := true
|
|
|
|
var logCont LogList
|
|
logCont.State = AgreeToRefuse //状态 1、未操作;2、通过;3、驳回
|
|
logCont.TimeVal = publicmethod.UnixTimeToDay(time.Now().Unix(), 1)
|
|
logCont.UID = strconv.FormatInt(runUid, 10)
|
|
logCont.Cause = suggest
|
|
for _, v := range operator {
|
|
nodeUser = append(nodeUser, v.Id)
|
|
if v.Id == userKey && AgreeToRefuse != 1 {
|
|
// isOk = false
|
|
v.LogList = append(v.LogList, logCont)
|
|
}
|
|
OperatorAry = append(OperatorAry, v)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-11-30 08:01:37
|
|
@ 功能: 已有表单数据,只发布流程
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) OnlyPublishFlow(c *gin.Context) {
|
|
var requestData StartFlow
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
if requestData.Id == "" {
|
|
publicmethod.Result(100, err, c, "未知进程!不可执行")
|
|
return
|
|
}
|
|
if len(requestData.FlowList) < 1 {
|
|
publicmethod.Result(100, err, c, "未知进程!不可执行")
|
|
return
|
|
}
|
|
if requestData.State == 0 {
|
|
requestData.State = 3
|
|
}
|
|
context, _ := c.Get(overall.MyContJwt)
|
|
var userCont modelshr.ManCont
|
|
userCont.GetLoginCont(context) //当前操作人
|
|
creetTime := time.Now().Unix() //当前时间
|
|
var runInfo modelAppPlatform.RunFlow
|
|
err = runInfo.GetCont(map[string]interface{}{"`flow_key`": requestData.Id}, "`flow_cont`", "`current_step`", "`runKey`", "`participants`")
|
|
if err != nil {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
if len(requestData.FlowList) < 1 && runInfo.FlowCont != "" {
|
|
json.Unmarshal([]byte(runInfo.FlowCont), &requestData.FlowList)
|
|
}
|
|
startUs := strconv.FormatInt(userCont.Key, 10) //当前操作人
|
|
//执行流程
|
|
var runFlow RunWorkFlow
|
|
runFlow.Step = 0 //执行第几部
|
|
runFlow.FlowList = requestData.FlowList
|
|
runFlow.Participant = append(runFlow.Participant, startUs)
|
|
runFlow.TotalSteps = len(requestData.FlowList) //流程总长度
|
|
runFlow.Uuid = runInfo.FlowKey
|
|
runFlow.RunUid = runInfo.RunKey
|
|
if requestData.State == 3 {
|
|
runFlow.GainRunNode(startUs, 2, "发起审批")
|
|
} else {
|
|
runFlow.GainRunNode(startUs, 1, "")
|
|
}
|
|
flowJsonCont, _ := json.Marshal(runFlow.FlowList) //将步进流转化成json流
|
|
saveTask := publicmethod.MapOut[string]()
|
|
saveFlow := publicmethod.MapOut[string]()
|
|
saveFlow["`flow_cont`"] = flowJsonCont
|
|
saveFlow["`current_step`"] = runFlow.Step
|
|
saveFlow["`next_step`"] = runFlow.NextStep
|
|
//参与人去重
|
|
var parUser []string
|
|
for _, v := range runFlow.Participant {
|
|
if !publicmethod.IsInTrue[string](v, parUser) {
|
|
parUser = append(parUser, v)
|
|
}
|
|
}
|
|
saveFlow["`participants`"] = strings.Join(parUser, ",")
|
|
nextRunUser := runFlow.NextRunNodeUser(1)
|
|
saveFlow["`next_executor`"] = strings.Join(nextRunUser, ",")
|
|
saveFlow["`status`"] = requestData.State
|
|
saveTask["status"] = requestData.State
|
|
if runFlow.NextStep <= 0 {
|
|
saveFlow["`status`"] = 4
|
|
saveTask["status"] = 4
|
|
}
|
|
if requestData.State == 2 {
|
|
saveTask["status"] = 1
|
|
}
|
|
saveFlow["`update_time`"] = creetTime
|
|
saveTask["edit_time"] = creetTime
|
|
|
|
var saveRunInfo modelAppPlatform.RunFlow
|
|
err = saveRunInfo.EiteCont(map[string]interface{}{"`flow_key`": requestData.Id}, saveFlow)
|
|
if err != nil {
|
|
publicmethod.Result(106, err, c)
|
|
return
|
|
}
|
|
var saveTaskInfo modelAppPlatform.Task
|
|
saveTaskInfo.EiteCont(map[string]interface{}{"`masters_key`": requestData.Id}, saveTask)
|
|
publicmethod.Result(0, err, c)
|
|
}
|
|
|