Explorar o código

去掉模板概念

duyong hai 3 meses
pai
achega
effea845dd
Modificáronse 3 ficheiros con 43 adicións e 21 borrados
  1. 15 15
      approve_former/flow.go
  2. 4 3
      approve_former/parse.go
  3. 24 3
      approve_former/parse_test.go

+ 15 - 15
approve_former/flow.go

@@ -1,25 +1,24 @@
 package approve_former
 
 import (
-	"k8s.io/apimachinery/pkg/util/uuid"
 	"strings"
 )
 
 const flowTemplate = `apiVersion: argoproj.io/v1alpha1
-kind: WorkflowTemplate
+kind: Workflow
 metadata:
-  name: [[ .name ]]
+  generateName: [[ .name ]]-
 spec:
   entrypoint: front-json-flow
   arguments:
     parameters:
-      - name: flow-name
-        value: [[ .flowName ]]
-      - name: flow-type
-        value: [[ .flowType ]]
-      - name: flow-business-object
+      - name: matter
+        value: [[ .matter ]]
+      - name: create-user-id
+        value: [[ .create_user_id ]]
+      - name: business-object
         value: | 
-          [[ .flowBusinessObject ]]
+          [[ .business_object ]]
   templates:
     - name: front-json-flow
       steps:
@@ -49,8 +48,9 @@ spec:
               supplied: {}`
 
 type FlowBaseInfo struct {
-	Name           string
-	Type           string
+	Identifier     string
+	Matter         string
+	CreateUserID   string
 	BusinessObject string
 }
 
@@ -108,10 +108,10 @@ func (flow *Flow) Render(_ Noder) (string, error) {
 	}
 
 	return render("flow", flowTemplate, map[string]any{
-		"name":                   "flow-" + uuid.NewUUID()[:8],
-		"flowName":               flow.BaseInfo.Name,
-		"flowType":               flow.BaseInfo.Type,
-		"flowBusinessObject":     flow.BaseInfo.BusinessObject,
+		"name":                   "flow-" + flow.BaseInfo.Identifier,
+		"matter":                 flow.BaseInfo.Matter,
+		"create_user_id":         flow.BaseInfo.CreateUserID,
+		"business_object":        flow.BaseInfo.BusinessObject,
 		"childNodesContentLines": childNodesContents,
 	})
 }

+ 4 - 3
approve_former/parse.go

@@ -25,7 +25,7 @@ var (
 )
 
 // ParseFlowFromJson 解析当前云极和ERP使用的前端json格式,输出argo支持的模板字符串
-func ParseFlowFromJson(flowName, flowType, frontJson, argObj string) (string, error) {
+func ParseFlowFromJson(identifier, matter, createUserID, frontJson, argObj string) (string, error) {
 	var root Node
 	err := json.Unmarshal([]byte(frontJson), &root)
 	if err != nil {
@@ -37,8 +37,9 @@ func ParseFlowFromJson(flowName, flowType, frontJson, argObj string) (string, er
 
 	// 递归遍历流程节点,生成argo模板
 	flow := NewFlow(&FlowBaseInfo{
-		Name:           flowName,
-		Type:           flowType,
+		Identifier:     identifier,
+		Matter:         matter,
+		CreateUserID:   createUserID,
 		BusinessObject: argObj,
 	})
 	root.Children.NodeLevel = 1

+ 24 - 3
approve_former/parse_test.go

@@ -2,6 +2,8 @@ package approve_former
 
 import (
 	"fmt"
+	"git.sxidc.com/go-tools/argo-api"
+	"git.sxidc.com/go-tools/argo-api/client"
 	"github.com/stretchr/testify/assert"
 	"io"
 	"os"
@@ -12,7 +14,7 @@ import (
 func TestParseFlowFromJson(t *testing.T) {
 	// 测试结构解析
 	frontJson := readJsonFile("./front_json/full.json")
-	argoTmp, err := ParseFlowFromJson("full", "测试流程", frontJson, "")
+	argoTmp, err := ParseFlowFromJson("1", "测试流程", "duyong", frontJson, "")
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -21,19 +23,38 @@ func TestParseFlowFromJson(t *testing.T) {
 
 func TestParseEmptyFlowFromJson(t *testing.T) {
 	frontJson := readJsonFile("./front_json/empty.json")
-	_, err := ParseFlowFromJson("empty", "测试流程", frontJson, "")
+	_, err := ParseFlowFromJson("2", "测试流程", "duyong", frontJson, "")
 	assert.ErrorIs(t, err, ErrNodeEmpty)
 }
 
 func TestParseSingleFlowFromJsonFile(t *testing.T) {
 	frontJson := readJsonFile("./front_json/approval_one_user.json")
-	argoTmp, err := ParseFlowFromJson("single", "测试流程", frontJson, "")
+	argObj := `{"props":{"labelWidth":100,"labelPosition":"top","size":"large"},"formItems":[],"span":12}`
+	argoTmp, err := ParseFlowFromJson("3", "single", "duyong", frontJson, argObj)
 	if err != nil {
 		t.Fatal(err)
 	}
 	fmt.Println(argoTmp)
 }
 
+func TestGetParsedWorkfolw(t *testing.T) {
+	err := argo.Init("/Users/duyong/WorkPlace/fangshi/meta-business/argo/test/k3s.yaml")
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	defer argo.Destroy()
+
+	wfs, err := argo.GetInstance().GetWorkflowsInNamespace(client.GetWorkflowsInNamespaceParams{
+		Namespace: "default",
+	})
+	if err != nil {
+		t.Fatalf("%+v\n", err)
+	}
+
+	fmt.Println(wfs)
+}
+
 func readJsonFile(filePath string) string {
 	file, err := os.Open(filePath)
 	if err != nil {