From cb9847a2da6feb626688c32567b375b10496469a Mon Sep 17 00:00:00 2001 From: TS-QD1 Date: Sun, 14 May 2023 00:28:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=80=83=E6=A0=B8=E7=BB=86?= =?UTF-8?q?=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/apis/kpi/KpiController.java | 5 +++ .../apis/kpi/KpiKhxzController.java | 10 ++++-- .../cm/bigdata/dao/kpi/IKpiKhxzZnbmDao.java | 3 ++ .../pojo/pos/kpi/NPersonDayCountPO.java | 9 +++++ .../service/kpi/IDepartmentService.java | 2 ++ .../bigdata/service/kpi/IKpiKhxzService.java | 3 +- .../kpi/impl/DepartmentServiceImpl.java | 14 ++++++++ .../service/kpi/impl/KpiKhxzServiceImpl.java | 36 ++++++++++--------- .../service/kpi/impl/KpiServiceImpl.java | 3 +- .../service/kpi/task/KpiKhxzZfGaTask.java | 2 ++ .../task/sub/KpiKhxzZnbmCDEFGRunnable.java | 2 +- .../com/cm/bigdata/utils/KpiScoreUtil.java | 13 +++++-- .../java/com/cm/bigdata/utils/KpiUtil.java | 9 ++--- .../mapper/kpi/kpi-khxz-wgz-mapper.xml | 12 +++++-- .../mapper/kpi/kpi-khxz-znbm-mapper.xml | 28 +++++++++++++++ .../mybatis/mapper/kpi/kpi-mapper.xml | 3 ++ 16 files changed, 121 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/cm/bigdata/controller/apis/kpi/KpiController.java b/src/main/java/com/cm/bigdata/controller/apis/kpi/KpiController.java index ad97357..f975727 100644 --- a/src/main/java/com/cm/bigdata/controller/apis/kpi/KpiController.java +++ b/src/main/java/com/cm/bigdata/controller/apis/kpi/KpiController.java @@ -86,6 +86,11 @@ public class KpiController extends AbstractController { return departmentService.list(); } + @GetMapping("list-znbm") + public List listZnbm() { + return departmentService.listZnbm(); + } + @GetMapping("list-community-case-count") public List listCommunityCaseCount(@RequestParam(name = "areaId", required = false) String areaId, @RequestParam(name = "communityId", required = false) String communityId, 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 35089ea..62df640 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 @@ -36,7 +36,7 @@ public class KpiKhxzController extends AbstractController { return new SuccessResult(); } - @GetMapping("update/kh-year/{khYear}/kh-month/{khMonth}") + @GetMapping("reset-update-process") public void resetUpdateProcess() { KpiUpdateMonitor.getInstance().setTaskCount(0); } @@ -112,8 +112,6 @@ public class KpiKhxzController extends AbstractController { kpiKhxzService.exportWgz(httpServletResponse, queryMap); } - - @PutMapping("update-wgz") public synchronized SuccessResult updateWgz(@RequestBody KpiUpdateVO kpiUpdateVO) { kpiKhxzService.updateWgz(kpiUpdateVO); @@ -132,4 +130,10 @@ public class KpiKhxzController extends AbstractController { kpiKhxzService.exportZnbm(httpServletResponse, queryMap); } + @PutMapping("update-znbm") + public synchronized SuccessResult updateZnbm(@RequestBody KpiUpdateVO kpiUpdateVO) { + kpiKhxzService.updateZnbm(kpiUpdateVO); + return new SuccessResult(); + } + } diff --git a/src/main/java/com/cm/bigdata/dao/kpi/IKpiKhxzZnbmDao.java b/src/main/java/com/cm/bigdata/dao/kpi/IKpiKhxzZnbmDao.java index efbe9ff..6f0ff86 100644 --- a/src/main/java/com/cm/bigdata/dao/kpi/IKpiKhxzZnbmDao.java +++ b/src/main/java/com/cm/bigdata/dao/kpi/IKpiKhxzZnbmDao.java @@ -21,4 +21,7 @@ public interface IKpiKhxzZnbmDao { void updateIJ(Map updateParams); List list(Map params); + + void update(Map params); + } diff --git a/src/main/java/com/cm/bigdata/pojo/pos/kpi/NPersonDayCountPO.java b/src/main/java/com/cm/bigdata/pojo/pos/kpi/NPersonDayCountPO.java index 524253f..ce2404a 100644 --- a/src/main/java/com/cm/bigdata/pojo/pos/kpi/NPersonDayCountPO.java +++ b/src/main/java/com/cm/bigdata/pojo/pos/kpi/NPersonDayCountPO.java @@ -9,6 +9,7 @@ public class NPersonDayCountPO { private Integer isSigninLate; private Integer isSignout; private Integer isSignoutEarly; + private Double workDistance; private Integer isHoliday; private Double dayScore; @@ -68,6 +69,14 @@ public class NPersonDayCountPO { this.isSignoutEarly = isSignoutEarly; } + public Double getWorkDistance() { + return workDistance; + } + + public void setWorkDistance(Double workDistance) { + this.workDistance = workDistance; + } + public Integer getIsHoliday() { return isHoliday; } diff --git a/src/main/java/com/cm/bigdata/service/kpi/IDepartmentService.java b/src/main/java/com/cm/bigdata/service/kpi/IDepartmentService.java index 4ec3275..cb097dd 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/IDepartmentService.java +++ b/src/main/java/com/cm/bigdata/service/kpi/IDepartmentService.java @@ -14,5 +14,7 @@ public interface IDepartmentService { List list(); + List listZnbm(); + } 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 d94d618..990cdf9 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/IKpiKhxzService.java +++ b/src/main/java/com/cm/bigdata/service/kpi/IKpiKhxzService.java @@ -42,6 +42,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/DepartmentServiceImpl.java b/src/main/java/com/cm/bigdata/service/kpi/impl/DepartmentServiceImpl.java index ff68b16..30ea626 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/impl/DepartmentServiceImpl.java +++ b/src/main/java/com/cm/bigdata/service/kpi/impl/DepartmentServiceImpl.java @@ -5,11 +5,13 @@ import com.cm.bigdata.pojo.dtos.kpi.DepartmentDTO; import com.cm.bigdata.pojo.pos.kpi.DepartmentPO; import com.cm.bigdata.pojo.pos.kpi.DepartmentUserPO; import com.cm.bigdata.service.kpi.IDepartmentService; +import com.cm.bigdata.utils.KpiUtil; import com.mchange.v2.beans.BeansUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -41,4 +43,16 @@ public class DepartmentServiceImpl implements IDepartmentService { return departmentDTO; }).collect(Collectors.toList()); } + + @Override + public List listZnbm() { + Map params = new HashMap<>(); + params.put("departmentParentId", "0"); + params.put("excludeDepartmentIds", Arrays.asList(KpiUtil.ZF_DEPARTMENT_ID, KpiUtil.GA_DEPARTMENT_ID)); + return listPO(params).stream().map(departmentPO -> { + DepartmentDTO departmentDTO = new DepartmentDTO(); + BeanUtils.copyProperties(departmentPO, departmentDTO); + return departmentDTO; + }).collect(Collectors.toList()); + } } 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 f5f540f..e5a6186 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 @@ -49,61 +49,56 @@ public class KpiKhxzServiceImpl extends AbstractService implements IKpiKhxzServi @Override public void update(Integer khYear, Integer khMonth) { -// KpiUpdateMonitor.getInstance().setTaskCount(0); -// kpiService.updateCommunityBossDayCount(khYear, khMonth, 4); -// kpiKhxzWgyTask.update(khYear, khMonth, 4); -// kpiService.updateNPersonDayCount(KpiUtil.ZGY_ROLE_ID, khYear, khMonth); -// kpiKhxzDdyTask.update(khYear, khMonth); -// khKhxzZfGaTask.update(khYear, khMonth); -// kpiKhxzWgzTask.update(khYear, khMonth); -// kpiKhxzZnbmTask.update(khYear, khMonth); // 这个数要和下面的任务数之和一致 - KpiUpdateMonitor.getInstance().setTaskCount(28); + KpiUpdateMonitor.getInstance().setTaskCount(29); // 开始更新 Executors.newSingleThreadExecutor().execute(() -> { + // 更新案件,1任务 kpiService.updateCaseCount(); KpiUpdateMonitor.getInstance().complete(); + // 更新4级网格员日统计,1任务 kpiService.updateCommunityBossDayCount(khYear, khMonth, 3); KpiUpdateMonitor.getInstance().complete(); + // 更新5级网格员日统计,1任务 kpiService.updateCommunityBossDayCount(khYear, khMonth, 4); KpiUpdateMonitor.getInstance().complete(); + // 更新调度员日统计,1任务 kpiService.updateNPersonDayCount(KpiUtil.DDY_ROLE_ID, khYear, khMonth); KpiUpdateMonitor.getInstance().complete(); + // 更新专管员,1任务 kpiService.updateNPersonDayCount(KpiUtil.ZGY_ROLE_ID, khYear, khMonth); KpiUpdateMonitor.getInstance().complete(); -// kpiKhxzWgyTask.update(khYear, khMonth, 3); -// kpiKhxzWgyTask.update(khYear, khMonth, 4); -// kpiKhxzDdyTask.update(khYear, khMonth); -// khKhxzZfGaTask.update(khYear, khMonth); -// kpiKhxzWgzTask.update(khYear, khMonth); -// kpiKhxzZnbmTask.update(khYear, khMonth); - executorService.execute(() -> { // 更新4级网格员,4任务 kpiKhxzWgyTask.update(khYear, khMonth, 3); }); + executorService.execute(() -> { // 更新5级网格员,4个任务 kpiKhxzWgyTask.update(khYear, khMonth, 4); }); + executorService.execute(() -> { // 调度员,4任务 kpiKhxzDdyTask.update(khYear, khMonth); }); + executorService.execute(() -> { - // 执法公安,4任务 + // 执法公安,5任务 khKhxzZfGaTask.update(khYear, khMonth); }); + executorService.execute(() -> { // 网格长,3任务 kpiKhxzWgzTask.update(khYear, khMonth); }); + executorService.execute(() -> { // 职能部门,4任务 kpiKhxzZnbmTask.update(khYear, khMonth); @@ -190,4 +185,11 @@ public class KpiKhxzServiceImpl extends AbstractService implements IKpiKhxzServi public void exportZnbm(HttpServletResponse httpServletResponse, Map queryMap) throws IOException { ExcelExportUtil.simple(httpServletResponse, "职能部门考核细则", listZnbm(queryMap), KpiKhxzZnbmDTO.class); } + + @Override + public void updateZnbm(KpiUpdateVO kpiUpdateVO) { + kpiUpdateVO.getDatas().forEach(params -> { + kpiKhxzZnbmDao.update(params); + }); + } } diff --git a/src/main/java/com/cm/bigdata/service/kpi/impl/KpiServiceImpl.java b/src/main/java/com/cm/bigdata/service/kpi/impl/KpiServiceImpl.java index e87cf9c..657b66b 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/impl/KpiServiceImpl.java +++ b/src/main/java/com/cm/bigdata/service/kpi/impl/KpiServiceImpl.java @@ -92,6 +92,7 @@ public class KpiServiceImpl implements IKpiService { queryParams.put("isSigninLate", isSigninLate); queryParams.put("isSignout", isSignout); queryParams.put("isSignoutEarly", isSignoutEarly); + queryParams.put("workDistance", workDistance); queryParams.put("populationCount", populationCount); queryParams.put("savePopulationCount", savePopulationCount); @@ -157,7 +158,7 @@ public class KpiServiceImpl implements IKpiService { queryParams.put("dayScore", KpiScoreUtil.getDdyDayScore(isSignin, isSigninLate, isSignout, isSignoutEarly, isHoliday)); } if (StringUtils.equals(roleId, KpiUtil.ZGY_ROLE_ID)) { - queryParams.put("dayScore", KpiScoreUtil.getZgyDayScore(isSignin, isSigninLate, isSignout, isSignoutEarly, isHoliday)); + queryParams.put("dayScore", KpiScoreUtil.getZgyDayScore(isSignin, isSigninLate, isSignout, isSignoutEarly, workDistance, isHoliday)); } queryParams.put("isHoliday", isHoliday); kpiDao.saveNPersonDayCount(queryParams); diff --git a/src/main/java/com/cm/bigdata/service/kpi/task/KpiKhxzZfGaTask.java b/src/main/java/com/cm/bigdata/service/kpi/task/KpiKhxzZfGaTask.java index 6eec840..5905290 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/task/KpiKhxzZfGaTask.java +++ b/src/main/java/com/cm/bigdata/service/kpi/task/KpiKhxzZfGaTask.java @@ -48,6 +48,7 @@ public class KpiKhxzZfGaTask { params.put("khYear", khYear); params.put("khMonth", khMonth); kpiKhxzZfGaDao.delete(params); + KpiUpdateMonitor.getInstance().complete(); } private void updateBase(String departmentId, int khYear, int khMonth) { @@ -65,6 +66,7 @@ public class KpiKhxzZfGaTask { saveParams.put("khMonth", khMonth); kpiKhxzZfGaDao.save(saveParams); }); + KpiUpdateMonitor.getInstance().complete(); } private List listUserId(int khYear, int khMonth) { diff --git a/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzZnbmCDEFGRunnable.java b/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzZnbmCDEFGRunnable.java index 3fe0ee8..ae24d44 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzZnbmCDEFGRunnable.java +++ b/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzZnbmCDEFGRunnable.java @@ -54,7 +54,7 @@ public class KpiKhxzZnbmCDEFGRunnable implements Runnable { updateParams.put("D", inspectCount); updateParams.put("E", unInspectCount); updateParams.put("F", inspectCount * 200D); - updateParams.put("G", 60D / handleCount * inspectCount); + updateParams.put("G", handleCount == 0 ? 0 : 60D / handleCount * inspectCount); updateParams.put("khYear", khYear); updateParams.put("khMonth", khMonth); updateParams.put("userId", userId); diff --git a/src/main/java/com/cm/bigdata/utils/KpiScoreUtil.java b/src/main/java/com/cm/bigdata/utils/KpiScoreUtil.java index 244432c..2359a99 100644 --- a/src/main/java/com/cm/bigdata/utils/KpiScoreUtil.java +++ b/src/main/java/com/cm/bigdata/utils/KpiScoreUtil.java @@ -9,6 +9,7 @@ public class KpiScoreUtil { private static double DDY_SIGNOUT_SCORE = 15D; private static double ZGY_SIGNIN_SCORE = 25D; private static double ZGY_SIGNOUT_SCORE = 25D; + private static double ZGY_DISTANCE_SCORE = 50D; public static double getWgyDayScore(int isSignin, int isSigninLate, int isSignout, int isSignoutEarly, double workDistance, int isHoliday) { @@ -24,7 +25,8 @@ public class KpiScoreUtil { if (isSignout == 1) { signoutScore += isSignoutEarly == 1 ? WGY_SIGNOUT_SCORE / 2 : WGY_SIGNOUT_SCORE; } - if (workDistance > 0) { + // 有签到、签退、或轨迹的都算有轨迹 + if (isSignin == 1 || isSignout == 1 || workDistance > 0) { distanceScore = WGY_DISTANCE_SCORE; } return signinScore + signoutScore + distanceScore; @@ -45,19 +47,24 @@ public class KpiScoreUtil { return signinScore + signoutScore; } - public static double getZgyDayScore(int isSignin, int isSigninLate, int isSignout, int isSignoutEarly, int isHoliday) { + public static double getZgyDayScore(int isSignin, int isSigninLate, int isSignout, int isSignoutEarly, double workDistance, int isHoliday) { if (isHoliday == 1) { return 0; } double signinScore = 0D; double signoutScore = 0D; + double distanceScore = 0D; if (isSignin == 1) { signinScore += isSigninLate == 1 ? ZGY_SIGNIN_SCORE / 2 : ZGY_SIGNIN_SCORE; } if (isSignout == 1) { signoutScore += isSignoutEarly == 1 ? ZGY_SIGNOUT_SCORE / 2 : ZGY_SIGNOUT_SCORE; } - return signinScore + signoutScore; + // 有签到、签退、或轨迹的都算有轨迹 + if (isSignin == 1 || isSignout == 1 || workDistance > 0) { + distanceScore = ZGY_DISTANCE_SCORE; + } + return signinScore + signoutScore + distanceScore; } diff --git a/src/main/java/com/cm/bigdata/utils/KpiUtil.java b/src/main/java/com/cm/bigdata/utils/KpiUtil.java index ab935ee..f1feaa5 100644 --- a/src/main/java/com/cm/bigdata/utils/KpiUtil.java +++ b/src/main/java/com/cm/bigdata/utils/KpiUtil.java @@ -125,15 +125,15 @@ public class KpiUtil { * * @param userLocationService * @param userId - * @param day af535c78-f0ba-4ccf-891b-cf7c6e42e9e8 + * @param day * @return */ public static Double calculateWorkDistance(IUserLocationService userLocationService, String userId, String day) { double workDistance = 0D; - if (!StringUtils.equals(userId, "af535c78-f0ba-4ccf-891b-cf7c6e42e9e8")) { - return workDistance; - } List userLocationPOS = userLocationService.listPOByUserIdAndDate(userId, day); + // 由于轨迹不好统计,为了方便,只要有定位记录就算有轨迹,返回数量。后期在根据情况调整 + return (double) userLocationPOS.size(); + /** Point tempPoint = null; for (UserLocationPO userLocationPO : userLocationPOS) { Point point = new Point(Double.parseDouble(userLocationPO.getUserLatitude()), Double.parseDouble(userLocationPO.getUserLongitude())); @@ -145,6 +145,7 @@ public class KpiUtil { tempPoint = point; } return workDistance; + **/ } public static Map mapPopulationCount(IBasePopulationInfoService basePopulationInfoService, List userIds) { diff --git a/src/main/resources/mybatis/mapper/kpi/kpi-khxz-wgz-mapper.xml b/src/main/resources/mybatis/mapper/kpi/kpi-khxz-wgz-mapper.xml index c9d4ee6..fee319d 100644 --- a/src/main/resources/mybatis/mapper/kpi/kpi-khxz-wgz-mapper.xml +++ b/src/main/resources/mybatis/mapper/kpi/kpi-khxz-wgz-mapper.xml @@ -88,6 +88,14 @@ kh_year = #{khYear} AND kh_month = #{khMonth} + + AND + area_id = #{areaId} + + + AND + community_id = #{communityId} + AND ( B LIKE CONCAT('%', #{keywords}, '%') @@ -114,9 +122,9 @@ P = #{P} WHERE kh_year = #{khYear} - AND + AND kh_month = #{khMonth} - AND + AND user_id = #{userId} diff --git a/src/main/resources/mybatis/mapper/kpi/kpi-khxz-znbm-mapper.xml b/src/main/resources/mybatis/mapper/kpi/kpi-khxz-znbm-mapper.xml index f0ee701..61c1c7d 100644 --- a/src/main/resources/mybatis/mapper/kpi/kpi-khxz-znbm-mapper.xml +++ b/src/main/resources/mybatis/mapper/kpi/kpi-khxz-znbm-mapper.xml @@ -109,6 +109,10 @@ kh_year = #{khYear} AND kh_month = #{khMonth} + + AND + department_id = #{departmentId} + AND ( B LIKE CONCAT('%', #{keywords}, '%') @@ -118,4 +122,28 @@ + + UPDATE + kpi_khxz_znbm + SET + H = #{H}, + reasonH = #{reasonH}, + K = #{K}, + reasonK = #{reasonK}, + L = #{L}, + reasonL = #{reasonL}, + M = #{M}, + reasonM = #{reasonM}, + N = #{N}, + O = #{O}, + P = #{P} + WHERE + kh_year = #{khYear} + AND + kh_month = #{khMonth} + AND + user_id = #{userId} + + + \ No newline at end of file diff --git a/src/main/resources/mybatis/mapper/kpi/kpi-mapper.xml b/src/main/resources/mybatis/mapper/kpi/kpi-mapper.xml index 0c8a723..723773f 100644 --- a/src/main/resources/mybatis/mapper/kpi/kpi-mapper.xml +++ b/src/main/resources/mybatis/mapper/kpi/kpi-mapper.xml @@ -25,6 +25,7 @@ + @@ -156,6 +157,7 @@ is_signin_late, is_signout, is_signout_early, + work_distance, is_holiday, day_score ) VALUES ( @@ -165,6 +167,7 @@ #{isSigninLate}, #{isSignout}, #{isSignoutEarly}, + #{workDistance}, #{isHoliday}, #{dayScore} )