智慧保安后台管理-外网
Administrator
2022-06-15 30701db6feddef40a7306b93f1571baaa5d0aeaa
src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
@@ -59,10 +59,7 @@
import org.springblade.modules.securitypaper.entity.SecurityPaper;
import org.springblade.modules.securitypaper.service.SecurityPaperService;
import org.springblade.modules.system.entity.*;
import org.springblade.modules.system.excel.QrCodeExcel;
import org.springblade.modules.system.excel.SecurityExcel;
import org.springblade.modules.system.excel.SecurityYyExcel;
import org.springblade.modules.system.excel.UserExcel;
import org.springblade.modules.system.excel.*;
import org.springblade.modules.system.mapper.UserMapper;
import org.springblade.modules.system.node.TreeNode;
import org.springblade.modules.system.service.*;
@@ -350,8 +347,12 @@
   @Override
   public UserInfo userInfo(String tenantId, String account, String password, UserEnum userEnum) {
      User user = baseMapper.getUser(tenantId, account, password);
      return buildUserInfo(user, userEnum);
      try {
         User user = baseMapper.getUser(tenantId, account, password);
         return buildUserInfo(user, userEnum);
      }catch (Exception e){
         throw new ServiceException("账号["+account+"]"+"重复!");
      }
   }
   private UserInfo buildUserInfo(User user) {
@@ -1245,27 +1246,11 @@
    */
   @Override
   public void importSecurity(List<SecurityExcel> data, Boolean isCovered, String deptId) {
      long time = System.currentTimeMillis();
      //uuidList
      List<String> uuidList = new ArrayList<>();
      //将不能导入的保安员账号存起来
      List<String> errorList = new ArrayList<>();
      //年龄不符的保安员信息存入集合
      List<String> ageErrorList = new ArrayList<>();
      //保安员证编号不符的保安员信息存入集合
      List<String> securityInvalidList = new ArrayList<>();
      //将需要更新的保安员信息存入集合
      List<User> updateList = new ArrayList<>();
      //需要推送内网的保安员信息集合
      List<User> userList = new ArrayList<>();
      //需要新增的保安员集合
      List<User> addList = new ArrayList<>();
      //需要新增的从业记录集合
      List<Experience> experienceList = new ArrayList<>();
      //导入状态,默认为true ,如果有一个出现问题则为 false
      AtomicBoolean status = new AtomicBoolean(true);
      AtomicBoolean agetStatus = new AtomicBoolean(true);
      AtomicBoolean securityInvalidStatus = new AtomicBoolean(true);
      //遍历
      for (SecurityExcel userExcel : data) {
         User user = Objects.requireNonNull(BeanUtil.copy(userExcel, User.class));
@@ -1273,8 +1258,11 @@
         String deptIds = userDeptService.selectIn(user.getDeptId());
         if (null!=deptIds && !deptIds.equals("")) {
            if (null != deptId && !deptId.equals("")) {
               //管理员不分单位导入
               if (!deptId.equals(deptIds)) {
                  throw new ServiceException("导入失败!不能导入不是本公司的保安员数据!");
                  if(!deptId.equals("1123598813738675201")) {
                     throw new ServiceException("导入失败!不能导入不是本公司的保安员数据!");
                  }
               }
            }
            user.setDeptId(deptIds);
@@ -1302,8 +1290,6 @@
               agetStatus.set(false);
               ageErrorList.add(user.getCardid());
//               throw new ServiceException("导入失败!身份证号码[ "+user.getCardid()+" ]不正确,请核对!");
               //forEach 只能使用 return 跳出本次循环
//               return;
               continue;
            }
         }
@@ -1314,10 +1300,7 @@
         user.setStatus(1);
         user.setIsDeleted(0);
         //分配保安角色
         Role role = new Role();
         role.setRoleAlias("保安");
         Role oneRole = roleService.getOne(Condition.getQueryWrapper(role));
         user.setRoleId(oneRole.getId().toString());
         user.setRoleId("1412226235153731586");
         if (null!=user.getSecuritynumber() && !user.getSecuritynumber().equals("")){
            user.setHold("1");
@@ -1326,20 +1309,16 @@
         }
         //性别
         if (null != userExcel.getSex()) {
            if (userExcel.getSex().equals("男")) {
               user.setSex(1);
            }else if (userExcel.getSex().equals("女")) {
               user.setSex(2);
            }else {
               user.setSex(1);
            }
         }else {
         if (IdCardNoUtil.getSex(userExcel.getCardid()).equals("男")) {
            user.setSex(1);
         }else {
            user.setSex(2);
         }
         //设置账号
         user.setAccount(user.getRealName());
         String realName = user.getRealName();
         String cardid = user.getCardid();
         user.setAccount(realName.substring(0,1)+cardid.substring(cardid.length()-4));
         //加密
         user.setPassword(DigestUtil.encrypt(user.getCardid().substring(user.getCardid().length() - 6)));
         user.setCreateTime(new Date());
@@ -1359,10 +1338,8 @@
         user0.setReasonForLeav(uuid);
         //加入集合
         userList.add(user0);
         uuidList.add(uuid);
      }
      Result result = new Result();
      //用户批量插入
      if (userList.size()>0) {
         //生成随机数
@@ -1371,92 +1348,91 @@
         Map<String, Object> map = new HashMap<>(1);
         map.put(uuid, userList);
         myAsyncService.FTPObjectList(map);
      }
         int count = 0;
         //调用ftp获取返回数据
         while (true){
            try {
               Thread.sleep(1000);
            } catch (InterruptedException e) {
               e.printStackTrace();
            }
            //调用ftp获取返回数据
            result = Monitor.getFtpDataByUuidList(uuid);
            //如果返回true,就退处
            if (result.getCode() == 200) {
               break;
            }
//            else {
//               count++;
//               if (count == 60) {
//                  break;
//      if (null!=result){
//         //获取 result
//         List<Result> data1 = result.getData();
//         if (data1.size()>0){
//            for (Result result1 : data1) {
//               // 取出 Msg ,此 msg 存的对应的 uuid
//               String uuid = result1.getMsg();
//               //从redis 中获取用户数据
//               Object o1 = redisTemplate.opsForValue().get(uuid);
//               User user0 = JSON.parseObject(o1.toString(), User.class);
//               // 从redis 中获取对应的用户信息,脱敏处理过
//               User user = handlerUserInfo(uuid);
//               if (result1.getCode()==200){
//                  user.setId(result1.getUserId());
//                  boolean save = this.save(user);
//                  //同步用户数据到群防群控
//                  if (save) {
//                     myAsyncService.qfqkUserSave(user);
//                  }
//                  //加入新增集合
////                  addList.add(user);
//               }
//               if (result1.getCode()==201){
//                  //先查询当前库是否有改用户?
//                  User user1 = this.getById(result1.getUserId());
//                  if (null!=user1) {
//                     //存在,更新
//                     user.setId(result1.getUserId());
//                     user.setCreateTime(null);
//                     boolean update = this.updateById(user);
//                     if (update) {
//                        //数据异步同步到群防群控
//                        myAsyncService.updateUserByQfqk(user);
//                     }
//                  }else {
//                     //不存在,则新增
//                     user.setId(result1.getUserId());
//                     boolean save = this.save(user);
//                     if (save){
//                        //数据异步同步到群防群控
//                        myAsyncService.qfqkUserSave(user);
//                     }
//                  }
//                  //加入更新集合
////                  updateList.add(user);
//               }
//               if (result1.getCode()==202){
//                  status.set(false);
//                  //已在其他单位存在
//                  errorList.add(user0.getCardid());
//               }
//               if (result1.getCode()==203){
//                  securityInvalidStatus.set(false);
//                  //保安证编号不匹配
//                  securityInvalidList.add(user0.getCardid());
//               }
//            }
         }
      }
////            //批量插入
////            if (addList.size()>0){
////               baseMapper.batchUserList(addList);
////            }
////            //批量更新
////            if (updateList.size()>0){
////               baseMapper.batchUpdateUserList(updateList);
////            }
//         }
//      }
      if (null!=result){
         //获取 result
         List<Result> data1 = result.getData();
         if (data1.size()>0){
            for (Result result1 : data1) {
               // 取出 Msg ,此 msg 存的对应的 uuid
               String uuid = result1.getMsg();
               //从redis 中获取用户数据
               Object o1 = redisTemplate.opsForValue().get(uuid);
               User user0 = JSON.parseObject(o1.toString(), User.class);
               // 从redis 中获取对应的用户信息,脱敏处理过
               User user = handlerUserInfo(uuid);
               if (result1.getCode()==200){
                  user.setId(result1.getUserId());
                  this.save(user);
                  //加入新增集合
//                  addList.add(user);
               }
               if (result1.getCode()==201){
                  user.setId(result1.getUserId());
                  user.setCreateTime(null);
                  this.updateById(user);
                  //加入更新集合
//                  updateList.add(user);
               }
               if (result1.getCode()==202){
                  status.set(false);
                  //已在其他单位存在
                  errorList.add(user0.getCardid());
               }
               if (result1.getCode()==203){
                  securityInvalidStatus.set(false);
                  //保安证编号不匹配
                  securityInvalidList.add(user0.getCardid());
               }
            }
//            //批量插入
//            if (addList.size()>0){
//               baseMapper.batchUserList(addList);
//            }
//            //批量更新
//            if (updateList.size()>0){
//               baseMapper.batchUpdateUserList(updateList);
//            }
         }
      }
      //如果所有数据导入有一个异常
//      //如果所有数据导入有一个异常
      StringBuilder errorBuilder = new StringBuilder();
      if (!status.get()){
         String errorAccount = StringUtils.join(errorList, "\\\n");
         errorBuilder.append("用户:[" + errorAccount + "]导入失败!已在其他单位存在!");
      }
//      if (!status.get()){
//         String errorAccount = StringUtils.join(errorList, "\\\n");
//         errorBuilder.append("用户:[" + errorAccount + "]导入失败!已在其他单位存在!");
//      }
      if (!agetStatus.get()){
         String errorAccount = StringUtils.join(ageErrorList, "\\\n");
         errorBuilder.append("用户:[" + errorAccount + "]导入失败!身份证号码不正确,请核对!");
      }
      if (!securityInvalidStatus.get()){
         String errorAccount = StringUtils.join(securityInvalidList, "\\\n");
//         errorBuilder.append("用户:[" + errorAccount + "]保安证编号不匹配,请核实!");
         errorBuilder.append("用户:[" + errorAccount + "]保安证编号不匹配,请核实!也可通过提供保安证件信息提交核实申请!");
      }
//      if (!securityInvalidStatus.get()){
//         String errorAccount = StringUtils.join(securityInvalidList, "\\\n");
////         errorBuilder.append("用户:[" + errorAccount + "]保安证编号不匹配,请核实!");
//         errorBuilder.append("用户:[" + errorAccount + "]保安证编号不匹配,请核实!也可通过提供保安证件信息提交核实申请!");
//      }
      //抛出异常
      if (errorBuilder.length()>0){
         throw new ServiceException(errorBuilder.toString());
@@ -1477,6 +1453,7 @@
      //返回的user,需处理敏感数据
      User user1 = Objects.requireNonNull(BeanUtil.copy(user,User.class));
      //敏感数据处理
      user1.setRealName(DesensitizedUtil.desensitizedName(user.getRealName()));
      user1.setCardid(DesensitizedUtil.desensitizedIdNumberBy4(user.getCardid()));
      user1.setPhone(DesensitizedUtil.desensitizedPhoneNumber(user.getPhone()));
      user1.setRegistered(DesensitizedUtil.desensitizedAddress(user.getRegistered()));
@@ -1592,7 +1569,10 @@
         }
         //设置账号
         user.setAccount(user.getRealName());
         String realName = user.getRealName();
         String cardid = user.getCardid();
//         user.setAccount(user.getRealName());
         user.setAccount(realName.substring(0,1)+cardid.substring(cardid.length()-4));
         //加密
         user.setPassword(DigestUtil.encrypt(user.getCardid().substring(user.getCardid().length() - 6)));
         user.setCreateTime(new Date());
@@ -1625,81 +1605,109 @@
         map.put(uuid, userList);
         myAsyncService.FTPObjectList(map);
         int count = 0;
         //调用ftp获取返回数据
         while (true){
            try {
               Thread.sleep(1000);
            } catch (InterruptedException e) {
               e.printStackTrace();
            }
            //调用ftp获取返回数据
            result = Monitor.getFtpDataByUuidList(uuid);
            //如果返回true,就退处
            if (result.getCode() == 200) {
               break;
            }
         }
//         int count = 0;
//         //调用ftp获取返回数据
//         while (true){
//            try {
//               Thread.sleep(4000);
//            } catch (InterruptedException e) {
//               e.printStackTrace();
//            }
//            //调用ftp获取返回数据
//            result = Monitor.getFtpDataByUuidList(uuid);
//            //如果返回true,就退处
//            if (result.getCode() == 200) {
//               break;
//            }
//            else {
//               count++;
//               if (count == 20) {
//                  break;
//               }
//            }
//         }
      }
      if (null!=result){
         //获取 result
         List<Result> data1 = result.getData();
         if (data1.size()>0){
            for (Result result1 : data1) {
               // 取出 Msg ,此 msg 存的对应的 uuid
               String uuid = result1.getMsg();
               //从redis 中获取用户数据
               Object o1 = redisTemplate.opsForValue().get(uuid);
               User user0 = JSON.parseObject(o1.toString(), User.class);
               // 从redis 中获取对应的用户信息,脱敏处理过
               User user = handlerUserInfo(uuid);
               if (result1.getCode()==200){
                  user.setId(result1.getUserId());
                  this.save(user);
                  //加入新增集合
//                  addList.add(user);
               }
               if (result1.getCode()==201){
                  user.setId(result1.getUserId());
                  user.setCreateTime(null);
                  this.updateById(user);
                  //加入更新集合
//                  updateList.add(user);
               }
               if (result1.getCode()==202){
                  status.set(false);
                  //已在其他单位存在
                  errorList.add(user0.getCardid());
               }
               if (result1.getCode()==203){
                  securityInvalidStatus.set(false);
                  //保安证编号不匹配
                  securityInvalidList.add(user0.getCardid());
               }
            }
         }
      }
      //如果所有数据导入有一个异常
      StringBuilder errorBuilder = new StringBuilder();
      if (!status.get()){
         String errorAccount = StringUtils.join(errorList, "\\\n");
         errorBuilder.append("用户:[" + errorAccount + "]导入失败!已在其他单位存在!");
      }
      if (!agetStatus.get()){
         String errorAccount = StringUtils.join(ageErrorList, "\\\n");
         errorBuilder.append("用户:[" + errorAccount + "]导入失败!身份证号码不正确,请核对!");
      }
      if (!securityInvalidStatus.get()){
         String errorAccount = StringUtils.join(securityInvalidList, "\\\n");
         errorBuilder.append("用户:[" + errorAccount + "]保安证编号不匹配,请核实!");
//         errorBuilder.append("用户:[" + errorAccount + "]保安证编号不匹配,请核实!也可通过提供保安证件信息提交核实申请!");
      }
      //抛出异常
      if (errorBuilder.length()>0){
         throw new ServiceException(errorBuilder.toString());
      }
//      if (null!=result){
//         //获取 result
//         List<Result> data1 = result.getData();
//         if (data1.size()>0){
//            for (Result result1 : data1) {
//               // 取出 Msg ,此 msg 存的对应的 uuid
//               String uuid = result1.getMsg();
//               //从redis 中获取用户数据
//               Object o1 = redisTemplate.opsForValue().get(uuid);
//               User user0 = JSON.parseObject(o1.toString(), User.class);
//               // 从redis 中获取对应的用户信息,脱敏处理过
//               User user = handlerUserInfo(uuid);
//               if (result1.getCode()==200){
//                  user.setId(result1.getUserId());
//                  boolean save = this.save(user);
//                  if (save){
//                     //数据异步同步到群防群控
//                     myAsyncService.qfqkUserSave(user);
//                  }
//                  //加入新增集合
////                  addList.add(user);
//               }
//               //更新
//               if (result1.getCode()==201){
//                  //先查询当前库是否有改用户?
//                  User user1 = this.getById(result1.getUserId());
//                  if (null!=user1) {
//                     //存在,更新
//                     user.setId(result1.getUserId());
//                     user.setCreateTime(null);
//                     boolean update = this.updateById(user);
//                     if (update) {
//                        //数据异步同步到群防群控
//                        myAsyncService.updateUserByQfqk(user);
//                     }
//                  }else {
//                     //不存在,则新增
//                     user.setId(result1.getUserId());
//                     boolean save = this.save(user);
//                     if (save){
//                        //数据异步同步到群防群控
//                        myAsyncService.qfqkUserSave(user);
//                     }
//                  }
//                  //加入更新集合
////                  updateList.add(user);
//               }
//               if (result1.getCode()==202){
//                  status.set(false);
//                  //已在其他单位存在
//                  errorList.add(user0.getCardid());
//               }
//               if (result1.getCode()==203){
//                  securityInvalidStatus.set(false);
//                  //保安证编号不匹配
//                  securityInvalidList.add(user0.getCardid());
//               }
//            }
//         }
//      }
//
//      //如果所有数据导入有一个异常
//      StringBuilder errorBuilder = new StringBuilder();
//      if (!status.get()){
//         String errorAccount = StringUtils.join(errorList, "\\\n");
//         errorBuilder.append("用户:[" + errorAccount + "]导入失败!已在其他单位存在!");
//      }
//      if (!agetStatus.get()){
//         String errorAccount = StringUtils.join(ageErrorList, "\\\n");
//         errorBuilder.append("用户:[" + errorAccount + "]导入失败!身份证号码不正确,请核对!");
//      }
//      if (!securityInvalidStatus.get()){
//         String errorAccount = StringUtils.join(securityInvalidList, "\\\n");
//         errorBuilder.append("用户:[" + errorAccount + "]保安证编号不匹配,请核实!");
////         errorBuilder.append("用户:[" + errorAccount + "]保安证编号不匹配,请核实!也可通过提供保安证件信息提交核实申请!");
//      }
//      //抛出异常
//      if (errorBuilder.length()>0){
//         throw new ServiceException(errorBuilder.toString());
//      }
   }
@@ -2249,7 +2257,7 @@
    * @return
    */
   @Override
   public List<SecurityExcel> exportSecurityInfo(UserVO user) {
   public List<ExportSecurityExcel> exportSecurityInfo(UserVO user) {
      return baseMapper.exportSecurityInfo(user);
   }