update 优化 后端代码
This commit is contained in:
parent
11caba8832
commit
38670077ea
@ -82,7 +82,7 @@ public class FlwInstanceServiceImpl implements IFlwInstanceService {
|
|||||||
@Override
|
@Override
|
||||||
public TableDataInfo<FlowInstanceVo> pageByRunning(Instance instance, PageQuery pageQuery) {
|
public TableDataInfo<FlowInstanceVo> pageByRunning(Instance instance, PageQuery pageQuery) {
|
||||||
QueryWrapper<FlowInstanceBo> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<FlowInstanceBo> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.in("t.flow_status", BusinessStatusEnum.runningStatus());
|
queryWrapper.in("fi.flow_status", BusinessStatusEnum.runningStatus());
|
||||||
Page<FlowInstanceVo> page = flwInstanceMapper.page(pageQuery.build(), queryWrapper);
|
Page<FlowInstanceVo> page = flwInstanceMapper.page(pageQuery.build(), queryWrapper);
|
||||||
TableDataInfo<FlowInstanceVo> build = TableDataInfo.build();
|
TableDataInfo<FlowInstanceVo> build = TableDataInfo.build();
|
||||||
build.setRows(BeanUtil.copyToList(page.getRecords(), FlowInstanceVo.class));
|
build.setRows(BeanUtil.copyToList(page.getRecords(), FlowInstanceVo.class));
|
||||||
@ -99,7 +99,7 @@ public class FlwInstanceServiceImpl implements IFlwInstanceService {
|
|||||||
@Override
|
@Override
|
||||||
public TableDataInfo<FlowInstanceVo> pageByFinish(Instance instance, PageQuery pageQuery) {
|
public TableDataInfo<FlowInstanceVo> pageByFinish(Instance instance, PageQuery pageQuery) {
|
||||||
QueryWrapper<FlowInstanceBo> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<FlowInstanceBo> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.in("t.flow_status", BusinessStatusEnum.finishStatus());
|
queryWrapper.in("fi.flow_status", BusinessStatusEnum.finishStatus());
|
||||||
Page<FlowInstanceVo> page = flwInstanceMapper.page(pageQuery.build(), queryWrapper);
|
Page<FlowInstanceVo> page = flwInstanceMapper.page(pageQuery.build(), queryWrapper);
|
||||||
TableDataInfo<FlowInstanceVo> build = TableDataInfo.build();
|
TableDataInfo<FlowInstanceVo> build = TableDataInfo.build();
|
||||||
build.setRows(BeanUtil.copyToList(page.getRecords(), FlowInstanceVo.class));
|
build.setRows(BeanUtil.copyToList(page.getRecords(), FlowInstanceVo.class));
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.dromara.workflow.service.impl;
|
package org.dromara.workflow.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
@ -21,7 +22,6 @@ import org.dromara.workflow.domain.bo.TestLeaveBo;
|
|||||||
import org.dromara.workflow.domain.vo.TestLeaveVo;
|
import org.dromara.workflow.domain.vo.TestLeaveVo;
|
||||||
import org.dromara.workflow.mapper.TestLeaveMapper;
|
import org.dromara.workflow.mapper.TestLeaveMapper;
|
||||||
import org.dromara.workflow.service.ITestLeaveService;
|
import org.dromara.workflow.service.ITestLeaveService;
|
||||||
import org.dromara.workflow.utils.WorkDaysUtils;
|
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@ -84,7 +84,8 @@ public class TestLeaveServiceImpl implements ITestLeaveService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TestLeaveVo insertByBo(TestLeaveBo bo) {
|
public TestLeaveVo insertByBo(TestLeaveBo bo) {
|
||||||
bo.setLeaveDays(WorkDaysUtils.calculateWorkDays(bo.getStartDate(), bo.getEndDate()));
|
long day = DateUtil.betweenDay(bo.getStartDate(), bo.getEndDate(), true);
|
||||||
|
bo.setLeaveDays((int) day);
|
||||||
TestLeave add = MapstructUtils.convert(bo, TestLeave.class);
|
TestLeave add = MapstructUtils.convert(bo, TestLeave.class);
|
||||||
if (StringUtils.isBlank(add.getStatus())) {
|
if (StringUtils.isBlank(add.getStatus())) {
|
||||||
add.setStatus(FlowStatus.TOBESUBMIT.getKey());
|
add.setStatus(FlowStatus.TOBESUBMIT.getKey());
|
||||||
|
@ -75,7 +75,6 @@ public class WfCategoryServiceImpl implements IWfCategoryService {
|
|||||||
public Boolean updateByBo(WfCategoryBo bo) {
|
public Boolean updateByBo(WfCategoryBo bo) {
|
||||||
WfCategory update = MapstructUtils.convert(bo, WfCategory.class);
|
WfCategory update = MapstructUtils.convert(bo, WfCategory.class);
|
||||||
validEntityBeforeSave(update);
|
validEntityBeforeSave(update);
|
||||||
WfCategoryVo wfCategoryVo = baseMapper.selectVoById(bo.getId());
|
|
||||||
return baseMapper.updateById(update) > 0;
|
return baseMapper.updateById(update) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +82,7 @@ public class WfCategoryServiceImpl implements IWfCategoryService {
|
|||||||
* 保存前的数据校验
|
* 保存前的数据校验
|
||||||
*/
|
*/
|
||||||
private void validEntityBeforeSave(WfCategory entity) {
|
private void validEntityBeforeSave(WfCategory entity) {
|
||||||
//TODO 做一些数据校验,如唯一约束
|
// 做一些数据校验,如唯一约束
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,7 +91,7 @@ public class WfCategoryServiceImpl implements IWfCategoryService {
|
|||||||
@Override
|
@Override
|
||||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
//TODO 做一些业务上的校验,判断是否需要校验
|
// 做一些业务上的校验,判断是否需要校验
|
||||||
}
|
}
|
||||||
return baseMapper.deleteByIds(ids) > 0;
|
return baseMapper.deleteByIds(ids) > 0;
|
||||||
}
|
}
|
||||||
|
@ -1,248 +0,0 @@
|
|||||||
package org.dromara.workflow.utils;
|
|
||||||
|
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 工作日工具类
|
|
||||||
*
|
|
||||||
* @author AprilWind
|
|
||||||
*/
|
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
|
||||||
public class WorkDaysUtils {
|
|
||||||
|
|
||||||
private static final Map<Integer, Integer[]> DAYS_IN_YEARS = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 工作日
|
|
||||||
*/
|
|
||||||
public static final int WORKDAY = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 休息日
|
|
||||||
*/
|
|
||||||
public static final int RESTDAY = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据开始日期和工作日数计算截止日期
|
|
||||||
*
|
|
||||||
* @param startDate 开始日期
|
|
||||||
* @param workDays 工作日数
|
|
||||||
* @return 截止日期
|
|
||||||
*/
|
|
||||||
public static Date calculateEndDate(Date startDate, int workDays) {
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.setTime(startDate);
|
|
||||||
// 获取开始日期的年份
|
|
||||||
int startYear = getYear(startDate);
|
|
||||||
//开始日期年份天
|
|
||||||
Integer[] daysArray = daysInYear(startYear);
|
|
||||||
int startIndex = getDayOfYearIndex(startDate);
|
|
||||||
int endIndex = startIndex;
|
|
||||||
// 循环找到指定的工作日数
|
|
||||||
while (workDays > 0) {
|
|
||||||
// 检查当前日期是否是工作日
|
|
||||||
if (daysArray[endIndex] == WORKDAY) {
|
|
||||||
workDays--;
|
|
||||||
}
|
|
||||||
// 结束条件:工作日数为零
|
|
||||||
if (workDays <= 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// 移动到下一天
|
|
||||||
endIndex++;
|
|
||||||
// 如果移动到下一年
|
|
||||||
if (endIndex >= daysArray.length) {
|
|
||||||
startYear++;
|
|
||||||
daysArray = daysInYear(startYear);
|
|
||||||
endIndex = 0;
|
|
||||||
// 更新年份
|
|
||||||
calendar.set(Calendar.YEAR, startYear);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 设置截止日期
|
|
||||||
calendar.set(Calendar.DAY_OF_YEAR, endIndex + 1);
|
|
||||||
return calendar.getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 计算两个日期之间的工作日天数
|
|
||||||
*
|
|
||||||
* @param start 开始日期
|
|
||||||
* @param end 结束日期
|
|
||||||
* @return 实际工作日天数
|
|
||||||
*/
|
|
||||||
public static int calculateWorkDays(Date start, Date end) {
|
|
||||||
if (start.after(end)) {
|
|
||||||
throw new IllegalArgumentException("开始日期不能晚于结束日期");
|
|
||||||
}
|
|
||||||
int workDays = 0;
|
|
||||||
|
|
||||||
// 获取开始和结束日期的年份
|
|
||||||
int startYear = getYear(start);
|
|
||||||
int endYear = getYear(end);
|
|
||||||
|
|
||||||
// 如果在同一年
|
|
||||||
if (startYear == endYear) {
|
|
||||||
//开始日期年份天
|
|
||||||
Integer[] daysArray = daysInYear(startYear);
|
|
||||||
for (int i = getDayOfYearIndex(start); i <= getDayOfYearIndex(end); i++) {
|
|
||||||
if (daysArray[i] == WORKDAY) {
|
|
||||||
workDays++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {//跨年
|
|
||||||
// 处理开始年份
|
|
||||||
Integer[] startYearDaysArray = daysInYear(startYear);
|
|
||||||
int startIndex = getDayOfYearIndex(start);
|
|
||||||
for (int i = startIndex; i < startYearDaysArray.length; i++) {
|
|
||||||
if (startYearDaysArray[i] == WORKDAY) {
|
|
||||||
workDays++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理结束年份
|
|
||||||
Integer[] endYearDaysArray = daysInYear(endYear);
|
|
||||||
int endIndex = getDayOfYearIndex(end);
|
|
||||||
for (int i = 0; i <= endIndex; i++) {
|
|
||||||
if (endYearDaysArray[i] == WORKDAY) {
|
|
||||||
workDays++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理中间的完整年份
|
|
||||||
for (int year = startYear + 1; year < endYear; year++) {
|
|
||||||
Integer[] fullYearDaysArray = daysInYear(year);
|
|
||||||
for (Integer integer : fullYearDaysArray) {
|
|
||||||
if (integer == WORKDAY) {
|
|
||||||
workDays++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return workDays;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 计算指定年份的工作日数组,标记个人的加班和调休日期
|
|
||||||
*
|
|
||||||
* @param year 指定年份
|
|
||||||
* @param overtime 个人加班日期列表
|
|
||||||
* @param adjustments 个人调休日期列表
|
|
||||||
* @return 表示每一天状态的数组,0 表示工作日,1 表示休息日
|
|
||||||
*/
|
|
||||||
public static Integer[] calculateWorkDays(Integer year, List<Date> overtime, List<Date> adjustments) {
|
|
||||||
//获取指定年份天数
|
|
||||||
Integer[] daysArray = daysInYear(year);
|
|
||||||
//设置为工作日(假设用于标记补班的工作日)
|
|
||||||
updateDaysArray(daysArray, overtime, WORKDAY);
|
|
||||||
//设置为休息日(假设用于标记节假日)
|
|
||||||
updateDaysArray(daysArray, adjustments, RESTDAY);
|
|
||||||
return daysArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取指定年份的天数数组。如果指定年份的数据不存在,则生成并缓存数据
|
|
||||||
*
|
|
||||||
* @param year 指定年份
|
|
||||||
* @return 表示一年中每一天的状态数组,0 表示工作日,1 表示周末
|
|
||||||
*/
|
|
||||||
private static Integer[] daysInYear(Integer year) {
|
|
||||||
if (DAYS_IN_YEARS.containsKey(year)) {
|
|
||||||
return DAYS_IN_YEARS.get(year);
|
|
||||||
} else {
|
|
||||||
// 如果年份数据不存在,则生成指定年份的数据
|
|
||||||
Integer[] daysArray = generateDaysArray(year);
|
|
||||||
DAYS_IN_YEARS.put(year, daysArray);
|
|
||||||
return daysArray;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据指定年份生成天数数组
|
|
||||||
*
|
|
||||||
* @param year 指定年份
|
|
||||||
* @return 表示一年中每一天的状态数组
|
|
||||||
*/
|
|
||||||
private static Integer[] generateDaysArray(int year) {
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.set(year, Calendar.JANUARY, 1);
|
|
||||||
|
|
||||||
int daysInYear = getDaysInYear(year);
|
|
||||||
Integer[] daysArray = new Integer[daysInYear];
|
|
||||||
|
|
||||||
for (int i = 0; i < daysInYear; i++) {
|
|
||||||
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
|
|
||||||
daysArray[i] = (dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY) ? RESTDAY : WORKDAY;
|
|
||||||
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
|
||||||
}
|
|
||||||
//设置为工作日(假设用于标记补班的工作日)
|
|
||||||
updateDaysArray(daysArray, Collections.emptyList(), WORKDAY);
|
|
||||||
//设置为休息日(假设用于标记节假日)
|
|
||||||
updateDaysArray(daysArray, Collections.emptyList(), RESTDAY);
|
|
||||||
return daysArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据日期下标更新 daysArray,将对应下标的值改为指定值
|
|
||||||
*
|
|
||||||
* @param daysArray 原始的天数数组
|
|
||||||
* @param days 要修改的日期列表
|
|
||||||
* @param valueToSet 休息日用 1,工作日用 0
|
|
||||||
*/
|
|
||||||
private static void updateDaysArray(Integer[] daysArray, List<Date> days, int valueToSet) {
|
|
||||||
if (ArrayUtil.isEmpty(days)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 遍历日期下标数组,将对应的 daysArray 元素设置为1
|
|
||||||
for (Date holiday : days) {
|
|
||||||
int index = getDayOfYearIndex(holiday);
|
|
||||||
// 确保下标在有效范围内
|
|
||||||
if (index >= 0 && index < daysArray.length) {
|
|
||||||
daysArray[index] = valueToSet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取日期在一年中的下标(天数)
|
|
||||||
*
|
|
||||||
* @param date 指定日期
|
|
||||||
* @return 日期在该年份的下标(天数)
|
|
||||||
*/
|
|
||||||
private static int getDayOfYearIndex(Date date) {
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.setTime(date);
|
|
||||||
int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
|
|
||||||
return dayOfYear - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取指定日期的年份
|
|
||||||
*
|
|
||||||
* @param date 指定日期
|
|
||||||
* @return 年份
|
|
||||||
*/
|
|
||||||
private static int getYear(Date date) {
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.setTime(date);
|
|
||||||
return calendar.get(Calendar.YEAR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取指定年份的天数
|
|
||||||
*
|
|
||||||
* @param year 指定年份
|
|
||||||
* @return 年份中的天数
|
|
||||||
*/
|
|
||||||
private static int getDaysInYear(int year) {
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.set(year, Calendar.DECEMBER, 31);
|
|
||||||
return calendar.get(Calendar.DAY_OF_YEAR);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -23,27 +23,27 @@
|
|||||||
<result property="ext" column="ext"/>
|
<result property="ext" column="ext"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<select id="page" resultMap="FlowInstanceResult">
|
<select id="page" resultMap="FlowInstanceResult">
|
||||||
select * from (select a.id,
|
select fi.id,
|
||||||
a.create_time,
|
fi.create_time,
|
||||||
a.update_time,
|
fi.update_time,
|
||||||
a.tenant_id,
|
fi.tenant_id,
|
||||||
a.del_flag,
|
fi.del_flag,
|
||||||
a.definition_id,
|
fi.definition_id,
|
||||||
a.business_id,
|
fi.business_id,
|
||||||
a.node_type,
|
fi.node_type,
|
||||||
a.node_code,
|
fi.node_code,
|
||||||
a.node_name,
|
fi.node_name,
|
||||||
a.variable,
|
fi.variable,
|
||||||
a.flow_status,
|
fi.flow_status,
|
||||||
a.activity_status,
|
fi.activity_status,
|
||||||
a.create_by,
|
fi.create_by,
|
||||||
a.ext,
|
fi.ext,
|
||||||
b.flow_name,
|
fd.flow_name,
|
||||||
b.flow_code,
|
fd.flow_code,
|
||||||
b.version
|
fd.version
|
||||||
from flow_instance a
|
from flow_instance fi
|
||||||
left join flow_definition b on a.definition_id = b.id where a.del_flag = '0') t
|
left join flow_definition fd on fi.definition_id = fd.id where fi.del_flag = '0'
|
||||||
${ew.getCustomSqlSegment}
|
${ew.getCustomSqlSegment}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user