lixing 4 gadi atpakaļ
vecāks
revīzija
757eb4d8fa

+ 68 - 9
fm-person/src/main/java/com/persagy/fm/person/service/impl/PersonServiceImpl.java

@@ -541,16 +541,25 @@ public class PersonServiceImpl extends ServiceImpl<PersonMapper, Person>
      * @version V1.0 2021/4/8 3:07 下午
      */
     private void resetAccountRoles(UpdatePerson4FrontEndDTO updatePerson4FrontEndDTO, String accountId) {
+        // 判断主副岗角色是否重合
+        List<String> otherDuties = updatePerson4FrontEndDTO.getOtherDuties();
+        String mainDuty = updatePerson4FrontEndDTO.getMainDuty();
+        if (!CollectionUtils.isEmpty(otherDuties) &&
+                StringUtils.isNotBlank(mainDuty) &&
+                otherDuties.contains(mainDuty)) {
+            throw new IllegalArgumentException("人员主岗与副岗不能出现重合");
+        }
+
         List<AddSaasAccountRoleDTO> accountRoleDTOList = Lists.newArrayList();
-        if (StringUtils.isNotBlank(updatePerson4FrontEndDTO.getMainDuty())) {
+        if (StringUtils.isNotBlank(mainDuty)) {
             AddSaasAccountRoleDTO mainDutyDTO = new AddSaasAccountRoleDTO();
-            mainDutyDTO.setRoleId(updatePerson4FrontEndDTO.getMainDuty());
+            mainDutyDTO.setRoleId(mainDuty);
             mainDutyDTO.setCasType(AccountRoleTypeEnum.MAIN_DUTY.getType());
             accountRoleDTOList.add(mainDutyDTO);
         }
 
-        if (!CollectionUtils.isEmpty(updatePerson4FrontEndDTO.getOtherDuties())) {
-            updatePerson4FrontEndDTO.getOtherDuties().forEach(otherDuty -> {
+        if (!CollectionUtils.isEmpty(otherDuties)) {
+            otherDuties.forEach(otherDuty -> {
                 AddSaasAccountRoleDTO otherDutyDTO = new AddSaasAccountRoleDTO();
                 otherDutyDTO.setRoleId(otherDuty);
                 otherDutyDTO.setCasType(AccountRoleTypeEnum.OTHER_DUTY.getType());
@@ -888,6 +897,18 @@ public class PersonServiceImpl extends ServiceImpl<PersonMapper, Person>
             return;
         }
 
+        // 如果有主副岗的更新,判断涉及到的人员是否有主副岗重复的情况
+        String mainDuty = batchUpdatePersonDTO.getMainDuty();
+        List<String> otherDuties = batchUpdatePersonDTO.getOtherDuties();
+        if (mainDuty != null || otherDuties != null) {
+            if (mainDuty != null && otherDuties != null && otherDuties.contains(mainDuty)) {
+                throw new IllegalArgumentException("人员主岗与副岗不能出现重合");
+            }
+            personIds.forEach(personId -> {
+                checkMainAndOtherDutiesWhenBatchUpdate(mainDuty, otherDuties, personId);
+            });
+        }
+
         // 更新人员基本信息
         if (batchUpdatePersonDTO.getPersonType() != null ||
                 batchUpdatePersonDTO.getProfessions() != null) {
@@ -907,11 +928,11 @@ public class PersonServiceImpl extends ServiceImpl<PersonMapper, Person>
         }
 
         // 更新主岗
-        if (batchUpdatePersonDTO.getMainDuty() != null) {
+        if (mainDuty != null) {
             personIds.forEach(personId -> {
                 Person person = getById(personId);
                 AddSaasAccountRoleDTO addSaasAccountRoleDTO = new AddSaasAccountRoleDTO();
-                addSaasAccountRoleDTO.setRoleId(batchUpdatePersonDTO.getMainDuty());
+                addSaasAccountRoleDTO.setRoleId(mainDuty);
                 addSaasAccountRoleDTO.setCasType(AccountRoleTypeEnum.MAIN_DUTY.getType());
                 saasAccountRoleService.resetSaasAccountRole(
                         person.getAccountId(), AccountRoleTypeEnum.MAIN_DUTY.getType(),
@@ -920,10 +941,10 @@ public class PersonServiceImpl extends ServiceImpl<PersonMapper, Person>
         }
 
         // 更新副岗
-        if (batchUpdatePersonDTO.getOtherDuties() != null) {
+        if (otherDuties != null) {
             personIds.forEach(personId -> {
                 Person person = getById(personId);
-                List<AddSaasAccountRoleDTO> otherDuties = batchUpdatePersonDTO.getOtherDuties().stream().map(
+                List<AddSaasAccountRoleDTO> otherDutiesDTO = otherDuties.stream().map(
                         otherDuty -> {
                             AddSaasAccountRoleDTO addSaasAccountRoleDTO = new AddSaasAccountRoleDTO();
                             addSaasAccountRoleDTO.setRoleId(otherDuty);
@@ -932,7 +953,7 @@ public class PersonServiceImpl extends ServiceImpl<PersonMapper, Person>
                         }
                 ).collect(Collectors.toList());
                 saasAccountRoleService.resetSaasAccountRole(
-                        person.getAccountId(), AccountRoleTypeEnum.OTHER_DUTY.getType(), otherDuties);
+                        person.getAccountId(), AccountRoleTypeEnum.OTHER_DUTY.getType(), otherDutiesDTO);
             });
         }
 
@@ -954,6 +975,44 @@ public class PersonServiceImpl extends ServiceImpl<PersonMapper, Person>
         }
     }
 
+    /**
+     * 批量更新时,验证人员的主副岗是否重复
+     *
+     * @param mainDuty 更新条件中的主岗,为空代表不更新
+     * @param otherDuties 更新条件中的副岗,为空代表不更新
+     * @param personId 人员id
+     * @author lixing
+     * @version V1.0 2021/4/21 7:44 下午
+     */
+    private void checkMainAndOtherDutiesWhenBatchUpdate(String mainDuty, List<String> otherDuties, String personId) {
+        Person person = getById(personId);
+        String accountId = person.getAccountId();
+        // 设置人员岗位角色信息
+        Map<String, AccountRoleVO> accountRoleVoMap = saasAccountRoleService.
+                queryAccountRoleVoMapByAccountIdList(Lists.newArrayList(accountId));
+        if (accountRoleVoMap != null) {
+            AccountRoleVO accountRoleVO = accountRoleVoMap.get(accountId);
+            String personMainDuty = mainDuty;
+            if (mainDuty == null) {
+                SimpleObjVO mainDutyVO = accountRoleVO.getMainDuty();
+                personMainDuty = mainDutyVO == null? null: mainDutyVO.getId();
+            }
+            List<String> personOtherDuties = otherDuties;
+            if (otherDuties == null) {
+                List<SimpleObjVO> otherDutiesVO = accountRoleVO.getOtherDuties();
+                if (otherDutiesVO != null) {
+                    personOtherDuties = otherDutiesVO.stream().
+                            map(SimpleObjVO::getId).collect(Collectors.toList());
+                }
+            }
+            if(!CollectionUtils.isEmpty(personOtherDuties)
+                    && StringUtils.isNotBlank(personMainDuty)
+                    && personOtherDuties.contains(personMainDuty)) {
+                throw new IllegalArgumentException("人员主岗与副岗不能出现重合");
+            }
+        }
+    }
+
     @Override
     public List<Person> nameQuickSearch(NameQuickSearchDTO nameQuickSearchDTO) {
         return personMapper.queryPersonNameList(nameQuickSearchDTO);