update 优化流程记录运行时长获取
This commit is contained in:
parent
7a790eb236
commit
463c141f04
@ -199,6 +199,36 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
||||
return String.format("%d天 %d小时 %d分钟", day, hour, min);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算两个时间点的差值(天、小时、分钟、秒),当值为0时不显示该单位
|
||||
*
|
||||
* @param endDate 结束时间
|
||||
* @param nowDate 当前时间
|
||||
* @return 时间差字符串,格式为 "x天 x小时 x分钟 x秒",若为 0 则不显示
|
||||
*/
|
||||
public static String getTimeDifference(Date endDate, Date nowDate) {
|
||||
long diffInMillis = endDate.getTime() - nowDate.getTime();
|
||||
long day = TimeUnit.MILLISECONDS.toDays(diffInMillis);
|
||||
long hour = TimeUnit.MILLISECONDS.toHours(diffInMillis) % 24;
|
||||
long min = TimeUnit.MILLISECONDS.toMinutes(diffInMillis) % 60;
|
||||
long sec = TimeUnit.MILLISECONDS.toSeconds(diffInMillis) % 60;
|
||||
// 构建时间差字符串,条件是值不为0才显示
|
||||
StringBuilder result = new StringBuilder();
|
||||
if (day > 0) {
|
||||
result.append(String.format("%d天 ", day));
|
||||
}
|
||||
if (hour > 0) {
|
||||
result.append(String.format("%d小时 ", hour));
|
||||
}
|
||||
if (min > 0) {
|
||||
result.append(String.format("%d分钟 ", min));
|
||||
}
|
||||
if (sec > 0) {
|
||||
result.append(String.format("%d秒", sec));
|
||||
}
|
||||
return result.length() > 0 ? result.toString().trim() : "0秒";
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 LocalDateTime 对象转换为 Date 对象
|
||||
*
|
||||
|
@ -1,8 +1,10 @@
|
||||
package org.dromara.workflow.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import org.dromara.common.core.utils.DateUtils;
|
||||
import org.dromara.common.translation.annotation.Translation;
|
||||
import org.dromara.common.translation.constant.TransConstant;
|
||||
import org.dromara.warm.flow.core.enums.CooperateType;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
@ -183,4 +185,43 @@ public class FlowHisTaskVo implements Serializable {
|
||||
* 运行时长
|
||||
*/
|
||||
private String runDuration;
|
||||
|
||||
/**
|
||||
* 设置创建时间并计算任务运行时长
|
||||
*
|
||||
* @param createTime 创建时间
|
||||
*/
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
updateRunDuration();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置更新时间并计算任务运行时长
|
||||
*
|
||||
* @param updateTime 更新时间
|
||||
*/
|
||||
public void setUpdateTime(Date updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
updateRunDuration();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新运行时长
|
||||
*/
|
||||
private void updateRunDuration() {
|
||||
// 如果创建时间和更新时间均不为空,计算它们之间的时长
|
||||
if (this.updateTime != null && this.createTime != null) {
|
||||
this.runDuration = DateUtils.getTimeDifference(this.updateTime, this.createTime);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置协作方式,并通过协作方式获取名称
|
||||
*/
|
||||
public void setCooperateType(Integer cooperateType) {
|
||||
this.cooperateType = cooperateType;
|
||||
this.cooperateTypeName = CooperateType.getValueByKey(cooperateType);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -241,12 +241,6 @@ public class FlwInstanceServiceImpl implements IFlwInstanceService {
|
||||
wrapper.orderByDesc(FlowHisTask::getCreateTime).orderByDesc(FlowHisTask::getUpdateTime);
|
||||
List<FlowHisTask> flowHisTasks = flowHisTaskMapper.selectList(wrapper);
|
||||
List<FlowHisTaskVo> list = BeanUtil.copyToList(flowHisTasks, FlowHisTaskVo.class);
|
||||
for (FlowHisTaskVo vo : list) {
|
||||
vo.setCooperateTypeName(CooperateType.getValueByKey(vo.getCooperateType()));
|
||||
if (vo.getUpdateTime() != null && vo.getCreateTime() != null) {
|
||||
vo.setRunDuration(DateUtils.getDatePoor(vo.getUpdateTime(), vo.getCreateTime()));
|
||||
}
|
||||
}
|
||||
map.put("list", list);
|
||||
try {
|
||||
String flowChart = defService.flowChart(flowInstance.getId());
|
||||
|
Loading…
x
Reference in New Issue
Block a user