From f5da13af72cd2b904dbe22e11a5364d325ec3526 Mon Sep 17 00:00:00 2001 From: buaixuexideshitongxue <2936013465@qq.com> Date: Thu, 2 Apr 2026 00:48:19 +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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flow/action/ApplyCompletionAction.java | 30 +++++++++++++++- .../action/ConfirmationCompletionAction.java | 27 ++++++++++++++ .../flow/action/FirstApproveReturnAction.java | 22 ++++++++++++ .../flow/action/SecondApproveAction.java | 29 +++++++++++++-- .../action/SecondApproveReturnAction.java | 17 +++++++++ .../supervision/pojo/entity/Negative.java | 36 +++++++++++++++++++ .../com/biutag/supervision/util/TimeUtil.java | 31 ++++++++++++++++ 7 files changed, 189 insertions(+), 3 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..b285cf3 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,35 @@ 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()) + // 【审批时长统计】3级专班提交时,设置2级审批开始时间 + // 触发条件:isSecondHandle=false(3级提交案件,需要2级审批) + // 设置时机:任务从3级流转到2级时(2级待审批任务创建时) + // 业务含义:2级开始审批的计时起点,不是2级打开待办的时间 + // 后续使用:SecondApproveAction 计算(T1-T0)时长,SecondApproveReturnAction 退回时也计算时长 + .set(negative.getIsSecondHandle() == false, Negative::getSecondApproveStartTime, LocalDateTime.now()) + // 【审批时长统计】二级本级办理时,设置市局审批开始时间 + // 触发条件:isSecondHandle=true(本级办理)且 approvalFlow="3"(需要市局审批) + // 设置时机:二级本级办理提交到市局时 + // 后续使用:ConfirmationCompletionAction 计算市局审批时长,FirstApproveReturnAction 退回时也计算时长 + .set(negative.getIsSecondHandle() == true && ApprovalFlowEnum.THREE_APPROVAL.getValue().equals(negative.getApprovalFlow()), + Negative::getFirstApproveStartTime, LocalDateTime.now()); + // todo 如果 是二级办理,并且从市局退回后,二级重新办理的时间算审批时间的话 + // 【审批时长统计】本级办理场景:市局退回后整改提交时,累加二级整改时长 + // 触发条件:isSecondHandle=true 且 approvalFlow="3" 且 secondApproveStartTime != null + // 计算逻辑:(当前时间 - secondApproveStartTime),累加到 secondApproveDuration + // 业务含义:市局退回后,二级整改并重新提交的总时长 + // if (negative.getIsSecondHandle() == true && + // ApprovalFlowEnum.THREE_APPROVAL.getValue().equals(negative.getApprovalFlow()) && + // negative.getSecondApproveStartTime() != null) { + // LocalDateTime now = LocalDateTime.now(); + // long duration = TimeUtil.calculateWorkdayDuration(negative.getSecondApproveStartTime(), now); + // Long totalDuration = negative.getSecondApproveDuration() == null ? duration : negative.getSecondApproveDuration() + duration; + // negativeService.update(new LambdaUpdateWrapper() + // .eq(Negative::getId, negative.getId()) + // .set(Negative::getSecondApproveDuration, totalDuration) + // .set(Negative::getSecondApproveStartTime, null)); + // } 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..a66ee2a 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,32 @@ public class ConfirmationCompletionAction implements Action { } public void updateNegative(String negativeId, ConfirmationCompletionData completionData) { + Negative negative = negativeService.getById(negativeId); + LocalDateTime now = LocalDateTime.now(); + + // 【审批时长统计】计算市局审批时长并累加 + // 计算范围:firstApproveStartTime(市局开始审批时设置)到 now(当前办结时间) + // 触发时机:市局点击【审批通过】完成办结时 + // 累加规则:duration += (当前时间 - 开始时间) + // 注意事项:二级审批流程(approvalFlow="2")时,firstApproveStartTime 为null,不会进入此逻辑 + if (negative.getFirstApproveStartTime() != null) { + long duration = TimeUtil.calculateWorkdayDuration(negative.getFirstApproveStartTime(), now); + Long totalDuration = negative.getFirstApproveDuration() == null ? duration : negative.getFirstApproveDuration() + duration; + negativeService.update(new LambdaUpdateWrapper() + .eq(Negative::getId, negativeId) + .set(Negative::getFirstApproveDuration, totalDuration) + .set(Negative::getFirstApproveStartTime, null)); + } + if (negative.getSecondApproveStartTime() != null) { + long duration = TimeUtil.calculateWorkdayDuration(negative.getSecondApproveStartTime(), now); + Long totalDuration = negative.getSecondApproveDuration() == null ? duration : negative.getSecondApproveDuration() + duration; + negativeService.update(new LambdaUpdateWrapper() + .eq(Negative::getId, negativeId) + .set(Negative::getSecondApproveDuration, totalDuration) + .set(Negative::getSecondApproveStartTime, null)); + } + + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper() .eq(Negative::getId, negativeId) .set(Negative::getProcessingStatus, ProcessingStatusEnum.completed.name()) 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..894c5a6 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,11 +45,32 @@ public class FirstApproveReturnAction implements Action { public void updateNegative(String negativeId, String nextFlowKey) { Negative negative = negativeService.getById(negativeId); + LocalDateTime now = LocalDateTime.now(); + + // 【审批时长统计】计算市局审批时长并累加,然后重置开始时间 + // 计算范围:firstApproveStartTime(市局开始审批时设置)到 now(当前退回时间) + // 触发时机:市局点击【退回整改】时(退回也是一种审批操作) + // 累加规则:duration += (当前时间 - 开始时间) + // 重置说明:退回后任务回到2级,firstApproveStartTime设为null + if (negative.getFirstApproveStartTime() != null) { + long duration = TimeUtil.calculateWorkdayDuration(negative.getFirstApproveStartTime(), now); + Long totalDuration = negative.getFirstApproveDuration() == null ? duration : negative.getFirstApproveDuration() + duration; + negativeService.update(new LambdaUpdateWrapper() + .eq(Negative::getId, negativeId) + .set(Negative::getFirstApproveDuration, totalDuration) + .set(Negative::getFirstApproveStartTime, null)); + } + + // 【审批时长统计】市局退回后任务回到2级,需要重新设置2级审批开始时间 + // 设置时机:市局退回操作完成后,2级待审批任务重新激活时 + // 业务含义:2级重新开始审批的计时起点 + // 后续使用:SecondApproveAction/SecondApproveReturnAction 中计算新一轮2级审批时长 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())) + .set(Negative::getSecondApproveStartTime, LocalDateTime.now()) .eq(Negative::getId, negativeId)); } 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..c1f5949 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,18 +51,42 @@ public class SecondApproveAction implements Action { } public void updateNegative(String negativeId, String nextFlowKey) { + Negative negative = negativeService.getById(negativeId); + LocalDateTime now = LocalDateTime.now(); + + // 【审批时长统计】计算2级审批时长并累加 + // 计算范围:secondApproveStartTime(3级提交时设置)到 now(当前审批时间) + // 触发时机:2级点击【审批通过】或【退回整改】时 + // 累加规则:duration += (当前时间 - 开始时间),退回后再审批会继续累加 + // 注意事项:本级办理(isSecondHandle=true)时,secondApproveStartTime 为null,不会进入此逻辑 + if (negative.getSecondApproveStartTime() != null) { + long duration = TimeUtil.calculateWorkdayDuration(negative.getSecondApproveStartTime(), now); + Long totalDuration = negative.getSecondApproveDuration() == null ? duration : negative.getSecondApproveDuration() + duration; + negativeService.update(new LambdaUpdateWrapper() + .eq(Negative::getId, negativeId) + .set(Negative::getSecondApproveDuration, totalDuration) + .set(Negative::getSecondApproveStartTime, null)); + } + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper() .set(Negative::getFlowKey, nextFlowKey) .set(Negative::getUpdTime, LocalDateTime.now()) .eq(Negative::getId, negativeId); - Negative negative = negativeService.getById(negativeId); +// Negative negative = negativeService.getById(negativeId); if (ApprovalFlowEnum.SECOND_APPROVAL.getValue().equals(negative.getApprovalFlow())) { + // 二级审批流程,直接办结(无需市局审批,不设置firstApproveStartTime) updateWrapper.set(Negative::getFlowKey, FlowNodeEnum.COMPLETED.getKey()) .set(Negative::getProcessingStatus, ProcessingStatusEnum.completed.name()) .set(Negative::getCompleteDate, LocalDateTime.now()); } else { + // 【审批时长统计】三级审批流程,设置市局审批开始时间 + // 触发条件:approvalFlow="3"(三级审批),且2级审批通过 + // 设置时机:2级提交到市局时(市局待审批任务创建时) + // 业务含义:市局开始审批的计时起点 + // 后续使用:ConfirmationCompletionAction 计算市局审批时长,FirstApproveReturnAction 退回时也计算时长 updateWrapper.set(Negative::getFlowKey, nextFlowKey) - .set(Negative::getCurrentProcessingObject, "市局专班"); + .set(Negative::getCurrentProcessingObject, "市局专班") + .set(Negative::getFirstApproveStartTime, now); } 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..d50e60f 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,6 +46,22 @@ public class SecondApproveReturnAction implements Action { public void updateNegative(String negativeId, String nextFlowKey) { Negative negative = negativeService.getById(negativeId); + LocalDateTime now = LocalDateTime.now(); + + // 【审批时长统计】计算2级审批时长并累加,然后重置开始时间 + // 计算范围:secondApproveStartTime(3级提交时设置)到 now(当前退回时间) + // 触发时机:2级点击【退回整改】时(退回也是一种审批操作) + // 累加规则:duration += (当前时间 - 开始时间) + // 重置说明:退回后任务回到3级,secondApproveStartTime设为null,等待3级重新提交时再设置 + if (negative.getSecondApproveStartTime() != null) { + long duration = TimeUtil.calculateWorkdayDuration(negative.getSecondApproveStartTime(), now); + Long totalDuration = negative.getSecondApproveDuration() == null ? duration : negative.getSecondApproveDuration() + duration; + negativeService.update(new LambdaUpdateWrapper() + .eq(Negative::getId, negativeId) + .set(Negative::getSecondApproveDuration, totalDuration) + .set(Negative::getSecondApproveStartTime, null)); + } + negativeService.update(new LambdaUpdateWrapper() .set(Negative::getFlowKey, nextFlowKey) .set(Negative::getUpdTime, LocalDateTime.now()) 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..af3bdc1 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,40 @@ public class Negative { @Schema(description = "下发单位名字") @TableField("issuingDepartName") private String issuingDepartName; + + /** + * 2级审批开始时间 + * 设置时机:3级专班提交时(ApplyCompletionAction),或市局退回后任务回到2级时(FirstApproveReturnAction) + * 重置时机:2级审批完成或退回时(SecondApproveAction/SecondApproveReturnAction) + * 用途:计算2级审批累计时长 + */ + @TableField("second_approve_start_time") + private LocalDateTime secondApproveStartTime; + + /** + * 2级审批累计时长(秒) + * 计算公式:每次2级审批完成时累加 duration += (当前时间 - secondApproveStartTime) + * 包含场景:正常审批时长 + 退回后再审批时长 + * 不包含:本级办理(isSecondHandle=true) + */ + @TableField("second_approve_duration") + private Long secondApproveDuration; + + /** + * 市局审批开始时间 + * 设置时机:2级提交到市局时(SecondApproveAction) + * 重置时机:市局审批完成或退回时(ConfirmationCompletionAction/FirstApproveReturnAction) + * 用途:计算市局审批累计时长 + */ + @TableField("first_approve_start_time") + private LocalDateTime firstApproveStartTime; + + /** + * 市局审批累计时长(秒) + * 计算公式:每次市局审批完成时累加 duration += (当前时间 - firstApproveStartTime) + * 包含场景:正常审批时长 + 退回后再审批时长 + * 不包含:二级审批流程(approvalFlow="2") + */ + @TableField("first_approve_duration") + private Long firstApproveDuration; } 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; + } + }