Commit 9c74b043 by 张富康

fix(attendance): 优化考勤迟到早退逻辑及打卡时间判断

- 新增迟到和早退标识及分钟数变量,用以精确计算迟到早退工时
- 调整打卡时间范围判定,使用最早打卡时间EARLIEST_CLOCK_IN_TIME作为下限
- 增加下班打卡地址位置距离判断,确保位置距离商户地址100米内才算有效打卡
- 迟到早退时间段计算工时,半小时内算0.5小时,超过按分钟向上取整换算小时数
- 修正缺卡条件,提前打卡算缺卡,迟到或早退分别记录时间并计算出勤工时
- DistanceTest工具类增加调试输出,打印计算距离结果方便排查
1 parent 19ca08f4
...@@ -134,6 +134,14 @@ public class AttendanceDataCleansingService { ...@@ -134,6 +134,14 @@ public class AttendanceDataCleansingService {
int normalClockOutCount = 0; int normalClockOutCount = 0;
for (StaffQwClockInInfo item : staffQwClockInInfosItem) { for (StaffQwClockInInfo item : staffQwClockInInfosItem) {
// 判断上班打卡时间不为空 // 判断上班打卡时间不为空
// 判断是否迟到 boolean
boolean isLate = false;
// 迟到分钟数
Long lateMinutes = 0L;
// 判断是否早退
boolean isEarly = false;
// 早退分钟数
Long earlyMinutes = 0L;
if (ObjectUtil.isNotEmpty(item.getClockInTimeStart())) { if (ObjectUtil.isNotEmpty(item.getClockInTimeStart())) {
// 上班打卡经纬度不为空 去上班时间打卡经纬度找到考勤配置 // 上班打卡经纬度不为空 去上班时间打卡经纬度找到考勤配置
if (StrUtil.isNotBlank(item.getClockInAddrLng()) && StrUtil.isNotBlank(item.getClockInAddrLat())) { if (StrUtil.isNotBlank(item.getClockInAddrLng()) && StrUtil.isNotBlank(item.getClockInAddrLat())) {
...@@ -141,15 +149,72 @@ public class AttendanceDataCleansingService { ...@@ -141,15 +149,72 @@ public class AttendanceDataCleansingService {
// 如果不为空,则使用商户考勤打卡时间处理 // 如果不为空,则使用商户考勤打卡时间处理
if (ObjectUtil.isNotEmpty(nearestMerchant)) { if (ObjectUtil.isNotEmpty(nearestMerchant)) {
// 判断打卡时间是否在打卡时间范围内 // 判断打卡时间是否在打卡时间范围内
JudgeResult reasonForRange = TimeRangeChecker.getReasonForNotInRange(item.getClockInTimeStart(), nearestMerchant.getWorkStartTime(), nearestMerchant.getWorkEndTime(), 1); JudgeResult reasonForRange = TimeRangeChecker.getReasonForNotInRange(item.getClockInTimeStart(), EARLIEST_CLOCK_IN_TIME, nearestMerchant.getWorkStartTime(), 1);
if (reasonForRange.getInRangeType() == 1) { if (reasonForRange.getInRangeType() == 1) {
// 在打卡时间范围内 // 在打卡时间范围内
normalClockInCount++; normalClockInCount++;
// 出勤工时算4小时
totalWorkHours = NumberUtil.add(totalWorkHours, new BigDecimal("4"));
} else { } else {
// 不在打卡时间范围内 提前打卡则算缺卡 晚打卡算迟到记录分钟数 // 不在打卡时间范围内 提前打卡则算缺卡 晚打卡算迟到记录分钟数
if (reasonForRange.getInRangeType() == 3) { if (reasonForRange.getInRangeType() == 3) {
// 迟到 // 迟到
lateEarlyMinutes = NumberUtil.add(lateEarlyMinutes, reasonForRange.getDiffTime()); isLate = true;
lateMinutes = reasonForRange.getDiffTime();
}
}
// 判断下班时间是否为空
if (ObjectUtil.isNotEmpty(item.getClockOutTimeEnd())) {
// 判断经纬度是否在商户打卡地址100米范围内 如果不在则为缺卡
String clockOutAddrLat = item.getClockOutAddrLat();
String clockOutAddrLng = item.getClockOutAddrLng();
if (StrUtil.isNotBlank(clockOutAddrLat) && StrUtil.isNotBlank(clockOutAddrLng)) {
double distance = DistanceTest.GetDistance(
Double.parseDouble(nearestMerchant.getAddressLat()), // 商户纬度(lat1)
Double.parseDouble(nearestMerchant.getAddressLng()), // 商户经度(lng1)
Double.parseDouble(clockOutAddrLat), // 传入纬度(lat2)
Double.parseDouble(clockOutAddrLng) // 传入经度(lng2)
);
if (distance <= 0.1) {
// 判断下班打卡时间是否符合范围
JudgeResult clockOutForRange = TimeRangeChecker.getReasonForNotInRange(item.getClockOutTimeEnd(), nearestMerchant.getWorkEndTime(), LATEST_CLOCK_OUT_TIME, 1);
if (clockOutForRange.getInRangeType() == 1) {
// 在打卡时间范围内
normalClockOutCount++;
// 出勤工时算4小时
totalWorkHours = NumberUtil.add(totalWorkHours, new BigDecimal("4"));
} else {
// 不在打卡时间范围内 提前打卡则算缺卡 晚打卡算迟到记录分钟数
if (clockOutForRange.getInRangeType() == 2) {
// 早退
isEarly = true;
earlyMinutes = clockOutForRange.getDiffTime();
}
}
}
}
}
// 迟到早退处理
if (isLate) {
// 迟到不早退 计算今天考勤工时
if (!isEarly){
lateEarlyMinutes = NumberUtil.add(lateEarlyMinutes, lateMinutes);
// 迟到早退30分钟内算0.5小时,31-60分钟算1小时 未满半个小时按半个小时计算 计算出勤工时 diffTime为分钟 判断迟到早退时间
double lateHours = Math.ceil(lateMinutes / 30.0) * 0.5;
lateEarlyHours = NumberUtil.add(lateEarlyHours, new BigDecimal(4 - lateHours));
// 计算打卡数
normalClockInCount++;
}
} else {
// 不迟到但早退 计算今天考勤工时
if (isEarly) {
lateEarlyMinutes = NumberUtil.add(lateEarlyMinutes, earlyMinutes);
// 迟到早退30分钟内算0.5小时,31-60分钟算1小时 未满半个小时按半个小时计算 计算出勤工时 diffTime为分钟 判断迟到早退时间
double earlyHours = Math.ceil(earlyMinutes / 30.0) * 0.5;
lateEarlyHours = NumberUtil.add(lateEarlyHours, new BigDecimal(4 - earlyHours));
// 计算打卡数
normalClockInCount++;
} }
} }
} else { } else {
...@@ -174,7 +239,7 @@ public class AttendanceDataCleansingService { ...@@ -174,7 +239,7 @@ public class AttendanceDataCleansingService {
// 如果不为空,则使用商户考勤打卡时间处理 // 如果不为空,则使用商户考勤打卡时间处理
if (ObjectUtil.isNotEmpty(nearestMerchant)) { if (ObjectUtil.isNotEmpty(nearestMerchant)) {
// 判断打卡时间是否在打卡时间范围内 // 判断打卡时间是否在打卡时间范围内
JudgeResult reasonForRange = TimeRangeChecker.getReasonForNotInRange(item.getClockInTimeStart(), nearestMerchant.getWorkStartTime(), nearestMerchant.getWorkEndTime(), 1); JudgeResult reasonForRange = TimeRangeChecker.getReasonForNotInRange(item.getClockInTimeStart(), EARLIEST_CLOCK_IN_TIME, nearestMerchant.getWorkStartTime(), 1);
if (reasonForRange.getInRangeType() == 1) { if (reasonForRange.getInRangeType() == 1) {
// 在打卡时间范围内 // 在打卡时间范围内
normalClockInCount++; normalClockInCount++;
...@@ -208,7 +273,7 @@ public class AttendanceDataCleansingService { ...@@ -208,7 +273,7 @@ public class AttendanceDataCleansingService {
MerchantAttendanceList nearestMerchant = this.findNearestMerchant(item.getClockOutAddrLng(), item.getClockOutAddrLat(), merchantAttendanceLists); MerchantAttendanceList nearestMerchant = this.findNearestMerchant(item.getClockOutAddrLng(), item.getClockOutAddrLat(), merchantAttendanceLists);
// 如果不为空,则使用商户考勤打卡时间处理 // 如果不为空,则使用商户考勤打卡时间处理
if (ObjectUtil.isNotEmpty(nearestMerchant)) { if (ObjectUtil.isNotEmpty(nearestMerchant)) {
JudgeResult reasonForRange = TimeRangeChecker.getReasonForNotInRange(item.getClockInTimeStart(), nearestMerchant.getWorkStartTime(), nearestMerchant.getWorkEndTime(), 1); JudgeResult reasonForRange = TimeRangeChecker.getReasonForNotInRange(item.getClockInTimeStart(), EARLIEST_CLOCK_IN_TIME, nearestMerchant.getWorkStartTime(), 1);
if (reasonForRange.getInRangeType() == 1) { if (reasonForRange.getInRangeType() == 1) {
// 在打卡时间范围内 // 在打卡时间范围内
normalClockInCount++; normalClockInCount++;
...@@ -221,7 +286,7 @@ public class AttendanceDataCleansingService { ...@@ -221,7 +286,7 @@ public class AttendanceDataCleansingService {
} }
} else { } else {
// 如果为空,则使用默认打卡时间处理 // 如果为空,则使用默认打卡时间处理
JudgeResult reasonForRange = TimeRangeChecker.getReasonForNotInRange(item.getClockInTimeStart(), DEFAULT_CLOCK_IN_TIME, DEFAULT_CLOCK_OUT_TIME, 1); JudgeResult reasonForRange = TimeRangeChecker.getReasonForNotInRange(item.getClockInTimeStart(), EARLIEST_CLOCK_IN_TIME, DEFAULT_CLOCK_IN_TIME, 1);
if (reasonForRange.getInRangeType() == 1) { if (reasonForRange.getInRangeType() == 1) {
// 在打卡时间范围内 // 在打卡时间范围内
normalClockInCount++; normalClockInCount++;
......
...@@ -40,8 +40,9 @@ public class DistanceTest { ...@@ -40,8 +40,9 @@ public class DistanceTest {
double lat2 = 39.772501; double lat2 = 39.772501;
double dist = GetDistance(lat1, lon1, lat2, lon2); double dist = GetDistance(lat1, lon1, lat2, lon2);
System.out.println("输出结果:" + dist * 1000 + "m");
System.out.println("输出结果:" + dist * 1000); System.out.println("输出结果:" + dist * 1000);
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!