Browse Source

重构模型4:疑似漏登执法办案场所问题监督模型

main
xyx 1 year ago
parent
commit
ad1180c6df
  1. 6
      src/main/java/com/biutag/supervision/pojo/entity/ModelClue.java
  2. 8
      src/main/java/com/biutag/supervision/pojo/entity/SupExternalDepart.java
  3. 352
      src/main/java/com/biutag/supervision/service/ModelClueService.java

6
src/main/java/com/biutag/supervision/pojo/entity/ModelClue.java

@ -68,18 +68,24 @@ public class ModelClue {
@TableField("unique_key")
private String uniqueKey;
// 总警情数
@TableField(exist = false)
private Long zjjs;
// 执法场所登记数
@TableField(exist = false)
private Long zfcsdjs;
// 比例
@TableField(exist = false)
private BigDecimal bl;
@TableField(exist = false)
private String parentId;
@TableField(exist = false)
private String thisId;
@TableField(exist = false)
private Integer departLevel;

8
src/main/java/com/biutag/supervision/pojo/entity/SupExternalDepart.java

@ -40,6 +40,14 @@ public class SupExternalDepart {
@TableField("internal_short_name")
private String internalShortName;
// 单位级别
@TableField("level")
private Integer level;
// 上级单位id
@TableField("pid")
private String pid;
// 状态:0-启用,1-禁用
@TableField("status")
private Integer status;

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

@ -189,159 +189,9 @@ 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, sql);
return getModelCluesForModel2(sql, modelClues);
} else if (modelId == 4) { // 4号模型:疑似漏登执法办案场所问题监督模型
System.out.println("测试4开始查询数据库");
List<Map<String, Object>> maps = modelClueDataMapper.selectByUniqueKeys(sql);
BigDecimal avgPercentage = null;
if (!maps.isEmpty()) {
avgPercentage = (BigDecimal) maps.get(0).get("avg_percentage");
}
System.out.println("测试4查询数据库完毕");
List<ModelClue> modelClues3 = new ArrayList<>();
List<ModelClue> modelClues4 = new ArrayList<>();
for (Map<String, Object> data : maps) {
SupDepart supDepart = supDepartMapper.selectOne(new LambdaQueryWrapper<SupDepart>().eq(SupDepart::getCode, data.get("involve_depart_id")));
if (supDepart != null && (supDepart.getLevel() != 4)) {
ModelClue modelClue = new ModelClue();
modelClue.setData(JSONObject.toJSONString(data));
modelClue.setStatus(0);
modelClue.setInvolveDepartId((String) data.get("involve_depart_id"));
modelClue.setInvolveDepartName((String) data.get("involve_depart_name"));
modelClue.setZjjs((Long) data.get("zjjs"));
modelClue.setZfcsdjs((Long) data.get("zfcsdjs"));
modelClue.setBl((BigDecimal) data.get("bl"));
modelClue.setDepartLevel(0);
modelClue.setThingDesc("在" + getNowTime() + "之前的1个月内," + data.get("involve_depart_name")
+ "的总警情数为" + data.get("zjjs")
+ ",执法场所登记数为" + data.get("zfcsdjs")
+ ",每100起警情执法场所登记比例为" + data.get("bl")
+ ",低于全市平均值(" + data.get("avg_percentage")
+ "%),疑似漏登执法办案场所。");
modelClues3.add(modelClue);
}
}
for (Map<String, Object> data : maps) {
SupDepart supDepart = supDepartMapper.selectOne(new LambdaQueryWrapper<SupDepart>().eq(SupDepart::getCode, data.get("involve_depart_id")));
if (supDepart != null && (supDepart.getLevel() == 4)) {
SupDepart supDepart2 = supDepartMapper.selectOne(new LambdaQueryWrapper<SupDepart>().eq(SupDepart::getId, supDepart.getPid()));
if (supDepart2 != null) {
ModelClue modelClue = new ModelClue();
modelClue.setData(JSONObject.toJSONString(data));
modelClue.setStatus(0);
modelClue.setInvolveDepartId((String) data.get("involve_depart_id"));// 4039203948
modelClue.setInvolveDepartName(supDepart2.getShortName());
modelClue.setZjjs((Long) data.get("zjjs"));
modelClue.setZfcsdjs((Long) data.get("zfcsdjs"));
modelClue.setParentId(supDepart2.getCode());
modelClue.setBl((BigDecimal) data.get("bl"));
modelClue.setDepartLevel(4);
modelClue.setThingDesc("在" + getNowTime() + "之前的1个月内," + supDepart2.getShortName()
+ "的总警情数为" + data.get("zjjs")
+ ",执法场所登记数为" + data.get("zfcsdjs")
+ ",每100起警情执法场所登记比例为" + data.get("bl")
+ ",低于全市平均值(" + data.get("avg_percentage")
+ "%),疑似漏登执法办案场所。");
modelClues4.add(modelClue);
}
}
}
Iterator<ModelClue> iterator4 = modelClues4.iterator();
while (iterator4.hasNext()) {
ModelClue modelClue4 = iterator4.next();
Iterator<ModelClue> iterator3 = modelClues3.iterator();
boolean found = false;
while (iterator3.hasNext()) {
ModelClue modelClue3 = iterator3.next();
if (modelClue4.getParentId().equals(modelClue3.getInvolveDepartId())) {
modelClue3.setZjjs(modelClue4.getZjjs() + modelClue3.getZjjs());
modelClue3.setZfcsdjs(modelClue4.getZfcsdjs() + modelClue3.getZfcsdjs());
BigDecimal zfcsdjs = BigDecimal.valueOf(modelClue3.getZfcsdjs());
BigDecimal zjjs = BigDecimal.valueOf(modelClue3.getZjjs());
BigDecimal bl = zfcsdjs.divide(zjjs, 2, RoundingMode.HALF_UP);
modelClue3.setBl(bl);
modelClue3.setDepartLevel(3);
modelClue4.setDepartLevel(0);
found = true;
break;
}
}
if (!found) {
SupDepart supDepart = supDepartMapper.selectOne(new LambdaQueryWrapper<SupDepart>().eq(SupDepart::getCode, modelClue4.getInvolveDepartId()));
SupDepart supDepart2 = new SupDepart();
if (supDepart != null && (supDepart.getLevel() == 4)) {
supDepart2 = supDepartMapper.selectOne(new LambdaQueryWrapper<SupDepart>().eq(SupDepart::getId, supDepart.getPid()));
}
ModelClue newModelClue3 = new ModelClue();
newModelClue3.setData(modelClue4.getData());
newModelClue3.setStatus(0);
newModelClue3.setInvolveDepartId(supDepart2.getCode());
newModelClue3.setInvolveDepartName(supDepart2.getShortName());
newModelClue3.setZjjs(modelClue4.getZjjs());
newModelClue3.setZfcsdjs(modelClue4.getZfcsdjs());
BigDecimal zfcsdjs = BigDecimal.valueOf(newModelClue3.getZfcsdjs());
BigDecimal zjjs = BigDecimal.valueOf(newModelClue3.getZjjs());
BigDecimal bl = zfcsdjs.divide(zjjs, 2, RoundingMode.HALF_UP);
newModelClue3.setBl(bl);
newModelClue3.setDepartLevel(3);
modelClue4.setDepartLevel(0);
modelClues3.add(newModelClue3);
}
}
// for (ModelClue modelClue4 : modelClues4) {
// for (ModelClue modelClue3 : modelClues3) {
// if (modelClue4.getParentId().equals(modelClue3.getInvolveDepartId())) {
// modelClue3.setZjjs(modelClue4.getZjjs() + modelClue3.getZjjs());
// modelClue3.setZfcsdjs(modelClue4.getZfcsdjs() + modelClue3.getZfcsdjs());
// BigDecimal zfcsdjs = BigDecimal.valueOf(modelClue3.getZfcsdjs());
// BigDecimal zjjs = BigDecimal.valueOf(modelClue3.getZjjs());
// BigDecimal bl = zfcsdjs.divide(zjjs, 2, RoundingMode.HALF_UP);
// modelClue3.setBl(bl);
// modelClue3.setDepartLevel(3);
// modelClue4.setDepartLevel(0);
// break;
// }
// SupDepart supDepart = supDepartMapper.selectOne(new LambdaQueryWrapper<SupDepart>().eq(SupDepart::getCode, modelClue4.getInvolveDepartId()));
// SupDepart supDepart2 = new SupDepart();
// if (supDepart != null && (supDepart.getLevel() == 4)) {
// supDepart2 = supDepartMapper.selectOne(new LambdaQueryWrapper<SupDepart>().eq(SupDepart::getId, supDepart.getPid()));
// }
// ModelClue newModelClue3 = new ModelClue();
// newModelClue3.setData(modelClue4.getData());
// newModelClue3.setStatus(0);
// newModelClue3.setInvolveDepartId(supDepart2.getCode());
// newModelClue3.setInvolveDepartName(supDepart2.getShortName());
// newModelClue3.setZjjs(modelClue4.getZjjs());
// newModelClue3.setZfcsdjs(modelClue4.getZfcsdjs());
// BigDecimal zfcsdjs = BigDecimal.valueOf(newModelClue3.getZfcsdjs());
// BigDecimal zjjs = BigDecimal.valueOf(newModelClue3.getZjjs());
// BigDecimal bl = zfcsdjs.divide(zjjs, 2, RoundingMode.HALF_UP);
// newModelClue3.setBl(bl);
// newModelClue3.setDepartLevel(3);
// modelClue4.setDepartLevel(0);
// modelClues3.add(newModelClue3);
// }
// }
Iterator<ModelClue> iterator = modelClues3.iterator();
while (iterator.hasNext()) {
ModelClue modelClue = iterator.next();
if (modelClue.getBl().compareTo(avgPercentage) > 0) {
iterator.remove();
}
}
for (ModelClue modelClue : modelClues3) {
if (modelClue.getDepartLevel() == 3) {
modelClue.setThingDesc("在" + getNowTime() + "之前的1个月内," + modelClue.getInvolveDepartName()
+ "的总警情数为" + modelClue.getZjjs()
+ ",执法场所登记数为" + modelClue.getZfcsdjs()
+ ",每100起警情执法场所登记比例为" + modelClue.getBl()
+ ",低于全市平均值(" + avgPercentage
+ "%),疑似漏登执法办案场所。");
}
}
modelClues.addAll(modelClues3);
return modelClues;
return getModelCluesForModel4(sql, modelClues);
} else {
System.out.println("测试" + modelId + "开始查询数据库");
modelClues = modelClueDataMapper.selectDataByDynamicSql(sql);
@ -400,7 +250,195 @@ public class ModelClueService extends ServiceImpl<ModelClueMapper, ModelClue> {
return needsInsertModelClues;
}
private List<ModelClue> getModelCluesForModel2(List<ModelClue> modelClues, String param) {
private List<ModelClue> getModelCluesForModel4(String param, List<ModelClue> modelClues) {
System.out.println("测试4开始查询数据库");
List<String> params = parseSqlForModel2(param);
String jjdSql = "SELECT gxdwdm AS involve_depart_id, gxdwmc AS involve_depart_name, COUNT(*) AS zjjs FROM dwd_asj_zhtx_jjd WHERE cjsj BETWEEN '" + params.get(0) + " 00:00:00' AND '" + params.get(1) + " 00:00:00' GROUP BY gxdwdm, gxdwmc;";
String zfqySql = "SELECT csid AS involve_depart_id, COUNT(*) AS zfcsdjs FROM dwd_ry_zfba_zfqywfryb WHERE STR_TO_DATE( djsj, '%Y%m%d%H%i%s' ) BETWEEN '" + params.get(0) + " 00:00:00' AND '" + params.get(1) + " 00:00:00' GROUP BY csid;";
List<Map<String, Object>> jjdmaps = modelClueDataMapper.selectByUniqueKeys(jjdSql);
List<Map<String, Object>> zfqymaps = modelClueDataMapper.selectByUniqueKeys(zfqySql);
System.out.println("测试4查询数据库完毕");
if (jjdmaps.isEmpty()) {
return modelClues;
}
List<ModelClue> jjdModelClues = new ArrayList<>();
for (Map<String, Object> data : jjdmaps) {
SupExternalDepart supExternalDepart = supExternalDepartMapper.selectOne(new LambdaQueryWrapper<SupExternalDepart>().eq(SupExternalDepart::getExternalId, data.get("involve_depart_id")));
if (supExternalDepart != null) {
ModelClue modelClue = new ModelClue();
modelClue.setData(JSONObject.toJSONString(data));
modelClue.setInvolveDepartId(supExternalDepart.getExternalId());
modelClue.setInvolveDepartName(supExternalDepart.getExternalName());
modelClue.setZjjs((Long) data.get("zjjs"));
modelClue.setDepartLevel(supExternalDepart.getLevel());
modelClue.setParentId(supExternalDepart.getPid());
modelClue.setThisId(supExternalDepart.getInternalId());
jjdModelClues.add(modelClue);
}
}
List<ModelClue> jjdModelClues3 = new ArrayList<>(jjdModelClues.stream().filter(clue -> clue.getDepartLevel() == 3).toList());
List<ModelClue> jjdModelClues4 = new ArrayList<>(jjdModelClues.stream().filter(clue -> clue.getDepartLevel() == 4).toList());
List<ModelClue> jjdModelClues5 = new ArrayList<>(jjdModelClues.stream().filter(clue -> clue.getDepartLevel() == 5).toList());
mergeModelClues(jjdModelClues5, jjdModelClues4, 1);
mergeModelClues(jjdModelClues4, jjdModelClues3, 1);
List<ModelClue> zfqymModelClues = new ArrayList<>();
for (Map<String, Object> data : zfqymaps) {
SupExternalDepart supExternalDepart = supExternalDepartMapper.selectOne(new LambdaQueryWrapper<SupExternalDepart>().eq(SupExternalDepart::getExternalId, data.get("involve_depart_id")));
if (supExternalDepart != null) {
ModelClue modelClue = new ModelClue();
modelClue.setData(JSONObject.toJSONString(data));
modelClue.setInvolveDepartId(supExternalDepart.getExternalId());
modelClue.setZfcsdjs((Long) data.get("zfcsdjs"));
modelClue.setDepartLevel(supExternalDepart.getLevel());
modelClue.setParentId(supExternalDepart.getPid());
modelClue.setThisId(supExternalDepart.getInternalId());
zfqymModelClues.add(modelClue);
}
}
List<ModelClue> zfqymModelClues3 = new ArrayList<>(zfqymModelClues.stream().filter(clue -> clue.getDepartLevel() == 3).toList());
List<ModelClue> zfqymModelClues4 = new ArrayList<>(zfqymModelClues.stream().filter(clue -> clue.getDepartLevel() == 4).toList());
List<ModelClue> zfqymModelClues5 = new ArrayList<>(zfqymModelClues.stream().filter(clue -> clue.getDepartLevel() == 5).toList());
mergeModelClues(zfqymModelClues5, zfqymModelClues4, 2);
mergeModelClues(zfqymModelClues4, zfqymModelClues3, 2);
BigDecimal avgPercentage = null;
if (!zfqymModelClues3.isEmpty()) {
BigDecimal zjjsTotal = BigDecimal.valueOf(jjdModelClues3.stream().mapToLong(ModelClue::getZjjs).sum());
BigDecimal zfcsdjsTotal = BigDecimal.valueOf(zfqymModelClues3.stream().mapToLong(ModelClue::getZfcsdjs).sum());
// 全市平均数
avgPercentage = zfcsdjsTotal.divide(zjjsTotal, 2, RoundingMode.HALF_UP);
} else {
avgPercentage = BigDecimal.ZERO;
}
for (ModelClue jjdModelClue : jjdModelClues3) {
if (zfqymModelClues3.isEmpty()) {
jjdModelClue.setStatus(0);
jjdModelClue.setThingDesc("在" + params.get(0) + "到" + params.get(1) + "之间," + jjdModelClue.getInvolveDepartName()
+ "的总警情数为" + jjdModelClue.getZjjs()
+ ",执法场所登记数为0"
+ ",每100起警情执法场所登记比例为0"
+ ",低于全市平均值(" + avgPercentage
+ "%),疑似漏登执法办案场所。");
} else {
Iterator<ModelClue> iterator1 = zfqymModelClues3.iterator();
while (iterator1.hasNext()) {
ModelClue zfqymModelClue = iterator1.next();
if (jjdModelClue.getInvolveDepartId().equals(zfqymModelClue.getInvolveDepartId())) {
jjdModelClue.setZfcsdjs(zfqymModelClue.getZfcsdjs());
BigDecimal zfcsdjs = BigDecimal.valueOf(jjdModelClue.getZfcsdjs());
BigDecimal zjjs = BigDecimal.valueOf(jjdModelClue.getZjjs());
BigDecimal bl = zfcsdjs.divide(zjjs, 2, RoundingMode.HALF_UP);
jjdModelClue.setBl(bl);
jjdModelClue.setStatus(0);
jjdModelClue.setThingDesc("在" + params.get(0) + "到" + params.get(1) + "之间," + jjdModelClue.getInvolveDepartName()
+ "的总警情数为" + jjdModelClue.getZjjs()
+ ",执法场所登记数为" + jjdModelClue.getZfcsdjs()
+ ",每100起警情执法场所登记比例为" + jjdModelClue.getBl()
+ ",低于全市平均值(" + avgPercentage
+ "%),疑似漏登执法办案场所。");
iterator1.remove();
break;
}
}
}
}
modelClues.addAll(jjdModelClues3);
return modelClues;
}
/*
private List<ModelClue> getModelCluesForModel4(String sql, List<ModelClue> modelClues) {
System.out.println("测试4开始查询数据库");
List<Map<String, Object>> maps = modelClueDataMapper.selectByUniqueKeys(sql);
System.out.println("测试4查询数据库完毕");
// 全市平均数
BigDecimal avgPercentage = null;
if (!maps.isEmpty()) {
avgPercentage = (BigDecimal) maps.get(0).get("avg_percentage");
}
List<ModelClue> oriModelClues = new ArrayList<>();
for (Map<String, Object> data : maps) {
SupExternalDepart supExternalDepart = supExternalDepartMapper.selectOne(new LambdaQueryWrapper<SupExternalDepart>().eq(SupExternalDepart::getExternalId, data.get("involve_depart_id")));
if (supExternalDepart != null) {
ModelClue modelClue = new ModelClue();
modelClue.setData(JSONObject.toJSONString(data));
modelClue.setInvolveDepartId(supExternalDepart.getExternalId());
modelClue.setInvolveDepartName(supExternalDepart.getExternalName());
modelClue.setZjjs((Long) data.get("zjjs"));
modelClue.setZfcsdjs((Long) data.get("zfcsdjs"));
modelClue.setBl((BigDecimal) data.get("bl"));
modelClue.setDepartLevel(supExternalDepart.getLevel());
modelClue.setParentId(supExternalDepart.getPid());
modelClue.setThisId(supExternalDepart.getInternalId());
oriModelClues.add(modelClue);
}
}
List<ModelClue> modelClues3 = new ArrayList<>(oriModelClues.stream().filter(clue -> clue.getDepartLevel() == 3).toList());
List<ModelClue> modelClues4 = new ArrayList<>(oriModelClues.stream().filter(clue -> clue.getDepartLevel() == 4).toList());
List<ModelClue> modelClues5 = new ArrayList<>(oriModelClues.stream().filter(clue -> clue.getDepartLevel() == 5).toList());
mergeModelClues(modelClues5, modelClues3);
mergeModelClues(modelClues4, modelClues3);
Iterator<ModelClue> iterator = modelClues3.iterator();
while (iterator.hasNext()) {
ModelClue modelClue = iterator.next();
if (modelClue.getBl().compareTo(avgPercentage) > 0) {
iterator.remove();
}
}
for (ModelClue modelClue : modelClues3) {
modelClue.setStatus(0);
modelClue.setThingDesc("在" + getNowTime() + "之前的1个月内," + modelClue.getInvolveDepartName()
+ "的总警情数为" + modelClue.getZjjs()
+ ",执法场所登记数为" + modelClue.getZfcsdjs()
+ ",每100起警情执法场所登记比例为" + modelClue.getBl()
+ ",低于全市平均值(" + avgPercentage
+ "%),疑似漏登执法办案场所。");
}
modelClues.addAll(modelClues3);
return modelClues;
}
*/
private void mergeModelClues(List<ModelClue> modelClues2, List<ModelClue> modelClues1 , int no) {
for (ModelClue modelClue2 : modelClues2) {
Iterator<ModelClue> iterator1 = modelClues1.iterator();
boolean found = false;
while (iterator1.hasNext()) {
ModelClue modelClue1 = iterator1.next();
if (modelClue2.getParentId().equals(modelClue1.getThisId())) {
if (no == 1) {
modelClue1.setZjjs(modelClue2.getZjjs() + modelClue1.getZjjs());
} else if (no == 2) {
modelClue1.setZfcsdjs(modelClue2.getZfcsdjs() + modelClue1.getZfcsdjs());
}
modelClue1.setData(modelClue1.getData() + modelClue2.getData());
found = true;
break;
}
}
if (!found) {
SupExternalDepart supExternalDepart = supExternalDepartMapper.selectOne(new LambdaQueryWrapper<SupExternalDepart>().eq(SupExternalDepart::getInternalId, modelClue2.getParentId()));
if (supExternalDepart != null) {
ModelClue newModelClue = new ModelClue();
newModelClue.setData(modelClue2.getData());
newModelClue.setInvolveDepartId(supExternalDepart.getExternalId());
newModelClue.setInvolveDepartName(supExternalDepart.getExternalName());
newModelClue.setParentId(supExternalDepart.getPid());
newModelClue.setThisId(supExternalDepart.getInternalId());
newModelClue.setDepartLevel(supExternalDepart.getLevel());
if (no == 1) {
newModelClue.setZjjs(modelClue2.getZjjs());
} else if (no == 2) {
newModelClue.setZfcsdjs(modelClue2.getZfcsdjs());
}
modelClues1.add(newModelClue);
} else {
System.out.println("父级部门" + modelClue2.getParentId() + "不存在");
}
}
}
}
private List<ModelClue> getModelCluesForModel2(String param, List<ModelClue> modelClues) {
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 LIKE '01%' OR a.jqxzdm LIKE '02%') AND a.bjnr LIKE '%";
@ -449,10 +487,10 @@ public class ModelClueService extends ServiceImpl<ModelClueMapper, ModelClue> {
String jqxz = "";
jqxz = summarizeAttribute(data, jqxz);
modelClue.setThingDesc("该" + jqxz
+ "警情接警单编号为" + data.get("jjdbh")
+ ",报案时间为" + getDateString(data.get("bjsj"))
+ ",案件编号为" + data.get("ajbh")
+ ",立案时间为" + formatStringDate((String) data.get("lasj"))
+ "警情接警单编号为" + data.get("jjdbh")
+ ",报案时间为" + getDateString(data.get("bjsj"))
+ ",案件编号为" + data.get("ajbh")
+ ",立案时间为" + formatStringDate((String) data.get("lasj"))
+ ",报案时间与立案时间超过7天,受立案不及时。");
break;
}

Loading…
Cancel
Save