浏览代码

新增新版系统联通月份数据统计

anderx 6 月之前
父节点
当前提交
fa3f3df1c5

+ 18 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/project/ProjectTaskController.java

@@ -463,6 +463,24 @@ public class ProjectTaskController extends BaseController {
     }
 
 
+    /**
+     * 新项目月份打卡数据 模拟设置最长工时为8
+     * @param id 项目编号
+     * @param yearMonth  年月份
+     * @return 数据
+     */
+    @GetMapping("/getNewMonthClock")
+    public AjaxResult getNewMonthClock(@RequestParam("id") Integer id,@RequestParam("yearMonth") String yearMonth,@RequestParam("duration") String duration){
+        if (id==null){
+            return AjaxResult.error("项目编号不能为空");
+        }
+        if (yearMonth==null){
+            return AjaxResult.error("年月日期不能为空");
+        }
+        return AjaxResult.success(projectStaffRecordService.getNewMonthClock(id,yearMonth,duration));
+    }
+
+
 
 
     /**

+ 3 - 0
ruoyi-system/src/main/java/com/ruoyi/project/service/ProjectStaffRecordService.java

@@ -10,6 +10,7 @@ import com.ruoyi.project.domain.ProjectStaffRecord;
 import com.ruoyi.project.domain.ProjectStaffRecordLog;
 
 import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
 
@@ -52,4 +53,6 @@ public interface ProjectStaffRecordService {
     Object getAllProjectMonth();
 
     Object importClockData(List<Map<Integer,String >> list);
+
+    Object getNewMonthClock(Integer id, String yearMonth, String duration);
 }

+ 108 - 3
ruoyi-system/src/main/java/com/ruoyi/project/service/impl/ProjectStaffRecordServiceImpl.java

@@ -822,13 +822,13 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
 //        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, getDaysMap(lastDay, startDate), recordTime, listData);
+                pushDate(e, daysMap, recordTime, listData);
             }else {
                 boolean flag = false;
                 for (Map<String, Object> m : listData) {
@@ -855,7 +855,7 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
                     }
                 }
                 if (!flag){
-                    pushDate(e, getDaysMap(lastDay, startDate), recordTime, listData);
+                    pushDate(e, daysMap, recordTime, listData);
                 }
             }
         }
@@ -950,6 +950,13 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
         return list;
     }
 
+    /**
+     *
+     * @param e 打卡数据
+     * @param list 表头
+     * @param recordTime 打卡书剑
+     * @param listData
+     */
     private void pushDate(ProjectStaffRecord e, List<Map<String, Object>> list, LocalDate recordTime, List<Map<String, Object>> listData) {
         Map<String,Object> map = new LinkedHashMap<>();
         map.put("name", e.getName());
@@ -1020,6 +1027,104 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
         return failureMsg.toString();
     }
 
+    @Override
+    public Object getNewMonthClock(Integer id, String yearMonth,String duration) {
+        OutMontClockBo out = new OutMontClockBo();
+        ProjectTask projectTask = getProjectTask(id);
+        SysDept sysDept = deptService.selectDeptByPid(projectTask.getId());
+        out.setProjectName(projectTask.getName());
+        out.setDepartmentName(sysDept.getDeptName());
+        if (sysDept.getCompanyName()!=null){
+            out.setCompanyName(sysDept.getCompanyName());
+        }else {
+            out.setCompanyName(sysDept.getDeptName());
+        }
+        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;
+        }
+        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,duration);
+            }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 = new BigDecimal(duration);
+                                map2.put("projectDuration", added);
+                                map2.put("checkDuration", checkDuration);
+                                BigDecimal subtract = checkDuration.subtract(added);
+                                if (subtract.compareTo(BigDecimal.ZERO)==-1)subtract=BigDecimal.ZERO;
+                                map2.put("notDuration", subtract);
+                                break;
+                            }
+                        }
+                    }
+                }
+                if (!flag){
+                    pushDate(e, daysMap, recordTime, listData,duration);
+                }
+            }
+        }
+        //将数据统计,计算出所有工时与分摊率
+        pushDurationAndProportion(listData);
+        out.setList(listData);
+        return out;
+    }
+
+    private void pushDate(ProjectStaffRecord e, List<Map<String, Object>> daysMap, LocalDate recordTime, List<Map<String, Object>> listData, String duration) {
+        {
+            Map<String,Object> map = new LinkedHashMap<>();
+            map.put("name", e.getName());
+            //找出匹配的日期并设置时间
+            for (Map<String, Object> map2 : daysMap) {
+                Integer date = (Integer) map2.get("date");
+                if (recordTime.getDayOfMonth()==date) {
+                    BigDecimal projectDuration = BigDecimal.valueOf(e.getDuration());
+                    BigDecimal checkDuration = new BigDecimal(duration);
+                    map2.put("projectDuration", projectDuration);
+                    map2.put("checkDuration", checkDuration);
+                    BigDecimal subtract = checkDuration.subtract(projectDuration);
+                    if (subtract.compareTo(BigDecimal.ZERO)==-1)subtract=BigDecimal.ZERO;
+                    map2.put("notDuration", subtract);
+                    break;
+                }
+            }
+            map.put("data", new ArrayList<>(daysMap));
+            listData.add(map);
+        }
+    }
+
 
     public List<UserClockDataBo> clockDataToList(List<Map<Integer,String >> list) {
         List<UserClockDataBo> listData = new ArrayList<>();