|
|
@@ -8,6 +8,7 @@ import com.fs.company.domain.CourseWatchLogStatistics;
|
|
|
import com.fs.company.mapper.CourseWatchLogStatisticsMapper;
|
|
|
import com.fs.company.mapper.StatisticManageMapper;
|
|
|
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.google.common.collect.Lists;
|
|
|
@@ -45,38 +46,33 @@ public class StatisticManageServiceImpl implements IStatisticManageService {
|
|
|
@Override
|
|
|
public Object statisticMain(ComprehensiveStatisticsParam param) {
|
|
|
if(param.getDimension() == DimensionEnum.COMPANY.getValue()){
|
|
|
- Assert.notNull(param.getId(), "按公司展示查询条件不能为空!");
|
|
|
- return getStatisticNumByCompanyId(param);
|
|
|
+ return getStatisticNumByCompany(param);
|
|
|
}
|
|
|
if(param.getDimension() == DimensionEnum.DEPARTMENT.getValue()){
|
|
|
Assert.notNull(param.getId(), "按部门展示查询条件不能为空!");
|
|
|
- return getStatisticNumByDeptId(param);
|
|
|
+ return getStatisticNumByCompanyId(param);
|
|
|
}
|
|
|
if (param.getDimension() == DimensionEnum.PERSONAL.getValue()){
|
|
|
Assert.notNull(param.getId(), "按个人展示查询条件不能为空!");
|
|
|
- return getStatisticNumByPersonal(param);
|
|
|
+ return getStatisticNumByDeptId(param);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取个人统计数据
|
|
|
+ * 按照公司维度统计数据
|
|
|
*/
|
|
|
- public List getStatisticNumByDeptId(ComprehensiveStatisticsParam param){
|
|
|
- //先获取部门下的用户的信息
|
|
|
- Long id = param.getId();
|
|
|
- List<CompanyDeptUserInfo> searchUserInfo = statisticManageMapper.getSearchUserInfo(id);
|
|
|
+ public List getStatisticNumByCompany(ComprehensiveStatisticsParam param) {
|
|
|
+ List<CompanyDeptUserInfo> companyInfo = statisticManageMapper.getCompanyInfo();
|
|
|
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) {
|
|
|
- String deptName = companyDeptUserInfo.getDeptName();
|
|
|
+ for (CompanyDeptUserInfo companyDeptUserInfo : companyInfo) {
|
|
|
String companyName = companyDeptUserInfo.getCompanyName();
|
|
|
- Long deptId = companyDeptUserInfo.getDeptId();
|
|
|
Long companyId = companyDeptUserInfo.getCompanyId();
|
|
|
- param.setUserId(companyDeptUserInfo.getUserId());
|
|
|
+ param.setCompanyId(companyId);
|
|
|
ComprehensiveStatisticsDTO statisticDataByDeptId =
|
|
|
statisticManageMapper.getStatisticDataByDeptId(param);
|
|
|
if(ObjectUtils.isEmpty(statisticDataByDeptId)){
|
|
|
@@ -85,11 +81,10 @@ public class StatisticManageServiceImpl implements IStatisticManageService {
|
|
|
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(deptName);
|
|
|
- statisticDataByDeptId.setDeptId(deptId.intValue());
|
|
|
statisticDataByDeptId.setCompanyName(companyName);
|
|
|
statisticDataByDeptId.setCompanyId(companyId);
|
|
|
statisticDataByDeptId.setStatisticsTime(date);
|
|
|
@@ -100,54 +95,74 @@ public class StatisticManageServiceImpl implements IStatisticManageService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取个人统计数据
|
|
|
+ * 根据部门id获取个人统计数据
|
|
|
*/
|
|
|
- public List getStatisticNumByPersonal(ComprehensiveStatisticsParam param){
|
|
|
- //先获取用户的信息
|
|
|
+ public List getStatisticNumByDeptId(ComprehensiveStatisticsParam param){
|
|
|
+ //先获取部门下的用户的信息
|
|
|
Long id = param.getId();
|
|
|
- CompanyDeptUserInfo userInfoByUserId = statisticManageMapper.getUserInfoByUserId(id);
|
|
|
+ List<CompanyDeptUserInfo> searchUserInfo = statisticManageMapper.getSearchUserInfo(id);
|
|
|
List result = Lists.newArrayList();
|
|
|
List<Date> dates = generateDateList(param.getStartTime(), param.getEndTime());
|
|
|
- for (Date date : dates){
|
|
|
+ for (Date date : dates) {
|
|
|
param.setStartTime(date);
|
|
|
param.setEndTime(date);
|
|
|
- param.setDeptId(userInfoByUserId.getDeptId());
|
|
|
- param.setUserId(id);
|
|
|
- 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);
|
|
|
+ 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);
|
|
|
}
|
|
|
- statisticDataByDeptId.setDeptName(userInfoByUserId.getDeptName());
|
|
|
- statisticDataByDeptId.setCompanyUserName(userInfoByUserId.getNickName());
|
|
|
- statisticDataByDeptId.setCompanyUserId(userInfoByUserId.getUserId());
|
|
|
- statisticDataByDeptId.setDeptName(userInfoByUserId.getDeptName());
|
|
|
- statisticDataByDeptId.setDeptId(userInfoByUserId.getDeptId().intValue());
|
|
|
- statisticDataByDeptId.setCompanyName(userInfoByUserId.getCompanyName());
|
|
|
- statisticDataByDeptId.setCompanyId(userInfoByUserId.getCompanyId());
|
|
|
- statisticDataByDeptId.setStatisticsTime(date);
|
|
|
- result.add(statisticDataByDeptId);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 根据公司获取统计数据
|
|
|
+ * 根据公司获取统部门的计数据
|
|
|
*/
|
|
|
public List getStatisticNumByCompanyId(ComprehensiveStatisticsParam param){
|
|
|
//先从公司拿到公司和部门的信息
|
|
|
- List<CompanyDeptUserInfo> searchDeptInfo = getSearchDeptInfo(param.getId());
|
|
|
+ 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) {
|
|
|
- String deptName = companyDeptUserInfo.getDeptName();
|
|
|
+ //判断当前部门的父级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();
|
|
|
@@ -160,8 +175,9 @@ public class StatisticManageServiceImpl implements IStatisticManageService {
|
|
|
statisticDataByDeptId.setRedPacketNum(BigDecimal.ZERO.intValue());
|
|
|
statisticDataByDeptId.setSendCount(BigDecimal.ZERO.intValue());
|
|
|
statisticDataByDeptId.setRedPacketAmount(BigDecimal.ZERO);
|
|
|
+ statisticDataByDeptId.setCompleteNum(BigDecimal.ZERO.intValue());
|
|
|
}
|
|
|
- statisticDataByDeptId.setDeptName(deptName);
|
|
|
+ statisticDataByDeptId.setDeptName(companyDeptUserInfo.getDeptName());
|
|
|
statisticDataByDeptId.setDeptId(deptId.intValue());
|
|
|
statisticDataByDeptId.setCompanyName(companyName);
|
|
|
statisticDataByDeptId.setCompanyId(companyId);
|
|
|
@@ -229,12 +245,51 @@ public class StatisticManageServiceImpl implements IStatisticManageService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 根据公司id获取部门下拉搜索信息
|
|
|
- * @param id
|
|
|
+ * 根据公司id获取部门下拉搜索信息(递归获取完整部门树)
|
|
|
+ * @param id 公司ID
|
|
|
*/
|
|
|
@Override
|
|
|
public List<CompanyDeptUserInfo> getSearchDeptInfo(Long id){
|
|
|
- return statisticManageMapper.getSearchDeptInfo(id);
|
|
|
+ List<CompanyDeptUserInfo> allDepts = statisticManageMapper.getSearchDeptInfo(id);
|
|
|
+ if(CollectionUtils.isEmpty(allDepts)){
|
|
|
+ return allDepts;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建ID到部门的映射,方便查找
|
|
|
+ Map<Long, CompanyDeptUserInfo> deptMap = allDepts.stream()
|
|
|
+ .collect(Collectors.toMap(CompanyDeptUserInfo::getDeptId, Function.identity()));
|
|
|
+
|
|
|
+ // 找到所有根部门(父级ID为0或null的部门)
|
|
|
+ List<CompanyDeptUserInfo> rootDepts = allDepts.stream()
|
|
|
+ .filter(dept -> dept.getParentId() == null ||
|
|
|
+ dept.getParentId().equals(BigDecimal.ZERO.longValue()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 递归构建部门树
|
|
|
+ buildDeptTree(rootDepts, deptMap);
|
|
|
+
|
|
|
+ return rootDepts;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 递归构建部门树结构
|
|
|
+ * @param parentDepts 父部门列表
|
|
|
+ * @param deptMap 部门映射表
|
|
|
+ */
|
|
|
+ private void buildDeptTree(List<CompanyDeptUserInfo> parentDepts, Map<Long, CompanyDeptUserInfo> deptMap) {
|
|
|
+ for (CompanyDeptUserInfo parentDept : parentDepts) {
|
|
|
+ // 查找当前部门的所有直接子部门
|
|
|
+ List<CompanyDeptUserInfo> children = deptMap.values().stream()
|
|
|
+ .filter(dept -> dept.getParentId() != null &&
|
|
|
+ dept.getParentId().equals(parentDept.getDeptId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (!children.isEmpty()) {
|
|
|
+ // 递归构建子部门的子树
|
|
|
+ buildDeptTree(children, deptMap);
|
|
|
+ parentDept.setChildren(children);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -264,7 +319,7 @@ public class StatisticManageServiceImpl implements IStatisticManageService {
|
|
|
companyDeptdUserList.forEach(companyDeptUserInfo -> {
|
|
|
Long userId = companyDeptUserInfo.getUserId();
|
|
|
courseWatchLogStatisticsMapper.deleteByStatisticsTimeAndDeptId(userId, companyDeptUserInfo.getDeptId(), finalDateTime);
|
|
|
- //第一步通过人去查询【课程,项目,视频id】,【发送,看视频状态】
|
|
|
+ //第一步通过人去查询【课程,项目,视频id】,【发送,看视频状态】userId空就按照部门删除,但是要先将userId为空的先删除
|
|
|
List<CourseWatchLogData> courseWatchLogData = statisticManageMapper.getCourseWatchLogData(userId, finalDateTime);
|
|
|
CourseWatchLogStatistics courseWatchLogStatistics = component(companyDeptUserInfo, finalDateTime);
|
|
|
if(CollectionUtils.isEmpty(courseWatchLogData)){
|
|
|
@@ -343,7 +398,7 @@ public class StatisticManageServiceImpl implements IStatisticManageService {
|
|
|
//上面代码其实都是差不多,为了方便之后优化代码,保持整个逻辑清晰,先将整个数据保存后,再反查数据将答题数量、红包领取数量,以及金额统计更新
|
|
|
updateCourseRedPacket(finalDateTime);
|
|
|
stopWatch.stop();
|
|
|
- log.info("gs-执行数据统计任务完成,耗时:{}", stopWatch.getTotalTimeSeconds());
|
|
|
+ log.info("gs-执行数据统计任务完成,耗时:{}", stopWatch.prettyPrint());
|
|
|
}
|
|
|
|
|
|
/**
|