|
@@ -1,6 +1,10 @@
|
|
|
package com.dragoninfo.dcuc.auth.business.impl.zerotrust;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.lang.Assert;
|
|
|
import com.dragoninfo.dcuc.auth.auth.dto.zerotrust.approval.*;
|
|
|
+import com.dragoninfo.dcuc.auth.business.impl.zerotrust.dto.FlowApplyReqDTO;
|
|
|
+import com.dragoninfo.dcuc.auth.business.impl.zerotrust.dto.FlowDataRespDto;
|
|
|
import com.dragoninfo.dcuc.auth.business.zerotrust.IApproveRemoteCallBusiness;
|
|
|
import com.dragoninfo.dcuc.auth.config.zerotrust.ApprovalProperties;
|
|
|
import com.dragoninfo.dcuc.auth.config.zerotrust.DcucAuthZerotrustConfig;
|
|
@@ -10,26 +14,34 @@ import com.dragoninfo.dcuc.auth.sub.dto.zerotrust.tasktype.TaskInfoDetailResp;
|
|
|
import com.dragoninfo.dcuc.auth.sub.dto.zerotrust.tasktype.TaskTypeInfoDto;
|
|
|
import com.dragoninfo.dcuc.auth.sub.entity.AuthSubTaskType;
|
|
|
import com.dragoninfo.dcuc.auth.sub.service.IAuthSubTaskTypeService;
|
|
|
+import com.dragoninfo.dcuc.auth.util.ValidUtil;
|
|
|
import com.dragoninfo.dcuc.common.utils.ResponseUtil;
|
|
|
import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
|
|
|
import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
|
|
|
+import com.dragonsoft.duceap.commons.util.date.DateUtils;
|
|
|
import com.dragonsoft.duceap.commons.util.json.JsonUtils;
|
|
|
import com.dragonsoft.duceap.commons.util.string.StringUtils;
|
|
|
+import com.dragonsoft.smtools.loader.SMFactory;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.google.common.annotations.VisibleForTesting;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
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.Collections;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -50,6 +62,10 @@ public class ApproveRemoteCallBusinessImpl implements IApproveRemoteCallBusiness
|
|
|
|
|
|
private IAuthSubTaskTypeService taskTypeService;
|
|
|
|
|
|
+ private SMFactory smFactory;
|
|
|
+
|
|
|
+ private ObjectMapper dragonObjectMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
public void setApprovalProperties(ApprovalProperties approvalProperties) {
|
|
|
this.approvalProperties = approvalProperties;
|
|
@@ -65,6 +81,17 @@ public class ApproveRemoteCallBusinessImpl implements IApproveRemoteCallBusiness
|
|
|
this.restTemplate = restTemplate;
|
|
|
}
|
|
|
|
|
|
+ @Autowired
|
|
|
+ public void setSmFactory(SMFactory smFactory) {
|
|
|
+ this.smFactory = smFactory;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Qualifier("dragonObjectMapper")
|
|
|
+ @Autowired
|
|
|
+ public void setDragonObjectMapper(ObjectMapper dragonObjectMapper) {
|
|
|
+ this.dragonObjectMapper = dragonObjectMapper;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public ResponseStatus syncTaskClass() {
|
|
|
// 查询审批接口获取任务类型
|
|
@@ -98,12 +125,45 @@ public class ApproveRemoteCallBusinessImpl implements IApproveRemoteCallBusiness
|
|
|
|
|
|
@Override
|
|
|
public ResponseDTO<FlowApplyRespDTO> flowApply(FlowApplyReqDto flowApplyReqDto) {
|
|
|
- return null;
|
|
|
+ FlowApplyReqDTO flowApplyReqDTO = new FlowApplyReqDTO();
|
|
|
+ flowApplyReqDTO.setAppTokenId(flowApplyReqDto.getAppTokenId());
|
|
|
+ flowApplyReqDTO.setProcessDefId(flowApplyReqDto.getProcessDefId());
|
|
|
+ flowApplyReqDTO.setTitle(flowApplyReqDto.getTitle());
|
|
|
+ flowApplyReqDTO.setTaskClass(flowApplyReqDto.getTaskClass());
|
|
|
+ flowApplyReqDTO.setTaskId(flowApplyReqDto.getTaskId());
|
|
|
+ flowApplyReqDTO.setBo(flowApplyReqDto.getBo());
|
|
|
+ flowApplyReqDTO.setCallbackUrl(flowApplyReqDto.getCallbackUrl());
|
|
|
+ flowApplyReqDTO.setBizData(flowApplyReqDto.getBizData());
|
|
|
+
|
|
|
+ String callerSign = generateCallerSign(flowApplyReqDTO);
|
|
|
+
|
|
|
+ flowApplyReqDTO.setCallerSign(callerSign);
|
|
|
+
|
|
|
+ ResponseDTO<FlowApplyRespDTO> responseDTO = beginFlow(flowApplyReqDTO);
|
|
|
+ if (ResponseUtil.isFail(responseDTO)) {
|
|
|
+ return ResponseUtil.dtoFail(responseDTO.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ FlowApplyRespDTO amFlowApplyRespDTO = ResponseUtil.getResult(responseDTO);
|
|
|
+
|
|
|
+ FlowApplyItemRespDTO flowApplyItemRespDTO = new FlowApplyItemRespDTO();
|
|
|
+ flowApplyItemRespDTO.setUid("不需要,先填空");
|
|
|
+
|
|
|
+ FlowApplyRespDTO flowApplyRespDTO = new FlowApplyRespDTO();
|
|
|
+ flowApplyRespDTO.setProcessInstId(amFlowApplyRespDTO.getProcessInstId());
|
|
|
+ flowApplyRespDTO.setReviewer(Collections.singletonList(flowApplyItemRespDTO));
|
|
|
+
|
|
|
+ return ResponseUtil.newInstance(flowApplyRespDTO);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ResponseDTO<FlowSubmitRespDTO> flowSubmit(FlowSubmitReqDTO flowSubmitReqDTO) {
|
|
|
- return null;
|
|
|
+ String processInstId = flowSubmitReqDTO.getProcessInstId();
|
|
|
+
|
|
|
+ FlowSubmitRespDTO flowSubmitRespDTO = new FlowSubmitRespDTO();
|
|
|
+ flowSubmitRespDTO.setProcessInstId(processInstId);
|
|
|
+
|
|
|
+ return ResponseUtil.newInstance(flowSubmitRespDTO);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -154,7 +214,7 @@ public class ApproveRemoteCallBusinessImpl implements IApproveRemoteCallBusiness
|
|
|
JsonNode jsonNode = mapper.readTree(body);
|
|
|
String statusCode = jsonNode.get("statusCode").asText();
|
|
|
String message = jsonNode.get("message").asText();
|
|
|
- if (ApprovalResultEnum.SUCCESS.getValue().equals(statusCode)) {
|
|
|
+ if ("200".equals(statusCode)) {
|
|
|
respDto = mapper.readValue(body, typeReference);
|
|
|
} else {
|
|
|
return ResponseUtil.dtoFail(message);
|
|
@@ -204,4 +264,91 @@ public class ApproveRemoteCallBusinessImpl implements IApproveRemoteCallBusiness
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开启流程
|
|
|
+ *
|
|
|
+ */
|
|
|
+ protected ResponseDTO<FlowApplyRespDTO> beginFlow(FlowApplyReqDTO flowApplyReqDTO) {
|
|
|
+
|
|
|
+ String baseUrl = approvalProperties.getBaseUrl();
|
|
|
+ String url = baseUrl + "/api/v3/apply";
|
|
|
+ ResponseDTO<FlowApplyRespDTO> responseDTO = this.baseReqData(url, flowApplyReqDTO, "开启流程请求",
|
|
|
+ new TypeReference<FlowDataRespDto<FlowApplyRespDTO>>() {
|
|
|
+ });
|
|
|
+ return responseDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成签名
|
|
|
+ *
|
|
|
+ * @param dto 请求参数
|
|
|
+ * @return 签名
|
|
|
+ */
|
|
|
+ @VisibleForTesting
|
|
|
+ protected String generateCallerSign(FlowApplyReqDTO dto) {
|
|
|
+ String appTokenId = dto.getAppTokenId();
|
|
|
+ String processDefId = dto.getProcessDefId();
|
|
|
+ String title = dto.getTitle();
|
|
|
+ Assert.notBlank(appTokenId);
|
|
|
+ Assert.notBlank(processDefId);
|
|
|
+ Assert.notBlank(title);
|
|
|
+ String origin = appTokenId + "," + processDefId + "," + title+","+dto.getTaskClass()
|
|
|
+ +","+dto.getTaskId()+","+dto.getCallbackUrl();
|
|
|
+ String summary = smFactory.getSM3().summary(origin).toString().toLowerCase(Locale.ROOT);
|
|
|
+ log.info("生成审批请求签名原文:{}", origin);
|
|
|
+ log.info("生成审批请求签名后的值:{}", summary);
|
|
|
+ return summary;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 基础操作
|
|
|
+ *
|
|
|
+ * @param url 路径
|
|
|
+ * @param req 请求参数
|
|
|
+ * @return 返回内容
|
|
|
+ */
|
|
|
+ protected <R, S> ResponseDTO<S> baseReqData(String url, R req, String requestName, TypeReference<FlowDataRespDto<S>> typeReference) {
|
|
|
+ // 打印请求参数
|
|
|
+ log.info(requestName + " 请求路径:{} 请求参数:{}", url, JsonUtils.toJSONString(req));
|
|
|
+ String errorTip = requestName + "失败";
|
|
|
+ ResponseStatus responseStatus = ValidUtil.validReqVo(req);
|
|
|
+ if (ResponseUtil.isFail(responseStatus)) {
|
|
|
+ log.error("request vo valid error:{}", responseStatus.getMessage());
|
|
|
+ return ResponseUtil.dtoFail(responseStatus.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ HttpEntity<R> entity = new HttpEntity<>(req);
|
|
|
+ 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));
|
|
|
+
|
|
|
+ FlowDataRespDto<S> respDto;
|
|
|
+
|
|
|
+ try {
|
|
|
+ JsonNode jsonNode = dragonObjectMapper.readTree(body);
|
|
|
+ String statusCode = jsonNode.get("status_code").asText();
|
|
|
+ String message = jsonNode.get("message").asText();
|
|
|
+ if (ApprovalResultEnum.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());
|
|
|
+ }
|
|
|
}
|