|
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.exam.entity.ExamScore;
|
import org.springblade.modules.securitypaper.entity.SecurityPaper;
|
import org.springblade.modules.securitypaper.excel.PaperExcel;
|
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.*;
|
|
/**
|
* 保安员证管理服务实现类
|
* @author zhongrj
|
* @since 2021-12-25
|
*/
|
@Service
|
@AllArgsConstructor
|
public class SecurityPaperServiceImpl extends ServiceImpl<SecurityPaperMapper, SecurityPaper> implements SecurityPaperService {
|
|
private final MyAsyncService myAsyncService;
|
|
private final IUserDeptService userDeptService;
|
|
private final RedisTemplate redisTemplate;
|
|
// /**
|
// * 导入保安员证数据
|
// * @param data
|
// * @param isCovered
|
// * @param deptId
|
// */
|
// @Override
|
// public void importSecurityPaper(List<SecurityPaperExcel> data, Boolean isCovered, String deptId) {
|
// //需要推送内网的保安员信息集合
|
// 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());
|
// }
|
//
|
// }
|
//
|
|
/**
|
* 导入保安员证数据
|
* @param data
|
* @param isCovered
|
* @param deptId
|
*/
|
@Override
|
public void importSecurityPaper(List<SecurityPaperExcel> data, Boolean isCovered, String deptId) {
|
if (data.size()>0){
|
for (SecurityPaperExcel securityPaperExcel : data) {
|
//去内网生成保安证编号,由内网生成,无需返回
|
//数据推送
|
Map<String, Object> map = new HashMap<>(1);
|
ExamScore examScore = new ExamScore();
|
examScore.setUserId(securityPaperExcel.getId());
|
examScore.setExamId("0");
|
examScore.setApplyId(0L);
|
map.put("key",examScore);
|
myAsyncService.FTPSecurityNumberBit(map);
|
}
|
}
|
}
|
|
/**
|
* 批量导入证件数据
|
* @param data
|
* @param isCovered
|
*/
|
@Override
|
public void importPaper(List<PaperExcel> data, Boolean isCovered) {
|
if (data.size()>0){
|
for (PaperExcel paperExcel : data) {
|
//设置信息
|
String sql = "insert into sys_security_paper(number,create_time,people_name,id_card_no,source) " +
|
"values(" + "'" + paperExcel.getNumber() + "'" + "," +
|
"'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "'" + "," +
|
"'" + paperExcel.getRealName() + "'" + "," +
|
"'" + paperExcel.getCardid() + "'" + ",3)";
|
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "保安员证编号导入sql = " + sql);
|
//数据推送
|
myAsyncService.FTP(sql);
|
}
|
}
|
}
|
}
|