|
|
@@ -11,10 +11,12 @@ import com.fs.company.service.IStatisticManageService;
|
|
|
import java.util.function.Function;
|
|
|
import com.fs.statis.dto.ComprehensiveStatisticsDTO;
|
|
|
import com.fs.statis.param.ComprehensiveStatisticsParam;
|
|
|
+import com.fs.utils.MyDateUtils;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
@@ -28,6 +30,7 @@ import java.util.stream.Collectors;
|
|
|
* @author: Guos
|
|
|
* @time: 2025/10/30 上午9:21
|
|
|
*/
|
|
|
+@Lazy
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class StatisticManageServiceImpl implements IStatisticManageService {
|
|
|
@@ -44,7 +47,7 @@ public class StatisticManageServiceImpl implements IStatisticManageService {
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public Object statisticMain(ComprehensiveStatisticsParam param) {
|
|
|
+ public List<ComprehensiveStatisticsDTO> statisticMain(ComprehensiveStatisticsParam param) {
|
|
|
if(param.getDimension() == DimensionEnum.COMPANY.getValue()){
|
|
|
return getStatisticNumByCompany(param);
|
|
|
}
|
|
|
@@ -62,10 +65,10 @@ public class StatisticManageServiceImpl implements IStatisticManageService {
|
|
|
/**
|
|
|
* 按照公司维度统计数据
|
|
|
*/
|
|
|
- public List getStatisticNumByCompany(ComprehensiveStatisticsParam param) {
|
|
|
+ public List<ComprehensiveStatisticsDTO> getStatisticNumByCompany(ComprehensiveStatisticsParam param) {
|
|
|
List<CompanyDeptUserInfo> companyInfo = statisticManageMapper.getCompanyInfo();
|
|
|
List result = Lists.newArrayList();
|
|
|
- List<Date> dates = generateDateList(param.getStartTime(), param.getEndTime());
|
|
|
+ List<Date> dates = MyDateUtils.generateDateList(param.getStartTime(), param.getEndTime());
|
|
|
for (Date date : dates){
|
|
|
param.setStartTime(date);
|
|
|
param.setEndTime(date);
|
|
|
@@ -97,143 +100,116 @@ public class StatisticManageServiceImpl implements IStatisticManageService {
|
|
|
/**
|
|
|
* 根据部门id获取个人统计数据
|
|
|
*/
|
|
|
- public List getStatisticNumByDeptId(ComprehensiveStatisticsParam param){
|
|
|
+ public List<ComprehensiveStatisticsDTO> getStatisticNumByDeptId(ComprehensiveStatisticsParam param){
|
|
|
//先获取部门下的用户的信息
|
|
|
Long id = param.getId();
|
|
|
List<CompanyDeptUserInfo> searchUserInfo = statisticManageMapper.getSearchUserInfo(id);
|
|
|
List result = Lists.newArrayList();
|
|
|
- List<Date> dates = generateDateList(param.getStartTime(), param.getEndTime());
|
|
|
- for (Date date : dates) {
|
|
|
- param.setStartTime(date);
|
|
|
- param.setEndTime(date);
|
|
|
- for (CompanyDeptUserInfo companyDeptUserInfo : searchUserInfo) {
|
|
|
- Long parentId = companyDeptUserInfo.getParentId();
|
|
|
- Long deptId = companyDeptUserInfo.getDeptId();
|
|
|
- if (parentId != BigDecimal.ZERO.longValue()) {
|
|
|
- Optional<CompanyDeptUserInfo> first = searchUserInfo.stream().filter(dept -> dept.getDeptId().equals(parentId)).findFirst();
|
|
|
- if (first.isPresent()){
|
|
|
- CompanyDeptUserInfo findParentDept = first.get();
|
|
|
- String parentDeptName = findParentDept.getDeptName();
|
|
|
- String deptName = companyDeptUserInfo.getDeptName();
|
|
|
- companyDeptUserInfo.setDeptName(parentDeptName + "/" + deptName);
|
|
|
- }
|
|
|
- }
|
|
|
- String companyName = companyDeptUserInfo.getCompanyName();
|
|
|
- Long companyId = companyDeptUserInfo.getCompanyId();
|
|
|
- param.setUserId(companyDeptUserInfo.getUserId());
|
|
|
- ComprehensiveStatisticsDTO statisticDataByDeptId =
|
|
|
- statisticManageMapper.getStatisticDataByDeptId(param);
|
|
|
- if(ObjectUtils.isEmpty(statisticDataByDeptId)){
|
|
|
- statisticDataByDeptId = new ComprehensiveStatisticsDTO();
|
|
|
- statisticDataByDeptId.setAnswerNum(BigDecimal.ZERO.intValue());
|
|
|
- statisticDataByDeptId.setRedPacketNum(BigDecimal.ZERO.intValue());
|
|
|
- statisticDataByDeptId.setSendCount(BigDecimal.ZERO.intValue());
|
|
|
- statisticDataByDeptId.setRedPacketAmount(BigDecimal.ZERO);
|
|
|
- statisticDataByDeptId.setCompleteNum(BigDecimal.ZERO.intValue());
|
|
|
- }
|
|
|
- statisticDataByDeptId.setCompanyUserName(companyDeptUserInfo.getNickName());
|
|
|
- statisticDataByDeptId.setCompanyUserId(companyDeptUserInfo.getUserId());
|
|
|
- statisticDataByDeptId.setDeptName(companyDeptUserInfo.getDeptName());
|
|
|
- statisticDataByDeptId.setDeptId(deptId.intValue());
|
|
|
- statisticDataByDeptId.setCompanyName(companyName);
|
|
|
- statisticDataByDeptId.setCompanyId(companyId);
|
|
|
- statisticDataByDeptId.setStatisticsTime(date);
|
|
|
- result.add(statisticDataByDeptId);
|
|
|
+
|
|
|
+ if(param.getTimeGroupFlag()){
|
|
|
+ List<Date> dates = MyDateUtils.generateDateList(param.getStartTime(), param.getEndTime());
|
|
|
+ for (Date date : dates) {
|
|
|
+ param.setStartTime(date);
|
|
|
+ param.setEndTime(date);
|
|
|
+ personalDimension(param, date, searchUserInfo, result);
|
|
|
}
|
|
|
+ }else{
|
|
|
+ personalDimension(param, null, searchUserInfo, result);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 根据公司获取统部门的计数据
|
|
|
- */
|
|
|
- public List getStatisticNumByCompanyId(ComprehensiveStatisticsParam param){
|
|
|
- //先从公司拿到公司和部门的信息
|
|
|
- List<CompanyDeptUserInfo> searchDeptInfo = statisticManageMapper.getSearchDeptInfo(param.getId());;
|
|
|
- List result = Lists.newArrayList();
|
|
|
- List<Date> dates = generateDateList(param.getStartTime(), param.getEndTime());
|
|
|
- for (Date date : dates){
|
|
|
- param.setStartTime(date);
|
|
|
- param.setEndTime(date);
|
|
|
- for (CompanyDeptUserInfo companyDeptUserInfo : searchDeptInfo) {
|
|
|
- //判断当前部门的父级id不是0就组装名称
|
|
|
- Long parentId = companyDeptUserInfo.getParentId();
|
|
|
- if(parentId != BigDecimal.ZERO.longValue()){
|
|
|
- String parentDeptName = searchDeptInfo.stream().filter(dept -> dept.getDeptId().equals(parentId)).findFirst().get().getDeptName();
|
|
|
+ private void personalDimension(ComprehensiveStatisticsParam param, Date date, List<CompanyDeptUserInfo> searchUserInfo, List result) {
|
|
|
+ for (CompanyDeptUserInfo companyDeptUserInfo : searchUserInfo) {
|
|
|
+ Long parentId = companyDeptUserInfo.getParentId();
|
|
|
+ Long deptId = companyDeptUserInfo.getDeptId();
|
|
|
+ if (parentId != BigDecimal.ZERO.longValue()) {
|
|
|
+ Optional<CompanyDeptUserInfo> first = searchUserInfo.stream().filter(dept -> dept.getDeptId().equals(parentId)).findFirst();
|
|
|
+ if (first.isPresent()){
|
|
|
+ CompanyDeptUserInfo findParentDept = first.get();
|
|
|
+ String parentDeptName = findParentDept.getDeptName();
|
|
|
String deptName = companyDeptUserInfo.getDeptName();
|
|
|
companyDeptUserInfo.setDeptName(parentDeptName + "/" + deptName);
|
|
|
}
|
|
|
- String companyName = companyDeptUserInfo.getCompanyName();
|
|
|
- Long deptId = companyDeptUserInfo.getDeptId();
|
|
|
- Long companyId = companyDeptUserInfo.getCompanyId();
|
|
|
- param.setDeptId(deptId);
|
|
|
- ComprehensiveStatisticsDTO statisticDataByDeptId =
|
|
|
- statisticManageMapper.getStatisticDataByDeptId(param);
|
|
|
- if(ObjectUtils.isEmpty(statisticDataByDeptId)){
|
|
|
- statisticDataByDeptId = new ComprehensiveStatisticsDTO();
|
|
|
- statisticDataByDeptId.setAnswerNum(BigDecimal.ZERO.intValue());
|
|
|
- statisticDataByDeptId.setRedPacketNum(BigDecimal.ZERO.intValue());
|
|
|
- statisticDataByDeptId.setSendCount(BigDecimal.ZERO.intValue());
|
|
|
- statisticDataByDeptId.setRedPacketAmount(BigDecimal.ZERO);
|
|
|
- statisticDataByDeptId.setCompleteNum(BigDecimal.ZERO.intValue());
|
|
|
- }
|
|
|
- statisticDataByDeptId.setDeptName(companyDeptUserInfo.getDeptName());
|
|
|
- statisticDataByDeptId.setDeptId(deptId.intValue());
|
|
|
- statisticDataByDeptId.setCompanyName(companyName);
|
|
|
- statisticDataByDeptId.setCompanyId(companyId);
|
|
|
+ }
|
|
|
+ String companyName = companyDeptUserInfo.getCompanyName();
|
|
|
+ Long companyId = companyDeptUserInfo.getCompanyId();
|
|
|
+ param.setUserId(companyDeptUserInfo.getUserId());
|
|
|
+ ComprehensiveStatisticsDTO statisticDataByDeptId =
|
|
|
+ statisticManageMapper.getStatisticDataByDeptId(param);
|
|
|
+ if(ObjectUtils.isEmpty(statisticDataByDeptId)){
|
|
|
+ statisticDataByDeptId = new ComprehensiveStatisticsDTO();
|
|
|
+ statisticDataByDeptId.setAnswerNum(BigDecimal.ZERO.intValue());
|
|
|
+ statisticDataByDeptId.setRedPacketNum(BigDecimal.ZERO.intValue());
|
|
|
+ statisticDataByDeptId.setSendCount(BigDecimal.ZERO.intValue());
|
|
|
+ statisticDataByDeptId.setRedPacketAmount(BigDecimal.ZERO);
|
|
|
+ statisticDataByDeptId.setCompleteNum(BigDecimal.ZERO.intValue());
|
|
|
+ }
|
|
|
+ statisticDataByDeptId.setCompanyUserName(companyDeptUserInfo.getNickName());
|
|
|
+ statisticDataByDeptId.setCompanyUserId(companyDeptUserInfo.getUserId());
|
|
|
+ statisticDataByDeptId.setDeptName(companyDeptUserInfo.getDeptName());
|
|
|
+ statisticDataByDeptId.setDeptId(deptId.intValue());
|
|
|
+ statisticDataByDeptId.setCompanyName(companyName);
|
|
|
+ statisticDataByDeptId.setCompanyId(companyId);
|
|
|
+ if(date != null){
|
|
|
statisticDataByDeptId.setStatisticsTime(date);
|
|
|
- result.add(statisticDataByDeptId);
|
|
|
}
|
|
|
+ result.add(statisticDataByDeptId);
|
|
|
}
|
|
|
- return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 生成开始时间到结束时间之间的每日时间数组
|
|
|
- * @param startTime 开始时间
|
|
|
- * @param endTime 结束时间
|
|
|
- * @return 时间数组列表
|
|
|
+ * 根据公司获取统部门的计数据
|
|
|
*/
|
|
|
- public List<Date> generateDateList(Date startTime, Date endTime) {
|
|
|
- List<Date> dateList = new ArrayList<>();
|
|
|
- if (startTime == null || endTime == null) {
|
|
|
- return dateList;
|
|
|
- }
|
|
|
-
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(startTime);
|
|
|
-
|
|
|
- // 设置时间为当天00:00:00,确保按天计算
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
- calendar.set(Calendar.MINUTE, 0);
|
|
|
- calendar.set(Calendar.SECOND, 0);
|
|
|
- calendar.set(Calendar.MILLISECOND, 0);
|
|
|
-
|
|
|
- Date currentDate = calendar.getTime();
|
|
|
- Date finalEndTime = getStartOfDay(endTime);
|
|
|
-
|
|
|
- while (!currentDate.after(finalEndTime)) {
|
|
|
- dateList.add(currentDate);
|
|
|
- calendar.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
- currentDate = calendar.getTime();
|
|
|
+ public List<ComprehensiveStatisticsDTO> getStatisticNumByCompanyId(ComprehensiveStatisticsParam param){
|
|
|
+ //先从公司拿到公司和部门的信息
|
|
|
+ List<CompanyDeptUserInfo> searchDeptInfo = statisticManageMapper.getSearchDeptInfo(param.getId());;
|
|
|
+ List result = Lists.newArrayList();
|
|
|
+ if(param.getTimeGroupFlag()){
|
|
|
+ List<Date> dates = MyDateUtils.generateDateList(param.getStartTime(), param.getEndTime());
|
|
|
+ for (Date date : dates){
|
|
|
+ param.setStartTime(date);
|
|
|
+ param.setEndTime(date);
|
|
|
+ deptDimension(param, date, searchDeptInfo, result);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ deptDimension(param, null, searchDeptInfo, result);
|
|
|
}
|
|
|
-
|
|
|
- return dateList;
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获取指定日期的开始时间(00:00:00)
|
|
|
- * @param date 指定日期
|
|
|
- * @return 当天开始时间
|
|
|
- */
|
|
|
- private Date getStartOfDay(Date date) {
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(date);
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
- calendar.set(Calendar.MINUTE, 0);
|
|
|
- calendar.set(Calendar.SECOND, 0);
|
|
|
- calendar.set(Calendar.MILLISECOND, 0);
|
|
|
- return calendar.getTime();
|
|
|
+ private void deptDimension(ComprehensiveStatisticsParam param, Date date, List<CompanyDeptUserInfo> searchDeptInfo, List result) {
|
|
|
+ for (CompanyDeptUserInfo companyDeptUserInfo : searchDeptInfo) {
|
|
|
+ //判断当前部门的父级id不是0就组装名称
|
|
|
+ Long parentId = companyDeptUserInfo.getParentId();
|
|
|
+ if(parentId != BigDecimal.ZERO.longValue()){
|
|
|
+ String parentDeptName = searchDeptInfo.stream().filter(dept -> dept.getDeptId().equals(parentId)).findFirst().get().getDeptName();
|
|
|
+ String deptName = companyDeptUserInfo.getDeptName();
|
|
|
+ companyDeptUserInfo.setDeptName(parentDeptName + "/" + deptName);
|
|
|
+ }
|
|
|
+ String companyName = companyDeptUserInfo.getCompanyName();
|
|
|
+ Long deptId = companyDeptUserInfo.getDeptId();
|
|
|
+ Long companyId = companyDeptUserInfo.getCompanyId();
|
|
|
+ param.setDeptId(deptId);
|
|
|
+ ComprehensiveStatisticsDTO statisticDataByDeptId =
|
|
|
+ statisticManageMapper.getStatisticDataByDeptId(param);
|
|
|
+ if(ObjectUtils.isEmpty(statisticDataByDeptId)){
|
|
|
+ statisticDataByDeptId = new ComprehensiveStatisticsDTO();
|
|
|
+ statisticDataByDeptId.setAnswerNum(BigDecimal.ZERO.intValue());
|
|
|
+ statisticDataByDeptId.setRedPacketNum(BigDecimal.ZERO.intValue());
|
|
|
+ statisticDataByDeptId.setSendCount(BigDecimal.ZERO.intValue());
|
|
|
+ statisticDataByDeptId.setRedPacketAmount(BigDecimal.ZERO);
|
|
|
+ statisticDataByDeptId.setCompleteNum(BigDecimal.ZERO.intValue());
|
|
|
+ }
|
|
|
+ statisticDataByDeptId.setDeptName(companyDeptUserInfo.getDeptName());
|
|
|
+ statisticDataByDeptId.setDeptId(deptId.intValue());
|
|
|
+ statisticDataByDeptId.setCompanyName(companyName);
|
|
|
+ statisticDataByDeptId.setCompanyId(companyId);
|
|
|
+ if(date != null){
|
|
|
+ statisticDataByDeptId.setStatisticsTime(date);
|
|
|
+ }
|
|
|
+ result.add(statisticDataByDeptId);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -436,73 +412,6 @@ public class StatisticManageServiceImpl implements IStatisticManageService {
|
|
|
return build;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-// /**
|
|
|
-// * 执行定时任务
|
|
|
-// * 还需要考虑在统计部门数据时,部门下面没有用户,某个时候这个部门下面又加入新的用户了,这个时候就会出现数据偏差
|
|
|
-// */
|
|
|
-// @Override
|
|
|
-// public void executeTask() {
|
|
|
-// StopWatch stopWatch = new StopWatch();
|
|
|
-// stopWatch.start("gs-执行数据统计任务");
|
|
|
-// List<CompanyDeptUserInfo> companyDeptdUserList = statisticManageMapper.getCompanyAndDeptAndDeptUserList(null);
|
|
|
-// log.info("统计人数列表:{}", companyDeptdUserList.size());
|
|
|
-// companyDeptdUserList.forEach(companyDeptUserInfo -> {
|
|
|
-// CompanyDeptUserInfoDTO statisticNum = new CompanyDeptUserInfoDTO();
|
|
|
-// boolean empty = null == companyDeptUserInfo.getUserId(); //用户id为空返回true
|
|
|
-// if(!empty){
|
|
|
-// statisticNum = statisticManageMapper.getStatisticNum(companyDeptUserInfo.getUserId());
|
|
|
-// }
|
|
|
-// ComprehensiveDailyStats comprehensiveDailyStats = component(companyDeptUserInfo, statisticNum);
|
|
|
-// ComprehensiveDailyStats selectResult = null;
|
|
|
-// if(!empty){
|
|
|
-// //用户id不为空,我们就用用户id去查询这个日期是否有数据
|
|
|
-// selectResult = statisticManageMapper.selectByUserAndDate(comprehensiveDailyStats.getUserId(), comprehensiveDailyStats.getStatisticsTime());
|
|
|
-// }else{
|
|
|
-// //如果用户id为空,说明部门下面没有人(没人情况下,部门id只会在当天的日期中存在一条),先按照部门去查询后删除(或者直接按照id更新就可以了)
|
|
|
-// selectResult = statisticManageMapper.selectByDeptAndDate(companyDeptUserInfo.getDeptId(), comprehensiveDailyStats.getStatisticsTime());
|
|
|
-// }
|
|
|
-// if(!ObjectUtils.isEmpty(selectResult)){
|
|
|
-// comprehensiveDailyStats.setId(selectResult.getId());
|
|
|
-// statisticManageMapper.updateById(comprehensiveDailyStats);
|
|
|
-// }else{
|
|
|
-// statisticManageMapper.insert(comprehensiveDailyStats);
|
|
|
-// }
|
|
|
-// });
|
|
|
-// stopWatch.stop();
|
|
|
-// log.info("gs-执行数据统计任务完成,耗时:{}", stopWatch.getTotalTimeSeconds());
|
|
|
-// }
|
|
|
-//
|
|
|
-// private ComprehensiveDailyStats component(CompanyDeptUserInfo source, CompanyDeptUserInfoDTO statisticNum){
|
|
|
-// ComprehensiveDailyStats target = new ComprehensiveDailyStats();
|
|
|
-// target.setCompanyId(source.getCompanyId());
|
|
|
-// target.setCompanyName(source.getCompanyName());
|
|
|
-// target.setDeptId(source.getDeptId());
|
|
|
-// target.setDeptName(source.getDeptName());
|
|
|
-// target.setStatisticsTime(new Date());
|
|
|
-// target.setCreateTime(new Date());
|
|
|
-// target.setUpdateTime(new Date());
|
|
|
-// if(null != source.getUserId()){
|
|
|
-// target.setUserId(source.getUserId());
|
|
|
-// target.setUserName(source.getUserName());
|
|
|
-// target.setNickName(source.getNickName());
|
|
|
-// target.setAnswerNum(statisticNum.getAnswerNum());
|
|
|
-// target.setCompleteNum(statisticNum.getCompleteNum());
|
|
|
-// target.setLineNum(statisticNum.getLineNum());
|
|
|
-// target.setActiveNum(statisticNum.getActiveNum());
|
|
|
-// target.setRedPacketNum(statisticNum.getRedPacketNum());
|
|
|
-// target.setRedPacketAmount(new BigDecimal(0.00));
|
|
|
-// }else{
|
|
|
-// target.setAnswerNum(0);
|
|
|
-// target.setCompleteNum(0);
|
|
|
-// target.setLineNum(0);
|
|
|
-// target.setActiveNum(0);
|
|
|
-// target.setRedPacketNum(0);
|
|
|
-// target.setRedPacketAmount(new BigDecimal(0.00));
|
|
|
-// }
|
|
|
-// return target;
|
|
|
-// }
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|