From efcb8c3fd7719c3bdd7cd8696ec2bdca0d9e9bd9 Mon Sep 17 00:00:00 2001 From: WenG <450292408@qq.com> Date: Sat, 5 Mar 2022 20:24:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8C=BA=E5=9F=9F=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/user-expand/update.html | 69 +++--- .../tenlion/usercenter/DepartmentTest.java | 202 ++++++++++++++++++ 2 files changed, 246 insertions(+), 25 deletions(-) create mode 100644 src/test/java/cn/com/tenlion/usercenter/DepartmentTest.java diff --git a/src/main/resources/templates/user-expand/update.html b/src/main/resources/templates/user-expand/update.html index 7c89ec8..6893c2b 100644 --- a/src/main/resources/templates/user-expand/update.html +++ b/src/main/resources/templates/user-expand/update.html @@ -11,6 +11,10 @@ @@ -21,9 +25,17 @@
基础信息
-
+
+
+ + +
@@ -88,25 +100,25 @@
- +
- +
- +
- +
@@ -254,30 +266,37 @@ return false; }); - $('#areaName').on('click', function() { - top.dialog.open({ - title: '选择地区', - url: top.restAjax.path('route/area/get-select?areaName={areaName}', [encodeURI($('#areaName').val())]), - width: '600px', - height: '225px', - onClose: function() { - var selectedAreaArray = top.dialog.dialogData.selectedAreaArray; - if(selectedAreaArray.length > 0) { - var areaCode = ''; - var areaName = ''; - areaCode = selectedAreaArray[selectedAreaArray.length - 1].areaCode; - for(var i = 0, item; item = selectedAreaArray[i++];) { - if(areaName) { - areaName += ' / '; + // 区域选择 + (function() { + $('#areaSelectBtn').on('click', function() { + top.dialog.open({ + title: '选择地区', + url: top.restAjax.path('route/area/get-select?areaName={areaName}', [encodeURI($('#departmentAreaName').val())]), + width: '600px', + height: '225px', + onClose: function() { + var selectedAreaArray = top.dialog.dialogData.selectedAreaArray; + if(selectedAreaArray.length > 0) { + var areaCode = ''; + var areaName = ''; + areaCode = selectedAreaArray[selectedAreaArray.length - 1].areaCode; + for(var i = 0, item; item = selectedAreaArray[i++];) { + if(areaName) { + areaName += ' / '; + } + areaName += item.areaName; } - areaName += item.areaName; + $('#areaCode').val(areaCode); + $('#areaName').val(areaName); } - $('#areaCode').val(areaCode); - $('#areaName').val(areaName); } - } + }) + }); + $('#areaCleanBtn').on('click', function () { + $('#areaCode').val(''); + $('#areaName').val(''); }) - }) + })(); $('.close').on('click', function() { closeBox(); diff --git a/src/test/java/cn/com/tenlion/usercenter/DepartmentTest.java b/src/test/java/cn/com/tenlion/usercenter/DepartmentTest.java new file mode 100644 index 0000000..22e19e3 --- /dev/null +++ b/src/test/java/cn/com/tenlion/usercenter/DepartmentTest.java @@ -0,0 +1,202 @@ +package cn.com.tenlion.usercenter; + +import ink.wgink.util.UUIDUtil; +import ink.wgink.util.date.DateUtil; +import ink.wgink.util.jdbc.JdbcUtil; +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; + +import java.sql.*; +import java.util.List; +import java.util.Map; + +/** + * @Description: 部门数据 + * @Author: WenG + * @Date: 2022/3/5 10:04 + * @Version: 1.0 + **/ +public class DepartmentTest { + + public static String[] WLCB = new String[]{"发改委民委", "工信局", "卫生健康委员会", "审计局", "财政局", "住建委", "交通局", "自然资源局", "农牧局", "水利局", "林业和草原局", "公安局", "司法局", "人社局", "民政局", "教育局", "科技局", "文化旅游体育局", "商务局", "金融办", "税务局", "统计局", "生态环境局", "市场监督管理局", "乡村振兴局", "气象局信访局", "邮政管理局", "应急管理局", "供销社", "人民银行", "国资委", "退役军人事务局", "区域经济合作局", "医疗保障局", "政务服务局"}; + public static String[] QXQ = new String[]{"人民政府办公室", "发展和改革委员会", "教育局", "工业和信息化局", "民族事务委员会", "民政局", "司法局", "财政局", "人力资源和社会保障局", "住房和城乡建设局", "农牧水利局(乡村振兴局)", "商务局", "文化旅游体育局", "卫生健康委员会", "退役军人事务局", "应急管理局", "审计局", "国有资产监督管理委员会", "市场监督管理局", "统计局", "医疗保障局", "信访局", "城市管理综合执法局", "科技和大数据管理局", "政务服务局"}; + public static String[] JD = new String[]{"派出所", "司法所", "物业所", "城管中队", "市场管理中队"}; + public static String[] SQ = new String[]{"居委会", "支委会"}; + + // 区域 + private String SQL_GET_AREA_BY_AREA_CODE = "SELECT area_id, area_parent_id, area_name, area_code FROM data_area WHERE area_code = ?"; + private String SQL_GET_AREA_BY_AREA_ID = "SELECT area_id, area_parent_id, area_name, area_code FROM data_area WHERE area_id = ?"; + private String SQL_LIST_AREA_BY_PARENT_ID = "SELECT area_id, area_parent_id, area_name, area_code, area_level FROM data_area WHERE area_parent_id = ?"; + /** + * 部门 + */ + private String SQL_COUNT_DEPARTMENT_BY_PARENT_ID = "SELECT COUNT(*) count FROM sys_department WHERE department_parent_id = ?"; + private String SQL_SAVE_DEPARTMENT = "INSERT INTO sys_department(`department_id`,`department_parent_id`,`department_name`,`department_code`,`department_type`,`department_state`, `department_order`,`department_area_code`,`department_area_name`) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)"; + private static int COUNT_SAVED_AREA_DEPARTMENT = 0; + private static int COUNT_SAVED_DEPARTMENT = 0; + + @Test + public void importData() throws SQLException { + long startTime = System.currentTimeMillis(); + String currentDateTime = DateUtil.getTime(); + Connection connection = DriverManager.getConnection(String.format("jdbc:mysql://%s:%s/db_smart_city_usercenter?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC&nullCatalogMeansCurrent=true", "192.168.0.103", 3306), "root", "root"); + + // 区域 + PreparedStatement getAreaByCodePS = connection.prepareStatement(SQL_GET_AREA_BY_AREA_CODE); + PreparedStatement getAreaByIdPS = connection.prepareStatement(SQL_GET_AREA_BY_AREA_ID); + PreparedStatement listAreaByParentIdPS = connection.prepareStatement(SQL_LIST_AREA_BY_PARENT_ID); + + // 部门 + PreparedStatement countDepartmentPS = connection.prepareStatement(SQL_COUNT_DEPARTMENT_BY_PARENT_ID); + PreparedStatement saveDepartmentPS = connection.prepareStatement(SQL_SAVE_DEPARTMENT); + + saveAreaDepartment("0", "", "0", listAreaByParentIdPS, countDepartmentPS, saveDepartmentPS, getAreaByCodePS, getAreaByIdPS); + + long endTime = System.currentTimeMillis(); + System.out.println("耗时:" + (endTime - startTime) + "ms"); + System.out.println("****************************************"); + System.out.println("区域: " + COUNT_SAVED_AREA_DEPARTMENT); + System.out.println("部门: " + COUNT_SAVED_DEPARTMENT); + System.out.println("****************************************"); + } + + private void saveAreaDepartment(String departmentParentId, String departmentParentCode, String areaParentId, PreparedStatement listAreaByParentIdPS, PreparedStatement countDepartmentPS, PreparedStatement saveDepartmentPS, PreparedStatement getAreaByCodePS, PreparedStatement getAreaByParentIdPS) throws SQLException { + // 查询子区域 + listAreaByParentIdPS.setString(1, areaParentId); + ResultSet resultSet = listAreaByParentIdPS.executeQuery(); + List> areaMaps = JdbcUtil.listResult(resultSet); + if (areaMaps.isEmpty()) { + return; + } + countDepartmentPS.setString(1, departmentParentId); + ResultSet countResultSet = countDepartmentPS.executeQuery(); + Map resultMap = JdbcUtil.getResult(countResultSet); + Long totalCount = (Long) resultMap.get("count"); + // 保存地区 + for (int i = 0; i < areaMaps.size(); i++) { + Map areaMap = areaMaps.get(i); + System.out.println("area: " + areaMap); + String areaName = areaMap.get("area_name").toString(); + + String areaCode = areaMap.get("area_code").toString(); + Integer areaLevel = (Integer) areaMap.get("area_level"); + // 保存地区部门 + String departmentId = UUIDUtil.getUUID(); + String fullDepartmentName = areaName; + long departmentOrder = (totalCount + i + 1); + String fullDepartmentCode = String.format("%s%04d", departmentParentCode, departmentOrder); + saveDepartmentPS.setString(1, departmentId); + saveDepartmentPS.setString(2, departmentParentId); + saveDepartmentPS.setString(3, fullDepartmentName); + saveDepartmentPS.setString(4, fullDepartmentCode); + saveDepartmentPS.setInt(5, 1); + saveDepartmentPS.setInt(6, 1); + saveDepartmentPS.setLong(7, departmentOrder); + saveDepartmentPS.setString(8, areaCode); + saveDepartmentPS.setString(9, getFullArea(areaCode, getAreaByCodePS, getAreaByParentIdPS)); + saveDepartmentPS.executeUpdate(); + System.out.println("areaDepartmentName: " + areaName + ", areaDepartmentCode: " + fullDepartmentCode); + System.out.println("saveAreaDepartment: " + saveDepartmentPS); + COUNT_SAVED_AREA_DEPARTMENT++; + if (StringUtils.equals("市辖区", areaName)) { + continue; + } + // 保存部门 + Integer departmentCount = saveDepartment(areaName, fullDepartmentCode, departmentId, areaCode, areaLevel, countDepartmentPS, saveDepartmentPS, getAreaByCodePS, getAreaByParentIdPS); + // 保存地区下的部门 + saveAreaDepartment(departmentId, fullDepartmentCode, areaMap.get("area_id").toString(), listAreaByParentIdPS, countDepartmentPS, saveDepartmentPS, getAreaByCodePS, getAreaByParentIdPS); + } + } + + /** + * 保存部门 + * + * @param areaName + * @param departmentCode + * @param departmentParentId + * @param areaLevel + * @param saveDepartmentPS + * @param getAreaByCodePS + * @param getAreaByParentIdPS + * @return + * @throws SQLException + */ + private int saveDepartment(String areaName, String departmentCode, String departmentParentId, String areaCode, int areaLevel, PreparedStatement countDepartmentPS, PreparedStatement saveDepartmentPS, PreparedStatement getAreaByCodePS, PreparedStatement getAreaByParentIdPS) throws SQLException { + String[] baseDefaultNameArray; + if (areaLevel == 1) { + baseDefaultNameArray = WLCB; + } else if (areaLevel == 2) { + baseDefaultNameArray = QXQ; + } else if (areaLevel == 3) { + baseDefaultNameArray = JD; + } else { + return -1; + } +// else if (areaLevel == 4) { +// baseDefaultNameArray = SQ; +// } + countDepartmentPS.setString(1, departmentParentId); + ResultSet resultSet = countDepartmentPS.executeQuery(); + Map resultMap = JdbcUtil.getResult(resultSet); + Long totalCount = (Long) resultMap.get("count"); + for (int i = 0; i < baseDefaultNameArray.length; i++) { + String baseDefaultName = baseDefaultNameArray[i]; + String departmentId = UUIDUtil.getUUID(); + String fullDepartmentName = areaName + baseDefaultName; + long departmentOrder = (totalCount + i + 1); + String fullDepartmentCode = String.format("%s%04d", departmentCode, departmentOrder); + saveDepartmentPS.setString(1, departmentId); + saveDepartmentPS.setString(2, departmentParentId); + saveDepartmentPS.setString(3, fullDepartmentName); + saveDepartmentPS.setString(4, fullDepartmentCode); + saveDepartmentPS.setInt(5, 1); + saveDepartmentPS.setInt(6, 1); + saveDepartmentPS.setLong(7, departmentOrder); + saveDepartmentPS.setString(8, departmentCode); + saveDepartmentPS.setString(9, getFullArea(areaCode, getAreaByCodePS, getAreaByParentIdPS)); + saveDepartmentPS.executeUpdate(); + System.out.println("departmentName: " + fullDepartmentName + ", departmentCode: " + fullDepartmentCode); + System.out.println("saveDepartment: " + saveDepartmentPS); + COUNT_SAVED_DEPARTMENT++; + } + return baseDefaultNameArray.length; + } + + /** + * 获取地区全称 + * + * @param areaCode + * @param getAreaByCodePS + * @return + * @throws SQLException + */ + private String getFullArea(String areaCode, PreparedStatement getAreaByCodePS, PreparedStatement getAreaByParentIdPS) throws SQLException { + getAreaByCodePS.setString(1, areaCode); + Map areaMap = JdbcUtil.getResult(getAreaByCodePS.executeQuery()); + String areaParentId = areaMap.get("area_parent_id").toString(); + String areaName = areaMap.get("area_name").toString(); + return getFullArea(areaName, areaParentId, getAreaByParentIdPS); + } + + /** + * 获取地区全称 + * + * @param fullName + * @param areaParentId + * @param getAreaByParentIdPS + * @return + * @throws SQLException + */ + private String getFullArea(String fullName, String areaParentId, PreparedStatement getAreaByParentIdPS) throws SQLException { + getAreaByParentIdPS.setString(1, areaParentId); + // System.out.println(getAreaByParentIdPS); + Map areaMap = JdbcUtil.getResult(getAreaByParentIdPS.executeQuery()); + if (areaMap == null) { + System.out.println(fullName); + return fullName; + } + fullName = areaMap.get("area_name").toString() + " / " + fullName; + return getFullArea(fullName, areaMap.get("area_parent_id").toString(), getAreaByParentIdPS); + } + +}