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 2a6735d..a26b5df 100644 --- a/src/main/java/com/biutag/supervision/pojo/entity/ModelClue.java +++ b/src/main/java/com/biutag/supervision/pojo/entity/ModelClue.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Getter; import lombok.Setter; +import java.math.BigDecimal; import java.time.LocalDateTime; @Setter @@ -67,4 +68,19 @@ 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 Integer departLevel; + } \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/service/ModelClueService.java b/src/main/java/com/biutag/supervision/service/ModelClueService.java index 9ff170f..6d22ab5 100644 --- a/src/main/java/com/biutag/supervision/service/ModelClueService.java +++ b/src/main/java/com/biutag/supervision/service/ModelClueService.java @@ -20,6 +20,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.text.SimpleDateFormat; import java.time.Instant; import java.time.LocalDateTime; @@ -191,21 +193,154 @@ public class ModelClueService extends ServiceImpl { } 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) { - 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.setThingDesc("在" + getNowTime() + "之前的1个月内," + data.get("involve_depart_name") - + "的总警情数为" + data.get("zjjs") - + ",执法场所登记数为" + data.get("zfcsdjs") - + ",每100起警情执法场所登记比例为" + data.get("bl") - + ",低于全市平均值(" + data.get("avg_percentage") - + "%),疑似漏登执法办案场所。"); - modelClues.add(modelClue); + 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; } else { System.out.println("测试" + modelId + "开始查询数据库");