From bb078cde6d9641ec84ee3c52b544153845795c0e Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期一, 13 七月 2026 21:00:50 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_New_pro' into dev_pro_山西长治

---
 src/main/resources/mapper/staff/PersonalShiftMapper.xml |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/src/main/resources/mapper/staff/PersonalShiftMapper.xml b/src/main/resources/mapper/staff/PersonalShiftMapper.xml
index bd1e5fc..b912e24 100644
--- a/src/main/resources/mapper/staff/PersonalShiftMapper.xml
+++ b/src/main/resources/mapper/staff/PersonalShiftMapper.xml
@@ -18,6 +18,7 @@
         u.id user_id
         FROM personal_shift s
         LEFT JOIN staff_on_job u ON u.id = s.staff_on_job_id
+        LEFT JOIN staff_leave sl ON sl.staff_on_job_id = u.id
         LEFT JOIN personal_attendance_location_config palc ON palc.id = s.personal_attendance_location_config_id
         <where>
             u.id IS NOT NULL
@@ -26,6 +27,7 @@
             </if>
             <if test="time != null and time != ''">
                 and DATE_FORMAT(s.work_time, '%Y-%m') = DATE_FORMAT(#{time}, '%Y-%m')
+                AND (u.staff_state = 1 OR (u.staff_state = 0 AND sl.leave_date IS NOT NULL AND sl.leave_date >= DATE_FORMAT(#{time}, '%Y-%m-01')))
             </if>
             <if test="userName != null and userName != ''">
                 and u.staff_name like concat('%', #{userName}, '%')
@@ -44,10 +46,12 @@
         GROUP_CONCAT(DATE_FORMAT(s.work_time, '%c'), '锛�', IFNULL(palc.shift, '') order by s.work_time SEPARATOR ';') month_str
         FROM personal_shift s
         LEFT JOIN staff_on_job u ON u.id = s.staff_on_job_id
-         LEFT JOIN personal_attendance_location_config palc ON palc.id = s.personal_attendance_location_config_id
+        LEFT JOIN staff_leave sl ON sl.staff_on_job_id = u.id
+        LEFT JOIN personal_attendance_location_config palc ON palc.id = s.personal_attendance_location_config_id
          <where>
             <if test="time != null and time != ''">
                 and DATE_FORMAT(s.work_time, '%Y') = DATE_FORMAT(#{time}, '%Y' )
+                AND (u.staff_state = 1 OR (u.staff_state = 0 AND sl.leave_date IS NOT NULL AND sl.leave_date >= DATE_FORMAT(#{time}, '%Y-01-01')))
             </if>
             <if test="userName != null and userName != ''">
                 and u.staff_name like concat('%', #{userName}, '%')
@@ -67,10 +71,12 @@
         GROUP_CONCAT(DATE_FORMAT(s.work_time, '%c'), '锛�', IFNULL(palc.shift, '') order by s.work_time SEPARATOR ';') month_str
         FROM personal_shift s
         LEFT JOIN staff_on_job u ON u.id = s.staff_on_job_id
+        LEFT JOIN staff_leave sl ON sl.staff_on_job_id = u.id
         LEFT JOIN personal_attendance_location_config palc ON palc.id = s.personal_attendance_location_config_id
        <where>
         <if test="time != null and time != ''">
             and DATE_FORMAT(s.work_time, '%Y') = DATE_FORMAT(#{time}, '%Y' )
+            AND (u.staff_state = 1 OR (u.staff_state = 0 AND sl.leave_date IS NOT NULL AND sl.leave_date >= DATE_FORMAT(#{time}, '%Y-01-01')))
         </if>
         <if test="userName != null and userName != ''">
             and u.staff_name like concat('%', #{userName}, '%')
@@ -88,10 +94,12 @@
         GROUP_CONCAT(s.work_time, '锛�', IFNULL(palc.shift, ''), '锛�', s.id order by s.work_time SEPARATOR ';') AS shift_time, u.id user_id
         FROM personal_shift s
         LEFT JOIN staff_on_job u ON u.id = s.staff_on_job_id
+        LEFT JOIN staff_leave sl ON sl.staff_on_job_id = u.id
         LEFT JOIN personal_attendance_location_config palc ON palc.id = s.personal_attendance_location_config_id
         <where>
             <if test="time != null and time != ''">
                 and DATE_FORMAT(s.work_time, '%Y-%m') = DATE_FORMAT(#{time}, '%Y-%m' )
+                AND (u.staff_state = 1 OR (u.staff_state = 0 AND sl.leave_date IS NOT NULL AND sl.leave_date >= DATE_FORMAT(#{time}, '%Y-%m-01')))
             </if>
             <if test="userName != null and userName != ''">
                 and u.staff_name like concat('%', #{userName}, '%')
@@ -104,4 +112,15 @@
         order by s.create_time
     </select>
 
+    <select id="existsAttendanceUsedByConfig" resultType="boolean">
+        SELECT EXISTS (
+            SELECT 1
+            FROM personal_shift ps
+            INNER JOIN personal_attendance_records par
+                ON par.staff_on_job_id = ps.staff_on_job_id
+               AND par.date = DATE(ps.work_time)
+            WHERE ps.personal_attendance_location_config_id = #{configId}
+        )
+    </select>
+
 </mapper>

--
Gitblit v1.9.3