diff --git a/src/main/java/com/cm/bigdata/config/AuthClientSecurityConfig.java b/src/main/java/com/cm/bigdata/config/AuthClientSecurityConfig.java index 54db111..af7cf94 100644 --- a/src/main/java/com/cm/bigdata/config/AuthClientSecurityConfig.java +++ b/src/main/java/com/cm/bigdata/config/AuthClientSecurityConfig.java @@ -41,7 +41,7 @@ public class AuthClientSecurityConfig extends WebSecurityConfigurerAdapter { .and() .logout().logoutSuccessUrl(authServer.getOauthLogout()) .and() - .authorizeRequests().antMatchers("/app/**", "/route/file/**", "/assets/**", "/api/kpi/khxz/**").permitAll() + .authorizeRequests().antMatchers("/app/**", "/route/file/**", "/assets/**", "/api/kpi/**").permitAll() .and() .authorizeRequests() .anyRequest() 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 ccfdaa3..cbe746f 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 @@ -146,6 +146,15 @@ public class KpiController extends AbstractController { return kpiService.listCommunityBossCaseDayCount(areaId, communityId, startTime, endTime, communityBossLevel); } + @GetMapping("list-community-boss-day-count/user-id/{userId}") + public List listCommunityBossCaseDayCountByUserId( + @PathVariable("userId") String userId, + @RequestParam(name = "year", required = false) Integer year, + @RequestParam(name = "month", required = false) Integer month, + @RequestParam(name = "level") Integer level) { + return kpiService.listCommunityBossDayCountByUserId(userId, year, month, level); + } + @GetMapping("export-community-boss-case-day-count") public void exportCommunityBossCaseDayCount(HttpServletResponse httpServletResponse, @RequestParam(name = "areaId", required = false) String areaId, 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 19011d7..fdd1fd7 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 @@ -1,9 +1,12 @@ package com.cm.bigdata.controller.apis.kpi; +import com.cm.bigdata.monitor.KpiUpdateMonitor; import com.cm.bigdata.service.kpi.IKpiKhxzService; import com.cm.common.base.AbstractController; import com.cm.common.constants.ISystemConstant; +import com.cm.common.exception.UpdateException; import com.cm.common.result.SuccessResult; +import com.cm.common.result.SuccessResultData; import io.swagger.annotations.Api; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -19,12 +22,21 @@ public class KpiKhxzController extends AbstractController { @Autowired private IKpiKhxzService kpiKhxzService; - @PutMapping("update-wgy/kh-year/{khYear}/kh-month/{khMonth}/wgy-level/{wgyLevel}") - public synchronized SuccessResult updateWgy(@PathVariable("khYear") Integer khYear, @PathVariable("khMonth") Integer khMonth, @PathVariable("wgyLevel") Integer wgyLevel) { - kpiKhxzService.updateWgy(khYear, khMonth, wgyLevel); + @PutMapping("update/kh-year/{khYear}/kh-month/{khMonth}") + public synchronized SuccessResult update(@PathVariable("khYear") Integer khYear, @PathVariable("khMonth") Integer khMonth) { + double percent = KpiUpdateMonitor.getInstance().getPercent(); + if (percent > 0 && percent < 100) { + throw new UpdateException("正在有任务运行"); + } + kpiKhxzService.update(khYear, khMonth); return new SuccessResult(); } + @GetMapping("get-update-percent") + public SuccessResultData getUpdatePercent() { + return new SuccessResultData<>(KpiUpdateMonitor.getInstance().getPercent()); + } + @GetMapping("list-wgy") public List> listWgy() { Map queryMap = requestParams(); diff --git a/src/main/java/com/cm/bigdata/dao/kpi/IKpiDao.java b/src/main/java/com/cm/bigdata/dao/kpi/IKpiDao.java index 245a7f7..c0630d9 100644 --- a/src/main/java/com/cm/bigdata/dao/kpi/IKpiDao.java +++ b/src/main/java/com/cm/bigdata/dao/kpi/IKpiDao.java @@ -35,4 +35,6 @@ public interface IKpiDao { List listNPersonDayCountPO(Map queryParams); + List listCase(Map params); + } diff --git a/src/main/java/com/cm/bigdata/dao/kpi/IKpiKhxzWgyDao.java b/src/main/java/com/cm/bigdata/dao/kpi/IKpiKhxzWgyDao.java index 1e85e7d..862895d 100644 --- a/src/main/java/com/cm/bigdata/dao/kpi/IKpiKhxzWgyDao.java +++ b/src/main/java/com/cm/bigdata/dao/kpi/IKpiKhxzWgyDao.java @@ -16,7 +16,10 @@ public interface IKpiKhxzWgyDao { @MapKey("id") List> listWgy(Map params); + List listUserId(Map params); + void updateC(Map updateParams); - List listUserId(Map params); + void updateEGIKRT(Map params); + } diff --git a/src/main/java/com/cm/bigdata/monitor/KpiUpdateMonitor.java b/src/main/java/com/cm/bigdata/monitor/KpiUpdateMonitor.java new file mode 100644 index 0000000..6d997de --- /dev/null +++ b/src/main/java/com/cm/bigdata/monitor/KpiUpdateMonitor.java @@ -0,0 +1,40 @@ +package com.cm.bigdata.monitor; + +import com.cm.common.exception.UpdateException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.atomic.AtomicInteger; + +public class KpiUpdateMonitor { + private static final Logger LOG = LoggerFactory.getLogger(KpiUpdateMonitor.class); + private static KpiUpdateMonitor INSTANCE = KpiUpdateMonitorFactory.KPI_UPDATE_MONITOR; + private Integer taskCount = 0; + private AtomicInteger completeTaskCount = new AtomicInteger(0); + + public static KpiUpdateMonitor getInstance() { + return INSTANCE; + } + + public synchronized void setTaskCount(int newValue) { + taskCount = newValue; + completeTaskCount.set(0); + } + + public void complete() { + completeTaskCount.getAndAdd(1); + } + + public double getPercent() { + LOG.debug("task: {}, complete: {}", taskCount, completeTaskCount); + if (taskCount == 0) { + return 100; + } + return (double) completeTaskCount.get() / taskCount * 100D; + } + + private static class KpiUpdateMonitorFactory { + public static KpiUpdateMonitor KPI_UPDATE_MONITOR = new KpiUpdateMonitor(); + } + +} diff --git a/src/main/java/com/cm/bigdata/pojo/dtos/kpi/CommunityBossDayCountDTO.java b/src/main/java/com/cm/bigdata/pojo/dtos/kpi/CommunityBossDayCountDTO.java new file mode 100644 index 0000000..ffd4bd3 --- /dev/null +++ b/src/main/java/com/cm/bigdata/pojo/dtos/kpi/CommunityBossDayCountDTO.java @@ -0,0 +1,113 @@ +package com.cm.bigdata.pojo.dtos.kpi; + +public class CommunityBossDayCountDTO { + + private Long id; + private String userId; + private String dayDate; + private Integer isSignin; + private Integer isSigninLate; + private Integer isSignout; + private Integer isSignoutEarly; + private Double workDistance; + private Integer savePopulationCount; + private Integer updatePopulationCount; + private Integer isHoliday; + private Double dayScore; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getDayDate() { + return dayDate; + } + + public void setDayDate(String dayDate) { + this.dayDate = dayDate; + } + + public Integer getIsSignin() { + return isSignin; + } + + public void setIsSignin(Integer isSignin) { + this.isSignin = isSignin; + } + + public Integer getIsSigninLate() { + return isSigninLate; + } + + public void setIsSigninLate(Integer isSigninLate) { + this.isSigninLate = isSigninLate; + } + + public Integer getIsSignout() { + return isSignout; + } + + public void setIsSignout(Integer isSignout) { + this.isSignout = isSignout; + } + + public Integer getIsSignoutEarly() { + return isSignoutEarly; + } + + public void setIsSignoutEarly(Integer isSignoutEarly) { + this.isSignoutEarly = isSignoutEarly; + } + + public Double getWorkDistance() { + return workDistance; + } + + public void setWorkDistance(Double workDistance) { + this.workDistance = workDistance; + } + + public Integer getSavePopulationCount() { + return savePopulationCount; + } + + public void setSavePopulationCount(Integer savePopulationCount) { + this.savePopulationCount = savePopulationCount; + } + + public Integer getUpdatePopulationCount() { + return updatePopulationCount; + } + + public void setUpdatePopulationCount(Integer updatePopulationCount) { + this.updatePopulationCount = updatePopulationCount; + } + + public Integer getIsHoliday() { + return isHoliday; + } + + public void setIsHoliday(Integer isHoliday) { + this.isHoliday = isHoliday; + } + + public Double getDayScore() { + return dayScore; + } + + public void setDayScore(Double dayScore) { + this.dayScore = dayScore; + } +} diff --git a/src/main/java/com/cm/bigdata/pojo/pos/kpi/CasePO.java b/src/main/java/com/cm/bigdata/pojo/pos/kpi/CasePO.java index fca6fb9..2e4db06 100644 --- a/src/main/java/com/cm/bigdata/pojo/pos/kpi/CasePO.java +++ b/src/main/java/com/cm/bigdata/pojo/pos/kpi/CasePO.java @@ -15,18 +15,18 @@ public class CasePO { private String handleEndTimeLong; private String handleEndTime; private String gmtHandle; - private String isTimeout; + private Integer isTimeout; private String gmtInspect; - private String isSelf; + private Integer isSelf; private String reportUserId; private String handleUserId; private String inspectUserId; private String inspectScore; - private String isDelete; + private Integer isDelete; private String gmtDelete; private String deleteUserId; - private String totalUrge; - private String totalBack; + private Integer totalUrge; + private Integer totalBack; private Integer caseStatus; private Integer caseSource; private Integer isAccept; @@ -138,11 +138,11 @@ public class CasePO { this.gmtHandle = gmtHandle; } - public String getIsTimeout() { + public Integer getIsTimeout() { return isTimeout; } - public void setIsTimeout(String isTimeout) { + public void setIsTimeout(Integer isTimeout) { this.isTimeout = isTimeout; } @@ -154,11 +154,11 @@ public class CasePO { this.gmtInspect = gmtInspect; } - public String getIsSelf() { + public Integer getIsSelf() { return isSelf; } - public void setIsSelf(String isSelf) { + public void setIsSelf(Integer isSelf) { this.isSelf = isSelf; } @@ -194,11 +194,11 @@ public class CasePO { this.inspectScore = inspectScore; } - public String getIsDelete() { + public Integer getIsDelete() { return isDelete; } - public void setIsDelete(String isDelete) { + public void setIsDelete(Integer isDelete) { this.isDelete = isDelete; } @@ -218,19 +218,19 @@ public class CasePO { this.deleteUserId = deleteUserId; } - public String getTotalUrge() { - return totalUrge; + public Integer getTotalUrge() { + return totalUrge == null ? 0 : totalUrge; } - public void setTotalUrge(String totalUrge) { + public void setTotalUrge(Integer totalUrge) { this.totalUrge = totalUrge; } - public String getTotalBack() { + public Integer getTotalBack() { return totalBack; } - public void setTotalBack(String totalBack) { + public void setTotalBack(Integer totalBack) { this.totalBack = totalBack; } 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 c8bfb92..c483cfe 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/IKpiKhxzService.java +++ b/src/main/java/com/cm/bigdata/service/kpi/IKpiKhxzService.java @@ -5,7 +5,7 @@ import java.util.Map; public interface IKpiKhxzService { - void updateWgy(Integer khYear, Integer khMonth, Integer wgyLevel); + void update(Integer khYear, Integer khMonth); List> listWgy(Map queryMap); diff --git a/src/main/java/com/cm/bigdata/service/kpi/IKpiService.java b/src/main/java/com/cm/bigdata/service/kpi/IKpiService.java index 970ace4..c13f873 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/IKpiService.java +++ b/src/main/java/com/cm/bigdata/service/kpi/IKpiService.java @@ -64,4 +64,7 @@ public interface IKpiService { void exportNPersonCaseDayCount(HttpServletResponse httpServletResponse, String departmentId, String startTime, String endTime) throws IOException; + List listCommunityBossDayCountByUserId(String userId, Integer year, Integer month, Integer level); + + } diff --git a/src/main/java/com/cm/bigdata/service/kpi/IUserService.java b/src/main/java/com/cm/bigdata/service/kpi/IUserService.java index 51843ff..a3632bd 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/IUserService.java +++ b/src/main/java/com/cm/bigdata/service/kpi/IUserService.java @@ -12,4 +12,6 @@ public interface IUserService { List listPO(Map params); + List listPOByKeywords(Object userName); + } 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 25abf45..73cd009 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 @@ -1,7 +1,9 @@ package com.cm.bigdata.service.kpi.impl; import com.cm.bigdata.dao.kpi.IKpiKhxzDao; +import com.cm.bigdata.monitor.KpiUpdateMonitor; import com.cm.bigdata.service.kpi.IKpiKhxzService; +import com.cm.bigdata.service.kpi.IKpiService; import com.cm.bigdata.service.kpi.task.KpiKhxzWgyTask; import com.cm.common.base.AbstractService; import org.springframework.beans.factory.annotation.Autowired; @@ -9,22 +11,47 @@ import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; @Service public class KpiKhxzServiceImpl extends AbstractService implements IKpiKhxzService { @Autowired private IKpiKhxzDao kpiKhxzDao; + + @Autowired + private IKpiService kpiService; + @Autowired private KpiKhxzWgyTask kpiKhxzWgyTask; @Override - public void updateWgy(Integer khYear, Integer khMonth, Integer wgyLevel) { - kpiKhxzWgyTask.update(khYear, khMonth, wgyLevel); + public void update(Integer khYear, Integer khMonth) { + // 这个数要和下面的任务数之和一致 + KpiUpdateMonitor.getInstance().setTaskCount(11); + // 开始更新 + Executors.newSingleThreadExecutor().execute(() -> { + // 更新案件,1任务 + kpiService.updateCaseCount(); + KpiUpdateMonitor.getInstance().complete(); + // 更新4级网格员日统计,1任务 + kpiService.updateCommunityBossDayCount(khYear, khMonth, 3); + KpiUpdateMonitor.getInstance().complete(); + // 更新4级网格员,4任务 + kpiKhxzWgyTask.update(khYear, khMonth, 3); + // 更新5级网格员日统计,1任务 + kpiService.updateCommunityBossDayCount(khYear, khMonth, 4); + KpiUpdateMonitor.getInstance().complete(); + // 更新5级网格员,4个任务 + kpiKhxzWgyTask.update(khYear, khMonth, 4); + }); } @Override public List> listWgy(Map queryMap) { return kpiKhxzDao.listWgy(queryMap); } + + } 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 9928ce9..7b34059 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 @@ -2,6 +2,7 @@ package com.cm.bigdata.service.kpi.impl; import com.cm.bigdata.dao.kpi.IKpiDao; import com.cm.bigdata.dao.kpi.IKpiHolidayDao; +import com.cm.bigdata.monitor.KpiUpdateMonitor; import com.cm.bigdata.pojo.dtos.kpi.*; import com.cm.bigdata.pojo.pos.kpi.*; import com.cm.bigdata.service.kpi.*; @@ -509,6 +510,21 @@ public class KpiServiceImpl implements IKpiService { ExcelExportUtil.simple(httpServletResponse, "专管员考勤", nPersonCaseDayCountDTOS, NPersonCaseDayCountDTO.class); } + @Override + public List listCommunityBossDayCountByUserId(String userId, Integer year, Integer month, Integer level) { + List dates = KpiUtil.listDate(year, month); + Map params = new HashMap<>(); + params.put("startTime", dates.get(0)); + params.put("endTime", dates.get(dates.size() - 1)); + params.put("level", level); + params.put("userId", userId); + return kpiDao.listCommunityBossDayCountPO(params).stream().map(communityBossDayCountPO -> { + CommunityBossDayCountDTO communityBossDayCountDTO = new CommunityBossDayCountDTO(); + BeanUtils.copyProperties(communityBossDayCountPO, communityBossDayCountDTO); + return communityBossDayCountDTO; + }).collect(Collectors.toList()); + } + private Integer countCase(Map params) { return kpiDao.countCase(params); } diff --git a/src/main/java/com/cm/bigdata/service/kpi/impl/UserServiceImpl.java b/src/main/java/com/cm/bigdata/service/kpi/impl/UserServiceImpl.java index 12b393b..91d60c4 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/impl/UserServiceImpl.java +++ b/src/main/java/com/cm/bigdata/service/kpi/impl/UserServiceImpl.java @@ -35,4 +35,10 @@ public class UserServiceImpl implements IUserService { return userDao.listPO(params); } + @Override + public List listPOByKeywords(Object keywords) { + Map params = new HashMap<>(); + params.put("keywords", keywords); + return userDao.listPO(params); + } } 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 bb1c0aa..4e5d0ca 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 @@ -1,13 +1,16 @@ package com.cm.bigdata.service.kpi.task; import com.cm.bigdata.dao.kpi.IKpiDao; +import com.cm.bigdata.dao.kpi.IKpiHolidayDao; import com.cm.bigdata.dao.kpi.IKpiKhxzWgyDao; +import com.cm.bigdata.monitor.KpiUpdateMonitor; import com.cm.bigdata.pojo.dtos.kpi.CommunityBossDTO; import com.cm.bigdata.pojo.pos.kpi.UserPO; import com.cm.bigdata.service.kpi.ICommunityBossService; import com.cm.bigdata.service.kpi.IKpiService; import com.cm.bigdata.service.kpi.IUserService; import com.cm.bigdata.service.kpi.task.sub.KpiKhxzWgyCRunnable; +import com.cm.bigdata.service.kpi.task.sub.KpiKhxzWgyEGIKRTRunnable; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -17,7 +20,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; import java.util.stream.Collectors; @Service @@ -28,41 +30,36 @@ public class KpiKhxzWgyTask { @Autowired private IKpiDao kpiDao; @Autowired + private IKpiHolidayDao kpiHolidayDao; + @Autowired private IUserService userService; @Autowired private ICommunityBossService communityBossService; - @Autowired - private IKpiService kpiService; + + private ExecutorService executorService = Executors.newFixedThreadPool(10); public void update(int khYear, int khMonth, int wgyLevel) { - kpiService.updateCommunityBossDayCount(khYear, khMonth, wgyLevel); - deleteBase(khYear, khMonth, wgyLevel); - updateBase(khYear, khMonth, wgyLevel); + deleteBaseWgy(khYear, khMonth, wgyLevel); + updateBaseWgy(khYear, khMonth, wgyLevel); List userIds = listUserIds(khYear, khMonth, wgyLevel); if (userIds.isEmpty()) { return; } executorService.execute(new KpiKhxzWgyCRunnable(kpiKhxzWgyDao, kpiDao, khYear, khMonth, wgyLevel, userIds)); + executorService.execute(new KpiKhxzWgyEGIKRTRunnable(kpiKhxzWgyDao, kpiHolidayDao, kpiDao, khYear, khMonth, wgyLevel, userIds)); } - private List listUserIds(int khYear, int khMonth, int wgyLevel) { - Map params = new HashMap<>(); - params.put("khYear", khYear); - params.put("khMonth", khMonth); - params.put("wgyLevel", wgyLevel); - return kpiKhxzWgyDao.listUserId(params); - } - - private void deleteBase(int khYear, int khMonth, int wgyLevel) { + private void deleteBaseWgy(int khYear, int khMonth, int wgyLevel) { Map params = new HashMap<>(); params.put("khYear", khYear); params.put("khMonth", khMonth); params.put("wgyLevel", wgyLevel); kpiKhxzWgyDao.delete(params); + KpiUpdateMonitor.getInstance().complete(); } - private void updateBase(int khYear, int khMonth, int wgyLevel) { + private void updateBaseWgy(int khYear, int khMonth, int wgyLevel) { Map params = new HashMap<>(); params.put("communityBossLevel", wgyLevel); // 删除 @@ -92,12 +89,22 @@ public class KpiKhxzWgyTask { saveParams.put("areaId", areaId); saveParams.put("communityId", communityId); saveParams.put("userId", userPO.getUserId()); + saveParams.put("userUsername", userPO.getUserUsername()); saveParams.put("B", userPO.getUserName()); saveParams.put("khYear", khYear); saveParams.put("khMonth", khMonth); saveParams.put("wgyLevel", wgyLevel); kpiKhxzWgyDao.save(saveParams); }); + KpiUpdateMonitor.getInstance().complete(); + } + + private List listUserIds(int khYear, int khMonth, int wgyLevel) { + Map params = new HashMap<>(); + params.put("khYear", khYear); + params.put("khMonth", khMonth); + params.put("wgyLevel", wgyLevel); + return kpiKhxzWgyDao.listUserId(params); } } diff --git a/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzWgyCRunnable.java b/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzWgyCRunnable.java index 53c20e7..aab3065 100644 --- a/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzWgyCRunnable.java +++ b/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzWgyCRunnable.java @@ -2,6 +2,7 @@ package com.cm.bigdata.service.kpi.task.sub; import com.cm.bigdata.dao.kpi.IKpiDao; import com.cm.bigdata.dao.kpi.IKpiKhxzWgyDao; +import com.cm.bigdata.monitor.KpiUpdateMonitor; import com.cm.bigdata.pojo.pos.kpi.CommunityBossDayCountPO; import com.cm.bigdata.utils.KpiUtil; @@ -30,34 +31,34 @@ public class KpiKhxzWgyCRunnable implements Runnable { @Override public void run() { List dates = KpiUtil.listDate(year, month); - dates.forEach(date -> { - Map params = new HashMap<>(); - params.put("level", level); - userIds.forEach(userId -> { - params.put("userId", userId); - params.put("dayDate", date); - List communityBossDayCountPOS = kpiDao.listCommunityBossDayCountPO(params); - int workDay = 0; - double totalDayScore = 0D; - for (CommunityBossDayCountPO communityBossDayCountPO : communityBossDayCountPOS) { - int isHoliday = communityBossDayCountPO.getIsHoliday(); - if (isHoliday == 1) { - continue; - } - workDay++; - totalDayScore += communityBossDayCountPO.getDayScore(); + Map params = new HashMap<>(); + params.put("level", level); + userIds.forEach(userId -> { + params.put("userId", userId); + params.put("startTime", dates.get(0)); + params.put("endTime", dates.get(dates.size() - 1)); + List communityBossDayCountPOS = kpiDao.listCommunityBossDayCountPO(params); + int workDay = 0; + double totalDayScore = 0D; + for (CommunityBossDayCountPO communityBossDayCountPO : communityBossDayCountPOS) { + totalDayScore += communityBossDayCountPO.getDayScore(); + int isHoliday = communityBossDayCountPO.getIsHoliday(); + if (isHoliday == 1) { + continue; } - double totalScore = workDay == 0 ? 0D : totalDayScore / workDay; - // 保存总分 - Map updateParams = new HashMap<>(); - updateParams.put("khYear", year); - updateParams.put("khMonth", month); - updateParams.put("wgyLevel", level); - updateParams.put("userId", userId); - updateParams.put("C", totalScore); - kpiKhxzWgyDao.updateC(updateParams); - }); + workDay++; + } + double totalScore = workDay == 0 ? 0D : totalDayScore / workDay; + // 保存总分 + Map updateParams = new HashMap<>(); + updateParams.put("khYear", year); + updateParams.put("khMonth", month); + updateParams.put("wgyLevel", level); + updateParams.put("userId", userId); + updateParams.put("C", totalScore); + kpiKhxzWgyDao.updateC(updateParams); }); + KpiUpdateMonitor.getInstance().complete(); } } diff --git a/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzWgyDRunnable.java b/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzWgyDRunnable.java deleted file mode 100644 index 63cb1c5..0000000 --- a/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzWgyDRunnable.java +++ /dev/null @@ -1,136 +0,0 @@ -package com.cm.bigdata.service.kpi.task.sub; - -import com.cm.bigdata.dao.kpi.IKpiHolidayDao; -import com.cm.bigdata.dao.kpi.IKpiKhxzWgyDao; -import com.cm.bigdata.pojo.pos.kpi.HolidayPO; -import com.cm.bigdata.utils.KpiUtil; -import com.cm.common.constants.ISystemConstant; -import javafx.scene.effect.InnerShadow; -import org.apache.commons.lang3.StringUtils; -import org.joda.time.DateTime; -import org.joda.time.format.DateTimeFormat; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class KpiKhxzWgyDRunnable implements Runnable { - - private IKpiKhxzWgyDao kpiKhxzWgyDao; - private IKpiHolidayDao kpiHolidayDao; - private int year; - private int month; - private int level; - - @Override - public void run() { - List holidayPOS = listHoliday(); - List> dayWeeks = listDayWeekOfMonth(year, month); - int shouldReportCount = 0; - for (List dws : dayWeeks) { - int holidayCount = 0; - for (DayWeek dayWeek : dws) { - boolean isHoliday = false; - for (HolidayPO holidayPO : holidayPOS) { - String holiday = String.format("%04d-%02d-%02d", holidayPO.getHolidayYear(), holidayPO.getHolidayMonth(), holidayPO.getHolidayDay()); - if (StringUtils.equals(dayWeek.getDate(), holiday)) { - isHoliday = true; - break; - } - } - if (isHoliday) { - holidayCount++; - } - } - // 如果假期小于4天,就应该上报一条 - if (holidayCount > 4) { - shouldReportCount++; - } - } - } - - private List listHoliday() { - Map params = new HashMap<>(); - params.put("holidayYear", year); - params.put("holidayMonth", month); - return kpiHolidayDao.list(params); - } - - private List> listDayWeekOfMonth(int year, int month) { - DateTime dateTime = DateTime.parse(String.format("%04d-%02d", year, month), DateTimeFormat.forPattern("yyyy-MM")); - DateTime.Property dayOfMonth = dateTime.dayOfMonth(); - DateTime monthEndDateTime = dayOfMonth.withMaximumValue(); - int monthEndDay = monthEndDateTime.getDayOfMonth(); - List> dayWeeks = new ArrayList<>(); - int weekOfMonth = 1; - List currentWeekDays = new ArrayList<>(); - for (int i = 1; i <= monthEndDay; i++) { - DateTime dayDateTime = dateTime.withDayOfMonth(i); - String day = dayDateTime.toString(DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD)); - DayWeek dayWeek = new DayWeek(day, weekOfMonth, dayDateTime.dayOfWeek().get()); - currentWeekDays.add(dayWeek); - if (dayWeek.getDayOfWeek() == 7 || (i == monthEndDay - 1)) { - dayWeeks.add(currentWeekDays); - weekOfMonth++; - currentWeekDays = new ArrayList<>(); - } - } - return dayWeeks; - } - - public static class DayWeek { - private String date; - private int year; - private int month; - private int day; - private int weekOfMonth; - private int dayOfWeek; - - public DayWeek(String date, int weekOfMonth, int dayOfWeek) { - this.date = date; - this.weekOfMonth = weekOfMonth; - this.dayOfWeek = dayOfWeek; - String[] dateArray = date.split("-"); - this.year = Integer.parseInt(dateArray[0]); - this.month = Integer.parseInt(dateArray[1]); - this.day = Integer.parseInt(dateArray[2]); - } - - public String getDate() { - return date; - } - - public int getYear() { - return year; - } - - public int getMonth() { - return month; - } - - public int getDay() { - return day; - } - - public int getWeekOfMonth() { - return weekOfMonth; - } - - public int getDayOfWeek() { - return dayOfWeek; - } - - @Override - public String toString() { - return "DayWeek{" + - "date='" + date + '\'' + - ", year=" + year + - ", month=" + month + - ", day=" + day + - ", weekOfMonth=" + weekOfMonth + - ", dayOfWeek=" + dayOfWeek + - '}'; - } - } -} 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 new file mode 100644 index 0000000..8e9a7fc --- /dev/null +++ b/src/main/java/com/cm/bigdata/service/kpi/task/sub/KpiKhxzWgyEGIKRTRunnable.java @@ -0,0 +1,159 @@ +package com.cm.bigdata.service.kpi.task.sub; + +import com.cm.bigdata.dao.kpi.IKpiDao; +import com.cm.bigdata.dao.kpi.IKpiHolidayDao; +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.utils.KpiUtil; +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class KpiKhxzWgyEGIKRTRunnable implements Runnable { + + private IKpiKhxzWgyDao kpiKhxzWgyDao; + private IKpiHolidayDao kpiHolidayDao; + private IKpiDao kpiDao; + private int year; + private int month; + private int level; + private List userIds; + + public KpiKhxzWgyEGIKRTRunnable(IKpiKhxzWgyDao kpiKhxzWgyDao, IKpiHolidayDao kpiHolidayDao, IKpiDao kpiDao, int year, int month, int level, List userIds) { + this.kpiKhxzWgyDao = kpiKhxzWgyDao; + this.kpiHolidayDao = kpiHolidayDao; + this.kpiDao = kpiDao; + this.year = year; + this.month = month; + this.level = level; + this.userIds = userIds; + } + + @Override + public void run() { + List holidayPOS = listHoliday(); + List> dayWeeks = KpiUtil.listDayWeekOfMonth(year, month); + List> shouldReportDayWeeks = listShouldReportDayWeek(holidayPOS, dayWeeks); + updateEGIKRT(userIds, shouldReportDayWeeks); + KpiUpdateMonitor.getInstance().complete(); + } + + /** + * 上报统计数组 + * + * @param holidayPOS + * @param dayWeeks + * @return [应报,实报,少报,多报] + */ + public static List> listShouldReportDayWeek(List holidayPOS, List> dayWeeks) { + List> shouldReportDayWeeks = new ArrayList<>(); + for (List dws : dayWeeks) { + int workdayCount = 0; + for (KpiUtil.DayWeek dayWeek : dws) { + boolean isHoliday = false; + for (HolidayPO holidayPO : holidayPOS) { + String holiday = String.format("%04d-%02d-%02d", holidayPO.getHolidayYear(), holidayPO.getHolidayMonth(), holidayPO.getHolidayDay()); + if (StringUtils.equals(dayWeek.getDate(), holiday)) { + dayWeek.setHoliday(true); + isHoliday = true; + break; + } + } + if (isHoliday) { + continue; + } + workdayCount++; + } + // 工作天数大于三天,需要上报 + if (workdayCount > 3) { + shouldReportDayWeeks.add(dws); + } + } + return shouldReportDayWeeks; + } + + private void updateEGIKRT(List userIds, List> shouldReportDayWeeks) { + int shouldCount = shouldReportDayWeeks.size(); + userIds.forEach(userId -> { + // 每周上报 + int weekReportCount = 0; + // 实报 + int realityCount = 0; + // 少报 + int lackCount = 0; + // 多报 + int exceedCount = 0; + // 督办次数 + int urgeCount = 0; + // 超时检查数量 + int inspectTimeoutCount = 0; + for (List shouldReportDayWeek : shouldReportDayWeeks) { + String startTime = shouldReportDayWeek.get(0).getDate(); + String endTime = shouldReportDayWeek.get(shouldReportDayWeek.size() - 1).getDate(); + Map params = new HashMap<>(); + params.put("reportUserId", userId); + params.put("startTime", startTime); + params.put("endTime", endTime); + List casePOS = kpiDao.listCase(params); + boolean isWeekReport = false; + for (CasePO casePO : casePOS) { + urgeCount += casePO.getTotalUrge(); + // 自处理 + Integer isSelf = casePO.getIsSelf(); + // 不是自处理,上报就算处理 + if (isSelf == 0) { + realityCount++; + isWeekReport = true; + continue; + } + // 处理时间 + String gmtHandle = casePO.getGmtHandle(); + if (StringUtils.isBlank(gmtHandle)) { + continue; + } + // 检查时间 + String gmtInspect = casePO.getGmtInspect(); + if (StringUtils.isBlank(gmtInspect)) { + continue; + } + // 处理时间和检查时间超过24小时 + if (KpiUtil.isdateTimeIn24Hours(gmtHandle, gmtInspect)) { + inspectTimeoutCount++; + } + if (KpiUtil.isDateBetween(gmtInspect, startTime, endTime)) { + realityCount++; + isWeekReport = true; + } + } + weekReportCount += isWeekReport ? 1 : 0; + lackCount = Math.max(shouldCount - weekReportCount, 0); + exceedCount = Math.max(realityCount - shouldCount, 0); + } + Map updateParams = new HashMap<>(); + updateParams.put("E", shouldCount); + updateParams.put("G", weekReportCount); + updateParams.put("I", lackCount); + updateParams.put("K", exceedCount); + updateParams.put("R", urgeCount); + updateParams.put("T", inspectTimeoutCount * 0.1); + updateParams.put("khYear", year); + updateParams.put("khMonth", month); + updateParams.put("wgyLevel", level); + updateParams.put("userId", userId); + kpiKhxzWgyDao.updateEGIKRT(updateParams); + }); + } + + private List listHoliday() { + Map params = new HashMap<>(); + params.put("holidayYear", year); + params.put("holidayMonth", month); + return kpiHolidayDao.list(params); + } + +} diff --git a/src/main/java/com/cm/bigdata/utils/KpiUtil.java b/src/main/java/com/cm/bigdata/utils/KpiUtil.java index 51839f4..6b63e81 100644 --- a/src/main/java/com/cm/bigdata/utils/KpiUtil.java +++ b/src/main/java/com/cm/bigdata/utils/KpiUtil.java @@ -1,6 +1,5 @@ package com.cm.bigdata.utils; -import com.cm.bigdata.dao.kpi.IKpiKhxzWgyDao; import com.cm.bigdata.pojo.pos.kpi.BasePopulationInfoCountPO; import com.cm.bigdata.pojo.pos.kpi.UserLocationPO; import com.cm.bigdata.pojo.pos.kpi.UserSigninPO; @@ -13,13 +12,38 @@ import com.cm.common.utils.point.Point; import com.cm.common.utils.point.PointUtil; import org.apache.commons.lang3.StringUtils; import org.joda.time.DateTime; +import org.joda.time.Hours; import org.joda.time.format.DateTimeFormat; import java.util.*; -import java.util.stream.Collectors; public class KpiUtil { + public static boolean isdateTimeIn24Hours(String date1, DateTime date2) { + date1 = date1.split("\\.")[0]; + DateTime date1DateTime = DateTime.parse(date1, DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD_HH_MM_SS)); + return Hours.hoursBetween(date1DateTime, date2).getHours() < 24; + } + + public static boolean isdateTimeIn24Hours(String date1, String date2) { + date1 = date1.split("\\.")[0]; + date2 = date2.split("\\.")[0]; + DateTime date1DateTime = DateTime.parse(date1, DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD_HH_MM_SS)); + DateTime date2DateTime = DateTime.parse(date2, DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD_HH_MM_SS)); + return Hours.hoursBetween(date1DateTime, date2DateTime).getHours() < 24; + } + + public static boolean isDateBetween(String date, String startDate, String endDate) { + if (StringUtils.isBlank(date)) { + return false; + } + date = date.split("\\.")[0]; + DateTime dateTime = DateTime.parse(date, DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD_HH_MM_SS)); + DateTime startDateTime = DateTime.parse(startDate, DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD)); + DateTime endDateTime = DateTime.parse(endDate, DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD)); + return dateTime.isAfter(startDateTime) && dateTime.isBefore(endDateTime); + } + public static boolean hasValueInList(List values, String checkValue) { for (String value : values) { if (StringUtils.equals(value, checkValue)) { @@ -145,5 +169,83 @@ public class KpiUtil { return map; } + public static List> listDayWeekOfMonth(int year, int month) { + DateTime dateTime = DateTime.parse(String.format("%04d-%02d", year, month), DateTimeFormat.forPattern("yyyy-MM")); + DateTime.Property dayOfMonth = dateTime.dayOfMonth(); + DateTime monthEndDateTime = dayOfMonth.withMaximumValue(); + int monthEndDay = monthEndDateTime.getDayOfMonth(); + List> dayWeeks = new ArrayList<>(); + int weekOfMonth = 1; + List currentWeekDays = new ArrayList<>(); + for (int i = 1; i <= monthEndDay; i++) { + DateTime dayDateTime = dateTime.withDayOfMonth(i); + String day = dayDateTime.toString(DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD)); + DayWeek dayWeek = new DayWeek(day, weekOfMonth, dayDateTime.dayOfWeek().get()); + currentWeekDays.add(dayWeek); + if (dayWeek.getDayOfWeek() == 7 || (i == monthEndDay - 1)) { + dayWeeks.add(currentWeekDays); + weekOfMonth++; + currentWeekDays = new ArrayList<>(); + } + } + return dayWeeks; + } + + public static class DayWeek { + private String date; + private int year; + private int month; + private int day; + private int weekOfMonth; + private int dayOfWeek; + private boolean isHoliday = false; + + public DayWeek(String date, int weekOfMonth, int dayOfWeek) { + this.date = date; + this.weekOfMonth = weekOfMonth; + this.dayOfWeek = dayOfWeek; + String[] dateArray = date.split("-"); + this.year = Integer.parseInt(dateArray[0]); + this.month = Integer.parseInt(dateArray[1]); + this.day = Integer.parseInt(dateArray[2]); + } + + public String getDate() { + return date; + } + + public int getYear() { + return year; + } + + public int getMonth() { + return month; + } + + public int getDay() { + return day; + } + + public int getWeekOfMonth() { + return weekOfMonth; + } + + public int getDayOfWeek() { + return dayOfWeek; + } + + public boolean isHoliday() { + return isHoliday; + } + + public void setHoliday(boolean holiday) { + isHoliday = holiday; + } + + @Override + public String toString() { + return "DayWeek{" + "date='" + date + '\'' + ", year=" + year + ", month=" + month + ", day=" + day + ", weekOfMonth=" + weekOfMonth + ", dayOfWeek=" + dayOfWeek + ", isHoliday=" + isHoliday + '}'; + } + } } diff --git a/src/main/resources/mybatis/db2-mapper/kpi/user-mapper.xml b/src/main/resources/mybatis/db2-mapper/kpi/user-mapper.xml index 83b3b87..2a8c7c9 100644 --- a/src/main/resources/mybatis/db2-mapper/kpi/user-mapper.xml +++ b/src/main/resources/mybatis/db2-mapper/kpi/user-mapper.xml @@ -17,6 +17,13 @@ sys_user su WHERE is_delete = 0 + + AND ( + user_name LIKE CONCAT('%', #{keywords}, '%') + OR + user_username LIKE CONCAT('%', #{keywords}, '%') + ) + AND user_id IN diff --git a/src/main/resources/mybatis/mapper/kpi/kpi-khxz-mapper.xml b/src/main/resources/mybatis/mapper/kpi/kpi-khxz-mapper.xml index deffb36..711ba12 100644 --- a/src/main/resources/mybatis/mapper/kpi/kpi-khxz-mapper.xml +++ b/src/main/resources/mybatis/mapper/kpi/kpi-khxz-mapper.xml @@ -7,10 +7,37 @@ * FROM kpi_khxz_wgy_${wgyLevel} - WHERE - kh_year = #{khYear} + + + area_id = #{areaId} + + AND + community_id = #{communityId} + + + AND ( + B LIKE CONCAT('%', #{keywords}, '%') + OR + user_username LIKE CONCAT('%', #{keywords}, '%') + ) + + + AND + kh_year = #{khYear} + + AND + kh_month = #{khMonth} + + + AND + user_id IN + + #{userIds[${index}]} + + + \ No newline at end of file diff --git a/src/main/resources/mybatis/mapper/kpi/kpi-khxz-wgy-mapper.xml b/src/main/resources/mybatis/mapper/kpi/kpi-khxz-wgy-mapper.xml index cd579c6..6229d47 100644 --- a/src/main/resources/mybatis/mapper/kpi/kpi-khxz-wgy-mapper.xml +++ b/src/main/resources/mybatis/mapper/kpi/kpi-khxz-wgy-mapper.xml @@ -7,6 +7,7 @@ area_id, community_id, user_id, + user_username, kh_year, kh_month, B @@ -14,6 +15,7 @@ #{areaId}, #{communityId}, #{userId}, + #{userUsername}, #{khYear}, #{khMonth}, #{B} @@ -40,6 +42,17 @@ kh_month = #{khMonth} + + UPDATE kpi_khxz_wgy_${wgyLevel} @@ -53,15 +66,23 @@ user_id = #{userId} - + 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 029118d..f7bae1a 100644 --- a/src/main/resources/mybatis/mapper/kpi/kpi-mapper.xml +++ b/src/main/resources/mybatis/mapper/kpi/kpi-mapper.xml @@ -139,6 +139,82 @@ day_date = #{dayDate} + + + DELETE FROM + kpi_n_person + WHERE + day_date = #{dayDate} + + + + INSERT INTO kpi_n_person( + user_id, + day_date, + is_signin, + is_signin_late, + is_signout, + is_signout_early, + is_holiday, + day_score + ) VALUES ( + #{userId}, + #{dayDate}, + #{isSignin}, + #{isSigninLate}, + #{isSignout}, + #{isSignoutEarly}, + #{isHoliday}, + #{dayScore} + ) + + + + + + INSERT INTO kpi_case( @@ -286,35 +362,6 @@ case_id = #{caseId} - - - DELETE FROM - kpi_n_person - WHERE - day_date = #{dayDate} - - - - INSERT INTO kpi_n_person( - user_id, - day_date, - is_signin, - is_signin_late, - is_signout, - is_signout_early, - is_holiday, - day_score - ) VALUES ( - #{userId}, - #{dayDate}, - #{isSignin}, - #{isSigninLate}, - #{isSignout}, - #{isSignoutEarly}, - #{isHoliday}, - #{dayScore} - ) - - - - SELECT - * + case_id, + area_id, + area_name, + community_id, + community_name, + case_type_id, + case_type_name, + gmt_report, + gmt_accept, + gmt_assign, + handle_end_time_long, + handle_end_time, + gmt_handle, + is_timeout, + gmt_inspect, + is_self, + report_user_id, + handle_user_id, + inspect_user_id, + inspect_score, + is_delete, + gmt_delete, + delete_user_id, + total_urge, + total_back, + case_status, + case_source, + is_accept, + is_assign, + is_handle, + is_inspect FROM - kpi_n_person + kpi_case - - AND - user_id = #{userId} - - - AND - day_date = ]]> #{startTime} - - - AND - day_date #{endTime} - - + is_delete = 0 + + AND + report_user_id = #{reportUserId} + + + AND + handle_user_id = #{handleUserId} + + + AND + area_id = #{areaId} + + + AND + community_id = #{communityId} + + + AND + is_accept = #{isAccept} + + + AND + is_handle = #{isHandle} + + + AND + is_inspect = #{isInspect} + + + AND + gmt_report = ]]> #{startTime} + + + AND + gmt_report #{endTime} + + \ No newline at end of file