Browse Source

填写日报时计算工作时长,优化休息时间的对比处理

seyason 2 years ago
parent
commit
438c6446af

+ 21 - 10
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/ReportController.java

@@ -123,7 +123,9 @@ public class ReportController {
             worktimeItemList.add(worktimeItem);
         }
         User user = userMapper.selectById(token);
+        //按当前填报人所属部门或者全公司来匹配
         List<TimeAutoExclude> excludeTimeList = timeAutoExcludeMapper.selectList(new QueryWrapper<TimeAutoExclude>().eq("company_id", user.getCompanyId()));
+        excludeTimeList = excludeTimeList.stream().filter(ex->ex.getDId() == null || ex.getDId().equals(user.getDepartmentId())).collect(Collectors.toList());
 
         int totalMinutes = 0;
         for (WorktimeItem worktimeItem : worktimeItemList) {
@@ -161,7 +163,7 @@ public class ReportController {
             totalMinutes += minutes;
         }
         double hours = totalMinutes*1.0f/60;
-        DecimalFormat df = new DecimalFormat("0.00");
+        DecimalFormat df = new DecimalFormat("0.0");
         msg.data = df.format(hours);
         return msg;
     }
@@ -571,7 +573,10 @@ public class ReportController {
             List<TimeAutoExclude> excludeTimeList = new ArrayList<>();
             //按照时间段填报的模式下,检查是否设置了休息时间段,要自动剔除
             if (comTimeType.getType() == 2) {
-                excludeTimeList = timeAutoExcludeMapper.selectList(new QueryWrapper<TimeAutoExclude>().eq("company_id", company.getId()));
+                excludeTimeList = timeAutoExcludeMapper.selectList(new QueryWrapper<TimeAutoExclude>().eq("company_id", user.getCompanyId()));
+                //按当前填报人所属部门或者全公司来匹配
+                excludeTimeList = excludeTimeList.stream().filter(ex->ex.getDId() == null || ex.getDId().equals(user.getDepartmentId())).collect(Collectors.toList());
+
             }
 
             for (int i = 0; i < id.length; i++) {
@@ -1834,7 +1839,8 @@ public class ReportController {
             TimeType allDay = timeTypeMapper.selectOne(new QueryWrapper<TimeType>().eq("company_id", compId));
             List<User> allUserList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", compId));
             //获取休息设置
-            TimeAutoExclude timeAutoExclude = timeAutoExcludeMapper.selectOne(new QueryWrapper<TimeAutoExclude>().eq("company_id", compId));
+            List<TimeAutoExclude> excludeTimeList = timeAutoExcludeMapper.selectList(new QueryWrapper<TimeAutoExclude>().eq("company_id", compId));
+
             //Todo: 获取考勤打卡数据
             HttpRespMsg workDataMsg = dockWithMLD.getResult("http://10.1.10.51:20175/api/cube/restful/interface/getModeDataPageList/getWorkData", jsonString);
             List<Map<String,Object>> workDataList= (List<Map<String, Object>>) workDataMsg.data;
@@ -1848,6 +1854,9 @@ public class ReportController {
             List<User> userList = userMapper.selectList(new QueryWrapper<User>().in("job_number", userIds));
             List<LocalDateTime> dateTimeList = getDays(yesterday, yesterday.plusDays(2));
             for (User user : userList) {
+                //按当前填报人所属部门或者全公司来匹配
+                excludeTimeList = excludeTimeList.stream().filter(ex->ex.getDId() == null || ex.getDId().equals(user.getDepartmentId())).collect(Collectors.toList());
+
                 for (LocalDateTime localDateTime : dateTimeList) {
                     LocalDate workDate=localDateTime.toLocalDate();
                     //当天的考勤记录
@@ -1894,14 +1903,16 @@ public class ReportController {
                         userFvTime.setCompanyId(user.getCompanyId());
                         userFvTime.setUserId(user.getId());
                         long workHours = between.toHours();
-                        long restHours;
-                        if(startTime.isBefore(LocalTime.parse(timeAutoExclude.getStartTime(),dtf2))
-                                &&endTime.isAfter(LocalTime.parse(timeAutoExclude.getEndTime(),dtf2))){
-                            Duration bt = Duration.between(LocalTime.parse(timeAutoExclude.getStartTime(),dtf2), LocalTime.parse(timeAutoExclude.getEndTime(),dtf2));
-                            restHours=bt.toHours();
-                        }else {
-                            restHours=0;
+                        long restHours = 0;
+                        //处理排除时间段
+                        for (TimeAutoExclude timeAutoExclude : excludeTimeList) {
+                            if(startTime.isBefore(LocalTime.parse(timeAutoExclude.getStartTime(),dtf2))
+                                    &&endTime.isAfter(LocalTime.parse(timeAutoExclude.getEndTime(),dtf2))){
+                                Duration bt = Duration.between(LocalTime.parse(timeAutoExclude.getStartTime(),dtf2), LocalTime.parse(timeAutoExclude.getEndTime(),dtf2));
+                                restHours += bt.toHours();
+                            }
                         }
+
                         userFvTime.setWorkHours(BigDecimal.valueOf(workHours).subtract(BigDecimal.valueOf(restHours)).floatValue());
                         Optional<UserFvTime> first = oldUserFvTimeList.stream().filter(ol -> ol.getWorkDate().isEqual(userFvTime.getWorkDate()) && ol.getUserId().equals(userFvTime.getUserId())).findFirst();
                         if(first.isPresent()){