From 18b268c241b891100030f7e7dc12542551431c49 Mon Sep 17 00:00:00 2001 From: wxc <191104855@qq.com> Date: Tue, 5 Nov 2024 18:28:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84=E5=8D=95=E4=BD=8D?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E7=94=BB=E5=83=8F=E3=80=81=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E7=94=BB=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constants/enums/PersonTypeEnum.java | 7 +++ .../ProfileDepartController.java | 31 ++++++++----- .../ProfilePoliceController.java | 21 +++++++-- .../com/biutag/supervision/job/DepartJob.java | 21 ++++----- .../mapper/ProfileDepartMapper.java | 5 ++- .../supervision/mapper/SupPoliceMapper.java | 2 - .../supervision/pojo/domain/NegativeInfo.java | 9 ++-- .../pojo/entity/SupDepartPoliceSize.java | 9 ++-- .../service/SupDepartPoliceSizeService.java | 22 ++++++++- .../supervision/service/SupPoliceService.java | 8 ++-- .../resources/mapper/ProfileDepartMapper.xml | 45 ++++++++++++------- 11 files changed, 121 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/biutag/supervision/constants/enums/PersonTypeEnum.java b/src/main/java/com/biutag/supervision/constants/enums/PersonTypeEnum.java index c0bd005..95163f9 100644 --- a/src/main/java/com/biutag/supervision/constants/enums/PersonTypeEnum.java +++ b/src/main/java/com/biutag/supervision/constants/enums/PersonTypeEnum.java @@ -3,6 +3,8 @@ package com.biutag.supervision.constants.enums; import lombok.AllArgsConstructor; import lombok.Getter; +import java.util.List; + /** * @author wxc * @date 2024/11/1 @@ -18,4 +20,9 @@ public enum PersonTypeEnum { xj("5", "协警"); private String value; private String label; + + public static List getAuxPersonType() { + return List.of(works.getValue(), aux.getValue(), clerk.getValue(), xj.getValue()); + } + } diff --git a/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfileDepartController.java b/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfileDepartController.java index 1a32eaa..7ff5656 100644 --- a/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfileDepartController.java +++ b/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfileDepartController.java @@ -73,33 +73,39 @@ public class ProfileDepartController { List polices = policeService.listAllByDepartId(departId); profileDepart.getDepartInfo().setMainRole(polices.stream().filter(item -> "正职".equals(item.getPosition())).findFirst().map(SupPolice::getName).orElse(null)); profileDepart.getDepartInfo().setDeputyRole(polices.stream().filter(item -> "副职".equals(item.getPosition())).map(SupPolice::getName).toList()); - // 民警数量 - profileDepart.getDepartInfo().setPoliceSize(polices.stream().filter(item -> PersonTypeEnum.police.getValue().equals(item.getPersonType())).count()); - - // 协警辅警数量 - profileDepart.getDepartInfo().setAuxSize(polices.stream().filter(item -> PersonTypeEnum.aux.getValue().equals(item.getPersonType()) || PersonTypeEnum.xj.getValue().equals(item.getPersonType())).count()); List list = negativeService.list(new LambdaQueryWrapper().eq(Negative::getInvolveDepartId, departId) .between(Negative::getCrtTime, beginTime, endTime) .in(Negative::getCheckStatus, List.of(InspectCaseEnum.TRUE.getValue(), InspectCaseEnum.PARTIALLY_TRUE.getValue()))); List negativeIds = list.stream().map(Negative::getId).toList(); - int negativePoliceSize = profileDepartMapper.countByNegativeIdsAndPersonTypes(negativeIds, List.of(PersonTypeEnum.police.getValue())); + int negativePoliceSize = negativeIds.isEmpty() ? 0 : profileDepartMapper.countByNegativeIdsAndPersonTypes(negativeIds, List.of(PersonTypeEnum.police.getValue())); profileDepart.getDepartInfo().setNegativePoliceSize(negativePoliceSize); - int negativeAuxSize = profileDepartMapper.countByNegativeIdsAndPersonTypes(negativeIds, List.of(PersonTypeEnum.aux.getValue(), PersonTypeEnum.xj.getValue())); + int negativeAuxSize = negativeIds.isEmpty() ? 0 : profileDepartMapper.countByNegativeIdsAndPersonTypes(negativeIds, List.of(PersonTypeEnum.aux.getValue(), PersonTypeEnum.xj.getValue())); profileDepart.getDepartInfo().setNegativeAuxSize(negativeAuxSize); profileDepart.getNegativeInfo().setSize(list.size()); - int jcjBusinessSize = businessDepartService.list(new LambdaQueryWrapper() + int jcj110BusinessSize = businessDepartService.list(new LambdaQueryWrapper() .between(BusinessDepart::getDate, beginTime, endTime) .eq(BusinessDepart::getBusinessType, BusinessTypeEnum.JCJ_110.getValue()) .eq(BusinessDepart::getDepartId, departId)) .stream().mapToInt(BusinessDepart::getNumber).sum(); - int jcjSize = negativeService.list(new LambdaQueryWrapper() + int jcj110Size = negativeService.list(new LambdaQueryWrapper() .between(Negative::getCrtTime, beginTime, endTime) .eq(Negative::getBusinessTypeCode, BusinessTypeEnum.JCJ_110.getValue()) .eq(Negative::getInvolveDepartId, departId) .in(Negative::getCheckStatus, List.of(InspectCaseEnum.TRUE.getValue(), InspectCaseEnum.PARTIALLY_TRUE.getValue()))).size(); + int jcj122BusinessSize = businessDepartService.list(new LambdaQueryWrapper() + .between(BusinessDepart::getDate, beginTime, endTime) + .eq(BusinessDepart::getBusinessType, BusinessTypeEnum.JCJ_122.getValue()) + .eq(BusinessDepart::getDepartId, departId)) + .stream().mapToInt(BusinessDepart::getNumber).sum(); + int jcj122Size = negativeService.list(new LambdaQueryWrapper() + .between(Negative::getCrtTime, beginTime, endTime) + .eq(Negative::getBusinessTypeCode, BusinessTypeEnum.JCJ_122.getValue()) + .eq(Negative::getInvolveDepartId, departId) + .in(Negative::getCheckStatus, List.of(InspectCaseEnum.TRUE.getValue(), InspectCaseEnum.PARTIALLY_TRUE.getValue()))).size(); + int zfbaBusinessSize = businessDepartService.list(new LambdaQueryWrapper() .between(BusinessDepart::getDate, beginTime, endTime) .eq(BusinessDepart::getBusinessType, BusinessTypeEnum.ZFBA.getValue()) @@ -110,7 +116,10 @@ public class ProfileDepartController { .eq(Negative::getBusinessTypeCode, BusinessTypeEnum.ZFBA.getValue()) .eq(Negative::getInvolveDepartId, departId) .in(Negative::getCheckStatus, List.of(InspectCaseEnum.TRUE.getValue(), InspectCaseEnum.PARTIALLY_TRUE.getValue()))).size(); - profileDepart.getNegativeInfo().setJcjSize(jcjSize).setJcjBusinessSize(jcjBusinessSize).setZfbaBusinessSize(zfbaBusinessSize).setZfbaSize(zfbaSize); + profileDepart.getNegativeInfo().setJcj110Size(jcj110Size).setJcj110BusinessSize(jcj110BusinessSize) + .setJcj122Size(jcj122Size) + .setJcj122BusinessSize(jcj122BusinessSize) + .setZfbaBusinessSize(zfbaBusinessSize).setZfbaSize(zfbaSize); // 问题来源占比 Map> problemSourcesGroup = list.stream().collect(Collectors.groupingBy(Negative::getProblemSourcesCode)); List problemSourcesList = problemSourcesGroup.keySet().stream().map(key -> new PieItem(Optional.ofNullable(ProblemSourcesEnum.get(key)).map(ProblemSourcesEnum::getLabel).orElse(key), problemSourcesGroup.get(key).size())).toList(); @@ -137,7 +146,7 @@ public class ProfileDepartController { profileDepart.setProblemTypeRadarIndicator(problemTypeRadarIndicator); profileDepart.setProblemTypeRadarData(problemTypeRadarData); // 突出问题排名 - profileDepart.setProblemTypeBarList(problemTypeBarList); + profileDepart.setProblemTypeBarList(profileDepartMapper.selectThirdProblemType(departId, beginTime, endTime)); return Result.success(profileDepart); } diff --git a/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfilePoliceController.java b/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfilePoliceController.java index 9dc3e40..8ad6492 100644 --- a/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfilePoliceController.java +++ b/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfilePoliceController.java @@ -76,7 +76,7 @@ public class ProfilePoliceController { ProfilePolice profilePolice = new ProfilePolice(); profilePolice.setPoliceInfo(policeService.getByIdCode(idCode)); - int jcjBusinessSize = businessPoliceService.list(new LambdaQueryWrapper() + int jcj110BusinessSize = businessPoliceService.list(new LambdaQueryWrapper() .between(BusinessPolice::getDate, beginTime, endTime) .eq(BusinessPolice::getBusinessType, BusinessTypeEnum.JCJ_110.getValue()) .eq(BusinessPolice::getEmpNo, profilePolice.getPoliceInfo().getEmpNo()) @@ -84,11 +84,24 @@ public class ProfilePoliceController { .stream().mapToInt(BusinessPolice::getNumber).sum(); Set negativeIds = negativeBlameService.list(new LambdaQueryWrapper().eq(NegativeBlame::getBlameIdCode, idCode)).stream().map(NegativeBlame::getNegativeId).collect(Collectors.toSet()); - int jcjSize = negativeIds.isEmpty() ? 0 : negativeService.list(new LambdaQueryWrapper() + int jcj110Size = negativeIds.isEmpty() ? 0 : negativeService.list(new LambdaQueryWrapper() .between(Negative::getCrtTime, beginTime, endTime) .eq(Negative::getBusinessTypeCode, BusinessTypeEnum.JCJ_110.getValue()) .in(Negative::getId, negativeIds) .in(Negative::getCheckStatus, List.of(InspectCaseEnum.TRUE.getValue(), InspectCaseEnum.PARTIALLY_TRUE.getValue()))).size(); + int jcj122BusinessSize = businessPoliceService.list(new LambdaQueryWrapper() + .between(BusinessPolice::getDate, beginTime, endTime) + .eq(BusinessPolice::getBusinessType, BusinessTypeEnum.JCJ_122.getValue()) + .eq(BusinessPolice::getEmpNo, profilePolice.getPoliceInfo().getEmpNo()) + .eq(BusinessPolice::getPoliceName, profilePolice.getPoliceInfo().getName())) + .stream().mapToInt(BusinessPolice::getNumber).sum(); + + int jcj122Size = negativeIds.isEmpty() ? 0 : negativeService.list(new LambdaQueryWrapper() + .between(Negative::getCrtTime, beginTime, endTime) + .eq(Negative::getBusinessTypeCode, BusinessTypeEnum.JCJ_122.getValue()) + .in(Negative::getId, negativeIds) + .in(Negative::getCheckStatus, List.of(InspectCaseEnum.TRUE.getValue(), InspectCaseEnum.PARTIALLY_TRUE.getValue()))).size(); + int zfbaBusinessSize = businessPoliceService.list(new LambdaQueryWrapper() .between(BusinessPolice::getDate, beginTime, endTime) .eq(BusinessPolice::getBusinessType, BusinessTypeEnum.ZFBA.getValue()) @@ -100,7 +113,9 @@ public class ProfilePoliceController { .eq(Negative::getBusinessTypeCode, BusinessTypeEnum.ZFBA.getValue()) .in(Negative::getId, negativeIds) .in(Negative::getCheckStatus, List.of(InspectCaseEnum.TRUE.getValue(), InspectCaseEnum.PARTIALLY_TRUE.getValue()))).size(); - profilePolice.getNegativeInfo().setJcjBusinessSize(jcjBusinessSize).setJcjSize(jcjSize).setZfbaBusinessSize(zfbaBusinessSize).setZfbaSize(zfbaSize); + profilePolice.getNegativeInfo().setJcj110BusinessSize(jcj110BusinessSize).setJcj110Size(jcj110Size) + .setJcj122BusinessSize(jcj122BusinessSize).setJcj122Size(jcj122Size) + .setZfbaBusinessSize(zfbaBusinessSize).setZfbaSize(zfbaSize); List list = negativeIds.isEmpty() ? new ArrayList<>() : negativeService.list(new LambdaQueryWrapper() .between(Negative::getCrtTime, beginTime, endTime) diff --git a/src/main/java/com/biutag/supervision/job/DepartJob.java b/src/main/java/com/biutag/supervision/job/DepartJob.java index 756657e..7fae51e 100644 --- a/src/main/java/com/biutag/supervision/job/DepartJob.java +++ b/src/main/java/com/biutag/supervision/job/DepartJob.java @@ -1,12 +1,13 @@ package com.biutag.supervision.job; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.biutag.supervision.pojo.entity.SupDepart; import com.biutag.supervision.service.SupDepartPoliceSizeService; import com.biutag.supervision.service.SupDepartService; -import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.List; @@ -23,12 +24,6 @@ public class DepartJob { private final SupDepartPoliceSizeService departPoliceSizeService; - - @PostConstruct - public void init() { -// updateDepartPath(); - } - @Async public void updateDepartPath() { List departs = departService.list(); @@ -41,14 +36,14 @@ public class DepartJob { } - @Async + /** + * 1个小时 + */ + @Scheduled(fixedRate = 1000 * 60 * 60) public void updatePoliceSize() { - List departs = departService.list(); + List departs = departService.list(new LambdaQueryWrapper().eq(SupDepart::getLevel, 3)); departs.forEach(item -> { - String pathTrace = departService.getPathTrace(item); - if (!pathTrace.equals(item.getPathTrace())) { - departService.update(new LambdaUpdateWrapper().eq(SupDepart::getId, item.getId()).set(SupDepart::getPathTrace, pathTrace)); - } + departPoliceSizeService.saveOrUpdate(item.getId()); }); } diff --git a/src/main/java/com/biutag/supervision/mapper/ProfileDepartMapper.java b/src/main/java/com/biutag/supervision/mapper/ProfileDepartMapper.java index 84fbce5..71a2ee3 100644 --- a/src/main/java/com/biutag/supervision/mapper/ProfileDepartMapper.java +++ b/src/main/java/com/biutag/supervision/mapper/ProfileDepartMapper.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.biutag.supervision.pojo.dto.common.BarItem; import com.biutag.supervision.pojo.dto.common.PieItem; import com.biutag.supervision.pojo.model.DepartNegativeModel; +import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.util.Date; @@ -22,6 +23,8 @@ public interface ProfileDepartMapper { List selectProblemType(String departId, Date beginTime, Date endTime); - int countByNegativeIdsAndPersonTypes(List negativeIds, List personTypes); + List selectThirdProblemType(String departId, Date beginTime, Date endTime); + + int countByNegativeIdsAndPersonTypes(@Param("negativeIds") List negativeIds, @Param("personTypes") List personTypes); } diff --git a/src/main/java/com/biutag/supervision/mapper/SupPoliceMapper.java b/src/main/java/com/biutag/supervision/mapper/SupPoliceMapper.java index 1b374ca..97f4148 100644 --- a/src/main/java/com/biutag/supervision/mapper/SupPoliceMapper.java +++ b/src/main/java/com/biutag/supervision/mapper/SupPoliceMapper.java @@ -15,6 +15,4 @@ public interface SupPoliceMapper extends BaseMapper { Page queryPage(@Param("page") Page page, @Param(Constants.WRAPPER) QueryWrapper queryWrapper); - - } \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/pojo/domain/NegativeInfo.java b/src/main/java/com/biutag/supervision/pojo/domain/NegativeInfo.java index 3dc642e..05eb1f1 100644 --- a/src/main/java/com/biutag/supervision/pojo/domain/NegativeInfo.java +++ b/src/main/java/com/biutag/supervision/pojo/domain/NegativeInfo.java @@ -14,9 +14,12 @@ import lombok.experimental.Accessors; public class NegativeInfo { private long size; - // 接处警 - private Integer jcjBusinessSize; - private Integer jcjSize; + // 110接处警 + private Integer jcj110BusinessSize; + private Integer jcj110Size; + // 122接处警 + private Integer jcj122BusinessSize; + private Integer jcj122Size; // 执法办案 private Integer zfbaBusinessSize; private Integer zfbaSize; diff --git a/src/main/java/com/biutag/supervision/pojo/entity/SupDepartPoliceSize.java b/src/main/java/com/biutag/supervision/pojo/entity/SupDepartPoliceSize.java index 54b2ba4..360d7a7 100644 --- a/src/main/java/com/biutag/supervision/pojo/entity/SupDepartPoliceSize.java +++ b/src/main/java/com/biutag/supervision/pojo/entity/SupDepartPoliceSize.java @@ -1,13 +1,12 @@ package com.biutag.supervision.pojo.entity; -import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import lombok.Getter; import lombok.Setter; +import lombok.experimental.Accessors; -import java.time.LocalDateTime; - +@Accessors(chain = true) @Setter @Getter public class SupDepartPoliceSize { @@ -18,10 +17,10 @@ public class SupDepartPoliceSize { // 民警人数 @TableField("police_size") - private Integer policeSize; + private Long policeSize; // 协警人数 @TableField("aux_size") - private Integer auxSize; + private Long auxSize; } \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/service/SupDepartPoliceSizeService.java b/src/main/java/com/biutag/supervision/service/SupDepartPoliceSizeService.java index d8bd4b4..ce04a58 100644 --- a/src/main/java/com/biutag/supervision/service/SupDepartPoliceSizeService.java +++ b/src/main/java/com/biutag/supervision/service/SupDepartPoliceSizeService.java @@ -1,11 +1,31 @@ package com.biutag.supervision.service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.biutag.supervision.pojo.entity.SupDepartPoliceSize; +import com.biutag.supervision.constants.enums.PersonTypeEnum; import com.biutag.supervision.mapper.SupDepartPoliceSizeMapper; +import com.biutag.supervision.pojo.entity.SupDepartPoliceSize; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + +@RequiredArgsConstructor @Service public class SupDepartPoliceSizeService extends ServiceImpl { + private final SupDepartService departService; + + private final SupPoliceService policeService; + + public boolean saveOrUpdate(String departId) { + List departChildrenIds = departService.getAllNodeIds(departId); + List list = new ArrayList<>(departChildrenIds); + list.add(departId); + long policeSize = policeService.countByOrgIdsAndPersonTypes(list, List.of(PersonTypeEnum.police.getValue())); + long auxSize = policeService.countByOrgIdsAndPersonTypes(list, PersonTypeEnum.getAuxPersonType()); + SupDepartPoliceSize departPoliceSize = new SupDepartPoliceSize().setDepartId(departId).setPoliceSize(policeSize).setAuxSize(auxSize); + return saveOrUpdate(departPoliceSize); + } + } diff --git a/src/main/java/com/biutag/supervision/service/SupPoliceService.java b/src/main/java/com/biutag/supervision/service/SupPoliceService.java index 7c7d7e7..333bf19 100644 --- a/src/main/java/com/biutag/supervision/service/SupPoliceService.java +++ b/src/main/java/com/biutag/supervision/service/SupPoliceService.java @@ -76,12 +76,12 @@ public class SupPoliceService extends ServiceImpl { return exists(new LambdaQueryWrapper().in(SupPolice::getOrgId, orgIds)); } - public Boolean ge(String empNo) { - return exists(new LambdaQueryWrapper().in(SupPolice::getEmpNo, empNo)); - } - public Boolean existsByIdCode(String idCode) { return exists(new LambdaQueryWrapper().in(SupPolice::getIdCode, idCode)); } + public long countByOrgIdsAndPersonTypes(List orgIds, List personTypes) { + return count(new LambdaQueryWrapper().in(SupPolice::getOrgId, orgIds).in(SupPolice::getPersonType, personTypes)); + } + } diff --git a/src/main/resources/mapper/ProfileDepartMapper.xml b/src/main/resources/mapper/ProfileDepartMapper.xml index 11e3084..7f80074 100644 --- a/src/main/resources/mapper/ProfileDepartMapper.xml +++ b/src/main/resources/mapper/ProfileDepartMapper.xml @@ -11,22 +11,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" count( n.id ) verify_size FROM ( - SELECT - d.id depart_id, - d1.short_name parent_depart_name, - d.short_name depart_name, - sum( CASE WHEN p.person_type = '1' THEN 1 ELSE 0 END ) police_size, - sum( CASE WHEN p.person_type = '3' OR p.person_type = '5' THEN 1 ELSE 0 END ) aux_size + SELECT + d.id depart_id, + d1.short_name parent_depart_name, + d.short_name depart_name, + p.police_size, + p.aux_size FROM - sup_depart d + sup_depart d LEFT JOIN sup_depart d1 ON d.pid = d1.id - LEFT JOIN sup_police p ON p.org_id = d.id + LEFT JOIN sup_depart_police_size p ON p.depart_id = d.id WHERE - d.LEVEL = 3 - GROUP BY - d.id, - d1.short_name, - d.short_name + d.LEVEL = 3 ) d LEFT JOIN negative n ON n.involveDepartId = d.depart_id AND n.checkStatus IN ( '1', '2' ) @@ -88,9 +84,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" order by value desc - SELECT - count( p.id ) + pr.`threeLevelContent` name, + count( DISTINCT n.id ) value + FROM + negative_problem_relation pr + LEFT JOIN negative_blame nb ON pr.blameId = nb.blameId + LEFT JOIN negative n ON n.id = nb.negativeId + AND n.checkStatus IN ( '1', '2' ) + AND n.involveDepartId = #{departId} + AND n.crtTime BETWEEN #{beginTime} AND #{endTime} + GROUP BY + pr.`threeLevelContent` + having value > 0 + order by value desc + + +