Sfoglia il codice sorgente

更新sdk,发起流程增加前置校验并增加参数用户自定义组织ID

张亚军 3 mesi fa
parent
commit
a551d1ed44

+ 48 - 21
ng_cws_client/ng_cws_client.go

@@ -30,26 +30,6 @@ func Destroy() {
 	http_client.Destroy(NGCwsClient)
 }
 
-var workflowTemplateMap = map[string]string{
-	"CGJH":  "4e0f65ab8547436ba9f744c4dcaef14e",
-	"CGDD":  "5e9bb84779b34d31947107f2c4ead93d",
-	"CGHT":  "d0c7ac374d2a4ed58cd2ee5f1c065110",
-	"RKZJ":  "ffc0b6044e154707ad80d174c08236be",
-	"RKYS":  "bdf8eeaf78c146cd914aef8067dea8b2",
-	"RK":    "2b6338dcdddb4e51b992347e87a1044a",
-	"XSHT":  "2f1997724b4b49c99379a18bf7067cee",
-	"XSDD":  "e73bd99b5761464ea74a612d3eaf3ea7",
-	"CK":    "f82e46c9c4c04862a9babbf3734432e8",
-	"SCJH":  "762685ccfdc3499590d99d3a8d55b78f",
-	"SCGD":  "0d43eaff78bb4abf9d6c5634b74e212e",
-	"SCZJ":  "f5c091e62e6a4cef9a68fda99736fd2e",
-	"BSD":   "0973c19af66546899638d816cf5ee5c6",
-	"BYD":   "9d9762864db14271ad9ada7acc73bacd",
-	"DBD":   "c8aff838c20741758de134903d24934a",
-	"KHTH":  "1e12eb97c9db4e53bb0704bb1c3d93f7",
-	"GYSTH": "459542e8b07a4cda93d98ba0234c079f",
-}
-
 func StartWorkFlowByBusinessType(reqParams *request.StartWorkFlowByBusinessTypeRequest) error {
 	//根据业务类型获取流程模型ID
 	workflowTemplateId, err := getWorkTemplateInfoByBusinessType(reqParams.BusinessType, reqParams.TenantID)
@@ -60,6 +40,17 @@ func StartWorkFlowByBusinessType(reqParams *request.StartWorkFlowByBusinessTypeR
 		return errors.New("该业务类型未配置流程")
 	}
 
+	//发起流程前校验 获取人员组织信息
+	customStructureInfo, err := LaunchWorkflowPrepare(&request.LaunchWorkflowPrepareParams{
+		WorkflowTemplateID: workflowTemplateId,
+		CreateUserID:       reqParams.CreateUserID,
+		TenantID:           reqParams.TenantID,
+	})
+	if err != nil {
+		return err
+	}
+
+	//发起流程
 	businessObject := &request.WorkflowBusinessObject{
 		BusinessType:   reqParams.BusinessType,
 		BusinessObject: reqParams.Data,
@@ -71,10 +62,11 @@ func StartWorkFlowByBusinessType(reqParams *request.StartWorkFlowByBusinessTypeR
 	businessObjectStr := string(jsonBytes)
 
 	err = StartWorkflow(&request.StartWorkflowRequest{
-		LaunchUserName:     reqParams.LaunchUserName,
 		WorkflowTemplateID: workflowTemplateId,
+		LaunchUserName:     reqParams.LaunchUserName,
 		Matter:             reqParams.Matter,
 		BusinessObject:     businessObjectStr,
+		UserStructureID:    customStructureInfo.ID,
 		CreateUserID:       reqParams.CreateUserID,
 		TenantID:           reqParams.TenantID,
 	})
@@ -135,3 +127,38 @@ func getWorkTemplateInfoByBusinessType(businessType string, tenantId string) (st
 	}
 	return respInfo.Info.WorkTemplateId, nil
 }
+
+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)
+	if err != nil {
+		return nil, err
+	}
+	if !resp.Success {
+		return nil, errors.New(resp.Msg)
+	}
+	customStructureInfo := &response.CustomStructureInfo{}
+	for _, info := range resp.Infos {
+		if 1 == info.Flag && len(info.ChooseData) > 0 {
+			customStructureInfo = &info.ChooseData[0]
+			break
+		}
+	}
+
+	if utils.IsStringEmpty(customStructureInfo.ID) {
+		return nil, errors.New("发起流程前校验异常,人员组织信息不存在")
+	}
+
+	return customStructureInfo, nil
+}

+ 1 - 0
service/method_names.go

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

+ 7 - 0
service/request/workflow.go

@@ -5,11 +5,18 @@ type WorkflowBusinessObject struct {
 	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 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"`
 }

+ 34 - 0
service/response/workflow.go

@@ -6,11 +6,22 @@ type MsgResponse struct {
 	Msg     string `json:"msg"`
 }
 
+type InfosData[T any] struct {
+	Infos      []T   `json:"infos"`
+	TotalCount int64 `json:"totalCount"`
+	PageNo     int   `json:"pageNo"`
+}
+
 type InfoResponse[T any] struct {
 	MsgResponse
 	Info T `json:"info"`
 }
 
+type InfosResponse[T any] struct {
+	MsgResponse
+	InfosData[T]
+}
+
 type BusinessCatalogsInfoWithWorkflowTemplate struct {
 	ID               string `json:"id"`
 	Name             string `json:"name"`
@@ -23,3 +34,26 @@ type BusinessCatalogsInfoWithWorkflowTemplate struct {
 	LastUpdatedTime  string `json:"lastUpdatedTime"`
 	WorkTemplateId   string `json:"workTemplateId"`
 }
+
+type PrepareInfo struct {
+	Flag               int                   `json:"flag"` // 1-选择部门 2-选择审批人
+	WorkflowFieldLabel string                `json:"workflowFieldLabel"`
+	ChooseData         []CustomStructureInfo `json:"chooseData"`
+	WorkflowFieldName  string                `json:"workflowFieldName"`
+}
+
+type CustomStructureInfo struct {
+	ID               string `json:"id"`
+	Name             string `json:"name"`
+	Visible          int    `json:"visible"`
+	Sort             int    `json:"sort"`
+	ParentID         string `json:"parentId"`
+	Paths            string `json:"paths" `
+	LeaderUserID     string `json:"leaderUserId" `
+	LeaderUserName   string `json:"leaderUserName"`
+	TenantID         string `json:"tenantId"`
+	CreateUserID     string `json:"createUserId"`
+	LastUpdateUserID string `json:"lastUpdateUserId"`
+	CreatedTime      string `json:"createdTime"`
+	LastUpdatedTime  string `json:"lastUpdatedTime"`
+}