From 9596a2b85190cbcbf677937b884387f09d3a0774 Mon Sep 17 00:00:00 2001 From: TS-QD1 Date: Fri, 14 Jul 2023 16:17:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E7=BB=A9=E6=95=88=E8=80=83?= =?UTF-8?q?=E6=A0=B8=E7=9A=84=E6=96=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apis/kpi/KpiKhxzController.java | 55 ++++++++++++ .../bigdata/service/kpi/IKpiKhxzService.java | 22 +++++ .../service/kpi/impl/KpiKhxzServiceImpl.java | 89 +++++++++++++++---- .../service/kpi/task/KpiKhxzWgyTask.java | 2 +- .../service/kpi/task/KpiKhxzWgzTask.java | 2 +- .../task/sub/KpiKhxzWgyEGIKRTRunnable.java | 18 ++-- .../task/sub/KpiKhxzWgzCDEFGHRunnable.java | 48 +++++++--- .../db2-mapper/kpi/community-boss-mapper.xml | 11 +++ .../mapper/kpi/kpi-khxz-wgy-mapper.xml | 8 ++ 9 files changed, 220 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/cm/bigdata/controller/apis/kpi/KpiKhxzController.java b/src/main/java/com/cm/bigdata/controller/apis/kpi/KpiKhxzController.java index 62df640..5223280 100644 --- a/src/main/java/com/cm/bigdata/controller/apis/kpi/KpiKhxzController.java +++ b/src/main/java/com/cm/bigdata/controller/apis/kpi/KpiKhxzController.java @@ -136,4 +136,59 @@ public class KpiKhxzController extends AbstractController { return new SuccessResult(); } + @GetMapping("sync-case") + public void syncCase() throws IOException { + kpiKhxzService.updateCase(); + } + + @GetMapping("sync-wgy3/{year}/{month}") + public void syncWgy3(@PathVariable("year") Integer year, @PathVariable("month") Integer month) throws IOException { + kpiKhxzService.updateWgy3(year, month); + } + + @GetMapping("sync-wgy4/{year}/{month}") + public void syncWgy4(@PathVariable("year") Integer year, @PathVariable("month") Integer month) throws IOException { + kpiKhxzService.updateWgy4(year, month); + } + + @GetMapping("sync-ddy/{year}/{month}") + public void syncDdy(@PathVariable("year") Integer year, @PathVariable("month") Integer month) throws IOException { + kpiKhxzService.updateDdy(year, month); + } + + @GetMapping("sync-zgy/{year}/{month}") + public void syncZgy(@PathVariable("year") Integer year, @PathVariable("month") Integer month) throws IOException { + kpiKhxzService.updateZgy(year, month); + } + + @GetMapping("sync-wgy3-task/{year}/{month}") + public void syncWgy3Task(@PathVariable("year") Integer year, @PathVariable("month") Integer month) throws IOException { + kpiKhxzService.updateWgy3Task(year, month); + } + + @GetMapping("sync-wgy4-task/{year}/{month}") + public void syncWgy4Task(@PathVariable("year") Integer year, @PathVariable("month") Integer month) throws IOException { + kpiKhxzService.updateWgy4Task(year, month); + } + + @GetMapping("sync-ddy-task/{year}/{month}") + public void syncDdyTask(@PathVariable("year") Integer year, @PathVariable("month") Integer month) throws IOException { + kpiKhxzService.updateDdyTask(year, month); + } + + @GetMapping("sync-zf-ga-task/{year}/{month}") + public void syncZfGaTask(@PathVariable("year") Integer year, @PathVariable("month") Integer month) throws IOException { + kpiKhxzService.updateZfGaTask(year, month); + } + + @GetMapping("sync-znbm-task/{year}/{month}") + public void syncZnbmTask(@PathVariable("year") Integer year, @PathVariable("month") Integer month) throws IOException { + kpiKhxzService.updateZnbmTask(year, month); + } + + @GetMapping("sync-wgz-tazk/{year}/{month}") + public void syncWgzTask(@PathVariable("year") Integer year, @PathVariable("month") Integer month) throws IOException { + kpiKhxzService.updateWgzTask(year, month); + } + } diff --git a/src/main/java/com/cm/bigdata/service/kpi/IKpiKhxzService.java b/src/main/java/com/cm/bigdata/service/kpi/IKpiKhxzService.java index 990cdf9..732930f 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/IKpiKhxzService.java +++ b/src/main/java/com/cm/bigdata/service/kpi/IKpiKhxzService.java @@ -12,6 +12,27 @@ public interface IKpiKhxzService { void update(Integer khYear, Integer khMonth); + void updateCase(); + + void updateWgy3(Integer khYear, Integer khMonth); + + void updateWgy4(Integer khYear, Integer khMonth); + + void updateDdy(Integer khYear, Integer khMonth); + + void updateZgy(Integer khYear, Integer khMonth); + + void updateWgy3Task(Integer khYear, Integer khMonth); + + void updateWgy4Task(Integer khYear, Integer khMonth); + + void updateDdyTask(Integer khYear, Integer khMonth); + + void updateZfGaTask(Integer khYear, Integer khMonth); + + void updateZnbmTask(Integer khYear, Integer khMonth); + + void updateWgzTask(Integer khYear, Integer khMonth); List listWgy(Map queryMap); @@ -43,4 +64,5 @@ public interface IKpiKhxzService { void exportZnbm(HttpServletResponse httpServletResponse, Map queryMap) throws IOException; void updateZnbm(KpiUpdateVO kpiUpdateVO); + } diff --git a/src/main/java/com/cm/bigdata/service/kpi/impl/KpiKhxzServiceImpl.java b/src/main/java/com/cm/bigdata/service/kpi/impl/KpiKhxzServiceImpl.java index 6da5ba0..a65f093 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/impl/KpiKhxzServiceImpl.java +++ b/src/main/java/com/cm/bigdata/service/kpi/impl/KpiKhxzServiceImpl.java @@ -54,52 +54,47 @@ public class KpiKhxzServiceImpl extends AbstractService implements IKpiKhxzServi // 开始更新 Executors.newSingleThreadExecutor().execute(() -> { // 更新案件,1任务 - kpiService.updateCaseCount(); - KpiUpdateMonitor.getInstance().complete(); + updateCase(); // 更新4级网格员日统计,1任务 - kpiService.updateCommunityBossDayCount(khYear, khMonth, 3); - KpiUpdateMonitor.getInstance().complete(); + updateWgy3(khYear, khMonth); // 更新5级网格员日统计,1任务 - kpiService.updateCommunityBossDayCount(khYear, khMonth, 4); - KpiUpdateMonitor.getInstance().complete(); + updateWgy4(khYear, khMonth); // 更新调度员日统计,1任务 - kpiService.updateNPersonDayCount(KpiUtil.DDY_ROLE_ID, khYear, khMonth); - KpiUpdateMonitor.getInstance().complete(); + updateDdy(khYear, khMonth); // 更新专管员,1任务 - kpiService.updateNPersonDayCount(KpiUtil.ZGY_ROLE_ID, khYear, khMonth); - KpiUpdateMonitor.getInstance().complete(); + updateZgy(khYear, khMonth); executorService.execute(() -> { // 更新4级网格员,4任务 - kpiKhxzWgyTask.update(khYear, khMonth, 3); + updateWgy3Task(khYear, khMonth); }); executorService.execute(() -> { // 更新5级网格员,4个任务 - kpiKhxzWgyTask.update(khYear, khMonth, 4); + updateWgy4Task(khYear, khMonth); }); executorService.execute(() -> { // 调度员,4任务 - kpiKhxzDdyTask.update(khYear, khMonth); + updateDdyTask(khYear, khMonth); }); executorService.execute(() -> { // 执法公安,5任务 - khKhxzZfGaTask.update(khYear, khMonth); + updateZfGaTask(khYear, khMonth); }); executorService.execute(() -> { // 职能部门,4任务 - kpiKhxzZnbmTask.update(khYear, khMonth); + updateZnbmTask(khYear, khMonth); }); executorService.execute(() -> { - while(KpiUpdateMonitor.getInstance().getCompleteCount() < 26) { + while (KpiUpdateMonitor.getInstance().getCompleteCount() < 26) { try { Thread.sleep(3000); LOG.debug("等待其他任务执行完成"); @@ -108,11 +103,71 @@ public class KpiKhxzServiceImpl extends AbstractService implements IKpiKhxzServi } } // 网格长,3任务 - kpiKhxzWgzTask.update(khYear, khMonth); + updateWgzTask(khYear, khMonth); }); }); } + @Override + public void updateCase() { + kpiService.updateCaseCount(); + KpiUpdateMonitor.getInstance().complete(); + } + + @Override + public void updateWgy3(Integer khYear, Integer khMonth) { + kpiService.updateCommunityBossDayCount(khYear, khMonth, 3); + KpiUpdateMonitor.getInstance().complete(); + } + + @Override + public void updateWgy4(Integer khYear, Integer khMonth) { + kpiService.updateCommunityBossDayCount(khYear, khMonth, 4); + KpiUpdateMonitor.getInstance().complete(); + } + + @Override + public void updateDdy(Integer khYear, Integer khMonth) { + kpiService.updateNPersonDayCount(KpiUtil.DDY_ROLE_ID, khYear, khMonth); + KpiUpdateMonitor.getInstance().complete(); + } + + @Override + public void updateZgy(Integer khYear, Integer khMonth) { + kpiService.updateNPersonDayCount(KpiUtil.ZGY_ROLE_ID, khYear, khMonth); + KpiUpdateMonitor.getInstance().complete(); + } + + @Override + public void updateWgy3Task(Integer khYear, Integer khMonth) { + kpiKhxzWgyTask.update(khYear, khMonth, 3); + } + + @Override + public void updateWgy4Task(Integer khYear, Integer khMonth) { + kpiKhxzWgyTask.update(khYear, khMonth, 4); + } + + @Override + public void updateDdyTask(Integer khYear, Integer khMonth) { + kpiKhxzDdyTask.update(khYear, khMonth); + } + + @Override + public void updateZfGaTask(Integer khYear, Integer khMonth) { + khKhxzZfGaTask.update(khYear, khMonth); + } + + @Override + public void updateZnbmTask(Integer khYear, Integer khMonth) { + kpiKhxzZnbmTask.update(khYear, khMonth); + } + + @Override + public void updateWgzTask(Integer khYear, Integer khMonth) { + kpiKhxzWgzTask.update(khYear, khMonth); + } + @Override public List listWgy(Map queryMap) { return kpiKhxzWgyDao.listWgy(queryMap); diff --git a/src/main/java/com/cm/bigdata/service/kpi/task/KpiKhxzWgyTask.java b/src/main/java/com/cm/bigdata/service/kpi/task/KpiKhxzWgyTask.java index 1302d39..b727e94 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/task/KpiKhxzWgyTask.java +++ b/src/main/java/com/cm/bigdata/service/kpi/task/KpiKhxzWgyTask.java @@ -51,7 +51,7 @@ public class KpiKhxzWgyTask { return; } executorService.execute(new KpiKhxzWgyCRunnable(kpiKhxzWgyDao, kpiDao, khYear, khMonth, wgyLevel, userIds)); - executorService.execute(new KpiKhxzWgyEGIKRTRunnable(kpiKhxzWgyDao, kpiHolidayDao, kpiDao, khYear, khMonth, wgyLevel, userIds)); + executorService.execute(new KpiKhxzWgyEGIKRTRunnable(userGridService, kpiKhxzWgyDao, kpiHolidayDao, kpiDao, khYear, khMonth, wgyLevel, userIds)); } private void deleteBaseWgy(int khYear, int khMonth, int wgyLevel) { diff --git a/src/main/java/com/cm/bigdata/service/kpi/task/KpiKhxzWgzTask.java b/src/main/java/com/cm/bigdata/service/kpi/task/KpiKhxzWgzTask.java index 932ce25..6e1c5c8 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/task/KpiKhxzWgzTask.java +++ b/src/main/java/com/cm/bigdata/service/kpi/task/KpiKhxzWgzTask.java @@ -38,7 +38,7 @@ public class KpiKhxzWgzTask { KpiUpdateMonitor.getInstance().complete(); return; } - executorService.execute(new KpiKhxzWgzCDEFGHRunnable(kpiKhxzWgzDao, kpiKhxzWgyDao, khYear, khMonth, kpiKhxzWgzDTOS)); + executorService.execute(new KpiKhxzWgzCDEFGHRunnable(communityBossService, kpiKhxzWgzDao, kpiKhxzWgyDao, khYear, khMonth, kpiKhxzWgzDTOS)); } private void deleteBase(int khYear, int khMonth) { diff --git a/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzWgyEGIKRTRunnable.java b/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzWgyEGIKRTRunnable.java index 8e9a7fc..089716c 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzWgyEGIKRTRunnable.java +++ b/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzWgyEGIKRTRunnable.java @@ -6,6 +6,7 @@ import com.cm.bigdata.dao.kpi.IKpiKhxzWgyDao; import com.cm.bigdata.monitor.KpiUpdateMonitor; import com.cm.bigdata.pojo.pos.kpi.CasePO; import com.cm.bigdata.pojo.pos.kpi.HolidayPO; +import com.cm.bigdata.service.kpi.IUserGridService; import com.cm.bigdata.utils.KpiUtil; import org.apache.commons.lang3.StringUtils; @@ -16,6 +17,7 @@ import java.util.Map; public class KpiKhxzWgyEGIKRTRunnable implements Runnable { + private IUserGridService userGridService; private IKpiKhxzWgyDao kpiKhxzWgyDao; private IKpiHolidayDao kpiHolidayDao; private IKpiDao kpiDao; @@ -24,7 +26,8 @@ public class KpiKhxzWgyEGIKRTRunnable implements Runnable { private int level; private List userIds; - public KpiKhxzWgyEGIKRTRunnable(IKpiKhxzWgyDao kpiKhxzWgyDao, IKpiHolidayDao kpiHolidayDao, IKpiDao kpiDao, int year, int month, int level, List userIds) { + public KpiKhxzWgyEGIKRTRunnable(IUserGridService userGridService, IKpiKhxzWgyDao kpiKhxzWgyDao, IKpiHolidayDao kpiHolidayDao, IKpiDao kpiDao, int year, int month, int level, List userIds) { + this.userGridService = userGridService; this.kpiKhxzWgyDao = kpiKhxzWgyDao; this.kpiHolidayDao = kpiHolidayDao; this.kpiDao = kpiDao; @@ -80,6 +83,9 @@ public class KpiKhxzWgyEGIKRTRunnable implements Runnable { private void updateEGIKRT(List userIds, List> shouldReportDayWeeks) { int shouldCount = shouldReportDayWeeks.size(); userIds.forEach(userId -> { + // 网格数量 + Integer gridCount = userGridService.countUserGrid(userId); + int totalShouldCount = shouldCount * gridCount; // 每周上报 int weekReportCount = 0; // 实报 @@ -100,6 +106,7 @@ public class KpiKhxzWgyEGIKRTRunnable implements Runnable { params.put("startTime", startTime); params.put("endTime", endTime); List casePOS = kpiDao.listCase(params); + // 本周是否有上报数据 boolean isWeekReport = false; for (CasePO casePO : casePOS) { urgeCount += casePO.getTotalUrge(); @@ -130,12 +137,13 @@ public class KpiKhxzWgyEGIKRTRunnable implements Runnable { isWeekReport = true; } } - weekReportCount += isWeekReport ? 1 : 0; - lackCount = Math.max(shouldCount - weekReportCount, 0); - exceedCount = Math.max(realityCount - shouldCount, 0); + // 每周上报数量由网格数量决定 + weekReportCount += isWeekReport ? gridCount : 0; + lackCount = Math.max(totalShouldCount - weekReportCount, 0); + exceedCount = Math.max(realityCount - totalShouldCount, 0); } Map updateParams = new HashMap<>(); - updateParams.put("E", shouldCount); + updateParams.put("E", totalShouldCount); updateParams.put("G", weekReportCount); updateParams.put("I", lackCount); updateParams.put("K", exceedCount); diff --git a/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzWgzCDEFGHRunnable.java b/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzWgzCDEFGHRunnable.java index 9c7d019..f9fead6 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzWgzCDEFGHRunnable.java +++ b/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzWgzCDEFGHRunnable.java @@ -5,21 +5,27 @@ import com.cm.bigdata.dao.kpi.IKpiKhxzWgzDao; import com.cm.bigdata.monitor.KpiUpdateMonitor; import com.cm.bigdata.pojo.dtos.kpi.KpiKhxzWgyDTO; import com.cm.bigdata.pojo.dtos.kpi.KpiKhxzWgzDTO; +import com.cm.bigdata.pojo.pos.kpi.CommunityBossPO; +import com.cm.bigdata.service.kpi.ICommunityBossService; +import org.apache.commons.collections4.ListUtils; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; public class KpiKhxzWgzCDEFGHRunnable implements Runnable { + private ICommunityBossService communityBossService; private IKpiKhxzWgzDao kpiKhxzWgzDao; private IKpiKhxzWgyDao kpiKhxzWgyDao; private int khYear; private int khMonth; private List kpiKhxzWgzDTOS; - public KpiKhxzWgzCDEFGHRunnable(IKpiKhxzWgzDao kpiKhxzWgzDao, IKpiKhxzWgyDao kpiKhxzWgyDao, int khYear, int khMonth, List kpiKhxzWgzDTOS) { + public KpiKhxzWgzCDEFGHRunnable(ICommunityBossService communityBossService, IKpiKhxzWgzDao kpiKhxzWgzDao, IKpiKhxzWgyDao kpiKhxzWgyDao, int khYear, int khMonth, List kpiKhxzWgzDTOS) { + this.communityBossService = communityBossService; this.kpiKhxzWgzDao = kpiKhxzWgzDao; this.kpiKhxzWgyDao = kpiKhxzWgyDao; this.khYear = khYear; @@ -30,14 +36,34 @@ public class KpiKhxzWgzCDEFGHRunnable implements Runnable { @Override public void run() { kpiKhxzWgzDTOS.forEach(kpiKhxzWgzDTO -> { - Map wgyParams = new HashMap<>(); - wgyParams.put("areaId", kpiKhxzWgzDTO.getAreaId()); - wgyParams.put("communityId", kpiKhxzWgzDTO.getCommunityId()); - wgyParams.put("wgyLevel", 3); - List kpiKhxzWgyDTOS = kpiKhxzWgyDao.listWgy(wgyParams); - wgyParams.put("wgyLevel", 4); - List kpiKhxzWgyDTOS1 = kpiKhxzWgyDao.listWgy(wgyParams); - kpiKhxzWgyDTOS.addAll(kpiKhxzWgyDTOS1); + Map communityBossMap = new HashMap<>(); + communityBossMap.put("communityBossParentUserId", kpiKhxzWgzDTO.getUserId()); + // 直属下级网格员 + List communityBossPOS = communityBossService.listPO(communityBossMap); + List communityBossUserIds = communityBossPOS.stream().map(CommunityBossPO::getCommunityBossUserId).collect(Collectors.toList()); + List kpiKhxzWgyDTOS = new ArrayList<>(); + if (!communityBossUserIds.isEmpty()) { + // 下级的直属下级 + communityBossMap.clear(); + communityBossMap.put("communityBossParentUserIds", communityBossUserIds); + List communityBossPOS1 = communityBossService.listPO(communityBossMap); + List communityBossUserIds1 = communityBossPOS1.stream().map(CommunityBossPO::getCommunityBossUserId).collect(Collectors.toList()); + // 合并用户ID + communityBossUserIds.addAll(communityBossUserIds1); + List userIds = communityBossUserIds; + + Map wgyParams = new HashMap<>(); + wgyParams.put("areaId", kpiKhxzWgzDTO.getAreaId()); + wgyParams.put("communityId", kpiKhxzWgzDTO.getCommunityId()); + wgyParams.put("khYear", khYear); + wgyParams.put("khMonth", khMonth); + wgyParams.put("userIds", userIds); + wgyParams.put("wgyLevel", 3); + kpiKhxzWgyDTOS.addAll(kpiKhxzWgyDao.listWgy(wgyParams)); + wgyParams.put("wgyLevel", 4); + List kpiKhxzWgyDTOS1 = kpiKhxzWgyDao.listWgy(wgyParams); + kpiKhxzWgyDTOS.addAll(kpiKhxzWgyDTOS1); + } int unPassCount = 0; int unReportCompleteCount = 0; for (KpiKhxzWgyDTO kpiKhxzWgyDTO : kpiKhxzWgyDTOS) { @@ -58,10 +84,10 @@ public class KpiKhxzWgzCDEFGHRunnable implements Runnable { updateParams.put("userId", kpiKhxzWgzDTO.getUserId()); updateParams.put("C", defaultC); updateParams.put("D", unPassCount); - updateParams.put("E", unPassCount * 10); + updateParams.put("E", Math.min(defaultC, unPassCount * 10)); updateParams.put("F", defaultF); updateParams.put("G", unReportCompleteCount); - updateParams.put("H", unReportCompleteCount * 10); + updateParams.put("H", Math.min(defaultF, unReportCompleteCount * 10)); kpiKhxzWgzDao.updateCDEFGH(updateParams); }); KpiUpdateMonitor.getInstance().complete(); diff --git a/src/main/resources/mybatis/db2-mapper/kpi/community-boss-mapper.xml b/src/main/resources/mybatis/db2-mapper/kpi/community-boss-mapper.xml index d8e5dfb..1d48e1a 100644 --- a/src/main/resources/mybatis/db2-mapper/kpi/community-boss-mapper.xml +++ b/src/main/resources/mybatis/db2-mapper/kpi/community-boss-mapper.xml @@ -55,6 +55,17 @@ AND community_boss_level = #{communityBossLevel} + + AND + community_boss_parent_user_id = #{communityBossParentUserId}; + + + AND + community_boss_parent_user_id IN + + #{communityBossParentUserIds[${index}]} + +