新增了网格长导入脚本
This commit is contained in:
parent
31c4ef3c0c
commit
4148945308
10
pom.xml
10
pom.xml
@ -6,12 +6,12 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.2.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<groupId>com.cm</groupId>
|
||||
<artifactId>system-city</artifactId>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
<name>servicecity</name>
|
||||
<name>systemcity</name>
|
||||
<description>城市管理系统</description>
|
||||
|
||||
<properties>
|
||||
@ -157,6 +157,12 @@
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>4.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -24,11 +24,14 @@ spring:
|
||||
max-request-size: 1GB
|
||||
datasource:
|
||||
druid:
|
||||
url: jdbc:mysql://49.233.36.36:6688/db_cloud_city?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false
|
||||
# url: jdbc:mysql://49.233.36.36:6688/db_cloud_city?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false
|
||||
url: jdbc:mysql://127.0.0.1:3306/db_cloud_v2_city?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false
|
||||
db-type: mysql
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
username: wanggeng
|
||||
password: WenG>2132997
|
||||
# username: wanggeng
|
||||
username: root
|
||||
# password: WenG>2132997
|
||||
password: root
|
||||
initial-size: 2
|
||||
min-idle: 2
|
||||
max-active: 10
|
||||
@ -70,7 +73,7 @@ swagger:
|
||||
|
||||
# 文件
|
||||
file:
|
||||
uploadPath: /Users/wanggeng/Desktop/UploadFiles/
|
||||
uploadPath: C:\Users\wenc0\Desktop\UploadFiles\
|
||||
imageTypes: png,jpg,jpeg,gif,blob
|
||||
videoTypes: mp4,rmvb
|
||||
audioTypes: mp3,wmv,wav
|
||||
|
@ -1,13 +1,396 @@
|
||||
package com.cm.systemcity;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.event.AnalysisEventListener;
|
||||
import com.cm.common.utils.UUIDUtil;
|
||||
import com.cm.common.utils.jdbc.JdbcUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.security.core.parameters.P;
|
||||
|
||||
@SpringBootTest
|
||||
class SystemCityApplicationTests {
|
||||
import java.io.File;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
//@SpringBootTest
|
||||
public class SystemCityApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
public void importCommunityBoss() throws SQLException, ClassNotFoundException {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/db_cloud_v2_city?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false", "root", "root");
|
||||
// 所有用户
|
||||
String sql = "SELECT * FROM sys_user WHERE is_delete = '0'";
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(sql);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
List<Map<String, Object>> userMaps = JdbcUtil.listResult(resultSet);
|
||||
// 所有地区
|
||||
sql = "SELECT * FROM city_dict WHERE is_delete = '0'";
|
||||
preparedStatement = connection.prepareStatement(sql);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
List<Map<String, Object>> areaMaps = JdbcUtil.listResult(resultSet);
|
||||
// 所有社区
|
||||
sql = "SELECT * FROM city_community WHERE is_delete = '0'";
|
||||
preparedStatement = connection.prepareStatement(sql);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
List<Map<String, Object>> communityMaps = JdbcUtil.listResult(resultSet);
|
||||
|
||||
// 读取Excel
|
||||
List<CommunityBossExcel> noUsernameList = new ArrayList<>();
|
||||
List<CommunityBossExcel> noLeaderUsernameList = new ArrayList<>();
|
||||
List<CommunityBossExcel> noAreaList = new ArrayList<>();
|
||||
List<CommunityBossExcel> noCommunityList = new ArrayList<>();
|
||||
String wsqExcel = "H:\\工作资料\\项目\\文档资料\\包头-片长制城市管理服务平台\\2期\\网格信息(新)\\万水泉镇网格员模板1(2)(1).xlsx";
|
||||
String xtlExcel = "H:\\工作资料\\项目\\文档资料\\包头-片长制城市管理服务平台\\2期\\网格信息(新)\\网格划分信息(稀土路街道)(1)(3)(1).xlsx";
|
||||
String mxExcel = "H:\\工作资料\\项目\\文档资料\\包头-片长制城市管理服务平台\\2期\\网格信息(新)\\网格划分信息6.16(民馨路街道).xlsx";
|
||||
EasyExcel.read(new File(wsqExcel), CommunityBossExcel.class, new CommunityBossExcelListener() {
|
||||
@Override
|
||||
public void listExcel(List<CommunityBossExcel> communityBossExcels) throws Exception {
|
||||
for (CommunityBossExcel communityBossExcel : communityBossExcels) {
|
||||
if (StringUtils.isBlank(communityBossExcel.getUsername())) {
|
||||
continue;
|
||||
}
|
||||
boolean isUsernameExist = false;
|
||||
boolean isLeaderUsernameExist = false;
|
||||
boolean isAreaExist = false;
|
||||
boolean isCommunityExist = false;
|
||||
for (Map<String, Object> userMap : userMaps) {
|
||||
if (StringUtils.equals(communityBossExcel.getUsername(), userMap.get("user_username").toString())) {
|
||||
isUsernameExist = true;
|
||||
communityBossExcel.setCommunityBossUserId(userMap.get("user_id").toString());
|
||||
}
|
||||
if (StringUtils.equals(communityBossExcel.getLeaderUsername(), userMap.get("user_username").toString())) {
|
||||
isLeaderUsernameExist = true;
|
||||
communityBossExcel.setCommunityBossParentUserId(userMap.get("user_id").toString());
|
||||
}
|
||||
}
|
||||
if (!isUsernameExist) {
|
||||
noUsernameList.add(communityBossExcel);
|
||||
continue;
|
||||
}
|
||||
if (!isLeaderUsernameExist) {
|
||||
noLeaderUsernameList.add(communityBossExcel);
|
||||
}
|
||||
for (Map<String, Object> areaMap : areaMaps) {
|
||||
if (StringUtils.equals(communityBossExcel.getArea(), areaMap.get("dict_name").toString())) {
|
||||
isAreaExist = true;
|
||||
communityBossExcel.setAreaId(areaMap.get("dict_id").toString());
|
||||
}
|
||||
}
|
||||
if (!isAreaExist) {
|
||||
noAreaList.add(communityBossExcel);
|
||||
continue;
|
||||
}
|
||||
String communities = communityBossExcel.getCommunities();
|
||||
String[] communityArray = communities.split(",");
|
||||
for (String community : communityArray) {
|
||||
for (Map<String, Object> communityMap : communityMaps) {
|
||||
if (StringUtils.equals(community, communityMap.get("community_name").toString())) {
|
||||
isCommunityExist = true;
|
||||
String communityIds = communityBossExcel.getCommunityIds();
|
||||
if (StringUtils.isNotBlank(communityIds)) {
|
||||
communityIds += ",";
|
||||
}
|
||||
communityIds += communityMap.get("community_id").toString();
|
||||
communityBossExcel.setCommunityIds(communityIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isCommunityExist) {
|
||||
noCommunityList.add(communityBossExcel);
|
||||
continue;
|
||||
}
|
||||
communityBossExcel.setCommunityBossId(UUIDUtil.getUUID());
|
||||
}
|
||||
// 添加2级管理员
|
||||
// 万水泉镇,吴振宏
|
||||
CommunityBossExcel wuZhenHong = new CommunityBossExcel();
|
||||
wuZhenHong.setCommunityBossId(UUIDUtil.getUUID());
|
||||
wuZhenHong.setCommunityBossParentId("0");
|
||||
wuZhenHong.setCommunityBossUserId("e7cd222c-b9f6-436c-a914-88fe1319f771");
|
||||
wuZhenHong.setCommunityBossParentUserId("0");
|
||||
wuZhenHong.setAreaId("8d62a0cc-2c15-4355-906c-6720f8f3617e");
|
||||
wuZhenHong.setArea("万水泉镇");
|
||||
wuZhenHong.setLevel(2);
|
||||
// 民馨路街道,石磊
|
||||
CommunityBossExcel shiLei = new CommunityBossExcel();
|
||||
shiLei.setCommunityBossId(UUIDUtil.getUUID());
|
||||
shiLei.setCommunityBossParentId("0");
|
||||
shiLei.setCommunityBossUserId("f33bfdd0-2114-4c06-95df-03bdc0402f69");
|
||||
shiLei.setCommunityBossParentUserId("0");
|
||||
shiLei.setAreaId("6e922367-f21f-4daf-b38c-c55a67d9a35b");
|
||||
shiLei.setArea("民馨路街道");
|
||||
shiLei.setLevel(2);
|
||||
// 稀土路街道,白世平
|
||||
CommunityBossExcel baiShiPing = new CommunityBossExcel();
|
||||
baiShiPing.setCommunityBossId(UUIDUtil.getUUID());
|
||||
baiShiPing.setCommunityBossParentId("0");
|
||||
baiShiPing.setCommunityBossUserId("81ea01a3-6d87-427b-85a2-aca60e58e757");
|
||||
baiShiPing.setCommunityBossParentUserId("0");
|
||||
baiShiPing.setAreaId("7ed23f06-566d-43b7-acd9-4f0b5db08974");
|
||||
baiShiPing.setArea("稀土路街道");
|
||||
baiShiPing.setLevel(2);
|
||||
communityBossExcels.add(wuZhenHong);
|
||||
communityBossExcels.add(shiLei);
|
||||
communityBossExcels.add(baiShiPing);
|
||||
|
||||
// 完善parentId
|
||||
for (CommunityBossExcel communityBossExcel : communityBossExcels) {
|
||||
for (CommunityBossExcel parentCommunityBossExcel : communityBossExcels) {
|
||||
if (StringUtils.equals(communityBossExcel.getLeaderUsername(), parentCommunityBossExcel.getUsername())) {
|
||||
communityBossExcel.setCommunityBossParentId(parentCommunityBossExcel.getCommunityBossId());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 新增网格长
|
||||
String insertCommunityBossSql = "INSERT INTO city_community_boss(" +
|
||||
"community_boss_id, " +
|
||||
"community_boss_user_id, " +
|
||||
"community_boss_parent_id, " +
|
||||
"community_boss_parent_user_id, " +
|
||||
"community_boss_level, " +
|
||||
"area_id, " +
|
||||
"area_name, " +
|
||||
"grid_summary, " +
|
||||
"creator, " +
|
||||
"gmt_create, " +
|
||||
"modifier, " +
|
||||
"gmt_modified, " +
|
||||
"is_delete) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
PreparedStatement insertCommunityBossPreparedStatement = connection.prepareStatement(insertCommunityBossSql);
|
||||
String insertDay = "2021-06-23 22:22:22";
|
||||
|
||||
// 网格长社区的关联关系
|
||||
String insertCommunityBossCommunitySql = "INSERT INTO city_community_boss_community(" +
|
||||
"community_boss_id, " +
|
||||
"community_id) VALUES(?, ?)";
|
||||
PreparedStatement insertCommunityBossCommunityPreparedStatement = connection.prepareStatement(insertCommunityBossCommunitySql);
|
||||
for (CommunityBossExcel communityBossExcel : communityBossExcels) {
|
||||
insertCommunityBossPreparedStatement.setString(1, communityBossExcel.getCommunityBossId());
|
||||
insertCommunityBossPreparedStatement.setString(2, communityBossExcel.getCommunityBossUserId());
|
||||
insertCommunityBossPreparedStatement.setString(3, communityBossExcel.getCommunityBossParentId());
|
||||
insertCommunityBossPreparedStatement.setString(4, communityBossExcel.getCommunityBossParentUserId());
|
||||
insertCommunityBossPreparedStatement.setInt(5, communityBossExcel.getLevel() - 1);
|
||||
insertCommunityBossPreparedStatement.setString(6, communityBossExcel.getAreaId());
|
||||
insertCommunityBossPreparedStatement.setString(7, communityBossExcel.getArea());
|
||||
insertCommunityBossPreparedStatement.setString(8, communityBossExcel.getDistinct());
|
||||
insertCommunityBossPreparedStatement.setString(9, "1");
|
||||
insertCommunityBossPreparedStatement.setString(10, insertDay);
|
||||
insertCommunityBossPreparedStatement.setString(11, "1");
|
||||
insertCommunityBossPreparedStatement.setString(12, insertDay);
|
||||
insertCommunityBossPreparedStatement.setInt(13, 0);
|
||||
int insertCommunityBossCount = insertCommunityBossPreparedStatement.executeUpdate();
|
||||
System.out.println("insert communityBoss: " + insertCommunityBossCount);
|
||||
|
||||
if (!communityBossExcel.getCommunityIds().isEmpty()) {
|
||||
String[] communityIdArray = communityBossExcel.getCommunityIds().split(",");
|
||||
for (String communityId : communityIdArray) {
|
||||
insertCommunityBossCommunityPreparedStatement.setString(1, communityBossExcel.getCommunityBossId());
|
||||
insertCommunityBossCommunityPreparedStatement.setString(2, communityId);
|
||||
int insertCommunityBossCommunityCount = insertCommunityBossCommunityPreparedStatement.executeUpdate();
|
||||
System.out.println("insert communityBossCommunity: " + insertCommunityBossCommunityCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).headRowNumber(2).sheet(0).doRead();
|
||||
System.out.println("无用户名片长");
|
||||
noUsernameList.forEach(System.out::println);
|
||||
System.out.println("无领导用户名片长");
|
||||
noLeaderUsernameList.forEach(System.out::println);
|
||||
System.out.println("无地区片长");
|
||||
noAreaList.forEach(System.out::println);
|
||||
System.out.println("无社区片长");
|
||||
noCommunityList.forEach(System.out::println);
|
||||
}
|
||||
|
||||
public abstract class CommunityBossExcelListener extends AnalysisEventListener<CommunityBossExcel> {
|
||||
private List<CommunityBossExcel> communityBossExcels = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void invoke(CommunityBossExcel communityBossExcel, AnalysisContext analysisContext) {
|
||||
communityBossExcels.add(communityBossExcel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
||||
try {
|
||||
listExcel(communityBossExcels);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
communityBossExcels.clear();
|
||||
}
|
||||
|
||||
public abstract void listExcel(List<CommunityBossExcel> communityBossExcels) throws Exception;
|
||||
}
|
||||
|
||||
|
||||
public static class CommunityBossExcel {
|
||||
@ExcelProperty(index = 0)
|
||||
private String username;
|
||||
@ExcelProperty(index = 1)
|
||||
private String leaderUsername;
|
||||
@ExcelProperty(index = 2)
|
||||
private String userName;
|
||||
@ExcelProperty(index = 3)
|
||||
private Integer level;
|
||||
@ExcelProperty(index = 4)
|
||||
private String area;
|
||||
@ExcelProperty(index = 5)
|
||||
private String communities;
|
||||
@ExcelProperty(index = 6)
|
||||
private String distinct;
|
||||
private String communityBossUserId;
|
||||
private String communityBossParentUserId;
|
||||
private String areaId;
|
||||
private String communityIds;
|
||||
private String communityBossId;
|
||||
private String communityBossParentId;
|
||||
|
||||
public String getUsername() {
|
||||
return username == null ? "" : username.trim().replaceAll("\\s", "");
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getLeaderUsername() {
|
||||
return leaderUsername == null ? "" : leaderUsername.trim().replaceAll("\\s", "");
|
||||
}
|
||||
|
||||
public void setLeaderUsername(String leaderUsername) {
|
||||
this.leaderUsername = leaderUsername;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName == null ? "" : userName.trim().replaceAll("\\s", "");
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public Integer getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(Integer level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public String getArea() {
|
||||
return area == null ? "" : area.trim().replaceAll("\\s", "");
|
||||
}
|
||||
|
||||
public void setArea(String area) {
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
public String getCommunities() {
|
||||
return communities == null ? "" : communities.trim().replaceAll("\\s", "");
|
||||
}
|
||||
|
||||
public void setCommunities(String communities) {
|
||||
this.communities = communities;
|
||||
}
|
||||
|
||||
public String getDistinct() {
|
||||
return distinct == null ? "" : distinct.trim().replaceAll("\\s", "");
|
||||
}
|
||||
|
||||
public void setDistinct(String distinct) {
|
||||
this.distinct = distinct;
|
||||
}
|
||||
|
||||
public String getCommunityBossId() {
|
||||
return communityBossId == null ? "" : communityBossId.trim();
|
||||
}
|
||||
|
||||
public void setCommunityBossId(String communityBossId) {
|
||||
this.communityBossId = communityBossId;
|
||||
}
|
||||
|
||||
public String getCommunityBossParentId() {
|
||||
return communityBossParentId == null ? "0" : communityBossParentId.trim();
|
||||
}
|
||||
|
||||
public void setCommunityBossParentId(String communityBossParentId) {
|
||||
this.communityBossParentId = communityBossParentId;
|
||||
}
|
||||
|
||||
public String getCommunityBossUserId() {
|
||||
return communityBossUserId == null ? "" : communityBossUserId.trim();
|
||||
}
|
||||
|
||||
public void setCommunityBossUserId(String communityBossUserId) {
|
||||
this.communityBossUserId = communityBossUserId;
|
||||
}
|
||||
|
||||
public String getCommunityBossParentUserId() {
|
||||
return communityBossParentUserId == null ? "" : communityBossParentUserId.trim();
|
||||
}
|
||||
|
||||
public void setCommunityBossParentUserId(String communityBossParentUserId) {
|
||||
this.communityBossParentUserId = communityBossParentUserId;
|
||||
}
|
||||
|
||||
public String getAreaId() {
|
||||
return areaId == null ? "" : areaId.trim();
|
||||
}
|
||||
|
||||
public void setAreaId(String areaId) {
|
||||
this.areaId = areaId;
|
||||
}
|
||||
|
||||
public String getCommunityIds() {
|
||||
return communityIds == null ? "" : communityIds.trim();
|
||||
}
|
||||
|
||||
public void setCommunityIds(String communityIds) {
|
||||
this.communityIds = communityIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
sb.append("\"username\":\"")
|
||||
.append(username).append('\"');
|
||||
sb.append(",\"leaderUsername\":\"")
|
||||
.append(leaderUsername).append('\"');
|
||||
sb.append(",\"userName\":\"")
|
||||
.append(userName).append('\"');
|
||||
sb.append(",\"level\":")
|
||||
.append(level);
|
||||
sb.append(",\"area\":\"")
|
||||
.append(area).append('\"');
|
||||
sb.append(",\"communities\":\"")
|
||||
.append(communities).append('\"');
|
||||
sb.append(",\"distinct\":\"")
|
||||
.append(distinct).append('\"');
|
||||
sb.append(",\"communityBossUserId\":\"")
|
||||
.append(communityBossUserId).append('\"');
|
||||
sb.append(",\"communityBossParentUserId\":\"")
|
||||
.append(communityBossParentUserId).append('\"');
|
||||
sb.append(",\"areaId\":\"")
|
||||
.append(areaId).append('\"');
|
||||
sb.append(",\"communityIds\":\"")
|
||||
.append(communityIds).append('\"');
|
||||
sb.append(",\"communityBossId\":\"")
|
||||
.append(communityBossId).append('\"');
|
||||
sb.append(",\"communityBossParentId\":\"")
|
||||
.append(communityBossParentId).append('\"');
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user