Bläddra i källkod

发起流程校验是否配置流程改为调用接口动态调用

张亚军 1 månad sedan
förälder
incheckning
d859d9906a
3 ändrade filer med 52 tillägg och 7 borttagningar
  1. 31 5
      ng_cws_client/ng_cws_client.go
  2. 3 2
      service/method_names.go
  3. 18 0
      service/response/workflow.go

+ 31 - 5
ng_cws_client/ng_cws_client.go

@@ -52,9 +52,12 @@ var workflowTemplateMap = map[string]string{
 
 func StartWorkFlowByBusinessType(reqParams *request.StartWorkFlowByBusinessTypeRequest) error {
 	//根据业务类型获取流程模型ID
-	workflowTempalteId := workflowTemplateMap[reqParams.BusinessType]
-	if utils.IsStringEmpty(workflowTempalteId) {
-		return errors.New("未配置流程")
+	workflowTemplateId, err := getWorkTemplateInfoByBusinessType(reqParams.BusinessType, reqParams.TenantID)
+	if err != nil {
+		return err
+	}
+	if utils.IsStringEmpty(workflowTemplateId) {
+		return errors.New("该业务类型未配置流程")
 	}
 
 	businessObject := &request.WorkflowBusinessObject{
@@ -69,7 +72,7 @@ func StartWorkFlowByBusinessType(reqParams *request.StartWorkFlowByBusinessTypeR
 
 	err = StartWorkflow(&request.StartWorkflowRequest{
 		LaunchUserName:     reqParams.LaunchUserName,
-		WorkflowTemplateID: workflowTempalteId,
+		WorkflowTemplateID: workflowTemplateId,
 		Matter:             reqParams.Matter,
 		BusinessObject:     businessObjectStr,
 		CreateUserID:       reqParams.CreateUserID,
@@ -102,10 +105,33 @@ func StartWorkflow(reqParams *request.StartWorkflowRequest) error {
 	if err != nil {
 		return err
 	}
-
 	if !resp.Success {
 		return errors.New(resp.Msg)
 	}
 
 	return nil
 }
+
+func getWorkTemplateInfoByBusinessType(businessType string, tenantId string) (string, error) {
+
+	//查询业务类型配置
+	queryParams := map[string]string{
+		"code":     businessType,
+		"tenantId": tenantId,
+	}
+	newRequest := NGCwsClient.NewRequest(http_client.WithNewRequestTimeout(cwsTimeOut))
+	newRequest.SetQueryParams(queryParams)
+	resp, err := newRequest.Get(cwsUrl + service.GetWorkTemplateByCodeMethodName)
+	if err != nil {
+		return "", err
+	}
+	respInfo := new(response.InfoResponse[response.BusinessCatalogsInfoWithWorkflowTemplate])
+	err = resp.Json(respInfo)
+	if err != nil {
+		return "", err
+	}
+	if !respInfo.Success {
+		return "", errors.New(respInfo.Msg)
+	}
+	return respInfo.Info.WorkTemplateId, nil
+}

+ 3 - 2
service/method_names.go

@@ -1,6 +1,7 @@
 package service
 
 const (
-	methodNamePrefix        = "cws/api/v1"
-	StartWorkFlowMethodName = methodNamePrefix + "/workflow/launch"
+	methodNamePrefix                = "cws/api/v1"
+	StartWorkFlowMethodName         = methodNamePrefix + "/workflow/launch"
+	GetWorkTemplateByCodeMethodName = methodNamePrefix + "/businessCatalogs/code/getWithWorkTemplate"
 )

+ 18 - 0
service/response/workflow.go

@@ -5,3 +5,21 @@ type MsgResponse struct {
 	ErrCode int    `json:"errCode"`
 	Msg     string `json:"msg"`
 }
+
+type InfoResponse[T any] struct {
+	MsgResponse
+	Info T `json:"info"`
+}
+
+type BusinessCatalogsInfoWithWorkflowTemplate struct {
+	ID               string `json:"id"`
+	Name             string `json:"name"`
+	Code             string `json:"code"`
+	Sort             int    `json:"sort"`
+	TenantID         string `json:"tenantId" `
+	CreateUserID     string `json:"createUserId"`
+	LastUpdateUserID string `json:"lastUpdateUserId"`
+	CreatedTime      string `json:"createdTime"`
+	LastUpdatedTime  string `json:"lastUpdatedTime"`
+	WorkTemplateId   string `json:"workTemplateId"`
+}