From 30701db6feddef40a7306b93f1571baaa5d0aeaa Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Wed, 15 Jun 2022 10:34:46 +0800
Subject: [PATCH] 保安员人员导入修改

---
 src/main/java/org/springblade/modules/FTP/FtpUtil.java                                         |   18 +
 src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java                 |   74 +------
 src/main/java/org/springblade/modules/system/service/MyAsyncService.java                       |    8 
 src/main/java/org/springblade/modules/securitypaper/service/impl/SecurityPaperServiceImpl.java |  139 ++++++++++++-
 src/main/java/org/springblade/modules/securitypaper/excel/SecurityPaperExcel.java              |   16 -
 src/main/java/org/springblade/common/utils/IdCardNoUtil.java                                   |   21 ++
 src/main/java/org/springblade/modules/quartz/task/Task.java                                    |  268 +++++++++++++++-----------
 7 files changed, 339 insertions(+), 205 deletions(-)

diff --git a/src/main/java/org/springblade/common/utils/IdCardNoUtil.java b/src/main/java/org/springblade/common/utils/IdCardNoUtil.java
index be8a13e..7adf70d 100644
--- a/src/main/java/org/springblade/common/utils/IdCardNoUtil.java
+++ b/src/main/java/org/springblade/common/utils/IdCardNoUtil.java
@@ -99,6 +99,27 @@
 
 
 	/**
+	 *  根据身份证号判断用户性别
+	 * @param cardNo
+	 * @return
+	 */
+	public static String getSex(String cardNo) {
+		String sexStr = "0";
+		if (cardNo.length() == 15) {
+			sexStr = cardNo.substring(14, 15);
+		} else if (cardNo.length() == 18) {
+			sexStr = cardNo.substring(16,17);
+		}
+		int sexNo = Integer.parseInt(sexStr);
+		return sexNo % 2 == 0 ? "女" : "男";
+	}
+
+	public static void main(String[] args) {
+		System.out.println(getSex("530121198903119551"));
+	}
+
+
+	/**
 	 * 根据身份证号码的前17位计算校验码
 	 * @param idNum
 	 * @return
diff --git a/src/main/java/org/springblade/modules/FTP/FtpUtil.java b/src/main/java/org/springblade/modules/FTP/FtpUtil.java
index 4f90cd8..04a7bba 100644
--- a/src/main/java/org/springblade/modules/FTP/FtpUtil.java
+++ b/src/main/java/org/springblade/modules/FTP/FtpUtil.java
@@ -437,4 +437,22 @@
 		FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/",  "e"+response1+".json", in1);
 		MysqlCenlint.deletess("e"+response1+".json");
     }
+
+	/**
+	 * 管理员导入保安人员并创建保安证编号
+	 * @param map
+	 */
+    public static void getSecurityPaperAndUserImport(Map<String, Object> map) {
+		String json = JSON.toJSONString(map);
+		String response = String.valueOf((new Date()).getTime());
+		OutJson.createJsonFile(json, localPath, "p"+response);
+		FileInputStream in = null;
+		try {
+			in = new FileInputStream(new File(localPath + "p"+response+".json"));
+		} catch (FileNotFoundException e) {
+			e.printStackTrace();
+		}
+		FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/",  "p"+response+".json", in);
+		MysqlCenlint.deletess("p"+response+".json");
+    }
 }
diff --git a/src/main/java/org/springblade/modules/quartz/task/Task.java b/src/main/java/org/springblade/modules/quartz/task/Task.java
index ae3bdd8..62a5861 100644
--- a/src/main/java/org/springblade/modules/quartz/task/Task.java
+++ b/src/main/java/org/springblade/modules/quartz/task/Task.java
@@ -414,6 +414,103 @@
 		return false;
 	}
 
+
+	/**
+	 * 读取内外推送的管理员导入的保安员返回文件(带保安证编号)
+	 * @return
+	 */
+	public boolean readPaperListFile() {
+		FTPClient ftp = new FTPClient();
+		try {
+			//设置传输超时时间为60秒
+			ftp.setDataTimeout(10000);
+			//连接超时为60秒
+			ftp.setConnectTimeout(10000);
+			//连接
+			ftp.connect(ftpHost, ftpPort);
+			System.out.println("定时任务:读取内外推送的管理员导入的保安员返回文件(带保安证编号)!"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+			// 登陆
+			ftp.login(ftpUserNameIn, ftpPasswordIn);
+			// 检验登陆操作的返回码是否正确
+			if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
+				ftp.disconnect();
+				return false;
+			}
+
+			// 设置文件类型为二进制,与ASCII有区别
+			ftp.setFileType(FTP.BINARY_FILE_TYPE);
+
+			// 设置编码格式
+			ftp.setControlEncoding("GBK");
+
+			// 检验文件是否存在
+			ftp.changeWorkingDirectory(ftpPath);
+
+			// Use passive mode as default
+			ftp.enterLocalPassiveMode();
+
+			FTPFile[] files = ftp.listFiles();
+			//文件处理
+			if (files.length==0){
+				return false;
+			}
+			else {
+				for (int i = files.length-1; i >=0 ; i--) {
+					String fileName = files[i].getName();
+					String substring = fileName.substring(0, 2);
+					System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+":读取到文件 = " + fileName);
+					if (substring.contains("np")) {
+						//把文件下载到本地
+						long l = System.currentTimeMillis();
+						FtpUtil.downloadFtpFile(ftpHost, ftpUserNameIn, ftpPasswordIn, ftpPort, ftpPath, localPath, fileName);
+						long x = System.currentTimeMillis();
+						System.out.println("下载文件耗时 = " + (x-l)+" 毫秒");
+						//数据转换
+						String json = OutJson.TestJson(fileName);
+						//取出map
+						Map<String,Object> map = JSON.parseObject(json, Map.class);
+						Result result = new Result();
+						for (Map.Entry entry : map.entrySet()) {
+							Object value = entry.getValue();
+							//转换
+							result = JSON.parseObject(value.toString(), Result.class);
+						}
+						if (null!=result) {
+							try {
+								paperListInfoHandler(result);
+							}catch (Exception e) {
+								//异步用户处理逻辑
+								e.printStackTrace();
+							}
+						}
+						//删除本地文件
+						MysqlCenlint.deletess(fileName);
+						//删除 ftp 文件
+						FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserNameIn, ftpPasswordIn, ftpPath, fileName);
+						System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+":成功删除ftp文件 = " + fileName);
+					}
+				}
+			}
+		} catch (Exception e) {
+			System.out.println("ftp连接失败");
+			e.printStackTrace();
+		} finally {
+			if (ftp.isConnected()) {
+				try {
+					ftp.logout();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+				try {
+					ftp.disconnect();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+		}
+		return false;
+	}
+
 	/**
 	 * 用户集合信息处理
 	 * @param result
@@ -504,6 +601,62 @@
 					handlerLog.setDeptId(user.getDeptId());
 					handlerLog.setOperatorTime(user.getCreateTime());
 					handlerLog.setRemark("用户["+DesensitizedUtil.desensitizedIdNumberBy4(user0.getCardid())+"]保安证编号不匹配,请核实!");
+					handlerLog.setType(2);
+					//插入记录
+					handlerLogService.save(handlerLog);
+				}
+			}
+		}
+	}
+
+	/**
+	 * 管理员导入用户集合信息处理
+	 * @param result
+	 */
+	@Async
+	public void paperListInfoHandler(Result result) {
+		//获取 result
+		List<Result> data1 = result.getData();
+		System.out.println("批量导入数据 = " + data1);
+		if (data1.size()>0){
+			for (Result result1 : data1) {
+				// 取出 Msg ,此 msg 存的对应的 uuid
+				String[] split = result1.getMsg().split(",");
+				String uuid = split[0];
+				//从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());
+					user.setSecuritynumber(split[1]);
+					user.setHold("1");
+					user.setExaminationType("0");
+					boolean save = userService.save(user);
+					if (save){
+						//数据异步同步到群防群控
+						myAsyncService.qfqkUserSave(user);
+					}
+				}
+				if (result1.getCode()==202){
+					//已在其他单位存在
+					HandlerLog handlerLog = new HandlerLog();
+					handlerLog.setCreateTime(new Date());
+					handlerLog.setDeptId(user.getDeptId());
+					handlerLog.setOperatorTime(user.getCreateTime());
+					handlerLog.setRemark("用户["+DesensitizedUtil.desensitizedIdNumberBy4(user0.getCardid())+"]已在其他单位存在");
+					handlerLog.setType(2);
+					//插入记录
+					handlerLogService.save(handlerLog);
+				}
+				if (result1.getCode()==205){
+					//审查异常
+					HandlerLog handlerLog = new HandlerLog();
+					handlerLog.setCreateTime(new Date());
+					handlerLog.setDeptId(user.getDeptId());
+					handlerLog.setOperatorTime(user.getCreateTime());
+					handlerLog.setRemark("用户["+DesensitizedUtil.desensitizedIdNumberBy4(user0.getCardid())+"]导入失败,该人员审查异常!");
 					handlerLog.setType(2);
 					//插入记录
 					handlerLogService.save(handlerLog);
@@ -611,121 +764,6 @@
 		}
 		return false;
 	}
-
-//	/**
-//	 * 读取内外推送的实操成绩导入情况信息
-//	 * @return
-//	 */
-//	public boolean readExamScoreFile() {
-//		FTPClient ftp = new FTPClient();
-//		try {
-//			//设置传输超时时间为60秒
-//			ftp.setDataTimeout(10000);
-//			//连接超时为60秒
-//			ftp.setConnectTimeout(10000);
-//			//连接
-//			ftp.connect(ftpHost, ftpPort);
-//			System.out.println("读取内外推送的实操成绩导入情况信息!"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
-//			// 登陆
-//			ftp.login(ftpUserNameIn, ftpPasswordIn);
-//			// 检验登陆操作的返回码是否正确
-//			if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
-//				ftp.disconnect();
-//				return false;
-//			}
-//
-////			ftp.enterLocalActiveMode();
-//
-//			// 设置文件类型为二进制,与ASCII有区别
-//			ftp.setFileType(FTP.BINARY_FILE_TYPE);
-//
-//			// 设置编码格式
-//			ftp.setControlEncoding("GBK");
-//
-//			// 检验文件是否存在
-////			ftp.changeWorkingDirectory(ftpPath);
-//
-//			// Use passive mode as default
-//			ftp.enterLocalPassiveMode();
-//
-//			FTPFile[] files = ftp.listFiles();
-//			//文件个数大于10个时开始处理
-//			if (files.length==0){
-////				ftp.logout();
-//				return false;
-//			}
-//			else {
-//				for (int i = files.length-1; i >=0 ; i--) {
-//					String fileName = files[i].getName();
-//					String substring = fileName.substring(0, 2);
-//					System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+":读取到文件 = " + fileName);
-//					if (substring.contains("ne")) {
-//						//把文件下载到本地
-//						long l = System.currentTimeMillis();
-//						FtpUtil.downloadFtpFile(ftpHost, ftpUserNameIn, ftpPasswordIn, ftpPort, ftpPath, localPath, fileName);
-//						long x = System.currentTimeMillis();
-//						System.out.println("下载文件耗时 = " + (x-l)+" 毫秒");
-//						//数据转换
-//						String json = OutJson.TestJson(fileName);
-//						//取出map
-//						Map<String,Object> map = JSON.parseObject(json, Map.class);
-//						//取出 key/uuid,取出结果
-//						String uuid = null;
-//						Result result = new Result();
-//						for (Map.Entry entry : map.entrySet()) {
-//							Object value = entry.getValue();
-//							//转换
-//							result = JSON.parseObject(value.toString(), Result.class);
-//						}
-//						if (null!=result) {
-//							examScoreHandler(result);
-//						}
-//						//删除本地文件
-//						MysqlCenlint.deletess(fileName);
-//						//删除 ftp 文件
-//						FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserNameIn, ftpPasswordIn, ftpPath, fileName);
-//						System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+":成功删除ftp文件 = " + fileName);
-//					}
-//				}
-//				//关闭流
-////				ftp.completePendingCommand();
-////				ftp.logout();
-//			}
-//		} catch (Exception e) {
-//			System.out.println("ftp连接失败");
-//			e.printStackTrace();
-//		} finally {
-//			try {
-//				ftp.logout();
-//			} catch (IOException e) {
-//				e.printStackTrace();
-//			}
-//			if (ftp.isConnected()) {
-//				try {
-//					ftp.disconnect();
-//				} catch (IOException e) {
-//					e.printStackTrace();
-//				}
-//			}
-//		}
-//		return false;
-//	}
-
-//	/**
-//	 * 实操成绩导入修改
-//	 * @param result
-//	 */
-//	private void examScoreHandler(Result result) {
-//		//导入的人员不存在
-//		HandlerLog handlerLog = new HandlerLog();
-//		handlerLog.setCreateTime(new Date());
-//		handlerLog.setDeptId(deptId);
-//		handlerLog.setOperatorTime(new Date());
-//		handlerLog.setType(4);
-//		handlerLog.setRemark(result.getMsg());
-//		//插入记录
-//		handlerLogService.save(handlerLog);
-//	}
 
 	/**
 	 * 报名信息处理
diff --git a/src/main/java/org/springblade/modules/securitypaper/excel/SecurityPaperExcel.java b/src/main/java/org/springblade/modules/securitypaper/excel/SecurityPaperExcel.java
index e65f21a..4225a49 100644
--- a/src/main/java/org/springblade/modules/securitypaper/excel/SecurityPaperExcel.java
+++ b/src/main/java/org/springblade/modules/securitypaper/excel/SecurityPaperExcel.java
@@ -48,28 +48,12 @@
 	@ExcelProperty("联系电话*")
 	private String phone;
 
-	@ExcelProperty("性别*")
-	@ColumnWidth(10)
-	private String sex;
-
 	@ExcelProperty("身份证号*")
 	@ColumnWidth(20)
 	private String cardid;
 
-	@ExcelProperty("民族")
-	@ColumnWidth(10)
-	private String nation;
-
 	@ExcelProperty("身份证住址*")
 	private String registered;
-
-	@ExcelProperty("是否持证*")
-	@ColumnWidth(15)
-	private String hold;
-
-	@ExcelProperty("保安员证编码")
-	@ColumnWidth(20)
-	private String securitynumber;
 
 
 }
diff --git a/src/main/java/org/springblade/modules/securitypaper/service/impl/SecurityPaperServiceImpl.java b/src/main/java/org/springblade/modules/securitypaper/service/impl/SecurityPaperServiceImpl.java
index ee09ba7..e653264 100644
--- a/src/main/java/org/springblade/modules/securitypaper/service/impl/SecurityPaperServiceImpl.java
+++ b/src/main/java/org/springblade/modules/securitypaper/service/impl/SecurityPaperServiceImpl.java
@@ -1,18 +1,27 @@
 
 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.*;
 
 /**
  * 保安员证管理服务实现类
@@ -25,6 +34,10 @@
 
 	private final MyAsyncService myAsyncService;
 
+	private final IUserDeptService userDeptService;
+
+	private final RedisTemplate redisTemplate;
+
 	/**
 	 * 导入保安员证数据
 	 * @param data
@@ -33,15 +46,117 @@
 	 */
 	@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("")) {
+				if (null != deptId && !deptId.equals("")) {
+					//管理员不分单位导入
+					if (!deptId.equals(deptIds)) {
+						if(!deptId.equals("1123598813738675201")) {
+							throw new ServiceException("导入失败!不能导入不是本公司的保安员数据!");
+						}
+					}
+				}
+				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());
+		}
+
 	}
 }
diff --git a/src/main/java/org/springblade/modules/system/service/MyAsyncService.java b/src/main/java/org/springblade/modules/system/service/MyAsyncService.java
index 827c603..8b5b350 100644
--- a/src/main/java/org/springblade/modules/system/service/MyAsyncService.java
+++ b/src/main/java/org/springblade/modules/system/service/MyAsyncService.java
@@ -218,4 +218,12 @@
 	public void FTPObjectExamScore(Map<String, Object> map) {
 		FtpUtil.objectFileUploadExamScore(map);
 	}
+
+	/**
+	 * 管理员导入保安人员并创建保安证编号
+	 * @param map
+	 */
+    public void FTPSecurityPaperAndUserImport(Map<String, Object> map) {
+		FtpUtil.getSecurityPaperAndUserImport(map);
+    }
 }
diff --git a/src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java b/src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
index 413865b..e06ef31 100644
--- a/src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
+++ b/src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
@@ -1246,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));
@@ -1316,9 +1300,6 @@
 			user.setStatus(1);
 			user.setIsDeleted(0);
 			//分配保安角色
-//			Role role = new Role();
-//			role.setRoleAlias("保安");
-//			Role oneRole = roleService.getOne(Condition.getQueryWrapper(role));
 			user.setRoleId("1412226235153731586");
 
 			if (null!=user.getSecuritynumber() && !user.getSecuritynumber().equals("")){
@@ -1328,22 +1309,15 @@
 			}
 
 			//性别
-			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);
 			}
 
 			//设置账号
 			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)));
@@ -1364,10 +1338,8 @@
 			user0.setReasonForLeav(uuid);
 			//加入集合
 			userList.add(user0);
-			uuidList.add(uuid);
 		}
 
-		Result result = new Result();
 		//用户批量插入
 		if (userList.size()>0) {
 			//生成随机数
@@ -1376,28 +1348,6 @@
 			Map<String, Object> map = new HashMap<>(1);
 			map.put(uuid, userList);
 			myAsyncService.FTPObjectList(map);
-
-//			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){
@@ -1469,24 +1419,24 @@
 //		}
 
 //		//如果所有数据导入有一个异常
-//		StringBuilder errorBuilder = new StringBuilder();
+		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 (!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 (errorBuilder.length()>0){
+			throw new ServiceException(errorBuilder.toString());
+		}
 	}
 
 	/**

--
Gitblit v1.9.3