智慧保安后台管理-外网项目备份
Administrator
2021-12-25 497df0adf57c8a076596fa763cdbe5a554b96b5b
src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
@@ -42,6 +42,7 @@
import org.springblade.core.tool.utils.*;
import org.springblade.modules.FTP.FtpUtil;
import org.springblade.modules.auth.enums.UserEnum;
import org.springblade.modules.dispatcher.entity.Dispatcher;
import org.springblade.modules.dispatcher.vo.DispatcherVO;
import org.springblade.modules.experience.entity.Experience;
import org.springblade.modules.experience.service.IExperienceService;
@@ -800,16 +801,22 @@
    */
   @Override
   public void importSecurity(List<SecurityExcel> data, Boolean isCovered, String deptId) {
      long time = System.currentTimeMillis();
      //将不能导入的保安员账号存起来
      List<String> errorList = new ArrayList<>();
      //年龄不符的保安员信息存入集合
      List<String> ageErrorList = new ArrayList<>();
      //将需要更新的保安员信息存入集合
      List<User> updateList = new ArrayList<>();
      //需要新增的保安员集合
      List<User> userList = new ArrayList<>();
      //需要新增的从业记录集合
      List<Experience> experienceList = new ArrayList<>();
      //导入状态,默认为true ,如果有一个出现问题则为 false
      AtomicBoolean status = new AtomicBoolean(true);
      AtomicBoolean agetStatus = new AtomicBoolean(true);
      data.forEach(userExcel -> {
      //遍历
      for (SecurityExcel userExcel : data) {
         User user = Objects.requireNonNull(BeanUtil.copy(userExcel, User.class));
         //设置部门id
         String deptIds = userDeptService.selectIn(user.getDeptId());
@@ -845,7 +852,8 @@
               ageErrorList.add(user.getCardid());
//               throw new ServiceException("导入失败!身份证号码[ "+user.getCardid()+" ]不正确,请核对!");
               //forEach 只能使用 return 跳出本次循环
               return;
//               return;
               continue;
            }
         }
         //判断当前用户是否已在本单位,如果是的更新数据
@@ -872,100 +880,53 @@
            }
            //判断年龄,超过60岁的不入
//            if (AgeUtil.idCardToAge(user.getCardid())<60) {
               //分配保安角色
               Role role = new Role();
               role.setRoleAlias("保安");
               Role oneRole = roleService.getOne(Condition.getQueryWrapper(role));
               user.setRoleId(oneRole.getId().toString());
            //分配保安角色
            Role role = new Role();
            role.setRoleAlias("保安");
            Role oneRole = roleService.getOne(Condition.getQueryWrapper(role));
            user.setRoleId(oneRole.getId().toString());
               //性别
               if (null != userExcel.getSex()) {
                  if (userExcel.getSex().equals("男")) {
                     user.setSex(1);
                  }
                  if (userExcel.getSex().equals("女")) {
                     user.setSex(2);
                  }
            //性别
            if (null != userExcel.getSex()) {
               if (userExcel.getSex().equals("男")) {
                  user.setSex(1);
               }
               //设置账号
               user.setAccount(user.getCardid());
               //获取默认密码配置
               user.setPassword(user.getCardid().substring(user.getCardid().length() - 6));
               //加密
               if (Func.isNotEmpty(user.getPassword())) {
                  user.setPassword(DigestUtil.encrypt(user.getPassword()));
               if (userExcel.getSex().equals("女")) {
                  user.setSex(2);
               }
               Integer userCount = baseMapper.selectCountAccount(user.getAccount());
               if (userCount > 0 && Func.isEmpty(user.getId())) {
                  throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount()));
               }
               user.setCreateTime(new Date());
               //新增
               this.save(user);
            }
            //设置账号
            user.setAccount(user.getCardid());
            //获取默认密码配置
            user.setPassword(user.getCardid().substring(user.getCardid().length() - 6));
            //加密
            if (Func.isNotEmpty(user.getPassword())) {
               user.setPassword(DigestUtil.encrypt(user.getPassword()));
            }
            Integer userCount = baseMapper.selectCountAccount(user.getAccount());
            if (userCount > 0 && Func.isEmpty(user.getId())) {
               throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount()));
            }
            user.setCreateTime(new Date());
            user.setDispatch("1");
            user.setExaminationType("0");
            //新增
//            this.save(user);
            //加入集合
            userList.add(user);
            //从业记录新增
            Experience experience = new Experience();
            experience.setCardid(user.getCardid());
//            experience.setSecurityid(user.getId().toString());
            experience.setCompanyname(userExcel.getDeptId());
            experience.setName(user.getRealName());
            experience.setPost("保安员");
            experience.setEntrytime(new Date());
//            experienceService.save(experience);
            //加入集合
            experienceList.add(experience);
               //从业记录新增
               Experience experience = new Experience();
               experience.setCardid(user.getCardid());
               experience.setSecurityid(user.getId().toString());
               experience.setCompanyname(userExcel.getDeptId());
               experience.setName(user.getRealName());
               experience.setPost("保安员");
               experience.setEntrytime(new Date());
               experienceService.save(experience);
               //内网同步
               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," +
                  "politicaloutlook,healstats,height,address,registered," +
                  "securitynumber,hold,jurisdiction,examination_type,status,is_deleted,dispatch,create_time) " +
                  "values(" + "'" + user.getId() + "'" +
                  "," + "'" + user.getTenantId() + "'" +
                  "," + "'" + user.getAccount() + "'" +
                  "," + "'" + user.getPassword() + "'" +
                  "," + "'" + user.getName() + "'" +
                  "," + "'" + user.getRealName() + "'" +
                  "," + "'" + user.getAvatar() + "'" +
                  "," + "'" + user.getEmail() + "'" +
                  "," + "'" + user.getPhone() + "'" +
                  "," + "'" + user.getSex() + "'" +
                  "," + "'" + user.getRoleId() + "'" +
                  "," + "'" + user.getDeptId() + "'" +
                  "," + "'" + user.getCardid() + "'" +
                  "," + "'" + user.getNativeplace() + "'" +
                  "," + "'" + user.getNation() + "'" +
                  "," + "'" + user.getFingerprint() + "'" +
                  "," + "'" + user.getEducation() + "'" +
                  "," + "'" + user.getPoliticaloutlook() + "'" +
                  "," + "'" + user.getHealstats() + "'" +
                  "," + "'" + user.getHeight() + "'" +
                  "," + "'" + user.getAddress() + "'" +
                  "," + "'" + user.getRegistered() + "'" +
                  "," + "'" + user.getSecuritynumber() + "'" +
                  "," + "'" + user.getHold() + "'" +
                  "," + "'" + user.getJurisdiction() + "'" +
                  "," + "'" + user.getExaminationType() + "'" +
                  "," + "'" + user.getStatus() + "'" +
                  "," + "'" + user.getIsDeleted() + "'" +
                  "," + "'" + user.getDispatch() + "'" +
                  "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getCreateTime()) + "'" + ");"+
               "insert into sys_experience(id,name,post,entryTime," +
                  "cardId,companyname,securityId) " +
                  "values(" + "'" + experience.getId() + "'" + "," +
                  "'" + experience.getName() + "'" + "," +
                  "'" + experience.getPost() + "'" + "," +
                  "," + "'" + new SimpleDateFormat("yyyy-MM-dd").format(experience.getEntrytime()) + "'" +
                  "," + "'" + experience.getCardid() + "'" +
                  "," + "'" + experience.getCompanyname() + "'" +
                  "," + "'" + experience.getSecurityid() + "'"
                  + ")";
               FtpUtil.sqlFileUpload(s);
//            }else {
//               agetStatus.set(false);
//               ageErrorList.add(user.getCardid());
//            }
         }else {
            //匹配组织机构是否一致,如果不一致
            if(!user2.getDeptId().equals(user.getDeptId())){
@@ -1006,7 +967,8 @@
                  //加入集合
                  errorList.add(user.getCardid());
                  //forEach 只能使用 return 跳出本次循环
                  return;
//                  return;
                  continue;
               }
            }else {
               //如果是一致,则更新用户数据
@@ -1038,7 +1000,102 @@
               FtpUtil.sqlFileUpload(s1);
            }
         }
      });
      }
      //批量插入
      //用户批量插入
      if (userList.size()>0) {
         baseMapper.batchUserList(userList);
         //sql 拼接
         StringBuilder builder = new StringBuilder();
         StringBuilder builder1 = new StringBuilder();
         //遍历
         for (User user : userList) {
            //内网同步,sql 拼接
            String sql = "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," +
               "politicaloutlook,healstats,height,address,registered," +
               "securitynumber,hold,jurisdiction,examination_type,status,is_deleted,dispatch,create_time) " +
               "values(" + "'" + user.getId() + "'" +
               "," + "'" + user.getTenantId() + "'" +
               "," + "'" + user.getAccount() + "'" +
               "," + "'" + user.getPassword() + "'" +
               "," + "'" + user.getName() + "'" +
               "," + "'" + user.getRealName() + "'" +
               "," + "'" + user.getAvatar() + "'" +
               "," + "'" + user.getEmail() + "'" +
               "," + "'" + user.getPhone() + "'" +
               "," + "'" + user.getSex() + "'" +
               "," + "'" + user.getRoleId() + "'" +
               "," + "'" + user.getDeptId() + "'" +
               "," + "'" + user.getCardid() + "'" +
               "," + "'" + user.getNativeplace() + "'" +
               "," + "'" + user.getNation() + "'" +
               "," + "'" + user.getFingerprint() + "'" +
               "," + "'" + user.getEducation() + "'" +
               "," + "'" + user.getPoliticaloutlook() + "'" +
               "," + "'" + user.getHealstats() + "'" +
               "," + "'" + user.getHeight() + "'" +
               "," + "'" + user.getAddress() + "'" +
               "," + "'" + user.getRegistered() + "'" +
               "," + "'" + user.getSecuritynumber() + "'" +
               "," + "'" + user.getHold() + "'" +
               "," + "'" + user.getJurisdiction() + "'" +
               "," + "'" + user.getExaminationType() + "'" +
               "," + "'" + user.getStatus() + "'" +
               "," + "'" + user.getIsDeleted() + "'" +
               "," + "'" + user.getDispatch() + "'" +
               "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getCreateTime()) + "'" + ")";
            //拼接
            builder  = builder.append(sql).append(";");
            List<String> list = Arrays.asList(builder.toString().split(";"));
            //判断list.size 大小
            if (list.size()==1000){
               //执行
               FtpUtil.sqlFileUpload(builder.toString());
               //清空
               builder.delete(0,builder.length());
            }
         }
         //装换成map
         Map<String, User> userMap = userList.stream().collect(Collectors.toMap(user -> user.getCardid(), user -> user));
         //匹配
         experienceList = experienceList.stream().map(experience -> {
            if (experience.getCardid().equals(userMap.get(experience.getCardid()).getCardid())) {
               experience.setSecurityid(userMap.get(experience.getCardid()).getId().toString());
            }
            return experience;
         }).collect(Collectors.toList());
         //批量插入从业记录
         baseMapper.batchExperienceList(experienceList);
         //遍历,拼接sql ,同步数据到内网
         for (Experience experience : experienceList) {
            String sql1  = "insert into sys_experience(id,name,post,entryTime,cardId,companyname,securityId) " +
               "values(" + "'" + experience.getId() + "'" + "," +
               "'" + experience.getName() + "'" + "," +
               "'" + experience.getPost() + "'" + "," +
               "," + "'" + new SimpleDateFormat("yyyy-MM-dd").format(experience.getEntrytime()) + "'" +
               "," + "'" + experience.getCardid() + "'" +
               "," + "'" + experience.getCompanyname() + "'" +
               "," + "'" + experience.getSecurityid() + "'" + ")";
            //拼接
            builder1  = builder1.append(sql1).append(";");
            String[] split1 = builder.toString().split(";");
            //判断list.size 大小
            if (split1.length==1000){
               //执行
               FtpUtil.sqlFileUpload(builder1.toString());
               //清空
               builder1.delete(0,builder1.length());
            }
         }
         //剩余的继续执行
         FtpUtil.sqlFileUpload(builder.toString());
         FtpUtil.sqlFileUpload(builder1.toString());
      }
//      System.out.println("导入时间: = " + (System.currentTimeMillis()-time));
      //如果所有数据导入有一个异常
      if (!status.get() || !agetStatus.get()){
         if (!status.get() && agetStatus.get()) {
@@ -1390,7 +1447,17 @@
    */
   @Override
   public UserVO getUserInfoBySecurityNumber(String securityNumber) {
      return baseMapper.getUserInfoBySecurityNumber(securityNumber);
      UserVO userVO = baseMapper.getUserInfoBySecurityNumber(securityNumber);
      //查询派遣信息
      if (null!=userVO) {
         DispatcherVO dispatcherVO = baseMapper.getUserDispatcherInfo(userVO.getId());
         if (null != dispatcherVO) {
            userVO.setDispatchUnitName(dispatcherVO.getDispatcherCompany());
            userVO.setDispatchStartTime(new SimpleDateFormat("yyyy-MM-dd").format(dispatcherVO.getDispatchertime()));
            userVO.setDispatchEndTime(new SimpleDateFormat("yyyy-MM-dd").format(dispatcherVO.getEndTime()));
         }
      }
      return userVO;
   }