From 9a5d984a74d5f893fc51366b42391d9b4f8a83ed Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期四, 12 三月 2026 15:40:08 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_New' into dev_New

---
 src/main/java/com/ruoyi/staff/service/impl/PersonalAttendanceRecordsServiceImpl.java |   58 +++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 33 insertions(+), 25 deletions(-)

diff --git a/src/main/java/com/ruoyi/staff/service/impl/PersonalAttendanceRecordsServiceImpl.java b/src/main/java/com/ruoyi/staff/service/impl/PersonalAttendanceRecordsServiceImpl.java
index 10e32a2..9d5e688 100644
--- a/src/main/java/com/ruoyi/staff/service/impl/PersonalAttendanceRecordsServiceImpl.java
+++ b/src/main/java/com/ruoyi/staff/service/impl/PersonalAttendanceRecordsServiceImpl.java
@@ -1,5 +1,6 @@
 package com.ruoyi.staff.service.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -14,10 +15,12 @@
 import com.ruoyi.staff.dto.PersonalAttendanceRecordsDto;
 import com.ruoyi.staff.dto.StaffOnJobDto;
 import com.ruoyi.staff.mapper.PersonalAttendanceLocationConfigMapper;
+import com.ruoyi.staff.mapper.PersonalShiftMapper;
 import com.ruoyi.staff.mapper.StaffOnJobMapper;
 import com.ruoyi.staff.pojo.PersonalAttendanceLocationConfig;
 import com.ruoyi.staff.pojo.PersonalAttendanceRecords;
 import com.ruoyi.staff.mapper.PersonalAttendanceRecordsMapper;
+import com.ruoyi.staff.pojo.PersonalShift;
 import com.ruoyi.staff.pojo.StaffOnJob;
 import com.ruoyi.staff.service.PersonalAttendanceRecordsService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -63,6 +66,9 @@
     @Autowired
     private SysDeptMapper sysDeptMapper;
 
+    @Autowired
+    private PersonalShiftMapper personalShiftMapper;
+
     @Override
     public int add(PersonalAttendanceRecordsDto personalAttendanceRecordsDto) {
         // 褰撳墠鏃堕棿
@@ -71,24 +77,29 @@
         /*鏌ヨ鍛樺伐淇℃伅*/
         QueryWrapper<StaffOnJob> staffQueryWrapper = new QueryWrapper<>();
         staffQueryWrapper.eq("staff_no", SecurityUtils.getUsername());
+        staffQueryWrapper.eq("staff_state", 1);//鍦ㄨ亴
         StaffOnJob staffOnJob = staffOnJobMapper.selectOne(staffQueryWrapper);
         if (staffOnJob == null) {
             throw new BaseException("褰撳墠鐢ㄦ埛娌℃湁瀵瑰簲鐨勫憳宸ヤ俊鎭�");
         }
-        /*鍒ゆ柇鎵撳崱浣嶇疆鏄惁鍦ㄨ鍒欒寖鍥村唴*/
-        List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs = personalAttendanceLocationConfigMapper.selectList(Wrappers.<PersonalAttendanceLocationConfig>lambdaQuery()
-                .eq(PersonalAttendanceLocationConfig::getSysDeptId, staffOnJob.getSysDeptId())
-                .orderByDesc(PersonalAttendanceLocationConfig::getId));
-        if (personalAttendanceLocationConfigs == null || personalAttendanceLocationConfigs.isEmpty()) {
-            throw new BaseException("褰撳墠閮ㄩ棬娌℃湁璁剧疆鎵撳崱瑙勫垯");
+        //鍒ゆ柇鍒ゆ柇鍛樺伐褰撳ぉ鏄惁鏈夋帓鐝暟鎹�
+        List<PersonalShift> personalShifts = personalShiftMapper.selectList(Wrappers.<PersonalShift>lambdaQuery()
+                .eq(PersonalShift::getStaffOnJobId, staffOnJob.getId())
+                .eq(PersonalShift::getWorkTime, currentDate.atStartOfDay())
+                .isNotNull(PersonalShift::getPersonalAttendanceLocationConfigId));
+        if (CollectionUtil.isEmpty(personalShifts)){
+            throw new BaseException("褰撳墠鐢ㄦ埛褰撳ぉ娌℃湁鎺掔彮鏁版嵁");
         }
+        /*鍒ゆ柇鎵撳崱浣嶇疆鏄惁鍦ㄨ鍒欒寖鍥村唴*/
+        PersonalShift personalShift = personalShifts.get(0);
+
+        PersonalAttendanceLocationConfig locationConfig = personalAttendanceLocationConfigMapper.selectById(personalShift.getPersonalAttendanceLocationConfigId());
         Double punchLongitude = personalAttendanceRecordsDto.getLongitude(); //鎵撳崱鐨勭粡搴�
         Double punchLatitude = personalAttendanceRecordsDto.getLatitude(); // 鎵撳崱鐨勭含搴�
         if (punchLongitude == null || punchLatitude == null) {
             throw new BaseException("鎵撳崱澶辫触锛氭湭鑾峰彇鍒版偍鐨勪綅缃俊鎭紝璇峰紑鍚畾浣嶆潈闄�");
         }
         //璁$畻鎵撳崱浣嶇疆涓庤�冨嫟鐐圭殑璺濈
-        PersonalAttendanceLocationConfig locationConfig = personalAttendanceLocationConfigs.get(0);//鑾峰彇鏈�鏂扮殑涓�鏉℃暟鎹�
         double allowedRadius = locationConfig.getRadius(); // 鍏佽鐨勮寖鍥达紙绫筹級
         double actualDistance = LocationUtils.calculateDistance(
                 punchLatitude, punchLongitude, // 鍛樺伐鎵撳崱鐨勭粡绾害
@@ -99,23 +110,12 @@
             throw new BaseException(String.format("鎵撳崱澶辫触锛氭偍褰撳墠浣嶇疆璺濈鑰冨嫟鐐�%.2f绫筹紝瓒呭嚭鍏佽鑼冨洿锛�%s绫筹級", actualDistance, allowedRadius));
         }
         /*鍒ゆ柇鎵撳崱鏃堕棿*/
-        LocalTime   endAt = locationConfig.getEndAt(); //涓嬬彮鏃堕棿
-        // 鑾峰彇鑰冨嫟涓嬬彮鏃堕棿鐐�
-        int standardHour = endAt.getHour();
-        int standardMinute = endAt.getMinute();
-        // 褰撳墠鏃堕棿
-        int actualHour = currentDateTime.getHour();
-        int actualMinute = currentDateTime.getMinute();
-        // 鍒ゆ柇鎵撳崱鏃堕棿鏄惁鏅氫簬褰撳墠鏃堕棿
-        if (actualHour > standardHour || (actualHour == standardHour && actualMinute > standardMinute)) {
-            throw new BaseException(String.format("鎵撳崱澶辫触锛氭墦鍗℃椂闂翠笉鑳芥櫄浜庝笅鐝椂闂达紙%02d:%02d锛�", standardHour, standardMinute));
-        }
         // 鏍规嵁鍛樺伐ID鍜屽綋鍓嶆棩鏈熸煡璇㈡墦鍗¤褰�
         QueryWrapper<PersonalAttendanceRecords> attendanceQueryWrapper = new QueryWrapper<>();
         attendanceQueryWrapper.eq("staff_on_job_id", staffOnJob.getId())
                 .eq("date", currentDate);
         PersonalAttendanceRecords attendanceRecord = personalAttendanceRecordsMapper.selectOne(attendanceQueryWrapper);
-        // 鏍规嵁瀛楀吀璁剧疆鐨勮�冨嫟鏃堕棿鍒ゆ柇杩熷埌鏃╅��
+        // 鏍规嵁鑰冨嫟鏃堕棿鍒ゆ柇杩熷埌鏃╅��
         if (attendanceRecord == null) {
             // 涓嶅瓨鍦ㄦ墦鍗¤褰曪紝鍒涘缓鏂拌褰�
             PersonalAttendanceRecords personalAttendanceRecords = new PersonalAttendanceRecords();
@@ -176,6 +176,8 @@
                         return 3; // 杩熷埌鏃╅��
                     }
                     return 2; // 鏃╅��
+                }else if (attendanceRecord.getStatus() == 1) {
+                    return 1; // 涓嬬彮鎵撳崱姝e父浣嗘槸涓婄彮杩熷埌
                 }
             }
             return 0; // 姝e父
@@ -192,6 +194,7 @@
         if (!admin) {
             QueryWrapper<StaffOnJob> staffQueryWrapper = new QueryWrapper<>();
             staffQueryWrapper.eq("staff_no", SecurityUtils.getUsername());
+            staffQueryWrapper.eq("staff_state", 1);//鍦ㄨ亴
             StaffOnJob staffOnJob = staffOnJobMapper.selectOne(staffQueryWrapper);
             if (staffOnJob == null) {
                 return new Page<>(page.getCurrent(), page.getSize(), 0);
@@ -210,6 +213,7 @@
         // 棣栧厛鏍规嵁鐢ㄦ埛ID鏌ヨ鍛樺伐淇℃伅
         QueryWrapper<StaffOnJob> staffQueryWrapper = new QueryWrapper<>();
         staffQueryWrapper.eq("staff_no", SecurityUtils.getUsername());
+        staffQueryWrapper.eq("staff_state", 1);//鍦ㄨ亴
         StaffOnJob staffOnJob = staffOnJobMapper.selectOne(staffQueryWrapper);
 
         if (staffOnJob == null) {
@@ -237,12 +241,15 @@
         SysDept dept = sysDeptMapper.selectDeptById(staffOnJob.getSysDeptId());
         resultDto.setDeptName(dept != null ? dept.getDeptName() : null);
         //鑾峰彇璇ュ憳宸ュ搴旂殑鎵撳崱瑙勫垯
-        List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs = personalAttendanceLocationConfigMapper.selectList(Wrappers.<PersonalAttendanceLocationConfig>lambdaQuery()
-                .eq(PersonalAttendanceLocationConfig::getSysDeptId, staffOnJob.getSysDeptId())
-                .orderByDesc(PersonalAttendanceLocationConfig::getId));
-        if (personalAttendanceLocationConfigs.size()>0){
-            resultDto.setStartAt(personalAttendanceLocationConfigs.get(0).getStartAt());
-            resultDto.setEndAt(personalAttendanceLocationConfigs.get(0).getEndAt());
+        List<PersonalShift> personalShifts = personalShiftMapper.selectList(Wrappers.<PersonalShift>lambdaQuery()
+                .eq(PersonalShift::getStaffOnJobId, staffOnJob.getId())
+                .eq(PersonalShift::getWorkTime, currentDate.atStartOfDay())
+                .isNotNull(PersonalShift::getPersonalAttendanceLocationConfigId));
+        if (CollectionUtil.isNotEmpty(personalShifts)){
+            PersonalAttendanceLocationConfig personalAttendanceLocationConfig = personalAttendanceLocationConfigMapper.selectById(personalShifts.get(0).getPersonalAttendanceLocationConfigId());
+            resultDto.setStartAt(personalAttendanceLocationConfig.getStartAt());
+            resultDto.setEndAt(personalAttendanceLocationConfig.getEndAt());
+            resultDto.setShift(personalAttendanceLocationConfig.getShift());
         }
         return resultDto;
     }
@@ -253,6 +260,7 @@
         if (!admin) {
             QueryWrapper<StaffOnJob> staffQueryWrapper = new QueryWrapper<>();
             staffQueryWrapper.eq("staff_no", SecurityUtils.getUsername());
+            staffQueryWrapper.eq("staff_state", 1);//鍦ㄨ亴
             StaffOnJob staffOnJob = staffOnJobMapper.selectOne(staffQueryWrapper);
             if (staffOnJob == null) {
                 throw new ServiceException("娌℃湁鍛樺伐淇℃伅锛屾棤娉曞鍑鸿�冨嫟璁板綍");

--
Gitblit v1.9.3