智慧保安后台管理-外网项目备份
Administrator
2021-11-29 2a76be6f05cf13453b69609aa36d8548a5bae119
src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
@@ -27,6 +27,7 @@
import org.springblade.common.constant.AgeUtil;
import org.springblade.common.constant.CommonConstant;
import org.springblade.common.constant.TenantConstant;
import org.springblade.common.utils.IdCardNoUtil;
import org.springblade.common.utils.QRCodeUtil;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
@@ -826,6 +827,26 @@
            //如果deptIds 为空,则说明还没有改公司
            throw new ServiceException("导入失败!公司名:["+user.getDeptId()+"]不存在!");
         }
         //身份证校验
         if (null==user.getCardid() || user.getCardid().equals("")){
            throw new ServiceException("导入失败!身份证号码不能为空!");
         }
         if (null!=user.getCardid() && !user.getCardid().equals("")){
            //去除所有空格
            String cardid = user.getCardid().replaceAll(" ", "");
            //校验
            boolean b = IdCardNoUtil.checkIdCardNo(cardid);
            if(b){
               user.setCardid(cardid);
            }else {
               agetStatus.set(false);
               ageErrorList.add(user.getCardid());
//               throw new ServiceException("导入失败!身份证号码[ "+user.getCardid()+" ]不正确,请核对!");
               //forEach 只能使用 return 跳出本次循环
               return;
            }
         }
         //判断当前用户是否已在本单位,如果是的更新数据
         User user1 = new User();
         user1.setAccount(user.getCardid());
@@ -881,26 +902,6 @@
               //新增
               this.save(user);
               //内网同步
//            String s = "insert into blade_user(" +
//               "id,tenant_id,account,password,real_name,phone,sex,role_id,dept_id," +
//               "cardid,nation,registered,securitynumber,hold,status,is_deleted) " +
//               "values(" + "'" + user.getId() + "'" + "," +
//               "'" + user.getTenantId() + "'" + "," +
//               "'" + user.getAccount() + "'" + "," +
//               "'" + user.getPassword() + "'" + "," +
//               "'" + user.getRealName() + "'" + "," +
//               "'" + user.getPhone() + "'" + "," +
//               "'" + user.getSex() + "'" + "," +
//               "'" + user.getRoleId() + "'" +
//               "," + "'" + user.getDeptId() + "'" +
//               "," + "'" + user.getCardid() + "'" +
//               "," + "'" + user.getNation() + "'" +
//               "," + "'" + user.getRegistered() + "'" +
//               "," + "'" + user.getSecuritynumber() + "'" +
//               "," + "'" + user.getHold() + "'" +
//               "," + "'" + user.getStatus() + "'" +
//               "," + "'" + user.getIsDeleted() + "'"
//               + ")";
               String s = "insert into blade_user(" +
                  "id,tenant_id,account,password,name,real_name,avatar,email,phone,sex," +
                  "role_id,dept_id,cardid,nativePlace,nation,fingerprint,education," +
@@ -944,9 +945,7 @@
            //匹配组织机构是否一致,如果不一致
            if(!user2.getDeptId().equals(user.getDeptId())){
               Dept dept = deptService.getById(user2.getDeptId());
               System.out.println("dept = " + dept);
               Dept dept1 = deptService.getById(user.getDeptId());
               System.out.println("dept1 = " + dept1);
               //如果是南昌总公司分公司导入的
               if (dept.getId().equals(1432626178757275649L) && dept1.getParentId().equals(1432626178757275649L)){
                  user2.setDeptId(dept1.getId().toString());
@@ -1012,26 +1011,26 @@
         }
      });
      //如果所有数据导入有一个异常
//      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 + "]导入失败!年龄不符!");
//         }
//      }
      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 + "]导入失败!身份证号码不正确,请核对!");
         }
      }
//      if (!status.get()) {
//         String errorAccount = StringUtils.join(errorList, "\\\n");
//         throw new ServiceException("用户:[" + errorAccount + "]导入失败!已在其他单位存在!");
//      }
   }
   @Override
@@ -1039,11 +1038,12 @@
//将不能导入的保安员账号存起来
      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
@@ -1058,6 +1058,26 @@
         }else {
            //如果deptIds 为空,则说明还没有改公司
            throw new ServiceException("导入失败!公司名:["+user.getDeptId()+"]不存在!");
         }
         //身份证校验
         if (null==user.getCardid() || user.getCardid().equals("")){
            throw new ServiceException("导入失败!身份证号码不能为空!");
         }
         if (null!=user.getCardid() && !user.getCardid().equals("")){
            //去除所有空格
            String cardid = user.getCardid().replaceAll(" ", "");
            //校验
            boolean b = IdCardNoUtil.checkIdCardNo(cardid);
            if(b){
               user.setCardid(cardid);
            }else {
               agetStatus.set(false);
               ageErrorList.add(user.getCardid());
//               throw new ServiceException("导入失败!身份证号码[ "+user.getCardid()+" ]不正确,请核对!");
               //forEach 只能使用 return 跳出本次循环
               return;
            }
         }
         //判断当前用户是否已在本单位,如果是的更新数据
         User user1 = new User();
@@ -1173,12 +1193,50 @@
         else {
            //匹配组织机构是否一致,如果不一致
            if(!user2.getDeptId().equals(user.getDeptId())){
//               Dept dept = deptService.getById(user2.getDeptId());
//               status.set(false);
//               //加入集合
//               errorList.add(user.getCardid());
//               //forEach 只能使用 return 跳出本次循环
//               return;
               Dept dept = deptService.getById(user2.getDeptId());
               Dept dept1 = deptService.getById(user.getDeptId());
               //如果是南昌总公司分公司导入的
               if (dept.getId().equals(1432626178757275649L) && dept1.getParentId().equals(1432626178757275649L)){
                  user2.setDeptId(dept1.getId().toString());
                  //判断是否持证
                  if (null != userExcel.getHold() && userExcel.getHold() != "") {
                     if (userExcel.getHold().equals("是") && userExcel.getSecuritynumber()!=null && !userExcel.getSecuritynumber().equals("")) {
                        user2.setHold("1");
                        //更新保安证编号
                        user2.setSecuritynumber(user.getSecuritynumber());
                     }
                     if (userExcel.getHold().equals("否")) {
                        user2.setHold("2");
                     }
                  }
                  if (null!=userExcel.getRegistered()){
                     user2.setRegistered(userExcel.getRegistered());
                  }else {
                     user2.setRegistered("");
                  }
                  //更新用户数据
                  this.updateById(user2);
                  String s1 =
                     "update blade_user set hold = " + "'" + user2.getHold() + "'"
                        + ",securitynumber = " + "'" + user2.getSecuritynumber() + "'"
                        + ",dept_id = " + "'" + user2.getDeptId() + "'"
                        + ",registered = " + "'" + user2.getRegistered() + "'"
                        + " " + "where id = " + "'" + user2.getId() + "'";
                  FtpUtil.sqlFileUpload(s1);
               }else {
               status.set(false);
               //加入集合
               errorList.add(user.getCardid());
               //forEach 只能使用 return 跳出本次循环
               return;
               }
            }else {
               //如果是一致,则更新用户数据
               //判断是否持证
@@ -1209,10 +1267,26 @@
         }
      });
      //如果所有数据导入有一个异常
      if (!status.get()){
//      if (!status.get()){
//         String errorAccount = StringUtils.join(errorList, "\\\n");
//         throw new ServiceException("用户:["+errorAccount+"]导入失败!已在其他单位存在!");
//      }
      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 + "]导入失败!身份证号码不正确,请核对!");
         }
      }
   }