From 7c9742190965b22f4ea3864aa8588fad19e0be58 Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Wed, 29 Sep 2021 20:27:18 +0800
Subject: [PATCH] 培训审核查询修改

---
 src/main/java/org/springblade/modules/information/controller/InformationController.java |  223 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 194 insertions(+), 29 deletions(-)

diff --git a/src/main/java/org/springblade/modules/information/controller/InformationController.java b/src/main/java/org/springblade/modules/information/controller/InformationController.java
index 64c6ad6..b19ddbd 100644
--- a/src/main/java/org/springblade/modules/information/controller/InformationController.java
+++ b/src/main/java/org/springblade/modules/information/controller/InformationController.java
@@ -17,20 +17,26 @@
 package org.springblade.modules.information.controller;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
 import com.alibaba.fastjson.JSON;
 import org.springblade.common.cache.DictCache;
+import org.springblade.common.config.FtpConfig;
 import org.springblade.common.enums.DictEnum;
 import org.springblade.core.boot.ctrl.BladeController;
 import org.springblade.core.cache.utils.CacheUtil;
 import org.springblade.core.excel.util.ExcelUtil;
+import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.support.Kv;
+import org.springblade.core.tool.utils.DigestUtil;
+import org.springblade.core.tool.utils.Func;
+import org.springblade.core.tool.utils.StringUtil;
 import org.springblade.modules.FTP.FtpUtil;
 import org.springblade.modules.FTP.OutJson;
 import org.springblade.modules.information.entity.Information;
@@ -39,7 +45,12 @@
 import org.springblade.modules.information.service.IInformationService;
 import org.springblade.modules.information.vo.InformationVO;
 import org.springblade.modules.system.entity.Dept;
+import org.springblade.modules.system.entity.Role;
+import org.springblade.modules.system.entity.User;
 import org.springblade.modules.system.service.IDeptService;
+import org.springblade.modules.system.service.IRoleService;
+import org.springblade.modules.system.service.IUserService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -76,6 +87,11 @@
 
 	private final IInformationService informationService;
 	private final IDeptService iDeptService;
+
+
+	private final IUserService userService;
+
+	private final IRoleService roleService;
 
 	/**
 	 * 详情
@@ -127,7 +143,7 @@
 	@PostMapping("/save")
 	@ApiOperationSupport(order = 4)
 	@ApiOperation(value = "新增", notes = "传入information")
-	public R save(@Valid @RequestBody Information information) throws Exception {
+	public R save(@Valid @RequestBody Information information){
 		Dept dept = new Dept();
 		//自招保安公司
 		if (information.getStats().equals("0")) {
@@ -182,22 +198,76 @@
 			String id = kv.get("id").toString();
 			information.setDepartmentid(id);
 		}
-		informationService.save(information);
-		String formatStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(information.getEstablishtime());
-		//Integer id = information.getId();
-		String s = "insert into sys_information(id,creditcode,enterprisename,representative,establishtime," +
-			"registeredcapital,organizationcode,registrationnumber,identificationnumber, enterprises, address," +
-			" business,region,registration,industry,departmentid,stats,jurisdiction,representativecell,contacts,contactscell) " +
-			"values(" + "'" + information.getId() + "'" + "," + "'" + information.getCreditcode() + "'" + "," + "'" + information.getEnterprisename() + "'" + "," + "'" + information.getRepresentative() + "'" + "," +
-			"'" + formatStr + "'" + "," + "'" + information.getRegisteredcapital() + "'" + "," + "'" + information.getOrganizationcode() + "'" + "," + "'" + information.getRegistrationnumber() + "'" + "," +
-			"'" + information.getIdentificationnumber() + "'" + "," + "'" + information.getEnterprises() + "'" + "," + "'" +
-			information.getAddress() + "'" + "," + "'" + information.getBusiness() + "'" + "," + "'" +
-			information.getRegion() + "'" + "," + "'" + information.getRegistration() + "'" + "," + "'" + information.getIndustry() + "'" + "," + "'" + information.getDepartmentid() + "'" + "," +
-			"'" + information.getStats() + "'" + "," + "'" + information.getJurisdiction() + "'" + "," + "'" + information.getRepresentativecell() + "'" + "," +
-			"'" + information.getContacts() + "'" + "," + "'" + information.getContactscell() + "'" + ");" +
-			"insert into blade_dept(id,parent_id,tenant_id,dept_name,ancestors,dept_category) values(" + "'" + information.getDepartmentid() + "'" + "," + "'" + dept.getParentId() + "'" + ","
-			+ "'" + dept.getTenantId() + "'" + "," + "'" + information.getEnterprisename() + "'" + "," + "'" + dept.getAncestors() + "'" + "," + "'" + dept.getDeptCategory() + "'" + ")";
-		FtpUtil.sqlFileUpload(s);
+
+		//公司新增
+		boolean status = informationService.save(information);
+
+		//公司新增成功则创建默认账户,公司名即为账号名,默认密码为 123456
+		if (status) {
+			User user = new User();
+			user.setAccount(information.getEnterprisename());
+			user.setPassword(DigestUtil.encrypt("123456"));
+			Integer userCount = userService.selectCount(information.getEnterprisename());
+			if (userCount > 0 && Func.isEmpty(user.getId())) {
+				throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount()));
+			}
+			user.setDeptId(information.getDepartmentid());
+			user.setTenantId("000000");
+			user.setCreateTime(new Date());
+			user.setUpdateTime(new Date());
+			user.setStatus(1);
+			user.setIsDeleted(0);
+			//分配保安角色
+			Role role = new Role();
+			role.setRoleAlias("保安公司管理员");
+			Role oneRole = roleService.getOne(Condition.getQueryWrapper(role));
+			user.setRoleId(oneRole.getId().toString());
+			//插入用户数据
+			userService.save(user);
+
+			Integer isDeleted = 0;
+			//Integer id = information.getId();
+			String s = "insert into sys_information(id,creditCode,enterpriseName,representative" +
+						",registeredCapital,organizationCode,registrationNumber, enterprises, address," +
+						" business,region,registration,industry,departmentid,stats,jurisdiction,representativecell,contacts,contactscell) " +
+						"values(" + "'" + information.getId() + "'" +
+						"," + "'" + information.getCreditcode() + "'" +
+						"," + "'" + information.getEnterprisename() + "'" +
+						"," + "'" + information.getRepresentative() + "'" +
+						"," + "'" + information.getRegisteredcapital() + "'" +
+						"," + "'" + information.getOrganizationcode() + "'" +
+						"," + "'" + information.getRegistrationnumber() + "'" +
+						"," + "'" + information.getEnterprises() + "'" +
+						"," + "'" + information.getAddress() + "'" +
+						"," + "'" + information.getBusiness() + "'" +
+						"," + "'" + information.getRegion() + "'" +
+						"," + "'" + information.getRegistration() + "'" +
+						"," + "'" + information.getIndustry() + "'" +
+						"," + "'" + information.getDepartmentid() + "'" +
+						"," + "'" + information.getStats() + "'" +
+						"," + "'" + information.getJurisdiction() + "'" +
+						"," + "'" + information.getRepresentativecell() + "'" +
+						"," + "'" + information.getContacts() + "'" +
+						"," + "'" + information.getContactscell() + "'" + ");" +
+						"insert into blade_dept(id,parent_id,tenant_id,dept_name,ancestors,dept_category,is_deleted) values(" + "'" + information.getDepartmentid() + "'" + "," + "'" + dept.getParentId() + "'" + ","
+						+ "'" + dept.getTenantId() + "'" +
+						"," + "'" + information.getEnterprisename() + "'" +
+						"," + "'" + dept.getAncestors() + "'" +
+						"," + "'" + dept.getDeptCategory() + "'" +
+						"," + "'" + isDeleted + "'" + ");" +
+						"insert into blade_user(id,tenant_id,account,password,role_id,dept_id,create_time,update_time,status,is_deleted) " +
+						"values(" + "'" + user.getId() + "'" +
+						"," + "'" + user.getTenantId() + "'"
+						+ "," + "'" + user.getAccount() + "'" +
+						"," + "'" + user.getPassword() + "'" +
+						"," + "'" + user.getRoleId() + "'" +
+						"," + "'" + user.getDeptId() + "'" +
+						"," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getCreateTime()) + "'" +
+						"," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getUpdateTime()) + "'" +
+						"," + "'" + user.getStatus() + "'" +
+						"," + "'" + user.getIsDeleted() + "'" + ")";
+			FtpUtil.sqlFileUpload(s);
+		}
 		return R.success("成功");
 	}
 
@@ -208,7 +278,50 @@
 	@ApiOperationSupport(order = 5)
 	@ApiOperation(value = "修改", notes = "传入information")
 	public R update(@Valid @RequestBody Information information) throws Exception {
-		return R.status(informationService.updateById(information));
+		informationService.updateById(information);
+		String businessLicense = null;
+		String businessLicenses = null;
+		String licence = null;
+		String licences = null;
+		String format = "";
+		if (information.getBusinessLicense() != null && !"".equals(information.getBusinessLicense())) {
+			businessLicense = information.getBusinessLicense().substring(26, information.getBusinessLicense().length());
+			businessLicenses = FtpConfig.ip + businessLicense;
+		} else {
+			businessLicenses = "";
+		}
+		if (information.getLicence() != null && !"".equals(information.getLicence())) {
+			licence = information.getLicence().substring(26, information.getLicence().length());
+			licences = FtpConfig.ip + licence;
+		} else {
+			licences = "";
+		}
+		if (information.getEstablishtime() != null && !"".equals(information.getEstablishtime())) {
+			format = new SimpleDateFormat("yyyy-MM-dd").format(information.getEstablishtime());
+		}
+		//内网同步
+		String s1 = "update sys_information set creditCode = " + "'" + information.getCreditcode() + "'" +
+			",enterpriseName = " + "'" + information.getEnterprisename() + "'" +
+			",representative = " + "'" + information.getRepresentative() + "'" +
+			",establishTime = " + "'" + format + "'" +
+			",registeredCapital = " + "'" + information.getRegisteredcapital() + "'" +
+			",jurisdiction = " + "'" + information.getJurisdiction() + "'" +
+			",enterprises = " + "'" + information.getEnterprises() + "'" +
+			",address = " + "'" + information.getAddress() + "'" +
+			",business = " + "'" + information.getBusiness() + "'" +
+			",region = " + "'" + information.getRegion() + "'" +
+			",registration = " + "'" + information.getRegistration() + "'" +
+			",industry = " + "'" + information.getIndustry() + "'" +
+			",departmentid = " + "'" + information.getDepartmentid() + "'" +
+			",stats = " + "'" + information.getStats() + "'" +
+			",representativecell = " + "'" + information.getRepresentativecell() + "'" +
+			",contacts = " + "'" + information.getContacts() + "'" +
+			",contactscell = " + "'" + information.getContactscell() + "'" +
+			",business_License = " + "'" + businessLicenses + "'" +
+			",licence = " + "'" + licences + "'" +
+			" " + "where id = " + "'" + information.getId() + "'";
+		FtpUtil.sqlFileUpload(s1);
+		return R.success("修改成功");
 	}
 
 	/**
@@ -235,11 +348,18 @@
 			informationService.deleteIn(strArray[i]);
 			informationService.deleteSh(strArray[i]);
 			informationService.deleteMe(strArray[i]);
-
+			String s1 = "delete from sys_information where creditCode = " + "'" + strArray[i] + "'";
+			FtpUtil.sqlFileUpload(s1);
+			String s2 = "delete from sys_shareholder where creditCode = " + "'" + strArray[i] + "'";
+			FtpUtil.sqlFileUpload(s2);
+			String s3 = "delete from sys_member where creditCode = " + "'" + strArray[i] + "'";
+			FtpUtil.sqlFileUpload(s3);
 		}
 		for (int j = 0; j < strArrays.length; j++) {
 			//机构删除
 			informationService.deleteDept(strArrays[j]);
+			String s4 = "delete from blade_dept where id = " + "'" + strArrays[j] + "'";
+			FtpUtil.sqlFileUpload(s4);
 		}
 
 		return R.success("删除成功");
@@ -249,8 +369,8 @@
 	 * 统计保安员资格异常的数量
 	 */
 	@PostMapping("/selectExtype")
-	public R selectExtype(String deptid) {
-		List<Map<Object, Object>> lists = informationService.selectExtype(deptid);
+	public R selectExtype(String deptid, String jurisdiction) {
+		List<Map<Object, Object>> lists = informationService.selectExtype(deptid, jurisdiction);
 		return R.data(lists);
 	}
 
@@ -258,8 +378,8 @@
 	 * 统计保安员持证的数量
 	 */
 	@PostMapping("/selectHold")
-	public R selectHold(String deptid) {
-		List<Map<Object, Object>> lists = informationService.selectHold(deptid);
+	public R selectHold(String deptid, String jurisdiction) {
+		List<Map<Object, Object>> lists = informationService.selectHold(deptid, jurisdiction);
 		return R.data(lists);
 	}
 
@@ -276,8 +396,8 @@
 	 * 保安派遣数量统计
 	 */
 	@PostMapping("/selectDisp")
-	public R selectDisp(String deptid) {
-		List<Map<Object, Object>> lists = informationService.selectDisp(deptid);
+	public R selectDisp(String deptid, String jurisdiction) {
+		List<Map<Object, Object>> lists = informationService.selectDisp(deptid, jurisdiction);
 		return R.data(lists);
 	}
 
@@ -285,8 +405,8 @@
 	 * 社保统计
 	 */
 	@PostMapping("/selectSoil")
-	public R selectSoil(String deptid) {
-		List<Map<Object, Object>> lists = informationService.selectSoil(deptid);
+	public R selectSoil(String deptid, String jurisdiction) {
+		List<Map<Object, Object>> lists = informationService.selectSoil(deptid, jurisdiction);
 		List<Map<String, Object>> list = new ArrayList<>();
 		for (int i = 0; i < lists.size(); i++) {
 			Map<String, Object> map = new HashMap<String, Object>();
@@ -294,9 +414,9 @@
 			Integer a = Integer.valueOf(numj);
 			String numz = lists.get(i).get("numz").toString();
 			Integer b = Integer.valueOf(numz);
-			Integer c = b - a;
+			//Integer c = b - a;
 			map.put("numj", a);
-			map.put("nmuwj", c);
+			map.put("nmuwj", b);
 			list.add(map);
 		}
 		return R.data(list);
@@ -314,5 +434,50 @@
 		return R.success("操作成功");
 	}
 
+	/**
+	 * 查询本年所有月份的客户数量
+	 *
+	 * @return
+	 */
+	@PostMapping("/queryYearKh")
+	public List queryYearKh(String jurisdiction, String deptid) {
+		Calendar cal = Calendar.getInstance();
+		String year = String.valueOf(cal.get(Calendar.YEAR));
+		List list = informationService.queryYearKh(year, jurisdiction, deptid);
+		return list;
+	}
+
+	//升序
+	public static Map<String, String> sortMapBykeyAsc(Map<String, String> oriMap) {
+		Map<String, String> sortedMap = new LinkedHashMap<String, String>();
+		try {
+			if (oriMap != null && !oriMap.isEmpty()) {
+				List<Map.Entry<String, String>> entryList = new ArrayList<Map.Entry<String, String>>(oriMap.entrySet());
+				Collections.sort(entryList,
+					new Comparator<Map.Entry<String, String>>() {
+						public int compare(Map.Entry<String, String> entry2,
+										   Map.Entry<String, String> entry1) {
+							int value2 = 0, value1 = 0;
+							try {
+								value2 = Integer.parseInt(entry1.getKey());
+								value1 = Integer.parseInt(entry2.getKey());
+							} catch (NumberFormatException e) {
+								value2 = 0;
+								value1 = 0;
+							}
+							return value1 - value2;
+						}
+					});
+				Iterator<Map.Entry<String, String>> iter = entryList.iterator();
+				Map.Entry<String, String> tmpEntry = null;
+				while (iter.hasNext()) {
+					tmpEntry = iter.next();
+					sortedMap.put(tmpEntry.getKey(), tmpEntry.getValue());
+				}
+			}
+		} catch (Exception e) {
+		}
+		return sortedMap;
+	}
 
 }

--
Gitblit v1.9.3