From 68b11b71934a1c662dae683ad3b893048abd909f Mon Sep 17 00:00:00 2001 From: buaixuexideshitongxue <2936013465@qq.com> Date: Thu, 2 Apr 2026 15:28:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E9=87=8D=E6=96=B0=E5=89=A5=E7=A6=BB?= =?UTF-8?q?=E5=87=BA=E5=AE=A1=E6=89=B9=E6=97=B6=E9=97=B4--lastTime?= =?UTF-8?q?=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flow/action/ApplyCompletionAction.java | 3 +- .../action/ConfirmationCompletionAction.java | 10 +++++- .../flow/action/FirstApproveReturnAction.java | 10 +++++- .../flow/action/SecondApproveAction.java | 11 ++++++- .../action/SecondApproveReturnAction.java | 7 +++++ .../supervision/pojo/entity/Negative.java | 28 +++++++++++++++++ .../com/biutag/supervision/util/TimeUtil.java | 31 +++++++++++++++++++ 7 files changed, 96 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/biutag/supervision/flow/action/ApplyCompletionAction.java b/src/main/java/com/biutag/supervision/flow/action/ApplyCompletionAction.java index 33a7e2d..c23a097 100644 --- a/src/main/java/com/biutag/supervision/flow/action/ApplyCompletionAction.java +++ b/src/main/java/com/biutag/supervision/flow/action/ApplyCompletionAction.java @@ -70,7 +70,8 @@ public class ApplyCompletionAction implements Action { .set(Negative::getCurrentProcessingObject, negative.getIsSecondHandle() ? "市局专班" : String.format("%s专班", negative.getHandleSecondDepartName())) .set(Negative::getHandleTime, LocalDateTime.now()) .set(Negative::getHandleTimeout, Objects.isNull(remainingDuration) || remainingDuration >= 0 ? 0 : -remainingDuration) - .set(Negative::getVerifyTime, LocalDateTime.now()); + .set(Negative::getVerifyTime, LocalDateTime.now()) + .set(Negative::getLatestProcessTime, LocalDateTime.now()); negativeService.update(updateWrapper); } diff --git a/src/main/java/com/biutag/supervision/flow/action/ConfirmationCompletionAction.java b/src/main/java/com/biutag/supervision/flow/action/ConfirmationCompletionAction.java index ead16c8..eb8a468 100644 --- a/src/main/java/com/biutag/supervision/flow/action/ConfirmationCompletionAction.java +++ b/src/main/java/com/biutag/supervision/flow/action/ConfirmationCompletionAction.java @@ -14,6 +14,7 @@ import com.biutag.supervision.pojo.entity.NegativeScorePolice; import com.biutag.supervision.pojo.entity.NegativeWork; import com.biutag.supervision.pojo.model.UserAuth; import com.biutag.supervision.service.*; +import com.biutag.supervision.util.TimeUtil; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -98,6 +99,12 @@ public class ConfirmationCompletionAction implements Action { } public void updateNegative(String negativeId, ConfirmationCompletionData completionData) { + Negative negative = negativeService.getById(negativeId); + LocalDateTime now = LocalDateTime.now(); + Long firstApproveTime = negative.getFirstApproveTime() == null ? 0L : negative.getFirstApproveTime(); + if (negative.getLatestProcessTime() != null) { + firstApproveTime = firstApproveTime + TimeUtil.calculateWorkdayDuration(negative.getLatestProcessTime(), now); + } LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper() .eq(Negative::getId, negativeId) .set(Negative::getProcessingStatus, ProcessingStatusEnum.completed.name()) @@ -107,7 +114,8 @@ public class ConfirmationCompletionAction implements Action { .set(StrUtil.isNotEmpty(completionData.getReportId()),Negative::getReportId,completionData.getReportId()) .set(StrUtil.isNotEmpty(completionData.getReportNumber()),Negative::getReportNumber,completionData.getReportNumber()) .set(Negative::getFlowKey, FlowNodeEnum.COMPLETED.getKey()) - .set(Negative::getUpdTime, LocalDateTime.now()); + .set(Negative::getUpdTime, LocalDateTime.now()) + .set(Negative::getFirstApproveTime, firstApproveTime); negativeService.update(updateWrapper); } public void doneWork(Integer workId, String negativeId) { diff --git a/src/main/java/com/biutag/supervision/flow/action/FirstApproveReturnAction.java b/src/main/java/com/biutag/supervision/flow/action/FirstApproveReturnAction.java index 80b39b1..85d220b 100644 --- a/src/main/java/com/biutag/supervision/flow/action/FirstApproveReturnAction.java +++ b/src/main/java/com/biutag/supervision/flow/action/FirstApproveReturnAction.java @@ -14,6 +14,7 @@ import com.biutag.supervision.pojo.model.UserAuth; import com.biutag.supervision.service.NegativeApproveService; import com.biutag.supervision.service.NegativeService; import com.biutag.supervision.service.NegativeWorkService; +import com.biutag.supervision.util.TimeUtil; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -44,12 +45,19 @@ public class FirstApproveReturnAction implements Action { public void updateNegative(String negativeId, String nextFlowKey) { Negative negative = negativeService.getById(negativeId); + LocalDateTime now = LocalDateTime.now(); + Long firstApproveTime = negative.getFirstApproveTime() == null ? 0L : negative.getFirstApproveTime(); + if (negative.getLatestProcessTime() != null) { + firstApproveTime = firstApproveTime + TimeUtil.calculateWorkdayDuration(negative.getLatestProcessTime(), now); + } negativeService.update(new LambdaUpdateWrapper() .set(Negative::getFlowKey, negative.getIsSecondHandle() ? FlowNodeEnum.VERIFY.getKey() : nextFlowKey) .set(Negative::getUpdTime, LocalDateTime.now()) // 当前处理对象 .set(Negative::getCurrentProcessingObject, String.format("%s专班", negative.getHandleSecondDepartName())) - .eq(Negative::getId, negativeId)); + .eq(Negative::getId, negativeId) + .set(Negative::getFirstApproveTime, firstApproveTime) + .set(Negative::getLatestProcessTime, now)); } public void addApprove(String negativeId, String comments, Integer workId) { diff --git a/src/main/java/com/biutag/supervision/flow/action/SecondApproveAction.java b/src/main/java/com/biutag/supervision/flow/action/SecondApproveAction.java index 000916a..64e8da7 100644 --- a/src/main/java/com/biutag/supervision/flow/action/SecondApproveAction.java +++ b/src/main/java/com/biutag/supervision/flow/action/SecondApproveAction.java @@ -15,6 +15,7 @@ import com.biutag.supervision.pojo.model.UserAuth; import com.biutag.supervision.service.NegativeApproveService; import com.biutag.supervision.service.NegativeService; import com.biutag.supervision.service.NegativeWorkService; +import com.biutag.supervision.util.TimeUtil; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -50,17 +51,25 @@ public class SecondApproveAction implements Action { } public void updateNegative(String negativeId, String nextFlowKey) { + Negative negative = negativeService.getById(negativeId); + LocalDateTime now = LocalDateTime.now(); + Long secondApprovalTime = negative.getSecondApprovalTime() == null ? 0L : negative.getSecondApprovalTime(); + if (negative.getLatestProcessTime() != null) { + secondApprovalTime = secondApprovalTime + TimeUtil.calculateWorkdayDuration(negative.getLatestProcessTime(), now); + } LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper() .set(Negative::getFlowKey, nextFlowKey) .set(Negative::getUpdTime, LocalDateTime.now()) + .set(Negative::getSecondApprovalTime, secondApprovalTime) .eq(Negative::getId, negativeId); - Negative negative = negativeService.getById(negativeId); +// Negative negative = negativeService.getById(negativeId); if (ApprovalFlowEnum.SECOND_APPROVAL.getValue().equals(negative.getApprovalFlow())) { updateWrapper.set(Negative::getFlowKey, FlowNodeEnum.COMPLETED.getKey()) .set(Negative::getProcessingStatus, ProcessingStatusEnum.completed.name()) .set(Negative::getCompleteDate, LocalDateTime.now()); } else { updateWrapper.set(Negative::getFlowKey, nextFlowKey) + .set(Negative::getLatestProcessTime, now) .set(Negative::getCurrentProcessingObject, "市局专班"); } negativeService.update(updateWrapper); diff --git a/src/main/java/com/biutag/supervision/flow/action/SecondApproveReturnAction.java b/src/main/java/com/biutag/supervision/flow/action/SecondApproveReturnAction.java index d22f116..5ac468d 100644 --- a/src/main/java/com/biutag/supervision/flow/action/SecondApproveReturnAction.java +++ b/src/main/java/com/biutag/supervision/flow/action/SecondApproveReturnAction.java @@ -15,6 +15,7 @@ import com.biutag.supervision.pojo.model.UserAuth; import com.biutag.supervision.service.NegativeApproveService; import com.biutag.supervision.service.NegativeService; import com.biutag.supervision.service.NegativeWorkService; +import com.biutag.supervision.util.TimeUtil; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -45,12 +46,18 @@ public class SecondApproveReturnAction implements Action { public void updateNegative(String negativeId, String nextFlowKey) { Negative negative = negativeService.getById(negativeId); + LocalDateTime now = LocalDateTime.now(); + Long secondApprovalTime = negative.getSecondApprovalTime() == null ? 0L : negative.getSecondApprovalTime(); + if (negative.getLatestProcessTime() != null) { + secondApprovalTime = secondApprovalTime + TimeUtil.calculateWorkdayDuration(negative.getLatestProcessTime(), now); + } negativeService.update(new LambdaUpdateWrapper() .set(Negative::getFlowKey, nextFlowKey) .set(Negative::getUpdTime, LocalDateTime.now()) .set(Negative::getProcessingStatus, ProcessingStatusEnum.processing.name()) // 当前处理对象 .set(Negative::getCurrentProcessingObject, String.format("%s专班", negative.getHandleThreeDepartName())) + .set(Negative::getSecondApprovalTime, secondApprovalTime) .eq(Negative::getId, negativeId)); } diff --git a/src/main/java/com/biutag/supervision/pojo/entity/Negative.java b/src/main/java/com/biutag/supervision/pojo/entity/Negative.java index dc8114f..7a6d081 100644 --- a/src/main/java/com/biutag/supervision/pojo/entity/Negative.java +++ b/src/main/java/com/biutag/supervision/pojo/entity/Negative.java @@ -370,4 +370,32 @@ public class Negative { @Schema(description = "下发单位名字") @TableField("issuingDepartName") private String issuingDepartName; + + /** + * 2级审批开始时间 + * 设置时机:3级专班提交时(ApplyCompletionAction),或市局退回后任务回到2级时(FirstApproveReturnAction) + * 重置时机:2级审批完成或退回时(SecondApproveAction/SecondApproveReturnAction) + * 用途:计算2级审批累计时长 + */ + @TableField("latest_process_time") + private LocalDateTime latestProcessTime; + + /** + * 2级审批累计时长(秒) + * 计算公式:每次2级审批完成时累加 duration += (当前时间 - secondApproveStartTime) + * 包含场景:正常审批时长 + 退回后再审批时长 + * 不包含:本级办理(isSecondHandle=true) + */ + @TableField("second_approval_time") + private Long secondApprovalTime; + + + /** + * 市局审批累计时长(秒) + * 计算公式:每次市局审批完成时累加 duration += (当前时间 - firstApproveStartTime) + * 包含场景:正常审批时长 + 退回后再审批时长 + * 不包含:二级审批流程(approvalFlow="2") + */ + @TableField("first_approve_time") + private Long firstApproveTime; } diff --git a/src/main/java/com/biutag/supervision/util/TimeUtil.java b/src/main/java/com/biutag/supervision/util/TimeUtil.java index 2a0019d..1adfeaa 100644 --- a/src/main/java/com/biutag/supervision/util/TimeUtil.java +++ b/src/main/java/com/biutag/supervision/util/TimeUtil.java @@ -109,4 +109,35 @@ public class TimeUtil { public static String formatDate(Date date) { return new SimpleDateFormat("yyyy年MM月dd日").format(date); } + + + /** + * 计算两个时间之间的工作日时长(秒) + * @param beginTime 开始时间 + * @param endTime 结束时间 + * @return 工作日时长(秒) + */ + public static long calculateWorkdayDuration(LocalDateTime beginTime, LocalDateTime endTime) { + if (Objects.isNull(beginTime) || Objects.isNull(endTime)) { + return 0; + } + HolidayService holidayService = SpringUtil.getBean(HolidayService.class); + long duration = 0; + for (LocalDateTime time = beginTime; time.isBefore(endTime.with(LocalTime.MAX)); time = time.plusDays(1)) { + if (holidayService.isHoliday(DatePattern.NORM_DATE_FORMATTER.format(time))) { + continue; + } + if (beginTime.toLocalDate().equals(endTime.toLocalDate())) { + duration += ChronoUnit.SECONDS.between(beginTime, endTime); + } else if (time.equals(beginTime)) { + duration += ChronoUnit.SECONDS.between(time, time.with(LocalTime.MAX)); + } else if (time.toLocalDate().equals(endTime.toLocalDate())) { + duration += ChronoUnit.SECONDS.between(time.with(LocalTime.MIN), endTime); + } else { + duration += SECONDS_OF_A_DAY; + } + } + return duration; + } + }