Browse Source

修改模型3、4:修复一些bug

main
sjh 1 year ago
parent
commit
267ac92090
  1. 12
      src/main/java/com/biutag/supervision/service/BusinessDepartService.java
  2. 70
      src/main/java/com/biutag/supervision/service/ModelClueService.java

12
src/main/java/com/biutag/supervision/service/BusinessDepartService.java

@ -61,23 +61,27 @@ public class BusinessDepartService extends ServiceImpl<BusinessDepartMapper, Bus
// generate(happenTime);
// }
if (businessQueryParam.getDepartName() != null && businessQueryParam.getDepartName().equals("运行测试1")) {
System.out.println("开始执行测试1");
modelClueService.generate(1);
System.out.println("执行完毕");
System.out.println("测试1执行完毕");
return null;
}
if (businessQueryParam.getDepartName() != null && businessQueryParam.getDepartName().equals("运行测试2")) {
System.out.println("开始执行测试2");
modelClueService.generate(2);
System.out.println("执行完毕");
System.out.println("测试2执行完毕");
return null;
}
if (businessQueryParam.getDepartName() != null && businessQueryParam.getDepartName().equals("运行测试3")) {
System.out.println("开始执行测试3");
modelClueService.generate(3);
System.out.println("执行完毕");
System.out.println("测试3执行完毕");
return null;
}
if (businessQueryParam.getDepartName() != null && businessQueryParam.getDepartName().equals("运行测试4")) {
System.out.println("开始执行测试4");
modelClueService.generate(4);
System.out.println("执行完毕");
System.out.println("测试4执行完毕");
return null;
}
if (businessQueryParam.getDepartName() != null && businessQueryParam.getDepartName().equals("导入单位")) {

70
src/main/java/com/biutag/supervision/service/ModelClueService.java

@ -187,12 +187,14 @@ public class ModelClueService extends ServiceImpl<ModelClueMapper, ModelClue> {
public List<ModelClue> getModelClueBySql(String sql, Integer modelId) {
List<ModelClue> modelClues = new ArrayList<>();
if (modelId == 2) { // 2号模型:行政、刑事案件受立案不及时问题监督模型
return getModelCluesForModel2(modelClues);
return getModelCluesForModel2(modelClues, sql);
} else if (modelId == 4) { // 4号模型:疑似漏登执法办案场所问题监督模型
System.out.println("测试4开始查询数据库");
List<Map<String, Object>> maps = modelClueDataMapper.selectByUniqueKeys(sql);
System.out.println("测试4查询数据库完毕");
for (Map<String, Object> data : maps) {
ModelClue modelClue = new ModelClue();
modelClue.setData(JSONObject.toJSONString(maps));
modelClue.setData(JSONObject.toJSONString(data));
modelClue.setStatus(0);
modelClue.setInvolveDepartId((String) data.get("involve_depart_id"));
modelClue.setInvolveDepartName((String) data.get("involve_depart_name"));
@ -206,7 +208,9 @@ public class ModelClueService extends ServiceImpl<ModelClueMapper, ModelClue> {
}
return modelClues;
} else {
System.out.println("测试" + modelId + "开始查询数据库");
modelClues = modelClueDataMapper.selectDataByDynamicSql(sql);
System.out.println("测试" + modelId + "查询数据库完毕");
}
List<String> uniqueKeys = modelClues.stream().map(ModelClue::getUniqueKey).filter(k -> k != null && !k.isEmpty()).toList();
List<String> oldUniqueKeys = this.listObjs(new LambdaQueryWrapper<ModelClue>().select(ModelClue::getUniqueKey).eq(ModelClue::getStatus, 0).eq(ModelClue::getModelId, modelId), String::valueOf);
@ -261,10 +265,11 @@ public class ModelClueService extends ServiceImpl<ModelClueMapper, ModelClue> {
return needsInsertModelClues;
}
private List<ModelClue> getModelCluesForModel2(List<ModelClue> modelClues) {
private List<ModelClue> getModelCluesForModel2(List<ModelClue> modelClues, String param) {
List<ModelClue> modelClues1 = new ArrayList<>();
List<String> params = parseSqlForModel2(param);
String preSql = "SELECT a.jjdbh AS uniqueKey, a.jjdbh AS negative_id, a.gxdwmc AS involve_depart_name, a.gxdwdm AS involve_depart_id FROM dwd_asj_zhtx_jjd a WHERE a.jqxzdm NOT LIKE '11%' AND a.jqxzdm NOT LIKE '99%' AND a.bjnr LIKE '%";
String postSql = "%' AND NOT EXISTS (SELECT 1 FROM dwd_asj_sjjhygx_jjcjxxb b WHERE b.BARLXDH = a.bjdh) AND a.cjsj BETWEEN '2024-01-01 00:00:00' AND '2024-10-23 00:00:00';";
String postSql = "%' AND NOT EXISTS (SELECT 1 FROM dwd_asj_sjjhygx_jjcjxxb b WHERE b.BARLXDH = a.bjdh) AND a.bjsj BETWEEN '" + params.get(0) + " 00:00:00' AND '" + params.get(1) + " 00:00:00';";
genarateModelCluesForModel2(preSql, postSql, modelClues1);
List<String> uniqueKeys = modelClues1.stream().map(ModelClue::getUniqueKey).filter(k -> k != null && !k.isEmpty()).toList();
if (!uniqueKeys.isEmpty()) {
@ -288,7 +293,7 @@ public class ModelClueService extends ServiceImpl<ModelClueMapper, ModelClue> {
}
List<ModelClue> modelClues2 = new ArrayList<>();
String preSql2 = "SELECT a.jjdbh AS uniqueKey, a.jjdbh AS negative_id, a.gxdwmc AS involve_depart_name, a.gxdwdm AS involve_depart_id FROM dwd_asj_zhtx_jjd a WHERE a.jqxzdm NOT LIKE '11%' AND a.jqxzdm NOT LIKE '99%' AND a.bjnr LIKE '%";
String postSql2 = "%' AND EXISTS (SELECT 1 FROM dwd_asj_sjjhygx_jjcjxxb b WHERE b.lasj IS NOT NULL AND b.basj < DATE_SUB(STR_TO_DATE(b.lasj, '%Y%m%d%H%i%s') , INTERVAL 7 DAY) AND b.BARLXDH = a.bjdh AND STR_TO_DATE(b.lasj, '%Y%m%d%H%i%s') > a.cjsj) ORDER BY a.cjsj desc LIMIT 1;";
String postSql2 = "%' AND EXISTS (SELECT 1 FROM dwd_asj_sjjhygx_jjcjxxb b WHERE b.lasj IS NOT NULL AND b.basj < DATE_SUB(STR_TO_DATE(b.lasj, '%Y%m%d%H%i%s') , INTERVAL 7 DAY) AND b.BARLXDH = a.bjdh AND STR_TO_DATE(b.lasj, '%Y%m%d%H%i%s') > a.bjsj) AND a.bjsj BETWEEN '" + params.get(0) + " 00:00:00' AND '" + params.get(1) + " 00:00:00' ORDER BY a.bjsj desc LIMIT 1;";
genarateModelCluesForModel2(preSql2, postSql2, modelClues2);
List<String> uniqueKeys2 = modelClues2.stream().map(ModelClue::getUniqueKey).filter(k -> k != null && !k.isEmpty()).toList();
if (!uniqueKeys2.isEmpty()) {
@ -316,22 +321,35 @@ public class ModelClueService extends ServiceImpl<ModelClueMapper, ModelClue> {
}
private void genarateModelCluesForModel2(String preSql, String postSql, List<ModelClue> modelClues) {
System.out.println("测试2开始查询数据库 盗");
List<ModelClue> modelClues1 = modelClueDataMapper.selectDataByDynamicSql(preSql + "盗" + postSql);
System.out.println("测试2开始查询数据库 骗");
List<ModelClue> modelClues2 = modelClueDataMapper.selectDataByDynamicSql(preSql + "骗" + postSql);
System.out.println("测试2开始查询数据库 强奸");
List<ModelClue> modelClues3 = modelClueDataMapper.selectDataByDynamicSql(preSql + "强奸" + postSql);
System.out.println("测试2开始查询数据库 抢");
List<ModelClue> modelClues4 = modelClueDataMapper.selectDataByDynamicSql(preSql + "抢" + postSql);
System.out.println("测试2开始查询数据库 10岁");
List<ModelClue> modelClues5 = modelClueDataMapper.selectDataByDynamicSql(preSql + "10岁" + postSql);
System.out.println("测试2开始查询数据库 11岁");
List<ModelClue> modelClues6 = modelClueDataMapper.selectDataByDynamicSql(preSql + "11岁" + postSql);
System.out.println("测试2开始查询数据库 12岁");
List<ModelClue> modelClues7 = modelClueDataMapper.selectDataByDynamicSql(preSql + "12岁" + postSql);
System.out.println("测试2开始查询数据库 13岁");
List<ModelClue> modelClues8 = modelClueDataMapper.selectDataByDynamicSql(preSql + "13岁" + postSql);
System.out.println("测试2开始查询数据库 14岁");
List<ModelClue> modelClues9 = modelClueDataMapper.selectDataByDynamicSql(preSql + "14岁" + postSql);
System.out.println("测试2开始查询数据库 15岁");
List<ModelClue> modelClues10 = modelClueDataMapper.selectDataByDynamicSql(preSql + "15岁" + postSql);
System.out.println("测试2开始查询数据库 16岁");
List<ModelClue> modelClues11 = modelClueDataMapper.selectDataByDynamicSql(preSql + "16岁" + postSql);
System.out.println("测试2开始查询数据库 未成年");
List<ModelClue> modelClues12 = modelClueDataMapper.selectDataByDynamicSql(preSql + "未成年" + postSql);
modelClues.addAll(Stream.of(modelClues1, modelClues2, modelClues3, modelClues4, modelClues5, modelClues6, modelClues7, modelClues8, modelClues9, modelClues10, modelClues11, modelClues12)
.flatMap(List::stream)
.collect(Collectors.toMap(ModelClue::getUniqueKey, data -> data, (existing, replacement) -> existing))
.values());
System.out.println("测试2查询数据库完毕");
}
private static String getDateString(Object param) {
@ -344,9 +362,21 @@ public class ModelClueService extends ServiceImpl<ModelClueMapper, ModelClue> {
Instant instant = parse.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); return formatter.format(localDateTime);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return formatter.format(localDateTime);
} catch (Exception e) {
log.info("日期转换异常{}", time, e);
try {
time = String.valueOf(param);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date parse = sdf.parse(time);
Instant instant = parse.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return formatter.format(localDateTime);
} catch (Exception ex) {
log.info("日期转换异常{}", time, ex);
}
}
}
return " ";
@ -378,10 +408,21 @@ public class ModelClueService extends ServiceImpl<ModelClueMapper, ModelClue> {
}
public static String formatStringDate(String date) {
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime dateTime = LocalDateTime.parse(date, inputFormatter);
try {
DateTimeFormatter inputFormatterWithSeconds = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
LocalDateTime dateTime = LocalDateTime.parse(date, inputFormatterWithSeconds);
return dateTime.format(outputFormatter);
} catch (Exception e) {
try {
DateTimeFormatter inputFormatterWithMinutes = DateTimeFormatter.ofPattern("yyyyMMddHHmm");
LocalDateTime dateTime = LocalDateTime.parse(date, inputFormatterWithMinutes);
return dateTime.withSecond(0).format(outputFormatter);
} catch (Exception ex) {
log.info("日期转换异常", ex);
}
}
return " ";
}
public static String getNowTime() {
@ -389,4 +430,15 @@ public class ModelClueService extends ServiceImpl<ModelClueMapper, ModelClue> {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return now.format(formatter);
}
public static List<String> parseSqlForModel2(String param) {
List<String> result = new ArrayList<>();
String date1 = param.substring(0, 8);
String date2 = param.substring(8, 16);
String formattedDate1 = date1.substring(0, 4) + "-" + date1.substring(4, 6) + "-" + date1.substring(6, 8);
String formattedDate2 = date2.substring(0, 4) + "-" + date2.substring(4, 6) + "-" + date2.substring(6, 8);
result.add(formattedDate1);
result.add(formattedDate2);
return result;
}
}

Loading…
Cancel
Save