修改区域选择方式
This commit is contained in:
parent
218e8f7793
commit
efcb8c3fd7
@ -11,6 +11,10 @@
|
||||
<link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
|
||||
<style>
|
||||
.layui-form-selected dl{max-height: 200px;}
|
||||
.select-area {position: relative;}
|
||||
.select-area #departmentAreaName {width: 64%}
|
||||
.select-area .select-btn {position: absolute; top: 0px; right: 0px; width: 36%; border-color: #e6e6e6;}
|
||||
.select-area .select-btn button {height: 38px; width: 50%;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@ -21,9 +25,17 @@
|
||||
<blockquote class="layui-elem-quote">基础信息</blockquote>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label layui-form-label-up">所在区域 *</label>
|
||||
<div class="layui-input-block layui-input-block-down">
|
||||
<div class="layui-input-block layui-input-block-down select-area">
|
||||
<input type="hidden" id="areaCode" name="areaCode">
|
||||
<input type="text" id="areaName" name="areaName" class="layui-input" value="" placeholder="请选择地区" maxlength="255" lay-verify="required" style="cursor:pointer;">
|
||||
<div class="layui-btn-group select-btn">
|
||||
<button type="button" id="areaSelectBtn" class="layui-btn layui-btn-sm layui-btn-primary" title="选择区域">
|
||||
<i class="fa fa-circle-thin"></i>
|
||||
</button>
|
||||
<button type="button" id="areaCleanBtn" class="layui-btn layui-btn-sm layui-btn-primary" title="删除区域">
|
||||
<i class="fa fa-times-circle"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item" pane>
|
||||
@ -88,25 +100,25 @@
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label layui-form-label-up">会议ID</label>
|
||||
<div class="layui-input-block layui-input-block-down">
|
||||
<input type="text" id="smcMeetingId" name="smcMeetingId" class="layui-input" value="" placeholder="未绑定融合通信账号" maxlength="255" readonly>
|
||||
<input type="text" id="smcMeetingId" name="smcMeetingId" class="layui-input" value="" placeholder="未绑定融合通信账号" maxlength="255">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label layui-form-label-up">用户名</label>
|
||||
<div class="layui-input-block layui-input-block-down">
|
||||
<input type="text" id="smcUsername" name="smcUsername" class="layui-input" value="" placeholder="未绑定融合通信账号" maxlength="255" readonly>
|
||||
<input type="text" id="smcUsername" name="smcUsername" class="layui-input" value="" placeholder="未绑定融合通信账号" maxlength="255">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label layui-form-label-up">密码</label>
|
||||
<div class="layui-input-block layui-input-block-down">
|
||||
<input type="text" id="smcPassword" name="smcPassword" class="layui-input" value="" placeholder="未绑定融合通信账号" maxlength="255" readonly>
|
||||
<input type="text" id="smcPassword" name="smcPassword" class="layui-input" value="" placeholder="未绑定融合通信账号" maxlength="255">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label layui-form-label-up">会议号</label>
|
||||
<div class="layui-input-block layui-input-block-down">
|
||||
<input type="text" id="smcNumber" name="smcNumber" class="layui-input" value="" placeholder="未绑定融合通信账号" maxlength="255" readonly>
|
||||
<input type="text" id="smcNumber" name="smcNumber" class="layui-input" value="" placeholder="未绑定融合通信账号" maxlength="255">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-layout-admin">
|
||||
@ -254,10 +266,12 @@
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#areaName').on('click', function() {
|
||||
// 区域选择
|
||||
(function() {
|
||||
$('#areaSelectBtn').on('click', function() {
|
||||
top.dialog.open({
|
||||
title: '选择地区',
|
||||
url: top.restAjax.path('route/area/get-select?areaName={areaName}', [encodeURI($('#areaName').val())]),
|
||||
url: top.restAjax.path('route/area/get-select?areaName={areaName}', [encodeURI($('#departmentAreaName').val())]),
|
||||
width: '600px',
|
||||
height: '225px',
|
||||
onClose: function() {
|
||||
@ -277,7 +291,12 @@
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
$('#areaCleanBtn').on('click', function () {
|
||||
$('#areaCode').val('');
|
||||
$('#areaName').val('');
|
||||
})
|
||||
})();
|
||||
|
||||
$('.close').on('click', function() {
|
||||
closeBox();
|
||||
|
202
src/test/java/cn/com/tenlion/usercenter/DepartmentTest.java
Normal file
202
src/test/java/cn/com/tenlion/usercenter/DepartmentTest.java
Normal file
@ -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<Map<String, Object>> areaMaps = JdbcUtil.listResult(resultSet);
|
||||
if (areaMaps.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
countDepartmentPS.setString(1, departmentParentId);
|
||||
ResultSet countResultSet = countDepartmentPS.executeQuery();
|
||||
Map<String, Object> resultMap = JdbcUtil.getResult(countResultSet);
|
||||
Long totalCount = (Long) resultMap.get("count");
|
||||
// 保存地区
|
||||
for (int i = 0; i < areaMaps.size(); i++) {
|
||||
Map<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user