package approve_former import ( "strings" ) const flowTemplate = `apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: generateName: [[ .name ]]- spec: entrypoint: front-json-flow arguments: parameters: - name: matter value: [[ .matter ]] - name: create-user-id value: [[ .create_user_id ]] - name: business-object value: | [[ .business_object ]] templates: - name: front-json-flow steps: [[- if .childNodesContentLines ]] [[- range .childNodesContentLines ]] [[ . ]] [[- end ]] [[- else ]] - name: parse-flow template: approval [[- end ]] - name: approval suspend: {} inputs: parameters: - name: front-json default: '通过' enum: - '通过' - '拒绝' - '忽略' outputs: parameters: - name: front-json valueFrom: supplied: {}` type FlowBaseInfo struct { Identifier string Matter string CreateUserID string BusinessObject string } type Flow struct { BaseInfo *FlowBaseInfo childNodes []Noder } func NewFlow(baseInfo *FlowBaseInfo, childNodes ...Noder) *Flow { return &Flow{ BaseInfo: baseInfo, childNodes: childNodes, } } func (flow *Flow) GetDepends() string { return "" } func (flow *Flow) GetWhen() string { return "" } func (flow *Flow) AddNodes(childNodes ...Noder) *Flow { if childNodes == nil || len(childNodes) == 0 { return flow } flow.childNodes = append(flow.childNodes, childNodes...) return flow } func (flow *Flow) Render(_ Noder) (string, error) { childNodesContents := make([]string, 0) for i, childNode := range flow.childNodes { var childNodeContent string if i == 0 { content, err := childNode.Render(nil) if err != nil { return "", err } childNodeContent = content } else { content, err := childNode.Render(flow.childNodes[i-1]) if err != nil { return "", err } childNodeContent = content } childNodesContents = append(childNodesContents, strings.Split(childNodeContent, "\n")...) } return render("flow", flowTemplate, map[string]any{ "name": "flow-" + flow.BaseInfo.Identifier, "matter": flow.BaseInfo.Matter, "create_user_id": flow.BaseInfo.CreateUserID, "business_object": flow.BaseInfo.BusinessObject, "childNodesContentLines": childNodesContents, }) }