|
@@ -1,40 +1,27 @@
|
|
|
package com.dragonsoft.dcuc.approve.business.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.dragoninfo.dcuc.common.annotation.CacheLock;
|
|
|
import com.dragoninfo.dcuc.common.utils.ResponseUtil;
|
|
|
import com.dragonsoft.dcuc.approve.business.IBuSyncBusiness;
|
|
|
-import com.dragonsoft.dcuc.approve.constants.ApproveBeanConstants;
|
|
|
+import com.dragonsoft.dcuc.approve.business.INoticeBusiness;
|
|
|
import com.dragonsoft.dcuc.approve.constants.ApproveConstants;
|
|
|
import com.dragonsoft.dcuc.approve.enumresources.bu.ApproveModeEnum;
|
|
|
-import com.dragonsoft.dcuc.approve.enumresources.bu.BuErrorCodeEnum;
|
|
|
import com.dragonsoft.dcuc.approve.model.ApproveCirculationInfo;
|
|
|
import com.dragonsoft.dcuc.approve.model.ApproveRecordInfo;
|
|
|
import com.dragonsoft.dcuc.approve.model.resp.bu.BuApproveSyncBizApproveReqVO;
|
|
|
import com.dragonsoft.dcuc.approve.model.resp.bu.BuApproveSyncBizDataReqVO;
|
|
|
import com.dragonsoft.dcuc.approve.model.resp.bu.BuApproveSyncReqVO;
|
|
|
-import com.dragonsoft.dcuc.approve.model.resp.v3.ZeroTrustResultDataVO;
|
|
|
-import com.dragoninfo.dcuc.common.utils.ValidUtil;
|
|
|
-import com.dragonsoft.dcuc.approve.properties.ApproveBuProperties;
|
|
|
+import com.dragonsoft.dcuc.approve.model.vo.ApprovalInfoMsgItemDTO;
|
|
|
import com.dragonsoft.dcuc.approve.service.IApproveCirculationService;
|
|
|
import com.dragonsoft.dcuc.approve.service.IApproveRecordService;
|
|
|
import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
|
|
|
import com.dragonsoft.duceap.base.enums.BooleanEnum;
|
|
|
-import com.dragonsoft.duceap.commons.util.json.JsonUtils;
|
|
|
-import com.dragonsoft.duceap.commons.util.string.StringUtils;
|
|
|
-import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
-import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
-import com.fasterxml.jackson.databind.JsonNode;
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
-import org.springframework.http.HttpEntity;
|
|
|
-import org.springframework.http.HttpMethod;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
@@ -50,41 +37,25 @@ import java.util.List;
|
|
|
@Component
|
|
|
public class BuSyncBusinessImpl implements IBuSyncBusiness {
|
|
|
|
|
|
- private RestTemplate restTemplate;
|
|
|
-
|
|
|
- private ObjectMapper dragonObjectMapper;
|
|
|
-
|
|
|
- private ApproveBuProperties approveBuProperties;
|
|
|
-
|
|
|
private IApproveRecordService approveRecordService;
|
|
|
|
|
|
private IApproveCirculationService approveCirculationService;
|
|
|
|
|
|
- @Autowired
|
|
|
- public void setApproveCirculationService(IApproveCirculationService approveCirculationService) {
|
|
|
- this.approveCirculationService = approveCirculationService;
|
|
|
- }
|
|
|
-
|
|
|
- @Autowired
|
|
|
- public void setApproveRecordService(IApproveRecordService approveRecordService) {
|
|
|
- this.approveRecordService = approveRecordService;
|
|
|
- }
|
|
|
+ private INoticeBusiness noticeBusiness;
|
|
|
|
|
|
@Autowired
|
|
|
- public void setApproveBuProperties(ApproveBuProperties approveBuProperties) {
|
|
|
- this.approveBuProperties = approveBuProperties;
|
|
|
+ public void setNoticeBusiness(INoticeBusiness noticeBusiness) {
|
|
|
+ this.noticeBusiness = noticeBusiness;
|
|
|
}
|
|
|
|
|
|
- @Qualifier(ApproveBeanConstants.DRAGON_OBJECT_MAPPER)
|
|
|
@Autowired
|
|
|
- public void setDragonObjectMapper(ObjectMapper dragonObjectMapper) {
|
|
|
- this.dragonObjectMapper = dragonObjectMapper;
|
|
|
+ public void setApproveCirculationService(IApproveCirculationService approveCirculationService) {
|
|
|
+ this.approveCirculationService = approveCirculationService;
|
|
|
}
|
|
|
|
|
|
- @Qualifier(ApproveBeanConstants.SKIP_SSL_REST_TEMPLATE)
|
|
|
@Autowired
|
|
|
- public void setRestTemplate(RestTemplate restTemplate) {
|
|
|
- this.restTemplate = restTemplate;
|
|
|
+ public void setApproveRecordService(IApproveRecordService approveRecordService) {
|
|
|
+ this.approveRecordService = approveRecordService;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -167,7 +138,7 @@ public class BuSyncBusinessImpl implements IBuSyncBusiness {
|
|
|
buApproveSyncBizDataReqVO.setBizApprove(buApproveSyncBizApproveReqVO);
|
|
|
buApproveSyncReqVO.setBizData(buApproveSyncBizDataReqVO);
|
|
|
|
|
|
- ResponseStatus responseStatus = requestSyncToBu(buApproveSyncReqVO);
|
|
|
+ ResponseStatus responseStatus = noticeBusiness.retryRequestSyncToBu(buApproveSyncReqVO);
|
|
|
if (ResponseUtil.isSuccess(responseStatus)) {
|
|
|
approveRecordService.updateSyncFlag(id, BooleanEnum.TRUE);
|
|
|
return ResponseStatus.success();
|
|
@@ -176,70 +147,14 @@ public class BuSyncBusinessImpl implements IBuSyncBusiness {
|
|
|
return ResponseStatus.fail();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * 请求同步到 BU
|
|
|
- *
|
|
|
- * @param buApproveSyncReqVO 同步请求
|
|
|
- * @return 状态
|
|
|
- */
|
|
|
- public ResponseStatus requestSyncToBu(BuApproveSyncReqVO buApproveSyncReqVO) {
|
|
|
- if (!approveBuProperties.isEnable()) {
|
|
|
- return ResponseStatus.success();
|
|
|
- }
|
|
|
- String syncTaskUrl = approveBuProperties.getSyncTaskUrl();
|
|
|
+ @Override
|
|
|
+ public ResponseStatus syncToBu(ApprovalInfoMsgItemDTO approvalInfoMsgItemDTO) {
|
|
|
+ ApproveRecordInfo approveRecordInfo = new ApproveRecordInfo();
|
|
|
+ BeanUtil.copyProperties(approvalInfoMsgItemDTO, approveRecordInfo);
|
|
|
+
|
|
|
|
|
|
- return baseReq(syncTaskUrl, buApproveSyncReqVO, "同步任务信息到BU");
|
|
|
+ return syncToBu(approveRecordInfo);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * 流程详情
|
|
|
- *
|
|
|
- * @param url 路径
|
|
|
- * @param buApproveSyncReqVO 请求参数
|
|
|
- * @return 返回内容
|
|
|
- */
|
|
|
- protected ResponseStatus baseReq(String url, BuApproveSyncReqVO buApproveSyncReqVO, String requestName) {
|
|
|
-
|
|
|
- log.info(requestName + " 请求路径:{} 请求参数:{}", url, JsonUtils.toJSONString(buApproveSyncReqVO));
|
|
|
- String errorTip = requestName + "失败";
|
|
|
- ResponseStatus responseStatus = ValidUtil.validReqVo(buApproveSyncReqVO);
|
|
|
- if (ResponseUtil.isFail(responseStatus)) {
|
|
|
- log.error("request vo valid error:{}", responseStatus.getMessage());
|
|
|
- return ResponseUtil.dtoFail(responseStatus.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- HttpEntity<BuApproveSyncReqVO> entity = new HttpEntity<>(buApproveSyncReqVO);
|
|
|
- ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
|
|
|
|
|
|
- if (!exchange.getStatusCode().is2xxSuccessful()) {
|
|
|
- log.error("{} error. resp: {}", requestName, JsonUtils.toJSONString(exchange));
|
|
|
- return ResponseUtil.dtoFail(errorTip);
|
|
|
- }
|
|
|
- String body = exchange.getBody();
|
|
|
- if (StringUtils.isBlank(body)) {
|
|
|
- log.error("{} error. resp: {}", requestName, JsonUtils.toJSONString(exchange));
|
|
|
- return ResponseUtil.dtoFail(errorTip);
|
|
|
- }
|
|
|
-
|
|
|
- log.info("baseReq resp :{}", JsonUtils.toJSONString(exchange));
|
|
|
- TypeReference<ZeroTrustResultDataVO<Object>> typeReference = new TypeReference<ZeroTrustResultDataVO<Object>>() {
|
|
|
- };
|
|
|
-
|
|
|
- ZeroTrustResultDataVO<Object> respDto;
|
|
|
- try {
|
|
|
- JsonNode jsonNode = dragonObjectMapper.readTree(body);
|
|
|
- String statusCode = jsonNode.get("status_code").asText();
|
|
|
- String message = jsonNode.get("message").asText();
|
|
|
- if (BuErrorCodeEnum.SUCCESS.getValue().equals(statusCode)) {
|
|
|
- respDto = dragonObjectMapper.readValue(body, typeReference);
|
|
|
- } else {
|
|
|
- return ResponseUtil.dtoFail(message);
|
|
|
- }
|
|
|
- } catch (JsonProcessingException e) {
|
|
|
- log.error("parse error.", e);
|
|
|
- return ResponseUtil.dtoFail("返回值解析失败");
|
|
|
- }
|
|
|
-
|
|
|
- return ResponseUtil.newInstance(respDto.getData());
|
|
|
- }
|
|
|
}
|