|
|
@ -77,6 +77,11 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
String templateCode = TbsSeeYonConst.BudgetBatchApplyConf.Code(); |
|
|
|
//构建Batch
|
|
|
|
TbsBudgetBatch budgetBatch = buildBatchData(param, batchCode, sysUser); |
|
|
|
|
|
|
|
if(budgetBatch==null){ |
|
|
|
return param; |
|
|
|
} |
|
|
|
|
|
|
|
//保存后赋值
|
|
|
|
Long budgetBatchId = budgetBatch.getId(); |
|
|
|
|
|
|
@ -124,9 +129,34 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
return budgetBatch; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public TbsBudgetBatch buildBatchData(TbsBudgetBatchBo param,String batchCode,SysUser sysUser){ |
|
|
|
List<TbsBudgetBatchBo.BudgetMain> paramBudgetList = param.getBudgetList(); |
|
|
|
for (TbsBudgetBatchBo.BudgetMain budgetMain : paramBudgetList) { |
|
|
|
if(!StringUtils.hasText(budgetMain.getScheduleName())){ |
|
|
|
budgetMain.getErrorInfos().add("预算周期名称不能为空"); |
|
|
|
param.setErrorFlag(true); |
|
|
|
} |
|
|
|
if(!StringUtils.hasText(budgetMain.getBudgetName())){ |
|
|
|
budgetMain.getErrorInfos().add("预算名称不能为空"); |
|
|
|
param.setErrorFlag(true); |
|
|
|
} |
|
|
|
if(!StringUtils.hasText(budgetMain.getCenterType())){ |
|
|
|
budgetMain.getErrorInfos().add("成本中心类型不能为空"); |
|
|
|
param.setErrorFlag(true); |
|
|
|
} |
|
|
|
if(!StringUtils.hasText(budgetMain.getCenterType())){ |
|
|
|
budgetMain.getErrorInfos().add("成本中心不能为空"); |
|
|
|
param.setErrorFlag(true); |
|
|
|
} |
|
|
|
for (TbsBudgetBatchBo.BudgetAmount budgetAmount : budgetMain.getScheduleAmount()) { |
|
|
|
if(budgetAmount.getBudgetAmount()==null){ |
|
|
|
budgetAmount.setBudgetAmount(BigDecimal.ZERO); |
|
|
|
} |
|
|
|
if(budgetAmount.getPreDispatchAmount()==null){ |
|
|
|
budgetAmount.setPreDispatchAmount(BigDecimal.ZERO); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
TbsBudgetBatch budgetBatch = new TbsBudgetBatch(); |
|
|
|
budgetBatch.setBatchTitle(sysUser.getName()+"发起了批量导入预算"); |
|
|
|
budgetBatch.setBatchCode(batchCode); |
|
|
@ -142,18 +172,27 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
//加载 周期信息
|
|
|
|
List<String> scheduleNames = paramBudgetList.stream() |
|
|
|
.map(TbsBudgetBatchBo.BudgetMain::getScheduleName).distinct().collect(Collectors.toList()); |
|
|
|
Map<String,TbsSchedule> scheduleMap = loadScheduleMap(scheduleNames); |
|
|
|
Map<String,TbsSchedule> scheduleMap = loadScheduleMap(scheduleNames,param); |
|
|
|
//加载 科目
|
|
|
|
Map<String,BmsSubject> subjectMap = loadSubjectMapWithFilterInvalid(param); |
|
|
|
//加载 成本中心
|
|
|
|
Map<String,TbsCenterDto> centerDtoMap = new HashMap<>(); |
|
|
|
for (TbsBudgetBatchBo.BudgetMain budgetMain : paramBudgetList) { |
|
|
|
TbsCenterDto centerDto = tbsCenterDtoService.getCenterDtoByName(budgetMain.getCenterType(),budgetMain.getCenterName(),true); |
|
|
|
TbsCenterDto centerDto = tbsCenterDtoService.getCenterDtoByName(budgetMain.getCenterType(),budgetMain.getCenterName(),false); |
|
|
|
if(centerDto==null){ |
|
|
|
budgetMain.getErrorInfos().add("无效的成本中心:"+budgetMain.getCenterType()+" "+budgetMain.getCenterName()); |
|
|
|
param.setErrorFlag(true); |
|
|
|
} |
|
|
|
//key=> budgetMain.getCenterType()+"_&_"+budgetMain.getCenterName()
|
|
|
|
centerDtoMap.put(budgetMain.getCenterType()+"_&_"+budgetMain.getCenterName(),centerDto); |
|
|
|
} |
|
|
|
//加载 品类
|
|
|
|
Map<String,GoodsCategory> categoryMap = loadGoodsCategoryMap(paramBudgetList); |
|
|
|
Map<String,GoodsCategory> categoryMap = loadGoodsCategoryMap(param); |
|
|
|
|
|
|
|
//有错误信息退出
|
|
|
|
if(param.isErrorFlag()){ |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
//修改的生成为更变记录
|
|
|
|
List<TbsBudgetBatchBo.BudgetMain> updBudgetList = paramBudgetList.stream() |
|
|
@ -228,10 +267,10 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
.filter(a->!StringUtils.hasText(a.getBudgetNumber())).collect(Collectors.toList()); |
|
|
|
for (TbsBudgetBatchBo.BudgetMain budgetMain : addBudgetList) { |
|
|
|
TbsBudget newBudget = new TbsBudget(); |
|
|
|
tbsBudgetService.save(newBudget); |
|
|
|
Long budgetId = newBudget.getId(); |
|
|
|
TbsSchedule schedule = scheduleMap.get(budgetMain.getScheduleName()); |
|
|
|
this.initBudget4Update(sysUser,schedule, subjectMap, centerDtoMap, budgetMain, newBudget); |
|
|
|
tbsBudgetService.save(newBudget); |
|
|
|
Long budgetId = newBudget.getId(); |
|
|
|
//创建新条件
|
|
|
|
List<TbsBudgetCondition> conditionList = this.createTbsBudgetConditions(categoryMap, budgetMain, budgetId); |
|
|
|
//创建新预算周期
|
|
|
@ -271,6 +310,9 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
//设置新的值
|
|
|
|
TbsBudget newBudget = new TbsBudget(); |
|
|
|
newBudget.setId(budgetId); |
|
|
|
newBudget.setUserId(sysUser.getId()); |
|
|
|
newBudget.setUserCode(sysUser.getCode()); |
|
|
|
newBudget.setUserName(sysUser.getName()); |
|
|
|
TbsSchedule schedule = scheduleMap.get(paramItem.getScheduleName()); |
|
|
|
this.initBudget4Update(sysUser,schedule, subjectMap, centerDtoMap, paramItem, newBudget); |
|
|
|
//创建新条件
|
|
|
@ -290,7 +332,7 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
List<TbsBudgetCondition> existingConditionList = tbsBudgetConditionService |
|
|
|
.list(new LambdaQueryWrapper<TbsBudgetCondition>() |
|
|
|
.eq(TbsBudgetCondition::getBudgetId, budgetId)); |
|
|
|
String bandNames = paramItem.getBandNames(); |
|
|
|
String bandNames = paramItem.getBrandNames(); |
|
|
|
String categoryNames = paramItem.getCategoryNames(); |
|
|
|
String seriesNames = paramItem.getSeriesNames(); |
|
|
|
//设置changeConditionList参数
|
|
|
@ -372,8 +414,8 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
@NotNull |
|
|
|
private List<TbsBudgetCondition> createTbsBudgetConditions(Map<String, GoodsCategory> categoryMap, TbsBudgetBatchBo.BudgetMain paramItem, Long budgetId) { |
|
|
|
List<TbsBudgetCondition> conditionList = new ArrayList<>(); |
|
|
|
if(StringUtils.hasText(paramItem.getBandNames())){ |
|
|
|
String[] values = paramItem.getBandNames().split(","); |
|
|
|
if(StringUtils.hasText(paramItem.getBrandNames())){ |
|
|
|
String[] values = paramItem.getBrandNames().split(","); |
|
|
|
for (String value : values) { |
|
|
|
GoodsCategory category = categoryMap.get(value); |
|
|
|
TbsBudgetCondition budgetCondition = new TbsBudgetCondition(); |
|
|
@ -421,8 +463,8 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
newBudget.setBudgetNumber(paramItem.getBudgetNumber()); |
|
|
|
newBudget.setBudgetState(0); |
|
|
|
newBudget.setBudgetCheckState(TbsBudgetCheckState.State_1_apply); |
|
|
|
if(StringUtils.hasText(paramItem.getSubjectName())){ |
|
|
|
BmsSubject bmsSubject = subjectMap.get(paramItem.getSubjectName()); |
|
|
|
if(StringUtils.hasText(paramItem.getSubjectCode())){ |
|
|
|
BmsSubject bmsSubject = subjectMap.get(paramItem.getSubjectCode()); |
|
|
|
if(bmsSubject==null){ |
|
|
|
|
|
|
|
} |
|
|
@ -441,7 +483,7 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
newBudget.setScheduleName(schedule.getName()); |
|
|
|
boolean conditionFlag = StringUtils.hasText(paramItem.getCategoryNames()) |
|
|
|
||StringUtils.hasText(paramItem.getSeriesNames()) |
|
|
|
||StringUtils.hasText(paramItem.getBandNames()); |
|
|
|
||StringUtils.hasText(paramItem.getBrandNames()); |
|
|
|
newBudget.setConditionFlag(conditionFlag?0:1); |
|
|
|
newBudget.setUserId(sysUser.getId()); |
|
|
|
newBudget.setUserCode(sysUser.getCode()); |
|
|
@ -451,19 +493,23 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
|
|
|
|
/** |
|
|
|
* 加载类目 |
|
|
|
* @param paramBudgetList |
|
|
|
* @param param |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private Map<String,GoodsCategory> loadGoodsCategoryMap(List<TbsBudgetBatchBo.BudgetMain> paramBudgetList) { |
|
|
|
private Map<String,GoodsCategory> loadGoodsCategoryMap(TbsBudgetBatchBo param) { |
|
|
|
List<TbsBudgetBatchBo.BudgetMain> paramBudgetList = param.getBudgetList(); |
|
|
|
Set<String> goodsCategoryNames = new HashSet<>(); |
|
|
|
for (TbsBudgetBatchBo.BudgetMain budgetMain : paramBudgetList) { |
|
|
|
String bandNames = budgetMain.getBandNames(); |
|
|
|
String bandNames = budgetMain.getBrandNames(); |
|
|
|
String categoryNames = budgetMain.getCategoryNames(); |
|
|
|
String seriesNames = budgetMain.getSeriesNames(); |
|
|
|
initCategorySet(goodsCategoryNames, bandNames); |
|
|
|
initCategorySet(goodsCategoryNames, categoryNames); |
|
|
|
initCategorySet(goodsCategoryNames, seriesNames); |
|
|
|
} |
|
|
|
if(goodsCategoryNames.size()<1){ |
|
|
|
return new HashMap<>(); |
|
|
|
} |
|
|
|
List<GoodsCategory> goodsCategories = goodsCategoryService.list( |
|
|
|
new LambdaQueryWrapper<GoodsCategory>() |
|
|
|
.in(GoodsCategory::getName,goodsCategoryNames) |
|
|
@ -474,7 +520,16 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
for (String categoryName : goodsCategoryNames) { |
|
|
|
boolean exist = goodsCategories.stream().anyMatch(a->a.getName().equals(categoryName)); |
|
|
|
if(!exist){ |
|
|
|
Assert.throwEx("无效的品类:"+categoryName); |
|
|
|
//Assert.throwEx("无效的品类:"+categoryName);
|
|
|
|
for (TbsBudgetBatchBo.BudgetMain budgetMain : paramBudgetList) { |
|
|
|
boolean bandNamesFlag = budgetMain.getBrandNames() != null && budgetMain.getBrandNames().contains(categoryName); |
|
|
|
boolean categoryNamesFlag = budgetMain.getCategoryNames() != null && budgetMain.getCategoryNames().contains(categoryName); |
|
|
|
boolean seriesNamesFlag = budgetMain.getSeriesNames() != null && budgetMain.getSeriesNames().contains(categoryName); |
|
|
|
if(bandNamesFlag||categoryNamesFlag||seriesNamesFlag){ |
|
|
|
budgetMain.getErrorInfos().add("无效的品类:"+categoryName); |
|
|
|
param.setErrorFlag(true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -499,21 +554,41 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private Map<String,TbsSchedule> loadScheduleMap(List<String> scheduleNames) { |
|
|
|
private Map<String,TbsSchedule> loadScheduleMap(List<String> scheduleNames,TbsBudgetBatchBo param) { |
|
|
|
List<TbsSchedule> schedules = tbsScheduleService.list( |
|
|
|
new LambdaQueryWrapper<TbsSchedule>().in(TbsSchedule::getName, scheduleNames) |
|
|
|
); |
|
|
|
if(scheduleNames.size()!=schedules.size()){ |
|
|
|
for (String scheduleName : scheduleNames) { |
|
|
|
boolean exist = schedules.stream().anyMatch(a->a.getName().equals(scheduleName)); |
|
|
|
boolean exist = schedules.stream() |
|
|
|
.filter(b->b.getName()!=null) |
|
|
|
.anyMatch(a->a.getName().equals(scheduleName)); |
|
|
|
if(!exist){ |
|
|
|
Assert.throwEx("预算周期不存在:["+scheduleName+"]"); |
|
|
|
for (TbsBudgetBatchBo.BudgetMain budgetMain : param.getBudgetList()) { |
|
|
|
if(budgetMain.getScheduleName()!=null&&budgetMain.getScheduleName().equals(scheduleName)){ |
|
|
|
budgetMain.getErrorInfos().add("预算周期不存在:"+scheduleName); |
|
|
|
param.setErrorFlag(true); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Map<String,TbsSchedule> scheduleMap = new HashMap<>(scheduleNames.size()); |
|
|
|
for (TbsSchedule schedule : schedules) { |
|
|
|
List<TbsScheduleItem> scheduleItems = tbsScheduleItemService.listByScheduleId(schedule.getId()); |
|
|
|
for (TbsBudgetBatchBo.BudgetMain budgetMain : param.getBudgetList()) { |
|
|
|
if(budgetMain.getScheduleName().equals(schedule.getName())){ |
|
|
|
for (TbsBudgetBatchBo.BudgetAmount budgetAmount : budgetMain.getScheduleAmount()) { |
|
|
|
String scheduleItemName = budgetAmount.getScheduleItemName(); |
|
|
|
boolean exist = scheduleItems.stream().anyMatch(item -> scheduleItemName.equals(item.getItemName())); |
|
|
|
if(!exist){ |
|
|
|
budgetAmount.setErrorInfo("周期项不存在:"+scheduleItemName); |
|
|
|
param.setErrorFlag(true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
schedule.setScheduleItemlist(scheduleItems); |
|
|
|
scheduleMap.put(schedule.getName(),schedule); |
|
|
|
} |
|
|
@ -521,15 +596,15 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 加载param的所有科目(过滤无效的) |
|
|
|
* 加载param的所有科目 |
|
|
|
* @param param |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private Map<String,BmsSubject> loadSubjectMapWithFilterInvalid(TbsBudgetBatchBo param){ |
|
|
|
List<String> subjectCodes = param.getBudgetList().stream().filter(a->a.getSubjectName()!=null) |
|
|
|
.map(TbsBudgetBatchBo.BudgetMain::getSubjectName) |
|
|
|
List<String> subjectCodes = param.getBudgetList().stream().filter(a->StringUtils.hasText(a.getSubjectCode())) |
|
|
|
.map(TbsBudgetBatchBo.BudgetMain::getSubjectCode) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
return bmsSubjectService.loadByNameOrCode(subjectCodes,true); |
|
|
|
return bmsSubjectService.loadByCode(subjectCodes,param); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|