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.
465 lines
13 KiB
465 lines
13 KiB
package taskflow
|
|
|
|
import (
|
|
"appPlatform/models/modelAppPlatform"
|
|
"appPlatform/overall"
|
|
"appPlatform/overall/publicmethod"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-10-26 11:36:54
|
|
@ 功能: 写入工作流
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) SaveFlowCont(c *gin.Context) {
|
|
var requestData FlowMainBody
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
if requestData.NodeConfig.NodeNumber == "" {
|
|
publicmethod.Result(1, err, c, "工作流数据错误!请检查后再提交")
|
|
return
|
|
}
|
|
uuid := publicmethod.GetUUid(1)
|
|
if requestData.TableId != "" {
|
|
requestData.TableId = strconv.FormatInt(publicmethod.GetUUid(1), 10)
|
|
uuid, _ = strconv.ParseInt(requestData.TableId, 10, 64)
|
|
}
|
|
if requestData.DirectorMaxLevel == 0 {
|
|
requestData.DirectorMaxLevel = 4
|
|
}
|
|
publicTime := time.Now().Unix()
|
|
var worfFlowMain modelAppPlatform.WorkFlow //工作流主体
|
|
worfFlowMain.Id = uuid
|
|
worfFlowMain.Name = requestData.WorkFlowDef.Name
|
|
worfFlowMain.Describe = fmt.Sprintf("%v关联工作流", requestData.WorkFlowDef.Name)
|
|
worfFlowMain.OpenWechat = 1
|
|
worfFlowMain.State = 1
|
|
if requestData.WorkFlowDef.FormKey != "" {
|
|
formKey, _ := strconv.ParseInt(requestData.WorkFlowDef.FormKey, 10, 64)
|
|
worfFlowMain.FormKey = formKey
|
|
}
|
|
worfFlowMain.Time = publicTime
|
|
var numVal int64
|
|
var flowVersion modelAppPlatform.WorkFlowVersion
|
|
overall.CONSTANT_DB_AppPlatform.Model(&flowVersion).Where("`key` = ?", uuid).Count(&numVal)
|
|
flowVersion.Key = uuid
|
|
flowVersion.Version = strconv.FormatInt(numVal+1, 10)
|
|
var isVersionNum int64
|
|
overall.CONSTANT_DB_AppPlatform.Model(&flowVersion).Where("`state` = 1 AND `key` = ?", uuid).Count(&isVersionNum)
|
|
flowVersion.State = 1
|
|
if isVersionNum > 0 {
|
|
flowVersion.State = 2
|
|
}
|
|
flowVersion.Time = publicTime
|
|
jsonCont, _ := json.Marshal(requestData)
|
|
flowVersion.Content = string(jsonCont)
|
|
var userList []string
|
|
var orgList []string
|
|
isFormWrite := false
|
|
if len(requestData.FlowPermission) > 0 {
|
|
for _, v := range requestData.FlowPermission {
|
|
if v.Types == 3 {
|
|
// orgId, _ := strconv.ParseInt(v.TargetId, 10, 64)
|
|
orgList = append(orgList, v.TargetId)
|
|
isFormWrite = true
|
|
}
|
|
if v.Types == 1 {
|
|
// userId, _ := strconv.ParseInt(v.TargetId, 10, 64)
|
|
userList = append(userList, v.TargetId)
|
|
isFormWrite = true
|
|
}
|
|
}
|
|
}
|
|
saveData := publicmethod.MapOut[string]()
|
|
var customerForm modelAppPlatform.CustomerForm
|
|
if isFormWrite {
|
|
var customerForm modelAppPlatform.CustomerForm
|
|
err = customerForm.GetCont(map[string]interface{}{"`id`": requestData.WorkFlowDef.FormKey}, "`permitstr`", "`userpermit`")
|
|
if err == nil {
|
|
|
|
if len(orgList) > 0 {
|
|
if customerForm.PermitStr != "" {
|
|
oldOrgList := strings.Split(customerForm.PermitStr, ",")
|
|
orgNew := publicmethod.MergeStruct(orgList, oldOrgList)
|
|
saveData["permitstr"] = strings.Join(orgNew, ",")
|
|
flowVersion.OrgPermit = strings.Join(orgNew, ",")
|
|
}
|
|
} else {
|
|
flowVersion.OrgPermit = customerForm.PermitStr
|
|
}
|
|
if len(userList) > 0 {
|
|
if customerForm.UserPermit != "" {
|
|
oldUserList := strings.Split(customerForm.UserPermit, ",")
|
|
userNew := publicmethod.MergeStruct(userList, oldUserList)
|
|
saveData["userpermit"] = strings.Join(userNew, ",")
|
|
flowVersion.UserPermit = strings.Join(userNew, ",")
|
|
}
|
|
} else {
|
|
flowVersion.UserPermit = customerForm.UserPermit
|
|
}
|
|
|
|
if len(saveData) > 0 {
|
|
saveData["edit_time"] = time.Now().Unix()
|
|
saveData["classify"] = 2
|
|
customerForm.EiteCont(map[string]interface{}{"`id`": requestData.WorkFlowDef.FormKey}, saveData)
|
|
}
|
|
}
|
|
}
|
|
saveData["flowkey"] = uuid
|
|
saveData["edit_time"] = time.Now().Unix()
|
|
saveData["classify"] = 2
|
|
customerForm.EiteCont(map[string]interface{}{"`id`": requestData.WorkFlowDef.FormKey}, saveData)
|
|
sendMap := publicmethod.MapOut[string]()
|
|
writeDb := overall.CONSTANT_DB_AppPlatform.Begin()
|
|
flowErr := writeDb.Create(&worfFlowMain).Error
|
|
versionErr := writeDb.Create(&flowVersion).Error
|
|
sendMap["flowErr"] = flowErr
|
|
sendMap["versionErr"] = versionErr
|
|
if flowErr == nil && versionErr == nil {
|
|
writeDb.Commit()
|
|
|
|
} else {
|
|
writeDb.Rollback()
|
|
publicmethod.Result(104, sendMap, c)
|
|
}
|
|
publicmethod.Result(0, sendMap, c)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-10-27 10:25:00
|
|
@ 功能: 获取工作流内容
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) GainFlowInfo(c *gin.Context) {
|
|
var requestData publicmethod.CommonId[string]
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil || requestData.Id == "" {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
var flowVersionInfo modelAppPlatform.FlowVersion
|
|
err = flowVersionInfo.GetCont(map[string]interface{}{"`id`": requestData.Id}, "`content`")
|
|
if err != nil && flowVersionInfo.Content == "" {
|
|
publicmethod.Result(104, err, c)
|
|
return
|
|
}
|
|
var flowVersionCont FlowMainBody
|
|
err = json.Unmarshal([]byte(flowVersionInfo.Content), &flowVersionCont)
|
|
if err != nil {
|
|
publicmethod.Result(104, err, c)
|
|
return
|
|
}
|
|
publicmethod.Result(0, flowVersionCont, c)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-10-27 14:41:00
|
|
@ 功能: 编辑工作流
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) EditFlowCont(c *gin.Context) {
|
|
var requestData EditFlowInfo
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil || requestData.Id == "" {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
why := publicmethod.MapOut[string]()
|
|
why["`id`"] = requestData.Id
|
|
var flowVersionInfo modelAppPlatform.FlowVersion
|
|
err = flowVersionInfo.GetCont(why)
|
|
if err != nil {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
var userList []string
|
|
var orgList []string
|
|
isFormWrite := false
|
|
if len(requestData.FlowInfo.FlowPermission) > 0 {
|
|
for _, v := range requestData.FlowInfo.FlowPermission {
|
|
if v.Types == 3 {
|
|
// orgId, _ := strconv.ParseInt(v.TargetId, 10, 64)
|
|
orgList = append(orgList, v.TargetId)
|
|
isFormWrite = true
|
|
}
|
|
if v.Types == 1 {
|
|
// userId, _ := strconv.ParseInt(v.TargetId, 10, 64)
|
|
userList = append(userList, v.TargetId)
|
|
isFormWrite = true
|
|
}
|
|
}
|
|
}
|
|
editInfo := publicmethod.MapOut[string]()
|
|
jsonCont, _ := json.Marshal(requestData.FlowInfo)
|
|
editInfo["`content`"] = jsonCont
|
|
editInfo["`time`"] = time.Now().Unix()
|
|
saveData := publicmethod.MapOut[string]()
|
|
var customerForm modelAppPlatform.CustomerForm
|
|
err = customerForm.GetCont(map[string]interface{}{"`id`": flowVersionInfo.FormKey}, "`permitstr`", "`userpermit`")
|
|
if isFormWrite {
|
|
|
|
if err == nil {
|
|
|
|
if len(orgList) > 0 {
|
|
if customerForm.PermitStr != "" {
|
|
oldOrgList := strings.Split(customerForm.PermitStr, ",")
|
|
orgNew := publicmethod.MergeStruct(orgList, oldOrgList)
|
|
saveData["permitstr"] = strings.Join(orgNew, ",")
|
|
editInfo["orgpermit"] = strings.Join(orgNew, ",")
|
|
}
|
|
} else {
|
|
editInfo["orgpermit"] = customerForm.PermitStr
|
|
}
|
|
if len(userList) > 0 {
|
|
if customerForm.UserPermit != "" {
|
|
oldUserList := strings.Split(customerForm.UserPermit, ",")
|
|
userNew := publicmethod.MergeStruct(userList, oldUserList)
|
|
saveData["userpermit"] = strings.Join(userNew, ",")
|
|
editInfo["userpermit"] = strings.Join(userNew, ",")
|
|
}
|
|
} else {
|
|
editInfo["userpermit"] = customerForm.UserPermit
|
|
}
|
|
|
|
}
|
|
}
|
|
err = flowVersionInfo.EiteCont(why, editInfo)
|
|
if err != nil {
|
|
publicmethod.Result(106, err, c)
|
|
return
|
|
}
|
|
saveData["flowkey"] = flowVersionInfo.Key
|
|
saveData["classify"] = 2
|
|
saveData["edit_time"] = time.Now().Unix()
|
|
customerForm.EiteCont(map[string]interface{}{"`id`": flowVersionInfo.FormKey}, saveData)
|
|
|
|
publicmethod.Result(0, err, c)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-10-27 15:54:31
|
|
@ 功能: 另存为新版
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) SaveNewFlow(c *gin.Context) {
|
|
var requestData EditFlowInfo
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil || requestData.Id == "" {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
why := publicmethod.MapOut[string]()
|
|
why["`id`"] = requestData.Id
|
|
var flowVersionInfo modelAppPlatform.FlowVersion
|
|
err = flowVersionInfo.GetCont(why)
|
|
if err != nil {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
uuid := flowVersionInfo.Key
|
|
publicTime := time.Now().Unix()
|
|
var numVal int64
|
|
var flowVersion modelAppPlatform.WorkFlowVersion
|
|
overall.CONSTANT_DB_AppPlatform.Model(&flowVersion).Where("`key` = ?", uuid).Count(&numVal)
|
|
flowVersion.Key = uuid
|
|
flowVersion.Version = strconv.FormatInt(numVal+1, 10)
|
|
var isVersionNum int64
|
|
overall.CONSTANT_DB_AppPlatform.Model(&flowVersion).Where("`state` = 1 AND `key` = ?", uuid).Count(&isVersionNum)
|
|
flowVersion.State = 1
|
|
if isVersionNum > 0 {
|
|
flowVersion.State = 2
|
|
}
|
|
flowVersion.Time = publicTime
|
|
jsonCont, _ := json.Marshal(requestData.FlowInfo)
|
|
flowVersion.Content = string(jsonCont)
|
|
var userList []string
|
|
var orgList []string
|
|
isFormWrite := false
|
|
if len(requestData.FlowInfo.FlowPermission) > 0 {
|
|
for _, v := range requestData.FlowInfo.FlowPermission {
|
|
if v.Types == 3 {
|
|
// orgId, _ := strconv.ParseInt(v.TargetId, 10, 64)
|
|
orgList = append(orgList, v.TargetId)
|
|
isFormWrite = true
|
|
}
|
|
if v.Types == 1 {
|
|
// userId, _ := strconv.ParseInt(v.TargetId, 10, 64)
|
|
userList = append(userList, v.TargetId)
|
|
isFormWrite = true
|
|
}
|
|
}
|
|
}
|
|
var customerForm modelAppPlatform.CustomerForm
|
|
err = customerForm.GetCont(map[string]interface{}{"`id`": flowVersionInfo.FormKey}, "`permitstr`", "`userpermit`")
|
|
saveData := publicmethod.MapOut[string]()
|
|
if isFormWrite {
|
|
|
|
if err == nil {
|
|
|
|
if len(orgList) > 0 {
|
|
if customerForm.PermitStr != "" {
|
|
oldOrgList := strings.Split(customerForm.PermitStr, ",")
|
|
orgNew := publicmethod.MergeStruct(orgList, oldOrgList)
|
|
saveData["permitstr"] = strings.Join(orgNew, ",")
|
|
flowVersion.OrgPermit = strings.Join(orgNew, ",")
|
|
}
|
|
} else {
|
|
flowVersion.OrgPermit = customerForm.PermitStr
|
|
}
|
|
if len(userList) > 0 {
|
|
if customerForm.UserPermit != "" {
|
|
oldUserList := strings.Split(customerForm.UserPermit, ",")
|
|
userNew := publicmethod.MergeStruct(userList, oldUserList)
|
|
saveData["userpermit"] = strings.Join(userNew, ",")
|
|
flowVersion.UserPermit = strings.Join(userNew, ",")
|
|
}
|
|
} else {
|
|
flowVersion.UserPermit = customerForm.UserPermit
|
|
}
|
|
saveData["flowkey"] = uuid
|
|
// if len(saveData) > 0 {
|
|
// saveData["edit_time"] = time.Now().Unix()
|
|
// customerForm.EiteCont(map[string]interface{}{"`id`": flowVersionInfo.FormKey}, saveData)
|
|
// }
|
|
}
|
|
}
|
|
err = flowVersion.InSetCont()
|
|
if err != nil {
|
|
publicmethod.Result(104, err, c)
|
|
return
|
|
}
|
|
saveData["flowkey"] = flowVersionInfo.Key
|
|
saveData["classify"] = 2
|
|
saveData["edit_time"] = time.Now().Unix()
|
|
customerForm.EiteCont(map[string]interface{}{"`id`": flowVersionInfo.FormKey}, saveData)
|
|
publicmethod.Result(0, err, c)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-10-27 16:33:54
|
|
@ 功能: 启用&禁用
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) SwitchFlowVersion(c *gin.Context) {
|
|
var requestData SwitchFlowStatus
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil || requestData.Id == "" {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
if requestData.Status == 0 {
|
|
requestData.Status = 2
|
|
}
|
|
why := publicmethod.MapOut[string]()
|
|
why["`id`"] = requestData.Id
|
|
var flowVersionInfo modelAppPlatform.FlowVersion
|
|
err = flowVersionInfo.GetCont(why)
|
|
if err != nil {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
publicTime := time.Now().Unix()
|
|
var flowVersionCont modelAppPlatform.WorkFlowVersion
|
|
saveVersion := publicmethod.MapOut[string]()
|
|
saveVersion["`state`"] = requestData.Status
|
|
saveVersion["`time`"] = publicTime
|
|
var isVersionNum int64
|
|
overall.CONSTANT_DB_AppPlatform.Model(&flowVersionCont).Where("`state` = 1 AND `key` = ?", flowVersionInfo.Key).Count(&isVersionNum)
|
|
if requestData.Status == 1 {
|
|
if isVersionNum < 1 {
|
|
err = flowVersionCont.EiteCont(why, saveVersion)
|
|
if err == nil {
|
|
var flowInfo modelAppPlatform.WorkFlow
|
|
err = flowInfo.EiteCont(map[string]interface{}{"`id`": flowVersionInfo.Key}, map[string]interface{}{"`state`": requestData.Status, "`time`": publicTime})
|
|
}
|
|
} else {
|
|
err = flowVersionCont.EiteCont(map[string]interface{}{"`key`": flowVersionInfo.Key}, map[string]interface{}{"`state`": 2, "`time`": publicTime})
|
|
if err == nil {
|
|
err = flowVersionCont.EiteCont(why, saveVersion)
|
|
}
|
|
}
|
|
} else {
|
|
err = flowVersionCont.EiteCont(why, saveVersion)
|
|
if isVersionNum <= 1 {
|
|
if err == nil {
|
|
var flowInfo modelAppPlatform.WorkFlow
|
|
err = flowInfo.EiteCont(map[string]interface{}{"`id`": flowVersionInfo.Key}, map[string]interface{}{"`state`": requestData.Status, "`time`": publicTime})
|
|
}
|
|
}
|
|
}
|
|
if err != nil {
|
|
publicmethod.Result(104, err, c)
|
|
return
|
|
}
|
|
publicmethod.Result(0, err, c)
|
|
}
|
|
|