From ad1180c6df3da120e53581a7e1f05ed4bd20b8e7 Mon Sep 17 00:00:00 2001 From: xyx <13570059550@163.com> Date: Sun, 27 Oct 2024 20:07:01 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E6=A8=A1=E5=9E=8B4=EF=BC=9A?= =?UTF-8?q?=E7=96=91=E4=BC=BC=E6=BC=8F=E7=99=BB=E6=89=A7=E6=B3=95=E5=8A=9E?= =?UTF-8?q?=E6=A1=88=E5=9C=BA=E6=89=80=E9=97=AE=E9=A2=98=E7=9B=91=E7=9D=A3?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supervision/pojo/entity/ModelClue.java | 6 + .../pojo/entity/SupExternalDepart.java | 8 + .../supervision/service/ModelClueService.java | 352 ++++++++++-------- 3 files changed, 209 insertions(+), 157 deletions(-) diff --git a/src/main/java/com/biutag/supervision/pojo/entity/ModelClue.java b/src/main/java/com/biutag/supervision/pojo/entity/ModelClue.java index a26b5df..946803d 100644 --- a/src/main/java/com/biutag/supervision/pojo/entity/ModelClue.java +++ b/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; diff --git a/src/main/java/com/biutag/supervision/pojo/entity/SupExternalDepart.java b/src/main/java/com/biutag/supervision/pojo/entity/SupExternalDepart.java index a1f3065..22f9493 100644 --- a/src/main/java/com/biutag/supervision/pojo/entity/SupExternalDepart.java +++ b/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; diff --git a/src/main/java/com/biutag/supervision/service/ModelClueService.java b/src/main/java/com/biutag/supervision/service/ModelClueService.java index 6d22ab5..1b64b2d 100644 --- a/src/main/java/com/biutag/supervision/service/ModelClueService.java +++ b/src/main/java/com/biutag/supervision/service/ModelClueService.java @@ -189,159 +189,9 @@ public class ModelClueService extends ServiceImpl { public List getModelClueBySql(String sql, Integer modelId) { List 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> maps = modelClueDataMapper.selectByUniqueKeys(sql); - BigDecimal avgPercentage = null; - if (!maps.isEmpty()) { - avgPercentage = (BigDecimal) maps.get(0).get("avg_percentage"); - } - System.out.println("测试4查询数据库完毕"); - List modelClues3 = new ArrayList<>(); - List modelClues4 = new ArrayList<>(); - for (Map data : maps) { - SupDepart supDepart = supDepartMapper.selectOne(new LambdaQueryWrapper().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 data : maps) { - SupDepart supDepart = supDepartMapper.selectOne(new LambdaQueryWrapper().eq(SupDepart::getCode, data.get("involve_depart_id"))); - if (supDepart != null && (supDepart.getLevel() == 4)) { - SupDepart supDepart2 = supDepartMapper.selectOne(new LambdaQueryWrapper().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 iterator4 = modelClues4.iterator(); - while (iterator4.hasNext()) { - ModelClue modelClue4 = iterator4.next(); - Iterator 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().eq(SupDepart::getCode, modelClue4.getInvolveDepartId())); - SupDepart supDepart2 = new SupDepart(); - if (supDepart != null && (supDepart.getLevel() == 4)) { - supDepart2 = supDepartMapper.selectOne(new LambdaQueryWrapper().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().eq(SupDepart::getCode, modelClue4.getInvolveDepartId())); -// SupDepart supDepart2 = new SupDepart(); -// if (supDepart != null && (supDepart.getLevel() == 4)) { -// supDepart2 = supDepartMapper.selectOne(new LambdaQueryWrapper().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 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 { return needsInsertModelClues; } - private List getModelCluesForModel2(List modelClues, String param) { + private List getModelCluesForModel4(String param, List modelClues) { + System.out.println("测试4开始查询数据库"); + List 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> jjdmaps = modelClueDataMapper.selectByUniqueKeys(jjdSql); + List> zfqymaps = modelClueDataMapper.selectByUniqueKeys(zfqySql); + System.out.println("测试4查询数据库完毕"); + if (jjdmaps.isEmpty()) { + return modelClues; + } + List jjdModelClues = new ArrayList<>(); + for (Map data : jjdmaps) { + SupExternalDepart supExternalDepart = supExternalDepartMapper.selectOne(new LambdaQueryWrapper().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 jjdModelClues3 = new ArrayList<>(jjdModelClues.stream().filter(clue -> clue.getDepartLevel() == 3).toList()); + List jjdModelClues4 = new ArrayList<>(jjdModelClues.stream().filter(clue -> clue.getDepartLevel() == 4).toList()); + List jjdModelClues5 = new ArrayList<>(jjdModelClues.stream().filter(clue -> clue.getDepartLevel() == 5).toList()); + mergeModelClues(jjdModelClues5, jjdModelClues4, 1); + mergeModelClues(jjdModelClues4, jjdModelClues3, 1); + List zfqymModelClues = new ArrayList<>(); + for (Map data : zfqymaps) { + SupExternalDepart supExternalDepart = supExternalDepartMapper.selectOne(new LambdaQueryWrapper().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 zfqymModelClues3 = new ArrayList<>(zfqymModelClues.stream().filter(clue -> clue.getDepartLevel() == 3).toList()); + List zfqymModelClues4 = new ArrayList<>(zfqymModelClues.stream().filter(clue -> clue.getDepartLevel() == 4).toList()); + List 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 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 getModelCluesForModel4(String sql, List modelClues) { + System.out.println("测试4开始查询数据库"); + List> maps = modelClueDataMapper.selectByUniqueKeys(sql); + System.out.println("测试4查询数据库完毕"); + // 全市平均数 + BigDecimal avgPercentage = null; + if (!maps.isEmpty()) { + avgPercentage = (BigDecimal) maps.get(0).get("avg_percentage"); + } + List oriModelClues = new ArrayList<>(); + for (Map data : maps) { + SupExternalDepart supExternalDepart = supExternalDepartMapper.selectOne(new LambdaQueryWrapper().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 modelClues3 = new ArrayList<>(oriModelClues.stream().filter(clue -> clue.getDepartLevel() == 3).toList()); + List modelClues4 = new ArrayList<>(oriModelClues.stream().filter(clue -> clue.getDepartLevel() == 4).toList()); + List modelClues5 = new ArrayList<>(oriModelClues.stream().filter(clue -> clue.getDepartLevel() == 5).toList()); + mergeModelClues(modelClues5, modelClues3); + mergeModelClues(modelClues4, modelClues3); + Iterator 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 modelClues2, List modelClues1 , int no) { + for (ModelClue modelClue2 : modelClues2) { + Iterator 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().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 getModelCluesForModel2(String param, List modelClues) { List modelClues1 = new ArrayList<>(); List 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 { 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; }