提交 76e8bb53 authored 作者: chenshiying's avatar chenshiying

[新增] 廊坊生成大小类管理问题sql

上级 98683b34
......@@ -52,5 +52,11 @@
<version>5.0.10.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.21</version>
</dependency>
</dependencies>
</project>
package com.loit.common.langfang;
import com.loit.common.langfang.dto.CommandManualDTO;
import com.loit.common.langfang.dto.LimitUnitType;
import com.loit.common.utils.DateUtils;
import com.loit.common.utils.ListUtil;
import com.loit.common.utils.StringUtils;
import com.loit.common.utils.excel.ImportExcel;
import com.loit.common.utils.file.FileUtils;
import com.loit.common.utils.freemarker.FreeMarkerUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.entity.ContentType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
public class GeneratorCommandManualFromDbScript {
private static Logger logger = LoggerFactory.getLogger(GeneratorCommandManualFromDbScript.class);
//TODO 1:事件,2:部件
public static final String CASE_TYPE = "2";
public static final String FILE_NAME = "部件0523.xlsx";
protected static String root_path = "F:\\9Git140\\loit-build-common\\loit-build-component\\loit-build-deploy-env\\src\\main\\resources\\langfang";
public static final String CHECK_FILE_NAME = root_path + "\\5、验证.sql";
public static void main(String[] args) {
JdbcQueryUtils jdbcQueryUtils = new JdbcQueryUtils();
try {
jdbcQueryUtils.init();
String filePathStr = "F:\\9Git140\\loit-build-common\\loit-build-component\\loit-build-deploy-env\\src\\main\\resources\\" + FILE_NAME;
File pdfFile = new File(filePathStr);
FileInputStream fileInputStream = new FileInputStream(pdfFile);
MultipartFile multipartFile = new MockMultipartFile(pdfFile.getName(), pdfFile.getName(),
ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
ImportExcel ei = new ImportExcel(multipartFile, 2, 0);
List<CommandManualDTO> commandManualDTOList = ei.getDataList(CommandManualDTO.class);
if (ListUtil.isEmpty(commandManualDTOList)) {
return;
}
List<CommandManualDTO> transformList = transform(commandManualDTOList);
transformStepTwo(transformList);
createBigTypeScript(transformList);
createSmallTypeScript(transformList);
createManageProblemScript(transformList);
createManageProblemSmallTypeScript(transformList);
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
jdbcQueryUtils.close();
}
}
/**
* 生成大类脚本
*
* @throws IOException
*/
private static void createBigTypeScript(List<CommandManualDTO> commandManualList) {
List<CommandManualDTO> bitTypeList = commandManualList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
new TreeSet<>(Comparator.comparing(CommandManualDTO::getBigTypeCodeInt))), ArrayList::new));
if (bitTypeList == null || bitTypeList.isEmpty()) {
return;
}
bitTypeList.sort(Comparator.comparing(CommandManualDTO::getBigTypeCodeInt));
String configFilePath = root_path + "\\1、bigTypeScript.sql";
FileUtils.append(CHECK_FILE_NAME, "-- 查询所有大类 parent_id 为空的\n");
String sql1 = "select * from base_base_casetype order by parent_id asc;\n";
FileUtils.append(CHECK_FILE_NAME, sql1);
FileUtils.append(CHECK_FILE_NAME, "-- 判断大类是否存在\n");
for (CommandManualDTO commandManualDTO : bitTypeList) {
String sql2 = "select * from base_base_casetype where level = 2 and case_type = " + CASE_TYPE + " and obj_name = '" + commandManualDTO.getBigTypeName() + "';\n";
FileUtils.append(CHECK_FILE_NAME, sql2);
}
FileUtils.append(CHECK_FILE_NAME, "-- 验证小类编码是否顺序\n");
for (CommandManualDTO commandManualDTO : bitTypeList) {
FileUtils.append(CHECK_FILE_NAME, "-- 大类名称: " + commandManualDTO.getBigTypeName() + "\n");
String sql = "select * from base_base_casetype where parent_id = '" + commandManualDTO.getBigTypeId() + "';\n";
FileUtils.append(CHECK_FILE_NAME, sql);
}
for (CommandManualDTO commandManualDTO : bitTypeList) {
Map model = new HashMap();
model.put("bigTypeCode", commandManualDTO.getBigTypeCode());
model.put("bigTypeName", commandManualDTO.getBigTypeName());
model.put("caseType", CASE_TYPE);
String jobConfig = FreeMarkerUtils.process("langfang" + "\\bigTypeScript.ftl", model);
FileUtils.append(configFilePath, jobConfig);
}
}
/**
* 生成小类脚本
*
* @throws IOException
*/
private static void createSmallTypeScript(List<CommandManualDTO> commandManualList) {
List<CommandManualDTO> smallTypeList = commandManualList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
new TreeSet<>(Comparator.comparing(CommandManualDTO::getBigAndSmallCode))), ArrayList::new));
if (smallTypeList == null || smallTypeList.isEmpty()) {
return;
}
smallTypeList.sort(Comparator.comparing(CommandManualDTO::getBigTypeCodeInt)
.thenComparing(CommandManualDTO::getSmallTypeCodeInt));
String configFilePath = root_path + "\\2、smallTypeScript.sql";
FileUtils.append(CHECK_FILE_NAME, "-- 判断小类是否存在\n");
for (CommandManualDTO commandManualDTO : smallTypeList) {
String sql = "select * from base_base_casetype where parent_id = '" + commandManualDTO.getBigTypeId() + "' and obj_name = '" + commandManualDTO.getSmallTypeName() + "';\n";
FileUtils.append(CHECK_FILE_NAME, sql);
}
FileUtils.append(CHECK_FILE_NAME, "-- 查询大类小类下的所有管理问题\n");
for (CommandManualDTO commandManualDTO : smallTypeList) {
String sql = "select * from digital_command_manual where big_type_id = '" + commandManualDTO.getBigTypeId() + "' and small_type = '" + commandManualDTO.getSmallTypeName() + "';\n";
FileUtils.append(CHECK_FILE_NAME, sql);
}
for (CommandManualDTO commandManualDTO : smallTypeList) {
Map model = new HashMap();
model.put("bigTypeId", commandManualDTO.getBigTypeId());
model.put("bigTypeCode", commandManualDTO.getBigTypeCode());
model.put("bigTypeName", commandManualDTO.getBigTypeName());
model.put("smallTypeCode", commandManualDTO.getSmallTypeCode());
model.put("smallTypeName", commandManualDTO.getSmallTypeName());
model.put("caseType", CASE_TYPE);
String jobConfig = FreeMarkerUtils.process("langfang" + "\\smallTypeScript.ftl", model);
FileUtils.append(configFilePath, jobConfig);
}
}
/**
* 生成管理问题脚本
*
* @throws IOException
*/
private static void createManageProblemScript(List<CommandManualDTO> commandManualList) {
if (commandManualList == null || commandManualList.isEmpty()) {
return;
}
String configFilePath = root_path + "\\3、manageProblemScript.sql";
FileUtils.append(CHECK_FILE_NAME, "-- 判断管理问题是否存在\n");
for (CommandManualDTO commandManualDTO : commandManualList) {
Map model = new HashMap();
model.put("bigTypeId", commandManualDTO.getBigTypeId());
model.put("bigTypeCode", commandManualDTO.getBigTypeCode());
model.put("bigTypeName", commandManualDTO.getBigTypeName());
model.put("smallTypeCode", commandManualDTO.getSmallTypeCode());
model.put("smallTypeName", commandManualDTO.getSmallTypeName());
model.put("manageProblem", commandManualDTO.getManageProblem());
model.put("datetime", DateUtils.getDateTime());
model.put("caseType", CASE_TYPE);
LimitUnitType alimitUnit = getLimitUnit(commandManualDTO.getAtype());
LimitUnitType blimitUnit = getLimitUnit(commandManualDTO.getBtype());
LimitUnitType climitUnit = getLimitUnit(commandManualDTO.getCtype());
model.put("alimit", alimitUnit.getLimit());
model.put("aunit", alimitUnit.getUnit());
model.put("blimit", blimitUnit.getLimit());
model.put("bunit", blimitUnit.getUnit());
model.put("climit", climitUnit.getLimit());
model.put("cunit", climitUnit.getUnit());
String sql = "select * from digital_command_manual where manage_problem = '" + commandManualDTO.getManageProblem() + "' and big_type_id = '" + commandManualDTO.getBigTypeId() + "' and small_type = '" + commandManualDTO.getSmallTypeName() + "';\n";
FileUtils.append(CHECK_FILE_NAME, sql);
String jobConfig = FreeMarkerUtils.process("langfang" + "\\manageProblemScript.ftl", model);
FileUtils.append(configFilePath, jobConfig);
}
}
/**
* 生成管理问题脚本-清洗小类id
*
* @throws IOException
*/
private static void createManageProblemSmallTypeScript(List<CommandManualDTO> commandManualList) {
if (commandManualList == null || commandManualList.isEmpty()) {
return;
}
for (CommandManualDTO commandManualDTO : commandManualList) {
Map model = new HashMap();
model.put("bigTypeId", commandManualDTO.getBigTypeId());
model.put("bigTypeCode", commandManualDTO.getBigTypeCode());
model.put("bigTypeName", commandManualDTO.getBigTypeName());
model.put("smallTypeCode", commandManualDTO.getSmallTypeCode());
model.put("smallTypeName", commandManualDTO.getSmallTypeName());
model.put("manageProblem", commandManualDTO.getManageProblem());
String configFilePath = root_path + "\\4、manageProblem_smallTypeId_Script.sql";
String jobConfig = FreeMarkerUtils.process("langfang" + "\\manageProblem_smallTypeId_Script.ftl", model);
FileUtils.append(configFilePath, jobConfig);
}
}
private static LimitUnitType getLimitUnit(String limitStr) {
LimitUnitType limitUnitType = new LimitUnitType();
if (StringUtils.isEmpty(limitStr)) {
logger.error("limitStr is null");
return limitUnitType;
}
limitStr = limitStr.trim();
//0:工作日,1:工作时, 2:紧急工作时
if (limitStr.contains("工作日")) {
limitUnitType.setUnit("0");
limitUnitType.setLimit(limitStr.replaceAll("工作日", "").trim());
} else if (limitStr.contains("紧急工作时")) {
limitUnitType.setUnit("2");
limitUnitType.setLimit(limitStr.replaceAll("紧急工作时", "").trim());
} else if (limitStr.contains("工作时")) {
limitUnitType.setUnit("1");
limitUnitType.setLimit(limitStr.replaceAll("工作时", "").trim());
}
if (limitUnitType.getLimit().length() > 1) {
logger.error("limit length > 1" + limitUnitType.getLimit());
}
return limitUnitType;
}
/**
* 对excel中的数据做转换:
* 1、去除空数据
* 2、填充大类小类
* 3、填充A类B类C类处置时限一样的
* 4、
*/
private static List<CommandManualDTO> transform(List<CommandManualDTO> commandManualDTOList) {
List<CommandManualDTO> resultList = new ArrayList();
for (CommandManualDTO commandManual : commandManualDTOList) {
if (StringUtils.isEmpty(commandManual.getManageProblem())) {
continue;
}
resultList.add(commandManual);
}
return resultList;
}
private static List<CommandManualDTO> transformStepTwo(List<CommandManualDTO> commandManualDTOList) {
// for (CommandManualDTO commandManual : commandManualDTOList) {
//
//
//
// commandManual.setBigTypeCode(bigTypeCodeMap.get(commandManual.getBigTypeName()));
//
//
// if (StringUtils.isNotEmpty(commandManual.getSmallTypeCode())) {
// smallTypeCode = commandManual.getSmallTypeCode();
// } else {
// commandManual.setSmallTypeCode(smallTypeCode);
// }
//
// if (StringUtils.isNotEmpty(commandManual.getSmallTypeName())) {
// smallTypeName = commandManual.getSmallTypeName();
// } else {
// commandManual.setSmallTypeName(smallTypeName);
// }
//
//
// String atype = commandManual.getAtype();
// if (StringUtils.isEmpty(commandManual.getBtype())) {
// commandManual.setBtype(atype);
// }
//
// if (StringUtils.isEmpty(commandManual.getCtype())) {
// commandManual.setCtype(atype);
// }
//
// commandManual.setBigAndSmallCode(commandManual.getBigTypeCode() + "|" + commandManual.getSmallTypeCode());
//
//
// try {
// commandManual.setBigTypeCodeInt(Integer.valueOf(commandManual.getBigTypeCode()));
// } catch (Exception ignore) {
// logger.error("bigTypeCodeMap中未找到大类id: " + commandManual.getBigTypeName(), new RuntimeException("数据异常"));
// commandManual.setBigTypeCode("99999");
// commandManual.setBigTypeCodeInt(99999);
// }
//
// try {
// commandManual.setSmallTypeCodeInt(Integer.valueOf(commandManual.getSmallTypeCode()));
// } catch (Exception ignore) {
// logger.error("excel中小类编号为空: " + commandManual.getSmallTypeName(), new RuntimeException("数据异常"));
// commandManual.setSmallTypeCodeInt(99999);
// }
//
// String bigTypeId = bigTypeIdMap.get(commandManual.getBigTypeName());
// if (StringUtils.isEmpty(bigTypeId)) {
// logger.error("bigTypeIdMap中未找到大类id:" + commandManual.getBigTypeName(), new RuntimeException("数据异常"));
// bigTypeId = "99999";
// }
// commandManual.setBigTypeId(bigTypeId);
// resultList.add(commandManual);
// }
//
//
// return resultList;
return null;
}
}
......@@ -29,7 +29,7 @@ public class GeneratorCommandManualScript {
//TODO 1:事件,2:部件
public static final String CASE_TYPE = "2";
public static final String FILE_NAME = "部件0523.xlsx";
public static final String FILE_NAME = "井盖大小类扩展all.xlsx";
public static Map<String, String> bigTypeIdMap = new LinkedHashMap<>();
......@@ -38,7 +38,7 @@ public class GeneratorCommandManualScript {
protected static String root_path = "F:\\9Git140\\loit-build-common\\loit-build-component\\loit-build-deploy-env\\src\\main\\resources\\langfang";
public static final String CHECK_FILE_NAME = root_path + "\\4、验证.sql";
public static final String CHECK_FILE_NAME = root_path + "\\5、验证.sql";
public static void main(String[] args) {
......@@ -211,6 +211,17 @@ public class GeneratorCommandManualScript {
String jobConfig = FreeMarkerUtils.process("langfang" + "\\smallTypeScript.ftl", model);
FileUtils.append(configFilePath, jobConfig);
// String sql = "select * from geocode_component where big_type = '" + commandManualDTO.getBigTypeName() + "' and obj_type = '" + commandManualDTO.getSmallTypeName() + "';\n";
// FileUtils.append(root_path + "\\6、部件表geocode_component.sql", sql);
String sql2 = "update geocode_component set big_code = '" + commandManualDTO.getBigTypeCode() + "' , obj_type_code = '"
+ commandManualDTO.getSmallTypeCode() + "' , small_code = '" + commandManualDTO.getSmallTypeCode() + "' where big_type = '"
+ commandManualDTO.getBigTypeName() + "' and obj_type = '" + commandManualDTO.getSmallTypeName() + "';\n";
FileUtils.append(root_path + "\\6、部件表geocode_component.sql", sql2);
}
}
......@@ -257,7 +268,6 @@ public class GeneratorCommandManualScript {
model.put("cunit", climitUnit.getUnit());
String sql = "select * from digital_command_manual where manage_problem = '" + commandManualDTO.getManageProblem() + "' and big_type_id = '" + commandManualDTO.getBigTypeId() + "' and small_type = '" + commandManualDTO.getSmallTypeName() + "';\n";
FileUtils.append(CHECK_FILE_NAME, sql);
......
package com.loit.common.langfang;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class JdbcQueryUtils {
private static Logger logger = LoggerFactory.getLogger(JdbcQueryUtils.class);
/**
* 必要配置-数据库相关配置
*/
protected String url = "jdbc:mysql://10.39.10.228:3306/digital_city_test" + "?characterEncoding=utf8";
protected String driverName = "com.mysql.cj.jdbc.Driver";
protected String user = "root";
protected String password = "Loit!#2022A";
private Connection conn = null;
public void init() {
try {
Class.forName(driverName);
conn = DriverManager.getConnection(url, user, password);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
public static void main(String[] args) {
try {
JdbcQueryUtils generator = new JdbcQueryUtils();
generator.init();
List<String> columnList = new ArrayList<>();
columnList.add("id");
columnList.add("obj_code");
columnList.add("obj_name");
List<Map<String, String>> result = generator.queryDictInfo("select id, obj_code, obj_name from base_base_casetype where level = 2 and case_type = 2 and obj_name = '交通设施'", columnList);
System.out.println(result.isEmpty());
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
System.exit(0);
}
public List<Map<String, String>> queryDictInfo(String sql, List<String> columnList) {
List<Map<String, String>> resultList = new ArrayList();
PreparedStatement pstate = null;
try {
pstate = conn.prepareStatement(sql);
ResultSet results = pstate.executeQuery();
while (results.next()) {
Map<String, String> objInfo = new LinkedHashMap<>();
for (String col : columnList) {
objInfo.put(col, results.getString(col));
}
resultList.add(objInfo);
}
} catch (SQLException e) {
logger.error(e.getMessage(), e);
} finally {
try {
pstate.close();
} catch (SQLException ignore) {
}
}
return resultList;
}
public void close() {
try {
conn.close();
} catch (SQLException ignore) {
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论