Parcourir la source

feat: 新增获取标签对应机构人员信息

黄资权 il y a 1 an
Parent
commit
f04015a721

+ 33 - 0
approve-api/src/main/java/com/dragonsoft/dcuc/approve/facade/api/v3/IApiV3WorkFlowCallbackFacade.java

@@ -0,0 +1,33 @@
+package com.dragonsoft.dcuc.approve.facade.api.v3;
+
+import io.swagger.annotations.Api;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <p>
+ *
+ * </p>
+ *
+ * @author huangziquan
+ * @date 2024/3/1
+ */
+@Api(tags = "工作流回调服务接口")
+@FeignClient(name = "approve", path = "api/v3/work-flow-callback/")
+public interface IApiV3WorkFlowCallbackFacade {
+    /**
+     * 1、先获取当前机构所属标签的人
+     * 2、无人员再获取上级机构所属标签的人,循环获取直至顶级节点
+     * 3、获取配置的兜底审批人员
+     *
+     * @param param 参数
+     * @return 进行审批的人员身份证号码
+     */
+    @PostMapping("current-org-next/handlers")
+    List<String> getCurrentOrgAndNextOrgLabelHandlers(@RequestBody Map<String, Object> param);
+
+}

+ 10 - 6
approve-core-service/src/main/java/com/dragonsoft/dcuc/approve/business/api/impl/ApiV3ApproveBusinessImpl.java

@@ -271,14 +271,18 @@ public class ApiV3ApproveBusinessImpl implements IApiV3ApproveBusiness {
         if (StrUtil.isAllBlank(jqbh, ajbh)) {
             return ResponseUtil.dtoFail("警情编号、案件编号其中一个必填");
         }
-        // 校验警情编号是否存在
-        if (!jqInfoService.exitsJqbh(jqbh)) {
-            return ResponseUtil.dtoFail(String.format("警情编号:%s 不存在", jqbh));
+        if (StrUtil.isNotBlank(jqbh)) {
+            // 校验警情编号是否存在
+            if (!jqInfoService.exitsJqbh(jqbh)) {
+                return ResponseUtil.dtoFail(String.format("警情编号:%s 不存在", jqbh));
+            }
         }
 
-        // 校验案件编号是否存在
-        if (!ajInfoService.exitsAjbh(ajbh)) {
-            return ResponseUtil.dtoFail(String.format("案件编号:%s 不存在", ajbh));
+        if (StrUtil.isNotBlank(ajbh)) {
+            // 校验案件编号是否存在
+            if (!ajInfoService.exitsAjbh(ajbh)) {
+                return ResponseUtil.dtoFail(String.format("案件编号:%s 不存在", ajbh));
+            }
         }
 
         approvalInfoReqVO.setFlowType(FlowTypeEnum.TASK.getValue());

+ 13 - 0
approve-core-service/src/main/java/com/dragonsoft/dcuc/approve/business/external/IDcucBusiness.java

@@ -5,6 +5,9 @@ import com.dragoninfo.dcuc.common.entity.ApiSearchReq;
 import com.dragonsoft.dcuc.approve.model.vo.dcuc.ApiOrgResultVo;
 import com.dragonsoft.dcuc.approve.model.vo.dcuc.ApiPoliceResultVo;
 import com.dragonsoft.dcuc.approve.model.vo.dcuc.OauthUserVO;
+import com.dragonsoft.dcuc.approve.model.vo.dcuc.UserLabel2RespVO;
+
+import java.util.List;
 
 /**
  * <p>
@@ -50,9 +53,19 @@ public interface IDcucBusiness {
 
     /**
      * 根据身份证号查询警员信息
+     *
      * @param idcard 身份证号
      * @return 警员信息
      */
     ApiPoliceResultVo policeDetailByIdcard(String idcard);
 
+    /**
+     * 根据标签代码获取对应人员信息
+     *
+     * @param orgCode   机构代码
+     * @param labelCode 标签代码
+     * @return 人员信息
+     */
+    List<UserLabel2RespVO> getUserByLabelCode(String orgCode, String labelCode);
+
 }

+ 25 - 0
approve-core-service/src/main/java/com/dragonsoft/dcuc/approve/business/external/IWorkFlowCallbackBusiness.java

@@ -0,0 +1,25 @@
+package com.dragonsoft.dcuc.approve.business.external;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <p>
+ * 工作流回调
+ * </p>
+ *
+ * @author huangziquan
+ * @date 2024/3/1
+ */
+public interface IWorkFlowCallbackBusiness {
+    /**
+     * 1、先获取当前机构所属标签的人
+     * 2、无人员再获取上级机构所属标签的人,循环获取直至顶级节点
+     * 3、获取配置的兜底审批人员
+     *
+     * @param param 参数
+     * @return 进行审批的人员身份证号码
+     */
+    List<String> getCurrentOrgAndNextOrgLabelHandlers(Map<String, Object> param);
+
+}

+ 78 - 2
approve-core-service/src/main/java/com/dragonsoft/dcuc/approve/business/external/impl/DcucBusinessImpl.java

@@ -7,12 +7,14 @@ import com.alibaba.fastjson.JSONObject;
 import com.dragoninfo.dcuc.common.entity.ApiResult;
 import com.dragoninfo.dcuc.common.entity.ApiResultPage;
 import com.dragoninfo.dcuc.common.entity.ApiSearchReq;
+import com.dragoninfo.dcuc.common.entity.SearchParam;
 import com.dragoninfo.dcuc.common.utils.ResponseUtil;
 import com.dragonsoft.dcuc.approve.business.external.IDcucBusiness;
 import com.dragonsoft.dcuc.approve.constants.ApproveBeanConstants;
 import com.dragonsoft.dcuc.approve.model.vo.dcuc.ApiOrgResultVo;
 import com.dragonsoft.dcuc.approve.model.vo.dcuc.ApiPoliceResultVo;
 import com.dragonsoft.dcuc.approve.model.vo.dcuc.OauthUserVO;
+import com.dragonsoft.dcuc.approve.model.vo.dcuc.UserLabel2RespVO;
 import com.dragonsoft.dcuc.approve.properties.ApproveProperties;
 import com.dragonsoft.dcuc.approve.utils.ProofsUtil;
 import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
@@ -20,6 +22,7 @@ import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
 import com.dragonsoft.duceap.base.entity.security.SecurityUser;
 import com.dragonsoft.duceap.base.utils.UserContextUtils;
 import com.dragonsoft.duceap.commons.util.json.JsonUtils;
+import com.dragonsoft.duceap.core.search.enums.SearchOperator;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -29,18 +32,21 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.http.*;
+import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 
 import java.net.URI;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
- * @author lidr
+ * @author lidr huangziquan
  * @date 2021/2/23
  */
-@Service
+@Component
 public class DcucBusinessImpl implements IDcucBusiness {
     private static final Logger logger = LoggerFactory.getLogger(DcucBusinessImpl.class);
 
@@ -61,6 +67,11 @@ public class DcucBusinessImpl implements IDcucBusiness {
      */
     public static final String POLICE_DETAIL_API = "/api/user-service/v3/users/police/%s";
 
+    /**
+     * 用户标签查询
+     */
+    public static final String LABEL_USER_API = "/api/user-service/v1/users/label/search";
+
     private RestTemplate restTemplate;
 
     private ApproveProperties approveProperties;
@@ -228,6 +239,71 @@ public class DcucBusinessImpl implements IDcucBusiness {
         return oauthUserVO;
     }
 
+    @Override
+    public List<UserLabel2RespVO> getUserByLabelCode(String orgCode, String labelCode) {
+        SearchParam labelSearchParam = new SearchParam();
+        labelSearchParam.setOperator(SearchOperator.eq.name());
+        labelSearchParam.setValue(labelCode);
+
+        SearchParam orgCodeSearchParam = new SearchParam();
+        orgCodeSearchParam.setOperator(SearchOperator.eq.name());
+        orgCodeSearchParam.setValue(orgCode);
+
+        Map<String, SearchParam> filters = new HashMap<>(2);
+        filters.put("orgCode", orgCodeSearchParam);
+        filters.put("labelCode", labelSearchParam);
+
+        ApiSearchReq apiSearchReq = ApiSearchReq.reqInfo(1, 1000, filters);
+
+        ApiResultPage<UserLabel2RespVO> page = labelPage(apiSearchReq);
+        Long total = page.getTotal();
+        List<UserLabel2RespVO> content = page.getContent();
+        // todo 循环获取全部
+        return content;
+    }
+
+    @SneakyThrows(JsonProcessingException.class)
+    public ApiResultPage<UserLabel2RespVO> labelPage(ApiSearchReq apiSearchReq) {
+        Assert.notNull(apiSearchReq);
+        String requestName = "获取人员标签列表";
+
+        String userServiceUrl = approveProperties.getUserServiceUrl();
+        String url = userServiceUrl + LABEL_USER_API;
+
+        HttpHeaders httpHeaders = HttpHeaders.EMPTY;
+        SecurityUser currentUser = UserContextUtils.getCurrentUser();
+        if (ObjectUtil.isNotNull(currentUser)) {
+            httpHeaders = ProofsUtil.buildHttpHeaders(currentUser);
+        }
+
+        RequestEntity<ApiSearchReq> apiSearchReqRequestEntity = new RequestEntity<>(apiSearchReq, httpHeaders, HttpMethod.POST, URI.create(url));
+        logger.info(requestName + "参数:{}", JsonUtils.toJSONString(apiSearchReqRequestEntity));
+        ResponseEntity<String> resEntity = restTemplate.exchange(apiSearchReqRequestEntity, String.class);
+        String jsonString = JsonUtils.toJSONString(resEntity);
+        logger.info(requestName + "返回参数:{}", jsonString);
+        if (!resEntity.getStatusCode().is2xxSuccessful()) {
+            logger.error(requestName + "信息错误:{}", jsonString);
+            return null;
+        }
+
+        String body = resEntity.getBody();
+        ApiResult apiResult = JSONObject.parseObject(body, ApiResult.class);
+        if (ObjectUtil.isNull(apiResult)) {
+            logger.error(requestName + "信息错误:{}", body);
+            return null;
+        }
+        if (!apiResult.getStatusCode().equalsIgnoreCase(ResponseStatus.SUCCESS_CODE)) {
+            logger.error(requestName + "信息错误:{}", body);
+            return null;
+        }
+
+        Object result = apiResult.getResult();
+        String resultJson = objectMapper.writeValueAsString(result);
+        TypeReference<ApiResultPage<UserLabel2RespVO>> typeReference = new TypeReference<ApiResultPage<UserLabel2RespVO>>() {
+        };
+        return objectMapper.readValue(resultJson, typeReference);
+    }
+
     @Override
     @SneakyThrows(JsonProcessingException.class)
     public ApiResultPage<ApiPoliceResultVo> policePage(ApiSearchReq apiSearchReq) {

+ 96 - 0
approve-core-service/src/main/java/com/dragonsoft/dcuc/approve/business/external/impl/DcucWorkFlowCallbackBusinessImpl.java

@@ -0,0 +1,96 @@
+package com.dragonsoft.dcuc.approve.business.external.impl;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.map.MapUtil;
+import com.dragonsoft.dcuc.approve.business.external.IDcucBusiness;
+import com.dragonsoft.dcuc.approve.business.external.IWorkFlowCallbackBusiness;
+import com.dragonsoft.dcuc.approve.model.vo.dcuc.ApiOrgResultVo;
+import com.dragonsoft.dcuc.approve.model.vo.dcuc.OauthUserVO;
+import com.dragonsoft.dcuc.approve.model.vo.dcuc.UserLabel2RespVO;
+import com.dragonsoft.dcuc.approve.properties.ApproveWorkFlowCallbackProperties;
+import com.dragonsoft.duceap.commons.util.json.JsonUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * <p>
+ *
+ * </p>
+ *
+ * @author huangziquan
+ * @date 2024/3/1
+ */
+@Slf4j
+@Component
+public class DcucWorkFlowCallbackBusinessImpl implements IWorkFlowCallbackBusiness {
+
+    private ApproveWorkFlowCallbackProperties approveWorkFlowCallbackProperties;
+
+    private IDcucBusiness dcucBusiness;
+
+    @Autowired
+    public void setDcucBusiness(IDcucBusiness dcucBusiness) {
+        this.dcucBusiness = dcucBusiness;
+    }
+
+    @Autowired
+    public void setApproveWorkFlowCallbackProperties(ApproveWorkFlowCallbackProperties approveWorkFlowCallbackProperties) {
+        this.approveWorkFlowCallbackProperties = approveWorkFlowCallbackProperties;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public List<String> getCurrentOrgAndNextOrgLabelHandlers(Map<String, Object> param) {
+        String reqJsonString = JsonUtils.toJSONString(param);
+        log.debug("工作流回调请求参数:{}", reqJsonString);
+
+        Map<String, Object> contextMap = (Map<String, Object>) param.get("context");
+        Map<String, Object> dataMap = (Map<String, Object>) param.get("data");
+        // 需要提交才有
+        String handleUser = MapUtil.getStr(dataMap, "handleUser");
+        // 获取申请人对应的机构代码
+        OauthUserVO handleUserInfo = dcucBusiness.getOauthUserInfoByIdcard(handleUser);
+        String currentOrgCode = handleUserInfo.getOrgCode();
+
+        String labelCode = approveWorkFlowCallbackProperties.getLabelCode();
+        // 获取机构代码上有这个标签的人
+        List<String> approverList = getOrgLabelUser(currentOrgCode, labelCode);
+
+        if (CollUtil.isEmpty(approverList)) {
+            // 看有没有再获取上级机构的
+            // todo 确认需求是获取上一级还是只是获取上级
+            ApiOrgResultVo apiOrgResultVo = dcucBusiness.orgInfo(currentOrgCode);
+            String upOrgCode = apiOrgResultVo.getUpOrgCode();
+            approverList = getOrgLabelUser(upOrgCode, labelCode);
+        }
+
+        // 没有的话获取兜底的科信审批人员
+        if (CollUtil.isEmpty(approverList)) {
+            approverList = approveWorkFlowCallbackProperties.getFinalApproveList();
+        }
+        return approverList;
+    }
+
+    /**
+     * 根据机构代码、标签代码获取审批人员
+     *
+     * @param orgCode   机构代码
+     * @param labelCode 标签代码
+     * @return 审批人
+     */
+    protected List<String> getOrgLabelUser(String orgCode, String labelCode) {
+        List<UserLabel2RespVO> userByLabelCodeList = dcucBusiness.getUserByLabelCode(orgCode, labelCode);
+        return Optional.ofNullable(userByLabelCodeList)
+                .orElse(Collections.emptyList())
+                .stream().map(UserLabel2RespVO::getIdcard)
+                .collect(Collectors.toList());
+    }
+
+}

+ 35 - 0
approve-core-service/src/main/java/com/dragonsoft/dcuc/approve/facade/api/v3/ApiV3WorkFlowCallbackFacade.java

@@ -0,0 +1,35 @@
+package com.dragonsoft.dcuc.approve.facade.api.v3;
+
+import com.dragonsoft.dcuc.approve.business.external.IWorkFlowCallbackBusiness;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <p>
+ *
+ * </p>
+ *
+ * @author huangziquan
+ * @date 2024/3/1
+ */
+@Slf4j
+@RestController
+@RequestMapping("api/v3/work-flow-callback/")
+public class ApiV3WorkFlowCallbackFacade implements IApiV3WorkFlowCallbackFacade {
+    private IWorkFlowCallbackBusiness workFlowCallbackBusiness;
+
+    @Autowired
+    public void setWorkFlowCallbackBusiness(IWorkFlowCallbackBusiness workFlowCallbackBusiness) {
+        this.workFlowCallbackBusiness = workFlowCallbackBusiness;
+    }
+
+    @Override
+    public List<String> getCurrentOrgAndNextOrgLabelHandlers(Map<String, Object> param) {
+        return workFlowCallbackBusiness.getCurrentOrgAndNextOrgLabelHandlers(param);
+    }
+}

+ 34 - 0
approve-core-service/src/main/java/com/dragonsoft/dcuc/approve/model/vo/dcuc/UserLabel2RespVO.java

@@ -0,0 +1,34 @@
+package com.dragonsoft.dcuc.approve.model.vo.dcuc;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @Author yica
+ * @Date 2021/5/21 14:16
+ **/
+@Api(value = "用户标签输出vo")
+@Data
+public class UserLabel2RespVO {
+    @ApiModelProperty(value = "姓名")
+    private String name;
+
+    @ApiModelProperty(value = "身份证号")
+    private String idcard;
+
+    @ApiModelProperty(value = "所在机构编码")
+    private String orgCode;
+
+    @ApiModelProperty(value = "所在机构编码名称")
+    private String orgName;
+
+    @ApiModelProperty(value = "业务标签")
+    private String labelCode;
+
+    @ApiModelProperty(value = "更新时间")
+    private String updateTime;
+
+    @ApiModelProperty(value = "删除标识")
+    private String deleted;
+}

+ 34 - 0
approve-core-service/src/main/java/com/dragonsoft/dcuc/approve/properties/ApproveWorkFlowCallbackProperties.java

@@ -0,0 +1,34 @@
+package com.dragonsoft.dcuc.approve.properties;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * <p>
+ * 工作流回调配置
+ * </p>
+ *
+ * @author huangziquan
+ * @date 2024/3/1
+ */
+@Setter
+@Getter
+@Component
+@ConfigurationProperties(prefix = "approve.work-flow.callback")
+public class ApproveWorkFlowCallbackProperties {
+    /**
+     * 标签代码
+     */
+    private String labelCode = "";
+
+    /**
+     * 最后兜底审批人员,身份证号
+     */
+    private List<String> finalApproveList = Collections.emptyList();
+
+}