|
@@ -43,6 +43,7 @@ import com.zjugis.module.adm.util.DateUtil;
|
|
|
import com.zjugis.module.adm.util.PageUtil;
|
|
|
import com.zjugis.module.system.api.dept.DeptApi;
|
|
|
import com.zjugis.module.system.api.dept.dto.DeptRespDTO;
|
|
|
+import com.zjugis.module.system.api.dept.dto.DeptTreeRespDTO;
|
|
|
import com.zjugis.module.system.api.dict.DictDataApi;
|
|
|
import com.zjugis.module.system.api.dict.dto.DictDataRespDTO;
|
|
|
import com.zjugis.module.system.api.user.AdminUserApi;
|
|
@@ -232,16 +233,16 @@ public class ReportServiceImpl implements ReportService {
|
|
|
/**
|
|
|
* 获取员工工作报告Map
|
|
|
* @param reportType 报告类型
|
|
|
- * @param year 年份
|
|
|
- * @param month 月份
|
|
|
- * @param deptId 部门Id
|
|
|
- * @param userId 用户Id
|
|
|
+ * @param year 年份
|
|
|
+ * @param month 月份
|
|
|
+ * @param deptId 部门Id
|
|
|
+ * @param userId 用户Id
|
|
|
* @return
|
|
|
*/
|
|
|
private Map<String, List<ReportDO>> getReport(String reportType, Short year, Short month, Set<String> deptId, String userId) {
|
|
|
LambdaQueryWrapper<ReportDO> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.select(ReportDO::getReportStartDate, ReportDO::getReportYear, ReportDO::getReportMonth, ReportDO::getReportWeek, ReportDO::getDeptId, ReportDO::getUserId, ReportDO::getId);
|
|
|
- queryWrapper.eq(ReportDO::getIsTemp,false);
|
|
|
+ queryWrapper.eq(ReportDO::getIsTemp, false);
|
|
|
queryWrapper.in(CollectionUtils.isNotEmpty(deptId), ReportDO::getDeptId, deptId);
|
|
|
queryWrapper.eq(StrUtil.isNotBlank(userId), ReportDO::getUserId, userId);
|
|
|
|
|
@@ -289,10 +290,10 @@ public class ReportServiceImpl implements ReportService {
|
|
|
|
|
|
//获取工作日或工作周数量
|
|
|
Integer shouldFillCount = 0;
|
|
|
- if("daily".equals(reportStatisticReqDTO.getReportType())){
|
|
|
- shouldFillCount = workdayService.getMonthWorkDayNum(year,month);
|
|
|
- }else{
|
|
|
- shouldFillCount = workdayService.getMonthWorkWeekNum(year,month);
|
|
|
+ if ("daily".equals(reportStatisticReqDTO.getReportType())) {
|
|
|
+ shouldFillCount = workdayService.getMonthWorkDayNum(year, month);
|
|
|
+ } else {
|
|
|
+ shouldFillCount = workdayService.getMonthWorkWeekNum(year, month);
|
|
|
}
|
|
|
|
|
|
List<StaffRecordSDO> records = staffPage.getRecords();
|
|
@@ -304,9 +305,10 @@ public class ReportServiceImpl implements ReportService {
|
|
|
|
|
|
statisticRespVO.setUserId(staff.getUserId());
|
|
|
statisticRespVO.setNickName(userMap.get(staff.getUserId()) == null ? null : userMap.get(staff.getUserId()).getNickname());
|
|
|
- statisticRespVO.setDeptId(userMap.get(staff.getUserId()) == null ? null :userMap.get(staff.getUserId()).getDeptId());
|
|
|
- statisticRespVO.setDeptName(userMap.get(staff.getUserId()) == null ? null :userMap.get(staff.getUserId()).getDeptName());
|
|
|
+ statisticRespVO.setDeptId(userMap.get(staff.getUserId()) == null ? null : userMap.get(staff.getUserId()).getDeptId());
|
|
|
+ statisticRespVO.setDeptName(userMap.get(staff.getUserId()) == null ? null : userMap.get(staff.getUserId()).getDeptName());
|
|
|
|
|
|
+ statisticRespVO.setReportType(reportStatisticReqDTO.getReportType());
|
|
|
statisticRespVO.setShouldFilledCount(shouldFillCount);
|
|
|
List<ReportDO> staffReportList = staffReportMap.get(staff.getUserId());
|
|
|
statisticRespVO.setFilledCount(staffReportList == null ? 0 : staffReportList.size());
|
|
@@ -320,30 +322,55 @@ public class ReportServiceImpl implements ReportService {
|
|
|
return pages;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 部门工作报告统计
|
|
|
+ *
|
|
|
+ * @param year
|
|
|
+ * @param month
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
- public List<DeptReportStatisticRespVO> getDeptReportStatistics(Short year,Short month) {
|
|
|
+ public List<DeptReportStatisticRespVO> getDeptReportStatistics(Short year, Short month) {
|
|
|
ReportStatisticReqDTO reportStatisticReqDTO = new ReportStatisticReqDTO();
|
|
|
reportStatisticReqDTO.setPageNo(1);
|
|
|
reportStatisticReqDTO.setPageSize(9999);
|
|
|
reportStatisticReqDTO.setYear(year);
|
|
|
reportStatisticReqDTO.setMonth(month);
|
|
|
|
|
|
+ //获取部门列表
|
|
|
+ List<DeptRespDTO> deptList = deptApi.getDeptList().getData();
|
|
|
+
|
|
|
+ //获取职能部门
|
|
|
+ List<DictDataRespDTO> functionalDeptList = dictApi.getDictDataList("functional_dept").getData();
|
|
|
+ List<String> functionalDeptIdList = functionalDeptList.stream().map(DictDataRespDTO::getValue).collect(Collectors.toList());
|
|
|
+ //职能部门层级关系手动赋值
|
|
|
+ DeptRespDTO functionalDept = new DeptRespDTO();
|
|
|
+ functionalDept.setId("001");
|
|
|
+ functionalDept.setParentId("0");
|
|
|
+ functionalDept.setName("职能部门");
|
|
|
+ deptList.add(functionalDept);
|
|
|
+ for (DeptRespDTO dept : deptList) {
|
|
|
+ if (functionalDeptIdList.contains(dept.getId())) {
|
|
|
+ dept.setParentId("001");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //获取统计日报的部门(市场部门)
|
|
|
+ List<DictDataRespDTO> dailyReportDeptList = dictApi.getDictDataList("statistic_daily_dept").getData();
|
|
|
+ List<String> dailyReportDeptIdList = dailyReportDeptList.stream().map(DictDataRespDTO::getValue).collect(Collectors.toList());
|
|
|
+
|
|
|
//获取每个用户周报统计结果
|
|
|
List<ReportStatisticRespVO> weekReportStatistics = this.getReportStatistics(reportStatisticReqDTO.setReportType("weekly")).getList();
|
|
|
//获取每个部门周报统计结果
|
|
|
- Map<String, DeptReportStatisticRespVO> weekReportStatisticsGroup = this.getDeptReportStatisticsGroup(weekReportStatistics);
|
|
|
+ Map<String, DeptReportStatisticRespVO> weekReportStatisticsGroup = this.aggregateDeptReportStatistics(weekReportStatistics, deptList, year, month, dailyReportDeptIdList);
|
|
|
|
|
|
//获取每个用户日报统计结果
|
|
|
List<ReportStatisticRespVO> dailyReportStatistics = this.getReportStatistics(reportStatisticReqDTO.setReportType("daily")).getList();
|
|
|
//获取每个部门日报统计结果
|
|
|
- Map<String, DeptReportStatisticRespVO> dailyReportStatisticsGroup = this.getDeptReportStatisticsGroup(dailyReportStatistics);
|
|
|
-
|
|
|
- //获取统计日报的部门
|
|
|
- List<DictDataRespDTO> dictList = dictApi.getDictDataList("statistic_daily_dept").getData();
|
|
|
-
|
|
|
+ Map<String, DeptReportStatisticRespVO> dailyReportStatisticsGroup = this.aggregateDeptReportStatistics(dailyReportStatistics, deptList, year, month, dailyReportDeptIdList);
|
|
|
//统计每个部门的周日报完成率
|
|
|
List<DeptReportStatisticRespVO> voList = new ArrayList<>();
|
|
|
- List<DeptRespDTO> deptList = deptApi.getDeptList().getData();
|
|
|
+
|
|
|
+
|
|
|
for (DeptRespDTO dept : deptList) {
|
|
|
DeptReportStatisticRespVO vo = new DeptReportStatisticRespVO();
|
|
|
vo.setReportYear(year);
|
|
@@ -352,13 +379,16 @@ public class ReportServiceImpl implements ReportService {
|
|
|
vo.setDeptName(dept.getName());
|
|
|
vo.setParentId(dept.getParentId());
|
|
|
|
|
|
- DeptReportStatisticRespVO reportStatistic = null ;
|
|
|
- if(dictList.contains(dept.getId())){
|
|
|
+ DeptReportStatisticRespVO reportStatistic = null;
|
|
|
+ if (dailyReportDeptIdList.contains(dept.getId())) {
|
|
|
reportStatistic = dailyReportStatisticsGroup.get(dept.getId());
|
|
|
- } else{
|
|
|
+ vo.setReportType("daily");
|
|
|
+ } else {
|
|
|
reportStatistic = weekReportStatisticsGroup.get(dept.getId());
|
|
|
+ vo.setReportType("weekly");
|
|
|
}
|
|
|
- if(reportStatistic != null){
|
|
|
+
|
|
|
+ if (reportStatistic != null) {
|
|
|
vo.setShouldFilledCount(reportStatistic.getShouldFilledCount());
|
|
|
vo.setFilledCount(reportStatistic.getFilledCount());
|
|
|
vo.setNotFilledCount(reportStatistic.getNotFilledCount());
|
|
@@ -366,9 +396,100 @@ public class ReportServiceImpl implements ReportService {
|
|
|
}
|
|
|
voList.add(vo);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
return voList;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public Map<String, DeptReportStatisticRespVO> aggregateDeptReportStatistics(List<ReportStatisticRespVO> dailyReportStatistics, List<DeptRespDTO> deptList, Short year, Short month, List<String> dailyReportDeptIdList) {
|
|
|
+ // 第一步:合并用户统计到部门统计
|
|
|
+ Map<String, DeptReportStatisticRespVO> deptStatisticMap = new HashMap<>();
|
|
|
+ for (ReportStatisticRespVO vo : dailyReportStatistics) {
|
|
|
+ String deptId = vo.getDeptId();
|
|
|
+ DeptReportStatisticRespVO deptStat = deptStatisticMap.computeIfAbsent(deptId, k -> new DeptReportStatisticRespVO(deptId, 0, 0));
|
|
|
+ deptStat.setDeptId(deptId);
|
|
|
+ deptStat.setReportYear(year);
|
|
|
+ deptStat.setReportMonth(month);
|
|
|
+ deptStat.setShouldFilledCount(deptStat.getShouldFilledCount() + vo.getShouldFilledCount());
|
|
|
+ deptStat.setNotFilledCount(deptStat.getNotFilledCount() + vo.getNotFilledCount());
|
|
|
+ deptStat.setFilledCount(deptStat.getFilledCount() + vo.getFilledCount());
|
|
|
+ deptStat.setFillRate(deptStat.getShouldFilledCount() == 0 ? null : deptStat.getFilledCount() * 1.0 / deptStat.getShouldFilledCount());
|
|
|
+ }
|
|
|
+ List<DeptReportStatisticRespVO> deptStatisticValue = deptStatisticMap.values().stream().collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<String, List<String>> deptIdMap = collectSubtreeIds(deptList);
|
|
|
+
|
|
|
+
|
|
|
+ // 遍历部门id,找到有子节点的部门,并计算其子节点的统计值
|
|
|
+ for (String deptId : deptIdMap.keySet()) {
|
|
|
+
|
|
|
+ List<String> childDeptIdList = deptIdMap.get(deptId);
|
|
|
+ if (childDeptIdList.size() <= 1) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //子级去除市场部门
|
|
|
+ List<String> removeMarketChildDeptIdList = childDeptIdList.stream()
|
|
|
+ .filter(item -> !dailyReportDeptIdList.contains(item))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<DeptReportStatisticRespVO> childDeptList = deptStatisticValue.stream().filter(c -> removeMarketChildDeptIdList.contains(c.getDeptId())).collect(Collectors.toList());
|
|
|
+ // 使用Stream进行统计
|
|
|
+ int shouldFilledCount = (int) childDeptList.stream()
|
|
|
+ .mapToLong(DeptReportStatisticRespVO::getShouldFilledCount)
|
|
|
+ .sum();
|
|
|
+
|
|
|
+ int filledCount = (int) childDeptList.stream()
|
|
|
+ .mapToLong(DeptReportStatisticRespVO::getFilledCount)
|
|
|
+ .sum();
|
|
|
+ DeptReportStatisticRespVO vo = new DeptReportStatisticRespVO(deptId, shouldFilledCount, filledCount);
|
|
|
+ deptStatisticMap.put(deptId, vo);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return deptStatisticMap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static Map<String, List<String>> collectSubtreeIds(List<DeptRespDTO> deptTree) {
|
|
|
+ // 创建一个映射,用于快速查找部门对象
|
|
|
+ Map<String, DeptRespDTO> idToDeptMap = new HashMap<>();
|
|
|
+ for (DeptRespDTO dept : deptTree) {
|
|
|
+ idToDeptMap.put(dept.getId(), dept);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 最终的映射,key是部门id,value是所有子集节点id列表
|
|
|
+ Map<String, List<String>> result = new HashMap<>();
|
|
|
+
|
|
|
+ // 遍历每个部门,并递归地收集子集节点
|
|
|
+ for (DeptRespDTO dept : deptTree) {
|
|
|
+ collectSubtreeIdsRecursive(dept, idToDeptMap, result);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void collectSubtreeIdsRecursive(DeptRespDTO dept, Map<String, DeptRespDTO> idToDeptMap, Map<String, List<String>> result) {
|
|
|
+ // 获取当前部门的ID,并添加到结果映射中(如果尚未添加)
|
|
|
+ String deptId = dept.getId();
|
|
|
+ result.computeIfAbsent(deptId, k -> new ArrayList<>()).add(deptId);
|
|
|
+
|
|
|
+ // 递归地处理子部门
|
|
|
+ String parentId = dept.getParentId();
|
|
|
+ if (parentId != null) { // 确保parentId不是null,避免无限循环(理论上应该是这样,但最好检查)
|
|
|
+ DeptRespDTO parentDept = idToDeptMap.get(parentId);
|
|
|
+ if (parentDept != null) { // 确保找到了父部门
|
|
|
+ // 如果父部门的子集列表尚未初始化,则初始化它
|
|
|
+ result.computeIfAbsent(parentId, k -> new ArrayList<>());
|
|
|
+ // 将当前部门添加到父部门的子集列表中
|
|
|
+ result.get(parentId).add(deptId);
|
|
|
+ // 递归地处理父部门的所有其他子部门
|
|
|
+ collectSubtreeIdsRecursive(parentDept, idToDeptMap, result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public PageResult<ReportWorkloadStatisticVO> getReportWorkloadStatistics(ReportWorkloadStatisticReqDTO reportWorkloadStatisticReqDTO) {
|
|
|
Short year = reportWorkloadStatisticReqDTO.getYear();
|
|
@@ -376,13 +497,13 @@ public class ReportServiceImpl implements ReportService {
|
|
|
String projectName = reportWorkloadStatisticReqDTO.getProjectName();
|
|
|
|
|
|
QueryWrapper<ReportWorkloadDO> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("WORKLOAD.DELETED",0);
|
|
|
- queryWrapper.and(qw->{
|
|
|
+ queryWrapper.eq("WORKLOAD.DELETED", 0);
|
|
|
+ queryWrapper.and(qw -> {
|
|
|
qw.eq("REPORT_TYPE", "daily").ge("REPORT_START_DATE", DateUtil.getStartDateTime(year, month)).le("REPORT_START_DATE", DateUtil.getEndDateTime(year, month));
|
|
|
qw.or();
|
|
|
qw.eq("REPORT_TYPE", "weekly").eq("REPORT_YEAR", year).eq("REPORT_MONTH", month);
|
|
|
});
|
|
|
- if(StrUtil.isNotBlank(reportWorkloadStatisticReqDTO.getUserId())){
|
|
|
+ if (StrUtil.isNotBlank(reportWorkloadStatisticReqDTO.getUserId())) {
|
|
|
queryWrapper.eq("USER_ID", reportWorkloadStatisticReqDTO.getUserId());
|
|
|
}
|
|
|
|
|
@@ -392,10 +513,10 @@ public class ReportServiceImpl implements ReportService {
|
|
|
projectDto.setPageSize(-1);
|
|
|
projectDto.setXmmc(projectName);
|
|
|
CommonResult<Page<ProjectVO>> projectPage = projectClient.getProjectPage(projectDto);
|
|
|
- List<ProjectVO> projectList = new ArrayList<>();
|
|
|
+ List<ProjectVO> projectList = new ArrayList<>();
|
|
|
if (projectPage.isSuccess()) {
|
|
|
- projectList = projectPage.getData().getRecords();
|
|
|
- if(CollectionUtils.isEmpty(projectList)){
|
|
|
+ projectList = projectPage.getData().getRecords();
|
|
|
+ if (CollectionUtils.isEmpty(projectList)) {
|
|
|
return new PageResult<>();
|
|
|
}
|
|
|
}
|
|
@@ -407,7 +528,7 @@ public class ReportServiceImpl implements ReportService {
|
|
|
.collect(Collectors.toList());
|
|
|
int lastIndex = chunkedProjectIdList.size() - 1;
|
|
|
|
|
|
- queryWrapper.and(qw->{
|
|
|
+ queryWrapper.and(qw -> {
|
|
|
for (int i = 0; i <= lastIndex; i++) {
|
|
|
List<String> idList = chunkedProjectIdList.get(i);
|
|
|
qw.in("project_id", idList);
|
|
@@ -445,7 +566,7 @@ public class ReportServiceImpl implements ReportService {
|
|
|
result.setProjectId(projectId);
|
|
|
result.setWorkTime(totalWorkTime);
|
|
|
Optional<ProjectVO> projectOptional = projectList.stream().filter(c -> c.getId().equals(projectId)).findFirst();
|
|
|
- if(projectOptional.isPresent()){
|
|
|
+ if (projectOptional.isPresent()) {
|
|
|
result.setXmmc(projectOptional.get().getXmmc());
|
|
|
result.setXmbh(projectOptional.get().getXmbh());
|
|
|
}
|
|
@@ -456,35 +577,6 @@ public class ReportServiceImpl implements ReportService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 获取部门统计结果
|
|
|
- * @param reportStatisticsList
|
|
|
-
|
|
|
- */
|
|
|
- private Map<String, DeptReportStatisticRespVO> getDeptReportStatisticsGroup(List<ReportStatisticRespVO> reportStatisticsList) {
|
|
|
- Map<String, DeptReportStatisticRespVO> reportStatisticsGroup = reportStatisticsList.stream().filter(report->report.getDeptId() != null)
|
|
|
- .collect(Collectors.groupingBy(
|
|
|
- ReportStatisticRespVO::getDeptId,
|
|
|
- Collectors.collectingAndThen(
|
|
|
- Collectors.toList(),
|
|
|
- departmentReports -> {
|
|
|
- int shouldFilledCount = departmentReports.stream()
|
|
|
- .mapToInt(ReportStatisticRespVO::getShouldFilledCount)
|
|
|
- .sum();
|
|
|
- int filledCount = departmentReports.stream()
|
|
|
- .mapToInt(ReportStatisticRespVO::getFilledCount)
|
|
|
- .sum();
|
|
|
- return new DeptReportStatisticRespVO(
|
|
|
- shouldFilledCount,
|
|
|
- filledCount,
|
|
|
- shouldFilledCount - filledCount,
|
|
|
- filledCount*1.0/shouldFilledCount
|
|
|
- );
|
|
|
- }
|
|
|
- )
|
|
|
- ));
|
|
|
- return reportStatisticsGroup;
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public List<String> getRecentReceiveUser(String userId) {
|
|
@@ -492,7 +584,7 @@ public class ReportServiceImpl implements ReportService {
|
|
|
queryWrapper.eq(ReportDO::getUserId, userId);
|
|
|
queryWrapper.orderByDesc(ReportDO::getCreateTime);
|
|
|
List<ReportDO> reportDOList = reportMapper.selectList(queryWrapper);
|
|
|
- if(CollectionUtils.isEmpty(reportDOList)){
|
|
|
+ if (CollectionUtils.isEmpty(reportDOList)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
List<ReportReceiveRespVO> reportReceiveByRId = reportReceiveService.getReportReceiveByRId(reportDOList.get(0).getId());
|