From 2ebca060a47784db76369a4aa84f63293da9be33 Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Thu, 16 Jun 2022 10:08:08 +0800
Subject: [PATCH] 保安员新增同步编号问题

---
 src/main/java/org/springblade/modules/FTP/DataHanlder.java |  403 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 385 insertions(+), 18 deletions(-)

diff --git a/src/main/java/org/springblade/modules/FTP/DataHanlder.java b/src/main/java/org/springblade/modules/FTP/DataHanlder.java
index c366fa7..a3c6fa5 100644
--- a/src/main/java/org/springblade/modules/FTP/DataHanlder.java
+++ b/src/main/java/org/springblade/modules/FTP/DataHanlder.java
@@ -1,13 +1,19 @@
 package org.springblade.modules.FTP;
 
 import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import liquibase.pro.packaged.M;
+import org.json.JSONArray;
+import org.json.JSONObject;
 import org.springblade.common.utils.DesensitizedUtil;
+import org.springblade.common.utils.InvestigateUtil;
+import org.springblade.common.utils.SecurityPaperUtil;
+import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.mp.support.Condition;
-import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.BeanUtil;
 import org.springblade.modules.dispatcher.entity.Dispatcher;
 import org.springblade.modules.dispatcher.service.IDispatcherService;
+import org.springblade.modules.exam.entity.ExamPaper;
+import org.springblade.modules.exam.entity.ExamScore;
+import org.springblade.modules.exam.service.ExamScoreService;
 import org.springblade.modules.experience.entity.Experience;
 import org.springblade.modules.experience.service.IExperienceService;
 import org.springblade.modules.securitypaper.entity.SecurityPaper;
@@ -16,10 +22,12 @@
 import org.springblade.modules.system.entity.User;
 import org.springblade.modules.system.service.IDeptService;
 import org.springblade.modules.system.service.IUserService;
+import org.springblade.modules.system.vo.UserVO;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
-
 import javax.annotation.PostConstruct;
+import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -47,10 +55,13 @@
 	@Autowired
 	private IDeptService iDeptService;
 
+	@Autowired
+	private ExamScoreService examScoreService;
 
 
 
-	/**
+
+    /**
 	 * 初始化
 	 */
 	@PostConstruct
@@ -64,22 +75,77 @@
 		hanlder.iDeptService = this.iDeptService;
 	}
 
+
 	/**
-	 * 获取保安员证编号
+	 * 保安员审查
+	 * @param json
+	 */
+	public static void handlerUserExamine(String json) {
+		User user = JSON.parseObject(json, User.class);
+		//获取用户cardid
+		User user1 = hanlder.userService.getById(user.getId());
+		//用户审查
+		hanlder.myAsyncService.checkUserExamineByCardNo(user1);
+	}
+
+	/**
+	 * 生成保安员证编号
 	 * @param json
 	 */
 	public static void handlerSecurityNumerBit(String json) {
 		Map map = JSON.parseObject(json, Map.class);
 		//取出 key(uuid)
 		String key = map.keySet().toArray()[0].toString();
-		//编号前缀
-		String pre = map.get(key).toString();
-		Integer max = hanlder.userService.getSecurityPaperCount(pre);
-		Result result = new Result(200, null, max.toString(),null);
-		Map<String, Object> map1 = new HashMap<>(1);
-		map1.put(key, result);
-		//向外网发送数据
-		FtpUtil.objectFileUploadSecurityNumberCount(map1);
+		//获取考试信息
+		String value = map.get(key).toString();
+		ExamScore examScore = JSON.parseObject(value, ExamScore.class);
+		//查询用户
+		User user = hanlder.userService.getById(examScore.getUserId());
+		if (null!=user) {
+			//如果已有保安证编号,不更新用户信息
+			if (null == user.getSecuritynumber() || user.getSecuritynumber().equals("")) {
+				//去生成保安证编号
+				String pre = SecurityPaperUtil.getSecurityPaper();
+				//查询当前年份已有的保安证编号
+				int count = hanlder.userService.getSecurityPaperCount(pre);
+				String result = null;
+				if (count == 0) {
+					result = pre + "00001";
+				} else {
+					//格式化
+					DecimalFormat decimalFormat = new DecimalFormat("00000");
+					count++;
+					result = pre + (decimalFormat.format(count));
+				}
+				user.setSecuritynumber(result);
+				//修改为持证保安
+				user.setHold("1");
+				user.setUpdateTime(new Date());
+				user.setUserType(7);
+				//更新保安数据
+				hanlder.userService.updateById(user);
+
+				//生成保安证的同时向保安证管理表中插入一条数据
+				SecurityPaper securityPaper = new SecurityPaper();
+				securityPaper.setUserId(user.getId());
+				securityPaper.setNumber(result);
+				securityPaper.setCreateTime(new Date());
+				securityPaper.setIdCardNo(user.getCardid());
+				securityPaper.setPeopleName(user.getRealName());
+				securityPaper.setExamId(Long.parseLong(examScore.getExamId()));
+				securityPaper.setApplyId(examScore.getApplyId());
+				securityPaper.setSource(1);
+				hanlder.securityPaperService.save(securityPaper);
+
+				//内网同步
+				String s1 = "update blade_user set hold = " + "'" + user.getHold() + "'" +
+					",securitynumber = " + "'" + DesensitizedUtil.desensitizedSecurityNumber(result) + "'" +
+					",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getUpdateTime()) + "'" +
+					",user_type = " + "'" + user.getUserType() + "'" +
+					" " + "where id = " + "'" + user.getId() + "'";
+				hanlder.myAsyncService.FTP(s1);
+			}
+		}
 	}
 
 	/**
@@ -117,6 +183,133 @@
 			map1.put(key, result);
 			//向外网发送数据
 			FtpUtil.objectFileUploadListTrain(map1);
+		}
+	}
+
+	/**
+	 * 考试实操成绩处理
+	 * @param json
+	 */
+	public static void handlerUserExamScore(String json) {
+		Map map = JSON.parseObject(json, Map.class);
+		//取出 key(uuid)
+		String key = map.keySet().toArray()[0].toString();
+		Object value = map.get(key);
+		//得到考试成绩
+		ExamScore examScore = JSON.parseObject(value.toString(), ExamScore.class);
+		//处理实操考试成绩
+		examScoreHandler(examScore);
+	}
+
+	/**
+	 * 实操成绩处理
+	 * @param examScore0
+	 */
+	private static void examScoreHandler(ExamScore examScore0) {
+		//取第一个
+		List<ExamScore> examScoreList = hanlder.examScoreService.getExamScoreInfoByIdCardNo(examScore0.getCandidateNo(), new SimpleDateFormat("yyyy-MM-dd").format(examScore0.getExamTime()));
+		if (examScoreList.size()>0) {
+			//遍历集合
+			examScoreList.forEach(examScore -> {
+				if (null != examScore) {
+					//查询当前保安信息
+					UserVO user = hanlder.userService.getUserAgeById(Long.parseLong(examScore.getUserId()));
+					//设置实操成绩
+					examScore.setLearnGrade(examScore0.getLearnGrade());
+					if (null != examScore.getTheoryGrade()) {
+						if (examScore.getTheoryGrade() >= 60 && examScore.getLearnGrade() >= 60) {
+							//合格
+							examScore.setQualified(0);
+							//修改制证状态为未制证
+							user.setUserType(7);
+							//如果已有保安证编号,不更新用户信息
+							if (null == user.getSecuritynumber() || user.getSecuritynumber().equals("")) {
+								//去生成保安证编号
+								String pre = SecurityPaperUtil.getSecurityPaper();
+								//查询当前年份已有的保安证编号
+								int count = hanlder.userService.getSecurityPaperCount(pre);
+								String result = null;
+								if (count == 0) {
+									result = pre + "00001";
+								} else {
+									//格式化
+									DecimalFormat decimalFormat = new DecimalFormat("00000");
+									count++;
+									result = pre + (decimalFormat.format(count));
+								}
+								//脱敏处理
+								user.setSecuritynumber(DesensitizedUtil.desensitizedSecurityNumber(result));
+								//修改为持证保安
+								user.setHold("1");
+								user.setUpdateTime(new Date());
+								//更新保安数据
+								hanlder.userService.updateById(user);
+
+								//生成保安证的同时向保安证管理表中插入一条数据
+								SecurityPaper securityPaper = new SecurityPaper();
+								securityPaper.setUserId(user.getId());
+								securityPaper.setNumber(result);
+								securityPaper.setCreateTime(new Date());
+								securityPaper.setIdCardNo(user.getCardid());
+								securityPaper.setPeopleName(user.getRealName());
+								securityPaper.setExamId(Long.parseLong(examScore.getExamId()));
+								securityPaper.setApplyId(examScore.getApplyId());
+								securityPaper.setSource(1);
+								hanlder.securityPaperService.save(securityPaper);
+
+								//内网同步
+								String s1 = "update blade_user set hold = " + "'" + user.getHold() + "'" +
+									",securitynumber = " + "'" + DesensitizedUtil.desensitizedSecurityNumber(result) + "'" +
+									",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getUpdateTime()) + "'" +
+									",user_type = " + "'" + user.getUserType() + "'" +
+									" " + "where id = " + "'" + user.getId() + "'";
+								hanlder.myAsyncService.FTP(s1);
+							}
+						}
+					} else {
+						//不合格
+						examScore.setQualified(1);
+					}
+					//总成绩
+					if (user.getAge() <= 50) {
+						if (null != examScore.getTheoryGrade()) {
+							examScore.setAllGrade(Math.round((examScore.getTheoryGrade() + examScore0.getLearnGrade()) / 2));
+						} else {
+							examScore.setAllGrade(Math.round(examScore0.getLearnGrade() / 2));
+						}
+					}
+					if (user.getAge() > 50) {
+						if (null != examScore.getTheoryGrade()) {
+							examScore.setAllGrade(Integer.parseInt(String.valueOf(Math.round(examScore.getTheoryGrade() * 0.5)))
+								+ Integer.parseInt(String.valueOf(Math.round(examScore0.getLearnGrade() * 0.5))));
+						} else {
+							examScore.setAllGrade(Math.round(examScore0.getLearnGrade() / 2));
+						}
+					}
+
+					//外网同步
+					String s1 =
+						"update exam_score set learn_grade = " + "'" + examScore.getLearnGrade() + "'" +
+							",all_grade = " + "'" + examScore.getAllGrade() + "'" +
+							",qualified = " + "'" + examScore.getQualified() + "'" +
+							" " + "where id = " + "'" + examScore.getId() + "'";
+					hanlder.myAsyncService.FTP(s1);
+					//更新成绩数据
+					hanlder.examScoreService.updateById(examScore);
+				}
+			});
+		}else {
+			//根据身份证号查询用户
+			User user0 = hanlder.userService.getUserInfoByIdCardNo(examScore0.getCandidateNo());
+			if (null == user0) {
+				String msg = "没有找到用户:[" + examScore0.getCandidateNo() + "]相关考试成绩信息,请检查身份证是否有误!";
+				//向外网推送
+				Result result = new Result(200,null,msg);
+				Map<String, Object> map = new HashMap<>(1);
+				map.put("key", result);
+				//向外网发送数据
+				FtpUtil.objectFileUploadExamScore(map);
+			}
 		}
 	}
 
@@ -207,7 +400,171 @@
 	}
 
 	/**
-	 * 数据处理
+	 * 管理人员保安员导入并生成保安证编号
+	 * @param json
+	 */
+	public static void handlerSecurityPaperList(String json) {
+		Map map = JSON.parseObject(json, Map.class);
+		//取出 key(uuid)
+		String key = map.keySet().toArray()[0].toString();
+		Object users = map.get(key);
+		List<User> userList = JSON.parseArray(users.toString(), User.class);
+		//遍历
+		if (userList.size()>0) {
+			List<Result> resultList = new ArrayList<>();
+			//开始遍历
+			for (User user : userList) {
+				//取出 uuid
+				String uuid = user.getReasonForLeav();
+				//用户数据校验,是否已导入(本单位或其他单位)
+				Result result = userCheckOut(user);
+				//创建返回对象
+				Result result1 = new Result();
+				result1.setMsg(uuid);
+				if (result.getCode() == 200) {
+					user.setReasonForLeav("");
+					//直接去审查,审查异常则不新增
+					//异步审查
+					User user1 = hanlder.checkUserExamineByCardNos(user);
+					if (null!=user1){
+						if (user1.getExaminationType().equals("0")){
+							//生成保安证编号和记录
+							//去生成保安证编号
+							String pre = SecurityPaperUtil.getSecurityPaper();
+							//查询当前年份已有的保安证编号
+							int count = hanlder.userService.getSecurityPaperCount(pre);
+							String result0 = null;
+							if (count == 0) {
+								result0 = pre + "00001";
+							} else {
+								//格式化
+								DecimalFormat decimalFormat = new DecimalFormat("00000");
+								count++;
+								result0 = pre + (decimalFormat.format(count));
+							}
+							//修改制证状态为未制证
+							user.setUserType(7);
+							user.setSecuritynumber(result0);
+							//修改为持证保安
+							user.setHold("1");
+							user.setUpdateTime(new Date());
+							//更新保安数据
+							boolean save = hanlder.userService.save(user);
+
+							if (save) {
+								//生成保安证的同时向保安证管理表中插入一条数据
+								SecurityPaper securityPaper = new SecurityPaper();
+								securityPaper.setUserId(user.getId());
+								securityPaper.setNumber(result0);
+								securityPaper.setCreateTime(new Date());
+								securityPaper.setIdCardNo(user.getCardid());
+								securityPaper.setPeopleName(user.getRealName());
+								securityPaper.setSource(3);
+								hanlder.securityPaperService.save(securityPaper);
+
+								//异步新增从业记录
+								hanlder.myAsyncService.insertExperience(user);
+
+								//设置返回结果
+								result1.setCode(200);
+								result1.setUserId(user.getId());
+								result1.setMsg(result1.getMsg()+","+DesensitizedUtil.desensitizedSecurityNumber(result0));
+							}
+						}else {
+							//不新增,审查异常
+							result1.setCode(205);
+							result1.setUserId(null);
+						}
+					}
+				} else if (result.getCode() == 201) {
+				} else {
+					//不新增,不修改
+					//设置返回结果,以在其他单位存在
+					result1.setCode(202);
+					result1.setUserId(null);
+				}
+				//存入结果集
+				resultList.add(result1);
+			}
+			Result result = new Result(200, "", resultList);
+			Map<String, Object> map1 = new HashMap<>(1);
+			map1.put(key, result);
+			//向外网发送数据
+			FtpUtil.objectFileUploadPaperList(map1);
+		}
+	}
+
+
+	/**
+	 * 异步审查新增的保安员,审查通过并生成保安员证编号
+	 * @param user0
+	 */
+	public User checkUserExamineByCardNos(User user0){
+		//如果是保安员
+		if (user0.getRoleId().equals("1412226235153731586")){
+			//创建用户对象
+			User user = new User();
+			user.setId(user0.getId());
+			//远程调用接口
+			String body = InvestigateUtil.httpGetOne(user0.getCardid());
+			JSONObject jsonObject = new JSONObject(body);
+			Object data = jsonObject.get("data");
+			JSONObject jsonData = new JSONObject(data.toString());
+			JSONArray res = jsonData.getJSONArray("res");
+			//设置审核时间
+			user.setAuditTime(new Date());
+			//如果有结果返回
+			if (res.length() == 0) {
+				//没有数据正常
+				user.setExaminationType("0");
+			} else {
+				int count = 0;
+				user.setExaminationType("1");
+				for (int i = 0; i < res.length(); i++) {
+					if (res.getJSONObject(i).get("zdrylbjh").toString() != null
+						&& res.getJSONObject(i).get("zdrylbjh").toString() != ""
+						&& res.getJSONObject(i).get("zdrylbjh").toString() != "null"
+					) {
+						user.setExaminationMx(res.getJSONObject(i).get("zdrylbjh").toString());
+						//更新用户数据
+//						userService.updateById(user);
+						break;
+					}
+					if (res.getJSONObject(i).get("zdryxlmc").toString() != null
+						&& res.getJSONObject(i).get("zdryxlmc").toString() != ""
+						&& res.getJSONObject(i).get("zdryxlmc").toString() != "null"
+					) {
+						user.setExaminationMx(res.getJSONObject(i).get("zdryxlmc").toString());
+						//更新用户数据
+//						userService.updateById(user);
+						break;
+					}
+					if (res.getJSONObject(i).get("ztrylx").toString() != null
+						&& res.getJSONObject(i).get("ztrylx").toString() != ""
+						&& res.getJSONObject(i).get("ztrylx").toString() != "null"
+					) {
+						user.setExaminationMx(res.getJSONObject(i).get("ztrylx").toString());
+						//更新用户数据
+//						userService.updateById(user);
+						break;
+					}
+					count++;
+					//条件中的数据都为空,则审查为正常
+					if (count==res.length()){
+						//更新用户数据,设为正常
+						user.setExaminationType("0");
+//						userService.updateById(user);
+					}
+				}
+			}
+			//更新用户数据
+			return user;
+		}
+		return null;
+	}
+
+	/**
+	 * 数据处理(单个保安员新增)
 	 * @param json
 	 */
 	public static void handler(String json){
@@ -218,6 +575,8 @@
 			Map map = JSON.parseObject(s, Map.class);
 			Object user = map.get("user");
 			User user1 = JSON.parseObject(user.toString(), User.class);
+			System.out.println("user1 = " + user1);
+
 			//获取 uuid
 			String uuid = user1.getReasonForLeav();
 			//用户数据校验
@@ -283,8 +642,9 @@
 			}
 			Map<String, Object> map1 = new HashMap<>(1);
 			map1.put(uuid,result1);
+			System.out.println("用户新增:开始向外网推送数据............");
 			//向外网发送数据
-			FtpUtil.objectFileUpload(map1);
+			FtpUtil.objectFileUpload(map1,uuid);
 		}
 	}
 
@@ -311,7 +671,7 @@
 						one.setUpdateTime(new Date());
 						//离职
 						hanlder.userService.updateById(one);
-						//内网同步
+						//同步外网
 						String s1 = "update blade_user set status = " + one.getStatus() +
 							",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(one.getUpdateTime()) + "'" +
 							" where id = " + "'" + one.getId() + "'";
@@ -319,6 +679,8 @@
 
 						//人员离职后修改派遣记录,修改从业记录
 						hanlder.updateUserDispatcherExp(one);
+						//返回
+						return new Result(200,null,"");
 					}
 				}
 				return new Result(400,null,user.getRealName() + "已在其他单位导入");
@@ -418,7 +780,10 @@
 		//2.保安证编号校验
 		//判断是否持证
 		boolean states = false;
-		if (user.getHold().equals("1") && null!=user.getSecuritynumber() && !user.getSecuritynumber().equals("")){
+		if (null!= user.getHold()
+			&& user.getHold().equals("1")
+			&& null!=user.getSecuritynumber()
+			&& !user.getSecuritynumber().equals("")){
 			//持证,校验保安证编号是否合法
 			SecurityPaper securityPaper = new SecurityPaper();
 			securityPaper.setIdCardNo(user.getCardid());
@@ -432,10 +797,12 @@
 				}
 				if (!states){
 					user.setHold("2");
+					user.setSecuritynumber("");
 				}
 			}else {
 				states = false;
 				user.setHold("2");
+				user.setSecuritynumber("");
 			}
 		}else {
 			states = true;

--
Gitblit v1.9.3