|
@@ -0,0 +1,138 @@
|
|
|
|
+package com.dragoninfo.dcuc.auth.auth.service.impl.zerotrust;
|
|
|
|
+
|
|
|
|
+import com.dragoninfo.dcuc.auth.auth.dto.zerotrust.approval.FlowApplyReqDto;
|
|
|
|
+import com.dragoninfo.dcuc.auth.auth.dto.zerotrust.approval.FlowSubmitRespDTO;
|
|
|
|
+import com.dragoninfo.dcuc.auth.auth.entity.zerotrust.RoleAuthApply;
|
|
|
|
+import com.dragoninfo.dcuc.auth.auth.enumresources.zerotrust.approval.ApprovalApplyTypeEnum;
|
|
|
|
+import com.dragoninfo.dcuc.auth.auth.enumresources.zerotrust.approval.AuthApplyStatusEnum;
|
|
|
|
+import com.dragoninfo.dcuc.auth.auth.repo.zerotrust.RoleAuthApplyRepository;
|
|
|
|
+import com.dragoninfo.dcuc.auth.auth.service.zerotrust.IRoleAuthApplyService;
|
|
|
|
+import com.dragoninfo.dcuc.auth.auth.vo.zerotrust.roleauthapply.ApplyRoleInVo;
|
|
|
|
+import com.dragoninfo.dcuc.auth.auth.vo.zerotrust.roleauthapply.RoleAuthApplySaveVo;
|
|
|
|
+import com.dragoninfo.dcuc.auth.business.zerotrust.IApprovalBusiness;
|
|
|
|
+import com.dragoninfo.dcuc.auth.config.zerotrust.ApprovalProperties;
|
|
|
|
+import com.dragoninfo.dcuc.auth.sub.entity.AuthUserInfo;
|
|
|
|
+import com.dragoninfo.dcuc.auth.sub.service.IAuthUserInfoService;
|
|
|
|
+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.base.entity.security.BaseSecurityUser;
|
|
|
|
+import com.dragonsoft.duceap.base.utils.UserContextUtils;
|
|
|
|
+import com.dragonsoft.duceap.commons.util.UUIDUtils;
|
|
|
|
+import com.dragonsoft.duceap.commons.util.json.JsonUtils;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 角色授权申请业务类
|
|
|
|
+ *
|
|
|
|
+ * @author mazq
|
|
|
|
+ * @date 2023/7/19
|
|
|
|
+ */
|
|
|
|
+@Slf4j
|
|
|
|
+@Service
|
|
|
|
+public class RoleAuthApplyServiceImpl implements IRoleAuthApplyService {
|
|
|
|
+
|
|
|
|
+ private RoleAuthApplyRepository repository;
|
|
|
|
+
|
|
|
|
+ private IApprovalBusiness approvalBusiness;
|
|
|
|
+
|
|
|
|
+ private ApprovalProperties approvalProperties;
|
|
|
|
+
|
|
|
|
+ private IAuthUserInfoService authUserInfoService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ public void setAuthUserInfoService(IAuthUserInfoService authUserInfoService) {
|
|
|
|
+ this.authUserInfoService = authUserInfoService;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ public void setRepository(RoleAuthApplyRepository repository) {
|
|
|
|
+ this.repository = repository;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ public void setApprovalBusiness(IApprovalBusiness approvalBusiness) {
|
|
|
|
+ this.approvalBusiness = approvalBusiness;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ public void setApprovalProperties(ApprovalProperties approvalProperties) {
|
|
|
|
+ this.approvalProperties = approvalProperties;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseStatus roleAuthApply(RoleAuthApplySaveVo saveVo) {
|
|
|
|
+ String userId = saveVo.getUserId();
|
|
|
|
+ AuthUserInfo userInfo = authUserInfoService.findById(userId);
|
|
|
|
+ if (null == userInfo) {
|
|
|
|
+ return ResponseStatus.fail("授权主体人员不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 填充业务数据
|
|
|
|
+ Map<String, String> bizData = getBizData(saveVo, userInfo);
|
|
|
|
+
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
+ String format = formatter.format(LocalDate.now());
|
|
|
|
+ // 先推送成功后保存权限申请内容
|
|
|
|
+ String title = format + "-" + UserContextUtils.getCurrentUser().getName() + "角色授权申请";
|
|
|
|
+ FlowApplyReqDto applyDto = FlowApplyReqDto.builder()
|
|
|
|
+ .title(title)
|
|
|
|
+ .processDefId(ApprovalApplyTypeEnum.ROLE_AUTH_APPLY.getValue())
|
|
|
|
+ // TODO 后续填入
|
|
|
|
+ .bo(Collections.emptyMap())
|
|
|
|
+ .bizData(bizData)
|
|
|
|
+ .taskClass(approvalProperties.getRoleAuthTaskType())
|
|
|
|
+ .build();
|
|
|
|
+ ResponseDTO<FlowSubmitRespDTO> applyRespDto = approvalBusiness.approvalFlowApplyAndSubmitFirst(applyDto, UUIDUtils.getUUID());
|
|
|
|
+ if (ResponseUtil.isFail(applyRespDto)) {
|
|
|
|
+ log.info("申请推送审批失败");
|
|
|
|
+ return ResponseDTO.fail("申请推送审批失败", (Object) null);
|
|
|
|
+ }
|
|
|
|
+ FlowSubmitRespDTO flowSubmitRespDTO = ResponseUtil.getResult(applyRespDto);
|
|
|
|
+ String processInstId = flowSubmitRespDTO.getProcessInstId();
|
|
|
|
+
|
|
|
|
+ // 推送成功之后保存角色授权内容
|
|
|
|
+ List<ApplyRoleInVo> applyRoleInVos = saveVo.getApplyRoleInVos();
|
|
|
|
+ List<RoleAuthApply> collect = applyRoleInVos.stream()
|
|
|
|
+ .map(e -> {
|
|
|
|
+ RoleAuthApply roleAuthApply = new RoleAuthApply();
|
|
|
|
+ roleAuthApply.setUserId(userId);
|
|
|
|
+ roleAuthApply.setProcessInstId(processInstId);
|
|
|
|
+ roleAuthApply.setAppId(e.getAppId());
|
|
|
|
+ roleAuthApply.setRoleCode(e.getRoleCode());
|
|
|
|
+ roleAuthApply.setApprovalResult(AuthApplyStatusEnum.APPLYING.getValue());
|
|
|
|
+ return roleAuthApply;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ repository.saveAll(collect);
|
|
|
|
+
|
|
|
|
+ return ResponseDTO.success("", (Object) null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Map<String, String> getBizData(RoleAuthApplySaveVo saveVo, AuthUserInfo userInfo) {
|
|
|
|
+ Map<String, String> bizData = new HashMap<>();
|
|
|
|
+ // 授权主体人员信息
|
|
|
|
+ bizData.put("authUserName", userInfo.getName());
|
|
|
|
+ bizData.put("authUserIdcard", userInfo.getIdcard());
|
|
|
|
+ // 授权客体角色信息
|
|
|
|
+ List<ApplyRoleInVo> applyRoleInVos = saveVo.getApplyRoleInVos();
|
|
|
|
+ bizData.put("authRoleInfos", JsonUtils.toJSONString(applyRoleInVos));
|
|
|
|
+ // 授权操作人信息
|
|
|
|
+ BaseSecurityUser currentUser = UserContextUtils.getCurrentUser();
|
|
|
|
+ bizData.put("authOperateUserName", currentUser.getName());
|
|
|
|
+ bizData.put("authOperateUserIdcard", currentUser.getIdcard());
|
|
|
|
+ return bizData;
|
|
|
|
+ }
|
|
|
|
+}
|