Compare commits

...

2 Commits

Author SHA1 Message Date
xs 880c808569 Merge remote-tracking branch 'origin/dev' into dev 2 weeks ago
xs c475223c0d 1.0.47后端:
feat(budget):项目预算变更功能
2 weeks ago

@ -101,6 +101,17 @@ public class ErpBudgetInfoController extends BaseController {
return toAjax(erpBudgetInfoService.updateByBo(bo)); return toAjax(erpBudgetInfoService.updateByBo(bo));
} }
/**
*
*/
@SaCheckPermission("oa:erp/budgetInfo:change")
@Log(title = "项目预算", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PostMapping("/change")
public R<Void> change(@Validated(AddGroup.class) @RequestBody ErpBudgetInfoBo bo) {
return toAjax(erpBudgetInfoService.changeByBo(bo));
}
/** /**
* *
* *

@ -42,7 +42,7 @@ public class ErpBudgetInfo extends TenantEntity {
/** /**
* +1 * +1
*/ */
private Long budgetVersion; private Integer budgetVersion;
/** /**
* 1 2 3 * 1 2 3

@ -44,7 +44,7 @@ public class ErpBudgetInfoBo extends BaseEntity {
/** /**
* +1 * +1
*/ */
private Long budgetVersion; private Integer budgetVersion;
/** /**
* 1 2 3 * 1 2 3

@ -51,7 +51,7 @@ public class ErpBudgetInfoVo implements Serializable {
* +1 * +1
*/ */
@ExcelProperty(value = "版本,新版本+1") @ExcelProperty(value = "版本,新版本+1")
private Long budgetVersion; private Integer budgetVersion;
/** /**
* 1 2 3 * 1 2 3

@ -58,6 +58,14 @@ public interface IErpBudgetInfoService {
*/ */
Boolean updateByBo(ErpBudgetInfoBo bo); Boolean updateByBo(ErpBudgetInfoBo bo);
/**
*
*
* @param bo
* @return
*/
Boolean changeByBo(ErpBudgetInfoBo bo);
/** /**
* *
* *

@ -1,6 +1,7 @@
package org.dromara.oa.erp.service.impl; package org.dromara.oa.erp.service.impl;
import cn.hutool.core.util.ObjectUtil; 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.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; 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) { private <T> List<T> queryBudgetCosts(BaseMapper<T> mapper, Class<T> entityClass, Long budgetId) {
MPJLambdaWrapper<T> wrapper = JoinWrappers.lambda(entityClass) MPJLambdaWrapper<T> wrapper = JoinWrappers.lambda(entityClass)
.selectAll(entityClass) .selectAll(entityClass)
.eq("budget_id", budgetId); // 直接使用字段名 .eq("budget_id", budgetId)
.orderByAsc("sort_order"); // 直接使用字段名
return mapper.selectList(wrapper); return mapper.selectList(wrapper);
} }
@ -268,7 +270,6 @@ public class ErpBudgetInfoServiceImpl extends AbstractWorkflowService<ErpBudgetI
public Boolean insertByBo(ErpBudgetInfoBo bo) { public Boolean insertByBo(ErpBudgetInfoBo bo) {
ErpBudgetInfo add = MapstructUtils.convert(bo, ErpBudgetInfo.class); ErpBudgetInfo add = MapstructUtils.convert(bo, ErpBudgetInfo.class);
validEntityBeforeSave(add); validEntityBeforeSave(add);
add.setBudgetVersion(1L);
boolean flag = baseMapper.insert(add) > 0; boolean flag = baseMapper.insert(add) > 0;
if (add.getProjectCategory().equals(ProjectCategoryEnum.MARKET.getCode()) if (add.getProjectCategory().equals(ProjectCategoryEnum.MARKET.getCode())
@ -331,6 +332,55 @@ public class ErpBudgetInfoServiceImpl extends AbstractWorkflowService<ErpBudgetI
return isUpdated; 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);
}
/** /**
* *
*/ */
@ -694,19 +744,19 @@ public class ErpBudgetInfoServiceImpl extends AbstractWorkflowService<ErpBudgetI
@Override @Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) { public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if (isValid) { if (isValid) {
ids.forEach(id->{ ids.forEach(id -> {
ErpBudgetInfo erpBudgetInfo = baseMapper.selectById(id); ErpBudgetInfo erpBudgetInfo = baseMapper.selectById(id);
if(!erpBudgetInfo.getBudgetStatus().equals(OAStatusEnum.DRAFT.getStatus()) if (!erpBudgetInfo.getBudgetStatus().equals(OAStatusEnum.DRAFT.getStatus())
|| !erpBudgetInfo.getFlowStatus().equals(BusinessStatusEnum.DRAFT.getStatus())){ || !erpBudgetInfo.getFlowStatus().equals(BusinessStatusEnum.DRAFT.getStatus())) {
throw new ServiceException("此项目预算已进入审批,不能删除!"); throw new ServiceException("此项目预算已进入审批,不能删除!");
} }
LambdaUpdateWrapper<ErpBudgetInfo> luw = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper<ErpBudgetInfo> luw = new LambdaUpdateWrapper<>();
// luw.set(ObjectUtil.isNull(config.getPrefix()), SysOssConfig::getPrefix, ""); // luw.set(ObjectUtil.isNull(config.getPrefix()), SysOssConfig::getPrefix, "");
luw.set(ErpBudgetInfo::getBudgetVersion,null); luw.set(ErpBudgetInfo::getBudgetVersion, null);
luw.set(ErpBudgetInfo::getDelFlag,"1"); luw.set(ErpBudgetInfo::getDelFlag, "1");
luw.set(ErpBudgetInfo::getUpdateBy, LoginHelper.getUserId()); luw.set(ErpBudgetInfo::getUpdateBy, LoginHelper.getUserId());
luw.set(ErpBudgetInfo::getUpdateTime,new Date()); luw.set(ErpBudgetInfo::getUpdateTime, new Date());
luw.eq(ErpBudgetInfo::getBudgetId, erpBudgetInfo.getBudgetId()); luw.eq(ErpBudgetInfo::getBudgetId, erpBudgetInfo.getBudgetId());
boolean flag = baseMapper.update(null, luw) > 0; boolean flag = baseMapper.update(null, luw) > 0;

Loading…
Cancel
Save