|
@@ -808,77 +808,125 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public OutMontClockBo getMonthClock(Integer id, String yearMonth) {
|
|
public OutMontClockBo getMonthClock(Integer id, String yearMonth) {
|
|
|
- OutMontClockBo out = new OutMontClockBo();
|
|
|
|
|
|
|
+ OutMontClockBo result = new OutMontClockBo();
|
|
|
|
|
+ //获取项目信息
|
|
|
ProjectTask projectTask = getProjectTask(id);
|
|
ProjectTask projectTask = getProjectTask(id);
|
|
|
- SysDept sysDept = deptService.selectDeptByPid(projectTask.getId());
|
|
|
|
|
|
|
+ //获取部门信息
|
|
|
|
|
+ SysDept department = deptService.selectDeptByPid(projectTask.getId());
|
|
|
|
|
+ //填充基础信息
|
|
|
|
|
+ fillBasicInfo(result, projectTask, department);
|
|
|
|
|
+ //获取开始于结束时间
|
|
|
|
|
+ LocalDate startDate = parseStartDate(yearMonth);
|
|
|
|
|
+ LocalDate endDate = calculateEndDate(startDate);
|
|
|
|
|
+ //获取表名
|
|
|
|
|
+ result.setTableName(formatTableName(startDate));
|
|
|
|
|
+ //获取打卡数据
|
|
|
|
|
+ List<ProjectStaffRecord> monthClockRecords = projectStaffRecordMapper.getMonthClock(id, startDate, endDate);
|
|
|
|
|
+ //获取天数模板
|
|
|
|
|
+ LocalDate lastDayOfMonth = startDate.with(TemporalAdjusters.lastDayOfMonth());
|
|
|
|
|
+
|
|
|
|
|
+ List<Map<String, Object>> daysTemplate = getDaysMap(lastDayOfMonth, startDate);
|
|
|
|
|
+ //处理打卡数据
|
|
|
|
|
+ List<Map<String, Object>> processedData = processClockRecords(monthClockRecords, daysTemplate);
|
|
|
|
|
+ //处理时长和比例
|
|
|
|
|
+ pushDurationAndProportion(processedData);
|
|
|
|
|
+ //返回结果
|
|
|
|
|
+ result.setList(processedData);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void fillBasicInfo(OutMontClockBo out, ProjectTask projectTask, SysDept department) {
|
|
|
out.setProjectName(projectTask.getName());
|
|
out.setProjectName(projectTask.getName());
|
|
|
- out.setDepartmentName(sysDept.getDeptName());
|
|
|
|
|
- if (sysDept.getCompanyName()!=null){
|
|
|
|
|
- out.setCompanyName(sysDept.getCompanyName());
|
|
|
|
|
- }else {
|
|
|
|
|
- out.setCompanyName(sysDept.getDeptName());
|
|
|
|
|
|
|
+ out.setDepartmentName(department.getDeptName());
|
|
|
|
|
+ out.setCompanyName(department.getCompanyName() != null
|
|
|
|
|
+ ? department.getCompanyName()
|
|
|
|
|
+ : department.getDeptName());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private LocalDate parseStartDate(String yearMonth) {
|
|
|
|
|
+ String dateStr = yearMonth + "-01";
|
|
|
|
|
+ return LocalDate.parse(dateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private LocalDate calculateEndDate(LocalDate startDate) {
|
|
|
|
|
+ int year = startDate.getYear();
|
|
|
|
|
+ int month = startDate.getMonthValue();
|
|
|
|
|
+
|
|
|
|
|
+ if (month == Month.DECEMBER.getValue()) {
|
|
|
|
|
+ return LocalDate.of(year + 1, 1, 1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return LocalDate.of(year, month + 1, 1);
|
|
|
}
|
|
}
|
|
|
- String dateYMD=yearMonth+"-01";
|
|
|
|
|
- LocalDate startDate = LocalDate.parse(dateYMD, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
|
|
- startDate=startDate.withDayOfMonth(1);
|
|
|
|
|
- int year=startDate.getYear();
|
|
|
|
|
- int month=startDate.getMonthValue();
|
|
|
|
|
- out.setTableName(year+"年"+month+"月工时记录表");
|
|
|
|
|
- int lastMonth = month;
|
|
|
|
|
- if(startDate.getMonthValue()== Month.DECEMBER.getValue()){
|
|
|
|
|
- lastMonth=1;
|
|
|
|
|
- year=startDate.getYear()+1;
|
|
|
|
|
- }else {
|
|
|
|
|
- lastMonth=startDate.getMonthValue()+1;
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String formatTableName(LocalDate date) {
|
|
|
|
|
+ return date.getYear() + "年" + date.getMonthValue() + "月工时记录表";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<Map<String, Object>> processClockRecords(List<ProjectStaffRecord> records, List<Map<String, Object>> daysTemplate) {
|
|
|
|
|
+ Map<String, Map<String, Object>> employeeDataMap = new LinkedHashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ for (ProjectStaffRecord record : records) {
|
|
|
|
|
+ String employeeName = record.getName();
|
|
|
|
|
+
|
|
|
|
|
+ if (!employeeDataMap.containsKey(employeeName)) {
|
|
|
|
|
+ Map<String, Object> employeeEntry = createEmployeeEntry(employeeName, daysTemplate);
|
|
|
|
|
+ employeeDataMap.put(employeeName, employeeEntry);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ updateEmployeeDailyData(employeeDataMap.get(employeeName), record);
|
|
|
}
|
|
}
|
|
|
- LocalDate endDate = LocalDate.of(year,lastMonth,1);
|
|
|
|
|
- List<ProjectStaffRecord> monthClock = projectStaffRecordMapper.getMonthClock(id, startDate, endDate);
|
|
|
|
|
-// monthClock = monthClock.stream().filter(e -> e.getAid() == 48).collect(Collectors.toList());
|
|
|
|
|
- LocalDate lastDay = startDate.with(TemporalAdjusters.lastDayOfMonth());
|
|
|
|
|
- List<Map<String,Object>> listData = new ArrayList<>();
|
|
|
|
|
- List<Map<String, Object>> daysMap = getDaysMap(lastDay, startDate);
|
|
|
|
|
- //将数据与表头匹配
|
|
|
|
|
- for (ProjectStaffRecord e : monthClock) {
|
|
|
|
|
- //先匹配是否存在这个人,不存证则需要新增
|
|
|
|
|
- LocalDate recordTime = e.getRecordTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
|
|
- if (listData.isEmpty()){
|
|
|
|
|
- pushDate(e, daysMap, recordTime, listData);
|
|
|
|
|
- }else {
|
|
|
|
|
- boolean flag = false;
|
|
|
|
|
- for (Map<String, Object> m : listData) {
|
|
|
|
|
- String name = (String) m.get("name");
|
|
|
|
|
- if (name.equals(e.getName())){
|
|
|
|
|
- flag=true;
|
|
|
|
|
- //存在则需要匹配存入
|
|
|
|
|
- List<Map<String, Object>> maps = (List<Map<String, Object>>) m.get("data");
|
|
|
|
|
- for (Map<String, Object> map2 : maps) {
|
|
|
|
|
- Integer date = (Integer) map2.get("date");
|
|
|
|
|
- Integer dayOfMonth = recordTime.getDayOfMonth();
|
|
|
|
|
|
|
|
|
|
- //比对日期,如果日期有参数相加,没有则赋值
|
|
|
|
|
- if (dayOfMonth.equals(date)) {
|
|
|
|
|
- BigDecimal projectDuration = (BigDecimal) map2.get("projectDuration");
|
|
|
|
|
- BigDecimal added = projectDuration.add(BigDecimal.valueOf(e.getDuration()));
|
|
|
|
|
- BigDecimal checkDuration = BigDecimal.valueOf(e.getCheckDuration());
|
|
|
|
|
- map2.put("projectDuration", added);
|
|
|
|
|
- map2.put("checkDuration", checkDuration);
|
|
|
|
|
- map2.put("notDuration", checkDuration.subtract(added));
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (!flag){
|
|
|
|
|
- pushDate(e, daysMap, recordTime, listData);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return new ArrayList<>(employeeDataMap.values());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Map<String, Object> createEmployeeEntry(String employeeName, List<Map<String, Object>> daysTemplate) {
|
|
|
|
|
+ Map<String, Object> entry = new LinkedHashMap<>();
|
|
|
|
|
+ entry.put("name", employeeName);
|
|
|
|
|
+ entry.put("data", deepCopyDaysTemplate(daysTemplate));
|
|
|
|
|
+ return entry;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<Map<String, Object>> deepCopyDaysTemplate(List<Map<String, Object>> template) {
|
|
|
|
|
+ List<Map<String, Object>> copy = new ArrayList<>();
|
|
|
|
|
+ for (Map<String, Object> day : template) {
|
|
|
|
|
+ copy.add(new LinkedHashMap<>(day));
|
|
|
|
|
+ }
|
|
|
|
|
+ return copy;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void updateEmployeeDailyData(Map<String, Object> employeeEntry, ProjectStaffRecord record) {
|
|
|
|
|
+ LocalDate recordDate = record.getRecordTime().toInstant()
|
|
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
|
|
+ .toLocalDate();
|
|
|
|
|
+
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ List<Map<String, Object>> dailyData = (List<Map<String, Object>>) employeeEntry.get("data");
|
|
|
|
|
+
|
|
|
|
|
+ for (Map<String, Object> dayData : dailyData) {
|
|
|
|
|
+ Integer dayOfMonth = (Integer) dayData.get("date");
|
|
|
|
|
+
|
|
|
|
|
+ if (recordDate.getDayOfMonth() == dayOfMonth) {
|
|
|
|
|
+ updateDayRecord(dayData, record);
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- //将数据统计,计算出所有工时与分摊率
|
|
|
|
|
- pushDurationAndProportion(listData);
|
|
|
|
|
- out.setList(listData);
|
|
|
|
|
- return out;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void updateDayRecord(Map<String, Object> dayData, ProjectStaffRecord record) {
|
|
|
|
|
+ BigDecimal currentProjectDuration = (BigDecimal) dayData.get("projectDuration");
|
|
|
|
|
+ BigDecimal recordDuration = BigDecimal.valueOf(record.getDuration());
|
|
|
|
|
+ BigDecimal checkDuration = BigDecimal.valueOf(record.getCheckDuration());
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal updatedProjectDuration = currentProjectDuration.add(recordDuration);
|
|
|
|
|
+
|
|
|
|
|
+ dayData.put("projectDuration", updatedProjectDuration);
|
|
|
|
|
+ dayData.put("checkDuration", checkDuration);
|
|
|
|
|
+ dayData.put("notDuration", checkDuration.subtract(updatedProjectDuration));
|
|
|
|
|
+ }
|
|
|
|
|
+// ... existing code ...
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
private ProjectTask getProjectTask(Integer id) {
|
|
private ProjectTask getProjectTask(Integer id) {
|
|
|
return projectTaskMapper.selectByPrimaryKey(Long.valueOf(id));
|
|
return projectTaskMapper.selectByPrimaryKey(Long.valueOf(id));
|
|
|
}
|
|
}
|