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 62adb1b..8bdf65d 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 @@ -33,7 +33,7 @@ public class KpiKhxzController extends AbstractController { if (percent > 0 && percent < 100) { throw new UpdateException("正在有任务运行"); } - kpiKhxzService.update(khYear, khMonth); + kpiKhxzService.sync(khYear, khMonth); return new SuccessResult(); } @@ -79,7 +79,7 @@ public class KpiKhxzController extends AbstractController { @PutMapping("update-ddy") public synchronized SuccessResult updateDdy(@RequestBody KpiUpdateVO kpiUpdateVO) { - kpiKhxzService.updateDdy(kpiUpdateVO); + kpiKhxzService.syncDdy(kpiUpdateVO); return new SuccessResult(); } @@ -139,67 +139,67 @@ public class KpiKhxzController extends AbstractController { @GetMapping("sync-case") public void syncCase() throws IOException { - kpiKhxzService.updateCase(); + kpiKhxzService.syncCase(); } @GetMapping("sync-wgy3/{year}/{month}") public void syncWgy3(@PathVariable("year") Integer year, @PathVariable("month") Integer month) throws IOException { - kpiKhxzService.updateWgy3(year, month); + kpiKhxzService.syncWgy3(year, month); } @GetMapping("sync-wgy4/{year}/{month}") public void syncWgy4(@PathVariable("year") Integer year, @PathVariable("month") Integer month) throws IOException { - kpiKhxzService.updateWgy4(year, month); + kpiKhxzService.syncWgy4(year, month); } @GetMapping("sync-wgy4/{year}/{month}/{userId}") public void syncWgy4(@PathVariable("year") Integer year, @PathVariable("month") Integer month, @PathVariable("userId") String userId) { - kpiKhxzService.updateWgy4(year, month, userId); + kpiKhxzService.syncWgy4(year, month, userId); } @GetMapping("sync-ddy/{year}/{month}") public void syncDdy(@PathVariable("year") Integer year, @PathVariable("month") Integer month) throws IOException { - kpiKhxzService.updateDdy(year, month); + kpiKhxzService.syncDdy(year, month); } @GetMapping("sync-zgy/{year}/{month}") public void syncZgy(@PathVariable("year") Integer year, @PathVariable("month") Integer month) throws IOException { - kpiKhxzService.updateZgy(year, month); + kpiKhxzService.syncZgy(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); + kpiKhxzService.syncWgy3Task(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); + kpiKhxzService.syncWgy4Task(year, month); } @GetMapping("sync-wgy4-task/{year}/{month}/{userId}") public void syncWgy4Task(@PathVariable("year") Integer year, @PathVariable("month") Integer month, @PathVariable("userId") String userId) throws IOException { - kpiKhxzService.updateWgy4Task(year, month, userId); + kpiKhxzService.syncWgy4Task(year, month, userId); } @GetMapping("sync-ddy-task/{year}/{month}") public void syncDdyTask(@PathVariable("year") Integer year, @PathVariable("month") Integer month) throws IOException { - kpiKhxzService.updateDdyTask(year, month); + kpiKhxzService.syncDdyTask(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); + kpiKhxzService.syncZfGaTask(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); + kpiKhxzService.syncZnbmTask(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); + kpiKhxzService.syncWgzTask(year, month); } 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 ce2404a..bd22d21 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 @@ -4,6 +4,7 @@ public class NPersonDayCountPO { private Long id; private String userId; + private String roleId; private String dayDate; private Integer isSignin; private Integer isSigninLate; @@ -29,6 +30,14 @@ public class NPersonDayCountPO { this.userId = userId; } + public String getRoleId() { + return roleId; + } + + public void setRoleId(String roleId) { + this.roleId = roleId; + } + public String getDayDate() { return dayDate; } 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 77c9610..be47ecc 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/IKpiKhxzService.java +++ b/src/main/java/com/cm/bigdata/service/kpi/IKpiKhxzService.java @@ -10,34 +10,34 @@ import java.util.Map; public interface IKpiKhxzService { - void update(Integer khYear, Integer khMonth); + void sync(Integer khYear, Integer khMonth); - void updateCase(); + void syncCase(); - void updateWgy3(Integer khYear, Integer khMonth); + void syncWgy3(Integer khYear, Integer khMonth); - void updateWgy4(Integer khYear, Integer khMonth); + void syncWgy4(Integer khYear, Integer khMonth); - void updateWgy4(Integer year, Integer month, String userId); + void syncWgy4(Integer year, Integer month, String userId); - void updateDdy(Integer khYear, Integer khMonth); + void syncDdy(Integer khYear, Integer khMonth); - void updateZgy(Integer khYear, Integer khMonth); + void syncZgy(Integer khYear, Integer khMonth); - void updateWgy3Task(Integer khYear, Integer khMonth); + void syncWgy3Task(Integer khYear, Integer khMonth); - void updateWgy4Task(Integer khYear, Integer khMonth); + void syncWgy4Task(Integer khYear, Integer khMonth); - void updateWgy4Task(Integer year, Integer month, String userId); + void syncWgy4Task(Integer year, Integer month, String userId); - void updateDdyTask(Integer khYear, Integer khMonth); + void syncDdyTask(Integer khYear, Integer khMonth); - void updateZfGaTask(Integer khYear, Integer khMonth); + void syncZfGaTask(Integer khYear, Integer khMonth); - void updateZnbmTask(Integer khYear, Integer khMonth); + void syncZnbmTask(Integer khYear, Integer khMonth); - void updateWgzTask(Integer khYear, Integer khMonth); + void syncWgzTask(Integer khYear, Integer khMonth); List listWgy(Map queryMap); @@ -50,7 +50,7 @@ public interface IKpiKhxzService { void exportDdy(HttpServletResponse httpServletResponse, Map queryMap) throws IOException; - void updateDdy(KpiUpdateVO kpiUpdateVO); + void syncDdy(KpiUpdateVO kpiUpdateVO); List listZfGa(Map queryMap); 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 d997c1d..89fee8f 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 @@ -48,49 +48,50 @@ public class KpiKhxzServiceImpl extends AbstractService implements IKpiKhxzServi private ExecutorService executorService = Executors.newFixedThreadPool(10); @Override - public void update(Integer khYear, Integer khMonth) { + public void sync(Integer khYear, Integer khMonth) { // 这个数要和下面的任务数之和一致 KpiUpdateMonitor.getInstance().setTaskCount(29); +// KpiUpdateMonitor.getInstance().setTaskCount(15); // 开始更新 Executors.newSingleThreadExecutor().execute(() -> { // 更新案件,1任务 - updateCase(); + syncCase(); // 更新4级网格员日统计,1任务 - updateWgy3(khYear, khMonth); + syncWgy3(khYear, khMonth); // 更新5级网格员日统计,1任务 - updateWgy4(khYear, khMonth); + syncWgy4(khYear, khMonth); // 更新调度员日统计,1任务 - updateDdy(khYear, khMonth); + syncDdy(khYear, khMonth); // 更新专管员,1任务 - updateZgy(khYear, khMonth); + syncZgy(khYear, khMonth); executorService.execute(() -> { // 更新4级网格员,4任务 - updateWgy3Task(khYear, khMonth); + syncWgy3Task(khYear, khMonth); }); executorService.execute(() -> { // 更新5级网格员,4个任务 - updateWgy4Task(khYear, khMonth); + syncWgy4Task(khYear, khMonth); }); executorService.execute(() -> { // 调度员,4任务 - updateDdyTask(khYear, khMonth); + syncDdyTask(khYear, khMonth); }); executorService.execute(() -> { // 执法公安,5任务 - updateZfGaTask(khYear, khMonth); + syncZfGaTask(khYear, khMonth); }); executorService.execute(() -> { // 职能部门,4任务 - updateZnbmTask(khYear, khMonth); + syncZnbmTask(khYear, khMonth); }); executorService.execute(() -> { @@ -103,78 +104,78 @@ public class KpiKhxzServiceImpl extends AbstractService implements IKpiKhxzServi } } // 网格长,3任务 - updateWgzTask(khYear, khMonth); + syncWgzTask(khYear, khMonth); }); }); } @Override - public void updateCase() { + public void syncCase() { kpiService.updateCaseCount(); KpiUpdateMonitor.getInstance().complete(); } @Override - public void updateWgy3(Integer khYear, Integer khMonth) { + public void syncWgy3(Integer khYear, Integer khMonth) { kpiService.updateCommunityBossDayCount(khYear, khMonth, 3); KpiUpdateMonitor.getInstance().complete(); } @Override - public void updateWgy4(Integer khYear, Integer khMonth) { + public void syncWgy4(Integer khYear, Integer khMonth) { kpiService.updateCommunityBossDayCount(khYear, khMonth, 4); KpiUpdateMonitor.getInstance().complete(); } @Override - public void updateWgy4(Integer year, Integer month, String userId) { + public void syncWgy4(Integer year, Integer month, String userId) { kpiService.updateCommunityBossDayCount(year, month, 4, userId); } @Override - public void updateDdy(Integer khYear, Integer khMonth) { + public void syncDdy(Integer khYear, Integer khMonth) { kpiService.updateNPersonDayCount(KpiUtil.DDY_ROLE_ID, khYear, khMonth); KpiUpdateMonitor.getInstance().complete(); } @Override - public void updateZgy(Integer khYear, Integer khMonth) { + public void syncZgy(Integer khYear, Integer khMonth) { kpiService.updateNPersonDayCount(KpiUtil.ZGY_ROLE_ID, khYear, khMonth); KpiUpdateMonitor.getInstance().complete(); } @Override - public void updateWgy3Task(Integer khYear, Integer khMonth) { + public void syncWgy3Task(Integer khYear, Integer khMonth) { kpiKhxzWgyTask.update(khYear, khMonth, 3); } @Override - public void updateWgy4Task(Integer khYear, Integer khMonth) { + public void syncWgy4Task(Integer khYear, Integer khMonth) { kpiKhxzWgyTask.update(khYear, khMonth, 4); } @Override - public void updateWgy4Task(Integer year, Integer month, String userId) { + public void syncWgy4Task(Integer year, Integer month, String userId) { kpiKhxzWgyTask.update(year, month, 4, userId); } @Override - public void updateDdyTask(Integer khYear, Integer khMonth) { + public void syncDdyTask(Integer khYear, Integer khMonth) { kpiKhxzDdyTask.update(khYear, khMonth); } @Override - public void updateZfGaTask(Integer khYear, Integer khMonth) { + public void syncZfGaTask(Integer khYear, Integer khMonth) { khKhxzZfGaTask.update(khYear, khMonth); } @Override - public void updateZnbmTask(Integer khYear, Integer khMonth) { + public void syncZnbmTask(Integer khYear, Integer khMonth) { kpiKhxzZnbmTask.update(khYear, khMonth); } @Override - public void updateWgzTask(Integer khYear, Integer khMonth) { + public void syncWgzTask(Integer khYear, Integer khMonth) { kpiKhxzWgzTask.update(khYear, khMonth); } @@ -223,7 +224,7 @@ public class KpiKhxzServiceImpl extends AbstractService implements IKpiKhxzServi } @Override - public void updateDdy(KpiUpdateVO kpiUpdateVO) { + public void syncDdy(KpiUpdateVO kpiUpdateVO) { kpiUpdateVO.getDatas().forEach(params -> { kpiKhxzDdyDao.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 ce0189b..cabbc94 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 @@ -333,7 +333,7 @@ public class KpiServiceImpl implements IKpiService { Map> userSigninMap = KpiUtil.mapSignin(userSignService, userIds, date); Map> userSignoutMap = KpiUtil.mapSignout(userSignService, userIds, date); // 删除当日数据 - deleteNPersonDayCount(date); + deleteNPersonDayCount(roleId, date); userPOS.forEach(userPO -> { String userId = userPO.getUserId(); List userSigninPO = userSigninMap.get(userId); @@ -346,6 +346,7 @@ public class KpiServiceImpl implements IKpiService { // 新增 Map queryParams = new HashMap<>(); queryParams.put("userId", userId); + queryParams.put("roleId", roleId); queryParams.put("dayDate", date); queryParams.put("isSignin", isSignin); queryParams.put("isSigninLate", isSigninLate); @@ -391,8 +392,9 @@ public class KpiServiceImpl implements IKpiService { return dates; } - private void deleteNPersonDayCount(String date) { + private void deleteNPersonDayCount(String roleId, String date) { Map params = new HashMap<>(4); + params.put("roleId", roleId); params.put("dayDate", date); kpiDao.deleteNPersonDayCount(params); } diff --git a/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzDdyCRunnable.java b/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzDdyCRunnable.java index 51b3b30..d09fd2c 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzDdyCRunnable.java +++ b/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzDdyCRunnable.java @@ -32,6 +32,7 @@ public class KpiKhxzDdyCRunnable implements Runnable{ Map params = new HashMap<>(); userIds.forEach(userId -> { params.put("userId", userId); + params.put("roleId", KpiUtil.DDY_ROLE_ID); params.put("startTime", dates.get(0)); params.put("endTime", dates.get(dates.size() - 1)); List nPersonDayCountPOS = kpiDao.listNPersonDayCountPO(params); diff --git a/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzZfGaCRunnable.java b/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzZfGaCRunnable.java index be1eb1a..ae6053d 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzZfGaCRunnable.java +++ b/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzZfGaCRunnable.java @@ -10,7 +10,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -public class KpiKhxzZfGaCRunnable implements Runnable{ +public class KpiKhxzZfGaCRunnable implements Runnable { private IKpiKhxzZfGaDao kpiKhxzZfGaDao; private IKpiDao kpiDao; @@ -32,18 +32,25 @@ public class KpiKhxzZfGaCRunnable implements Runnable{ Map params = new HashMap<>(); userIds.forEach(userId -> { params.put("userId", userId); + params.put("roleId", KpiUtil.ZGY_ROLE_ID); params.put("startTime", dates.get(0)); params.put("endTime", dates.get(dates.size() - 1)); List nPersonDayCountPOS = kpiDao.listNPersonDayCountPO(params); int workDay = 0; double totalDayScore = 0D; for (NPersonDayCountPO nPersonDayCountPO : nPersonDayCountPOS) { - totalDayScore += nPersonDayCountPO.getDayScore(); int isHoliday = nPersonDayCountPO.getIsHoliday(); - if (isHoliday == 1) { + double dayScore = nPersonDayCountPO.getDayScore(); + // 如果是假期,有签到签退就算工作日 + if (isHoliday == 1 && dayScore > 0D) { + totalDayScore += nPersonDayCountPO.getDayScore(); + workDay++; continue; } - workDay++; + if (isHoliday == 0) { + totalDayScore += nPersonDayCountPO.getDayScore(); + workDay++; + } } double totalScore = workDay == 0 ? 0D : totalDayScore / workDay; // 保存总分 diff --git a/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzZfGaDEFRunnable.java b/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzZfGaDEFRunnable.java index 9ca7e59..ec6ade7 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzZfGaDEFRunnable.java +++ b/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzZfGaDEFRunnable.java @@ -30,7 +30,7 @@ public class KpiKhxzZfGaDEFRunnable implements Runnable { Map params = new HashMap<>(); params.put("handleYearMonth", String.format("%04d-%02d", khYear, khMonth)); userIds.forEach(userId -> { - params.put("handleUserId", userId); + params.put("reportOrHandleUserId", userId); int unInspectCount = 0; int inspectCount = 0; List casePOS = kpiDao.listCase(params); diff --git a/src/main/java/com/cm/bigdata/utils/KpiScoreUtil.java b/src/main/java/com/cm/bigdata/utils/KpiScoreUtil.java index 8da2bd2..81e4f43 100644 --- a/src/main/java/com/cm/bigdata/utils/KpiScoreUtil.java +++ b/src/main/java/com/cm/bigdata/utils/KpiScoreUtil.java @@ -17,10 +17,10 @@ public class KpiScoreUtil { double signoutScore = 0D; double distanceScore = 0D; if (isSignin == 1) { - signinScore += isSigninLate == 1 ? WGY_SIGNIN_SCORE / 2 : WGY_SIGNIN_SCORE; + signinScore = isSigninLate == 1 ? WGY_SIGNIN_SCORE / 2 : WGY_SIGNIN_SCORE; } if (isSignout == 1) { - signoutScore += isSignoutEarly == 1 ? WGY_SIGNOUT_SCORE / 2 : WGY_SIGNOUT_SCORE; + signoutScore = isSignoutEarly == 1 ? WGY_SIGNOUT_SCORE / 2 : WGY_SIGNOUT_SCORE; } // 有签到、签退、或轨迹的都算有轨迹 if (isSignin == 1 || isSignout == 1 || workDistance > 0) { @@ -30,14 +30,14 @@ public class KpiScoreUtil { if (isLeave == 1) { if (isLeaveSelf == 0) { // 公假,不算矿工 - signinScore += WGY_SIGNIN_SCORE; - signoutScore += WGY_SIGNOUT_SCORE; - distanceScore += WGY_DISTANCE_SCORE; + signinScore = WGY_SIGNIN_SCORE; + signoutScore = WGY_SIGNOUT_SCORE; + distanceScore = WGY_DISTANCE_SCORE; } else { // 私假,并且未超过上限 if (isLeaveSelfOverLimitInQuarter == 0) { - signinScore += isSigninLate == 1 ? WGY_SIGNIN_SCORE / 2 : WGY_SIGNIN_SCORE; - signoutScore += isSignoutEarly == 1 ? WGY_SIGNOUT_SCORE / 2 : WGY_SIGNOUT_SCORE; + signinScore = isSigninLate == 1 ? WGY_SIGNIN_SCORE / 2 : WGY_SIGNIN_SCORE; + signoutScore = isSignoutEarly == 1 ? WGY_SIGNOUT_SCORE / 2 : WGY_SIGNOUT_SCORE; } } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 4781f2c..6b20cf3 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -21,14 +21,14 @@ spring: datasource: druid: db1: - url: jdbc:mysql://127.0.0.1:3306/db_btgxq_bigdata?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false + url: jdbc:mysql://192.168.0.151:3306/db_btgxq_bigdata?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false db-type: mysql driver-class-name: com.mysql.jdbc.Driver username: root password: root mapper-locations: classpath*:mybatis/mapper/**/*.xml db2: - url: jdbc:mysql://127.0.0.1:3306/db_btgxq_city?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false + url: jdbc:mysql://192.168.0.151:3306/db_btgxq_city?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false db-type: mysql driver-class-name: com.mysql.jdbc.Driver username: root diff --git a/src/main/resources/mybatis/mapper/kpi/kpi-mapper.xml b/src/main/resources/mybatis/mapper/kpi/kpi-mapper.xml index 11066da..66730e5 100644 --- a/src/main/resources/mybatis/mapper/kpi/kpi-mapper.xml +++ b/src/main/resources/mybatis/mapper/kpi/kpi-mapper.xml @@ -24,6 +24,7 @@ + @@ -290,12 +291,15 @@ DELETE FROM kpi_n_person WHERE + role_id = #{roleId} + AND day_date = #{dayDate} INSERT INTO kpi_n_person( user_id, + role_id, day_date, is_signin, is_signin_late, @@ -306,6 +310,7 @@ day_score ) VALUES ( #{userId}, + #{roleId}, #{dayDate}, #{isSignin}, #{isSigninLate}, @@ -319,7 +324,7 @@