Browse Source

用户定时任务调整,热心居民去重

master
wangchao 5 years ago
parent
commit
93d4bfbe8d
  1. 23
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/feign/DataStatisticalOpenFeignClient.java
  2. 27
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/feign/impl/DataStatisticalOpenFeignClientFallBack.java
  3. 13
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/StatsTopicService.java
  4. 12
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/StatsUserService.java
  5. 26
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsTopicServiceImpl.java
  6. 26
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsUserServiceImpl.java
  7. 131
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/topic/impl/TopicServiceImpl.java
  8. 212
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/impl/UserServiceImpl.java
  9. 8
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/util/ModuleConstant.java
  10. 6
      epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/data_statistical.sql
  11. 184
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/user/UserDao.xml
  12. 15
      epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/service/StatsTopicService.java
  13. 15
      epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/service/StatsUserService.java
  14. 42
      epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/service/impl/StatsTopicServiceImpl.java
  15. 42
      epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/service/impl/StatsUserServiceImpl.java
  16. 34
      epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/task/StatsTopicTask.java
  17. 34
      epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/task/StatsUserTask.java

23
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/feign/DataStatisticalOpenFeignClient.java

@ -5,6 +5,9 @@ import com.epmet.commons.tools.utils.Result;
import com.epmet.feign.impl.DataStatisticalOpenFeignClientFallBack;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Date;
/**
* desc: 数据统计 对外feign client
@ -128,4 +131,24 @@ public interface DataStatisticalOpenFeignClient {
@PostMapping("/data/stats/statsproject/gridprojectstats")
Result gridProjectStats();
/**
* @Description 执行用户统计
* @param
* @return
* @author wangc
* @date 2020.06.29 09:26
**/
@PostMapping("/data/stats/statsuser/execute")
Result execUserStatistical(@RequestParam(value = "date",required = false) Date date);
/**
* @Description 执行话题统计
* @param
* @return
* @author wangc
* @date 2020.06.29 09:27
**/
@PostMapping("/data/stats/statstopic/execute")
Result execTopicStatistical(@RequestParam(value = "date",required = false) Date date);
}

27
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/feign/impl/DataStatisticalOpenFeignClientFallBack.java

@ -6,6 +6,9 @@ import com.epmet.commons.tools.utils.Result;
import com.epmet.feign.DataStatisticalOpenFeignClient;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* desc:
*
@ -132,4 +135,28 @@ public class DataStatisticalOpenFeignClientFallBack implements DataStatisticalOp
public Result gridProjectStats() {
return ModuleUtils.feignConError(ServiceConstant.DATA_STATISTICAL_SERVER, "gridProjectStats");
}
/**
* @Description 执行用户统计
* @param
* @return
* @author wangc
* @date 2020.06.29 09:26
**/
@Override
public Result execUserStatistical(Date date) {
return ModuleUtils.feignConError(ServiceConstant.DATA_STATISTICAL_SERVER, "execUserStatistical",date);
}
/**
* @Description 执行话题统计
* @param
* @return
* @author wangc
* @date 2020.06.29 09:27
**/
@Override
public Result execTopicStatistical(Date date) {
return ModuleUtils.feignConError(ServiceConstant.DATA_STATISTICAL_SERVER, "execTopicStatistical",date);
}
}

13
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/StatsTopicService.java

@ -2,7 +2,20 @@ package com.epmet.service;
import java.util.Date;
/**
* @Description 话题统计Service接口
* @ClassName StatsTopicService
* @Auth wangc
* @Date 2020-06-23 15:22
*/
public interface StatsTopicService {
/**
* @Description 分区统计按照客户Id划分
* @param date 如果目标日期为空则自动计算为T-1天
* @return
* @author wangc
* @date 2020.06.28 14:38
**/
void partition(Date date);
}

12
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/StatsUserService.java

@ -2,7 +2,19 @@ package com.epmet.service;
import java.util.Date;
/**
* @author wangc
* @dscription
* @date 2020/6/17 16:51
*/
public interface StatsUserService {
/**
* @Description 分区统计按照客户Id划分
* @param date 如果目标日期为空则自动计算为T-1天
* @return
* @author wangc
* @date 2020.06.28 14:38
**/
void partition(Date date);
}

26
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsTopicServiceImpl.java

@ -13,6 +13,7 @@ import com.epmet.service.stats.DimTopicStatusService;
import com.epmet.service.stats.topic.TopicStatisticalService;
import com.epmet.service.topic.TopicService;
import com.epmet.util.DimIdGenerator;
import com.epmet.util.ModuleConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -22,7 +23,7 @@ import org.springframework.util.CollectionUtils;
import java.util.*;
/**
* @Description
* @Description 话题统计Service
* @ClassName StatsTopicServiceImpl
* @Auth wangc
* @Date 2020-06-23 15:22
@ -47,6 +48,13 @@ public class StatsTopicServiceImpl implements StatsTopicService {
@Autowired
private TopicStatisticalService topicStatisticalService;
/**
* @Description 分区统计按照客户Id划分
* @param date 如果目标日期为空则自动计算为T-1天
* @return
* @author wangc
* @date 2020.06.28 14:38
**/
@Override
public void partition(Date date) {
@ -65,14 +73,22 @@ public class StatsTopicServiceImpl implements StatsTopicService {
}
/**
* @Description 生成话题统计数据
* @param customerId - 客户Id
* @parma date - 目标日期
* @return
* @author wangc
* @date 2020.06.28 14:50
**/
void generate(String customerId,Date date){
//1.初始化时间参数
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.DATE, NumConstant.ONE_NEG);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.HOUR_OF_DAY, NumConstant.ZERO);
calendar.set(Calendar.MINUTE, NumConstant.ZERO);
calendar.set(Calendar.SECOND, NumConstant.ZERO);
//2.初始化时间维度
DimIdGenerator.DimIdBean timeDimension = DimIdGenerator.getDimIdBean(null == date ? calendar.getTime() : date);
@ -91,7 +107,7 @@ public class StatsTopicServiceImpl implements StatsTopicService {
//6.生成唯一性统计数据
topicStatisticalService.insertUniquely(data);
}catch(Exception e){
log.error(String.format(ProjectConstant.STATS_FAILED_PREFIX, "topicStats", customerId, new Date().toString(), e.getMessage()));
log.error(String.format(ProjectConstant.STATS_FAILED_PREFIX, ModuleConstant.EXCEPTION_DING_INTERCEPTOR_PREFIX_TOPIC_STATISTICAL, customerId, new Date().toString(), e.getMessage()));
}
}

26
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsUserServiceImpl.java

@ -11,6 +11,7 @@ import com.epmet.service.stats.DimCustomerService;
import com.epmet.service.stats.user.UserStatisticalService;
import com.epmet.service.user.UserService;
import com.epmet.util.DimIdGenerator;
import com.epmet.util.ModuleConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -45,6 +46,13 @@ public class StatsUserServiceImpl implements StatsUserService {
@Autowired
private UserStatisticalService userStatisticalService;
/**
* @Description 分区统计按照客户Id划分
* @param date 如果目标日期为空则自动计算为T-1天
* @return
* @author wangc
* @date 2020.06.28 14:38
**/
@Override
public void partition(Date date) {
int pageNo = NumConstant.ONE;
@ -62,15 +70,23 @@ public class StatsUserServiceImpl implements StatsUserService {
}
/**
* @Description 生成用户统计数据
* @param customerId 客户Id
* @param date 目标日期
* @return
* @author wangc
* @date 2020.06.28 14:40
**/
void generate(String customerId,Date date){
//1.初始化时间参数
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
//获取当日的零点
calendar.add(Calendar.DATE, NumConstant.ONE_NEG);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.HOUR_OF_DAY, NumConstant.ZERO);
calendar.set(Calendar.MINUTE, NumConstant.ZERO);
calendar.set(Calendar.SECOND, NumConstant.ZERO);
//2.初始化时间维度
DimIdGenerator.DimIdBean timeDimension = DimIdGenerator.getDimIdBean(null == date ? calendar.getTime() : date);
@ -84,7 +100,7 @@ public class StatsUserServiceImpl implements StatsUserService {
UserStatisticalData agencyData = userService.traverseAgencyUser(agencies, date, timeDimension);
userStatisticalService.insertUniquely(agencyData);
}catch(Exception e){
log.error(String.format(ProjectConstant.STATS_FAILED_PREFIX, "agencyUserStats", customerId, new Date().toString(), e.getMessage()));
log.error(String.format(ProjectConstant.STATS_FAILED_PREFIX, ModuleConstant.EXCEPTION_DING_INTERCEPTOR_PREFIX_AGENCY_USER_STATISTICAL, customerId, new Date().toString(), e.getMessage()));
}
//5.计算网格统计数据、生成唯一性统计数据
@ -92,7 +108,7 @@ public class StatsUserServiceImpl implements StatsUserService {
UserStatisticalData gridData = userService.traverseGridUser(agencies, date, timeDimension);
userStatisticalService.insertUniquely(gridData);
}catch(Exception e){
log.error(String.format(ProjectConstant.STATS_FAILED_PREFIX, "gridUserStats", customerId, new Date().toString(), e.getMessage()));
log.error(String.format(ProjectConstant.STATS_FAILED_PREFIX, ModuleConstant.EXCEPTION_DING_INTERCEPTOR_PREFIX_GRID_USER_STATISTICAL, customerId, new Date().toString(), e.getMessage()));
}
}
}

131
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/topic/impl/TopicServiceImpl.java

@ -55,7 +55,7 @@ public class TopicServiceImpl implements TopicService {
@Override
public TopicStatisticalData compute(List<AgencySubTreeDto> agencies, Date targetDate, DimIdGenerator.DimIdBean timeDimension, String customerId, List<DimTopicStatusDTO> statusDimension) {
if(null == agencies || agencies.size() == NumConstant.ZERO){
logger.warn("没有相应的机关集合");
logger.warn(ModuleConstant.LOG_WARN_NO_AGENCY_MESSAGE);
return null;
}
@ -74,6 +74,18 @@ public class TopicServiceImpl implements TopicService {
Map<String,List<ResiGroupTopicResultDTO>> gridGroupMap =
topics.stream().collect(Collectors.groupingBy(ResiGroupTopicResultDTO::getGridId));
agencies.forEach(agency -> {
if(null != agency.getGridIds() && agency.getGridIds().size() > NumConstant.ZERO){
agency.getGridIds().forEach(gridId -> {
if(!gridGroupMap.containsKey(gridId)){
gridGroupMap.put(gridId,null);
}
});
}
});
return calculateAndSummarizeTopicStatisticalData(subGridOfAgency,agencies,gridGroupMap,targetDate,statusDimension,timeDimension,customerId);
}
@ -166,19 +178,19 @@ public class TopicServiceImpl implements TopicService {
* @date 2020.06.22 13:45
**/
void analyzeTopic(Map<String, Set<String>> subGridOfAgency, List<AgencySubTreeDto> agencies, Map<String,List<ResiGroupTopicResultDTO>> gridGroupMap, Map<String,List<ResiTopicOperationResultDTO>> topicOperationMap, Date targetDate, TopicStatisticalData dataPacket, List<DimTopicStatusDTO> statusDimension, DimIdGenerator.DimIdBean timeDimension){
Boolean isMonthEnd = false;
//Boolean isMonthEnd = false;
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
//前一天
//前一天零点
calendar.add(Calendar.DATE, NumConstant.ONE_NEG);
calendar.set(Calendar.HOUR_OF_DAY, NumConstant.ZERO);
calendar.set(Calendar.MINUTE, NumConstant.ZERO);
calendar.set(Calendar.SECOND, NumConstant.ZERO);
Date targetDateCheck = null == targetDate ? calendar.getTime() : targetDate;
calendar.setTime(targetDateCheck);
//如果目标日期是当月的最后一天
if(calendar.get(Calendar.DATE) == calendar.getActualMaximum(Calendar.DAY_OF_MONTH)){
//if(calendar.get(Calendar.DATE) == calendar.getActualMaximum(Calendar.DAY_OF_MONTH)){
//求出这个月的第一天
calendar.setTime(new Date());
calendar.set(Calendar.DAY_OF_MONTH, NumConstant.ONE);
@ -186,8 +198,8 @@ public class TopicServiceImpl implements TopicService {
calendar.set(Calendar.MINUTE, NumConstant.ZERO);
calendar.set(Calendar.SECOND, NumConstant.ZERO);
isMonthEnd = true;
}
// isMonthEnd = true;
//}
//计算百分比使用,保留小数点后两位
NumberFormat numberFormat = NumberFormat.getInstance();
@ -231,6 +243,9 @@ public class TopicServiceImpl implements TopicService {
if(null != entry.getValue() && entry.getValue().size() > NumConstant.ZERO){
entry.getValue().forEach(gridId -> {
FactTopicIssueGridDailyDTO issueGridD = new FactTopicIssueGridDailyDTO();
FactTopicStatusGridDailyDTO topicGridD_discussing = new FactTopicStatusGridDailyDTO();
FactTopicStatusGridDailyDTO topicGridD_hidden = new FactTopicStatusGridDailyDTO();
@ -305,6 +320,8 @@ public class TopicServiceImpl implements TopicService {
if(!gridDistinct.get(gridId)) {
setGridDailyDataPacket(dataPacket, issueGridD, totalGirdD, topicGridD_discussing, topicGridD_hidden, topicGridD_closed);
}
gridDistinct.put(gridId,true);
});
//机关-百分比
@ -318,13 +335,13 @@ public class TopicServiceImpl implements TopicService {
if(isMonthEnd){
// if(isMonthEnd){
gridDistinct.forEach((k,v) -> {
gridDistinct.put(k,false);
});
List<ResiGroupTopicResultDTO> topicsBetweenTimeRange = topicDao.selectGroupOrderByGridBetweenTimeRange(calendar.getTime(),targetDate,null);
List<ResiGroupTopicResultDTO> topicsBetweenTimeRange = topicDao.selectGroupOrderByGridBetweenTimeRange(calendar.getTime(),targetDate,dataPacket.getCustomerId());
Map<String,List<ResiGroupTopicResultDTO>> GridGroupMapBetweenTimeRange =
topicsBetweenTimeRange.stream().collect(Collectors.groupingBy(ResiGroupTopicResultDTO::getGridId));
List<ResiGroupTopicResultDTO> groupListBetweenTimeRange = new LinkedList<>();
@ -355,8 +372,9 @@ public class TopicServiceImpl implements TopicService {
if(null != entry.getValue() && entry.getValue().size() > NumConstant.ZERO){
entry.getValue().forEach(gridId -> {
FactTopicIssueGridMonthlyDTO issueGridM = new FactTopicIssueGridMonthlyDTO();
initGridMonthlyDTO(entry.getKey(),agencyMap.get(entry.getKey()).getCustomerId(),gridId,timeDimension,issueGridM);
initGridMonthlyDTO(entry.getKey(),gridId,agencyMap.get(entry.getKey()).getCustomerId(),timeDimension,issueGridM);
List<ResiGroupTopicResultDTO> groups = gridGroupMap.get(gridId);
@ -372,7 +390,7 @@ public class TopicServiceImpl implements TopicService {
issueGridM.setIssueTotal(issueGridM.getIssueTotal() + groupTopicDataBetweenTimeRange.get(group.getGroupId()).getIssueTotal());
GroupTopicData data = groupTopicData.get(group.getGroupId());
GroupTopicData data = groupTopicDataBetweenTimeRange.get(group.getGroupId());
if (null != data) {
@ -392,9 +410,11 @@ public class TopicServiceImpl implements TopicService {
});
}
if(!gridDistinct.get(gridId)) {
setGridMonthlyDataPacket(dataPacket, issueGridM);
}
gridDistinct.put(gridId,true);
});
//机关-百分比
@ -408,7 +428,7 @@ public class TopicServiceImpl implements TopicService {
}
// }
}
@ -431,10 +451,13 @@ public class TopicServiceImpl implements TopicService {
GroupTopicData groupTopicData = new GroupTopicData();
groupTopicData.setGroupId(group.getGroupId());
groupTopicData.setTotal(group.getTopics().size());
if (null == group.getTopics() || group.getTopics().size() == NumConstant.ZERO) {
groupTopicData.setTotal(NumConstant.ZERO);
}else {
groupTopicData.setTotal(group.getTopics().size());
}
//if (null == group.getTopics() || group.getTopics().size() == NumConstant.ZERO) {
groupTopicData.setTopicIncr(NumConstant.ZERO);
groupTopicData.setHiddenTotal(NumConstant.ZERO);
groupTopicData.setHiddenIncr(NumConstant.ZERO);
@ -444,7 +467,7 @@ public class TopicServiceImpl implements TopicService {
groupTopicData.setDiscussingTotal(NumConstant.ZERO);
groupTopicData.setDiscussingIncr(NumConstant.ZERO);
groupTopicData.setIssueTotal(NumConstant.ZERO);
}else{
//}else{
for (ResiTopicResultDTO topic : group.getTopics()) {
if(StringUtils.isBlank(topic.getTopicId())) continue;
@ -458,79 +481,53 @@ public class TopicServiceImpl implements TopicService {
}
Map<String,List<ResiTopicOperationResultDTO>> hiddenGroupByDate = operFlag ? operations.stream().filter(oper -> StringUtils.equals("hidden",oper.getStatus())).collect(Collectors.groupingBy(ResiTopicOperationResultDTO::getCreatedTime)) : null;
Map<String,List<ResiTopicOperationResultDTO>> hiddenCancelledGroupByDate = operFlag ? operations.stream().filter(oper -> StringUtils.equals("hidden_cancelled",oper.getStatus())).collect(Collectors.groupingBy(ResiTopicOperationResultDTO::getCreatedTime)) : null;
//Map<String,List<ResiTopicOperationResultDTO>> hiddenCancelledGroupByDate = operFlag ? operations.stream().filter(oper -> StringUtils.equals("hidden_cancelled",oper.getStatus())).collect(Collectors.groupingBy(ResiTopicOperationResultDTO::getCreatedTime)) : null;
if(operFlag) {
//如果在同一天内被多次屏蔽,只计算一次
hiddenGroupByDate.forEach((k, v) -> {
if (null != v && v.size() > NumConstant.ZERO) {
groupTopicData.setHiddenIncr(groupTopicData.getHiddenIncr() + NumConstant.ONE);
}
});
//转议题,operations会根据daily与monthly维度不同而取值不同,当daily时,operations只有当天的操作日志,当monthly时,operations包含时间区间内的操作日志
if (operations.stream().filter(operation -> StringUtils.equals(operation.getStatus(), "shift_issue")).findAny().isPresent()) {
groupTopicData.setIssueIncr(groupTopicData.getIssueIncr() + NumConstant.ONE);
}
}
if (topic.isShiftIssue()) {
groupTopicData.setIssueTotal(groupTopicData.getIssueTotal() + NumConstant.ONE);
}
//对于话题,每个话题的操作记录中,【关闭】与【转议题】只会出现一次,而【屏蔽】与【取消屏蔽】会出现多次
switch (topic.getStatus()) {
case "hidden":
groupTopicData.setHiddenTotal(groupTopicData.getHiddenTotal() + NumConstant.ONE);
if (operFlag) {
//如果在同一天内被多次屏蔽,只计算一次
hiddenGroupByDate.forEach((k, v) -> {
if (null != v && v.size() > NumConstant.ZERO) {
groupTopicData.setHiddenIncr(groupTopicData.getHiddenIncr() + NumConstant.ONE);
}
});
for (ResiTopicOperationResultDTO operation : operations) {
if (StringUtils.equals(operation.getStatus(), "shift_issue"))
groupTopicData.setIssueIncr(groupTopicData.getIssueIncr() + NumConstant.ONE);
}
}
break;
case "closed":
groupTopicData.setClosedTotal(groupTopicData.getClosedTotal() + NumConstant.ONE);
if (operFlag) {
for (ResiTopicOperationResultDTO operation : operations) {
if (StringUtils.equals(operation.getStatus(), "closed"))
groupTopicData.setClosedIncr(groupTopicData.getClosedIncr() + NumConstant.ONE);
if (StringUtils.equals(operation.getStatus(), "shift_issue"))
groupTopicData.setIssueIncr(groupTopicData.getIssueIncr() + NumConstant.ONE);
if (operations.stream().filter(operation -> StringUtils.equals(operation.getStatus(), "closed")).findAny().isPresent()) {
groupTopicData.setClosedIncr(groupTopicData.getClosedIncr() + NumConstant.ONE);
}
}
break;
case "discussing":
groupTopicData.setDiscussingTotal(groupTopicData.getDiscussingTotal() + NumConstant.ONE);
Set<String> dateRelease = new HashSet<>();
if(operFlag) {
if (null != hiddenGroupByDate && hiddenGroupByDate.size() > NumConstant.ZERO){
hiddenGroupByDate.forEach((k, v) -> {
if (null != v && v.size() > NumConstant.ZERO) {
if (null != hiddenCancelledGroupByDate.get(k) && hiddenCancelledGroupByDate.get(k).size() > NumConstant.ZERO) {
if (hiddenCancelledGroupByDate.get(k).size() == v.size()) {
groupTopicData.setDiscussingIncr(groupTopicData.getDiscussingIncr() + NumConstant.ONE);
dateRelease.add(k);
return; //相当于continue,循环下一个日期
} else {
//话题操作日志与话题状态不符
}
}
}
});
}
if (operations.stream().filter(operation -> StringUtils.equals(operation.getStatus(), "discussing") && !dateRelease.contains(operation.getCreatedTime())).findAny().isPresent()) {
//创建话题,operations会根据daily与monthly维度不同而取值不同,当daily时,operations只有当天的操作日志,当monthly时,operations包含时间区间内的操作日志
if (operations.stream().filter(operation -> StringUtils.equals(operation.getStatus(), "discussing")).findAny().isPresent()) {
groupTopicData.setDiscussingIncr(groupTopicData.getDiscussingIncr() + NumConstant.ONE);
}
if (operations.stream().filter(operation -> StringUtils.equals(operation.getStatus(), "shift_issue")).findAny().isPresent()) {
groupTopicData.setIssueIncr(groupTopicData.getIssueIncr() + NumConstant.ONE);
}
}
break;
}
if (topic.isShiftIssue()) {
groupTopicData.setIssueTotal(groupTopicData.getIssueTotal() + NumConstant.ONE);
}
}
}
// }
groupTopicStatistical.put(group.getGroupId(), groupTopicData);
}

212
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/impl/UserServiceImpl.java

@ -48,7 +48,7 @@ public class UserServiceImpl implements UserService {
@Override
public UserStatisticalData traverseAgencyUser(List<AgencySubTreeDto> agencies, Date targetDate, DimIdGenerator.DimIdBean timeDimension) {
if(null == agencies || agencies.size() == NumConstant.ZERO){
logger.warn("没有相应的机关集合");
logger.warn(ModuleConstant.LOG_WARN_NO_AGENCY_MESSAGE);
return null;
}
@ -90,7 +90,7 @@ public class UserServiceImpl implements UserService {
@Override
public UserStatisticalData traverseGridUser(List<AgencySubTreeDto> agencies, Date targetDate, DimIdGenerator.DimIdBean timeDimension) {
if(null == agencies || agencies.size() == NumConstant.ZERO){
logger.warn("没有相应的机关集合");
logger.warn(ModuleConstant.LOG_WARN_NO_AGENCY_MESSAGE);
return null;
}
@ -184,15 +184,15 @@ public class UserServiceImpl implements UserService {
NumberFormat numberFormat = NumberFormat.getInstance();
numberFormat.setMaximumFractionDigits(NumConstant.SIX);
Boolean isMonthEnd = false;
Boolean isMonthBeginning = true;
Calendar calendar =Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.DATE, NumConstant.ONE_NEG);
Date targetDateCheck = null == targetDate ? calendar.getTime() : targetDate;
calendar.setTime(targetDateCheck);
//如果目标日期是当月的最后一天
if(calendar.get(Calendar.DATE) == calendar.getActualMaximum(Calendar.DAY_OF_MONTH)){
//如果目标日期不是是当月的第一天
if(calendar.get(Calendar.DATE) != calendar.getActualMinimum(Calendar.DAY_OF_MONTH)){
//求出这个月的第一天
calendar.setTime(new Date());
calendar.set(Calendar.DAY_OF_MONTH, NumConstant.ONE);
@ -200,7 +200,7 @@ public class UserServiceImpl implements UserService {
calendar.set(Calendar.MINUTE, NumConstant.ZERO);
calendar.set(Calendar.SECOND, NumConstant.ZERO);
isMonthEnd = true;
isMonthBeginning = false;
}
if(StringUtils.equals(ModuleConstant.DIM_SUB_AGENCY,relation)){
@ -297,10 +297,68 @@ public class UserServiceImpl implements UserService {
}
//月末处理
if(isMonthEnd){
FactRegUserAgencyMonthlyDTO regAgencyM = new FactRegUserAgencyMonthlyDTO();
regAgencyM.setCustomerId(customerId);
regAgencyM.setAgencyId(agencyId);
regAgencyM.setMonthId(timeDimension.getMonthId());
regAgencyM.setQuarterId(timeDimension.getQuarterId());
regAgencyM.setYearId(timeDimension.getYearId());
regAgencyM.setRegTotal(regData.getTotal());
regAgencyM.setResiTotal(regData.getTotal());
regAgencyM.setWarmHeartedTotal(warmRegData.getTotal());
regAgencyM.setPartymemberTotal(partyRegData.getTotal());
regAgencyM.setRegIncr(regData.getIncr());
regAgencyM.setWarmIncr(warmRegData.getIncr());
regAgencyM.setPartymemberIncr(partiData.getIncr());
regAgencyM.setResiProportion(new BigDecimal(NumConstant.ONE));
regAgencyM.setPartymemberProportion(regAgencyD.getPartymemberProportion());
regAgencyM.setWarmHeartedProportion(regAgencyD.getWarmHeartedProportion());
regAgencyM.setCreatedBy(ModuleConstant.CREATED_BY_STATISTICAL_ROBOT);
FactParticipationUserAgencyMonthlyDTO partiAgencyM = new FactParticipationUserAgencyMonthlyDTO();
partiAgencyM.setCustomerId(customerId);
partiAgencyM.setAgencyId(agencyId);
partiAgencyM.setMonthId(timeDimension.getMonthId());
partiAgencyM.setQuarterId(timeDimension.getQuarterId());
partiAgencyM.setYearId(timeDimension.getYearId());
partiAgencyM.setRegTotal(partiData.getTotal());
partiAgencyM.setResiTotal(partiData.getTotal());
partiAgencyM.setWarmHeartedTotal(warmPartiData.getTotal());
partiAgencyM.setPartymemberTotal(partyPartiData.getTotal());
partiAgencyM.setRegIncr(partiData.getIncr());
partiAgencyM.setWarmIncr(warmPartiData.getIncr());
partiAgencyM.setPartymemberIncr(partyPartiData.getIncr());
partiAgencyM.setResiProportion(new BigDecimal(NumConstant.ONE));
partiAgencyM.setPartymemberProportion(partiAgencyD.getPartymemberProportion());
partiAgencyM.setWarmHeartedProportion(partiAgencyD.getWarmHeartedProportion());
partiAgencyM.setCreatedBy(ModuleConstant.CREATED_BY_STATISTICAL_ROBOT);
//如果是月初第一天,不再做日期区间查询
if(isMonthBeginning) {
if (null == dataPacket.getRegAgencyMonthlyList()) {
List<FactRegUserAgencyMonthlyDTO> list = new LinkedList<>();
list.add(regAgencyM);
dataPacket.setRegAgencyMonthlyList(list);
} else {
dataPacket.getRegAgencyMonthlyList().add(regAgencyM);
}
if (null == dataPacket.getPartiAgencyMonthlyList()) {
List<FactParticipationUserAgencyMonthlyDTO> list = new LinkedList<>();
list.add(partiAgencyM);
dataPacket.setPartiAgencyMonthlyList(list);
} else {
dataPacket.getPartiAgencyMonthlyList().add(partiAgencyM);
}
}else{
//如果不是月初第一天
//本月注册用户增长数
Integer regIncrMonthly = userDao.selectResiIncrWithinTimeRange(ModuleConstant.REG_OR_PARTI_FLAG_REG,gridIds,calendar.getTime(),targetDateCheck);
//本月新增注册用户Id集合
@ -321,23 +379,10 @@ public class UserServiceImpl implements UserService {
Integer incrWarmOfPartiMonthly = userDao.selectWarmIncrWithinTimeRange(incrPartiIdsMonthly,gridIds,calendar.getTime(),targetDateCheck);
FactRegUserAgencyMonthlyDTO regAgencyM = new FactRegUserAgencyMonthlyDTO();
regAgencyM.setCustomerId(customerId);
regAgencyM.setAgencyId(agencyId);
regAgencyM.setMonthId(timeDimension.getMonthId());
regAgencyM.setQuarterId(timeDimension.getQuarterId());
regAgencyM.setYearId(timeDimension.getYearId());
regAgencyM.setRegTotal(regData.getTotal());
regAgencyM.setResiTotal(regData.getTotal());
regAgencyM.setWarmHeartedTotal(warmRegData.getTotal());
regAgencyM.setPartymemberTotal(partyRegData.getTotal());
regAgencyM.setRegIncr(regIncrMonthly);
regAgencyM.setWarmIncr(incrWarmOfRegMonthly);
regAgencyM.setPartymemberIncr(incrPartyOfRegMonthly);
regAgencyM.setResiProportion(new BigDecimal(NumConstant.ONE));
regAgencyM.setPartymemberProportion(regAgencyD.getPartymemberProportion());
regAgencyM.setWarmHeartedProportion(regAgencyD.getWarmHeartedProportion());
regAgencyM.setCreatedBy(ModuleConstant.CREATED_BY_STATISTICAL_ROBOT);
if(null == dataPacket.getRegAgencyMonthlyList()){
List<FactRegUserAgencyMonthlyDTO> list = new LinkedList<>();
list.add(regAgencyM);
@ -347,23 +392,10 @@ public class UserServiceImpl implements UserService {
}
FactParticipationUserAgencyMonthlyDTO partiAgencyM = new FactParticipationUserAgencyMonthlyDTO();
partiAgencyM.setCustomerId(customerId);
partiAgencyM.setAgencyId(agencyId);
partiAgencyM.setMonthId(timeDimension.getMonthId());
partiAgencyM.setQuarterId(timeDimension.getQuarterId());
partiAgencyM.setYearId(timeDimension.getYearId());
partiAgencyM.setRegTotal(partiData.getTotal());
partiAgencyM.setResiTotal(partiData.getTotal());
partiAgencyM.setWarmHeartedTotal(warmPartiData.getTotal());
partiAgencyM.setPartymemberTotal(partyPartiData.getTotal());
partiAgencyM.setRegIncr(partiIncrMonthly);
partiAgencyM.setWarmIncr(incrWarmOfPartiMonthly);
partiAgencyM.setPartymemberIncr(incrPartyOfPartiMonthly);
partiAgencyM.setResiProportion(new BigDecimal(NumConstant.ONE));
partiAgencyM.setPartymemberProportion(partiAgencyD.getPartymemberProportion());
partiAgencyM.setWarmHeartedProportion(partiAgencyD.getWarmHeartedProportion());
partiAgencyM.setCreatedBy(ModuleConstant.CREATED_BY_STATISTICAL_ROBOT);
if(null == dataPacket.getPartiAgencyMonthlyList()){
List<FactParticipationUserAgencyMonthlyDTO> list = new LinkedList<>();
list.add(partiAgencyM);
@ -381,7 +413,7 @@ public class UserServiceImpl implements UserService {
Set<String> singleGridIdSet = new HashSet<>();
final boolean monthEndFlag = isMonthEnd;
final boolean monthBeginningFlag = isMonthBeginning;
//grid
gridIds.forEach(gridId -> {
@ -486,7 +518,68 @@ public class UserServiceImpl implements UserService {
if(monthEndFlag){
FactRegUserGridMonthlyDTO regGridM = new FactRegUserGridMonthlyDTO();
regGridM.setCustomerId(customerId);
regGridM.setAgencyId(agencyId);
regGridM.setGridId(gridId);
regGridM.setMonthId(timeDimension.getMonthId());
regGridM.setQuarterId(timeDimension.getQuarterId());
regGridM.setYearId(timeDimension.getYearId());
regGridM.setRegTotal(regData.getTotal());
regGridM.setResiTotal(regData.getTotal());
regGridM.setWarmHeartedTotal(warmRegData.getTotal());
regGridM.setPartymemberTotal(partyRegData.getTotal());
regGridM.setRegIncr(regData.getIncr());
regGridM.setWarmIncr(warmRegData.getIncr());
regGridM.setPartymemberIncr(partyRegData.getIncr());
regGridM.setResiProportion(new BigDecimal(NumConstant.ONE));
regGridM.setPartymemberProportion(regGridD.getPartymemberProportion());
regGridM.setWarmHeartedProportion(regGridD.getWarmHeartedProportion());
regGridM.setCreatedBy(ModuleConstant.CREATED_BY_STATISTICAL_ROBOT);
FactParticipationUserGridMonthlyDTO partiGridM = new FactParticipationUserGridMonthlyDTO();
partiGridM.setCustomerId(customerId);
partiGridM.setAgencyId(agencyId);
partiGridM.setGridId(gridId);
partiGridM.setMonthId(timeDimension.getMonthId());
partiGridM.setQuarterId(timeDimension.getQuarterId());
partiGridM.setYearId(timeDimension.getYearId());
partiGridM.setRegTotal(partiData.getTotal());
partiGridM.setResiTotal(partiData.getTotal());
partiGridM.setWarmHeartedTotal(warmPartiData.getTotal());
partiGridM.setPartymemberTotal(partyPartiData.getTotal());
partiGridM.setRegIncr(partiData.getIncr());
partiGridM.setWarmIncr(warmPartiData.getIncr());
partiGridM.setPartymemberIncr(partyPartiData.getIncr());
partiGridM.setResiProportion(new BigDecimal(NumConstant.ONE));
partiGridM.setPartymemberProportion(partiGridD.getPartymemberProportion());
partiGridM.setWarmHeartedProportion(partiGridD.getWarmHeartedProportion());
partiGridM.setCreatedBy(ModuleConstant.CREATED_BY_STATISTICAL_ROBOT);
//如果是月初第一天,不再做日期区间查询
if(monthBeginningFlag){
if(null != dataPacket.getRegGridMonthlyList()){
dataPacket.getRegGridMonthlyList().add(regGridM);
}else{
List<FactRegUserGridMonthlyDTO> list = new ArrayList<>();
list.add(regGridM);
dataPacket.setRegGridMonthlyList(list);
}
if(null != dataPacket.getPartiGridMonthlyList()){
dataPacket.getPartiGridMonthlyList().add(partiGridM);
}else{
List<FactParticipationUserGridMonthlyDTO> list = new ArrayList<>();
list.add(partiGridM);
dataPacket.setPartiGridMonthlyList(list);
}
}else{
//本月注册用户增长数
Integer regIncrMonthly = userDao.selectResiIncrWithinTimeRange(ModuleConstant.REG_OR_PARTI_FLAG_REG,singleGridIdSet,calendar.getTime(),targetDateCheck);
//本月新增注册用户Id集合
@ -506,24 +599,11 @@ public class UserServiceImpl implements UserService {
//本月新增热心居民数(参与用户)
Integer incrWarmOfPartiMonthly = userDao.selectWarmIncrWithinTimeRange(incrPartiIdsMonthly,singleGridIdSet,calendar.getTime(),targetDateCheck);
FactRegUserGridMonthlyDTO regGridM = new FactRegUserGridMonthlyDTO();
regGridM.setCustomerId(customerId);
regGridM.setAgencyId(agencyId);
regGridM.setGridId(gridId);
regGridM.setMonthId(timeDimension.getMonthId());
regGridM.setQuarterId(timeDimension.getQuarterId());
regGridM.setYearId(timeDimension.getYearId());
regGridM.setRegTotal(regData.getTotal());
regGridM.setResiTotal(regData.getTotal());
regGridM.setWarmHeartedTotal(warmRegData.getTotal());
regGridM.setPartymemberTotal(partyRegData.getTotal());
regGridM.setRegIncr(regIncrMonthly);
regGridM.setWarmIncr(incrWarmOfRegMonthly);
regGridM.setPartymemberIncr(incrPartyOfRegMonthly);
regGridM.setResiProportion(new BigDecimal(NumConstant.ONE));
regGridM.setPartymemberProportion(regGridD.getPartymemberProportion());
regGridM.setWarmHeartedProportion(regGridD.getWarmHeartedProportion());
regGridM.setCreatedBy(ModuleConstant.CREATED_BY_STATISTICAL_ROBOT);
if(null != dataPacket.getRegGridMonthlyList()){
dataPacket.getRegGridMonthlyList().add(regGridM);
}else{
@ -532,24 +612,11 @@ public class UserServiceImpl implements UserService {
dataPacket.setRegGridMonthlyList(list);
}
FactParticipationUserGridMonthlyDTO partiGridM = new FactParticipationUserGridMonthlyDTO();
partiGridM.setCustomerId(customerId);
partiGridM.setAgencyId(agencyId);
partiGridM.setGridId(gridId);
partiGridM.setMonthId(timeDimension.getMonthId());
partiGridM.setQuarterId(timeDimension.getQuarterId());
partiGridM.setYearId(timeDimension.getYearId());
partiGridM.setRegTotal(partiData.getTotal());
partiGridM.setResiTotal(partiData.getTotal());
partiGridM.setWarmHeartedTotal(warmPartiData.getTotal());
partiGridM.setPartymemberTotal(partyPartiData.getTotal());
partiGridM.setRegIncr(partiIncrMonthly);
partiGridM.setWarmIncr(incrWarmOfPartiMonthly);
partiGridM.setPartymemberIncr(incrPartyOfPartiMonthly);
partiGridM.setResiProportion(new BigDecimal(NumConstant.ONE));
partiGridM.setPartymemberProportion(partiGridD.getPartymemberProportion());
partiGridM.setWarmHeartedProportion(partiGridD.getWarmHeartedProportion());
partiGridM.setCreatedBy(ModuleConstant.CREATED_BY_STATISTICAL_ROBOT);
if(null != dataPacket.getPartiGridMonthlyList()){
dataPacket.getPartiGridMonthlyList().add(partiGridM);
}else{
@ -568,7 +635,6 @@ public class UserServiceImpl implements UserService {
}
}
@ -592,12 +658,4 @@ public class UserServiceImpl implements UserService {
System.out.println(format.format(calendar.getTime()));
System.out.println(format2.format(calendar.getTime()));
}
/**
* @Description 先查出所有的用户单位时间内新增的注册居民党员热心居民(跟随网格)然后查出单位时间内每一个网格下的参与用户Id集合和注册用户Id集合
* @param
* @return
* @author wangc
* @date 2020.06.23 00:32
**/
}

8
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/util/ModuleConstant.java

@ -31,4 +31,12 @@ public interface ModuleConstant {
* 统计机器人
* */
String CREATED_BY_STATISTICAL_ROBOT = "STATISTICAL_ROBOT";
String EXCEPTION_DING_INTERCEPTOR_PREFIX_AGENCY_USER_STATISTICAL = "agencyUserStats";
String EXCEPTION_DING_INTERCEPTOR_PREFIX_GRID_USER_STATISTICAL = "gridUserStats";
String EXCEPTION_DING_INTERCEPTOR_PREFIX_TOPIC_STATISTICAL = "topicStats";
String LOG_WARN_NO_AGENCY_MESSAGE = "没有相应的机关集合";
}

6
epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/data_statistical.sql

@ -697,7 +697,7 @@ CREATE TABLE `fact_topic_status_agency_daily` (
`YEAR_ID` varchar(32) NOT NULL COMMENT '年ID',
`TOPIC_STATUS_ID` varchar(32) NOT NULL COMMENT '话题状态ID 关联dim_topic_status表\n讨论中 discussing\n已屏蔽 hidden\n已关闭 closed\n已转项目 shift_project',
`TOPIC_COUNT` int(11) NOT NULL DEFAULT '0' COMMENT '话题数量 指定状态的话题数量',
`TOPIC_PROPORTION` decimal(4,2) NOT NULL COMMENT '话题状态百分比 指定状态话题数/话题总数\n总数在topic_total_agency_daily中',
`TOPIC_PROPORTION` decimal(11,6) NOT NULL COMMENT '话题状态百分比 指定状态话题数/话题总数\n总数在topic_total_agency_daily中',
`TOPIC_INCREMENT` int(11) NOT NULL DEFAULT '0' COMMENT '话题增量 单位时间内的状态话题的增加数',
`DEL_FLAG` char(1) NOT NULL DEFAULT '0' COMMENT '删除标识',
`REVISION` int(11) NOT NULL DEFAULT '0' COMMENT '乐观锁',
@ -727,7 +727,7 @@ CREATE TABLE `fact_topic_status_agency_monthly` (
`YEAR_ID` varchar(32) NOT NULL COMMENT '年ID 关联年度dm表',
`TOPIC_STATUS_ID` varchar(32) NOT NULL COMMENT '话题状态 讨论中 discussing\n已屏蔽 hidden\n已关闭 closed\n已转项目 shift_project',
`TOPIC_COUNT` int(11) NOT NULL DEFAULT '0' COMMENT '话题数量',
`TOPIC_PROPORTION` decimal(4,2) NOT NULL COMMENT '话题状态占比 月末一天 \n指定状态话题数/话题总数\n总数在topic_total_agency_daily中',
`TOPIC_PROPORTION` decimal(11,6) NOT NULL COMMENT '话题状态占比 月末一天 \n指定状态话题数/话题总数\n总数在topic_total_agency_daily中',
`TOPIC_INCR` int(11) NOT NULL DEFAULT '0' COMMENT '话题增量 单位时间内的话题状态增加数',
`DEL_FLAG` char(1) NOT NULL DEFAULT '0' COMMENT '删除标识',
`REVISION` int(11) NOT NULL DEFAULT '0' COMMENT '乐观锁',
@ -758,7 +758,7 @@ CREATE TABLE `fact_topic_status_grid_daily` (
`YEAR_ID` varchar(32) NOT NULL COMMENT '年ID',
`TOPIC_STATUS_ID` varchar(32) DEFAULT NULL COMMENT '话题状态ID 讨论中 discussing\n已屏蔽 hidden\n已关闭 closed\n已转项目 shift_project',
`TOPIC_COUNT` int(11) DEFAULT '0' COMMENT '话题数量',
`TOPIC_PROPORTION` decimal(4,2) DEFAULT NULL COMMENT '话题状态占比 指定状态话题数/话题总数\n总数在topic_total_grid_daily中',
`TOPIC_PROPORTION` decimal(11,6) DEFAULT NULL COMMENT '话题状态占比 指定状态话题数/话题总数\n总数在topic_total_grid_daily中',
`TOPIC_INCREMENT` int(11) DEFAULT '0' COMMENT '话题增量',
`DEL_FLAG` varchar(32) NOT NULL DEFAULT '0' COMMENT '删除标识',
`REVISION` int(11) NOT NULL DEFAULT '0' COMMENT '乐观锁',

184
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/user/UserDao.xml

@ -6,17 +6,17 @@
<!-- 查询注册用户的总量与增量 传参:注册用户or参与用户 | 网格Id集合 | 时间参数 格式[yyyy-MM-dd 00:00:00] -->
<select id="selectResiTotalAndIncrByLevel" resultType="com.epmet.dto.user.result.CommonTotalAndIncCountResultDTO">
SELECT
count( * ) AS total,
count( DISTINCT USER_ID ) AS total,
(
SELECT
count( * )
count( DISTINCT USER_ID )
FROM
REGISTER_RELATION
WHERE
DEL_FLAG = '0'
<choose>
<!-- 参与用户 -->
<when test='regOrPatiFlag = "parti"'>
<when test='regOrPartiFlag == "parti"'>
AND PARTICIPATION = '1'
</when>
<!-- 默认查注册用户 -->
@ -25,9 +25,16 @@
</otherwise>
</choose>
<foreach collection="gridIds" item="gridId" index="index" open="AND ( " separator=" OR " close=")">
GRID_ID = #{gridId}
</foreach>
<choose>
<when test='null == gridIds or gridIds.size == 0'>
AND GRID_ID = ''
</when>
<otherwise>
<foreach collection="gridIds" item="gridId" index="index" open="AND ( " separator=" OR " close=")">
GRID_ID = #{gridId}
</foreach>
</otherwise>
</choose>
<choose>
<when test='null != targetDate'>
@ -44,7 +51,7 @@
DEL_FLAG = '0'
<choose>
<!-- 参与用户 -->
<when test='regOrPatiFlag = "parti"'>
<when test='regOrPartiFlag == "parti"'>
AND PARTICIPATION = '1'
</when>
<!-- 默认查注册用户 -->
@ -52,9 +59,16 @@
AND REGISTER = '1'
</otherwise>
</choose>
<foreach collection="gridIds" item="gridId" index="index" open="AND ( " separator=" OR " close=")">
GRID_ID = #{gridId}
</foreach>
<choose>
<when test='null == gridIds or gridIds.size == 0'>
AND GRID_ID = ''
</when>
<otherwise>
<foreach collection="gridIds" item="gridId" index="index" open="AND ( " separator=" OR " close=")">
GRID_ID = #{gridId}
</foreach>
</otherwise>
</choose>
<choose>
<when test="null != targetDate">
AND CREATED_TIME <![CDATA[<]]> DATE_SUB( #{targetDate}, INTERVAL - 1 DAY )
@ -76,7 +90,7 @@
DEL_FLAG = '0'
<choose>
<!-- 参与用户 -->
<when test='regOrPatiFlag = "parti"'>
<when test='regOrPartiFlag == "parti"'>
AND PARTICIPATION = '1'
</when>
<!-- 默认查注册用户 -->
@ -84,9 +98,17 @@
AND REGISTER = '1'
</otherwise>
</choose>
<foreach collection="gridIds" item="gridId" index="index" open="AND ( " separator=" OR " close=")">
GRID_ID = #{gridId}
</foreach>
<choose>
<when test='null == gridIds or gridIds.size == 0'>
AND GRID_ID = ''
</when>
<otherwise>
<foreach collection="gridIds" item="gridId" index="index" open="AND ( " separator=" OR " close=")">
GRID_ID = #{gridId}
</foreach>
</otherwise>
</choose>
<choose>
<when test='null != targetDate'>
@ -108,7 +130,7 @@
DEL_FLAG = '0'
<choose>
<!-- 参与用户 -->
<when test='regOrPatiFlag = "parti"'>
<when test='regOrPartiFlag == "parti"'>
AND PARTICIPATION = '1'
</when>
<!-- 默认查注册用户 -->
@ -116,9 +138,17 @@
AND REGISTER = '1'
</otherwise>
</choose>
<foreach collection="gridIds" item="gridId" index="index" open="AND ( " separator=" OR " close=")">
GRID_ID = #{gridId}
</foreach>
<choose>
<when test='null == gridIds or gridIds.size == 0'>
AND GRID_ID = ''
</when>
<otherwise>
<foreach collection="gridIds" item="gridId" index="index" open="AND ( " separator=" OR " close=")">
GRID_ID = #{gridId}
</foreach>
</otherwise>
</choose>
<choose>
<when test='targetDate != null'>
@ -133,10 +163,10 @@
<!-- 查询党员的总量与增量 传参:用户Id集合(不用传注册or参与标识,用户Id会根据不同的flag范围不同) | 时间参数 格式[yyyy-MM-dd 00:00:00]-->
<select id="selectPartyTotalAndIncr" resultType="com.epmet.dto.user.result.CommonTotalAndIncCountResultDTO">
SELECT
count( 1 ) AS total,
count( DISTINCT urole.USER_ID ) AS total,
(
SELECT
count( 1 )
count( DISTINCT urole.USER_ID)
FROM
USER_ROLE urole
LEFT JOIN EPMET_ROLE erole ON urole.ROLE_ID = erole.ID
@ -163,9 +193,20 @@
AND erole.DEL_FLAG = '0'
WHERE
urole.DEL_FLAG = '0'
<foreach collection="userIds" item="userId" index="index" open="AND ( " separator=" OR " close=")">
urole.USER_ID = #{userId}
</foreach>
<choose>
<when test='null == userIds or userIds.size == 0'>
AND urole.USER_ID = ''
</when>
<otherwise>
<foreach collection="userIds" item="userId" index="index" open="AND ( " separator=" OR " close=")">
urole.USER_ID = #{userId}
</foreach>
</otherwise>
</choose>
<choose>
<when test='null != targetDate'>
AND urole.CREATED_TIME <![CDATA[<]]> DATE_SUB( #{targetDate}, INTERVAL - 1 DAY )
@ -180,10 +221,10 @@
<!-- 查询热心居民的总量与增量 传参:用户Id集合(不用传注册or参与标识,用户Id会根据不同的flag范围不同) | 网格Id集合(与用户Id集合同理) | 时间参数 格式[yyyy-MM-dd 00:00:00] -->
<select id="selectWarmTotalAndIncr" resultType="com.epmet.dto.user.result.CommonTotalAndIncCountResultDTO">
SELECT
count( 1 ) AS total,
count( DISTINCT urole.USER_ID ) AS total,
(
SELECT
count( 1 )
count( DISTINCT urole.USER_ID )
FROM
USER_ROLE urole
LEFT JOIN EPMET_ROLE erole ON urole.ROLE_ID = erole.ID
@ -193,9 +234,18 @@
<foreach collection="incrUserIds" item="incrUserId" index="index" open="AND ( " separator=" OR " close=")">
urole.USER_ID = #{incrUserId}
</foreach>
<foreach collection="gridIds" item="gridId" index="index" open="AND ( " separator=" OR " close=")">
urole.GRID_ID = #{gridId}
</foreach>
<choose>
<when test='null == gridIds or gridIds.size == 0'>
AND urole.GRID_ID = ''
</when>
<otherwise>
<foreach collection="gridIds" item="gridId" index="index" open="AND ( " separator=" OR " close=")">
urole.GRID_ID = #{gridId}
</foreach>
</otherwise>
</choose>
<choose>
<when test='null != targetDate'>
@ -213,9 +263,16 @@
AND erole.DEL_FLAG = '0'
WHERE
urole.DEL_FLAG = '0'
<foreach collection="gridIds" item="gridId" index="index" open="AND ( " separator=" OR " close=")">
urole.GRID_ID = #{gridId}
</foreach>
<choose>
<when test='null == gridIds or gridIds.size == 0'>
AND urole.GRID_ID = ''
</when>
<otherwise>
<foreach collection="gridIds" item="gridId" index="index" open="AND ( " separator=" OR " close=")">
urole.GRID_ID = #{gridId}
</foreach>
</otherwise>
</choose>
<foreach collection="userIds" item="userId" index="index" open="AND ( " separator=" OR " close=")">
urole.USER_ID = #{userId}
</foreach>
@ -241,7 +298,7 @@
DEL_FLAG = '0'
<choose>
<!-- 参与用户 -->
<when test='regOrPatiFlag = "parti"'>
<when test='regOrPartiFlag == "parti"'>
AND PARTICIPATION = '1'
</when>
<!-- 默认查注册用户 -->
@ -249,9 +306,17 @@
AND REGISTER = '1'
</otherwise>
</choose>
<foreach collection="gridIds" item="gridId" index="index" open="AND ( " separator=" OR " close=")">
GRID_ID = #{gridId}
</foreach>
<choose>
<when test='null == gridIds or gridIds.size == 0'>
AND GRID_ID = ''
</when>
<otherwise>
<foreach collection="gridIds" item="gridId" index="index" open="AND ( " separator=" OR " close=")">
GRID_ID = #{gridId}
</foreach>
</otherwise>
</choose>
AND CREATED_TIME <![CDATA[>=]]> #{startDate} AND CREATED_TIME <![CDATA[<]]> DATE_SUB( #{endDate}, INTERVAL - 1 DAY)
</select>
@ -259,14 +324,14 @@
<!-- 查询指定时间范围内居民增量 传参:注册用户or参与用户 | 网格Id集合 | 时间区间-->
<select id="selectResiIncrWithinTimeRange" resultType="integer">
SELECT
count( * )
count( distinct USER_ID)
FROM
REGISTER_RELATION
WHERE
DEL_FLAG = '0'
<choose>
<!-- 参与用户 -->
<when test='regOrPatiFlag = "parti"'>
<when test='regOrPartiFlag == "parti"'>
AND PARTICIPATION = '1'
</when>
<!-- 默认查注册用户 -->
@ -275,9 +340,16 @@
</otherwise>
</choose>
<foreach collection="gridIds" item="gridId" index="index" open="AND ( " separator=" OR " close=")">
GRID_ID = #{gridId}
</foreach>
<choose>
<when test='null == gridIds or gridIds.size == 0'>
AND GRID_ID = ''
</when>
<otherwise>
<foreach collection="gridIds" item="gridId" index="index" open="AND ( " separator=" OR " close=")">
GRID_ID = #{gridId}
</foreach>
</otherwise>
</choose>
AND CREATED_TIME <![CDATA[>=]]> #{startDate} AND CREATED_TIME <![CDATA[<]]> DATE_SUB( #{endDate}, INTERVAL - 1 DAY)
@ -287,16 +359,24 @@
<!-- 查询指定时间范围内党员的增量 传参:用户Id集合 | 时间区间 -->
<select id="selectPartyIncrWithinTimeRange" resultType="integer">
SELECT
count( 1 )
count( DISTINCT urole.USER_ID)
FROM
USER_ROLE urole
LEFT JOIN EPMET_ROLE erole ON urole.ROLE_ID = erole.ID
AND erole.DEL_FLAG = '0'
WHERE
urole.DEL_FLAG = '0'
<foreach collection="incrUserIds" item="incrUserId" index="index" open="AND ( " separator=" OR " close=")">
urole.USER_ID = #{incrUserId}
</foreach>
<choose>
<when test='null == incrUserIds or incrUserIds.size == 0'>
AND urole.USER_ID = ''
</when>
<otherwise>
<foreach collection="incrUserIds" item="incrUserId" index="index" open="AND ( " separator=" OR " close=")">
urole.USER_ID = #{incrUserId}
</foreach>
</otherwise>
</choose>
AND urole.CREATED_TIME <![CDATA[>=]]> #{startDate} AND urole.CREATED_TIME <![CDATA[<]]> DATE_SUB( #{endDate}, INTERVAL - 1 DAY)
AND erole.ROLE_NAME = '党员'
@ -305,7 +385,7 @@
<!-- 查询指定时间范围内热心居民的增量 传参:用户Id集合 | 网格Id集合 | 时间区间 -->
<select id="selectWarmIncrWithinTimeRange" resultType="integer">
SELECT
count( 1 )
count( DISTINCT urole.USER_ID)
FROM
USER_ROLE urole
LEFT JOIN EPMET_ROLE erole ON urole.ROLE_ID = erole.ID
@ -315,10 +395,16 @@
<foreach collection="incrUserIds" item="incrUserId" index="index" open="AND ( " separator=" OR " close=")">
urole.USER_ID = #{incrUserId}
</foreach>
<foreach collection="gridIds" item="gridId" index="index" open="AND ( " separator=" OR " close=")">
urole.GRID_ID = #{gridId}
</foreach>
<choose>
<when test='null == gridIds or gridIds.size == 0'>
AND GRID_ID = ''
</when>
<otherwise>
<foreach collection="gridIds" item="gridId" index="index" open="AND ( " separator=" OR " close=")">
GRID_ID = #{gridId}
</foreach>
</otherwise>
</choose>
AND urole.CREATED_TIME <![CDATA[>=]]> #{startDate} AND urole.CREATED_TIME <![CDATA[<]]> DATE_SUB( #{endDate}, INTERVAL - 1 DAY)
AND erole.ROLE_NAME = '热心居民'
</select>

15
epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/service/StatsTopicService.java

@ -0,0 +1,15 @@
package com.epmet.service;
import com.epmet.commons.tools.utils.Result;
public interface StatsTopicService {
/**
* @Description 调用统计服务执行统计 - 话题
* @param
* @return
* @author wangc
* @date 2020.06.29 09:40
**/
Result execTopicStatistical(String date);
}

15
epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/service/StatsUserService.java

@ -0,0 +1,15 @@
package com.epmet.service;
import com.epmet.commons.tools.utils.Result;
public interface StatsUserService {
/**
* @Description 调用统计服务-用户
* @param
* @return
* @author wangc
* @date 2020.06.29 09:39
**/
Result execUserStatistical(String date);
}

42
epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/service/impl/StatsTopicServiceImpl.java

@ -0,0 +1,42 @@
package com.epmet.service.impl;
import com.epmet.commons.tools.utils.Result;
import com.epmet.feign.DataStatisticalOpenFeignClient;
import com.epmet.service.StatsTopicService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @Description
* @ClassName StatsTopicServiceImpl
* @Auth wangc
* @Date 2020-06-29 09:47
*/
@Service
public class StatsTopicServiceImpl implements StatsTopicService {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private DataStatisticalOpenFeignClient dataStatisticalOpenFeignClient;
@Override
public Result execTopicStatistical(String date) {
Date dateParam = null;
if(StringUtils.isNotBlank(date)){
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
dateParam = format.parse(date);
}catch (Exception e){
logger.error(String.format("执行话题统计时,日期格式转换异常,param:%s,e:%s"),date,e.getMessage());
}
}
return dataStatisticalOpenFeignClient.execTopicStatistical(dateParam);
}
}

42
epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/service/impl/StatsUserServiceImpl.java

@ -0,0 +1,42 @@
package com.epmet.service.impl;
import com.epmet.commons.tools.utils.Result;
import com.epmet.feign.DataStatisticalOpenFeignClient;
import com.epmet.service.StatsUserService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @Description
* @ClassName StatsUserServiceImpl
* @Auth wangc
* @Date 2020-06-29 09:41
*/
@Service
public class StatsUserServiceImpl implements StatsUserService {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private DataStatisticalOpenFeignClient dataStatisticalOpenFeignClient;
@Override
public Result execUserStatistical(String date) {
Date dateParam = null;
if(StringUtils.isNotBlank(date)){
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
dateParam = format.parse(date);
}catch (Exception e){
logger.error(String.format("执行用户统计时,日期格式转换异常,param:%s,e:%s"),date,e.getMessage());
}
}
return dataStatisticalOpenFeignClient.execUserStatistical(dateParam);
}
}

34
epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/task/StatsTopicTask.java

@ -0,0 +1,34 @@
package com.epmet.task;
import com.epmet.commons.tools.utils.Result;
import com.epmet.service.StatsTopicService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @Description
* @ClassName StatsTopicTask
* @Auth wangc
* @Date 2020-06-29 09:49
*/
@Component("statsTopicTask")
public class StatsTopicTask implements ITask {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private StatsTopicService statsTopicService;
@Override
public void run(String params) {
logger.debug("StatsTopicTask定时任务正在执行,参数为:{}", params);
Result result = statsTopicService.execTopicStatistical(params);
if (result.success()){
logger.debug("StatsTopicTask定时任务正在执行定时任务执行成功");
}else {
logger.debug("StatsTopicTask定时任务正在执行定时任务执行失败:" + result.getMsg());
}
}
}

34
epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/task/StatsUserTask.java

@ -0,0 +1,34 @@
package com.epmet.task;
import com.epmet.commons.tools.utils.Result;
import com.epmet.service.StatsUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @Description
* @ClassName StatsUserTask
* @Auth wangc
* @Date 2020-06-29 09:49
*/
@Component("statsUserTask")
public class StatsUserTask implements ITask {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private StatsUserService statsUserService;
@Override
public void run(String params) {
logger.debug("StatsUserTask定时任务正在执行,参数为:{}", params);
Result result = statsUserService.execUserStatistical(params);
if (result.success()){
logger.debug("StatsUserTask定时任务正在执行定时任务执行成功");
}else {
logger.debug("StatsUserTask定时任务正在执行定时任务执行失败:" + result.getMsg());
}
}
}
Loading…
Cancel
Save