|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package org.dromara.oa.erp.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
@ -157,7 +158,8 @@ public class ErpBudgetInfoServiceImpl extends AbstractWorkflowService<ErpBudgetI
|
|
|
|
|
private <T> List<T> queryBudgetCosts(BaseMapper<T> mapper, Class<T> entityClass, Long budgetId) {
|
|
|
|
|
MPJLambdaWrapper<T> wrapper = JoinWrappers.lambda(entityClass)
|
|
|
|
|
.selectAll(entityClass)
|
|
|
|
|
.eq("budget_id", budgetId); // 直接使用字段名
|
|
|
|
|
.eq("budget_id", budgetId)
|
|
|
|
|
.orderByAsc("sort_order"); // 直接使用字段名
|
|
|
|
|
|
|
|
|
|
return mapper.selectList(wrapper);
|
|
|
|
|
}
|
|
|
|
|
@ -268,7 +270,6 @@ public class ErpBudgetInfoServiceImpl extends AbstractWorkflowService<ErpBudgetI
|
|
|
|
|
public Boolean insertByBo(ErpBudgetInfoBo bo) {
|
|
|
|
|
ErpBudgetInfo add = MapstructUtils.convert(bo, ErpBudgetInfo.class);
|
|
|
|
|
validEntityBeforeSave(add);
|
|
|
|
|
add.setBudgetVersion(1L);
|
|
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
|
|
|
|
|
|
|
if (add.getProjectCategory().equals(ProjectCategoryEnum.MARKET.getCode())
|
|
|
|
|
@ -331,6 +332,55 @@ public class ErpBudgetInfoServiceImpl extends AbstractWorkflowService<ErpBudgetI
|
|
|
|
|
return isUpdated;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增项目预算
|
|
|
|
|
*
|
|
|
|
|
* @param bo 项目预算
|
|
|
|
|
* @return 是否新增成功
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean changeByBo(ErpBudgetInfoBo bo) {
|
|
|
|
|
//当前变更预算的版本
|
|
|
|
|
Integer currentBudgetVersion = bo.getBudgetVersion();
|
|
|
|
|
|
|
|
|
|
// 1. 查询项目的所有预算(包括不可用的)
|
|
|
|
|
LambdaQueryWrapper<ErpBudgetInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
queryWrapper.eq(ErpBudgetInfo::getProjectId, bo.getProjectId())
|
|
|
|
|
.orderByDesc(ErpBudgetInfo::getBudgetVersion);
|
|
|
|
|
|
|
|
|
|
List<ErpBudgetInfo> allBudgets = baseMapper.selectList(queryWrapper);
|
|
|
|
|
|
|
|
|
|
if (allBudgets.isEmpty()) {
|
|
|
|
|
throw new RuntimeException("项目不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2.判断此变更项目预算的状态
|
|
|
|
|
ErpBudgetInfo currentEffectiveBudget = allBudgets.stream()
|
|
|
|
|
.filter(b -> currentBudgetVersion.equals(b.getBudgetVersion()))
|
|
|
|
|
.findFirst()
|
|
|
|
|
.orElse(null);
|
|
|
|
|
|
|
|
|
|
if (currentEffectiveBudget == null || !currentEffectiveBudget.getBudgetStatus().equals(FlowConfigEnum.BUDGET.getCompletedBusinessStatus())) {
|
|
|
|
|
throw new RuntimeException("项目不存在可用的预算进行变更");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 3. 获取最新版本号(包括所有状态的预算)
|
|
|
|
|
Integer latestVersion = allBudgets.stream()
|
|
|
|
|
.map(ErpBudgetInfo::getBudgetVersion)
|
|
|
|
|
.max(Integer::compareTo)
|
|
|
|
|
.orElse(0);
|
|
|
|
|
|
|
|
|
|
if (latestVersion.compareTo(currentBudgetVersion) > 0) {
|
|
|
|
|
throw new RuntimeException("已经有正在变更的项目预算,版本号:" + latestVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bo.setBudgetVersion(currentBudgetVersion+1);
|
|
|
|
|
|
|
|
|
|
return insertByBo(bo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存前的数据校验
|
|
|
|
|
*/
|
|
|
|
|
|