Browse Source

fix:重新剥离出审批时间

master
buaixuexideshitongxue 1 month ago
parent
commit
f5da13af72
  1. 30
      src/main/java/com/biutag/supervision/flow/action/ApplyCompletionAction.java
  2. 27
      src/main/java/com/biutag/supervision/flow/action/ConfirmationCompletionAction.java
  3. 22
      src/main/java/com/biutag/supervision/flow/action/FirstApproveReturnAction.java
  4. 29
      src/main/java/com/biutag/supervision/flow/action/SecondApproveAction.java
  5. 17
      src/main/java/com/biutag/supervision/flow/action/SecondApproveReturnAction.java
  6. 36
      src/main/java/com/biutag/supervision/pojo/entity/Negative.java
  7. 31
      src/main/java/com/biutag/supervision/util/TimeUtil.java

30
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::getCurrentProcessingObject, negative.getIsSecondHandle() ? "市局专班" : String.format("%s专班", negative.getHandleSecondDepartName()))
.set(Negative::getHandleTime, LocalDateTime.now()) .set(Negative::getHandleTime, LocalDateTime.now())
.set(Negative::getHandleTimeout, Objects.isNull(remainingDuration) || remainingDuration >= 0 ? 0 : -remainingDuration) .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<Negative>()
// .eq(Negative::getId, negative.getId())
// .set(Negative::getSecondApproveDuration, totalDuration)
// .set(Negative::getSecondApproveStartTime, null));
// }
negativeService.update(updateWrapper); negativeService.update(updateWrapper);
} }

27
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.entity.NegativeWork;
import com.biutag.supervision.pojo.model.UserAuth; import com.biutag.supervision.pojo.model.UserAuth;
import com.biutag.supervision.service.*; import com.biutag.supervision.service.*;
import com.biutag.supervision.util.TimeUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -98,6 +99,32 @@ public class ConfirmationCompletionAction implements Action {
} }
public void updateNegative(String negativeId, ConfirmationCompletionData completionData) { 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<Negative>()
.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<Negative>()
.eq(Negative::getId, negativeId)
.set(Negative::getSecondApproveDuration, totalDuration)
.set(Negative::getSecondApproveStartTime, null));
}
LambdaUpdateWrapper<Negative> updateWrapper = new LambdaUpdateWrapper<Negative>() LambdaUpdateWrapper<Negative> updateWrapper = new LambdaUpdateWrapper<Negative>()
.eq(Negative::getId, negativeId) .eq(Negative::getId, negativeId)
.set(Negative::getProcessingStatus, ProcessingStatusEnum.completed.name()) .set(Negative::getProcessingStatus, ProcessingStatusEnum.completed.name())

22
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.NegativeApproveService;
import com.biutag.supervision.service.NegativeService; import com.biutag.supervision.service.NegativeService;
import com.biutag.supervision.service.NegativeWorkService; import com.biutag.supervision.service.NegativeWorkService;
import com.biutag.supervision.util.TimeUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -44,11 +45,32 @@ public class FirstApproveReturnAction implements Action {
public void updateNegative(String negativeId, String nextFlowKey) { public void updateNegative(String negativeId, String nextFlowKey) {
Negative negative = negativeService.getById(negativeId); 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<Negative>()
.eq(Negative::getId, negativeId)
.set(Negative::getFirstApproveDuration, totalDuration)
.set(Negative::getFirstApproveStartTime, null));
}
// 【审批时长统计】市局退回后任务回到2级,需要重新设置2级审批开始时间
// 设置时机:市局退回操作完成后,2级待审批任务重新激活时
// 业务含义:2级重新开始审批的计时起点
// 后续使用:SecondApproveAction/SecondApproveReturnAction 中计算新一轮2级审批时长
negativeService.update(new LambdaUpdateWrapper<Negative>() negativeService.update(new LambdaUpdateWrapper<Negative>()
.set(Negative::getFlowKey, negative.getIsSecondHandle() ? FlowNodeEnum.VERIFY.getKey() : nextFlowKey) .set(Negative::getFlowKey, negative.getIsSecondHandle() ? FlowNodeEnum.VERIFY.getKey() : nextFlowKey)
.set(Negative::getUpdTime, LocalDateTime.now()) .set(Negative::getUpdTime, LocalDateTime.now())
// 当前处理对象 // 当前处理对象
.set(Negative::getCurrentProcessingObject, String.format("%s专班", negative.getHandleSecondDepartName())) .set(Negative::getCurrentProcessingObject, String.format("%s专班", negative.getHandleSecondDepartName()))
.set(Negative::getSecondApproveStartTime, LocalDateTime.now())
.eq(Negative::getId, negativeId)); .eq(Negative::getId, negativeId));
} }

29
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.NegativeApproveService;
import com.biutag.supervision.service.NegativeService; import com.biutag.supervision.service.NegativeService;
import com.biutag.supervision.service.NegativeWorkService; import com.biutag.supervision.service.NegativeWorkService;
import com.biutag.supervision.util.TimeUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -50,18 +51,42 @@ public class SecondApproveAction implements Action {
} }
public void updateNegative(String negativeId, String nextFlowKey) { 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<Negative>()
.eq(Negative::getId, negativeId)
.set(Negative::getSecondApproveDuration, totalDuration)
.set(Negative::getSecondApproveStartTime, null));
}
LambdaUpdateWrapper<Negative> updateWrapper = new LambdaUpdateWrapper<Negative>() LambdaUpdateWrapper<Negative> updateWrapper = new LambdaUpdateWrapper<Negative>()
.set(Negative::getFlowKey, nextFlowKey) .set(Negative::getFlowKey, nextFlowKey)
.set(Negative::getUpdTime, LocalDateTime.now()) .set(Negative::getUpdTime, LocalDateTime.now())
.eq(Negative::getId, negativeId); .eq(Negative::getId, negativeId);
Negative negative = negativeService.getById(negativeId); // Negative negative = negativeService.getById(negativeId);
if (ApprovalFlowEnum.SECOND_APPROVAL.getValue().equals(negative.getApprovalFlow())) { if (ApprovalFlowEnum.SECOND_APPROVAL.getValue().equals(negative.getApprovalFlow())) {
// 二级审批流程,直接办结(无需市局审批,不设置firstApproveStartTime)
updateWrapper.set(Negative::getFlowKey, FlowNodeEnum.COMPLETED.getKey()) updateWrapper.set(Negative::getFlowKey, FlowNodeEnum.COMPLETED.getKey())
.set(Negative::getProcessingStatus, ProcessingStatusEnum.completed.name()) .set(Negative::getProcessingStatus, ProcessingStatusEnum.completed.name())
.set(Negative::getCompleteDate, LocalDateTime.now()); .set(Negative::getCompleteDate, LocalDateTime.now());
} else { } else {
// 【审批时长统计】三级审批流程,设置市局审批开始时间
// 触发条件:approvalFlow="3"(三级审批),且2级审批通过
// 设置时机:2级提交到市局时(市局待审批任务创建时)
// 业务含义:市局开始审批的计时起点
// 后续使用:ConfirmationCompletionAction 计算市局审批时长,FirstApproveReturnAction 退回时也计算时长
updateWrapper.set(Negative::getFlowKey, nextFlowKey) updateWrapper.set(Negative::getFlowKey, nextFlowKey)
.set(Negative::getCurrentProcessingObject, "市局专班"); .set(Negative::getCurrentProcessingObject, "市局专班")
.set(Negative::getFirstApproveStartTime, now);
} }
negativeService.update(updateWrapper); negativeService.update(updateWrapper);
} }

17
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.NegativeApproveService;
import com.biutag.supervision.service.NegativeService; import com.biutag.supervision.service.NegativeService;
import com.biutag.supervision.service.NegativeWorkService; import com.biutag.supervision.service.NegativeWorkService;
import com.biutag.supervision.util.TimeUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -45,6 +46,22 @@ public class SecondApproveReturnAction implements Action {
public void updateNegative(String negativeId, String nextFlowKey) { public void updateNegative(String negativeId, String nextFlowKey) {
Negative negative = negativeService.getById(negativeId); 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<Negative>()
.eq(Negative::getId, negativeId)
.set(Negative::getSecondApproveDuration, totalDuration)
.set(Negative::getSecondApproveStartTime, null));
}
negativeService.update(new LambdaUpdateWrapper<Negative>() negativeService.update(new LambdaUpdateWrapper<Negative>()
.set(Negative::getFlowKey, nextFlowKey) .set(Negative::getFlowKey, nextFlowKey)
.set(Negative::getUpdTime, LocalDateTime.now()) .set(Negative::getUpdTime, LocalDateTime.now())

36
src/main/java/com/biutag/supervision/pojo/entity/Negative.java

@ -370,4 +370,40 @@ public class Negative {
@Schema(description = "下发单位名字") @Schema(description = "下发单位名字")
@TableField("issuingDepartName") @TableField("issuingDepartName")
private String 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;
} }

31
src/main/java/com/biutag/supervision/util/TimeUtil.java

@ -109,4 +109,35 @@ public class TimeUtil {
public static String formatDate(Date date) { public static String formatDate(Date date) {
return new SimpleDateFormat("yyyy年MM月dd日").format(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;
}
} }

Loading…
Cancel
Save