应用集成平台服务端
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.
 
 
 

341 lines
11 KiB

package workFlowRun
import (
"appPlatform/api/version1/taskplatform/taskmanagement"
"appPlatform/models/customerForm"
"appPlatform/models/modelAppPlatform"
"appPlatform/models/modelshr"
"appPlatform/overall"
"appPlatform/overall/publicmethod"
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
"github.com/gin-gonic/gin"
)
/*
*
@ 作者: 秦东
@ 时间: 2024-12-12 14:37:41
@ 功能: 启动流程
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) StartProcess(c *gin.Context) {
var requestData StartWorkFlow
err := c.ShouldBindJSON(&requestData)
if err != nil {
publicmethod.Result(10001, err, c, "未知进程!不可执行")
return
}
if requestData.Id == "" {
publicmethod.Result(10001, err, c, "未知进程!不可执行")
return
}
if requestData.State == 0 {
requestData.State = 3
}
var taskInfo customerForm.TaskRecord
taskInfo.GetCont(map[string]interface{}{"`masters_key`": requestData.Id}, "`title`", "`creater`", `masters_key`, "`version_id`", "`flow_key`", "`flow_run_sing`", "`tableKey`", "`appKey`", "`runFlowId`")
if len(requestData.FlowList) < 1 {
taskInfo.EiteCont(map[string]interface{}{"`masters_key`": requestData.Id}, map[string]interface{}{"`status`": 1})
if taskInfo.RunFlowId != 0 {
var runFlowInfo customerForm.RunWorkflow
runFlowInfo.EiteCont(map[string]interface{}{"`id`": taskInfo.RunFlowId}, map[string]interface{}{"`status`": 1})
}
publicmethod.Result(10001, err, c, "未知进程!不可执行")
return
}
//获取当前操作参数
context, _ := c.Get(overall.MyContJwt)
var userCont modelshr.ManCont
userCont.GetLoginCont(context) //当前操作人
startCreaterKey := strconv.FormatInt(userCont.Key, 10) //当前操作人
creetTime := time.Now().Unix() //当前时间
//获取流程详情
var flowVersionInfo modelAppPlatform.WorkFlowVersion
flowVersionInfo.GetCont(map[string]interface{}{"`id`": taskInfo.FlowRunSing}, "`content`")
uuid := publicmethod.GetUUid(1)
runUuId := publicmethod.GetUUid(6)
//工作流执行主体
var workFlowInfo customerForm.RunWorkflow
workFlowInfo.Id = uuid
workFlowInfo.FlowKey = taskInfo.FlowKey //统一识别符(任务标识符)
workFlowInfo.Version = strconv.FormatInt(taskInfo.FlowRunSing, 10) //工作流版本
workFlowInfo.VersionCont = flowVersionInfo.Content //当前工作流内容
workFlowInfo.Creater = userCont.Key //流程发起人
workFlowInfo.Status = requestData.State //状态:1、草稿;2:驳回;3:审批中;4:归档;5:删除
workFlowInfo.StartTime = creetTime //开始时间
workFlowInfo.UpdateTime = creetTime //更新时间
workFlowInfo.RunKey = runUuId //当前执行识别符
//流程结构体
var executeWorkflow RunWorkFlow
executeWorkflow.Step = 1 //执行第1部 发起流程。当前为第一步
executeWorkflow.FlowList = requestData.FlowList //工作流主体
executeWorkflow.Participant = append(executeWorkflow.Participant, startCreaterKey) //当前操作人
executeWorkflow.TotalSteps = len(requestData.FlowList) //流程总长度
executeWorkflow.Uuid = uuid //流程唯一识别符
executeWorkflow.RunUid = runUuId //执行Uid
executeWorkflow.SendWecharMsg.AppKey = taskInfo.AppKey
executeWorkflow.SendWecharMsg.Creater = taskInfo.Creater
executeWorkflow.SendWecharMsg.MastersKey = taskInfo.MastersKey
executeWorkflow.SendWecharMsg.TableKey = taskInfo.TableKey
executeWorkflow.SendWecharMsg.RunFlowId = taskInfo.RunFlowId
if requestData.State == 3 {
workFlowInfo.CurrentStep, workFlowInfo.NextStep = executeWorkflow.GainRunNodeNew(startCreaterKey, 1, 2, "发起审批")
} else {
workFlowInfo.CurrentStep, workFlowInfo.NextStep = executeWorkflow.GainRunNodeNew(startCreaterKey, 1, 1, "")
}
fmt.Printf("获取得步骤:workFlowInfo.CurrentStep :%v\n workFlowInfo.NextStep :%v\n", workFlowInfo.CurrentStep, workFlowInfo.NextStep)
flowJsonCont, _ := json.Marshal(executeWorkflow.FlowList) //将步进流转化成json流
workFlowInfo.FlowCont = string(flowJsonCont) //流程执行体
if requestData.State == 3 {
// workFlowInfo.CurrentStep = executeWorkflow.Step
// workFlowInfo.NextStep = executeWorkflow.NextStep
//参与人去重
var parUser []string
for _, v := range executeWorkflow.Participant {
if !publicmethod.IsInTrue[string](v, parUser) {
parUser = append(parUser, v)
}
}
workFlowInfo.Participants = strings.Join(parUser, ",")
nextNodeRunUser := executeWorkflow.NextNodePeople()
workFlowInfo.NextExecutor = strings.Join(nextNodeRunUser, ",")
if executeWorkflow.NextStep <= 0 {
workFlowInfo.Status = 4
}
}
err = workFlowInfo.WriteCont() //写入执行工作流
if err != nil {
var taskInfo customerForm.TaskRecord
taskInfo.EiteCont(map[string]interface{}{"`masters_key`": requestData.Id}, map[string]interface{}{"`status`": 1})
publicmethod.Result(10001, err, c, "流程写入失败!请重新发起")
return
}
if executeWorkflow.NextStep <= 0 {
var taskCont customerForm.TaskRecord
taskCont.EiteCont(map[string]interface{}{"`masters_key`": requestData.Id}, map[string]interface{}{"`status`": 4, "`runFlowId`": uuid})
} else {
var taskCont customerForm.TaskRecord
taskCont.EiteCont(map[string]interface{}{"`masters_key`": requestData.Id}, map[string]interface{}{"`status`": requestData.State, "`runFlowId`": uuid})
}
publicmethod.Result(0, err, c)
}
/*
*
@ 作者: 秦东
@ 时间: 2024-12-17 10:40:52
@ 功能: 执行工作流
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) RunTaskWorkFlow(c *gin.Context) {
var requestData SubmitAppResults
err := c.ShouldBindJSON(&requestData)
if err != nil {
publicmethod.Result(100, err, c)
return
}
if requestData.Id == "" {
publicmethod.Result(100, err, c)
return
}
if requestData.AgreeOrRefuse == 0 {
requestData.AgreeOrRefuse = 2
}
//step 1:获取流程执行情况
var flowInfo customerForm.RunWorkflow
err = flowInfo.GetCont(map[string]interface{}{"`id`": requestData.Id})
if err != nil {
publicmethod.Result(107, err, c)
return
}
if flowInfo.NextStep == 0 || flowInfo.Status != 3 {
publicmethod.Result(1, err, c, "此流程在不可审批状态!您的提交无效")
return
}
if len(requestData.FlowList) < 1 { //判断流程是否因表单条件而变化
if flowInfo.FlowCont != "" {
err = json.Unmarshal([]byte(flowInfo.FlowCont), &requestData.FlowList)
if err != nil {
publicmethod.Result(1, err, c, "流程异常!您的提交无效")
return
}
} else {
publicmethod.Result(1, err, c, "流程异常!您的提交无效")
return
}
}
//step 2:获取操作人
context, _ := c.Get(overall.MyContJwt)
var userCont modelshr.ManCont
userCont.GetLoginCont(context)
var taskInfo customerForm.TaskRecord
taskInfo.GetCont(map[string]interface{}{"`runFlowId`": requestData.Id}, "`title`", "`creater`", `masters_key`, "`version_id`", "`flow_key`", "`flow_run_sing`", "`tableKey`", "`appKey`", "`runFlowId`", "`participant`")
//step 3:执行流程
var runFlow RunWorkFlow
runFlow.Step = flowInfo.NextStep
runFlow.TotalSteps = len(requestData.FlowList) //流程总长度
runFlow.Uuid = flowInfo.FlowKey
runFlow.RunUid = flowInfo.RunKey
runFlow.Participant = strings.Split(flowInfo.Participants, ",")
runFlow.FlowList = requestData.FlowList
runFlow.SendWecharMsg.AppKey = taskInfo.AppKey
runFlow.SendWecharMsg.Creater = taskInfo.Creater
runFlow.SendWecharMsg.MastersKey = taskInfo.MastersKey
runFlow.SendWecharMsg.TableKey = taskInfo.TableKey
runFlow.SendWecharMsg.RunFlowId = taskInfo.RunFlowId
runFlow.RunNodeHandle(userCont.Key, requestData.AgreeOrRefuse, requestData.Suggest)
if runFlow.IsRun {
publicmethod.Result(1, err, c, runFlow.Msg)
return
}
flowJsonCont, _ := json.Marshal(runFlow.FlowList) //将步进流转化成json流
saveFlowInfo := publicmethod.MapOut[string]() //修改工作流
saveFlowInfo["`flow_cont`"] = flowJsonCont
saveFlowInfo["`current_step`"] = runFlow.Step
saveFlowInfo["`next_step`"] = runFlow.NextStep
if flowInfo.Participants != "" {
oldUser := strings.Split(flowInfo.Participants, ",")
runFlow.Participant = append(runFlow.Participant, oldUser...)
}
//参与人去重
var parUser []string
for _, v := range runFlow.Participant {
if !publicmethod.IsInTrue[string](v, parUser) {
parUser = append(parUser, v)
}
}
saveFlowInfo["`participants`"] = strings.Join(parUser, ",")
saveTaskInfo := publicmethod.MapOut[string]() //修改任务
//参与人去重
if len(parUser) > 0 {
oldTaskUser := strings.Split(taskInfo.Participant, ",")
for _, v := range parUser {
if !publicmethod.IsInTrue[string](v, oldTaskUser) {
oldTaskUser = append(oldTaskUser, v)
}
}
saveTaskInfo["`participant`"] = strings.Join(parUser, ",")
}
//抄送人
if flowInfo.MakeCopy != "" {
oldCopyUser := strings.Split(flowInfo.MakeCopy, ",")
runFlow.MakeCopy = append(runFlow.MakeCopy, oldCopyUser...)
}
//抄送人 去重
var copyMan []string
for _, v := range runFlow.MakeCopy {
if !publicmethod.IsInTrue[string](v, copyMan) {
copyMan = append(copyMan, v)
}
}
saveFlowInfo["`makeCopy`"] = strings.Join(copyMan, ",")
//下一步执行人
nextRunUser := runFlow.GainNextStepUser(runFlow.NextStep)
saveFlowInfo["`next_executor`"] = strings.Join(nextRunUser, ",")
saveFlowInfo["`update_time`"] = time.Now().Unix()
if requestData.AgreeOrRefuse == 1 {
if runFlow.NextStep != 0 {
saveFlowInfo["`status`"] = 3
saveTaskInfo["`status`"] = 3
} else {
saveFlowInfo["`status`"] = 4
saveTaskInfo["`status`"] = 4
taskmanagement.JudgeEditFlow(flowInfo.FlowKey)
}
} else {
saveFlowInfo["`runKey`"] = publicmethod.GetUUid(6)
if runFlow.Step != 1 {
saveFlowInfo["`status`"] = 3
} else {
saveFlowInfo["`status`"] = 2
saveTaskInfo["`status`"] = 1
}
}
saveTaskInfo["`edit_time`"] = time.Now().Unix()
gordb := overall.CONSTANT_DB_CustomerForm.Begin()
flowErr := gordb.Model(&customerForm.RunWorkflow{}).Where(map[string]interface{}{"`id`": requestData.Id}).Updates(saveFlowInfo).Error
taskErr := gordb.Model(&customerForm.TaskRecord{}).Where("`runFlowId` = ?", requestData.Id).Updates(saveTaskInfo).Error
if flowErr != nil || taskErr != nil {
gordb.Rollback()
publicmethod.Result(100, err, c, "数据提交失败!请重新提交!")
return
}
gordb.Commit()
publicmethod.Result(0, err, c)
// sendMap := publicmethod.MapOut[string]()
// sendMap["runFlow"] = runFlow
// sendMap["saveFlowInfo"] = saveFlowInfo
// sendMap["saveTaskInfo"] = saveTaskInfo
// sendMap["nextStep"] = runFlow.NextStep
// publicmethod.Result(1, sendMap, c, runFlow.Msg)
}
/*
*
@ 作者: 秦东
@ 时间: 2024-12-19 10:01:12
@ 功能: 获取指定节点执行人
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (r *RunWorkFlow) GainNextStepUser(stepNode int) (userAry []string) {
if stepNode <= 0 {
return
}
for _, v := range r.FlowList {
if v.Step == stepNode {
for _, op := range v.Operator {
if !publicmethod.IsInTrue[string](op.Id, userAry) {
userAry = append(userAry, op.Id)
}
}
}
}
return
}