From b763cf9321b65fba133769e046f0eab450287a9b Mon Sep 17 00:00:00 2001 From: buaixuexideshitongxue <2936013465@qq.com> Date: Wed, 1 Apr 2026 18:32:06 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=E5=89=A5=E7=A6=BB=E5=AE=A1=E6=89=B9?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../biutag/supervision/flow/FlowService.java | 1 + .../flow/action/ApplyCompletionAction.java | 7 +++- .../action/ConfirmationCompletionAction.java | 23 +++++++++++- .../flow/action/FirstApproveReturnAction.java | 5 ++- .../flow/action/SecondApproveAction.java | 20 ++++++++-- .../action/SecondApproveReturnAction.java | 2 + .../supervision/pojo/entity/Negative.java | 37 +++++++++++++++++++ .../com/biutag/supervision/util/TimeUtil.java | 31 ++++++++++++++++ 8 files changed, 120 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/biutag/supervision/flow/FlowService.java b/src/main/java/com/biutag/supervision/flow/FlowService.java index efa9c64..78f81ce 100644 --- a/src/main/java/com/biutag/supervision/flow/FlowService.java +++ b/src/main/java/com/biutag/supervision/flow/FlowService.java @@ -74,6 +74,7 @@ public class FlowService { } catch (RuntimeException e) { history.setCrtName("模型超市"); } +// System.out.println(1/0); return negativeHistoryService.save(history); } 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..91412b6 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,12 @@ 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()) + // 设置审批开始时间 + // 二级审批开始时间:isSecondHandle=false(3级提交本级办理)时设置, 如果不是二级办理,此时是提交到二级,需要记录二级审批开始时间 + .set(Negative::getSecondApproveStartTime, negative.getIsSecondHandle() ? null : LocalDateTime.now()) + // 市局审批开始时间:isSecondHandle=true(2级提交本级办理)时设置,如果是二级办理,此时是提交到市局,需要记录市局审批开始时间 + .set(Negative::getFirstApproveStartTime, negative.getIsSecondHandle() ? LocalDateTime.now() : 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..df09bb5 100644 --- a/src/main/java/com/biutag/supervision/flow/action/ConfirmationCompletionAction.java +++ b/src/main/java/com/biutag/supervision/flow/action/ConfirmationCompletionAction.java @@ -20,6 +20,8 @@ import org.springframework.stereotype.Component; import java.time.LocalDateTime; import java.util.List; +import com.biutag.supervision.util.TimeUtil; + /** * @author wxc * @date 2024/11/8 @@ -98,6 +100,8 @@ public class ConfirmationCompletionAction implements Action { } public void updateNegative(String negativeId, ConfirmationCompletionData completionData) { + Negative negative = negativeService.getById(negativeId); + LocalDateTime now = LocalDateTime.now(); LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper() .eq(Negative::getId, negativeId) .set(Negative::getProcessingStatus, ProcessingStatusEnum.completed.name()) @@ -107,7 +111,24 @@ 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, now); + + // 计算并累加市局审批时长(仅三级审批流程) + if (FlowNodeEnum.FIRST_APPROVE.getKey().equals(negative.getFlowKey()) + && negative.getFirstApproveStartTime() != null) { + long currentDuration = TimeUtil.calculateWorkdayDuration(negative.getFirstApproveStartTime(), now); + long accumulatedDuration = (negative.getFirstApproveDuration() == null ? 0 : negative.getFirstApproveDuration()) + currentDuration; + updateWrapper.set(Negative::getFirstApproveDuration, accumulatedDuration); + } + + // 计算并累加二级审批时长 + if (FlowNodeEnum.SECOND_APPROVE.getKey().equals(negative.getFlowKey()) + && negative.getSecondApproveStartTime() != null) { + long currentDuration = TimeUtil.calculateWorkdayDuration(negative.getSecondApproveStartTime(), now); + long accumulatedDuration = (negative.getSecondApproveDuration() == null ? 0 : negative.getSecondApproveDuration()) + currentDuration; + updateWrapper.set(Negative::getSecondApproveDuration, accumulatedDuration); + } + 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..b59b416 100644 --- a/src/main/java/com/biutag/supervision/flow/action/FirstApproveReturnAction.java +++ b/src/main/java/com/biutag/supervision/flow/action/FirstApproveReturnAction.java @@ -44,11 +44,14 @@ public class FirstApproveReturnAction implements Action { public void updateNegative(String negativeId, String nextFlowKey) { Negative negative = negativeService.getById(negativeId); + LocalDateTime now = LocalDateTime.now(); negativeService.update(new LambdaUpdateWrapper() .set(Negative::getFlowKey, negative.getIsSecondHandle() ? FlowNodeEnum.VERIFY.getKey() : nextFlowKey) - .set(Negative::getUpdTime, LocalDateTime.now()) + .set(Negative::getUpdTime, now) // 当前处理对象 .set(Negative::getCurrentProcessingObject, String.format("%s专班", negative.getHandleSecondDepartName())) + // 退回整改后,重新设置二级审批开始时间,下次二级审批完成后继续累加 + .set(Negative::getSecondApproveStartTime, 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..0849d15 100644 --- a/src/main/java/com/biutag/supervision/flow/action/SecondApproveAction.java +++ b/src/main/java/com/biutag/supervision/flow/action/SecondApproveAction.java @@ -20,6 +20,8 @@ import org.springframework.stereotype.Component; import java.time.LocalDateTime; +import com.biutag.supervision.util.TimeUtil; + /** * 二级机构审批通过 */ @@ -50,18 +52,30 @@ public class SecondApproveAction implements Action { } public void updateNegative(String negativeId, String nextFlowKey) { + Negative negative = negativeService.getById(negativeId); + LocalDateTime now = LocalDateTime.now(); LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper() .set(Negative::getFlowKey, nextFlowKey) .set(Negative::getUpdTime, LocalDateTime.now()) .eq(Negative::getId, negativeId); - Negative negative = negativeService.getById(negativeId); + + // 计算并累加二级审批时长 + if (negative.getSecondApproveStartTime() != null) { + long currentDuration = TimeUtil.calculateWorkdayDuration(negative.getSecondApproveStartTime(), now); + + long accumulatedDuration = (negative.getSecondApproveDuration() == null ? 0 : negative.getSecondApproveDuration()) + currentDuration; + updateWrapper.set(Negative::getSecondApproveDuration, accumulatedDuration); + } + 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()); + .set(Negative::getCompleteDate, now); } else { updateWrapper.set(Negative::getFlowKey, nextFlowKey) - .set(Negative::getCurrentProcessingObject, "市局专班"); + .set(Negative::getCurrentProcessingObject, "市局专班") + // 二级审批通过后流转到市局审批,设置市局审批开始时间 + .set(Negative::getFirstApproveStartTime, LocalDateTime.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..b543ea7 100644 --- a/src/main/java/com/biutag/supervision/flow/action/SecondApproveReturnAction.java +++ b/src/main/java/com/biutag/supervision/flow/action/SecondApproveReturnAction.java @@ -51,6 +51,8 @@ public class SecondApproveReturnAction implements Action { .set(Negative::getProcessingStatus, ProcessingStatusEnum.processing.name()) // 当前处理对象 .set(Negative::getCurrentProcessingObject, String.format("%s专班", negative.getHandleThreeDepartName())) + // 退回整改后,重新设置二级审批开始时间,下次二级审批完成后继续累加 + .set(Negative::getSecondApproveStartTime, LocalDateTime.now()) .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..ce5a777 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,41 @@ public class Negative { @Schema(description = "下发单位名字") @TableField("issuingDepartName") private String issuingDepartName; + + // ==================== 审批时长统计字段 ==================== + + /** + * 二级审批开始时间(最近一次开始审批的时间) + * 触发条件:isSecondHandle=false 且 3级提交后 + */ + @Schema(description = "二级审批开始时间") + @TableField("second_approve_start_time") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime secondApproveStartTime; + + /** + * 二级审批累计时长(秒) + * 累加规则:每次二级审批完成(包括通过/退回)后累加 + * 不计入:本级办理不计入 + */ + @Schema(description = "二级审批累计时长(秒)") + @TableField("second_approve_duration") + private Long secondApproveDuration; + + /** + * 市局审批开始时间(最近一次开始审批的时间) + * 触发条件:approvalFlow="3" 且 2级提交后 + */ + @Schema(description = "市局审批开始时间") + @TableField("first_approve_start_time") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime firstApproveStartTime; + + /** + * 市局审批累计时长(秒) + * 累加规则:每次市局审批完成(包括通过/退回)后累加 + */ + @Schema(description = "市局审批累计时长(秒)") + @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; + } + } From afc0140d258eafe12aad2faf93b3311f22a3bf7d Mon Sep 17 00:00:00 2001 From: buaixuexideshitongxue <2936013465@qq.com> Date: Wed, 1 Apr 2026 18:33:05 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=E5=88=A0=E9=99=A4=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/biutag/supervision/flow/FlowService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/biutag/supervision/flow/FlowService.java b/src/main/java/com/biutag/supervision/flow/FlowService.java index 78f81ce..efa9c64 100644 --- a/src/main/java/com/biutag/supervision/flow/FlowService.java +++ b/src/main/java/com/biutag/supervision/flow/FlowService.java @@ -74,7 +74,6 @@ public class FlowService { } catch (RuntimeException e) { history.setCrtName("模型超市"); } -// System.out.println(1/0); return negativeHistoryService.save(history); } 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 3/3] =?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; + } + }