|
|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
package org.dromara.oa.erp.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
|
|
import org.apache.seata.spring.annotation.GlobalTransactional;
|
|
|
|
|
import org.dromara.common.core.enums.OAStatusEnum;
|
|
|
|
|
@ -12,10 +14,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.github.yulichang.toolkit.JoinWrappers;
|
|
|
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.dromara.oa.erp.domain.ErpBudgetDetail;
|
|
|
|
|
import org.dromara.oa.erp.domain.ErpBudgetMaterialCost;
|
|
|
|
|
import org.dromara.oa.erp.mapper.ErpBudgetDetailMapper;
|
|
|
|
|
import org.dromara.oa.erp.mapper.ErpBudgetMaterialCostMapper;
|
|
|
|
|
import org.dromara.oa.erp.domain.*;
|
|
|
|
|
import org.dromara.oa.erp.enums.ProjectCategoryEnum;
|
|
|
|
|
import org.dromara.oa.erp.enums.RdBudgetCostEnums;
|
|
|
|
|
import org.dromara.oa.erp.mapper.*;
|
|
|
|
|
import org.dromara.oa.workflow.strategy.BudgetWorkflowStrategy;
|
|
|
|
|
import org.dromara.workflow.api.RemoteWorkflowService;
|
|
|
|
|
import org.dromara.workflow.api.domain.RemoteStartProcess;
|
|
|
|
|
@ -23,14 +25,16 @@ import org.dromara.workflow.strategy.AbstractWorkflowService;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.dromara.oa.erp.domain.bo.ErpBudgetInfoBo;
|
|
|
|
|
import org.dromara.oa.erp.domain.vo.ErpBudgetInfoVo;
|
|
|
|
|
import org.dromara.oa.erp.domain.ErpBudgetInfo;
|
|
|
|
|
import org.dromara.oa.erp.mapper.ErpBudgetInfoMapper;
|
|
|
|
|
import org.dromara.oa.erp.service.IErpBudgetInfoService;
|
|
|
|
|
import org.dromara.workflow.strategy.WorkflowStrategy;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 项目预算Service业务层处理
|
|
|
|
|
@ -48,6 +52,35 @@ public class ErpBudgetInfoServiceImpl extends AbstractWorkflowService<ErpBudgetI
|
|
|
|
|
|
|
|
|
|
private final ErpBudgetMaterialCostMapper erpBudgetMaterialCostMapper;
|
|
|
|
|
|
|
|
|
|
private final ErpBudgetLaborCostMapper erpBudgetLaborCostMapper;
|
|
|
|
|
|
|
|
|
|
private final ErpBudgetInstallCostMapper erpBudgetInstallCostMapper;
|
|
|
|
|
|
|
|
|
|
private final ErpBudgetTravelCostMapper erpBudgetTravelCostMapper;
|
|
|
|
|
|
|
|
|
|
private final ErpBudgetOtherCostMapper erpBudgetOtherCostMapper;
|
|
|
|
|
|
|
|
|
|
private final ErpRdBudgetEquipmentCostMapper erpRdBudgetEquipmentCostMapper;
|
|
|
|
|
|
|
|
|
|
private final ErpRdBudgetMaterialCostMapper erpRdBudgetMaterialCostMapper;
|
|
|
|
|
|
|
|
|
|
private final ErpRdBudgetTravelCostMapper erpRdBudgetTravelCostMapper;
|
|
|
|
|
|
|
|
|
|
private final ErpRdBudgetMeetingCostMapper erpRdBudgetMeetingCostMapper;
|
|
|
|
|
|
|
|
|
|
private final ErpRdBudgetExchangeCostMapper erpRdBudgetExchangeCostMapper;
|
|
|
|
|
|
|
|
|
|
private final ErpRdBudgetTechCostMapper erpRdBudgetTechCostMapper;
|
|
|
|
|
|
|
|
|
|
private final ErpRdBudgetLaborCostMapper erpRdBudgetLaborCostMapper;
|
|
|
|
|
|
|
|
|
|
private final ErpRdBudgetLiteratureCostMapper erpRdBudgetLiteratureCostMapper;
|
|
|
|
|
|
|
|
|
|
private final ErpRdBudgetTestingCostMapper erpRdBudgetTestingCostMapper;
|
|
|
|
|
|
|
|
|
|
private final ErpRdBudgetOtherCostMapper erpRdBudgetOtherCostMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@DubboReference(timeout = 30000)
|
|
|
|
|
private RemoteWorkflowService remoteWorkflowService;
|
|
|
|
|
|
|
|
|
|
@ -60,7 +93,7 @@ public class ErpBudgetInfoServiceImpl extends AbstractWorkflowService<ErpBudgetI
|
|
|
|
|
* 实现时执行remoteWorkflowService.startCompleteTask(startProcess);
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected boolean doStartWorkflow(RemoteStartProcess startProcess){
|
|
|
|
|
protected boolean doStartWorkflow(RemoteStartProcess startProcess) {
|
|
|
|
|
return remoteWorkflowService.startCompleteTask(startProcess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -72,7 +105,95 @@ public class ErpBudgetInfoServiceImpl extends AbstractWorkflowService<ErpBudgetI
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public ErpBudgetInfoVo queryById(Long budgetId) {
|
|
|
|
|
return baseMapper.selectVoById(budgetId);
|
|
|
|
|
ErpBudgetInfoVo erpBudgetInfoVo = baseMapper.selectVoById(budgetId);
|
|
|
|
|
if (erpBudgetInfoVo != null) {
|
|
|
|
|
String projectCategory = erpBudgetInfoVo.getProjectCategory();
|
|
|
|
|
MPJLambdaWrapper<ErpBudgetDetail> budgetDetailMPJLambdaWrapper = JoinWrappers.lambda(ErpBudgetDetail.class)
|
|
|
|
|
.selectAll(ErpBudgetDetail.class)
|
|
|
|
|
.eq(ErpBudgetDetail::getBudgetId, budgetId);
|
|
|
|
|
List<ErpBudgetDetail> erpBudgetDetailList = erpBudgetDetailMapper.selectList(budgetDetailMPJLambdaWrapper);
|
|
|
|
|
erpBudgetInfoVo.setErpBudgetDetailList(erpBudgetDetailList);
|
|
|
|
|
|
|
|
|
|
if (projectCategory.equals(ProjectCategoryEnum.MARKET.getCode()) || projectCategory.equals(ProjectCategoryEnum.MARKET_PART.getCode())) {
|
|
|
|
|
MPJLambdaWrapper<ErpBudgetMaterialCost> budgetMaterialCostMPJLambdaWrapper = JoinWrappers.lambda(ErpBudgetMaterialCost.class)
|
|
|
|
|
.selectAll(ErpBudgetMaterialCost.class)
|
|
|
|
|
.eq(ErpBudgetMaterialCost::getBudgetId, budgetId);
|
|
|
|
|
List<ErpBudgetMaterialCost> erpBudgetMaterialCostList = erpBudgetMaterialCostMapper.selectList(budgetMaterialCostMPJLambdaWrapper);
|
|
|
|
|
erpBudgetInfoVo.setErpBudgetMaterialCostList(erpBudgetMaterialCostList);
|
|
|
|
|
|
|
|
|
|
MPJLambdaWrapper<ErpBudgetLaborCost> budgetLaborCostMPJLambdaWrapper = JoinWrappers.lambda(ErpBudgetLaborCost.class)
|
|
|
|
|
.selectAll(ErpBudgetLaborCost.class)
|
|
|
|
|
.eq(ErpBudgetLaborCost::getBudgetId, budgetId);
|
|
|
|
|
List<ErpBudgetLaborCost> erpBudgetLaborCostList = erpBudgetLaborCostMapper.selectList(budgetLaborCostMPJLambdaWrapper);
|
|
|
|
|
erpBudgetInfoVo.setErpBudgetLaborCostList(erpBudgetLaborCostList);
|
|
|
|
|
|
|
|
|
|
MPJLambdaWrapper<ErpBudgetInstallCost> budgetInstallCostMPJLambdaWrapper = JoinWrappers.lambda(ErpBudgetInstallCost.class)
|
|
|
|
|
.selectAll(ErpBudgetInstallCost.class)
|
|
|
|
|
.eq(ErpBudgetInstallCost::getBudgetId, budgetId);
|
|
|
|
|
List<ErpBudgetInstallCost> erpBudgetInstallCostList = erpBudgetInstallCostMapper.selectList(budgetInstallCostMPJLambdaWrapper);
|
|
|
|
|
erpBudgetInfoVo.setErpBudgetInstallCostList(erpBudgetInstallCostList);
|
|
|
|
|
|
|
|
|
|
MPJLambdaWrapper<ErpBudgetTravelCost> budgetTravelCostMPJLambdaWrapper = JoinWrappers.lambda(ErpBudgetTravelCost.class)
|
|
|
|
|
.selectAll(ErpBudgetTravelCost.class)
|
|
|
|
|
.eq(ErpBudgetTravelCost::getBudgetId, budgetId);
|
|
|
|
|
List<ErpBudgetTravelCost> erpBudgetTravelCostList = erpBudgetTravelCostMapper.selectList(budgetTravelCostMPJLambdaWrapper);
|
|
|
|
|
erpBudgetInfoVo.setErpBudgetTravelCostList(erpBudgetTravelCostList);
|
|
|
|
|
|
|
|
|
|
MPJLambdaWrapper<ErpBudgetOtherCost> budgetOtherCostMPJLambdaWrapper = JoinWrappers.lambda(ErpBudgetOtherCost.class)
|
|
|
|
|
.selectAll(ErpBudgetOtherCost.class)
|
|
|
|
|
.eq(ErpBudgetOtherCost::getBudgetId, budgetId);
|
|
|
|
|
List<ErpBudgetOtherCost> erpBudgetOtherCostList = erpBudgetOtherCostMapper.selectList(budgetOtherCostMPJLambdaWrapper);
|
|
|
|
|
erpBudgetInfoVo.setErpBudgetOtherCostList(erpBudgetOtherCostList);
|
|
|
|
|
} else {
|
|
|
|
|
loadRdBudgetCosts(budgetId, erpBudgetInfoVo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return erpBudgetInfoVo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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); // 直接使用字段名
|
|
|
|
|
|
|
|
|
|
return mapper.selectList(wrapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadBudgetCosts(Long budgetId, ErpBudgetInfoVo erpBudgetInfoVo) {
|
|
|
|
|
erpBudgetInfoVo.setErpBudgetMaterialCostList(
|
|
|
|
|
queryBudgetCosts(erpBudgetMaterialCostMapper, ErpBudgetMaterialCost.class, budgetId));
|
|
|
|
|
erpBudgetInfoVo.setErpBudgetLaborCostList(
|
|
|
|
|
queryBudgetCosts(erpBudgetLaborCostMapper, ErpBudgetLaborCost.class, budgetId));
|
|
|
|
|
erpBudgetInfoVo.setErpBudgetInstallCostList(
|
|
|
|
|
queryBudgetCosts(erpBudgetInstallCostMapper, ErpBudgetInstallCost.class, budgetId));
|
|
|
|
|
erpBudgetInfoVo.setErpBudgetTravelCostList(
|
|
|
|
|
queryBudgetCosts(erpBudgetTravelCostMapper, ErpBudgetTravelCost.class, budgetId));
|
|
|
|
|
erpBudgetInfoVo.setErpBudgetOtherCostList(
|
|
|
|
|
queryBudgetCosts(erpBudgetOtherCostMapper, ErpBudgetOtherCost.class, budgetId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadRdBudgetCosts(Long budgetId, ErpBudgetInfoVo erpBudgetInfoVo) {
|
|
|
|
|
erpBudgetInfoVo.setErpRdBudgetEquipmentCostList(
|
|
|
|
|
queryBudgetCosts(erpRdBudgetEquipmentCostMapper, ErpRdBudgetEquipmentCost.class, budgetId));
|
|
|
|
|
erpBudgetInfoVo.setErpRdBudgetMaterialCostList(
|
|
|
|
|
queryBudgetCosts(erpRdBudgetMaterialCostMapper, ErpRdBudgetMaterialCost.class, budgetId));
|
|
|
|
|
erpBudgetInfoVo.setErpRdBudgetTravelCostList(
|
|
|
|
|
queryBudgetCosts(erpRdBudgetTravelCostMapper, ErpRdBudgetTravelCost.class, budgetId));
|
|
|
|
|
erpBudgetInfoVo.setErpRdBudgetMeetingCostList(
|
|
|
|
|
queryBudgetCosts(erpRdBudgetMeetingCostMapper, ErpRdBudgetMeetingCost.class, budgetId));
|
|
|
|
|
erpBudgetInfoVo.setErpRdBudgetExchangeCostList(
|
|
|
|
|
queryBudgetCosts(erpRdBudgetExchangeCostMapper, ErpRdBudgetExchangeCost.class, budgetId));
|
|
|
|
|
erpBudgetInfoVo.setErpRdBudgetTechCostList(
|
|
|
|
|
queryBudgetCosts(erpRdBudgetTechCostMapper, ErpRdBudgetTechCost.class, budgetId));
|
|
|
|
|
erpBudgetInfoVo.setErpRdBudgetLaborCostList(
|
|
|
|
|
queryBudgetCosts(erpRdBudgetLaborCostMapper, ErpRdBudgetLaborCost.class, budgetId));
|
|
|
|
|
erpBudgetInfoVo.setErpRdBudgetLiteratureCostList(
|
|
|
|
|
queryBudgetCosts(erpRdBudgetLiteratureCostMapper, ErpRdBudgetLiteratureCost.class, budgetId));
|
|
|
|
|
erpBudgetInfoVo.setErpRdBudgetTestingCostList(
|
|
|
|
|
queryBudgetCosts(erpRdBudgetTestingCostMapper, ErpRdBudgetTestingCost.class, budgetId));
|
|
|
|
|
erpBudgetInfoVo.setErpRdBudgetOtherCostList(
|
|
|
|
|
queryBudgetCosts(erpRdBudgetOtherCostMapper, ErpRdBudgetOtherCost.class, budgetId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -140,19 +261,21 @@ public class ErpBudgetInfoServiceImpl extends AbstractWorkflowService<ErpBudgetI
|
|
|
|
|
* @return 是否新增成功
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@GlobalTransactional(rollbackFor = Exception.class)
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean insertByBo(ErpBudgetInfoBo bo) {
|
|
|
|
|
ErpBudgetInfo add = MapstructUtils.convert(bo, ErpBudgetInfo.class);
|
|
|
|
|
validEntityBeforeSave(add);
|
|
|
|
|
add.setApprovedFlag(add.getProjectId());
|
|
|
|
|
add.setBudgetVersion(1L);
|
|
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
|
|
List<ErpBudgetDetail> erpBudgetDetailList = bo.getErpBudgetDetailList();
|
|
|
|
|
erpBudgetDetailList.forEach(erpBudgetDetail -> erpBudgetDetail.setBudgetId(add.getBudgetId()));
|
|
|
|
|
List<ErpBudgetMaterialCost> erpBudgetMaterialCostList = bo.getErpBudgetMaterialCostList();
|
|
|
|
|
erpBudgetMaterialCostList.forEach(erpBudgetMaterialCost -> erpBudgetMaterialCost.setBudgetId(add.getBudgetId()));
|
|
|
|
|
erpBudgetDetailMapper.insertBatch(erpBudgetDetailList);
|
|
|
|
|
erpBudgetMaterialCostMapper.insertBatch(erpBudgetMaterialCostList);
|
|
|
|
|
|
|
|
|
|
if (add.getProjectCategory().equals(ProjectCategoryEnum.MARKET.getCode())
|
|
|
|
|
|| add.getProjectCategory().equals(ProjectCategoryEnum.MARKET_PART.getCode())) {
|
|
|
|
|
batchBudgetCosts(add);
|
|
|
|
|
} else {
|
|
|
|
|
batchRdBudgetCosts(add);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
|
bo.setBudgetId(add.getBudgetId());
|
|
|
|
|
}
|
|
|
|
|
@ -189,11 +312,19 @@ public class ErpBudgetInfoServiceImpl extends AbstractWorkflowService<ErpBudgetI
|
|
|
|
|
* @return 是否修改成功
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@GlobalTransactional(rollbackFor = Exception.class)
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean updateByBo(ErpBudgetInfoBo bo) {
|
|
|
|
|
ErpBudgetInfo update = MapstructUtils.convert(bo, ErpBudgetInfo.class);
|
|
|
|
|
validEntityBeforeSave(update);
|
|
|
|
|
boolean isUpdated = baseMapper.updateById(update) > 0;
|
|
|
|
|
|
|
|
|
|
if (update.getProjectCategory().equals(ProjectCategoryEnum.MARKET.getCode())
|
|
|
|
|
|| update.getProjectCategory().equals(ProjectCategoryEnum.MARKET_PART.getCode())) {
|
|
|
|
|
batchBudgetCosts(update);
|
|
|
|
|
} else {
|
|
|
|
|
batchRdBudgetCosts(update);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean isUpdated = baseMapper.updateById(update) > 0;
|
|
|
|
|
this.executeWorkflow(bo);
|
|
|
|
|
return isUpdated;
|
|
|
|
|
}
|
|
|
|
|
@ -205,6 +336,352 @@ public class ErpBudgetInfoServiceImpl extends AbstractWorkflowService<ErpBudgetI
|
|
|
|
|
//TODO 做一些数据校验,如唯一约束
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void batchBudgetCosts(ErpBudgetInfo erpBudgetInfo) {
|
|
|
|
|
Long budgetId = erpBudgetInfo.getBudgetId();
|
|
|
|
|
Long projectId = erpBudgetInfo.getProjectId();
|
|
|
|
|
|
|
|
|
|
List<ErpBudgetDetail> erpBudgetDetailList = erpBudgetInfo.getErpBudgetDetailList();
|
|
|
|
|
erpBudgetDetailList.forEach(erpBudgetDetail -> erpBudgetDetail.setBudgetId(budgetId));
|
|
|
|
|
|
|
|
|
|
List<Long> toDeletedMaterialCostIdList = erpBudgetInfo.getToDeletedMaterialCostIdList();
|
|
|
|
|
erpBudgetMaterialCostMapper.deleteByIds(toDeletedMaterialCostIdList);
|
|
|
|
|
|
|
|
|
|
List<Long> toDeletedLaborCostIdList = erpBudgetInfo.getToDeletedLaborCostIdList();
|
|
|
|
|
erpBudgetLaborCostMapper.deleteByIds(toDeletedLaborCostIdList);
|
|
|
|
|
|
|
|
|
|
List<Long> toDeletedInstallCostIdList = erpBudgetInfo.getToDeletedInstallCostIdList();
|
|
|
|
|
erpBudgetInstallCostMapper.deleteByIds(toDeletedInstallCostIdList);
|
|
|
|
|
|
|
|
|
|
List<Long> toDeletedTravelCostIdList = erpBudgetInfo.getToDeletedTravelCostIdList();
|
|
|
|
|
erpBudgetTravelCostMapper.deleteByIds(toDeletedTravelCostIdList);
|
|
|
|
|
|
|
|
|
|
List<Long> toDeletedOtherCostIdList = erpBudgetInfo.getToDeletedOtherCostIdList();
|
|
|
|
|
erpBudgetOtherCostMapper.deleteByIds(toDeletedOtherCostIdList);
|
|
|
|
|
|
|
|
|
|
List<ErpBudgetMaterialCost> erpBudgetMaterialCostList = erpBudgetInfo.getErpBudgetMaterialCostList();
|
|
|
|
|
if (erpBudgetMaterialCostList != null) {
|
|
|
|
|
erpBudgetMaterialCostList.forEach(erpBudgetMaterialCost -> {
|
|
|
|
|
erpBudgetMaterialCost.setBudgetId(budgetId);
|
|
|
|
|
erpBudgetMaterialCost.setProjectId(projectId);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<ErpBudgetLaborCost> erpBudgetLaborCostList = erpBudgetInfo.getErpBudgetLaborCostList();
|
|
|
|
|
erpBudgetLaborCostList.forEach(erpBudgetLaborCost -> {
|
|
|
|
|
erpBudgetLaborCost.setBudgetId(budgetId);
|
|
|
|
|
erpBudgetLaborCost.setProjectId(projectId);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
List<ErpBudgetInstallCost> erpBudgetInstallCostList = erpBudgetInfo.getErpBudgetInstallCostList();
|
|
|
|
|
erpBudgetInstallCostList.forEach(erpBudgetInstallCost -> {
|
|
|
|
|
erpBudgetInstallCost.setBudgetId(budgetId);
|
|
|
|
|
erpBudgetInstallCost.setProjectId(projectId);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
List<ErpBudgetTravelCost> erpBudgetTravelCostList = erpBudgetInfo.getErpBudgetTravelCostList();
|
|
|
|
|
erpBudgetTravelCostList.forEach(erpBudgetTravelCost -> {
|
|
|
|
|
erpBudgetTravelCost.setBudgetId(budgetId);
|
|
|
|
|
erpBudgetTravelCost.setProjectId(projectId);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
List<ErpBudgetOtherCost> erpBudgetOtherCostList = erpBudgetInfo.getErpBudgetOtherCostList();
|
|
|
|
|
erpBudgetOtherCostList.forEach(erpBudgetOtherCost -> {
|
|
|
|
|
erpBudgetOtherCost.setBudgetId(budgetId);
|
|
|
|
|
erpBudgetOtherCost.setProjectId(projectId);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
erpBudgetDetailMapper.insertOrUpdateBatch(erpBudgetDetailList);
|
|
|
|
|
erpBudgetMaterialCostMapper.insertOrUpdateBatch(erpBudgetMaterialCostList);
|
|
|
|
|
erpBudgetLaborCostMapper.insertOrUpdateBatch(erpBudgetLaborCostList);
|
|
|
|
|
erpBudgetInstallCostMapper.insertOrUpdateBatch(erpBudgetInstallCostList);
|
|
|
|
|
erpBudgetTravelCostMapper.insertOrUpdateBatch(erpBudgetTravelCostList);
|
|
|
|
|
erpBudgetOtherCostMapper.insertOrUpdateBatch(erpBudgetOtherCostList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void batchRdBudgetCosts(ErpBudgetInfo erpBudgetInfo) {
|
|
|
|
|
Long budgetId = erpBudgetInfo.getBudgetId();
|
|
|
|
|
Long projectId = erpBudgetInfo.getProjectId();
|
|
|
|
|
|
|
|
|
|
// 1. 处理预算明细
|
|
|
|
|
processRdBudgetDetails(erpBudgetInfo, budgetId);
|
|
|
|
|
|
|
|
|
|
// 2. 批量处理删除操作 - 在同一个事务中
|
|
|
|
|
processRdBudgetDeletions(erpBudgetInfo);
|
|
|
|
|
|
|
|
|
|
// 3. 批量处理插入/更新操作 - 在同一个事务中
|
|
|
|
|
processRdBudgetInsertOrUpdates(erpBudgetInfo, budgetId, projectId);
|
|
|
|
|
|
|
|
|
|
// List<ErpBudgetDetail> erpBudgetDetailList = erpBudgetInfo.getErpBudgetDetailList();
|
|
|
|
|
// erpBudgetDetailList.forEach(erpBudgetDetail -> erpBudgetDetail.setBudgetId(budgetId));
|
|
|
|
|
//
|
|
|
|
|
// List<Long> toDeletedRdEquipmentCostIdList = erpBudgetInfo.getToDeletedRdEquipmentCostIdList();
|
|
|
|
|
// erpRdBudgetEquipmentCostMapper.deleteByIds(toDeletedRdEquipmentCostIdList);
|
|
|
|
|
//
|
|
|
|
|
// List<Long> toDeletedRdMaterialCostIdList = erpBudgetInfo.getToDeletedRdMaterialCostIdList();
|
|
|
|
|
// erpRdBudgetMaterialCostMapper.deleteByIds(toDeletedRdMaterialCostIdList);
|
|
|
|
|
//
|
|
|
|
|
// List<Long> toDeletedRdTravelCostIdList = erpBudgetInfo.getToDeletedRdTravelCostIdList();
|
|
|
|
|
// erpRdBudgetTravelCostMapper.deleteByIds(toDeletedRdTravelCostIdList);
|
|
|
|
|
//
|
|
|
|
|
// List<Long> toDeletedRdMeetingCostIdList = erpBudgetInfo.getToDeletedRdMeetingCostIdList();
|
|
|
|
|
// erpRdBudgetMeetingCostMapper.deleteByIds(toDeletedRdMeetingCostIdList);
|
|
|
|
|
//
|
|
|
|
|
// List<Long> toDeletedRdExchangeCostIdList = erpBudgetInfo.getToDeletedRdExchangeCostIdList();
|
|
|
|
|
// erpRdBudgetExchangeCostMapper.deleteByIds(toDeletedRdExchangeCostIdList);
|
|
|
|
|
//
|
|
|
|
|
// List<Long> toDeletedRdTechCostIdList = erpBudgetInfo.getToDeletedRdTechCostIdList();
|
|
|
|
|
// erpRdBudgetTechCostMapper.deleteByIds(toDeletedRdTechCostIdList);
|
|
|
|
|
//
|
|
|
|
|
// List<Long> toDeletedRdLaborCostIdList = erpBudgetInfo.getToDeletedRdLaborCostIdList();
|
|
|
|
|
// erpRdBudgetLaborCostMapper.deleteByIds(toDeletedRdLaborCostIdList);
|
|
|
|
|
//
|
|
|
|
|
// List<Long> toDeletedRdLiteratureCostIdList = erpBudgetInfo.getToDeletedRdLiteratureCostIdList();
|
|
|
|
|
// erpRdBudgetLiteratureCostMapper.deleteByIds(toDeletedRdLiteratureCostIdList);
|
|
|
|
|
//
|
|
|
|
|
// List<Long> toDeletedRdTestingCostIdList = erpBudgetInfo.getToDeletedRdTestingCostIdList();
|
|
|
|
|
// erpRdBudgetTestingCostMapper.deleteByIds(toDeletedRdTestingCostIdList);
|
|
|
|
|
//
|
|
|
|
|
// List<Long> toDeletedRdOtherCostIdList = erpBudgetInfo.getToDeletedRdOtherCostIdList();
|
|
|
|
|
// erpRdBudgetOtherCostMapper.deleteByIds(toDeletedRdOtherCostIdList);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// List<ErpRdBudgetEquipmentCost> erpRdBudgetEquipmentCostList = erpBudgetInfo.getErpRdBudgetEquipmentCostList();
|
|
|
|
|
// if (erpRdBudgetEquipmentCostList != null) {
|
|
|
|
|
// erpRdBudgetEquipmentCostList.forEach(erpRdBudgetEquipmentCost -> {
|
|
|
|
|
// erpRdBudgetEquipmentCost.setBudgetId(budgetId);
|
|
|
|
|
// erpRdBudgetEquipmentCost.setProjectId(projectId);
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// List<ErpRdBudgetMaterialCost> erpRdBudgetMaterialCostList = erpBudgetInfo.getErpRdBudgetMaterialCostList();
|
|
|
|
|
// if (erpRdBudgetMaterialCostList != null) {
|
|
|
|
|
// erpRdBudgetMaterialCostList.forEach(erpRdBudgetMaterialCost -> {
|
|
|
|
|
// erpRdBudgetMaterialCost.setBudgetId(budgetId);
|
|
|
|
|
// erpRdBudgetMaterialCost.setProjectId(projectId);
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// List<ErpRdBudgetTravelCost> erpRdBudgetTravelCostList = erpBudgetInfo.getErpRdBudgetTravelCostList();
|
|
|
|
|
// if (erpRdBudgetTravelCostList != null) {
|
|
|
|
|
// erpRdBudgetTravelCostList.forEach(erpRdBudgetTravelCost -> {
|
|
|
|
|
// erpRdBudgetTravelCost.setBudgetId(budgetId);
|
|
|
|
|
// erpRdBudgetTravelCost.setProjectId(projectId);
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// List<ErpRdBudgetMeetingCost> erpRdBudgetMeetingCostList = erpBudgetInfo.getErpRdBudgetMeetingCostList();
|
|
|
|
|
// if (erpRdBudgetMeetingCostList != null) {
|
|
|
|
|
// erpRdBudgetMeetingCostList.forEach(erpRdBudgetMeetingCost -> {
|
|
|
|
|
// erpRdBudgetMeetingCost.setBudgetId(budgetId);
|
|
|
|
|
// erpRdBudgetMeetingCost.setProjectId(projectId);
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// List<ErpRdBudgetExchangeCost> erpRdBudgetExchangeCostList = erpBudgetInfo.getErpRdBudgetExchangeCostList();
|
|
|
|
|
// if (erpRdBudgetExchangeCostList != null) {
|
|
|
|
|
// erpRdBudgetExchangeCostList.forEach(erpRdBudgetExchangeCost -> {
|
|
|
|
|
// erpRdBudgetExchangeCost.setBudgetId(budgetId);
|
|
|
|
|
// erpRdBudgetExchangeCost.setProjectId(projectId);
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// List<ErpRdBudgetTechCost> erpRdBudgetTechCostList = erpBudgetInfo.getErpRdBudgetTechCostList();
|
|
|
|
|
// if (erpRdBudgetTechCostList != null) {
|
|
|
|
|
// erpRdBudgetTechCostList.forEach(erpRdBudgetTechCost -> {
|
|
|
|
|
// erpRdBudgetTechCost.setBudgetId(budgetId);
|
|
|
|
|
// erpRdBudgetTechCost.setProjectId(projectId);
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// List<ErpRdBudgetLaborCost> erpRdBudgetLaborCostList = erpBudgetInfo.getErpRdBudgetLaborCostList();
|
|
|
|
|
// if (erpRdBudgetLaborCostList != null) {
|
|
|
|
|
// erpRdBudgetLaborCostList.forEach(erpRdBudgetLaborCost -> {
|
|
|
|
|
// erpRdBudgetLaborCost.setBudgetId(budgetId);
|
|
|
|
|
// erpRdBudgetLaborCost.setProjectId(projectId);
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// List<ErpRdBudgetLiteratureCost> erpRdBudgetLiteratureCostList = erpBudgetInfo.getErpRdBudgetLiteratureCostList();
|
|
|
|
|
// if (erpRdBudgetLiteratureCostList != null) {
|
|
|
|
|
// erpRdBudgetLiteratureCostList.forEach(erpRdBudgetLiteratureCost -> {
|
|
|
|
|
// erpRdBudgetLiteratureCost.setBudgetId(budgetId);
|
|
|
|
|
// erpRdBudgetLiteratureCost.setProjectId(projectId);
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// List<ErpRdBudgetTestingCost> erpRdBudgetTestingCostList = erpBudgetInfo.getErpRdBudgetTestingCostList();
|
|
|
|
|
// if (erpRdBudgetTestingCostList != null) {
|
|
|
|
|
// erpRdBudgetTestingCostList.forEach(erpRdBudgetTestingCost -> {
|
|
|
|
|
// erpRdBudgetTestingCost.setBudgetId(budgetId);
|
|
|
|
|
// erpRdBudgetTestingCost.setProjectId(projectId);
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// List<ErpRdBudgetOtherCost> erpRdBudgetOtherCostList = erpBudgetInfo.getErpRdBudgetOtherCostList();
|
|
|
|
|
// if (erpRdBudgetOtherCostList != null) {
|
|
|
|
|
// erpRdBudgetOtherCostList.forEach(erpRdBudgetOtherCost -> {
|
|
|
|
|
// erpRdBudgetOtherCost.setBudgetId(budgetId);
|
|
|
|
|
// erpRdBudgetOtherCost.setProjectId(projectId);
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// erpBudgetDetailMapper.insertOrUpdateBatch(erpBudgetDetailList);
|
|
|
|
|
// erpRdBudgetEquipmentCostMapper.insertOrUpdateBatch(erpRdBudgetEquipmentCostList);
|
|
|
|
|
// erpRdBudgetMaterialCostMapper.insertOrUpdateBatch(erpRdBudgetMaterialCostList);
|
|
|
|
|
// erpRdBudgetTravelCostMapper.insertOrUpdateBatch(erpRdBudgetTravelCostList);
|
|
|
|
|
// erpRdBudgetMeetingCostMapper.insertOrUpdateBatch(erpRdBudgetMeetingCostList);
|
|
|
|
|
// erpRdBudgetExchangeCostMapper.insertOrUpdateBatch(erpRdBudgetExchangeCostList);
|
|
|
|
|
// erpRdBudgetTechCostMapper.insertOrUpdateBatch(erpRdBudgetTechCostList);
|
|
|
|
|
// erpRdBudgetLaborCostMapper.insertOrUpdateBatch(erpRdBudgetLaborCostList);
|
|
|
|
|
// erpRdBudgetLiteratureCostMapper.insertOrUpdateBatch(erpRdBudgetLiteratureCostList);
|
|
|
|
|
// erpRdBudgetTestingCostMapper.insertOrUpdateBatch(erpRdBudgetTestingCostList);
|
|
|
|
|
// erpRdBudgetOtherCostMapper.insertOrUpdateBatch(erpRdBudgetOtherCostList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 处理预算明细信息
|
|
|
|
|
*
|
|
|
|
|
* @param erpBudgetInfo 预算信息
|
|
|
|
|
* @param budgetId 预算ID
|
|
|
|
|
*/
|
|
|
|
|
private void processRdBudgetDetails(ErpBudgetInfo erpBudgetInfo, Long budgetId) {
|
|
|
|
|
List<ErpBudgetDetail> detailList = erpBudgetInfo.getErpBudgetDetailList();
|
|
|
|
|
if (detailList != null && !detailList.isEmpty()) {
|
|
|
|
|
// log.debug("处理预算明细,数量: {}", detailList.size());
|
|
|
|
|
detailList.forEach(detail -> detail.setBudgetId(budgetId));
|
|
|
|
|
erpBudgetDetailMapper.insertOrUpdateBatch(detailList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 批量处理所有删除操作
|
|
|
|
|
* 使用批量执行减少数据库交互次数
|
|
|
|
|
*
|
|
|
|
|
* @param erpBudgetInfo 预算信息
|
|
|
|
|
*/
|
|
|
|
|
private void processRdBudgetDeletions(ErpBudgetInfo erpBudgetInfo) {
|
|
|
|
|
executeInBatch(() -> {
|
|
|
|
|
deleteIfNotEmpty(erpBudgetInfo.getToDeletedRdEquipmentCostIdList(),
|
|
|
|
|
erpRdBudgetEquipmentCostMapper::deleteByIds, "设备成本");
|
|
|
|
|
deleteIfNotEmpty(erpBudgetInfo.getToDeletedRdMaterialCostIdList(),
|
|
|
|
|
erpRdBudgetMaterialCostMapper::deleteByIds, "材料成本");
|
|
|
|
|
deleteIfNotEmpty(erpBudgetInfo.getToDeletedRdTravelCostIdList(),
|
|
|
|
|
erpRdBudgetTravelCostMapper::deleteByIds, "差旅成本");
|
|
|
|
|
deleteIfNotEmpty(erpBudgetInfo.getToDeletedRdMeetingCostIdList(),
|
|
|
|
|
erpRdBudgetMeetingCostMapper::deleteByIds, "会议成本");
|
|
|
|
|
deleteIfNotEmpty(erpBudgetInfo.getToDeletedRdExchangeCostIdList(),
|
|
|
|
|
erpRdBudgetExchangeCostMapper::deleteByIds, "交流成本");
|
|
|
|
|
deleteIfNotEmpty(erpBudgetInfo.getToDeletedRdTechCostIdList(),
|
|
|
|
|
erpRdBudgetTechCostMapper::deleteByIds, "技术成本");
|
|
|
|
|
deleteIfNotEmpty(erpBudgetInfo.getToDeletedRdLaborCostIdList(),
|
|
|
|
|
erpRdBudgetLaborCostMapper::deleteByIds, "人工成本");
|
|
|
|
|
deleteIfNotEmpty(erpBudgetInfo.getToDeletedRdLiteratureCostIdList(),
|
|
|
|
|
erpRdBudgetLiteratureCostMapper::deleteByIds, "文献成本");
|
|
|
|
|
deleteIfNotEmpty(erpBudgetInfo.getToDeletedRdTestingCostIdList(),
|
|
|
|
|
erpRdBudgetTestingCostMapper::deleteByIds, "测试成本");
|
|
|
|
|
deleteIfNotEmpty(erpBudgetInfo.getToDeletedRdOtherCostIdList(),
|
|
|
|
|
erpRdBudgetOtherCostMapper::deleteByIds, "其他成本");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 批量处理所有插入/更新操作
|
|
|
|
|
*
|
|
|
|
|
* @param erpBudgetInfo 预算信息
|
|
|
|
|
* @param budgetId 预算ID
|
|
|
|
|
* @param projectId 项目ID
|
|
|
|
|
*/
|
|
|
|
|
private void processRdBudgetInsertOrUpdates(ErpBudgetInfo erpBudgetInfo, Long budgetId, Long projectId) {
|
|
|
|
|
executeInBatch(() -> {
|
|
|
|
|
processCostList(erpBudgetInfo.getErpRdBudgetEquipmentCostList(), budgetId, projectId,
|
|
|
|
|
erpRdBudgetEquipmentCostMapper::insertOrUpdateBatch, ErpRdBudgetEquipmentCost.class);
|
|
|
|
|
processCostList(erpBudgetInfo.getErpRdBudgetMaterialCostList(), budgetId, projectId,
|
|
|
|
|
erpRdBudgetMaterialCostMapper::insertOrUpdateBatch, ErpRdBudgetMaterialCost.class);
|
|
|
|
|
processCostList(erpBudgetInfo.getErpRdBudgetTravelCostList(), budgetId, projectId,
|
|
|
|
|
erpRdBudgetTravelCostMapper::insertOrUpdateBatch, ErpRdBudgetTravelCost.class);
|
|
|
|
|
processCostList(erpBudgetInfo.getErpRdBudgetMeetingCostList(), budgetId, projectId,
|
|
|
|
|
erpRdBudgetMeetingCostMapper::insertOrUpdateBatch, ErpRdBudgetMeetingCost.class);
|
|
|
|
|
processCostList(erpBudgetInfo.getErpRdBudgetExchangeCostList(), budgetId, projectId,
|
|
|
|
|
erpRdBudgetExchangeCostMapper::insertOrUpdateBatch, ErpRdBudgetExchangeCost.class);
|
|
|
|
|
processCostList(erpBudgetInfo.getErpRdBudgetTechCostList(), budgetId, projectId,
|
|
|
|
|
erpRdBudgetTechCostMapper::insertOrUpdateBatch, ErpRdBudgetTechCost.class);
|
|
|
|
|
processCostList(erpBudgetInfo.getErpRdBudgetLaborCostList(), budgetId, projectId,
|
|
|
|
|
erpRdBudgetLaborCostMapper::insertOrUpdateBatch, ErpRdBudgetLaborCost.class);
|
|
|
|
|
processCostList(erpBudgetInfo.getErpRdBudgetLiteratureCostList(), budgetId, projectId,
|
|
|
|
|
erpRdBudgetLiteratureCostMapper::insertOrUpdateBatch, ErpRdBudgetLiteratureCost.class);
|
|
|
|
|
processCostList(erpBudgetInfo.getErpRdBudgetTestingCostList(), budgetId, projectId,
|
|
|
|
|
erpRdBudgetTestingCostMapper::insertOrUpdateBatch, ErpRdBudgetTestingCost.class);
|
|
|
|
|
processCostList(erpBudgetInfo.getErpRdBudgetOtherCostList(), budgetId, projectId,
|
|
|
|
|
erpRdBudgetOtherCostMapper::insertOrUpdateBatch, ErpRdBudgetOtherCost.class);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通用方法:处理成本列表数据
|
|
|
|
|
*
|
|
|
|
|
* @param costList 成本列表
|
|
|
|
|
* @param budgetId 预算ID
|
|
|
|
|
* @param projectId 项目ID
|
|
|
|
|
* @param saveFunction 保存函数
|
|
|
|
|
* @param clazz 成本类型Class
|
|
|
|
|
*/
|
|
|
|
|
private <T> void processCostList(List<T> costList, Long budgetId, Long projectId,
|
|
|
|
|
Consumer<List<T>> saveFunction, Class<T> clazz) {
|
|
|
|
|
if (costList != null && !costList.isEmpty()) {
|
|
|
|
|
// log.debug("处理{}成本数据,数量: {}", clazz.getSimpleName(), costList.size());
|
|
|
|
|
setBudgetAndProjectIds(costList, budgetId, projectId, clazz);
|
|
|
|
|
saveFunction.accept(costList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置预算ID和项目ID到成本对象
|
|
|
|
|
* 使用枚举方式避免大量的if-else判断
|
|
|
|
|
*
|
|
|
|
|
* @param costList 成本列表
|
|
|
|
|
* @param budgetId 预算ID
|
|
|
|
|
* @param projectId 项目ID
|
|
|
|
|
* @param clazz 成本类型Class
|
|
|
|
|
*/
|
|
|
|
|
private <T> void setBudgetAndProjectIds(List<T> costList, Long budgetId, Long projectId, Class<T> clazz) {
|
|
|
|
|
RdBudgetCostEnums rdBudgetCostEnums = RdBudgetCostEnums.fromClass(clazz);
|
|
|
|
|
if (rdBudgetCostEnums != null) {
|
|
|
|
|
costList.forEach(cost -> rdBudgetCostEnums.getSetter().accept(cost, budgetId, projectId));
|
|
|
|
|
} else {
|
|
|
|
|
// log.warn("未找到对应的CostType枚举,类名: {}", clazz.getName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 如果ID列表不为空则执行删除
|
|
|
|
|
*
|
|
|
|
|
* @param idList 要删除的ID列表
|
|
|
|
|
* @param deleteFunction 删除执行函数
|
|
|
|
|
* @param costTypeName 成本类型名称(用于日志)
|
|
|
|
|
*/
|
|
|
|
|
private void deleteIfNotEmpty(List<Long> idList, Consumer<List<Long>> deleteFunction, String costTypeName) {
|
|
|
|
|
if (idList != null && !idList.isEmpty()) {
|
|
|
|
|
// log.debug("删除{}数据,数量: {}", costTypeName, idList.size());
|
|
|
|
|
deleteFunction.accept(idList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 批量执行任务 - 预留批量操作扩展点
|
|
|
|
|
*
|
|
|
|
|
* @param task 要执行的任务
|
|
|
|
|
*/
|
|
|
|
|
private void executeInBatch(Runnable task) {
|
|
|
|
|
// 这里可以添加批量操作的相关优化,如批量提交、性能监控等
|
|
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
|
|
task.run();
|
|
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
|
|
// log.debug("批量操作执行完成,耗时: {}ms", endTime - startTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 校验并批量删除项目预算信息
|
|
|
|
|
*
|
|
|
|
|
|