From 7a4954210f92a011a10bb98e416cff5d531d348a Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Mon, 22 Nov 2021 20:29:22 +0800
Subject: [PATCH] 新增修改保安员信息接口,保安员导入修改,保安员新增修改,当机度身份证时,可以先将其他单位人员离职,然后再新增

---
 src/main/java/org/springblade/modules/system/controller/UserController.java |  137 +++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 131 insertions(+), 6 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 1ccc519..b8a4132 100644
--- a/src/main/java/org/springblade/modules/system/controller/UserController.java
+++ b/src/main/java/org/springblade/modules/system/controller/UserController.java
@@ -55,6 +55,8 @@
 import org.springblade.core.tool.support.Kv;
 import org.springblade.core.tool.utils.*;
 import org.springblade.modules.FTP.FtpUtil;
+import org.springblade.modules.dispatcher.entity.Dispatcher;
+import org.springblade.modules.dispatcher.service.IDispatcherService;
 import org.springblade.modules.exam.excel.ExportExamScoreExcel;
 import org.springblade.modules.experience.entity.Experience;
 import org.springblade.modules.experience.service.IExperienceService;
@@ -111,6 +113,8 @@
 	private final IExperienceService experienceService;
 
 	private final JurisdictionService jurisdictionService;
+
+	private final IDispatcherService dispatcherService;
 
 	/**
 	 * 查询单条
@@ -289,6 +293,31 @@
 			}
 		}
 
+		//如果是离职
+		if (null!=user.getStatus()){
+			if (user.getStatus()==2){
+				//修改派遣状态
+				user.setDispatch("1");
+				//同时将派遣记录中的派遣状态修改
+				//查询派遣记录(还在派遣中的)
+				Dispatcher dispatcher = new Dispatcher();
+				dispatcher.setUserIds(user.getId().toString());
+				dispatcher.setStatus(0);
+				List<Dispatcher> dispatcherList = dispatcherService.list(Condition.getQueryWrapper(dispatcher));
+				if (dispatcherList.size()>0){
+					dispatcherList.forEach(dispatcher1 -> {
+						dispatcher1.setStatus(1);
+						dispatcher1.setUpdateTime(new Date());
+						String s1 =
+							"update sys_dispatcher set status = " + "'" + dispatcher1.getStatus() + "'"
+								+ ",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dispatcher1.getUpdateTime()) + "'"
+								+ " " + "where id = " + "'" + dispatcher1.getId() + "'";
+						FtpUtil.sqlFileUpload(s1);
+					});
+				}
+			}
+		}
+
 		user.setPassword(user1.getPassword());
 		userService.updateById(user);
 		String rtime;
@@ -320,11 +349,51 @@
 				+ ",address = " + "'" + user.getAddress() + "'"
 				+ ",registered = " + "'" + user.getRegistered() + "'"
 				+ ",rtime = " + "'" + rtime + "'"
+				+ ",dispatch = " + "'" + user.getDispatch() + "'"
 				+ ",securitynumber = " + "'" + user.getSecuritynumber() + "'"
 				+ ",hold = " + "'" + user.getHold() + "'"
 				+ ",jurisdiction = " + "'" + user.getJurisdiction() + "'"
 				+ ",reason_for_leav = " + "'" + user.getReasonForLeav() + "'"
 				+ ",guncode = " + "'" + user.getGuncode() + "'"
+				+ " " + "where id = " + "'" + user.getId() + "'";
+		FtpUtil.sqlFileUpload(s1);
+		return R.success("修改成功");
+	}
+
+
+	/**
+	 * 修改
+	 */
+	@PostMapping("/updateUserInfo")
+	public R updateUserInfo(@Valid @RequestBody User user) throws Exception {
+		String url = null;
+		if (null!=user.getFingerprint() && !user.getFingerprint().equals("")) {
+			if (user.getFingerprint().length()>100) {
+				//指纹图片上传并返回url
+				String s = uploadBase64String(user);
+				String[] split = s.split(",");
+				user.setFingerprint(split[0]);
+				//内网指纹图片url
+				url = split[1];
+			}
+		}
+
+		userService.updateById(user);
+
+		//内网同步
+		String s1 =
+			"update blade_user set account = " + "'" + user.getCardid() + "'"
+				+ ",real_name = " + "'" + user.getRealName() + "'"
+				+ ",avatar = " + "'" + user.getAvatar() + "'"
+				+ ",sex = " + "'" + user.getSex() + "'"
+				+ ",cardid = " + "'" + user.getCardid() + "'"
+				+ ",nation = " + "'" + user.getNation() + "'"
+				+ ",fingerprint = " + "'" + url + "'"
+				+ ",my_picture = " + "'" + user.getMyPicture() + "'"
+				+ ",address = " + "'" + user.getAddress() + "'"
+				+ ",registered = " + "'" + user.getRegistered() + "'"
+				+ ",securitynumber = " + "'" + user.getSecuritynumber() + "'"
+				+ ",hold = " + "'" + user.getHold() + "'"
 				+ " " + "where id = " + "'" + user.getId() + "'";
 		FtpUtil.sqlFileUpload(s1);
 		return R.success("修改成功");
@@ -524,6 +593,18 @@
 	@ApiOperation(value = "导入用户", notes = "传入excel")
 	public R importSecurity(MultipartFile file, Integer isCovered,String deptId) {
 		SecurityImporter securityImporter = new SecurityImporter(userService, false,deptId);
+		ExcelUtil.save(file, securityImporter, SecurityExcel.class);
+		return R.success("操作成功");
+	}
+
+	/**
+	 * 导入保安员(test)
+	 */
+	@PostMapping("import-security-test")
+	@ApiOperationSupport(order = 12)
+	@ApiOperation(value = "导入用户", notes = "传入excel")
+	public R importSecurityTest(MultipartFile file, Integer isCovered,String deptId) {
+		SecurityImporterTest securityImporter = new SecurityImporterTest(userService, false,deptId);
 		ExcelUtil.save(file, securityImporter, SecurityExcel.class);
 		return R.success("操作成功");
 	}
@@ -812,9 +893,29 @@
 		user.setExaminationType("0");
 		user.setAccount(user.getCardid());
 
-		Integer userCount = userService.selectCount(user.getAccount());
-		if (userCount > 0 && Func.isEmpty(user.getId())) {
-			throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount()));
+//		Integer userCount = userService.selectCount(user.getAccount());
+		User user1 = new User();
+		user1.setIsDeleted(0);
+		user1.setStatus(1);
+		user1.setAccount(user.getCardid());
+		List<User> list = userService.list(Condition.getQueryWrapper(user1));
+
+		if (list.size() > 0 && Func.isEmpty(user.getId())) {
+			if (null!=user.getCell() && !user.getCell().equals("")) {
+				if (user.getCell().equals("2")){
+					list.forEach(user2 -> {
+						user2.setStatus(2);
+						//先将原有人员离职  cell 1:手动录入  2:自动录入
+						userService.updateById(user2);
+						//内网同步
+						String s1 = "update blade_user set status = " + user2.getStatus() +
+							" where id = " + "'" + user2.getId() + "'";
+						FtpUtil.sqlFileUpload(s1);
+					});
+				}
+			}else {
+				throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount()));
+			}
 		}
 
 		String url = null;
@@ -867,7 +968,7 @@
 			"id,tenant_id,account,password,name,real_name,avatar,email,phone,sex," +
 			"role_id,dept_id,cardid,nativePlace,nation,fingerprint,education," +
 			"politicaloutlook,healstats,height,address,registered,rtime," +
-			"securitynumber,hold,jurisdiction,examination_type,status,is_deleted,dispatch,guncode) " +
+			"securitynumber,hold,jurisdiction,examination_type,status,is_deleted,dispatch,guncode,cell) " +
 			"values(" + "'" + user.getId() + "'" +
 			"," + "'" + user.getTenantId() + "'" +
 			"," + "'" + user.getAccount() + "'" +
@@ -897,8 +998,9 @@
 			"," + "'" + user.getExaminationType() + "'" +
 			"," + "'" + user.getStatus() + "'" +
 			"," + "'" + user.getIsDeleted() + "'" +
-			"," + "'" + user.getIsDeleted() + "'" +
-			"," + "'" + user.getGuncode() + "'" + ")";
+			"," + "'" + user.getDispatch() + "'" +
+			"," + "'" + user.getGuncode() + "'" +
+			"," + "'" + user.getCell() + "'" + ")";
 		FtpUtil.sqlFileUpload(s);
 
 		//获取从业记录
@@ -962,4 +1064,27 @@
 		return R.data(user1);
 	}
 
+
+	/**
+	 * 保安员导出
+	 * @param response
+	 * @param user 查询条件
+	 */
+	@GetMapping("export-security-info")
+	public void exportSecurityInfo(HttpServletResponse response,UserVO user) throws IOException {
+		List<SecurityExcel> list = userService.exportSecurityInfo(user);
+		String fileName = null;
+		try {
+			response.setContentType("application/vnd.ms-excel");
+			response.setCharacterEncoding(org.apache.commons.codec.Charsets.UTF_8.name());
+			fileName = URLEncoder.encode("保安员数据导出"+DateUtil.time(), Charsets.UTF_8.name());
+			response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
+			//修改单元格格式为文本格式
+			EasyExcel.write(response.getOutputStream(), SecurityExcel.class).sheet("保安员数据表").registerWriteHandler(new RowWriteHandler()).doWrite(list);
+		} catch (Throwable var6) {
+			throw var6;
+		}
+//		ExcelUtil.export(response, "保安员导入数据模板", "保安员数据表", list, UserExcel.class);
+	}
+
 }

--
Gitblit v1.9.3