智慧保安后台管理-外网项目备份
src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
@@ -804,12 +804,13 @@
   public void importSecurity(List<SecurityExcel> data, Boolean isCovered, String deptId) {
      //将不能导入的保安员账号存起来
      List<String> errorList = new ArrayList<>();
      //将需要新增的保安员信息存入集合
      List<User> insertList = new ArrayList<>();
      //年龄不符的保安员信息存入集合
      List<String> ageErrorList = new ArrayList<>();
      //将需要更新的保安员信息存入集合
      List<User> updateList = new ArrayList<>();
      //导入状态,默认为true ,如果有一个出现问题则为 false
      AtomicBoolean status = new AtomicBoolean(true);
      AtomicBoolean agetStatus = new AtomicBoolean(true);
      data.forEach(userExcel -> {
         User user = Objects.requireNonNull(BeanUtil.copy(userExcel, User.class));
         //设置部门id
@@ -847,6 +848,8 @@
                  user.setHold("2");
               }
            }
            //判断年龄,超过60岁的不入
            if (AgeUtil.idCardToAge(user.getCardid())<60) {
            //分配保安角色
            Role role = new Role();
            role.setRoleAlias("保安");
@@ -934,6 +937,10 @@
               "," + "'" + user.getDispatch() + "'" + ")";
            FtpUtil.sqlFileUpload(s);
         }else {
               agetStatus.set(false);
               ageErrorList.add(user.getCardid());
            }
         }else {
            //匹配组织机构是否一致,如果不一致
            if(!user2.getDeptId().equals(user.getDeptId())){
               Dept dept = deptService.getById(user2.getDeptId());
@@ -972,10 +979,22 @@
         }
      });
      //如果所有数据导入有一个异常
      if (!status.get()){
      if (!status.get() || !agetStatus.get()){
         if (!status.get() && agetStatus.get()) {
         String errorAccount = StringUtils.join(errorList, "\\\n");
         throw new ServiceException("用户:["+errorAccount+"]导入失败!已在其他单位存在!");
      }
         if (!agetStatus.get() && status.get()) {
            String errorAccount = StringUtils.join(ageErrorList, "\\\n");
            throw new ServiceException("用户:[" + errorAccount + "]导入失败!年龄不符!");
         }
         if (!status.get() && !agetStatus.get()) {
            String errorAccount = StringUtils.join(errorList, "\\\n");
            String errorAgeAccount = StringUtils.join(ageErrorList, "\\\n");
            throw new ServiceException("用户:[" + errorAccount + "]导入失败!已在其他单位存在!"+
               "用户:[" + errorAgeAccount + "]导入失败!年龄不符!");
         }
      }
   }
   @Override