Browse Source

添加 发起流程模板审批

wangbo 6 days ago
parent
commit
4eed89c76b
3 changed files with 113 additions and 15 deletions
  1. 88 6
      ng_cws_client/ng_cws_client.go
  2. 6 4
      service/method_names.go
  3. 19 5
      service/request/workflow.go

+ 88 - 6
ng_cws_client/ng_cws_client.go

@@ -50,11 +50,6 @@ func StartWorkFlowByBusinessType(reqParams *request.StartWorkFlowByBusinessTypeR
 		return "", err
 	}
 
-	////发起流程
-	//businessObject := &request.WorkflowBusinessObject{
-	//	BusinessType:   reqParams.BusinessType,
-	//	BusinessObject: reqParams.Data,
-	//}
 	jsonBytes, err := json.Marshal(reqParams.Data)
 	if err != nil {
 		return "", err
@@ -78,6 +73,64 @@ func StartWorkFlowByBusinessType(reqParams *request.StartWorkFlowByBusinessTypeR
 
 }
 
+func StartWorkflowTemplate(reqParams *request.StartWorkflowTemplateRequest) (string, error) {
+	if utils.IsStringEmpty(cwsUrl) {
+		return "", errors.New("未配置CWS地址")
+	}
+
+	//发起流程前校验 获取人员组织信息
+	customStructureInfo, err := LaunchWorkflowTemplatePrepare(&request.LaunchWorkflowTemplatePrepareParams{
+		StructureRootID: reqParams.StructureRootID,
+		CreateUserID:    reqParams.CreateUserID,
+		TenantID:        reqParams.TenantID,
+	})
+	if err != nil {
+		return "", err
+	}
+
+	jsonBytes, err := json.Marshal(reqParams.Data)
+	if err != nil {
+		return "", err
+	}
+	businessObjectStr := string(jsonBytes)
+
+	reqJsonParams := &request.StartWorkflowTemplateRequest{
+		StructureRootID:      reqParams.StructureRootID,
+		WorkflowTemplateName: reqParams.WorkflowTemplateName,
+		Process:              reqParams.Process,
+		LaunchUserName:       reqParams.LaunchUserName,
+		Matter:               reqParams.Matter,
+		BusinessObject:       businessObjectStr,
+		UserStructureID:      customStructureInfo.ID,
+		CreateUserID:         reqParams.CreateUserID,
+		TenantID:             reqParams.TenantID,
+	}
+	if err != nil {
+		return "", err
+	}
+
+	requestJson, err := json.Marshal(reqJsonParams)
+	if err != nil {
+		return "", err
+	}
+	postResponse, err := NGCwsClient.NewRequest(http_client.WithNewRequestTimeout(cwsTimeOut)).
+		Post(cwsUrl+service.StartWorkFlowTemplateMethodName, requestJson)
+	if err != nil {
+		return "", err
+	}
+
+	resp := new(response.InfoResponse[string])
+	err = postResponse.Json(resp)
+	if err != nil {
+		return "", err
+	}
+	if !resp.Success {
+		return "", errors.New(resp.Msg)
+	}
+
+	return resp.Info, nil
+}
+
 func StartWorkflow(reqParams *request.StartWorkflowRequest) (string, error) {
 	if utils.IsStringEmpty(cwsUrl) {
 		return "", errors.New("未配置CWS地址")
@@ -128,8 +181,37 @@ func getWorkTemplateInfoByBusinessType(businessType string, tenantId string) (st
 	return respInfo.Info.WorkTemplateId, nil
 }
 
-func LaunchWorkflowPrepare(reqParams *request.LaunchWorkflowPrepareParams) (*response.CustomStructureInfo, error) {
+func LaunchWorkflowTemplatePrepare(reqParams *request.LaunchWorkflowTemplatePrepareParams) (*response.CustomStructureInfo, error) {
+	requestJson, err := json.Marshal(reqParams)
+	if err != nil {
+		return nil, err
+	}
+	postResponse, err := NGCwsClient.NewRequest(http_client.WithNewRequestTimeout(cwsTimeOut)).
+		Post(cwsUrl+service.StartWorkFlowTemplatePrepareMethodName, requestJson)
+	if err != nil {
+		return nil, err
+	}
 
+	resp := new(response.InfosResponse[response.PrepareInfo])
+	err = postResponse.Json(resp)
+	if err != nil {
+		return nil, err
+	}
+	if !resp.Success {
+		return nil, errors.New(resp.Msg)
+	}
+	customStructureInfo := &response.CustomStructureInfo{}
+	for _, info := range resp.Infos {
+		if info.ID == "userStructureId" {
+			customStructureInfo.ID = info.Options[0].Value
+			break
+		}
+	}
+
+	return customStructureInfo, nil
+}
+
+func LaunchWorkflowPrepare(reqParams *request.LaunchWorkflowPrepareParams) (*response.CustomStructureInfo, error) {
 	requestJson, err := json.Marshal(reqParams)
 	if err != nil {
 		return nil, err

+ 6 - 4
service/method_names.go

@@ -1,8 +1,10 @@
 package service
 
 const (
-	methodNamePrefix                = "cws/api/v1"
-	StartWorkFlowPrepareMethodName  = methodNamePrefix + "/workflow/launch/prepare"
-	StartWorkFlowMethodName         = methodNamePrefix + "/workflow/launch"
-	GetWorkTemplateByCodeMethodName = methodNamePrefix + "/businessCatalogs/code/getWithWorkTemplate"
+	methodNamePrefix                       = "cws/api/v1"
+	StartWorkFlowPrepareMethodName         = methodNamePrefix + "/workflow/launch/prepare"
+	StartWorkFlowMethodName                = methodNamePrefix + "/workflow/launch"
+	GetWorkTemplateByCodeMethodName        = methodNamePrefix + "/businessCatalogs/code/getWithWorkTemplate"
+	StartWorkFlowTemplatePrepareMethodName = methodNamePrefix + "/workflow/template/launch/prepare"
+	StartWorkFlowTemplateMethodName        = methodNamePrefix + "/workflow/template/launch"
 )

+ 19 - 5
service/request/workflow.go

@@ -1,16 +1,30 @@
 package request
 
-type WorkflowBusinessObject struct {
-	BusinessType   string      `json:"businessType"`
-	BusinessObject interface{} `json:"businessObject"`
-}
-
 type LaunchWorkflowPrepareParams struct {
 	WorkflowTemplateID string `json:"workflowTemplateId" binding:"required" assign:"toField:WorkflowTemplateID"`
 	CreateUserID       string `json:"createUserId" binding:"required"  assign:"toField:CreateUserID"`
 	TenantID           string `json:"tenantId" binding:"required"  assign:"toField:TenantID"`
 }
 
+type LaunchWorkflowTemplatePrepareParams struct {
+	StructureRootID string `json:"structureRootId" binding:"required"`
+	CreateUserID    string `json:"createUserId" binding:"required"  assign:"toField:CreateUserID"`
+	TenantID        string `json:"tenantId" binding:"required"  assign:"toField:TenantID"`
+}
+
+type StartWorkflowTemplateRequest struct {
+	WorkflowTemplateName string      `json:"workflowTemplateName"`
+	StructureRootID      string      `json:"structureRootId"`
+	Process              string      `json:"process"`
+	LaunchUserName       string      `json:"launchUserName"`
+	Matter               string      `json:"matter"`
+	BusinessObject       string      `json:"businessObject"`
+	UserStructureID      string      `json:"userStructureId"`
+	Data                 interface{} `json:"data"`
+	CreateUserID         string      `json:"createUserId"`
+	TenantID             string      `json:"tenantId"`
+}
+
 type StartWorkflowRequest struct {
 	WorkflowTemplateID string `json:"workflowTemplateId"`
 	LaunchUserName     string `json:"launchUserName"`