| | |
| | | |
| | | package org.springblade.modules.securitypaper.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springblade.common.utils.IdCardNoUtil; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.core.tool.utils.DigestUtil; |
| | | import org.springblade.modules.FTP.Result; |
| | | import org.springblade.modules.securitypaper.entity.SecurityPaper; |
| | | import org.springblade.modules.securitypaper.excel.SecurityPaperExcel; |
| | | import org.springblade.modules.securitypaper.mapper.SecurityPaperMapper; |
| | | import org.springblade.modules.securitypaper.service.SecurityPaperService; |
| | | import org.springblade.modules.system.entity.User; |
| | | import org.springblade.modules.system.service.IUserDeptService; |
| | | import org.springblade.modules.system.service.MyAsyncService; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 保安员证管理服务实现类 |
| | |
| | | |
| | | private final MyAsyncService myAsyncService; |
| | | |
| | | private final IUserDeptService userDeptService; |
| | | |
| | | private final RedisTemplate redisTemplate; |
| | | |
| | | /** |
| | | * 导入保安员证数据 |
| | | * @param data |
| | |
| | | */ |
| | | @Override |
| | | public void importSecurityPaper(List<SecurityPaperExcel> data, Boolean isCovered, String deptId) { |
| | | data.forEach(securityPaperExcel -> { |
| | | String sql = "insert into sys_security_paper(number,create_time,people_name,id_card_no,source) " + |
| | | "values(" + "'" + securityPaperExcel.getSecuritynumber() + "'" + "," + |
| | | "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "'" + "," + |
| | | "," + "'" + securityPaperExcel.getRealName() + "'" + |
| | | "," + "'" + securityPaperExcel.getCardid() + "'" + |
| | | "," + "'" + 3 + "'" |
| | | + ")"; |
| | | myAsyncService.FTP(sql); |
| | | }); |
| | | //需要推送内网的保安员信息集合 |
| | | List<User> userList = new ArrayList<>(); |
| | | //年龄不符的保安员信息存入集合 |
| | | List<String> cardErrorList = new ArrayList<>(); |
| | | boolean flag = false; |
| | | for (SecurityPaperExcel paperExcel : data) { |
| | | User user = Objects.requireNonNull(BeanUtil.copy(paperExcel, User.class)); |
| | | //设置部门id |
| | | String deptIds = userDeptService.selectIn(user.getDeptId()); |
| | | if (null!=deptIds && !deptIds.equals("")) { |
| | | user.setDeptId(deptIds); |
| | | }else { |
| | | //如果deptIds 为空,则说明还没有改公司 |
| | | throw new ServiceException("导入失败!公司名:["+user.getDeptId()+"]不存在!"); |
| | | } |
| | | |
| | | //身份证校验 |
| | | if (null==user.getCardid() || user.getCardid().equals("")){ |
| | | throw new ServiceException("导入失败!身份证号码不能为空!"); |
| | | } |
| | | //身份证住址校验 |
| | | if (null==user.getRegistered() || user.getRegistered().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 { |
| | | flag = true; |
| | | cardErrorList.add(user.getCardid()); |
| | | // throw new ServiceException("导入失败!身份证号码[ "+user.getCardid()+" ]不正确,请核对!"); |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | // 设置租户ID |
| | | user.setTenantId("000000"); |
| | | //默认在职 |
| | | user.setStatus(1); |
| | | user.setIsDeleted(0); |
| | | //分配保安角色 |
| | | user.setRoleId("1412226235153731586"); |
| | | |
| | | //默认设置未持证 |
| | | user.setHold("2"); |
| | | |
| | | //性别 |
| | | if (IdCardNoUtil.getSex(paperExcel.getCardid()).equals("男")) { |
| | | user.setSex(1); |
| | | }else { |
| | | user.setSex(2); |
| | | } |
| | | |
| | | //设置账号 |
| | | 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()); |
| | | user.setUpdateTime(new Date()); |
| | | user.setDispatch("1"); |
| | | //待审查 |
| | | user.setExaminationType("2"); |
| | | |
| | | //推送内网的数据 |
| | | User user0 = Objects.requireNonNull(BeanUtil.copy(user,User.class)); |
| | | |
| | | //生成随机数 |
| | | String uuid = UUID.randomUUID().toString(); |
| | | //将 user 存入 redis |
| | | redisTemplate.opsForValue().set(uuid, JSON.toJSONString(user)); |
| | | //user0 临时设置uuid 到 reason_for_leav 离职原因字段 |
| | | user0.setReasonForLeav(uuid); |
| | | //加入集合 |
| | | userList.add(user0); |
| | | } |
| | | |
| | | //用户批量插入 |
| | | if (userList.size()>0) { |
| | | //生成随机数 |
| | | String uuid = UUID.randomUUID().toString(); |
| | | //数据推送 |
| | | Map<String, Object> map = new HashMap<>(1); |
| | | map.put(uuid, userList); |
| | | myAsyncService.FTPSecurityPaperAndUserImport(map); |
| | | } |
| | | |
| | | //如果所有数据导入有一个异常 |
| | | StringBuilder errorBuilder = new StringBuilder(); |
| | | if (flag){ |
| | | String errorAccount = StringUtils.join(cardErrorList, "\\\n"); |
| | | errorBuilder.append("用户:[" + errorAccount + "]导入失败!身份证号码不正确,请核对!"); |
| | | } |
| | | |
| | | //抛出异常 |
| | | if (errorBuilder.length()>0){ |
| | | throw new ServiceException(errorBuilder.toString()); |
| | | } |
| | | |
| | | } |
| | | } |