Forráskód Böngészése

查找异常申请考勤审核角色逻辑更新

wangliang 1 éve
szülő
commit
cff71672da

+ 3 - 1
sop-business/src/main/java/com/qmth/sop/business/service/SysUserRoleService.java

@@ -6,6 +6,7 @@ import com.qmth.sop.business.bean.result.MenuResult;
 import com.qmth.sop.business.entity.SysRole;
 import com.qmth.sop.business.entity.SysUser;
 import com.qmth.sop.business.entity.SysUserRole;
+import com.qmth.sop.business.entity.TBDingApply;
 import com.qmth.sop.common.enums.RoleTypeEnum;
 
 import java.util.List;
@@ -72,7 +73,8 @@ public interface SysUserRoleService extends IService<SysUserRole> {
      * 根据服务单元查找用户
      *
      * @param serviceId
+     * @param userId
      * @return
      */
-    List<String> listByServiceId(Long serviceId);
+    List<String> listByServiceId(Long serviceId, Long userId);
 }

+ 77 - 34
sop-business/src/main/java/com/qmth/sop/business/service/impl/SysUserRoleServiceImpl.java

@@ -11,16 +11,15 @@ import com.qmth.sop.business.service.*;
 import com.qmth.sop.common.enums.DingObjTypeEnum;
 import com.qmth.sop.common.enums.ExceptionResultEnum;
 import com.qmth.sop.common.enums.RoleTypeEnum;
+import com.qmth.sop.common.enums.UserSourceEnum;
 import com.qmth.sop.common.util.ServletUtil;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -52,6 +51,18 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
     @Resource
     TBCrmService tbCrmService;
 
+    @Resource
+    SysUserService sysUserService;
+
+    @Resource
+    TBUserArchivesService tbUserArchivesService;
+
+    @Resource
+    TBUserArchivesSupplierService tbUserArchivesSupplierService;
+
+    @Resource
+    SysUserRoleService sysUserRoleService;
+
     /**
      * 获取用户菜单
      *
@@ -124,44 +135,76 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
      * 根据服务单元查找用户
      *
      * @param serviceId
+     * @param userId
      * @return
      */
     @Override
-    public List<String> listByServiceId(Long serviceId) {
-        SysDingGroup sysDingGroup = sysDingGroupService.getOne(new QueryWrapper<SysDingGroup>().lambda().eq(SysDingGroup::getServiceId, serviceId));
-        Optional.ofNullable(sysDingGroup).orElseThrow(() -> ExceptionResultEnum.SERVICE_DING_GROUP_NO_DATA.exception());
+    public List<String> listByServiceId(Long serviceId, Long userId) {
+        SysUser sysUser = sysUserService.getById(userId);
+        Optional.ofNullable(sysUser).orElseThrow(() -> ExceptionResultEnum.USER_NO_EXISTS.exception());
 
-        List<SysDingObj> sysDingObjList = sysDingObjService.list(new QueryWrapper<SysDingObj>().lambda().eq(SysDingObj::getDingGroupId, sysDingGroup.getId()).eq(SysDingObj::getType, DingObjTypeEnum.APPROVE));
-        if (CollectionUtils.isEmpty(sysDingObjList)) {
-            throw ExceptionResultEnum.SERVICE_DING_APPROVE_NO_DATA.exception();
+        if (sysUser.getSource() == UserSourceEnum.SYSTEM) {
+            throw ExceptionResultEnum.ERROR.exception("非档案用户不能发起异常补卡申请");
         }
+        TBUserArchives tbUserArchives = tbUserArchivesService.getOne(new QueryWrapper<TBUserArchives>().lambda().eq(TBUserArchives::getMobileNumber, sysUser.getMobileNumber()));
+        Optional.ofNullable(tbUserArchives).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("档案用户不存在"));
 
-        List<Long> roleIsList = sysDingObjList.stream().map(s -> s.getRoleId()).collect(Collectors.toList());
-        //首选查角色类型
-        List<SysRole> sysRoleList = sysRoleService.listByIds(roleIsList);
-        List<String> userIdList = new ArrayList<>();
-        List<Long> sysRoleOtherList = new ArrayList<>();
-        for (SysRole s : sysRoleList) {
-            if (s.getType() == RoleTypeEnum.BUSSINESS) {
-                List<TBService> tbServiceList = tbServiceService.listByIds(Arrays.asList(serviceId));
-                List<String> serviceLeadIdList = tbServiceList.stream().map(i -> String.valueOf(i.getServiceLeadId())).collect(Collectors.toList());
-                userIdList.addAll(serviceLeadIdList);
-            } else if (s.getType() == RoleTypeEnum.REGION_MANAGER) {
-                List<TBCrm> tbCrmList = tbCrmService.list(new QueryWrapper<TBCrm>().lambda().eq(TBCrm::getServiceId, serviceId));
-                List<String> leadIdList = tbCrmList.stream().map(i -> String.valueOf(i.getLeadId())).collect(Collectors.toList());
-                userIdList.addAll(leadIdList);
-            } else if (s.getType() == RoleTypeEnum.REGION_COORDINATOR) {
-                List<TBCrm> tbCrmList = tbCrmService.list(new QueryWrapper<TBCrm>().lambda().eq(TBCrm::getServiceId, serviceId));
-                List<String> regionCoordinatorIdList = tbCrmList.stream().map(i -> String.valueOf(i.getRegionCoordinatorId())).collect(Collectors.toList());
-                userIdList.addAll(regionCoordinatorIdList);
-            } else {
-                sysRoleOtherList.add(s.getId());
+        TBUserArchivesSupplier tbUserArchivesSupplier = tbUserArchivesSupplierService.getOne(new QueryWrapper<TBUserArchivesSupplier>().lambda().eq(TBUserArchivesSupplier::getUserArchivesId, tbUserArchives.getId()));
+        Optional.ofNullable(tbUserArchivesSupplier).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("档案机构不存在"));
+
+        List<SysRole> userArchivesRoleList = sysUserRoleService.listRoleByUserId(sysUser.getId());
+        Map<Long, SysRole> userArchivesRoleMap = userArchivesRoleList.stream().collect(Collectors.toMap(SysRole::getId, Function.identity(), (dto1, dto2) -> dto1));
+
+        List<SysDingGroup> sysDingGroupList = sysDingGroupService.list(new QueryWrapper<SysDingGroup>().lambda().eq(SysDingGroup::getServiceId, serviceId).eq(SysDingGroup::getSupplierId, tbUserArchivesSupplier.getSupplierId()));
+        if (CollectionUtils.isEmpty(sysDingGroupList)) {
+            throw ExceptionResultEnum.SERVICE_DING_GROUP_NO_DATA.exception();
+        }
+        List<String> userIdList = null;
+        for (SysDingGroup sysDingGroup : sysDingGroupList) {
+            List<SysDingObj> sysDingObjList = sysDingObjService.list(new QueryWrapper<SysDingObj>().lambda().eq(SysDingObj::getDingGroupId, sysDingGroup.getId()).eq(SysDingObj::getType, DingObjTypeEnum.APPROVE));
+            if (CollectionUtils.isEmpty(sysDingObjList)) {
+                throw ExceptionResultEnum.SERVICE_DING_APPROVE_NO_DATA.exception();
+            }
+            for (SysDingObj s : sysDingObjList) {
+                if (userArchivesRoleMap.containsKey(s.getRoleId())) {
+                    userIdList = new ArrayList<>();
+                    break;
+                }
+            }
+            if (Objects.isNull(userIdList)) {
+                continue;
+            }
+
+            List<Long> roleIsList = sysDingObjList.stream().map(s -> s.getRoleId()).collect(Collectors.toList());
+            //首选查角色类型
+            List<SysRole> sysRoleList = sysRoleService.listByIds(roleIsList);
+            List<Long> sysRoleOtherList = new ArrayList<>();
+            for (SysRole s : sysRoleList) {
+                if (s.getType() == RoleTypeEnum.BUSSINESS) {
+                    List<TBService> tbServiceList = tbServiceService.listByIds(Arrays.asList(serviceId));
+                    List<String> serviceLeadIdList = tbServiceList.stream().map(i -> String.valueOf(i.getServiceLeadId())).collect(Collectors.toList());
+                    userIdList.addAll(serviceLeadIdList);
+                } else if (s.getType() == RoleTypeEnum.REGION_MANAGER) {
+                    List<TBCrm> tbCrmList = tbCrmService.list(new QueryWrapper<TBCrm>().lambda().eq(TBCrm::getServiceId, serviceId));
+                    List<String> leadIdList = tbCrmList.stream().map(i -> String.valueOf(i.getLeadId())).collect(Collectors.toList());
+                    userIdList.addAll(leadIdList);
+                } else if (s.getType() == RoleTypeEnum.REGION_COORDINATOR) {
+                    List<TBCrm> tbCrmList = tbCrmService.list(new QueryWrapper<TBCrm>().lambda().eq(TBCrm::getServiceId, serviceId));
+                    List<String> regionCoordinatorIdList = tbCrmList.stream().map(i -> String.valueOf(i.getRegionCoordinatorId())).collect(Collectors.toList());
+                    userIdList.addAll(regionCoordinatorIdList);
+                } else {
+                    sysRoleOtherList.add(s.getId());
+                }
+            }
+            if (!CollectionUtils.isEmpty(sysRoleOtherList)) {
+                List<SysUserRole> sysUserRoleList = this.list(new QueryWrapper<SysUserRole>().lambda().in(SysUserRole::getRoleId, sysRoleOtherList));
+                List<String> otherRoleUserList = sysUserRoleList.stream().map(i -> String.valueOf(i.getUserId())).collect(Collectors.toList());
+                userIdList.addAll(otherRoleUserList);
             }
+            break;
         }
-        if (!CollectionUtils.isEmpty(sysRoleOtherList)) {
-            List<SysUserRole> sysUserRoleList = this.list(new QueryWrapper<SysUserRole>().lambda().in(SysUserRole::getRoleId, sysRoleOtherList));
-            List<String> otherRoleUserList = sysUserRoleList.stream().map(i -> String.valueOf(i.getUserId())).collect(Collectors.toList());
-            userIdList.addAll(otherRoleUserList);
+        if (CollectionUtils.isEmpty(userIdList)) {
+            throw ExceptionResultEnum.ERROR.exception("未找到异常考勤审批用户");
         }
         return userIdList;
     }

+ 2 - 2
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBDingApplyServiceImpl.java

@@ -92,7 +92,7 @@ public class TBDingApplyServiceImpl extends ServiceImpl<TBDingApplyMapper, TBDin
         CrmProjectResult crmProjectResult = tbCrmService.findCrmProjectBySopNoOrCrmNo(sopNo, crmNo);
         Optional.ofNullable(crmProjectResult).orElseThrow(() -> ExceptionResultEnum.CRM_NO_NO_DATA.exception());
 
-        List<String> sysUserRoleList = sysUserRoleService.listByServiceId(crmProjectResult.getServiceUnitId());
+        List<String> sysUserRoleList = sysUserRoleService.listByServiceId(crmProjectResult.getServiceUnitId(), sysUser.getId());
         List<String> approveUserIds = new ArrayList<>();
         approveUserIds.addAll(sysUserRoleList);
         FlowApproveParam flowApproveParam = new FlowApproveParam(tbDingApply.getFlowDeploymentId(), FlowApprovePassEnum.START, approveUserIds, crmNo);
@@ -316,7 +316,7 @@ public class TBDingApplyServiceImpl extends ServiceImpl<TBDingApplyMapper, TBDin
         Optional.ofNullable(crmProjectResult).orElseThrow(() -> ExceptionResultEnum.CRM_NO_NO_DATA.exception());
         Optional.ofNullable(crmProjectResult.getRegionCoordinatorId()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("crm区域协调人数据为空"));
 
-        List<String> sysUserRoleList = sysUserRoleService.listByServiceId(crmProjectResult.getServiceUnitId());
+        List<String> sysUserRoleList = sysUserRoleService.listByServiceId(crmProjectResult.getServiceUnitId(), tbDingApply.getCreateId());
         List<String> approveUserIds = new ArrayList<>();
         approveUserIds.addAll(sysUserRoleList);
         activitiService.taskApprove(new FlowApproveParam(taskId, FlowApprovePassEnum.PASS, approveUserIds, tfCustomFlowEntity.getCrmNo(), dingExceptionApprove.getTitle()));