|
@@ -2,17 +2,20 @@ package com.dragonsoft.dcuc.approve.business.external.impl;
|
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.PageUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
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 +23,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 +33,18 @@ 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.Service;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.net.URI;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
- * @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 +65,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 +237,102 @@ public class DcucBusinessImpl implements IDcucBusiness {
|
|
|
return oauthUserVO;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<String> getUserByLabelCodeUserList(String orgCode, String labelCode) {
|
|
|
+ List<UserLabel2RespVO> userByLabelCodeList = Collections.emptyList();
|
|
|
+ try {
|
|
|
+ userByLabelCodeList = getUserByLabelCode(orgCode, labelCode);
|
|
|
+ } catch (RuntimeException e) {
|
|
|
+ logger.error("查询审批人标签代码异常", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Optional.ofNullable(userByLabelCodeList)
|
|
|
+ .orElse(Collections.emptyList())
|
|
|
+ .stream().map(UserLabel2RespVO::getIdcard)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @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);
|
|
|
+ int size = 1000;
|
|
|
+ int currentPage = 1;
|
|
|
+
|
|
|
+ ApiSearchReq apiSearchReq = ApiSearchReq.reqInfo(currentPage, size, filters);
|
|
|
+
|
|
|
+ ApiResultPage<UserLabel2RespVO> page = labelPage(apiSearchReq);
|
|
|
+ List<UserLabel2RespVO> allContent = new ArrayList<>(page.getContent());
|
|
|
+
|
|
|
+ int total = 0;
|
|
|
+ if (ObjectUtil.isNotNull(page)) {
|
|
|
+ total = Math.toIntExact(page.getTotal());
|
|
|
+ }
|
|
|
+
|
|
|
+ int totalPage = PageUtil.totalPage(total, size);
|
|
|
+ currentPage++;
|
|
|
+ // 循环获取全部
|
|
|
+ for (int i = currentPage; i <= totalPage; i++) {
|
|
|
+ ApiResultPage<UserLabel2RespVO> itemPage = labelPage(apiSearchReq);
|
|
|
+ if (ObjectUtil.isNotNull(itemPage)) {
|
|
|
+ allContent.addAll(itemPage.getContent());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return allContent;
|
|
|
+ }
|
|
|
+
|
|
|
+ @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 = objectMapper.readValue(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) {
|