Prechádzať zdrojové kódy

未能分配的公共项目工时

seyason 3 týždňov pred
rodič
commit
3f9320accb

+ 12 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/FinanceMonthlyWorktimeController.java

@@ -43,6 +43,18 @@ public class FinanceMonthlyWorktimeController {
         }
     }
 
+    @RequestMapping("/getUnDistriibutedPublicTime")
+    public HttpRespMsg getUnDistriibutedPublicTime(Integer fmwId, HttpServletRequest request) {
+        try {
+            return financeMonthlyWorktimeService.getUnDistriibutedPublicTime(fmwId,request);
+        } catch (Exception e) {
+            e.printStackTrace();
+            HttpRespMsg msg = new HttpRespMsg();
+            msg.setError(e.getMessage());
+            return msg;
+        }
+    }
+
     @RequestMapping("/exportByMonth")
     public HttpRespMsg exportByMonth(Integer companyId, String ymonth, @RequestParam(required = false, defaultValue = "0" ) Integer reGenerate,Integer isItAWorkOrder,HttpServletRequest request) throws Exception {
        return financeMonthlyWorktimeService.exportByMonth(companyId, ymonth,reGenerate,isItAWorkOrder ,request);

+ 2 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/FinanceMonthlyWorktimeService.java

@@ -28,4 +28,6 @@ public interface FinanceMonthlyWorktimeService extends IService<FinanceMonthlyWo
     HttpRespMsg setStatusFinal(Integer id, HttpServletRequest request);
 
     HttpRespMsg exportByMonth(Integer companyId, String ymonth, Integer reGenerate, Integer isItAWorkOrder, HttpServletRequest request) throws Exception;
+
+    HttpRespMsg getUnDistriibutedPublicTime(Integer fmwId, HttpServletRequest request);
 }

+ 87 - 58
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/FinanceMonthlyWorktimeServiceImpl.java

@@ -341,64 +341,6 @@ public class FinanceMonthlyWorktimeServiceImpl extends ServiceImpl<FinanceMonthl
                                 }
                             }
                         }
-
-//                        List<FmwDetail> deptAllReportList = insertDataList.stream().filter(r -> r.getDeptId().equals(deptId)).collect(Collectors.toList());
-//                        final double totalDeptTime = threeCenterIds.contains(deptId)?deptAllReportList.stream().reduce(0.0, (a, b) -> a + b.getComposeTime() + b.getRepairTime() + b.getDebugTime() + b.getWaitingTime() + b.getAssistTime(), Double::sum)
-//                                : deptAllReportList.stream().reduce(0.0, (a, b) -> a + b.getComposeTime() + b.getRepairTime() + b.getDebugTime() + b.getWaitingTime(), Double::sum);
-//                        System.out.println("处理公共工时分摊,总工时=="+totalDeptTime);
-//                        if (totalDeptTime > 0) {
-//                            //计算总工时: 用维修组装工时,调试工时和等料工时相加
-//                            insertDataList.forEach(fmwDetail -> {
-//                                //计算每一个项目的部门内部工时占比,按比例分摊公共工时
-//                                if (fmwDetail.getDeptId().equals(deptId)) {
-//                                    double curProjectTime = fmwDetail.getComposeTime() + fmwDetail.getRepairTime() + fmwDetail.getDebugTime() + fmwDetail.getWaitingTime();
-//                                    double assignTime = curProjectTime / totalDeptTime * publicReportDeptItem.getWorkingTime();
-//                                    //理论上不会出现fmwDetail.getPublicTime()有值的情况,但是为了保险起见做个叠加计算吧
-//                                    fmwDetail.setPublicTime(fmwDetail.getPublicTime() == null ? assignTime : fmwDetail.getPublicTime() + assignTime);
-//                                }
-//                            });
-//                        } else {
-//                            //该部门没有部门内部工时,按照填报部门找协作工时
-//                            // 查找该部门的员工都协作了哪些部门
-//                            List<User> deptUserList = userList.stream().filter(u -> u.getDepartmentId().equals(deptId)).collect(Collectors.toList());
-//                            List<String> deptUserIds = deptUserList.stream().map(User::getId).collect(Collectors.toList());
-//                            List<Report> assistDeptListByUser = reportMapper.selectList(new QueryWrapper<Report>().select("dept_id, sum(working_time) working_time").eq("is_assist", 1)
-//                                    .in("creator_id", deptUserIds).between("create_date", firstDayOfMonth, lastDayOfMonth).groupBy("dept_id"));
-//                            //按协作的工时占比来分配
-//                            if (!assistDeptListByUser.isEmpty()) {
-//                                double totalAssistTime = assistDeptListByUser.stream().mapToDouble(Report::getWorkingTime).sum();
-//                                if (totalAssistTime > 0) {
-//                                    for (Report assistDeptItem : assistDeptListByUser) {
-//                                        //处理部门公共工时的分摊,先按协作的其他部门的占比,分到其他部门
-//                                        double curAssistTime = assistDeptItem.getWorkingTime();
-//                                        double assignToDeptTime = curAssistTime / totalAssistTime * publicReportDeptItem.getWorkingTime();
-//                                        //按目标部门的部门内部工时占比进行二次分配
-//                                        Integer assignToDeptId = assistDeptItem.getDeptId();
-//                                        List<FmwDetail> targetDeptReportList = insertDataList.stream().filter(r -> r.getDeptId().equals(assignToDeptId)).collect(Collectors.toList());
-//                                        double totalTargetDeptTime = targetDeptReportList.stream().reduce(0.0, (a, b) -> a + b.getComposeTime() + b.getRepairTime() + b.getDebugTime() + b.getWaitingTime(), Double::sum);
-//                                        if (totalTargetDeptTime > 0) {
-//                                            //计算总工时: 用维修组装工时,调试工时和等料工时相加
-//                                            insertDataList.forEach(fmwDetail -> {
-//                                                //计算每一个项目的部门内部工时占比,按比例分摊公共工时
-//                                                if (fmwDetail.getDeptId().equals(assignToDeptId)) {
-//                                                    double curProjectTime = fmwDetail.getComposeTime() + fmwDetail.getRepairTime() + fmwDetail.getDebugTime() + fmwDetail.getWaitingTime();
-//                                                    double assignTime = curProjectTime / totalTargetDeptTime * assignToDeptTime;
-//                                                    //可能之前已经有其他部门的分摊过来了,需要叠加
-//                                                    fmwDetail.setPublicTime(fmwDetail.getPublicTime() == null ? assignTime : fmwDetail.getPublicTime() +assignTime);
-//                                                }
-//                                            });
-//                                        } else {
-//                                            Department dept = departmentMapper.selectById(assignToDeptId);
-//                                            throw new Exception("存在目标部门没有内部工时,导致公共工时无法分摊:部门=="+dept.getDepartmentName()+",deptId=="+assignToDeptId);
-//                                        }
-//                                    }
-//                                }
-//                            } else {
-//                                //本部门也没有协作其他部门产生工单工时
-//                                Department dept = departmentMapper.selectById(deptId);
-//                                throw new Exception("公共工时无法分配,因为本部门没有协作其他部门产生工单工时,部门=="+dept.getDepartmentName()+",deptId=="+deptId);
-//                            }
-//                        }
                     }
                 }
             }
@@ -615,6 +557,93 @@ public class FinanceMonthlyWorktimeServiceImpl extends ServiceImpl<FinanceMonthl
         return httpRespMsg;
     }
 
+    @Override
+    public HttpRespMsg getUnDistriibutedPublicTime(Integer fmwId, HttpServletRequest request) {
+        FinanceMonthlyWorktime financeMonthlyWorktime = financeMonthlyWorktimeMapper.selectById(fmwId);
+        List<Project> publicProjectList = projectMapper.selectList(new LambdaQueryWrapper<Project>().eq(Project::getIsPublic, 1).eq(Project::getCompanyId, financeMonthlyWorktime.getCompanyId()));
+        List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>().select(User::getId, User::getName, User::getDepartmentId).eq(User::getCompanyId, financeMonthlyWorktime.getCompanyId()));
+// 处理公共项目工时分摊
+        List<Integer> publicProjectIds = publicProjectList.stream()
+                .map(Project::getId)
+                .collect(Collectors.toList());
+        HttpRespMsg msg = new HttpRespMsg();
+        List<Report> undistributedList = new ArrayList<>();
+        if (!publicProjectIds.isEmpty()) {
+            String ymonth = financeMonthlyWorktime.getYmonth();
+            //获取当月的第一天和最后一天
+            LocalDate firstDayOfMonth = LocalDate.parse(ymonth + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+            LocalDate lastDayOfMonth = firstDayOfMonth.withDayOfMonth(firstDayOfMonth.lengthOfMonth());
+            // 查询公共项目工时
+            //TODO: 需确认,员工填报公共项目工时的时候,会选择到工单吗?
+            //研发中心的公共工时不参与分摊; deptId=9508
+            int reserveDeptId = 9508;
+            List<Report> publicReportList = reportMapper.selectList(
+                    new LambdaQueryWrapper<Report>().select(Report::getCreatorId, Report::getDeptId, Report::getWorkingTime).eq(Report::getState, 1)
+                            .ne(Report::getDeptId, reserveDeptId)
+                            .in(Report::getProjectId, publicProjectIds).between(Report::getCreateDate, firstDayOfMonth, lastDayOfMonth));
+            //按照人员所在的部门进行分组,汇总,如果公共项目没有工单,此步骤可以省略
+            publicReportList.forEach(report -> {
+                User reportOwner = userList.stream().filter(u -> u.getId().equals(report.getCreatorId())).findFirst().orElse(null);
+                if (reportOwner != null) {
+                    report.setDeptId(reportOwner.getDepartmentId());
+                }
+            });
+
+            //分组,合计部门公共工时
+            Map<Integer, Double> map = publicReportList.stream().collect(Collectors.groupingBy(Report::getDeptId, Collectors.summingDouble(Report::getWorkingTime)));
+            //将map按照List形式重新组合
+            publicReportList = map.entrySet().stream()
+                    .map(e -> {
+                        Report report = new Report();
+                        report.setDeptId(e.getKey());
+                        report.setWorkingTime(e.getValue());
+                        return report;
+                    })
+                    .collect(Collectors.toList());
+            if (!publicReportList.isEmpty()) {
+                //处理每个部门的公共项目工时分摊
+
+                List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", financeMonthlyWorktime.getCompanyId()));
+                //三大中心:北京,上海,武汉需按照本部门人填报的全部工时(不区分是否是协作工时),按部门分组
+                List<Integer> threeCenterIds = new ArrayList<>(Arrays.asList(9508, 9509, 9510));
+                for (Report publicReportDeptItem : publicReportList) {
+                    Integer deptId = publicReportDeptItem.getDeptId();
+                    System.out.println("处理公共工时分摊,待分配部门=="+deptId);
+                    if (threeCenterIds.contains(deptId)) {
+                        //处理三大中心的公共工时分摊
+                        List<User> deptUserList = userList.stream().filter(u -> u.getDepartmentId().equals(deptId)).collect(Collectors.toList());
+                        List<String> deptUserIds = deptUserList.stream().map(User::getId).collect(Collectors.toList());
+                        List<Report> deptUserReportGroupList = reportMapper.selectList(new QueryWrapper<Report>().select("project_id,extra_field4,extra_field5,dept_id, sum(working_time) working_time")
+                                .in("creator_id", deptUserIds).between("create_date", firstDayOfMonth, lastDayOfMonth).isNotNull("extra_field4").ne("extra_field4", "")
+                                .groupBy("project_id,extra_field4,extra_field5"));
+                        double totalTime = deptUserReportGroupList.stream().mapToDouble(Report::getWorkingTime).sum();
+                        System.out.println("处理公共工时分摊,总工时=="+totalTime);
+                        if (totalTime == 0) {
+                            //当前部门没有工时
+                            departmentList.stream().filter(d->d.getDepartmentId().equals(deptId)).findFirst().ifPresent(department -> publicReportDeptItem.setUserReportDeptName(department.getDepartmentName()));
+                            undistributedList.add(publicReportDeptItem);
+                        }
+                    } else {
+                        //处理非三大中心的公共工时分摊,按本部门的工单工时来统计
+                        List<Report> deptUserReportGroupList = reportMapper.selectList(new QueryWrapper<Report>().select("project_id,extra_field4,extra_field5,dept_id, sum(working_time) working_time")
+                                .eq("dept_id", deptId).between("create_date", firstDayOfMonth, lastDayOfMonth).isNotNull("extra_field4").ne("extra_field4", "")
+                                .eq("is_assist", 0)
+                                .groupBy("project_id,extra_field4,extra_field5"));
+                        double totalTime = deptUserReportGroupList.stream().mapToDouble(Report::getWorkingTime).sum();
+                        System.out.println("处理非三大中心公共工时分摊,总工时=="+totalTime);
+                        if (totalTime == 0) {
+                            //当前部门没有工时
+                            departmentList.stream().filter(d->d.getDepartmentId().equals(deptId)).findFirst().ifPresent(department -> publicReportDeptItem.setUserReportDeptName(department.getDepartmentName()));
+                            undistributedList.add(publicReportDeptItem);
+                        }
+                    }
+                }
+                msg.setData(undistributedList);
+            }
+        }
+        return msg;
+    }
+
     private static CellStyle createHeaderStyle(Workbook workbook) {
         CellStyle style = workbook.createCellStyle();
         style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());