fuxubing hace 3 años
padre
commit
fb79bda1a3

+ 16 - 4
jz-crm-core/src/main/java/org/linlinjava/jz/core/util/DateTimeUtil.java

@@ -7,6 +7,7 @@ import java.time.format.DateTimeFormatter;
 import java.time.temporal.ChronoUnit;
 import java.time.temporal.TemporalAdjusters;
 import java.util.*;
+import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
 /**
@@ -18,6 +19,8 @@ public class DateTimeUtil {
 
     public static String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
 
+    public static String DATE_MONTH = "yyyy-MM";
+
     public static LocalDateTime strToLocalDateTime(String str) {
         DateTimeFormatter fmt = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT);
         return LocalDateTime.parse(str, fmt);
@@ -28,7 +31,6 @@ public class DateTimeUtil {
         return LocalDate.parse(str, fmt);
     }
 
-
     /**
      * 获取当前月的天数
      *
@@ -204,13 +206,23 @@ public class DateTimeUtil {
         return retStr;
     }
 
+
+    public static List<LocalDate> getBetweenDays(LocalDate startDate, LocalDate endDate) {
+        long numOfDays = ChronoUnit.DAYS.between(startDate, endDate);
+
+        return Stream.iterate(startDate, date -> date.plusDays(1))
+                .limit(numOfDays)
+                .collect(Collectors.toList());
+    }
+
     public static void main(String[] args) throws Exception {
-//        LocalDate startDate = LocalDate.of(2020, Month.JANUARY, 1);
-//        LocalDate endDate = LocalDate.of(2021, Month.MARCH, 4);
+        LocalDate startDate = LocalDate.of(2021, Month.MARCH, 1);
+        LocalDate endDate = LocalDate.of(2021, Month.MARCH, 4);
         //System.out.println(localDateFormat(LocalDateTime.now(), "yyyy-MM"));
         //System.out.println(formatToyyyy_MM_dd(LocalDateTime.now()));
 
-        System.out.println(LocalDate.now().plusDays(-1).atStartOfDay());
+        System.out.println(getBetweenDays(startDate, endDate));
     }
 
+
 }

+ 21 - 5
jz-crm-hm-api/src/main/java/org/linlinjava/jz/hm/web/employer/EmployerHomeController.java

@@ -109,16 +109,32 @@ public class EmployerHomeController {
         });
 
         Map<String, Object> map = new HashMap<>(16);
+        int needClockTimes;
         // 获取当月天数
-        List<String> days = CalendarUtil.getDayListOfMonth(calendarDto.getCurrentMonth());
+        List<String> days = CalendarUtil.getDayListOfMonth(date);
+        LocalDate startDate = relation.getFirstServiceTime().toLocalDate();
+        LocalDate endDate = DateTimeUtil.strToLocalDate(date + "-01");
+        if (startDate.isAfter(endDate)) {
+            LocalDate lastDayOfMonth = DateTimeUtil.lastDayOfMonth(endDate);
+            List<LocalDate> betweenDays = DateTimeUtil.getBetweenDays(startDate, lastDayOfMonth);
+            betweenDays.add(lastDayOfMonth);
+            needClockTimes = betweenDays.size();
+            for (String s : restDayArr) {
+                if (betweenDays.contains(DateTimeUtil.strToLocalDate(s))) {
+                    needClockTimes--;
+                }
+            }
+        } else {
+            needClockTimes = days.size() - restDayArr.length;
+        }
         //需打卡次数
-        map.put("needClockTimes", days.size() - restDayArr.length);
+        map.put("needClockTimes", needClockTimes);
         //已打卡次数
-        map.put("alreadyTimes", hmEmployClockService.queryByState(employRelationId, HmEmployClockEnum.STATUS_2.getType()));
+        map.put("alreadyTimes", hmEmployClockService.queryByStateAndDate(employRelationId, HmEmployClockEnum.STATUS_2.getType(), date));
         //请假
-        map.put("leaveTimes", hmEmployClockService.queryByState(employRelationId, HmEmployClockEnum.STATUS_4.getType()));
+        map.put("leaveTimes", hmEmployClockService.queryByStateAndDate(employRelationId, HmEmployClockEnum.STATUS_4.getType(), date));
         //缺勤
-        map.put("offWorkTimes", hmEmployClockService.queryByState(employRelationId, HmEmployClockEnum.STATUS_5.getType()));
+        map.put("offWorkTimes", hmEmployClockService.queryByStateAndDate(employRelationId, HmEmployClockEnum.STATUS_5.getType(), date));
         //打卡日历
         map.put("calendar", calendarDto);
         //薪资计算

+ 23 - 5
jz-crm-hm-api/src/main/java/org/linlinjava/jz/hm/web/servant/HmServantInfoController.java

@@ -212,16 +212,34 @@ public class HmServantInfoController {
         });
 
         Map<String, Object> map = new HashMap<>(16);
+
+        int needClockTimes;
         // 获取当月天数
-        List<String> days = CalendarUtil.getDayListOfMonth(calendarDto.getCurrentMonth());
+        List<String> days = CalendarUtil.getDayListOfMonth(date);
+        LocalDate startDate = relation.getFirstServiceTime().toLocalDate();
+        LocalDate endDate = DateTimeUtil.strToLocalDate(date + "-01");
+        if (startDate.isAfter(endDate)) {
+            LocalDate lastDayOfMonth = DateTimeUtil.lastDayOfMonth(endDate);
+            List<LocalDate> betweenDays = DateTimeUtil.getBetweenDays(startDate, lastDayOfMonth);
+            betweenDays.add(lastDayOfMonth);
+            needClockTimes = betweenDays.size();
+            for (String s : restDayArr) {
+                if (betweenDays.contains(DateTimeUtil.strToLocalDate(s))) {
+                    needClockTimes--;
+                }
+            }
+        } else {
+            needClockTimes = days.size() - restDayArr.length;
+        }
+
         //需打卡次数
-        map.put("needClockTimes", days.size() - restDayArr.length);
+        map.put("needClockTimes", needClockTimes);
         //已打卡次数
-        map.put("alreadyTimes", hmEmployClockService.queryByState(employRelationId, 2));
+        map.put("alreadyTimes", hmEmployClockService.queryByStateAndDate(employRelationId, HmEmployClockEnum.STATUS_2.getType(), date));
         //请假
-        map.put("leaveTimes", hmEmployClockService.queryByState(employRelationId, 4));
+        map.put("leaveTimes", hmEmployClockService.queryByStateAndDate(employRelationId, HmEmployClockEnum.STATUS_4.getType(), date));
         //缺勤
-        map.put("offWorkTimes", hmEmployClockService.queryByState(employRelationId, 5));
+        map.put("offWorkTimes", hmEmployClockService.queryByStateAndDate(employRelationId, HmEmployClockEnum.STATUS_5.getType(), date));
         //打卡日历
         map.put("calendar", calendarDto);
         return HmResponseUtil.ok(map);

+ 10 - 0
jz-crm-service/src/main/java/org/linlinjava/jz/service/HmEmployClockService.java

@@ -2,6 +2,7 @@ package org.linlinjava.jz.service;
 
 import com.github.pagehelper.PageHelper;
 import com.google.common.collect.Lists;
+import org.linlinjava.jz.core.util.DateTimeUtil;
 import org.linlinjava.jz.db.dao.HmEmployClockMapper;
 import org.linlinjava.jz.db.dao.HmEmployTaskMapper;
 import org.linlinjava.jz.db.domain.*;
@@ -390,4 +391,13 @@ public class HmEmployClockService {
 
         return hmEmployClockMapper.updateByExampleSelective(hmEmployClock, example);
     }
+
+    public HmEmployClock queryByStateAndDate(Long employRelationId, int state, String date) {
+        LocalDate localDate = DateTimeUtil.strToLocalDate(date + "-01");
+        LocalDate firstDayOfMonth = DateTimeUtil.firstDayOfMonth(localDate);
+        LocalDate lastDayOfMonth = DateTimeUtil.lastDayOfMonth(localDate);
+        HmEmployClockExample example = new HmEmployClockExample();
+        example.or().andEmployRelationIdEqualTo(employRelationId).andWorkDataBetween(firstDayOfMonth.atStartOfDay(),lastDayOfMonth.atStartOfDay()).andStatusEqualTo(state);
+        return hmEmployClockMapper.selectOneByExample(example);
+    }
 }