有效时长,计算逻辑调整

dev_dxf
dxfeng 1 year ago
parent bd464fa4fb
commit 3ffe3e7d79

@ -1,5 +1,6 @@
package com.engine.kq.job;
import cn.hutool.core.convert.Convert;
import com.alibaba.fastjson.JSON;
import com.engine.kq.biz.KQShiftManagementComInfo;
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");
/**
*
* 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 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();
try {
KQWorkTime kqWorkTime = new KQWorkTime();
@ -134,12 +201,12 @@ public class UpdateEffectiveDuration {
restIntervals.sort(Comparator.comparing(TimeInterval::getStart));
// 实际的工作开始时间、结束时间
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) {
effectiveTimeList.add(workInterval.getStart().format(DATE_TIME_FORMATTER) + "," + workInterval.getEnd().format(DATE_TIME_FORMATTER));
}
long totalMinutes = calculateTotalWorkMinutes(workIntervals);
new BaseBean().writeLog("totalMinutes==="+totalMinutes);
//new BaseBean().writeLog("totalMinutes==="+totalMinutes);
//if (intersectionStart.isBefore(intersectionEnd)) {

Loading…
Cancel
Save