From dacafac0449f8df3ef7637a7ed05fa6270964f16 Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Fri, 29 Apr 2022 16:19:45 +0800
Subject: [PATCH] ftp 修改,新增保安员培训报名校验,新增押运员批量导入校验,批量导入保安员优化

---
 src/main/java/org/springblade/modules/system/controller/UserController.java |  126 ++++++++++++++++++++++++++++++++++++++---
 1 files changed, 115 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/springblade/modules/system/controller/UserController.java b/src/main/java/org/springblade/modules/system/controller/UserController.java
index a683e9a..349c544 100644
--- a/src/main/java/org/springblade/modules/system/controller/UserController.java
+++ b/src/main/java/org/springblade/modules/system/controller/UserController.java
@@ -58,6 +58,8 @@
 import org.springblade.core.tool.support.Kv;
 import org.springblade.core.tool.utils.*;
 import org.springblade.modules.FTP.FtpUtil;
+import org.springblade.modules.FTP.Monitor;
+import org.springblade.modules.FTP.Result;
 import org.springblade.modules.accreditation.entity.AccreditationRecords;
 import org.springblade.modules.accreditation.service.AccreditationRecordsService;
 import org.springblade.modules.dispatcher.entity.Dispatcher;
@@ -86,6 +88,7 @@
 import org.springblade.modules.system.wrapper.UserWrapper;
 import org.springblade.modules.training.entity.TrainingRegistration;
 import org.springblade.modules.training.service.TrainingRegistrationService;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
@@ -142,6 +145,8 @@
 	private final SecurityPaperService securityPaperService;
 
 	private final MyAsyncService myAsyncService;
+
+	private final RedisTemplate redisTemplate;
 
 	/**
 	 * 查询单条
@@ -658,7 +663,7 @@
 			}
 		}
 		//填写你文件上传的地址以及相应信息
-		String url = "http://223.82.109.183:2081";
+		String url = "http://61.131.136.25:2081";
 		String access = "zhbaadmin";
 		String secret = "zhbapassword";
 		String bucket = "zhba";
@@ -691,7 +696,7 @@
 		FtpUtil.uploadFile(FtpConfig.ftpHost, ftpPort, FtpConfig.ftpUserName, ftpPassword, ftpPath, "/", split[2], inputStream);
 		in.close();
 		//外围url
-		String urls = "http://223.82.109.183:2081/zhba/" + newName;
+		String urls = "http://61.131.136.25:2081/zhba/" + newName;
 		//内网
 		String inUrl = FtpConfig.ip + "/zhba/" + newName;
 		//返回
@@ -1128,6 +1133,7 @@
 	@GetMapping("/security-apply-tree")
 	public R<List<TreeNode>> securityApplyTree(UserVO user) {
 		List<TreeNode> tree = userService.getSecurityApplyTree(user);
+		System.out.println("tree = " + tree);
 		return R.data(tree);
 	}
 
@@ -1178,6 +1184,7 @@
 		user.setDispatch("1");
 		user.setExaminationType("0");
 		user.setAccount(user.getCardid());
+		user.setStatus(1);
 
 		User user1 = new User();
 		user1.setIsDeleted(0);
@@ -1283,13 +1290,6 @@
 		experience.setPost("保安员");
 		experienceService.save(experience);
 
-
-		//发证日期处理
-//		if (user.getPaperTime() == null) {
-//			paperTime = "";
-//		} else {
-//			paperTime = new SimpleDateFormat("yyyy-MM-dd").format(user.getPaperTime());
-//		}
 		//头像
 		if (null != user.getAvatar() && !user.getAvatar().equals("")) {
 			user.setAvatar(FtpConfig.ip + user.getAvatar().substring(26));
@@ -1374,6 +1374,112 @@
 	}
 
 	/**
+	 * 保安员新增(外网不能存敏感数据)
+	 * @since 2022-04-26
+	 * @param userMap
+	 */
+	@PostMapping("/securitySaves")
+	@Transactional(rollbackFor = Exception.class)
+	public R securitySaves(@Valid @RequestBody Map<String, Object> userMap) throws Exception {
+		//获取user
+		User user = JSON.parseObject(JSON.toJSONString(userMap.get("user")), User.class);
+
+		//分配保安角色
+		Role role = new Role();
+		role.setRoleAlias("保安");
+		Role oneRole = roleService.getOne(Condition.getQueryWrapper(role));
+		user.setRoleId(oneRole.getId().toString());
+		user.setDispatch("1");
+		//待审查
+		user.setExaminationType("2");
+		user.setAccount(user.getRealName());
+		user.setStatus(1);
+
+		//密码加密
+		if (Func.isNotEmpty(user.getCardid())) {
+			//取身份证号码后6位作为密码
+			user.setPassword(DigestUtil.encrypt(user.getCardid().substring(user.getCardid().length() - 6)));
+		}
+		user.setCreateTime(new Date());
+		user.setTenantId("000000");
+		//用户新增
+//		boolean status = userService.save(user);
+
+
+		User user1 = user;
+		//头像
+		if (null != user.getAvatar() && !user.getAvatar().equals("")) {
+			user1.setAvatar(FtpConfig.ip + user.getAvatar().substring(26));
+		}
+		//指纹
+		String url = "";
+		if (null != user.getFingerprint() && !user.getFingerprint().equals("")) {
+			if (user.getFingerprint().length() > 100) {
+				String s = uploadBase64String(user);
+				String[] split = s.split(",");
+				user.setFingerprint(split[0]);
+				url = split[1];
+				user1.setFingerprint(url);
+			}
+		}
+
+		//生成随机数
+		String uuid = UUID.randomUUID().toString();
+		//将 user 存入 redis
+		redisTemplate.opsForValue().set(uuid,JSON.toJSONString(user));
+		//user1 临时设置uuid 到 reason_for_leav 离职原因字段
+		user1.setReasonForLeav(uuid);
+
+		//数据推送
+		Map<String, Object> map = new HashMap<>(1);
+		map.put("user",user1);
+		myAsyncService.FTPObject(map);
+
+		int count = 0;
+		int flag = 1;
+		Result result = new Result();
+		//调用ftp获取返回数据
+		while (true){
+			Thread.sleep(1000);
+			//调用ftp获取返回数据
+			result = Monitor.isFTPFileExist(uuid);
+			//如果返回true,就退处
+			if (result.getCode()==200){
+				flag = 1;
+				break;
+			}else if (result.getCode()==201){
+				flag = 2;
+				break;
+			}else if (result.getCode()==202){
+				flag = 3;
+				break;
+			}else if (result.getCode()==203){
+				flag = 4;
+				break;
+			}else{
+				//计数
+				count++;
+				//如果超过10s 没有读取到,则退出
+				if (count == 10) {
+					break;
+				}
+			}
+		}
+		if (flag==1 || flag==2) {
+			//返回
+			return R.data(200, null, "新增成功!");
+		}else if (flag==3){
+			throw new ServiceException(result.getMsg());
+		}else if (flag==4){
+//			return R.data(201, null, "保安证编号不匹配,请核实!也可通过提供保安证件信息提交核实申请!");
+			return R.data(201, null, "保安证编号不匹配,请核实!");
+		}else{
+			//返回
+			return R.data(400, null, "新增失败!");
+		}
+	}
+
+	/**
 	 * 修改派遣记录,修改从业记录
 	 *
 	 * @param user
@@ -1448,7 +1554,6 @@
 				"," + "'" + experience.getCompanyname() + "'" +
 				"," + "'" + experience.getSecurityid() + "'"
 				+ ")";
-			//FtpUtil.sqlFileUpload(s);
 			myAsyncService.FTP(s);
 		}
 	}
@@ -1491,7 +1596,6 @@
 		if (null != user1.getFingerprint() && !user1.getFingerprint().equals("")) {
 			//url 转base64
 			String base64Url = ImageUtils.imageUrlToBase64(user1.getFingerprint());
-			System.out.println("base64Url = " + base64Url);
 			user1.setFingerprint(base64Url);
 		}
 		return R.data(user1);

--
Gitblit v1.9.3