Browse Source

值班人员,统计逻辑修改

yangyue 1 year ago
parent
commit
0e73c786a3

+ 1 - 1
duty-service/src/main/java/cn/com/taiji/duty/controller/DutyWorkbenchController.java

@@ -61,7 +61,7 @@ public class DutyWorkbenchController {
         Date date = sdf.parse(time);
         DutySignInRecordVo vo = new DutySignInRecordVo();
         vo.setDeptId(deptId);
-        vo.setTime(date);
+        vo.setSignTime(time);
         List<DutySignInRecord> list = signInRecordService.queryCheckDayList(vo);
         DutyDailyReportRecord dailyReportRecord = dailyReportRecordService.queryByDeptIdAndTime(deptId, date);
         DutyWeekReportRecord weekReportRecord = weekReportRecordService.queryByDeptIdAndTime(deptId, date);

+ 1 - 1
duty-service/src/main/java/cn/com/taiji/duty/mapper/DutySignInRecordMapper.java

@@ -28,7 +28,7 @@ public interface DutySignInRecordMapper extends BaseMapper<DutySignInRecord> {
 
     DutySignInRecord queryByAccountId(@Param("deptId") Long deptId, @Param("type") Integer type, @Param("time") Date time);
 
-    long queryDaysCount(@Param("deptId") Long deptId, @Param("startTime") String startTime, @Param("endTime") String endTime);
+    long queryDaysCount(@Param("status") String status, @Param("deptId") Long deptId, @Param("startTime") String startTime, @Param("endTime") String endTime);
 
     long queryStatusCount(@Param("deptId") Long deptId, @Param("status") String status, @Param("startTime") String startTime, @Param("endTime") String endTime);
 

+ 4 - 0
duty-service/src/main/java/cn/com/taiji/duty/model/DutySignInRecordVo.java

@@ -81,6 +81,10 @@ public class DutySignInRecordVo implements Serializable {
 	@JSONField(format = "yyyy-MM-dd HH:mm:ss")
 	private Date endTime;
 
+	/** 考勤时间 */
+	@ApiModelProperty("考勤时间")
+	private String signTime;
+
 	/** 考勤开始时间 */
 	@ApiModelProperty("考勤开始时间")
 	private String beginSignTime;

+ 62 - 21
duty-service/src/main/java/cn/com/taiji/duty/service/impl/DutyWorkbenchServiceImpl.java

@@ -12,8 +12,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.time.DayOfWeek;
-import java.time.LocalDate;
+import java.time.*;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.ChronoField;
 import java.time.temporal.ChronoUnit;
@@ -64,31 +63,41 @@ public class DutyWorkbenchServiceImpl implements IDutyWorkbenchService {
     public CheckWeek queryCheckWeekCount(Long deptId, String startTime, String endTime) {
         LocalDate sTime = LocalDate.parse(startTime);
         LocalDate eTime = LocalDate.parse(endTime);
-        long daysBetween = ChronoUnit.DAYS.between(sTime, eTime);
-        long total = daysBetween + 1;
-        CheckWeek checkWeek = new CheckWeek();
-        long count = signInRecordMapper.queryDaysCount(deptId, startTime, endTime);
-        checkWeek.setDays(count);
-        checkWeek.setDelDays(total-count);
-        if (count == 0) {
-            checkWeek.setLateDays(0L);
-            checkWeek.setEarlyDays(0L);
-            checkWeek.setLackDays(2*total);
+        LocalDate now = LocalDate.now();
+        long daysBetween;
+        long until;
+        if (eTime.isAfter(now)) {
+            daysBetween = ChronoUnit.DAYS.between(sTime, now);
+            until = getWeekInTimes(sTime, now, 5).size();
         } else {
-            long normal = signInRecordMapper.queryStatusCount(deptId, "1", startTime, endTime);
-            long lateDays = signInRecordMapper.queryStatusCount(deptId, "2", startTime, endTime);
-            long earlyDays = signInRecordMapper.queryStatusCount(deptId, "3", startTime, endTime);
-            checkWeek.setLateDays(lateDays);
-            checkWeek.setEarlyDays(earlyDays);
-            checkWeek.setLackDays(2*total-normal-lateDays-earlyDays);
+            daysBetween = ChronoUnit.DAYS.between(sTime, eTime);
+            until = getWeekInTimes(sTime, eTime, 5).size();
         }
+        long total = daysBetween + 1;
+        CheckWeek checkWeek = new CheckWeek();
+        // 出勤天数
+        long days = signInRecordMapper.queryDaysCount("1", deptId, startTime, endTime);
+        // 缺勤天数
+        long delDays = signInRecordMapper.queryDaysCount("4", deptId, startTime, endTime);
+        checkWeek.setDays(days);
+        checkWeek.setDelDays(delDays);
+        // 迟到
+        long lateDays = signInRecordMapper.queryStatusCount(deptId, "2", startTime, endTime);
+        // 早退
+        long earlyDays = signInRecordMapper.queryStatusCount(deptId, "3", startTime, endTime);
+        // 缺卡
+        long lackDays = signInRecordMapper.queryStatusCount(deptId, "4", startTime, endTime);
+        checkWeek.setLateDays(lateDays);
+        checkWeek.setEarlyDays(earlyDays);
+        checkWeek.setLackDays(lackDays);
+
         long logCount = reportRecordMapper.querylogCount(deptId, startTime, endTime);
         long weekCount = weekReportRecordMapper.queryWeekCount(deptId, startTime, endTime);
         checkWeek.setDailySubmit(logCount);
         checkWeek.setDailyNotSubmit(total-logCount);
-        long until = sTime.until(eTime, ChronoUnit.WEEKS);
-        checkWeek.setWeekSubmit(logCount);
-        checkWeek.setWeekNotSubmit(until-logCount);
+        // long until = sTime.until(eTime, ChronoUnit.WEEKS);
+        checkWeek.setWeekSubmit(weekCount);
+        checkWeek.setWeekNotSubmit(until-weekCount);
         return checkWeek;
     }
 
@@ -446,4 +455,36 @@ public class DutyWorkbenchServiceImpl implements IDutyWorkbenchService {
         }
         return months;
     }
+
+    /**
+     * 获取指定时间内星期几的所有日期
+     * @Author liuwenxu.com (2020-04-26)
+     *
+     * @param start 开始日期 2020-04-01
+     * @param end   截止日期 2020-05-01
+     * @param week  星期几 1
+     * @return ArrayList<LocalDate> [2020-04-06, 2020-04-13, 2020-04-20, 2020-04-27]
+     */
+    public static List<LocalDate> getWeekInTimes(LocalDate start, LocalDate end, int week) {
+        ArrayList<LocalDate> list = new ArrayList<>();
+
+        long days = ChronoUnit.DAYS.between(start, end) + 1;
+        log.info("[{}~{})之间共有:{}天", start, end, days);
+
+        Calendar startCalender = GregorianCalendar.from(start.atStartOfDay(ZoneId.systemDefault()));
+        for (int i = 0; i <= days - 1; i++) {
+            // 1代表周日,7代表周六
+            if (startCalender.get(Calendar.DAY_OF_WEEK) == week + 1) {
+                list.add(
+                        LocalDateTime.ofInstant(
+                                startCalender.toInstant(),
+                                ZoneOffset.systemDefault()
+                        ).toLocalDate()
+                );
+            }
+            startCalender.add(Calendar.DATE, 1);
+        }
+        log.info("[{}~{})之间共有:{}个 星期{}", start, end, list.size(), week);
+        return list;
+    }
 }

+ 14 - 6
duty-service/src/main/resources/mapper/DutySignInRecordMapper.xml

@@ -67,6 +67,9 @@
                 <if test="vo.time != null">
                     and date_format(time, '%Y-%m-%d') = date_format(#{vo.time}, '%Y-%m-%d')
                 </if>
+                <if test="vo.signTime != null">
+                    and date_format(sign_time, '%Y-%m-%d') = date_format(#{vo.signTime}, '%Y-%m-%d')
+                </if>
                 <if test="vo.ids != null and vo.ids.size() != 0">
                     and id in
                     <foreach collection="vo.ids" open="(" separator="," close=")" item="item">
@@ -99,19 +102,24 @@
     <select id="queryDaysCount" resultType="java.lang.Long">
         SELECT count(*)
         from (
-            SELECT *
+            SELECT count(*) as num
             FROM duty_sign_in_record
-            WHERE dept_id = #{deptId}
+            WHERE `status` = #{status} and dept_id = #{deptId}
               AND date_format(sign_time, '%Y-%m-%d' ) BETWEEN date_format(#{startTime}, '%Y-%m-%d' ) AND date_format(#{endTime}, '%Y-%m-%d' )
             GROUP BY date_format(sign_time, '%Y-%m-%d')
+            HAVING num = 2
             ) t
     </select>
     <select id="queryStatusCount" resultType="java.lang.Long">
         SELECT count(*)
-        FROM duty_sign_in_record
-        WHERE dept_id = #{deptId}
-          AND `status` = #{status}
-          AND date_format(sign_time, '%Y-%m-%d') BETWEEN date_format(#{startTime}, '%Y-%m-%d') AND date_format(#{endTime}, '%Y-%m-%d')
+        from (
+                 SELECT count(*) as num
+                 FROM duty_sign_in_record
+                 WHERE `status` = #{status} and dept_id = #{deptId}
+                   AND date_format(sign_time, '%Y-%m-%d' ) BETWEEN date_format(#{startTime}, '%Y-%m-%d' ) AND date_format(#{endTime}, '%Y-%m-%d' )
+                 GROUP BY date_format(sign_time, '%Y-%m-%d')
+                 HAVING num = 1
+             ) t
     </select>
     <select id="queryDaysSignInRecord" resultType="DutySignInRecord">
         select date_format(time, '%Y-%m-%d') as time, type, status