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

303 lines
8.5 KiB

3 days ago
package taskflowing
import (
"appPlatform/overall/publicmethod"
"encoding/json"
"fmt"
"sort"
"github.com/gin-gonic/gin"
)
// 解析表单格式
func (a *ApiMethod) AnalyFormJsonMap(c *gin.Context) {
var requestData AnalysisNodesUnitPower
err := c.ShouldBindJSON(&requestData)
if err != nil {
publicmethod.Result(100, err, c)
return
}
if requestData.NodeKey == "" {
requestData.NodeKey = "begin"
}
var unitCont TypesAnalysisNodesUnit
json.Unmarshal([]byte(requestData.NodeJson), &unitCont.UnitList) //获取当前表单Json配置数据
var flowUnit FlowTypeKeyWordAry
if purviewList, ok := unitCont.UnitList["purview"]; ok {
if purviewAry, ok := purviewList.([]interface{}); ok {
for _, v := range purviewAry {
if vMap, ok := v.(map[string]interface{}); ok {
if nodeKey, ok := vMap["nodeKey"]; ok {
if publicmethod.TypeToInterface(nodeKey) == requestData.NodeKey {
if powerList, ok := vMap["powerAry"]; ok {
if powerListAry, ok := powerList.([]interface{}); ok {
flowUnit.NodePower = SplitNodeUnitPurviewNew(powerListAry)
}
}
}
}
}
}
// recUnitAry = SplitNodeUnitPurviewNew(purviewAry)
}
}
// fmt.Printf("授权清空\n%T----------------%v\n\n", flowUnit, flowUnit)
//获取组件
if list, ok := unitCont.UnitList["list"]; ok {
if listAry, ok := list.([]interface{}); ok {
var mainTable FlowTypeKeyWord
mainTable.Id = "masterid"
mainTable.Name = "主表"
mainTable.IsEdit = true
mainTable.IsLook = true
mainTable.Status = 4
mainTable.Sort = 0
flowUnit.SplitComponents(mainTable, listAry)
}
}
sort.Slice(flowUnit.ListAry, func(i, j int) bool {
return flowUnit.ListAry[i].Sort < flowUnit.ListAry[j].Sort
})
sendData := publicmethod.MapOut[string]()
sendData["nodeKey"] = requestData.NodeKey
sendData["recUnitAry"] = flowUnit.ListAry
publicmethod.Result(0, sendData, c)
}
/*
*
@ 作者: 秦东
@ 时间: 2024-03-14 08:38:32
@ 功能: 拆分节点已有得权限
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func SplitNodeUnitPurviewNew(purviewAry []interface{}) (nodeUnitPowerAry []NodesUnitNameStatue) {
jsonCont, jsonErr := json.Marshal(purviewAry)
// fmt.Printf("purviewList:%T--->%v--->%v\n", jsonCont, jsonErr, string(jsonCont))
if jsonErr == nil {
json.Unmarshal(jsonCont, &nodeUnitPowerAry)
}
return
}
// 拆分组件
func (f *FlowTypeKeyWordAry) SplitComponents(tableInfo FlowTypeKeyWord, unitList []interface{}) {
var masterUnit []NodesUnitNameStatue
for i, v := range unitList {
if mapVal, ok := v.(map[string]interface{}); ok {
if mapType, ok := mapVal["type"]; ok { //获取组件类型
// fmt.Printf("\n====1======\n%v:\n%v\n======1====\n", i, mapType)
unitName := ""
unitLabelName := ""
if mapName, ok := mapVal["name"]; ok {
unitName = publicmethod.TypeToInterface(mapName)
}
if item, ok := mapVal["item"]; ok {
if itemMap, ok := item.(map[string]interface{}); ok {
if itemName, ok := itemMap["label"]; ok {
unitLabelName = publicmethod.TypeToInterface(itemName)
}
}
}
switch mapType {
case "flex":
var mainTable FlowTypeKeyWord
mainTable.Id = unitName
if unitLabelName == "" {
if mapName, ok := mapVal["unitName"]; ok {
mainTable.Name = publicmethod.TypeToInterface(mapName)
}
} else {
mainTable.Name = unitLabelName
}
// mainTable.IsEdit = true
// mainTable.IsLook = true
mainTable.IsLook, mainTable.IsEdit, mainTable.Status = f.JuadgeUnitStatus(unitName)
// mainTable.Status = 4
mainTable.Sort = i + 1
if list, ok := mapVal["list"]; ok {
if listAry, ok := list.([]interface{}); ok {
f.SplitComponents(mainTable, listAry)
}
}
case "table":
var mainTable FlowTypeKeyWord
mainTable.Id = unitName
if unitLabelName == "" {
if mapName, ok := mapVal["unitName"]; ok {
mainTable.Name = publicmethod.TypeToInterface(mapName)
}
} else {
mainTable.Name = unitLabelName
}
// mainTable.IsEdit = true
// mainTable.IsLook = true
mainTable.IsLook, mainTable.IsEdit, mainTable.Status = f.JuadgeUnitStatus(unitName)
// mainTable.Status = 4
mainTable.Sort = i + 1
if list, ok := mapVal["list"]; ok {
if listAry, ok := list.([]interface{}); ok {
f.SplitComponents(mainTable, listAry)
}
}
case "grid":
var mainTable FlowTypeKeyWord
if unitName == "" {
mainTable.Id = fmt.Sprintf("%v_%v", mapType, i)
} else {
mainTable.Id = unitName
}
if unitLabelName == "" {
if mapName, ok := mapVal["unitName"]; ok {
mainTable.Name = publicmethod.TypeToInterface(mapName)
}
} else {
mainTable.Name = unitLabelName
}
// mainTable.IsEdit = true
// mainTable.IsLook = true
mainTable.IsLook, mainTable.IsEdit, mainTable.Status = f.JuadgeUnitStatus(unitName)
mainTable.Sort = i + 1
// mainTable.Status = 4
if columnsList, ok := mapVal["columns"]; ok {
if listAry, ok := columnsList.([]interface{}); ok {
for _, colVal := range listAry {
if colList, ok := colVal.(map[string]interface{}); ok {
if listMap, ok := colList["list"]; ok {
if colListAry, ok := listMap.([]interface{}); ok {
f.SplitComponents(mainTable, colListAry)
}
}
}
}
}
}
case "tabs":
var mainTable FlowTypeKeyWord
if unitName == "" {
mainTable.Id = fmt.Sprintf("%v_%v", mapType, i)
} else {
mainTable.Id = unitName
}
if unitLabelName == "" {
if mapName, ok := mapVal["unitName"]; ok {
mainTable.Name = publicmethod.TypeToInterface(mapName)
}
} else {
mainTable.Name = unitLabelName
}
// mainTable.IsEdit = true
// mainTable.IsLook = true
mainTable.IsLook, mainTable.IsEdit, mainTable.Status = f.JuadgeUnitStatus(unitName)
// mainTable.Status = 4
mainTable.Sort = i + 1
if columnsList, ok := mapVal["columns"]; ok {
if listAry, ok := columnsList.([]interface{}); ok {
for ci, colVal := range listAry {
if colList, ok := colVal.(map[string]interface{}); ok {
if mapName, ok := colList["label"]; ok {
mainTable.Name = publicmethod.TypeToInterface(mapName)
}
mainTable.Id = fmt.Sprintf("%v_%v", mainTable.Id, ci)
if listMap, ok := colList["list"]; ok {
if colListAry, ok := listMap.([]interface{}); ok {
f.SplitComponents(mainTable, colListAry)
}
}
}
}
}
}
case "card", "div":
// fmt.Printf("\n===普通容器,无需授权组装=======\n%v:\n%v\n==========\n", i, mapType)
if list, ok := mapVal["list"]; ok {
if listAry, ok := list.([]interface{}); ok {
f.SplitComponents(tableInfo, listAry)
}
}
case "title", "txt", "button":
// fmt.Printf("\n===无需授权组装=======\n%v:\n%v\n==========\n", i, mapType)
default:
var masterMainUnit NodesUnitNameStatue
masterMainUnit.Id = unitName
masterMainUnit.Name = unitLabelName
// masterMainUnit.IsEdit = true
// masterMainUnit.IsLook = true
masterMainUnit.IsLook, masterMainUnit.IsEdit, masterMainUnit.Status = f.JuadgeUnitStatus(unitName)
// masterMainUnit.Status = 4
masterUnit = append(masterUnit, masterMainUnit)
}
}
}
}
// jsonByte, err := json.Marshal(masterUnit)
// fmt.Printf("\n====2======\n%v:\n%v\n\n%v\n=====2=====\n", err, string(jsonByte), tableInfo)
if len(masterUnit) > 0 {
isNew := true
// fmt.Printf("\n=---------%v--------->\n=", len(f.ListAry))
if len(f.ListAry) > 0 {
for i, v := range f.ListAry {
// fmt.Printf("\n=---------%v-----%v-----%v--------->\n=", v.Id, tableInfo.Id, v.Id == tableInfo.Id)
if v.Id == tableInfo.Id {
isNew = false
f.ListAry[i].List = append(f.ListAry[i].List, masterUnit...)
}
}
if isNew {
tableInfo.List = append(tableInfo.List, masterUnit...)
f.ListAry = append(f.ListAry, tableInfo)
}
} else {
tableInfo.List = append(tableInfo.List, masterUnit...)
f.ListAry = append(f.ListAry, tableInfo)
}
}
}
// 判断组件授权状态
func (f *FlowTypeKeyWordAry) JuadgeUnitStatus(key string) (isLook, isErit bool, states int) {
isLook = true
isErit = true
for _, v := range f.NodePower {
if v.Id == key {
isLook = v.IsLook
isErit = v.IsEdit
}
}
if isLook && isErit {
states = 4
} else if isLook && !isErit {
states = 3
} else if !isLook && isErit {
states = 2
} else {
states = 1
}
return
}