duyong пре 3 месеци
родитељ
комит
4d3ffc2ada

+ 4 - 4
approve_former/and.go

@@ -3,10 +3,10 @@ package approve_former
 import "strings"
 
 type And struct {
-	childNodes []Node
+	childNodes []Noder
 }
 
-func NewAnd(childNodes ...Node) *And {
+func NewAnd(childNodes ...Noder) *And {
 	return &And{
 		childNodes: childNodes,
 	}
@@ -38,7 +38,7 @@ func (and *And) GetWhen() string {
 	return when
 }
 
-func (and *And) AddNodes(childNodes ...Node) *And {
+func (and *And) AddNodes(childNodes ...Noder) *And {
 	if childNodes == nil || len(childNodes) == 0 {
 		and.childNodes = append(and.childNodes, childNodes...)
 	}
@@ -46,7 +46,7 @@ func (and *And) AddNodes(childNodes ...Node) *And {
 	return and
 }
 
-func (and *And) Render(upperNode Node) (string, error) {
+func (and *And) Render(upperNode Noder) (string, error) {
 	var content string
 
 	for _, childNode := range and.childNodes {

+ 11 - 12
approve_former/flow.go

@@ -7,33 +7,32 @@ kind: WorkflowTemplate
 metadata:
   name: [[ .name ]]
 spec:
-  entrypoint: approve-flow
+  entrypoint: front_json-flow
   arguments:
     parameters:
       - name: object
         value: {}
 
   templates:
-    - name: approve-flow
+    - name: front_json-flow
       inputs:
         parameters:
           - name: object
-      dag:
-        tasks:
+      steps:
           [[- if .childNodesContentLines ]]
           [[- range .childNodesContentLines ]]
           [[ . ]]
           [[- end ]]
           [[- else ]]
-          - name: node
+          - name: parse_flow
             template: approval
           [[- end ]]
-          
+
     - name: approval
       suspend: {}
       inputs:
         parameters:
-          - name: approve
+          - name: front_json
             default: '通过'
             enum:
               - '通过'
@@ -41,16 +40,16 @@ spec:
               - '忽略'
       outputs:
         parameters:
-          - name: approve
+          - name: front_json
             valueFrom:
               supplied: {}`
 
 type Flow struct {
 	name       string
-	childNodes []Node
+	childNodes []Noder
 }
 
-func NewFlow(name string, childNodes ...Node) *Flow {
+func NewFlow(name string, childNodes ...Noder) *Flow {
 	return &Flow{
 		name:       name,
 		childNodes: childNodes,
@@ -65,7 +64,7 @@ func (flow *Flow) GetWhen() string {
 	return ""
 }
 
-func (flow *Flow) AddNodes(childNodes ...Node) *Flow {
+func (flow *Flow) AddNodes(childNodes ...Noder) *Flow {
 	if childNodes == nil || len(childNodes) == 0 {
 		flow.childNodes = append(flow.childNodes, childNodes...)
 	}
@@ -73,7 +72,7 @@ func (flow *Flow) AddNodes(childNodes ...Node) *Flow {
 	return flow
 }
 
-func (flow *Flow) Render(_ Node) (string, error) {
+func (flow *Flow) Render(_ Noder) (string, error) {
 	childNodesContents := make([]string, 0)
 	for i, childNode := range flow.childNodes {
 		var childNodeContent string

+ 138 - 0
approve_former/front_json/approval_next_user.json

@@ -0,0 +1,138 @@
+{
+  "name": "发起人",
+  "desc": "任何人",
+  "type": "ROOT",
+  "parentId": null,
+  "id": "root",
+  "props": {
+    "assignedUser": [
+
+    ],
+    "formPerms": [
+
+    ]
+  },
+  "children": {
+    "id": "EBp1GrFpnp8o86p1",
+    "name": "审批人",
+    "type": "APPROVAL",
+    "props": {
+      "assignedType": "ASSIGN_USER",
+      "mode": "NEXT",
+      "sign": false,
+      "nobody": {
+        "handler": "TO_PASS",
+        "assignedUser": [
+
+        ],
+        "assignedRole": [
+
+        ]
+      },
+      "timeLimit": {
+        "timeout": {
+          "unit": "H",
+          "value": 0
+        },
+        "handler": {
+          "type": "REFUSE",
+          "notify": {
+            "once": true,
+            "hour": 1
+          }
+        }
+      },
+      "assignedUser": [
+        {
+          "type": "user",
+          "subjectId": "39ada31e4e784fe981dd31d390bb6ad4",
+          "name": "张建东",
+          "id": "39ada31e4e784fe981dd31d390bb6ad4"
+        },
+        {
+          "type": "user",
+          "subjectId": "5ee809c560cf4fc78c3755c17f177c54",
+          "name": "任鹏飞",
+          "id": "5ee809c560cf4fc78c3755c17f177c54"
+        }
+      ],
+      "assignedRole": [
+
+      ],
+      "formPerms": [
+        {
+          "id": "field4368279468887",
+          "title": "名称",
+          "required": true,
+          "perm": "R"
+        }
+      ],
+      "selfSelect": {
+        "multiple": false
+      },
+      "leaderTop": {
+        "endCondition": "TOP",
+        "endLevel": 1
+      },
+      "leader": {
+        "level": 1
+      },
+      "role": [
+
+      ],
+      "refuse": {
+        "type": "TO_END",
+        "target": ""
+      },
+      "formUser": "",
+      "passHttp": {
+        "method": "POST",
+        "url": "abc.com",
+        "headers": [
+          {
+            "name": "",
+            "isField": true,
+            "value": ""
+          }
+        ],
+        "contentType": "JSON",
+        "params": [
+          {
+            "name": "",
+            "isField": true,
+            "value": ""
+          }
+        ],
+        "retry": 1,
+        "handlerByScript": false,
+        "success": "function handlerOk(res) {\n  return true;\n}",
+        "fail": "function handlerFail(res) {\n  return true;\n}"
+      },
+      "rejectHttp": {
+        "method": "POST",
+        "url": "abc.com",
+        "headers": [
+          {
+            "name": "",
+            "isField": true,
+            "value": ""
+          }
+        ],
+        "contentType": "JSON",
+        "params": [
+          {
+            "name": "",
+            "isField": true,
+            "value": ""
+          }
+        ],
+        "retry": 1,
+        "handlerByScript": false,
+        "success": "function handlerOk(res) {\n  return true;\n}",
+        "fail": "function handlerFail(res) {\n  return true;\n}"
+      }
+    },
+    "error": false,
+    "ParentID": "root"
+  }
+}

+ 138 - 0
approve_former/front_json/approval_or_user.json

@@ -0,0 +1,138 @@
+{
+  "name": "发起人",
+  "desc": "任何人",
+  "type": "ROOT",
+  "parentId": null,
+  "id": "root",
+  "props": {
+    "assignedUser": [
+
+    ],
+    "formPerms": [
+
+    ]
+  },
+  "children": {
+    "id": "3KbuWYgbmBmSTY6s",
+    "name": "审批人",
+    "type": "APPROVAL",
+    "props": {
+      "assignedType": "ASSIGN_USER",
+      "mode": "OR",
+      "sign": false,
+      "nobody": {
+        "handler": "TO_PASS",
+        "assignedUser": [
+
+        ],
+        "assignedRole": [
+
+        ]
+      },
+      "timeLimit": {
+        "timeout": {
+          "unit": "H",
+          "value": 0
+        },
+        "handler": {
+          "type": "REFUSE",
+          "notify": {
+            "once": true,
+            "hour": 1
+          }
+        }
+      },
+      "assignedUser": [
+        {
+          "type": "user",
+          "subjectId": "39ada31e4e784fe981dd31d390bb6ad4",
+          "name": "张建东",
+          "id": "39ada31e4e784fe981dd31d390bb6ad4"
+        },
+        {
+          "type": "user",
+          "subjectId": "5ee809c560cf4fc78c3755c17f177c54",
+          "name": "任鹏飞",
+          "id": "5ee809c560cf4fc78c3755c17f177c54"
+        }
+      ],
+      "assignedRole": [
+
+      ],
+      "formPerms": [
+        {
+          "id": "field4368279468887",
+          "title": "名称",
+          "required": true,
+          "perm": "R"
+        }
+      ],
+      "selfSelect": {
+        "multiple": false
+      },
+      "leaderTop": {
+        "endCondition": "TOP",
+        "endLevel": 1
+      },
+      "leader": {
+        "level": 1
+      },
+      "role": [
+
+      ],
+      "refuse": {
+        "type": "TO_END",
+        "target": ""
+      },
+      "formUser": "",
+      "passHttp": {
+        "method": "POST",
+        "url": "abc.com",
+        "headers": [
+          {
+            "name": "",
+            "isField": true,
+            "value": ""
+          }
+        ],
+        "contentType": "JSON",
+        "params": [
+          {
+            "name": "",
+            "isField": true,
+            "value": ""
+          }
+        ],
+        "retry": 1,
+        "handlerByScript": false,
+        "success": "function handlerOk(res) {\n  return true;\n}",
+        "fail": "function handlerFail(res) {\n  return true;\n}"
+      },
+      "rejectHttp": {
+        "method": "POST",
+        "url": "abc.com",
+        "headers": [
+          {
+            "name": "",
+            "isField": true,
+            "value": ""
+          }
+        ],
+        "contentType": "JSON",
+        "params": [
+          {
+            "name": "",
+            "isField": true,
+            "value": ""
+          }
+        ],
+        "retry": 1,
+        "handlerByScript": false,
+        "success": "function handlerOk(res) {\n  return true;\n}",
+        "fail": "function handlerFail(res) {\n  return true;\n}"
+      }
+    },
+    "error": false,
+    "ParentID": "root"
+  }
+}

+ 15 - 0
approve_former/front_json/empty.json

@@ -0,0 +1,15 @@
+{
+  "name": "发起人",
+  "desc": "任何人",
+  "type": "ROOT",
+  "parentId": null,
+  "id": "root",
+  "props": {
+    "assignedUser": [
+
+    ],
+    "formPerms": [
+
+    ]
+  }
+}

+ 789 - 0
approve_former/front_json/full.json

@@ -0,0 +1,789 @@
+{
+  "name": "发起人",
+  "desc": "任何人",
+  "type": "ROOT",
+  "parentId": null,
+  "id": "root",
+  "props": {
+    "assignedUser": [
+
+    ],
+    "formPerms": [
+
+    ]
+  },
+  "children": {
+    "id": "2QsXrpyaBmfctjCO",
+    "name": "条件分支",
+    "type": "CONDITIONS",
+    "children": {
+      "id": "eZMFYWfhAOeVK5Hn",
+      "name": "审批人",
+      "type": "APPROVAL",
+      "props": {
+        "assignedType": "ROLE",
+        "mode": "OR",
+        "sign": false,
+        "nobody": {
+          "handler": "TO_PASS",
+          "assignedUser": [
+
+          ],
+          "assignedRole": [
+
+          ]
+        },
+        "timeLimit": {
+          "timeout": {
+            "unit": "H",
+            "value": 0
+          },
+          "handler": {
+            "type": "REFUSE",
+            "notify": {
+              "once": true,
+              "hour": 1
+            }
+          }
+        },
+        "assignedUser": [
+
+        ],
+        "assignedRole": [
+          {
+            "type": "role",
+            "roleCode": "ShopProduction",
+            "name": "生产角色",
+            "id": "7a850e527ef64206b7317b2163df3b4d"
+          },
+          {
+            "type": "role",
+            "roleCode": "purchase",
+            "name": "采购角色",
+            "id": "f37721336f414371844954dda7362016"
+          }
+        ],
+        "formPerms": [
+          {
+            "id": "field4368279468887",
+            "title": "名称",
+            "required": true,
+            "perm": "R"
+          }
+        ],
+        "selfSelect": {
+          "multiple": false
+        },
+        "leaderTop": {
+          "endCondition": "TOP",
+          "endLevel": 1
+        },
+        "leader": {
+          "level": 1
+        },
+        "role": [
+
+        ],
+        "refuse": {
+          "type": "TO_END",
+          "target": ""
+        },
+        "formUser": "",
+        "passHttp": {
+          "method": "POST",
+          "url": "",
+          "headers": [
+            {
+              "name": "",
+              "isField": true,
+              "value": ""
+            }
+          ],
+          "contentType": "JSON",
+          "params": [
+            {
+              "name": "",
+              "isField": true,
+              "value": ""
+            }
+          ],
+          "retry": 1,
+          "handlerByScript": false,
+          "success": "function handlerOk(res) {\n  return true;\n}",
+          "fail": "function handlerFail(res) {\n  return true;\n}"
+        },
+        "rejectHttp": {
+          "method": "POST",
+          "url": "",
+          "headers": [
+            {
+              "name": "",
+              "isField": true,
+              "value": ""
+            }
+          ],
+          "contentType": "JSON",
+          "params": [
+            {
+              "name": "",
+              "isField": true,
+              "value": ""
+            }
+          ],
+          "retry": 1,
+          "handlerByScript": false,
+          "success": "function handlerOk(res) {\n  return true;\n}",
+          "fail": "function handlerFail(res) {\n  return true;\n}"
+        }
+      },
+      "subjects": [
+
+      ],
+      "examineMode": 1,
+      "noHanderAction": 2,
+      "error": false,
+      "children": {
+        "id": "MHPZqWEyYgJGMPUx",
+        "name": "审批人",
+        "type": "APPROVAL",
+        "props": {
+          "assignedType": "ROLE",
+          "mode": "NEXT",
+          "sign": false,
+          "nobody": {
+            "handler": "TO_PASS",
+            "assignedUser": [
+
+            ],
+            "assignedRole": [
+
+            ]
+          },
+          "timeLimit": {
+            "timeout": {
+              "unit": "H",
+              "value": 0
+            },
+            "handler": {
+              "type": "REFUSE",
+              "notify": {
+                "once": true,
+                "hour": 1
+              }
+            }
+          },
+          "assignedUser": [
+
+          ],
+          "assignedRole": [
+            {
+              "type": "role",
+              "roleCode": "SystemRole",
+              "name": "系统角色",
+              "id": "55f34936cec747f9b0c70030cc240b37"
+            },
+            {
+              "type": "role",
+              "roleCode": "dispatch",
+              "name": "调度角色",
+              "id": "28e756b7deb2495e896f59b2b93c0ca3"
+            }
+          ],
+          "formPerms": [
+            {
+              "id": "field4368279468887",
+              "title": "名称",
+              "required": true,
+              "perm": "R"
+            }
+          ],
+          "selfSelect": {
+            "multiple": false
+          },
+          "leaderTop": {
+            "endCondition": "TOP",
+            "endLevel": 1
+          },
+          "leader": {
+            "level": 1
+          },
+          "role": [
+
+          ],
+          "refuse": {
+            "type": "TO_END",
+            "target": ""
+          },
+          "formUser": "",
+          "passHttp": {
+            "method": "POST",
+            "url": "abc.com",
+            "headers": [
+              {
+                "name": "",
+                "isField": true,
+                "value": ""
+              }
+            ],
+            "contentType": "JSON",
+            "params": [
+              {
+                "name": "",
+                "isField": true,
+                "value": ""
+              }
+            ],
+            "retry": 1,
+            "handlerByScript": false,
+            "success": "function handlerOk(res) {\n  return true;\n}",
+            "fail": "function handlerFail(res) {\n  return true;\n}"
+          },
+          "rejectHttp": {
+            "method": "POST",
+            "url": "abc.com",
+            "headers": [
+              {
+                "name": "",
+                "isField": true,
+                "value": ""
+              }
+            ],
+            "contentType": "JSON",
+            "params": [
+              {
+                "name": "",
+                "isField": true,
+                "value": ""
+              }
+            ],
+            "retry": 1,
+            "handlerByScript": false,
+            "success": "function handlerOk(res) {\n  return true;\n}",
+            "fail": "function handlerFail(res) {\n  return true;\n}"
+          }
+        },
+        "error": false,
+        "subjects": [
+
+        ],
+        "examineMode": 1,
+        "noHanderAction": 2,
+        "children": {
+          "id": "9O6B8Mw4pFXwjejC",
+          "name": "并行分支",
+          "type": "CONCURRENTS",
+          "children": {
+            "id": "tB82T0goweCcKe76",
+            "name": "审批人",
+            "type": "APPROVAL",
+            "props": {
+              "assignedType": "LEADER",
+              "mode": "OR",
+              "sign": false,
+              "nobody": {
+                "handler": "TO_PASS",
+                "assignedUser": [
+
+                ],
+                "assignedRole": [
+
+                ]
+              },
+              "timeLimit": {
+                "timeout": {
+                  "unit": "H",
+                  "value": 0
+                },
+                "handler": {
+                  "type": "REFUSE",
+                  "notify": {
+                    "once": true,
+                    "hour": 1
+                  }
+                }
+              },
+              "assignedUser": [
+
+              ],
+              "assignedRole": [
+
+              ],
+              "formPerms": [
+                {
+                  "id": "field4368279468887",
+                  "title": "名称",
+                  "required": true,
+                  "perm": "R"
+                }
+              ],
+              "selfSelect": {
+                "multiple": false
+              },
+              "leaderTop": {
+                "endCondition": "TOP",
+                "endLevel": 1
+              },
+              "leader": {
+                "level": 1
+              },
+              "role": [
+
+              ],
+              "refuse": {
+                "type": "TO_END",
+                "target": ""
+              },
+              "formUser": "",
+              "passHttp": {
+                "method": "POST",
+                "url": "abc.com",
+                "headers": [
+                  {
+                    "name": "",
+                    "isField": true,
+                    "value": ""
+                  }
+                ],
+                "contentType": "JSON",
+                "params": [
+                  {
+                    "name": "",
+                    "isField": true,
+                    "value": ""
+                  }
+                ],
+                "retry": 1,
+                "handlerByScript": false,
+                "success": "function handlerOk(res) {\n  return true;\n}",
+                "fail": "function handlerFail(res) {\n  return true;\n}"
+              },
+              "rejectHttp": {
+                "method": "POST",
+                "url": "abc.com",
+                "headers": [
+                  {
+                    "name": "",
+                    "isField": true,
+                    "value": ""
+                  }
+                ],
+                "contentType": "JSON",
+                "params": [
+                  {
+                    "name": "",
+                    "isField": true,
+                    "value": ""
+                  }
+                ],
+                "retry": 1,
+                "handlerByScript": false,
+                "success": "function handlerOk(res) {\n  return true;\n}",
+                "fail": "function handlerFail(res) {\n  return true;\n}"
+              }
+            },
+            "subjects": [
+
+            ],
+            "examineMode": 1,
+            "noHanderAction": 2,
+            "error": false,
+            "ParentID": "9O6B8Mw4pFXwjejC"
+          },
+          "branchs": [
+            {
+              "id": "node_371077991169",
+              "name": "分支1",
+              "parentId": "node_371077998976",
+              "type": "CONCURRENT",
+              "props": {
+
+              },
+              "children": {
+                "id": "xApb9fqSPqZt13Tk",
+                "name": "抄送人",
+                "children": {
+
+                },
+                "type": "CC",
+                "props": {
+                  "shouldAdd": false,
+                  "assignedUser": [
+                    {
+                      "type": "user",
+                      "subjectId": "39ada31e4e784fe981dd31d390bb6ad4",
+                      "name": "张建东",
+                      "id": "39ada31e4e784fe981dd31d390bb6ad4"
+                    },
+                    {
+                      "type": "user",
+                      "subjectId": "3eb29f623e194916acf67732a9a8b040",
+                      "name": "张东峰",
+                      "id": "3eb29f623e194916acf67732a9a8b040"
+                    }
+                  ],
+                  "assignedRole": [
+
+                  ],
+                  "formPerms": [
+                    {
+                      "id": "field4368279468887",
+                      "title": "名称",
+                      "required": true,
+                      "perm": "R"
+                    }
+                  ]
+                },
+                "ccSelfSelectFlag": 0,
+                "error": false
+              },
+              "typeElse": false
+            },
+            {
+              "id": "node_371077991169",
+              "name": "分支2",
+              "parentId": "node_371077998976",
+              "type": "CONCURRENT",
+              "props": {
+
+              },
+              "children": {
+                "id": "EbhE21033TTEpqGl",
+                "name": "抄送人",
+                "children": {
+
+                },
+                "type": "CC",
+                "props": {
+                  "shouldAdd": false,
+                  "assignedUser": [
+                    {
+                      "type": "user",
+                      "subjectId": "18c77f85416a4e458c3bd20d6e325f59",
+                      "name": "郭娟娟",
+                      "id": "18c77f85416a4e458c3bd20d6e325f59"
+                    },
+                    {
+                      "type": "user",
+                      "subjectId": "586e7fc0f0aa42fc9a9aa68f80e4ee69",
+                      "name": "吴银军",
+                      "id": "586e7fc0f0aa42fc9a9aa68f80e4ee69"
+                    }
+                  ],
+                  "assignedRole": [
+
+                  ],
+                  "formPerms": [
+                    {
+                      "id": "field4368279468887",
+                      "title": "名称",
+                      "required": true,
+                      "perm": "R"
+                    }
+                  ]
+                },
+                "ccSelfSelectFlag": 0,
+                "error": false
+              },
+              "typeElse": false
+            }
+          ],
+          "ParentID": "MHPZqWEyYgJGMPUx"
+        },
+        "ParentID": "eZMFYWfhAOeVK5Hn"
+      },
+      "ParentID": "2QsXrpyaBmfctjCO"
+    },
+    "branchs": [
+      {
+        "name": "研发中心",
+        "error": false,
+        "nodeType": 3,
+        "priorityLevel": 1,
+        "condGroup": {
+          "type": "and",
+          "items": [
+            {
+              "showType": 3,
+              "columnId": "",
+              "type": 2,
+              "showName": "",
+              "optType": "",
+              "zdy1": "2",
+              "opt1": "<",
+              "zdy2": "",
+              "opt2": "<",
+              "columnDbname": "",
+              "columnType": "Double",
+              "fieldId": "input_1N5KzwbC",
+              "operator": "==",
+              "rightValue": "研发中心"
+            }
+          ]
+        },
+        "subjects": [
+
+        ],
+        "children": {
+          "id": "vCBlqFjPzTs0bUY9",
+          "name": "审批人",
+          "type": "APPROVAL",
+          "props": {
+            "assignedType": "ASSIGN_USER",
+            "mode": "NEXT",
+            "sign": false,
+            "nobody": {
+              "handler": "TO_PASS",
+              "assignedUser": [
+
+              ],
+              "assignedRole": [
+
+              ]
+            },
+            "timeLimit": {
+              "timeout": {
+                "unit": "H",
+                "value": 0
+              },
+              "handler": {
+                "type": "REFUSE",
+                "notify": {
+                  "once": true,
+                  "hour": 1
+                }
+              }
+            },
+            "assignedUser": [
+              {
+                "type": "user",
+                "subjectId": "39ada31e4e784fe981dd31d390bb6ad4",
+                "name": "张建东",
+                "id": "39ada31e4e784fe981dd31d390bb6ad4"
+              },
+              {
+                "type": "user",
+                "subjectId": "5ee809c560cf4fc78c3755c17f177c54",
+                "name": "任鹏飞",
+                "id": "5ee809c560cf4fc78c3755c17f177c54"
+              }
+            ],
+            "assignedRole": [
+
+            ],
+            "formPerms": [
+              {
+                "id": "field4368279468887",
+                "title": "名称",
+                "required": true,
+                "perm": "R"
+              }
+            ],
+            "selfSelect": {
+              "multiple": false
+            },
+            "leaderTop": {
+              "endCondition": "TOP",
+              "endLevel": 1
+            },
+            "leader": {
+              "level": 1
+            },
+            "role": [
+
+            ],
+            "refuse": {
+              "type": "TO_END",
+              "target": ""
+            },
+            "formUser": "",
+            "passHttp": {
+              "method": "POST",
+              "url": "",
+              "headers": [
+                {
+                  "name": "",
+                  "isField": true,
+                  "value": ""
+                }
+              ],
+              "contentType": "JSON",
+              "params": [
+                {
+                  "name": "",
+                  "isField": true,
+                  "value": ""
+                }
+              ],
+              "retry": 1,
+              "handlerByScript": false,
+              "success": "function handlerOk(res) {\n  return true;\n}",
+              "fail": "function handlerFail(res) {\n  return true;\n}"
+            },
+            "rejectHttp": {
+              "method": "POST",
+              "url": "",
+              "headers": [
+                {
+                  "name": "",
+                  "isField": true,
+                  "value": ""
+                }
+              ],
+              "contentType": "JSON",
+              "params": [
+                {
+                  "name": "",
+                  "isField": true,
+                  "value": ""
+                }
+              ],
+              "retry": 1,
+              "handlerByScript": false,
+              "success": "function handlerOk(res) {\n  return true;\n}",
+              "fail": "function handlerFail(res) {\n  return true;\n}"
+            }
+          },
+          "error": false
+        }
+      },
+      {
+        "name": "其他中心",
+        "nodeType": 3,
+        "priorityLevel": 2,
+        "condGroup": {
+          "type": "default",
+          "items": [
+
+          ]
+        },
+        "subjects": [
+
+        ],
+        "children": {
+          "id": "Jt5c9Dj4xR1r39bG",
+          "name": "审批人",
+          "type": "APPROVAL",
+          "props": {
+            "assignedType": "ASSIGN_USER",
+            "mode": "NEXT",
+            "sign": false,
+            "nobody": {
+              "handler": "TO_PASS",
+              "assignedUser": [
+
+              ],
+              "assignedRole": [
+
+              ]
+            },
+            "timeLimit": {
+              "timeout": {
+                "unit": "H",
+                "value": 0
+              },
+              "handler": {
+                "type": "REFUSE",
+                "notify": {
+                  "once": true,
+                  "hour": 1
+                }
+              }
+            },
+            "assignedUser": [
+              {
+                "type": "user",
+                "subjectId": "21e02163f597474288293fff187f7d25",
+                "name": "曹宏雁",
+                "id": "21e02163f597474288293fff187f7d25"
+              },
+              {
+                "type": "user",
+                "subjectId": "83392f07986c40c084d36d22a2092ba6",
+                "name": "高连所",
+                "id": "83392f07986c40c084d36d22a2092ba6"
+              }
+            ],
+            "assignedRole": [
+
+            ],
+            "formPerms": [
+              {
+                "id": "field4368279468887",
+                "title": "名称",
+                "required": true,
+                "perm": "R"
+              }
+            ],
+            "selfSelect": {
+              "multiple": false
+            },
+            "leaderTop": {
+              "endCondition": "TOP",
+              "endLevel": 1
+            },
+            "leader": {
+              "level": 1
+            },
+            "role": [
+
+            ],
+            "refuse": {
+              "type": "TO_END",
+              "target": ""
+            },
+            "formUser": "",
+            "passHttp": {
+              "method": "POST",
+              "url": "",
+              "headers": [
+                {
+                  "name": "",
+                  "isField": true,
+                  "value": ""
+                }
+              ],
+              "contentType": "JSON",
+              "params": [
+                {
+                  "name": "",
+                  "isField": true,
+                  "value": ""
+                }
+              ],
+              "retry": 1,
+              "handlerByScript": false,
+              "success": "function handlerOk(res) {\n  return true;\n}",
+              "fail": "function handlerFail(res) {\n  return true;\n}"
+            },
+            "rejectHttp": {
+              "method": "POST",
+              "url": "",
+              "headers": [
+                {
+                  "name": "",
+                  "isField": true,
+                  "value": ""
+                }
+              ],
+              "contentType": "JSON",
+              "params": [
+                {
+                  "name": "",
+                  "isField": true,
+                  "value": ""
+                }
+              ],
+              "retry": 1,
+              "handlerByScript": false,
+              "success": "function handlerOk(res) {\n  return true;\n}",
+              "fail": "function handlerFail(res) {\n  return true;\n}"
+            }
+          },
+          "error": false
+        },
+        "error": false
+      }
+    ],
+    "ParentID": "root"
+  }
+}

+ 2 - 2
approve_former/node.go

@@ -6,10 +6,10 @@ import (
 	"text/template"
 )
 
-type Node interface {
+type Noder interface {
 	GetDepends() string
 	GetWhen() string
-	Render(upperNode Node) (string, error)
+	Render(upperNode Noder) (string, error)
 }
 
 func render(name string, templateStr string, templateParams map[string]any) (string, error) {

+ 4 - 4
approve_former/or.go

@@ -3,10 +3,10 @@ package approve_former
 import "strings"
 
 type Or struct {
-	childNodes []Node
+	childNodes []Noder
 }
 
-func NewOr(childNodes ...Node) *Or {
+func NewOr(childNodes ...Noder) *Or {
 	return &Or{
 		childNodes: childNodes,
 	}
@@ -38,7 +38,7 @@ func (or *Or) GetWhen() string {
 	return when
 }
 
-func (or *Or) AddNodes(childNodes ...Node) *Or {
+func (or *Or) AddNodes(childNodes ...Noder) *Or {
 	if childNodes == nil || len(childNodes) == 0 {
 		or.childNodes = append(or.childNodes, childNodes...)
 	}
@@ -46,7 +46,7 @@ func (or *Or) AddNodes(childNodes ...Node) *Or {
 	return or
 }
 
-func (or *Or) Render(upperNode Node) (string, error) {
+func (or *Or) Render(upperNode Noder) (string, error) {
 	var content string
 
 	for _, childNode := range or.childNodes {

+ 74 - 0
approve_former/parse.go

@@ -0,0 +1,74 @@
+package approve_former
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/pkg/errors"
+)
+
+const (
+	NodeTypeApproval = "APPROVAL" //审批节点类型
+)
+
+var (
+	ErrNodeEmpty = errors.New("请最少设置一个流程节点")
+)
+
+// ParseFlowFromJson 解析当前云极和ERP使用的前端json格式,输出argo支持的模板字符串
+func ParseFlowFromJson(flowName, frontJson string, argObj interface{}) (string, error) {
+	var root Node
+	err := json.Unmarshal([]byte(frontJson), &root)
+	if err != nil {
+		return "", err
+	}
+	if root.Children == nil {
+		return "", ErrNodeEmpty
+	}
+
+	// 递归遍历流程节点,生成argo模板
+	flow := NewFlow(flowName)
+	err = traverseTree(flow, root.Children)
+	if err != nil {
+		return "", err
+	}
+
+	tmpStr, err := flow.Render(nil)
+	if err != nil {
+		return "", err
+	}
+	// 渲染模板
+	return tmpStr, nil
+}
+
+func traverseTree(flow *Flow, node *Node) error {
+	if node == nil {
+		return nil
+	}
+	fmt.Printf("NodeID:%s,NodeName:%s,NodeType:%s\n", node.ID, node.Name, node.NodeType)
+
+	// 生成模板逻辑
+	switch node.Type {
+	case NodeTypeApproval:
+
+	default:
+		return errors.New("不支持的节点类型")
+	}
+
+	// 递归遍历并行分支节点
+	for _, branch := range node.Branchs {
+		err := traverseTree(flow, branch.Children)
+		if err != nil {
+			return err
+		}
+	}
+
+	// 递归遍历子节点
+	if node.Children != nil {
+		err := traverseTree(flow, node.Children)
+		if err != nil {
+			return err
+		}
+	}
+
+	return nil
+}

+ 39 - 0
approve_former/parse_test.go

@@ -0,0 +1,39 @@
+package approve_former
+
+import (
+	"fmt"
+	"github.com/stretchr/testify/assert"
+	"io"
+	"os"
+	"testing"
+)
+
+// TestParseFlowFromJson 测试整体结构解析
+func TestParseFlowFromJson(t *testing.T) {
+	// 测试结构解析
+	frontJson := readJsonFile("./front_json/full.json")
+	argoTmp, err := ParseFlowFromJson("full", frontJson, nil)
+	if err != nil {
+		t.Fatal(err)
+	}
+	fmt.Println(argoTmp)
+}
+
+func TestParseEmptyFlowFromJson(t *testing.T) {
+	frontJson := readJsonFile("./front_json/empty.json")
+	_, err := ParseFlowFromJson("empty", frontJson, nil)
+	assert.ErrorIs(t, err, ErrNodeEmpty)
+}
+
+func readJsonFile(filePath string) string {
+	file, err := os.Open(filePath)
+	if err != nil {
+		panic(err)
+	}
+	defer file.Close()
+	content, err := io.ReadAll(file)
+	if err != nil {
+		panic(err)
+	}
+	return string(content)
+}

+ 2 - 5
approve_former/sign.go

@@ -4,9 +4,6 @@ import "fmt"
 
 const signTemplate = `- name: [[ .name ]]
   template: approval
-  [[- if .depends ]]
-  depends: "[[ .depends ]]"
-  [[- end ]] 
   [[- if .when ]]
   when: "[[ .when ]]"
   [[- end -]]`
@@ -26,10 +23,10 @@ func (sign *Sign) GetDepends() string {
 }
 
 func (sign *Sign) GetWhen() string {
-	return fmt.Sprintf(`{{ tasks.%s.outputs.parameters.approve }} == 通过`, sign.Name)
+	return fmt.Sprintf(`{{ tasks.%s.outputs.parameters.front_json }} == 通过`, sign.Name)
 }
 
-func (sign *Sign) Render(upperNode Node) (string, error) {
+func (sign *Sign) Render(upperNode Noder) (string, error) {
 	if upperNode == nil {
 		return render("sign", signTemplate, map[string]any{
 			"name": sign.Name,

+ 138 - 0
approve_former/struct.go

@@ -0,0 +1,138 @@
+package approve_former
+
+type Node struct {
+	ID       string        `json:"id"`
+	Name     string        `json:"name"`
+	Type     string        `json:"type"`
+	Props    Props         `json:"props"`
+	Children *Node         `json:"children,omitempty"`
+	Branchs  []Branch      `json:"branchs,omitempty"`
+	ParentID string        `json:"ParentID,omitempty"`
+	Subjects []interface{} `json:"subjects,omitempty"`
+	Error    bool          `json:"error"`
+	NodeType int           `json:"nodeType,omitempty"`
+	Priority int           `json:"priorityLevel,omitempty"`
+}
+
+type Props struct {
+	AssignedUser     []UserRole    `json:"assignedUser,omitempty"`
+	FormPerms        []FormPerm    `json:"formPerms,omitempty"`
+	AssignedType     string        `json:"assignedType,omitempty"`
+	Mode             string        `json:"mode,omitempty"`
+	Sign             bool          `json:"sign,omitempty"`
+	Nobody           Nobody        `json:"nobody,omitempty"`
+	TimeLimit        TimeLimit     `json:"timeLimit,omitempty"`
+	AssignedRole     []UserRole    `json:"assignedRole,omitempty"`
+	SelfSelect       SelfSelect    `json:"selfSelect,omitempty"`
+	LeaderTop        LeaderTop     `json:"leaderTop,omitempty"`
+	Leader           Leader        `json:"leader,omitempty"`
+	Role             []interface{} `json:"role,omitempty"`
+	Refuse           Refuse        `json:"refuse,omitempty"`
+	FormUser         string        `json:"formUser,omitempty"`
+	PassHttp         HTTPRequest   `json:"passHttp,omitempty"`
+	RejectHttp       HTTPRequest   `json:"rejectHttp,omitempty"`
+	ShouldAdd        bool          `json:"shouldAdd,omitempty"`
+	CCSelfSelectFlag int           `json:"ccSelfSelectFlag,omitempty"`
+}
+
+type UserRole struct {
+	Type      string `json:"type"`
+	RoleCode  string `json:"roleCode,omitempty"`
+	Name      string `json:"name"`
+	ID        string `json:"id"`
+	SubjectID string `json:"subjectId,omitempty"`
+}
+
+type FormPerm struct {
+	ID       string `json:"id"`
+	Title    string `json:"title"`
+	Required bool   `json:"required"`
+	Perm     string `json:"perm"`
+}
+
+type Nobody struct {
+	Handler      string     `json:"handler"`
+	AssignedUser []UserRole `json:"assignedUser,omitempty"`
+	AssignedRole []UserRole `json:"assignedRole,omitempty"`
+}
+
+type TimeLimit struct {
+	Timeout struct {
+		Unit  string `json:"unit"`
+		Value int    `json:"value"`
+	} `json:"timeout"`
+	Handler struct {
+		Type   string `json:"type"`
+		Notify struct {
+			Once bool `json:"once"`
+			Hour int  `json:"hour"`
+		} `json:"notify"`
+	} `json:"handler"`
+}
+
+type SelfSelect struct {
+	Multiple bool `json:"multiple"`
+}
+
+type LeaderTop struct {
+	EndCondition string `json:"endCondition"`
+	EndLevel     int    `json:"endLevel"`
+}
+
+type Leader struct {
+	Level int `json:"level"`
+}
+
+type Refuse struct {
+	Type   string `json:"type"`
+	Target string `json:"target"`
+}
+
+type HTTPRequest struct {
+	Method          string      `json:"method"`
+	URL             string      `json:"url"`
+	Headers         []HTTPParam `json:"headers"`
+	ContentType     string      `json:"contentType"`
+	Params          []HTTPParam `json:"params"`
+	Retry           int         `json:"retry"`
+	HandlerByScript bool        `json:"handlerByScript"`
+	Success         string      `json:"success"`
+	Fail            string      `json:"fail"`
+}
+
+type HTTPParam struct {
+	Name    string `json:"name"`
+	IsField bool   `json:"isField"`
+	Value   string `json:"value"`
+}
+
+type Branch struct {
+	ID        string     `json:"id"`
+	Name      string     `json:"name"`
+	Type      string     `json:"type"`
+	Props     Props      `json:"props"`
+	Children  *Node      `json:"children"`
+	CondGroup *CondGroup `json:"condGroup,omitempty"`
+}
+
+type CondGroup struct {
+	Type  string     `json:"type"`
+	Items []CondItem `json:"items"`
+}
+
+type CondItem struct {
+	ShowType     int    `json:"showType"`
+	ColumnID     string `json:"columnId"`
+	Type         int    `json:"type"`
+	ShowName     string `json:"showName"`
+	OptType      string `json:"optType"`
+	Zdy1         string `json:"zdy1"`
+	Opt1         string `json:"opt1"`
+	Zdy2         string `json:"zdy2"`
+	Opt2         string `json:"opt2"`
+	ColumnDbName string `json:"columnDbname"`
+	ColumnType   string `json:"columnType"`
+	FieldID      string `json:"fieldId"`
+	Operator     string `json:"operator"`
+	RightValue   string `json:"rightValue"`
+}

+ 9 - 9
example/template-render/andor.yaml

@@ -3,14 +3,14 @@ kind: WorkflowTemplate
 metadata:
   name: andor
 spec:
-  entrypoint: approve-flow
+  entrypoint: front_json-flow
   arguments:
     parameters:
       - name: object
         value: {}
 
   templates:
-    - name: approve-flow
+    - name: front_json-flow
       inputs:
         parameters:
           - name: object
@@ -21,29 +21,29 @@ spec:
           - name: B
             template: approval
             depends: "A.Succeeded"
-            when: "{{ tasks.A.outputs.parameters.approve }} == 通过"
+            when: "{{ tasks.A.outputs.parameters.front_json }} == 通过"
           - name: C
             template: approval
             depends: "A.Succeeded"
-            when: "{{ tasks.A.outputs.parameters.approve }} == 通过"
+            when: "{{ tasks.A.outputs.parameters.front_json }} == 通过"
           - name: D
             template: approval
             depends: "B.Succeeded && C.Succeeded"
-            when: "({{ tasks.B.outputs.parameters.approve }} == 通过) && ({{ tasks.C.outputs.parameters.approve }} == 通过)"
+            when: "({{ tasks.B.outputs.parameters.front_json }} == 通过) && ({{ tasks.C.outputs.parameters.front_json }} == 通过)"
           - name: E
             template: approval
             depends: "B.Succeeded && C.Succeeded"
-            when: "({{ tasks.B.outputs.parameters.approve }} == 通过) && ({{ tasks.C.outputs.parameters.approve }} == 通过)"
+            when: "({{ tasks.B.outputs.parameters.front_json }} == 通过) && ({{ tasks.C.outputs.parameters.front_json }} == 通过)"
           - name: F
             template: approval
             depends: "D.Succeeded && E.Succeeded"
-            when: "({{ tasks.D.outputs.parameters.approve }} == 通过) || ({{ tasks.E.outputs.parameters.approve }} == 通过)"
+            when: "({{ tasks.D.outputs.parameters.front_json }} == 通过) || ({{ tasks.E.outputs.parameters.front_json }} == 通过)"
           
     - name: approval
       suspend: {}
       inputs:
         parameters:
-          - name: approve
+          - name: front_json
             default: '通过'
             enum:
               - '通过'
@@ -51,6 +51,6 @@ spec:
               - '忽略'
       outputs:
         parameters:
-          - name: approve
+          - name: front_json
             valueFrom:
               supplied: {}

+ 3 - 13
example/template-render/main.go

@@ -9,7 +9,7 @@ const dir = "/Users/duyong/workspace/fangshi/meta-business/argo/example/template
 
 func main() {
 	//simpleTemp()
-	//buildSignsTemp()
+	buildSignsTemp()
 	buildAndORTemp()
 }
 
@@ -35,24 +35,14 @@ func writeFile(fileName string, data string) error {
 // 只有单签的流程模板
 func buildSignsTemp() {
 	flow := approve_former.NewFlow("signs",
-		approve_former.NewSign("技术总监"),
-		approve_former.NewSign("研发总监"),
-		approve_former.NewSign("人事总监"))
-	templateString, err := flow.Render(nil)
-	if err != nil {
-		panic(err)
-	}
-	_ = writeFile(dir+"signs.yaml", templateString)
-
-	flow1 := approve_former.NewFlow("signs",
 		approve_former.NewSign("A"),
 		approve_former.NewSign("B"),
 		approve_former.NewSign("C"))
-	templateString1, err := flow1.Render(nil)
+	templateString1, err := flow.Render(nil)
 	if err != nil {
 		panic(err)
 	}
-	_ = writeFile(dir+"signs1.yaml", templateString1)
+	_ = writeFile(dir+"signs.yaml", templateString1)
 }
 
 // 会签和或签

+ 9 - 9
example/template-render/signs.yaml

@@ -3,14 +3,14 @@ kind: WorkflowTemplate
 metadata:
   name: buildAndOR
 spec:
-  entrypoint: approve-flow
+  entrypoint: front_json-flow
   arguments:
     parameters:
       - name: object
         value: {}
 
   templates:
-    - name: approve-flow
+    - name: front_json-flow
       inputs:
         parameters:
           - name: object
@@ -21,35 +21,35 @@ spec:
           - name: B
             template: approval
             depends: "A.Succeeded"
-            when: "{{ tasks.A.outputs.parameters.approve }} == 通过"
+            when: "{{ tasks.A.outputs.parameters.front_json }} == 通过"
           - name: C
             template: approval
             depends: "A.Succeeded"
-            when: "{{ tasks.A.outputs.parameters.approve }} == 通过"
+            when: "{{ tasks.A.outputs.parameters.front_json }} == 通过"
           - name: D
             template: approval
             depends: "B.Succeeded && C.Succeeded"
-            when: "({{ tasks.B.outputs.parameters.approve }} == 通过) && ({{ tasks.C.outputs.parameters.approve }} == 通过)"
+            when: "({{ tasks.B.outputs.parameters.front_json }} == 通过) && ({{ tasks.C.outputs.parameters.front_json }} == 通过)"
           - name: E
             template: approval
             depends: "B.Succeeded && C.Succeeded"
-            when: "({{ tasks.B.outputs.parameters.approve }} == 通过) && ({{ tasks.C.outputs.parameters.approve }} == 通过)"
+            when: "({{ tasks.B.outputs.parameters.front_json }} == 通过) && ({{ tasks.C.outputs.parameters.front_json }} == 通过)"
           - name: F
             template: approval
             depends: "D.Succeeded && E.Succeeded"
-            when: "({{ tasks.D.outputs.parameters.approve }} == 通过) || ({{ tasks.E.outputs.parameters.approve }} == 通过)"
+            when: "({{ tasks.D.outputs.parameters.front_json }} == 通过) || ({{ tasks.E.outputs.parameters.front_json }} == 通过)"
           
     - name: approval
       suspend: {}
       inputs:
         parameters:
-          - name: approve
+          - name: front_json
             default: '通过'
             enum:
               - '通过'
               - '拒绝'
       outputs:
         parameters:
-          - name: approve
+          - name: front_json
             valueFrom:
               supplied: {}

+ 0 - 43
example/template-render/signs1.yaml

@@ -1,43 +0,0 @@
-apiVersion: argoproj.io/v1alpha1
-kind: WorkflowTemplate
-metadata:
-  name: signs
-spec:
-  entrypoint: approve-flow
-  arguments:
-    parameters:
-      - name: object
-        value: {}
-
-  templates:
-    - name: approve-flow
-      inputs:
-        parameters:
-          - name: object
-      dag:
-        tasks:
-          - name: A
-            template: approval
-          - name: B
-            template: approval
-            depends: "A.Succeeded"
-            when: "{{ tasks.A.outputs.parameters.approve }} == 通过"
-          - name: C
-            template: approval
-            depends: "B.Succeeded"
-            when: "{{ tasks.B.outputs.parameters.approve }} == 通过"
-          
-    - name: approval
-      suspend: {}
-      inputs:
-        parameters:
-          - name: approve
-            default: '通过'
-            enum:
-              - '通过'
-              - '拒绝'
-      outputs:
-        parameters:
-          - name: approve
-            valueFrom:
-              supplied: {}

+ 5 - 5
example/template-render/simple.yaml

@@ -3,33 +3,33 @@ kind: WorkflowTemplate
 metadata:
   name: simple
 spec:
-  entrypoint: approve-flow
+  entrypoint: front_json-flow
   arguments:
     parameters:
       - name: object
         value: {}
 
   templates:
-    - name: approve-flow
+    - name: front_json-flow
       inputs:
         parameters:
           - name: object
       dag:
         tasks:
-          - name: node
+          - name: parse_flow
             template: approval
           
     - name: approval
       suspend: {}
       inputs:
         parameters:
-          - name: approve
+          - name: front_json
             default: '通过'
             enum:
               - '通过'
               - '拒绝'
       outputs:
         parameters:
-          - name: approve
+          - name: front_json
             valueFrom:
               supplied: {}

+ 4 - 2
go.mod

@@ -5,7 +5,10 @@ go 1.22.5
 require (
 	github.com/argoproj/argo-workflows/v3 v3.5.8
 	github.com/pkg/errors v0.9.1
+	github.com/sirupsen/logrus v1.9.3
+	github.com/stretchr/testify v1.9.0
 	gopkg.in/yaml.v3 v3.0.1
+	k8s.io/apimachinery v0.24.3
 	k8s.io/client-go v0.24.3
 )
 
@@ -73,6 +76,7 @@ require (
 	github.com/modern-go/reflect2 v1.0.2 // indirect
 	github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
 	github.com/ncruces/go-strftime v0.1.9 // indirect
+	github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
 	github.com/prometheus/client_golang v1.16.0 // indirect
 	github.com/prometheus/client_model v0.3.0 // indirect
 	github.com/prometheus/common v0.42.0 // indirect
@@ -82,7 +86,6 @@ require (
 	github.com/segmentio/fasthash v1.0.3 // indirect
 	github.com/sethvargo/go-limiter v0.7.2 // indirect
 	github.com/shopspring/decimal v1.2.0 // indirect
-	github.com/sirupsen/logrus v1.9.3 // indirect
 	github.com/spf13/cast v1.5.1 // indirect
 	github.com/spf13/cobra v1.7.0 // indirect
 	github.com/spf13/pflag v1.0.5 // indirect
@@ -106,7 +109,6 @@ require (
 	gopkg.in/inf.v0 v0.9.1 // indirect
 	gopkg.in/yaml.v2 v2.4.0 // indirect
 	k8s.io/api v0.24.3 // indirect
-	k8s.io/apimachinery v0.24.3 // indirect
 	k8s.io/klog/v2 v2.70.1 // indirect
 	k8s.io/kube-openapi v0.0.0-20220627174259-011e075b9cb8 // indirect
 	k8s.io/utils v0.0.0-20220713171938-56c0de1e6f5e // indirect

+ 0 - 535
test/approve/approve.json

@@ -1,535 +0,0 @@
-{
-  "name": "发起人",
-  "desc": "任何人",
-  "type": "ROOT",
-  "parentId": null,
-  "id": "root",
-  "props": {
-    "assignedUser": [],
-    "formPerms": []
-  },
-  "children": {
-    "id": "9oMJ0ZGUSPsz3fGQ",
-    "name": "或签审批",
-    "type": "APPROVAL",
-    "props": {
-      "assignedType": "ASSIGN_USER",
-      "mode": "OR",
-      "sign": false,
-      "nobody": {
-        "handler": "TO_PASS",
-        "assignedUser": [],
-        "assignedRole": []
-      },
-      "timeLimit": {
-        "timeout": {
-          "unit": "H",
-          "value": 0
-        },
-        "handler": {
-          "type": "REFUSE",
-          "notify": {
-            "once": true,
-            "hour": 1
-          }
-        }
-      },
-      "assignedUser": [
-        {
-          "type": "user",
-          "subjectId": "81d10c9f19c244088c0066a6ba13bab7",
-          "name": "质检人员",
-          "id": "81d10c9f19c244088c0066a6ba13bab7"
-        },
-        {
-          "type": "user",
-          "subjectId": "c09bb598a48147e2a37f43e4130df843",
-          "name": "行政人员",
-          "id": "c09bb598a48147e2a37f43e4130df843"
-        }
-      ],
-      "assignedRole": [],
-      "formPerms": [
-        {
-          "id": "field4368279468887",
-          "title": "名称",
-          "required": true,
-          "perm": "R"
-        }
-      ],
-      "selfSelect": {
-        "multiple": false
-      },
-      "leaderTop": {
-        "endCondition": "TOP",
-        "endLevel": 1
-      },
-      "leader": {
-        "level": 1
-      },
-      "role": [],
-      "refuse": {
-        "type": "TO_END",
-        "target": ""
-      },
-      "formUser": "",
-      "passHttp": {
-        "method": "POST",
-        "url": "http://10.0.0.198:30701/mbwb/api/audit",
-        "headers": [
-          {
-            "name": "",
-            "isField": true,
-            "value": ""
-          }
-        ],
-        "contentType": "JSON",
-        "params": [
-          {
-            "name": "",
-            "isField": true,
-            "value": ""
-          }
-        ],
-        "retry": 1,
-        "handlerByScript": false,
-        "success": "function handlerOk(res) {\n  return true;\n}",
-        "fail": "function handlerFail(res) {\n  return true;\n}"
-      },
-      "rejectHttp": {
-        "method": "POST",
-        "url": "http://10.0.0.198:30701/mbwb/api/refuse",
-        "headers": [
-          {
-            "name": "",
-            "isField": true,
-            "value": ""
-          }
-        ],
-        "contentType": "JSON",
-        "params": [
-          {
-            "name": "",
-            "isField": true,
-            "value": ""
-          }
-        ],
-        "retry": 1,
-        "handlerByScript": false,
-        "success": "function handlerOk(res) {\n  return true;\n}",
-        "fail": "function handlerFail(res) {\n  return true;\n}"
-      }
-    },
-    "error": false,
-    "children": {
-      "id": "UnDmPp4P5JVP5DMT",
-      "name": "会签审批",
-      "type": "APPROVAL",
-      "props": {
-        "assignedType": "ASSIGN_USER",
-        "mode": "NEXT",
-        "sign": false,
-        "nobody": {
-          "handler": "TO_PASS",
-          "assignedUser": [],
-          "assignedRole": []
-        },
-        "timeLimit": {
-          "timeout": {
-            "unit": "H",
-            "value": 0
-          },
-          "handler": {
-            "type": "REFUSE",
-            "notify": {
-              "once": true,
-              "hour": 1
-            }
-          }
-        },
-        "assignedUser": [
-          {
-            "type": "user",
-            "subjectId": "afb08622b0144502b1294aad1021b876",
-            "name": "生产调度",
-            "id": "afb08622b0144502b1294aad1021b876"
-          },
-          {
-            "type": "user",
-            "subjectId": "2013392b19824330881c896a34fa0e77",
-            "name": "仓管人员",
-            "id": "2013392b19824330881c896a34fa0e77"
-          },
-          {
-            "type": "user",
-            "subjectId": "cbe10e4bc82145a8b57769821fbbf761",
-            "name": "销售人员",
-            "id": "cbe10e4bc82145a8b57769821fbbf761"
-          }
-        ],
-        "assignedRole": [],
-        "formPerms": [
-          {
-            "id": "field4368279468887",
-            "title": "名称",
-            "required": true,
-            "perm": "R"
-          }
-        ],
-        "selfSelect": {
-          "multiple": false
-        },
-        "leaderTop": {
-          "endCondition": "TOP",
-          "endLevel": 1
-        },
-        "leader": {
-          "level": 1
-        },
-        "role": [],
-        "refuse": {
-          "type": "TO_END",
-          "target": ""
-        },
-        "formUser": "",
-        "passHttp": {
-          "method": "POST",
-          "url": "http://10.0.0.198:30701/mbwb/api/audit",
-          "headers": [
-            {
-              "name": "",
-              "isField": true,
-              "value": ""
-            }
-          ],
-          "contentType": "JSON",
-          "params": [
-            {
-              "name": "",
-              "isField": true,
-              "value": ""
-            }
-          ],
-          "retry": 1,
-          "handlerByScript": false,
-          "success": "function handlerOk(res) {\n  return true;\n}",
-          "fail": "function handlerFail(res) {\n  return true;\n}"
-        },
-        "rejectHttp": {
-          "method": "POST",
-          "url": "http://10.0.0.198:30701/mbwb/api/refuse",
-          "headers": [
-            {
-              "name": "",
-              "isField": true,
-              "value": ""
-            }
-          ],
-          "contentType": "JSON",
-          "params": [
-            {
-              "name": "",
-              "isField": true,
-              "value": ""
-            }
-          ],
-          "retry": 1,
-          "handlerByScript": false,
-          "success": "function handlerOk(res) {\n  return true;\n}",
-          "fail": "function handlerFail(res) {\n  return true;\n}"
-        }
-      },
-      "error": false,
-      "children": {
-        "id": "UBtBe6PTv0kQDm4B",
-        "name": "并行分支",
-        "type": "CONCURRENTS",
-        "children": {
-          "id": "ntWxexK46WotEF0C",
-          "name": "抄送人",
-          "children": {
-            "ParentID": "ntWxexK46WotEF0C"
-          },
-          "type": "CC",
-          "props": {
-            "shouldAdd": false,
-            "assignedUser": [
-              {
-                "type": "user",
-                "subjectId": "81d10c9f19c244088c0066a6ba13bab7",
-                "name": "质检人员",
-                "id": "81d10c9f19c244088c0066a6ba13bab7"
-              },
-              {
-                "type": "user",
-                "subjectId": "2013392b19824330881c896a34fa0e77",
-                "name": "仓管人员",
-                "id": "2013392b19824330881c896a34fa0e77"
-              },
-              {
-                "type": "user",
-                "subjectId": "ff4466c00b944584b567a454f94fb8ce",
-                "name": "采购人员",
-                "id": "ff4466c00b944584b567a454f94fb8ce"
-              },
-              {
-                "type": "user",
-                "subjectId": "2d79964af26b4534a09a4a57b2f56d44",
-                "name": "系统人员",
-                "id": "2d79964af26b4534a09a4a57b2f56d44"
-              }
-            ],
-            "assignedRole": [],
-            "formPerms": [
-              {
-                "id": "field4368279468887",
-                "title": "名称",
-                "required": true,
-                "perm": "R"
-              }
-            ]
-          },
-          "ccSelfSelectFlag": 0,
-          "error": false,
-          "ParentID": "UBtBe6PTv0kQDm4B"
-        },
-        "branchs": [
-          {
-            "id": "node_371077991169",
-            "name": "分支1",
-            "parentId": "node_371077998976",
-            "type": "CONCURRENT",
-            "props": {},
-            "children": {
-              "id": "oSIsJsle3MWLrt26",
-              "name": "角色审批",
-              "type": "APPROVAL",
-              "props": {
-                "assignedType": "ROLE",
-                "mode": "OR",
-                "sign": false,
-                "nobody": {
-                  "handler": "TO_PASS",
-                  "assignedUser": [],
-                  "assignedRole": []
-                },
-                "timeLimit": {
-                  "timeout": {
-                    "unit": "H",
-                    "value": 0
-                  },
-                  "handler": {
-                    "type": "REFUSE",
-                    "notify": {
-                      "once": true,
-                      "hour": 1
-                    }
-                  }
-                },
-                "assignedUser": [],
-                "assignedRole": [
-                  {
-                    "type": "role",
-                    "roleCode": "00002",
-                    "name": "平台人员",
-                    "id": "6121fa5cd2ff451da98ad7c451790367"
-                  }
-                ],
-                "formPerms": [
-                  {
-                    "id": "field4368279468887",
-                    "title": "名称",
-                    "required": true,
-                    "perm": "R"
-                  }
-                ],
-                "selfSelect": {
-                  "multiple": false
-                },
-                "leaderTop": {
-                  "endCondition": "TOP",
-                  "endLevel": 1
-                },
-                "leader": {
-                  "level": 1
-                },
-                "role": [],
-                "refuse": {
-                  "type": "TO_END",
-                  "target": ""
-                },
-                "formUser": "",
-                "passHttp": {
-                  "method": "POST",
-                  "url": "",
-                  "headers": [
-                    {
-                      "name": "",
-                      "isField": true,
-                      "value": ""
-                    }
-                  ],
-                  "contentType": "JSON",
-                  "params": [
-                    {
-                      "name": "",
-                      "isField": true,
-                      "value": ""
-                    }
-                  ],
-                  "retry": 1,
-                  "handlerByScript": false,
-                  "success": "function handlerOk(res) {\n  return true;\n}",
-                  "fail": "function handlerFail(res) {\n  return true;\n}"
-                },
-                "rejectHttp": {
-                  "method": "POST",
-                  "url": "",
-                  "headers": [
-                    {
-                      "name": "",
-                      "isField": true,
-                      "value": ""
-                    }
-                  ],
-                  "contentType": "JSON",
-                  "params": [
-                    {
-                      "name": "",
-                      "isField": true,
-                      "value": ""
-                    }
-                  ],
-                  "retry": 1,
-                  "handlerByScript": false,
-                  "success": "function handlerOk(res) {\n  return true;\n}",
-                  "fail": "function handlerFail(res) {\n  return true;\n}"
-                }
-              },
-              "subjects": [],
-              "examineMode": 1,
-              "noHanderAction": 2,
-              "error": false
-            },
-            "typeElse": false
-          },
-          {
-            "id": "node_371077991169",
-            "name": "分支2",
-            "parentId": "node_371077998976",
-            "type": "CONCURRENT",
-            "props": {},
-            "children": {
-              "id": "jxHOnRDBoz0vH0vx",
-              "name": "主管审批",
-              "type": "APPROVAL",
-              "props": {
-                "assignedType": "LEADER",
-                "mode": "OR",
-                "sign": false,
-                "nobody": {
-                  "handler": "TO_PASS",
-                  "assignedUser": [],
-                  "assignedRole": []
-                },
-                "timeLimit": {
-                  "timeout": {
-                    "unit": "H",
-                    "value": 0
-                  },
-                  "handler": {
-                    "type": "REFUSE",
-                    "notify": {
-                      "once": true,
-                      "hour": 1
-                    }
-                  }
-                },
-                "assignedUser": [],
-                "assignedRole": [],
-                "formPerms": [
-                  {
-                    "id": "field4368279468887",
-                    "title": "名称",
-                    "required": true,
-                    "perm": "R"
-                  }
-                ],
-                "selfSelect": {
-                  "multiple": false
-                },
-                "leaderTop": {
-                  "endCondition": "TOP",
-                  "endLevel": 1
-                },
-                "leader": {
-                  "level": 1
-                },
-                "role": [],
-                "refuse": {
-                  "type": "TO_END",
-                  "target": ""
-                },
-                "formUser": "",
-                "passHttp": {
-                  "method": "POST",
-                  "url": "",
-                  "headers": [
-                    {
-                      "name": "",
-                      "isField": true,
-                      "value": ""
-                    }
-                  ],
-                  "contentType": "JSON",
-                  "params": [
-                    {
-                      "name": "",
-                      "isField": true,
-                      "value": ""
-                    }
-                  ],
-                  "retry": 1,
-                  "handlerByScript": false,
-                  "success": "function handlerOk(res) {\n  return true;\n}",
-                  "fail": "function handlerFail(res) {\n  return true;\n}"
-                },
-                "rejectHttp": {
-                  "method": "POST",
-                  "url": "",
-                  "headers": [
-                    {
-                      "name": "",
-                      "isField": true,
-                      "value": ""
-                    }
-                  ],
-                  "contentType": "JSON",
-                  "params": [
-                    {
-                      "name": "",
-                      "isField": true,
-                      "value": ""
-                    }
-                  ],
-                  "retry": 1,
-                  "handlerByScript": false,
-                  "success": "function handlerOk(res) {\n  return true;\n}",
-                  "fail": "function handlerFail(res) {\n  return true;\n}"
-                }
-              },
-              "subjects": [],
-              "examineMode": 1,
-              "noHanderAction": 2,
-              "error": false
-            },
-            "typeElse": false
-          }
-        ],
-        "ParentID": "UnDmPp4P5JVP5DMT"
-      },
-      "ParentID": "9oMJ0ZGUSPsz3fGQ"
-    },
-    "ParentID": "root"
-  }
-}

+ 6 - 26
test/approve_former_test.go

@@ -2,36 +2,16 @@ package test
 
 import (
 	_ "embed"
-	"encoding/json"
 	"fmt"
 	"git.sxidc.com/go-tools/argo-api"
 	"git.sxidc.com/go-tools/argo-api/approve_former"
 	"git.sxidc.com/go-tools/argo-api/client"
 	"github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
-	"github.com/pkg/errors"
 	"sync"
 	"testing"
 	"time"
 )
 
-//go:embed approve/approve.json
-var approveJson []byte
-
-func TestParseWorkflowTemplate(t *testing.T) {
-	approveJsonMap := make(map[string]any)
-	err := json.Unmarshal(approveJson, &approveJsonMap)
-	if err != nil {
-		t.Fatalf("%+v\n", errors.New(err.Error()))
-	}
-
-	workflowTemplateDefinition, err := approve_former.ParseWorkflowTemplate("test", approveJsonMap)
-	if err != nil {
-		t.Fatalf("%+v\n", err)
-	}
-
-	fmt.Println(workflowTemplateDefinition)
-}
-
 func TestApproveFormer(t *testing.T) {
 	flow := approve_former.NewFlow("flow",
 		approve_former.NewSign("A"),
@@ -142,7 +122,7 @@ func TestUseApproveFormer(t *testing.T) {
 					Namespace:         namespace,
 					Name:              workflowName,
 					NodeFieldSelector: "displayName=A",
-					OutputParameters:  `{"approve": "通过"}`,
+					OutputParameters:  `{"front_json": "通过"}`,
 				})
 				if err != nil {
 					t.Fatalf("%+v\n", err)
@@ -170,7 +150,7 @@ func TestUseApproveFormer(t *testing.T) {
 					Namespace:         namespace,
 					Name:              workflowName,
 					NodeFieldSelector: "displayName=B",
-					OutputParameters:  `{"approve": "通过"}`,
+					OutputParameters:  `{"front_json": "通过"}`,
 				})
 				if err != nil {
 					t.Fatalf("%+v\n", err)
@@ -198,7 +178,7 @@ func TestUseApproveFormer(t *testing.T) {
 					Namespace:         namespace,
 					Name:              workflowName,
 					NodeFieldSelector: "displayName=C",
-					OutputParameters:  `{"approve": "拒绝"}`,
+					OutputParameters:  `{"front_json": "拒绝"}`,
 				})
 				if err != nil {
 					t.Fatalf("%+v\n", err)
@@ -226,7 +206,7 @@ func TestUseApproveFormer(t *testing.T) {
 					Namespace:         namespace,
 					Name:              workflowName,
 					NodeFieldSelector: "displayName=D",
-					OutputParameters:  `{"approve": "通过"}`,
+					OutputParameters:  `{"front_json": "通过"}`,
 				})
 				if err != nil {
 					t.Fatalf("%+v\n", err)
@@ -254,7 +234,7 @@ func TestUseApproveFormer(t *testing.T) {
 					Namespace:         namespace,
 					Name:              workflowName,
 					NodeFieldSelector: "displayName=E",
-					OutputParameters:  `{"approve": "通过"}`,
+					OutputParameters:  `{"front_json": "通过"}`,
 				})
 				if err != nil {
 					t.Fatalf("%+v\n", err)
@@ -282,7 +262,7 @@ func TestUseApproveFormer(t *testing.T) {
 					Namespace:         namespace,
 					Name:              workflowName,
 					NodeFieldSelector: "displayName=F",
-					OutputParameters:  `{"approve": "通过"}`,
+					OutputParameters:  `{"front_json": "通过"}`,
 				})
 				if err != nil {
 					t.Fatalf("%+v\n", err)

+ 1 - 1
test/common.go

@@ -7,7 +7,7 @@ import (
 const (
 	kubeConfig                     = "/etc/rancher/k3s.yaml/k3s.yaml.yaml"
 	namespace                      = "argo-api"
-	workflowTemplateName           = "approve"
+	workflowTemplateName           = "front_json"
 	workflowTemplateWithParamsName = "hello"
 )
 

+ 10 - 10
test/definitions/approve_workflow.yaml

@@ -1,11 +1,11 @@
 apiVersion: argoproj.io/v1alpha1
 kind: Workflow
 metadata:
-  generateName: approve-
+  generateName: front_json-
 spec:
-  entrypoint: approve-flow
+  entrypoint: front_json-flow
   templates:
-    - name: approve-flow
+    - name: front_json-flow
       dag:
         tasks:
           - name: A
@@ -13,29 +13,29 @@ spec:
           - name: B
             template: approval
             depends: "A.Succeeded"
-            when: "{{ tasks.A.outputs.parameters.approve }} == 通过"
+            when: "{{ tasks.A.outputs.parameters.front_json }} == 通过"
           - name: C
             template: approval
             depends: "A.Succeeded"
-            when: "{{ tasks.A.outputs.parameters.approve }} == 通过"
+            when: "{{ tasks.A.outputs.parameters.front_json }} == 通过"
           - name: D
             template: approval
             depends: "B.Succeeded && C.Succeeded"
-            when: "{{ tasks.B.outputs.parameters.approve }} == 通过 && {{ tasks.C.outputs.parameters.approve }} == 通过"
+            when: "{{ tasks.B.outputs.parameters.front_json }} == 通过 && {{ tasks.C.outputs.parameters.front_json }} == 通过"
           - name: E
             template: approval
             depends: "B.Succeeded && C.Succeeded"
-            when: "{{ tasks.B.outputs.parameters.approve }} == 通过 && {{ tasks.C.outputs.parameters.approve }} == 通过"
+            when: "{{ tasks.B.outputs.parameters.front_json }} == 通过 && {{ tasks.C.outputs.parameters.front_json }} == 通过"
           - name: F
             template: approval
             depends: "D.Succeeded && E.Succeeded"
-            when: "{{ tasks.D.outputs.parameters.approve }} == 通过 || {{ tasks.E.outputs.parameters.approve }} == 通过"
+            when: "{{ tasks.D.outputs.parameters.front_json }} == 通过 || {{ tasks.E.outputs.parameters.front_json }} == 通过"
 
     - name: approval
       suspend: {}
       inputs:
         parameters:
-          - name: approve
+          - name: front_json
             default: '通过'
             enum:
               - '通过'
@@ -44,6 +44,6 @@ spec:
               请选择要执行的操作
       outputs:
         parameters:
-          - name: approve
+          - name: front_json
             valueFrom:
               supplied: {}

+ 10 - 10
test/definitions/approve_workflow_template.yaml

@@ -1,11 +1,11 @@
 apiVersion: argoproj.io/v1alpha1
 kind: WorkflowTemplate
 metadata:
-  name: approve
+  name: front_json
 spec:
-  entrypoint: approve-flow
+  entrypoint: front_json-flow
   templates:
-    - name: approve-flow
+    - name: front_json-flow
       dag:
         tasks:
           - name: A
@@ -13,29 +13,29 @@ spec:
           - name: B
             template: approval
             depends: "A.Succeeded"
-            when: "{{ tasks.A.outputs.parameters.approve }} == 通过"
+            when: "{{ tasks.A.outputs.parameters.front_json }} == 通过"
           - name: C
             template: approval
             depends: "A.Succeeded"
-            when: "{{ tasks.A.outputs.parameters.approve }} == 通过"
+            when: "{{ tasks.A.outputs.parameters.front_json }} == 通过"
           - name: D
             template: approval
             depends: "B.Succeeded && C.Succeeded"
-            when: "{{ tasks.B.outputs.parameters.approve }} == 通过 && {{ tasks.C.outputs.parameters.approve }} == 通过"
+            when: "{{ tasks.B.outputs.parameters.front_json }} == 通过 && {{ tasks.C.outputs.parameters.front_json }} == 通过"
           - name: E
             template: approval
             depends: "B.Succeeded && C.Succeeded"
-            when: "{{ tasks.B.outputs.parameters.approve }} == 通过 && {{ tasks.C.outputs.parameters.approve }} == 通过"
+            when: "{{ tasks.B.outputs.parameters.front_json }} == 通过 && {{ tasks.C.outputs.parameters.front_json }} == 通过"
           - name: F
             template: approval
             depends: "D.Succeeded && E.Succeeded"
-            when: "{{ tasks.D.outputs.parameters.approve }} == 通过 || {{ tasks.E.outputs.parameters.approve }} == 通过"
+            when: "{{ tasks.D.outputs.parameters.front_json }} == 通过 || {{ tasks.E.outputs.parameters.front_json }} == 通过"
           
     - name: approval
       suspend: {}
       inputs:
           parameters:
-            - name: approve
+            - name: front_json
               default: '通过'
               enum:
                   - '通过'
@@ -44,6 +44,6 @@ spec:
                 请选择要执行的操作
       outputs:
           parameters:
-            - name: approve
+            - name: front_json
               valueFrom:
                   supplied: {}

+ 2 - 2
test/workflow_test.go

@@ -412,7 +412,7 @@ func TestSetWorkflow(t *testing.T) {
 		Namespace:         namespace,
 		Name:              workflowName,
 		NodeFieldSelector: "displayName=A",
-		OutputParameters:  `{"approve": "pass"}`,
+		OutputParameters:  `{"front_json": "pass"}`,
 	})
 	if err != nil {
 		t.Fatalf("%+v\n", err)
@@ -428,7 +428,7 @@ func TestSetWorkflow(t *testing.T) {
 
 	for _, node := range wf.Status.Nodes {
 		if node.DisplayName == "A" {
-			if node.Outputs.Parameters[0].Name == "approve" && node.Outputs.Parameters[0].Value.String() == "pass" {
+			if node.Outputs.Parameters[0].Name == "front_json" && node.Outputs.Parameters[0].Value.String() == "pass" {
 				return
 			}