From 1b2f1eb44d9f0de6b9238cfe314988a95c87344a Mon Sep 17 00:00:00 2001
From: zouyu <2723363702@qq.com>
Date: 星期四, 02 四月 2026 13:37:15 +0800
Subject: [PATCH] 绩效管理:工时汇总对接MES数据&人员考勤调整
---
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/StaffAttendanceTrackingRecordServiceImpl.java | 51 +++++++++++++++++++++++++++++++++++----------------
1 files changed, 35 insertions(+), 16 deletions(-)
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/StaffAttendanceTrackingRecordServiceImpl.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/StaffAttendanceTrackingRecordServiceImpl.java
index 104239e..27a6c78 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/StaffAttendanceTrackingRecordServiceImpl.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/StaffAttendanceTrackingRecordServiceImpl.java
@@ -19,6 +19,7 @@
import com.ruoyi.inspect.pojo.StaffAttendanceTrackingRecord;
import com.ruoyi.inspect.service.StaffAttendanceTrackingRecordService;
import com.ruoyi.inspect.util.HourDiffCalculator;
+import com.ruoyi.inspect.util.TimeDiffCalculator;
import com.ruoyi.inspect.vo.StaffAttendanceVO;
import com.ruoyi.inspect.vo.StaffClockInVO;
import com.ruoyi.performance.dto.PerformanceShiftMapDto;
@@ -36,6 +37,7 @@
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
@@ -89,6 +91,11 @@
private final static List<String> syncDeviceCode = Arrays.asList("1001538", "1001539", "1001540", "1001541",
"1001626", "1001627", "1001628", "1001629");
+ /**
+ * 涓婄彮鏃堕棿鍒ゅ畾杈圭晫灏忔椂鏁�
+ */
+ private final static long WORK_TIME_BOUNDARY = 2L;
+
@Override
@Transactional(rollbackFor = Exception.class)
public boolean syncAttendanceRecord(LocalDateTime startDate, LocalDateTime endDate) {
@@ -139,9 +146,6 @@
public IPage<StaffAttendanceVO> pageAttendanceRecord(Page<StaffAttendanceTrackingRecord> page,
StaffAttendanceDTO staffAttendanceDTO) {
// 鏌ヨ鎵撳崱璁板綍
- System.out.println(staffAttendanceDTO.getStartDate());
- System.out.println(staffAttendanceDTO.getEndDate());
- System.out.println(ObjectUtils.allNotNull(staffAttendanceDTO.getStartDate(),staffAttendanceDTO.getEndDate()));
Wrapper<StaffAttendanceTrackingRecord> queryWrapper = Wrappers.<StaffAttendanceTrackingRecord>lambdaQuery()
.eq(StaffAttendanceTrackingRecord::getEnableReport, Boolean.TRUE)
.between(ObjectUtils.allNotNull(staffAttendanceDTO.getStartDate(),staffAttendanceDTO.getEndDate()),
@@ -170,6 +174,8 @@
* 姝e父锛氬綋鍓嶇彮娆$粨鏉熷悗绗竴娆″嚭闂ㄦ椂闂�
* 寮傚父(鏃╅��)锛氭棤褰撳墠鐝缁撴潫鍒颁笅涓�鐝寮�濮嬪墠鐨勫嚭闂ㄨ褰曞苟涓旀渶鍚庝竴娆″嚭闂ㄥ湪褰撳墠鐝鏃堕棿鑼冨洿鍐咃紝鍙栧綋鍓嶇彮娆℃渶鍚庝竴娆″嚭闂ㄦ椂闂�
*/
+ //褰撳墠鏃堕棿
+ LocalDateTime now = LocalDateTime.now(ZoneId.of("Asia/Shanghai"));
// 褰撳墠鐝寮�濮嬪ぉ0鐐规椂闂�
LocalDateTime startDateTime = LocalDateTime.of(p.getWorkTime().toLocalDate(), LocalTime.MIN);
// 褰撳墠鐝缁撴潫澶�24鐐规椂闂�
@@ -178,10 +184,6 @@
LocalTime currentShiftStartTime = LocalTime.parse(p.getStartTime(), HHmm);
LocalDateTime currentShiftStartDateTime = LocalDateTime.of(p.getWorkTime().toLocalDate(),
currentShiftStartTime);
- // 褰撳墠鐝缁撴潫鏃堕棿
- LocalTime currentShiftEndTime = LocalTime.parse(p.getEndTime(), HHmm);
- LocalDateTime currentShiftEndDateTime = LocalDateTime.of(endDateTime.toLocalDate(),
- currentShiftEndTime);
// 涓嬩竴鐝寮�濮嬫椂闂�
LocalDateTime nextShiftStartDateTime = getShiftStartDateTime(i + 1, performanceShifts,
startDateTime.plusDays(1L));
@@ -189,15 +191,21 @@
// 濡傛灉灏忔椂宸负璐熸暟锛岃〃绀鸿法澶╋紝缁撴潫鏃堕棿闇�鍔犱竴
endDateTime = endDateTime.plusDays(1L);
}
+ // 褰撳墠鐝缁撴潫鏃堕棿
+ LocalTime currentShiftEndTime = LocalTime.parse(p.getEndTime(), HHmm);
+ LocalDateTime currentShiftEndDateTime = LocalDateTime.of(endDateTime.toLocalDate(),
+ currentShiftEndTime);
// 杩囨护鍑哄綋鍓嶄汉鍛樺綋鍓嶇彮娆$殑杩�/鍑鸿褰�
LocalDateTime workDateTime = null;
LocalDateTime offWorkDateTime = null;
List<StaffAttendanceTrackingRecord> enterRecords = filterAttendanceRecord(p.getPersonCode(),
EnterOrExitType.ENTER.getValue(), startDateTime, endDateTime, recordList);
+ //涓婄彮鏃堕棿鍒ゅ畾杈圭晫
+ LocalDateTime boundaryTime = currentShiftStartDateTime.minusHours(WORK_TIME_BOUNDARY);
if (!enterRecords.isEmpty()) {
// 涓婄彮鏃堕棿鍜岀姸鎬�
StaffAttendanceTrackingRecord enterRecord = enterRecords.stream()
- .filter(s -> !s.getSwingTime().isAfter(currentShiftStartDateTime))
+ .filter(s -> !s.getSwingTime().isAfter(currentShiftStartDateTime) && !s.getSwingTime().isBefore(boundaryTime))
.max(Comparator.comparing(StaffAttendanceTrackingRecord::getSwingTime))
.orElse(new StaffAttendanceTrackingRecord());
if (BeanUtil.isEmpty(enterRecord)) {
@@ -224,7 +232,7 @@
&& s.getSwingTime().isBefore(nextShiftStartDateTime))
.min(Comparator.comparing(StaffAttendanceTrackingRecord::getSwingTime))
.orElse(new StaffAttendanceTrackingRecord());
- if (BeanUtil.isEmpty(exitRecord)) {
+ if (BeanUtil.isEmpty(exitRecord) && !now.isBefore(currentShiftEndDateTime)) {
exitRecord = exitRecords.stream()
.filter(s -> (s.getSwingTime().isAfter(currentShiftStartDateTime)
&& s.getSwingTime().isBefore(currentShiftEndDateTime)))
@@ -241,14 +249,16 @@
}
if (ObjectUtils.allNotNull(workDateTime, offWorkDateTime)) {
- vo.setActualWorkHours(HourDiffCalculator.getHourDiff(workDateTime.toLocalTime().format(HHmm),
- offWorkDateTime.toLocalTime().format(HHmm)));
+ vo.setActualWorkHours(TimeDiffCalculator.getHourDiff(workDateTime,
+ offWorkDateTime));
}
// 璧嬪��
vo.setShiftId(p.getShift());
vo.setPersonCode(p.getPersonCode());
vo.setPersonName(p.getUserName());
- vo.setPlannedWorkHours(hourDiff);
+ //搴斿嫟鏃堕暱
+ double plannedWorkHours = Math.abs(hourDiff);
+ vo.setPlannedWorkHours(plannedWorkHours);
vo.setSwingDate(startDateTime);
vo.setWorkDateTime(workDateTime);
vo.setOffWorkDateTime(offWorkDateTime);
@@ -258,9 +268,13 @@
vo.setCreateTime(recordList.get(0).getCreateTime());
vo.setUpdateUser(recordList.get(0).getUpdateUser());
vo.setUpdateTime(recordList.get(0).getUpdateTime());
- vo.setResult(ClockInState.ABNORMAL.getValue());
- if(ObjectUtils.allNotNull(vo.getWorkClockInState(),vo.getOffClockInState())){
- vo.setResult(Integer.min(vo.getWorkClockInState(),vo.getOffClockInState()));
+ //褰撳墠鏃堕棿鍦ㄤ笅鐝椂闂磋繃鍚庢墠鍒ゆ柇鑰冨嫟缁撴灉
+ if(!now.isBefore(currentShiftEndDateTime)){
+ if(ObjectUtils.allNotNull(vo.getWorkClockInState(),vo.getOffClockInState())){
+ vo.setResult(Integer.min(vo.getWorkClockInState(),vo.getOffClockInState()));
+ }else{
+ vo.setResult(ClockInState.ABNORMAL.getValue());
+ }
}
// 璁$畻缂哄嫟鏃堕暱
if (ObjectUtils.allNotNull(vo.getActualWorkHours(), vo.getPlannedWorkHours())) {
@@ -373,7 +387,12 @@
long pages = getPages(size,total);
int startIndex = Math.toIntExact((current - 1) * size >= total ? (pages - 1) * size : (current - 1) * size);
int endIndex = Math.toIntExact(Math.min(current * size, total));
- List<StaffAttendanceVO> records = resultList.subList(startIndex, endIndex);
+ List<StaffAttendanceVO> records;
+ if(resultList.isEmpty()){
+ records = new ArrayList<>();
+ }else{
+ records = resultList.subList(startIndex, endIndex);
+ }
resultPage.setRecords(records);
resultPage.setTotal(total);
resultPage.setSize(size);
--
Gitblit v1.9.3