Browse Source

修改业务对象为业务实体

wangbo 5 months ago
parent
commit
a53c7d92ae
6 changed files with 209 additions and 59 deletions
  1. 4 1
      go.mod
  2. 2 0
      go.sum
  3. 56 0
      ng_cws_client/api.go
  4. 79 51
      ng_cws_client/ng_cws_client.go
  5. 16 7
      service/request/workflow.go
  6. 52 0
      utils/request_util/util.go

+ 4 - 1
go.mod

@@ -1,6 +1,8 @@
 module git.sxidc.com/service-supports/cws-sdk
 
-go 1.21.1
+go 1.21.3
+
+toolchain go1.22.0
 
 require (
 	github.com/go-resty/resty/v2 v2.15.1
@@ -9,6 +11,7 @@ require (
 )
 
 require (
+	git.sxidc.com/go-tools/utils v1.5.32 // indirect
 	golang.org/x/net v0.27.0 // indirect
 	gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
 )

+ 2 - 0
go.sum

@@ -1,3 +1,5 @@
+git.sxidc.com/go-tools/utils v1.5.32 h1:FapJ86BJ8UfH12t9jP+9UOaoPX9ZtoN41HU8oFX0/A0=
+git.sxidc.com/go-tools/utils v1.5.32/go.mod h1:uTDb6QK5JZzK5+Fzsfeng7TwmnRDZiTY6JLYxIX94Qw=
 github.com/go-resty/resty/v2 v2.15.1 h1:vuna8FM2EaQ6IYbtjh+Gjh00uu7xEWuuGyTKeIaYkvE=
 github.com/go-resty/resty/v2 v2.15.1/go.mod h1:0fHAoK7JoBy/Ch36N8VFeMsK7xQOHhvWaC3iOktwmIU=
 github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=

+ 56 - 0
ng_cws_client/api.go

@@ -0,0 +1,56 @@
+package ng_cws_client
+
+import (
+	"encoding/json"
+	"errors"
+	"git.sxidc.com/service-supports/cws-sdk/service"
+	"git.sxidc.com/service-supports/cws-sdk/service/request"
+	"git.sxidc.com/service-supports/cws-sdk/service/response"
+	"git.sxidc.com/service-supports/cws-sdk/utils/http_client"
+)
+
+func launchWorkflowPrepareApi(reqParams *request.LaunchWorkflowPrepareParams) (*response.InfosResponse[response.PrepareInfo], error) {
+	requestJson, err := json.Marshal(reqParams)
+	if err != nil {
+		return nil, err
+	}
+	postResponse, err := NGCwsClient.NewRequest(http_client.WithNewRequestTimeout(cwsTimeOut)).
+		Post(cwsUrl+service.StartWorkFlowPrepareMethodName, 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)
+	}
+
+	return resp, nil
+}
+
+func getWorkTemplateInfoByBusinessTypeApi(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
+}

+ 79 - 51
ng_cws_client/ng_cws_client.go

@@ -8,6 +8,7 @@ import (
 	"git.sxidc.com/service-supports/cws-sdk/service/response"
 	"git.sxidc.com/service-supports/cws-sdk/utils"
 	"git.sxidc.com/service-supports/cws-sdk/utils/http_client"
+	"git.sxidc.com/service-supports/cws-sdk/utils/request_util"
 	"time"
 )
 
@@ -32,7 +33,7 @@ func Destroy() {
 
 func StartWorkFlowByBusinessType(reqParams *request.StartWorkFlowByBusinessTypeRequest) (string, error) {
 	//根据业务类型获取流程模型ID
-	workflowTemplateId, err := getWorkTemplateInfoByBusinessType(reqParams.BusinessType, reqParams.TenantID)
+	workflowTemplateId, err := getWorkTemplateInfoByBusinessTypeApi(reqParams.BusinessType, reqParams.TenantID)
 	if err != nil {
 		return "", err
 	}
@@ -54,16 +55,17 @@ func StartWorkFlowByBusinessType(reqParams *request.StartWorkFlowByBusinessTypeR
 	if err != nil {
 		return "", err
 	}
-	businessObjectStr := string(jsonBytes)
+	businessEntityObjectStr := string(jsonBytes)
 
 	workflowId, err := StartWorkflow(&request.StartWorkflowRequest{
-		WorkflowTemplateID: workflowTemplateId,
-		LaunchUserName:     reqParams.LaunchUserName,
-		Matter:             reqParams.Matter,
-		BusinessObject:     businessObjectStr,
-		UserStructureID:    customStructureInfo.ID,
-		CreateUserID:       reqParams.CreateUserID,
-		TenantID:           reqParams.TenantID,
+		WorkflowTemplateID:   workflowTemplateId,
+		LaunchUserName:       reqParams.LaunchUserName,
+		Matter:               reqParams.Matter,
+		BusinessEntityObject: businessEntityObjectStr,
+		BusinessObject:       businessEntityObjectStr,
+		UserStructureID:      customStructureInfo.ID,
+		CreateUserID:         reqParams.CreateUserID,
+		TenantID:             reqParams.TenantID,
 	})
 	if err != nil {
 		return "", err
@@ -73,6 +75,40 @@ func StartWorkFlowByBusinessType(reqParams *request.StartWorkFlowByBusinessTypeR
 
 }
 
+func StartWorkFlowWithoutPrepareByBusinessType(reqParams *request.StartWorkFlowWithoutPrepareByBusinessTypeRequest) (string, error) {
+	//根据业务类型获取流程模型ID
+	workflowTemplateId, err := getWorkTemplateInfoByBusinessTypeApi(reqParams.BusinessType, reqParams.TenantID)
+	if err != nil {
+		return "", err
+	}
+	if utils.IsStringEmpty(workflowTemplateId) {
+		return "", errors.New("该业务类型未配置流程")
+	}
+
+	jsonBytes, err := json.Marshal(reqParams.Data)
+	if err != nil {
+		return "", err
+	}
+	businessEntityObjectStr := string(jsonBytes)
+
+	workflowId, err := StartWorkflow(&request.StartWorkflowRequest{
+		WorkflowTemplateID:   workflowTemplateId,
+		LaunchUserName:       reqParams.LaunchUserName,
+		Matter:               reqParams.Matter,
+		BusinessEntityObject: businessEntityObjectStr,
+		BusinessObject:       businessEntityObjectStr,
+		UserStructureID:      reqParams.UserStructureID,
+		CreateUserID:         reqParams.CreateUserID,
+		TenantID:             reqParams.TenantID,
+		ChoiceApproveInfos:   reqParams.ChoiceApproveInfos,
+	})
+	if err != nil {
+		return "", err
+	}
+
+	return workflowId, nil
+}
+
 func StartWorkflowTemplate(reqParams *request.StartWorkflowTemplateRequest) (string, error) {
 	if utils.IsStringEmpty(cwsUrl) {
 		return "", errors.New("未配置CWS地址")
@@ -92,7 +128,7 @@ func StartWorkflowTemplate(reqParams *request.StartWorkflowTemplateRequest) (str
 	if err != nil {
 		return "", err
 	}
-	businessObjectStr := string(jsonBytes)
+	businessEntityObjectStr := string(jsonBytes)
 
 	reqJsonParams := &request.StartWorkflowTemplateRequest{
 		StructureRootID:      reqParams.StructureRootID,
@@ -100,7 +136,8 @@ func StartWorkflowTemplate(reqParams *request.StartWorkflowTemplateRequest) (str
 		Process:              reqParams.Process,
 		LaunchUserName:       reqParams.LaunchUserName,
 		Matter:               reqParams.Matter,
-		BusinessObject:       businessObjectStr,
+		BusinessEntityObject: businessEntityObjectStr,
+		BusinessObject:       businessEntityObjectStr,
 		UserStructureID:      customStructureInfo.ID,
 		CreateUserID:         reqParams.CreateUserID,
 		TenantID:             reqParams.TenantID,
@@ -135,7 +172,13 @@ func StartWorkflow(reqParams *request.StartWorkflowRequest) (string, error) {
 	if utils.IsStringEmpty(cwsUrl) {
 		return "", errors.New("未配置CWS地址")
 	}
-	requestJson, err := json.Marshal(reqParams)
+
+	reqMap := request_util.StructToMap(reqParams)
+	for nodeID, userIDs := range reqParams.ChoiceApproveInfos {
+		reqMap[nodeID] = userIDs
+	}
+
+	requestJson, err := json.Marshal(reqMap)
 	if err != nil {
 		return "", err
 	}
@@ -157,30 +200,6 @@ func StartWorkflow(reqParams *request.StartWorkflowRequest) (string, error) {
 	return resp.Info, 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
-}
-
 func LaunchWorkflowTemplatePrepare(reqParams *request.LaunchWorkflowTemplatePrepareParams) (*response.CustomStructureInfo, error) {
 	requestJson, err := json.Marshal(reqParams)
 	if err != nil {
@@ -212,24 +231,10 @@ func LaunchWorkflowTemplatePrepare(reqParams *request.LaunchWorkflowTemplatePrep
 }
 
 func LaunchWorkflowPrepare(reqParams *request.LaunchWorkflowPrepareParams) (*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.StartWorkFlowPrepareMethodName, requestJson)
-	if err != nil {
-		return nil, err
-	}
-
-	resp := new(response.InfosResponse[response.PrepareInfo])
-	err = postResponse.Json(resp)
+	resp, err := launchWorkflowPrepareApi(reqParams)
 	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" {
@@ -240,3 +245,26 @@ func LaunchWorkflowPrepare(reqParams *request.LaunchWorkflowPrepareParams) (*res
 
 	return customStructureInfo, nil
 }
+
+func LaunchWorkflowByBusinessTypePrepare(tenantID string, businessType string, createUserID string) ([]response.PrepareInfo, error) {
+	//根据业务类型获取流程模型ID
+	workflowTemplateId, err := getWorkTemplateInfoByBusinessTypeApi(businessType, tenantID)
+	if err != nil {
+		return nil, err
+	}
+	if utils.IsStringEmpty(workflowTemplateId) {
+		return nil, errors.New("该业务类型未配置流程")
+	}
+
+	//发起流程前校验 获取人员组织信息
+	resp, err := launchWorkflowPrepareApi(&request.LaunchWorkflowPrepareParams{
+		WorkflowTemplateID: workflowTemplateId,
+		CreateUserID:       createUserID,
+		TenantID:           tenantID,
+	})
+	if err != nil {
+		return nil, err
+	}
+
+	return resp.Infos, nil
+}

+ 16 - 7
service/request/workflow.go

@@ -18,6 +18,7 @@ type StartWorkflowTemplateRequest struct {
 	Process              string      `json:"process"`
 	LaunchUserName       string      `json:"launchUserName"`
 	Matter               string      `json:"matter"`
+	BusinessEntityObject string      `json:"businessEntityObject"`
 	BusinessObject       string      `json:"businessObject"`
 	UserStructureID      string      `json:"userStructureId"`
 	Data                 interface{} `json:"data"`
@@ -26,13 +27,15 @@ type StartWorkflowTemplateRequest struct {
 }
 
 type StartWorkflowRequest struct {
-	WorkflowTemplateID string `json:"workflowTemplateId"`
-	LaunchUserName     string `json:"launchUserName"`
-	Matter             string `json:"matter"`
-	BusinessObject     string `json:"businessObject"`
-	UserStructureID    string `json:"userStructureId"`
-	CreateUserID       string `json:"createUserId"`
-	TenantID           string `json:"tenantId"`
+	WorkflowTemplateID   string         `json:"workflowTemplateId"`
+	LaunchUserName       string         `json:"launchUserName"`
+	Matter               string         `json:"matter"`
+	BusinessEntityObject string         `json:"businessEntityObject"`
+	BusinessObject       string         `json:"businessObject"`
+	UserStructureID      string         `json:"userStructureId"`
+	CreateUserID         string         `json:"createUserId"`
+	TenantID             string         `json:"tenantId"`
+	ChoiceApproveInfos   map[string]any `json:"-"`
 }
 
 type StartWorkFlowByBusinessTypeRequest struct {
@@ -43,3 +46,9 @@ type StartWorkFlowByBusinessTypeRequest struct {
 	CreateUserID   string      `json:"createUserId"`
 	TenantID       string      `json:"tenantId"`
 }
+
+type StartWorkFlowWithoutPrepareByBusinessTypeRequest struct {
+	StartWorkFlowByBusinessTypeRequest
+	UserStructureID    string         `json:"userStructureId"`
+	ChoiceApproveInfos map[string]any `json:"choiceApproveInfos"`
+}

+ 52 - 0
utils/request_util/util.go

@@ -0,0 +1,52 @@
+package request_util
+
+import (
+	"encoding/json"
+	"git.sxidc.com/go-tools/utils/slice"
+)
+
+func StructToMap(originStruct any) map[string]any {
+	jsonBytes, err := json.Marshal(originStruct)
+	if err != nil {
+		panic(err)
+	}
+
+	retMap := make(map[string]any)
+	err = json.Unmarshal(jsonBytes, &retMap)
+	if err != nil {
+		panic(err)
+	}
+
+	return retMap
+}
+
+func ExtractDynamicValueMap(inputModelMap map[string]any, inputParamStruct any) (map[string]any, error) {
+	jsonBytes, err := json.Marshal(inputParamStruct)
+	if err != nil {
+		return nil, err
+	}
+	paramMap := make(map[string]any)
+	err = json.Unmarshal(jsonBytes, &paramMap)
+	if err != nil {
+		return nil, err
+	}
+
+	allValues := make([]string, 0)
+	paramValues := make([]string, 0)
+	for k := range inputModelMap {
+		allValues = append(allValues, k)
+	}
+	for k := range paramMap {
+		paramValues = append(paramValues, k)
+	}
+	extraKeys := slice.ExtractASubBSetValue(allValues, paramValues)
+
+	dynamicValueMap := make(map[string]any)
+	for _, key := range extraKeys {
+		if inputModelAny, ok := inputModelMap[key]; ok {
+			dynamicValueMap[key] = inputModelAny
+		}
+	}
+	return dynamicValueMap, nil
+
+}