|
@@ -4,6 +4,8 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.dragoninfo.dcuc.auth.AuthRedisConstant;
|
|
|
+import com.dragoninfo.dcuc.auth.api.enums.zerotrust.ZeroTrustBusinessRespEnum;
|
|
|
import com.dragoninfo.dcuc.auth.api.vo.zerotrust.ZeroTrustMessageRespVO;
|
|
|
import com.dragoninfo.dcuc.auth.auth.constance.zerotrust.approval.ApprovalConstance;
|
|
|
import com.dragoninfo.dcuc.auth.auth.dto.zerotrust.approval.*;
|
|
@@ -26,9 +28,9 @@ import com.dragoninfo.dcuc.common.utils.ResponseUtil;
|
|
|
import com.dragoninfo.dcuc.common.utils.SecurityUserUtil;
|
|
|
import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
|
|
|
import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
|
|
|
+import com.dragonsoft.duceap.base.enums.BooleanEnum;
|
|
|
import com.dragonsoft.duceap.base.utils.UserContextUtils;
|
|
|
import com.dragonsoft.duceap.commons.util.ObjectUtils;
|
|
|
-import com.dragonsoft.duceap.commons.util.UUIDUtils;
|
|
|
import com.dragonsoft.duceap.commons.util.date.DateConst;
|
|
|
import com.dragonsoft.duceap.commons.util.date.DateUtils;
|
|
|
import com.dragonsoft.duceap.commons.util.enums.EnumUtils;
|
|
@@ -37,6 +39,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.Collections;
|
|
|
import java.util.Date;
|
|
@@ -240,34 +243,65 @@ public class ApprovalBusinessImpl implements IApprovalBusiness {
|
|
|
return approveRemoteCallBusiness.flowDetail(appTokenId, processInstId);
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public ZeroTrustMessageRespVO approvalCallBack(ApprovalCallBackReqVO approvalCallBackReqVO) {
|
|
|
log.info("接收到的审批回调信息:{}", JSONUtil.toJsonStr(approvalCallBackReqVO));
|
|
|
-
|
|
|
String processInstId = approvalCallBackReqVO.getProcessInstId();
|
|
|
- String status = approvalCallBackReqVO.getEndFlag();
|
|
|
- ApprovalResult approvalResult = approvalResultService.getByProcessInstId(processInstId);
|
|
|
- if (ObjectUtils.isEmpty(approvalResult)) {
|
|
|
- log.error("processInstId {} can't find", processInstId);
|
|
|
- return ZeroTrustMessageRespVO.requestErrorMessage("审批单不存在");
|
|
|
+
|
|
|
+ // 接口回调并发控制
|
|
|
+ String key = AuthRedisConstant.REDIS_APPROVAL_CALL_BACK_NAMESPACE + processInstId;
|
|
|
+ Boolean ifAbsent = stringRedisTemplate.opsForValue()
|
|
|
+ .setIfAbsent(key, BooleanEnum.TRUE.value, 5, TimeUnit.MINUTES);
|
|
|
+ if (ifAbsent != null && !ifAbsent) {
|
|
|
+ log.info("回调接口并发控制");
|
|
|
+ return ZeroTrustMessageRespVO.messageEnumMessage(ZeroTrustBusinessRespEnum.SUCCESS);
|
|
|
}
|
|
|
- String applyType = approvalResult.getApplyType();
|
|
|
+ log.info("流程回调开始");
|
|
|
+ try {
|
|
|
+ String status = approvalCallBackReqVO.getEndFlag();
|
|
|
+ ApprovalResult approvalResult = approvalResultService.getByProcessInstId(processInstId);
|
|
|
+ if (ObjectUtils.isEmpty(approvalResult)) {
|
|
|
+ log.error("无对应的流程实例id:{}", processInstId);
|
|
|
+ return ZeroTrustMessageRespVO.requestErrorMessage("审批单不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 流程重复回调控制
|
|
|
+ String callBack = approvalResult.getCallBack();
|
|
|
+ if (BooleanEnum.TRUE.value.equals(callBack)) {
|
|
|
+ log.info("流程已经被回调处理");
|
|
|
+ return ZeroTrustMessageRespVO.messageEnumMessage(ZeroTrustBusinessRespEnum.SUCCESS);
|
|
|
+ }
|
|
|
|
|
|
- AmCallbackStatusEnum amCallbackStatusEnum = EnumUtils.enumOf(AmCallbackStatusEnum.class, status);
|
|
|
- String endFlag = amCallbackStatusEnum.toEndFlag();
|
|
|
- // 无该类型,默认使用end
|
|
|
- String type = "end";
|
|
|
+ String applyType = approvalResult.getApplyType();
|
|
|
|
|
|
- // 角色操作申请处理
|
|
|
- ApprovalBaseRespDto approvalBaseRespDto = new ApprovalBaseRespDto().success();
|
|
|
- if (ApprovalApplyTypeEnum.ROLE_OPERATE.getValue().equals(applyType)) {
|
|
|
- approvalBaseRespDto = roleOperateCallBackHandle(processInstId, type, endFlag);
|
|
|
+ AmCallbackStatusEnum amCallbackStatusEnum = EnumUtils.enumOf(AmCallbackStatusEnum.class, status);
|
|
|
+ String endFlag = amCallbackStatusEnum.toEndFlag();
|
|
|
+ // 无该类型,默认使用end
|
|
|
+ String type = "end";
|
|
|
+
|
|
|
+ // 角色操作申请处理
|
|
|
+ ApprovalBaseRespDto approvalBaseRespDto = new ApprovalBaseRespDto().success();
|
|
|
+ if (ApprovalApplyTypeEnum.ROLE_OPERATE.getValue().equals(applyType)) {
|
|
|
+ approvalBaseRespDto = roleOperateCallBackHandle(processInstId, type, endFlag);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新审批结果
|
|
|
+ updateApprovalResult(approvalResult, approvalCallBackReqVO);
|
|
|
+ ZeroTrustMessageRespVO zeroTrustMessageRespVO = new ZeroTrustMessageRespVO();
|
|
|
+ BeanUtil.copyProperties(approvalBaseRespDto, zeroTrustMessageRespVO);
|
|
|
+ return zeroTrustMessageRespVO;
|
|
|
+ } finally {
|
|
|
+ stringRedisTemplate.delete(key);
|
|
|
+ log.info("流程回调结束");
|
|
|
}
|
|
|
|
|
|
- // TODO 更新审批结果
|
|
|
- ZeroTrustMessageRespVO zeroTrustMessageRespVO = new ZeroTrustMessageRespVO();
|
|
|
- BeanUtil.copyProperties(approvalBaseRespDto, zeroTrustMessageRespVO);
|
|
|
- return zeroTrustMessageRespVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateApprovalResult(ApprovalResult approvalResult, ApprovalCallBackReqVO approvalCallBackReqVO) {
|
|
|
+ BeanUtil.copyProperties(approvalCallBackReqVO, approvalResult, "taskId", "businessKey");
|
|
|
+ approvalResult.setCallBack(BooleanEnum.TRUE.value);
|
|
|
+ approvalResultService.update(approvalResult);
|
|
|
}
|
|
|
|
|
|
private ApprovalBaseRespDto roleOperateCallBackHandle(String processInstId, String type, String endFlag) {
|