|
|
@ -1,5 +1,6 @@
|
|
|
|
package com.engine.kq.job;
|
|
|
|
package com.engine.kq.job;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.engine.kq.biz.KQShiftManagementComInfo;
|
|
|
|
import com.engine.kq.biz.KQShiftManagementComInfo;
|
|
|
|
import com.engine.kq.biz.KQShiftRestTimeSectionComInfo;
|
|
|
|
import com.engine.kq.biz.KQShiftRestTimeSectionComInfo;
|
|
|
@ -29,6 +30,72 @@ public class UpdateEffectiveDuration {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 有效时长计算逻辑:
|
|
|
|
|
|
|
|
* 1、最早、最晚打卡时间,与开始时间、结束时间没有交集=》有效时长=共计时长
|
|
|
|
|
|
|
|
* 2、最早、最晚打卡时间,与开始时间、结束时间有交集=》
|
|
|
|
|
|
|
|
* (1)比较最早打卡时间与开始时间,如果最早打卡时间晚于开始时间,统计晚打卡的分钟数
|
|
|
|
|
|
|
|
* (2)比较最晚打卡时间与结束时间,如果最晚打卡时间早于结束时间,统计早打卡的分钟数
|
|
|
|
|
|
|
|
* (3)统计相差的分钟数,按半小时起算,有效时长=共计时长-相差时长
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param mainId
|
|
|
|
|
|
|
|
* @param userId
|
|
|
|
|
|
|
|
* @param gzrq
|
|
|
|
|
|
|
|
* @param earlyStartTime
|
|
|
|
|
|
|
|
* @param afterEndTime
|
|
|
|
|
|
|
|
* @param startTime
|
|
|
|
|
|
|
|
* @param endTime
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static void execute(String mainId, String userId, String gzrq, String earlyStartTime, String afterEndTime, String startTime, String endTime) {
|
|
|
|
|
|
|
|
RecordSet recordSet = new RecordSet();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
LocalDateTime startSignTime = LocalDateTime.parse(earlyStartTime, DATE_TIME_FORMATTER);
|
|
|
|
|
|
|
|
LocalDateTime endSignTime = LocalDateTime.parse(afterEndTime, DATE_TIME_FORMATTER);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LocalDateTime startWorkTime = LocalDateTime.parse(startTime, DATE_TIME_FORMATTER);
|
|
|
|
|
|
|
|
LocalDateTime endWorkTime = LocalDateTime.parse(endTime, DATE_TIME_FORMATTER);
|
|
|
|
|
|
|
|
// 最早、最晚打卡时间,与开始时间、结束时间,是否存在交集
|
|
|
|
|
|
|
|
boolean hasIntersection = startSignTime.isBefore(endWorkTime) && endSignTime.isAfter(startWorkTime);
|
|
|
|
|
|
|
|
recordSet.executeQuery("select gjsc from uf_jbtz where id = ?", mainId);
|
|
|
|
|
|
|
|
double gjscHours = 0.0;
|
|
|
|
|
|
|
|
if (recordSet.next()) {
|
|
|
|
|
|
|
|
gjscHours = recordSet.getDouble("gjsc");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gjscHours < 0) {
|
|
|
|
|
|
|
|
throw new Exception("mainId===" + mainId + ",共计时长小于0");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasIntersection) {
|
|
|
|
|
|
|
|
int totalMinutes = 0;
|
|
|
|
|
|
|
|
if (startSignTime.isAfter(startWorkTime)) {
|
|
|
|
|
|
|
|
int startDifference = (int) (startWorkTime.until(startSignTime, ChronoUnit.MINUTES));
|
|
|
|
|
|
|
|
recordSet.execute("mainId=" + mainId + ",userId=" + userId + ",gzrq=" + gzrq + ",startDifference=" + startDifference);
|
|
|
|
|
|
|
|
totalMinutes += startDifference;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (endSignTime.isBefore(endWorkTime)) {
|
|
|
|
|
|
|
|
int endDifference = (int) (endSignTime.until(endWorkTime, ChronoUnit.MINUTES));
|
|
|
|
|
|
|
|
recordSet.execute("mainId=" + mainId + ",userId=" + userId + ",gzrq=" + gzrq + ",endDifference=" + endDifference);
|
|
|
|
|
|
|
|
totalMinutes += endDifference;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 总计相差时间,按照半小时,向上取整
|
|
|
|
|
|
|
|
double totalHours = (double) totalMinutes / 60;
|
|
|
|
|
|
|
|
double timeDifference = gjscHours - totalHours;
|
|
|
|
|
|
|
|
// 将小时数按照0.5小时的单位向下取整
|
|
|
|
|
|
|
|
double roundedHours = (int) Math.floor(timeDifference / 0.5) * 0.5;
|
|
|
|
|
|
|
|
recordSet.writeLog("userId==" + userId + ",totalMinutes===" + totalMinutes + ",gjscHours===" + gjscHours + ",totalHours==" + totalHours + ",roundedHours==" + roundedHours);
|
|
|
|
|
|
|
|
recordSet.executeUpdate("update uf_jbtz set yxsc=? where id=? ", roundedHours, mainId);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 最早、最晚打卡时间,与开始时间、结束时间没有交集=》有效时长=共计时长
|
|
|
|
|
|
|
|
recordSet.executeUpdate("update uf_jbtz set yxsc=? where id=? ", gjscHours, mainId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
recordSet.writeLog(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 更新加班台账表,有效时长字段
|
|
|
|
* 更新加班台账表,有效时长字段
|
|
|
@ -41,7 +108,7 @@ public class UpdateEffectiveDuration {
|
|
|
|
* @param earlyStartTime 最早打卡时间
|
|
|
|
* @param earlyStartTime 最早打卡时间
|
|
|
|
* @param afterEndTime 最晚打卡时间
|
|
|
|
* @param afterEndTime 最晚打卡时间
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static void execute(String mainId, String userId, String gzrq, String earlyStartTime, String afterEndTime, String startTime, String endTime) {
|
|
|
|
public static void execute1(String mainId, String userId, String gzrq, String earlyStartTime, String afterEndTime, String startTime, String endTime) {
|
|
|
|
RecordSet recordSet = new RecordSet();
|
|
|
|
RecordSet recordSet = new RecordSet();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
KQWorkTime kqWorkTime = new KQWorkTime();
|
|
|
|
KQWorkTime kqWorkTime = new KQWorkTime();
|
|
|
@ -134,12 +201,12 @@ public class UpdateEffectiveDuration {
|
|
|
|
restIntervals.sort(Comparator.comparing(TimeInterval::getStart));
|
|
|
|
restIntervals.sort(Comparator.comparing(TimeInterval::getStart));
|
|
|
|
// 实际的工作开始时间、结束时间
|
|
|
|
// 实际的工作开始时间、结束时间
|
|
|
|
List<TimeInterval> workIntervals = calculateWorkIntervals(intersectionStart, intersectionEnd, restIntervals);
|
|
|
|
List<TimeInterval> workIntervals = calculateWorkIntervals(intersectionStart, intersectionEnd, restIntervals);
|
|
|
|
new BaseBean().writeLog("workIntervals===" + JSON.toJSONString(workIntervals));
|
|
|
|
//new BaseBean().writeLog("workIntervals===" + JSON.toJSONString(workIntervals));
|
|
|
|
for (TimeInterval workInterval : workIntervals) {
|
|
|
|
for (TimeInterval workInterval : workIntervals) {
|
|
|
|
effectiveTimeList.add(workInterval.getStart().format(DATE_TIME_FORMATTER) + "," + workInterval.getEnd().format(DATE_TIME_FORMATTER));
|
|
|
|
effectiveTimeList.add(workInterval.getStart().format(DATE_TIME_FORMATTER) + "," + workInterval.getEnd().format(DATE_TIME_FORMATTER));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
long totalMinutes = calculateTotalWorkMinutes(workIntervals);
|
|
|
|
long totalMinutes = calculateTotalWorkMinutes(workIntervals);
|
|
|
|
new BaseBean().writeLog("totalMinutes==="+totalMinutes);
|
|
|
|
//new BaseBean().writeLog("totalMinutes==="+totalMinutes);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if (intersectionStart.isBefore(intersectionEnd)) {
|
|
|
|
//if (intersectionStart.isBefore(intersectionEnd)) {
|
|
|
|