|
|
@ -279,7 +279,6 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
batchItem.setUserName(sysUser.getName()); |
|
|
|
batchItem.setRemark(paramItem.getRemark()); |
|
|
|
batchItems.add(batchItem); |
|
|
|
|
|
|
|
}else { |
|
|
|
//修改后为新增类型提交
|
|
|
|
this.toUpdateBudgetInfo(batchId,sysUser, scheduleMap, subjectMap, centerDtoMap, categoryMap, paramItem, budgetId); |
|
|
@ -329,7 +328,9 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
return budgetBatch; |
|
|
|
} |
|
|
|
|
|
|
|
private void toUpdateBudgetInfo(Long batchId,SysUser sysUser, Map<String, TbsSchedule> scheduleMap, Map<String, BmsSubject> subjectMap, Map<String, TbsCenterDto> centerDtoMap, Map<String, GoodsCategory> categoryMap, TbsBudgetBatchBo.BudgetMain paramItem, Long budgetId) { |
|
|
|
private void toUpdateBudgetInfo(Long batchId,SysUser sysUser, Map<String, TbsSchedule> scheduleMap, |
|
|
|
Map<String, BmsSubject> subjectMap, Map<String, TbsCenterDto> centerDtoMap, |
|
|
|
Map<String, GoodsCategory> categoryMap, TbsBudgetBatchBo.BudgetMain paramItem, Long budgetId) { |
|
|
|
//tbsBudgetService.removeById(budgetId);
|
|
|
|
tbsBudgetConditionService.remove( |
|
|
|
new LambdaQueryWrapper<TbsBudgetCondition>() |
|
|
@ -363,19 +364,19 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
|
|
|
|
private void toSaveChangeCondition(Map<String, GoodsCategory> categoryMap, TbsBudget budget, TbsBudgetBatchBo.BudgetMain paramItem, Long budgetId, Long changeId) { |
|
|
|
if(budget.getConditionFlag().equals(1)){ |
|
|
|
List<TbsBudgetCondition> existingConditionList = tbsBudgetConditionService |
|
|
|
.list(new LambdaQueryWrapper<TbsBudgetCondition>() |
|
|
|
.eq(TbsBudgetCondition::getBudgetId, budgetId)); |
|
|
|
// List<TbsBudgetCondition> existingConditionList = tbsBudgetConditionService
|
|
|
|
// .list(new LambdaQueryWrapper<TbsBudgetCondition>()
|
|
|
|
// .eq(TbsBudgetCondition::getBudgetId, budgetId));
|
|
|
|
String bandNames = paramItem.getBrandNames(); |
|
|
|
String categoryNames = paramItem.getCategoryNames(); |
|
|
|
String seriesNames = paramItem.getSeriesNames(); |
|
|
|
//设置changeConditionList参数
|
|
|
|
List<TbsBudgetChangeCondition> changeConditionList = new ArrayList<>(); |
|
|
|
this.buildChangeConditionList(categoryMap, budgetId, changeId, changeConditionList, existingConditionList, |
|
|
|
this.buildChangeConditionList(categoryMap, budgetId, changeId, changeConditionList, null, |
|
|
|
bandNames, TbsGoodsType.brand.name()); |
|
|
|
this.buildChangeConditionList(categoryMap, budgetId, changeId, changeConditionList, existingConditionList, |
|
|
|
this.buildChangeConditionList(categoryMap, budgetId, changeId, changeConditionList, null, |
|
|
|
categoryNames, TbsGoodsType.category.name()); |
|
|
|
this.buildChangeConditionList(categoryMap, budgetId, changeId, changeConditionList, existingConditionList, |
|
|
|
this.buildChangeConditionList(categoryMap, budgetId, changeId, changeConditionList, null, |
|
|
|
seriesNames, TbsGoodsType.series.name()); |
|
|
|
if(CollUtil.isNotEmpty(changeConditionList)){ |
|
|
|
tbsBudgetChangeConditionService.saveBatch(changeConditionList); |
|
|
@ -407,18 +408,17 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
if(budgetAmount.getScheduleItemName().equals(itemBudget.getItemName())){ |
|
|
|
boolean ne1 = ! (itemBudget.getPreDispatchAmount().compareTo(budgetAmount.getPreDispatchAmount())==0); |
|
|
|
boolean ne2 = ! (realAmt.compareTo(budgetAmount.getBudgetAmount())==0); |
|
|
|
if(ne1 || ne2){ |
|
|
|
TbsBudgetChangeScheduleItem resultItem = TbsBudgetChangeScheduleItem.toNewObject(itemBudget); |
|
|
|
resultItem.setChangeId(changeId); |
|
|
|
resultItem.setBudgetAmount(realAmt); |
|
|
|
resultItem.setNewBudgetAmount(budgetAmount.getBudgetAmount()); |
|
|
|
resultItem.setNewPreDispatchAmount(budgetAmount.getPreDispatchAmount()); |
|
|
|
resultItem.setCategoryNames(paramItem.getCategoryNames()); |
|
|
|
resultItem.setBrandNames(paramItem.getBrandNames()); |
|
|
|
resultItem.setSeriesNames(paramItem.getSeriesNames()); |
|
|
|
resultItem.setRemark(paramItem.getRemark()); |
|
|
|
changeScheduleItemList.add(resultItem); |
|
|
|
} |
|
|
|
TbsBudgetChangeScheduleItem resultItem = TbsBudgetChangeScheduleItem.toNewObject(itemBudget); |
|
|
|
resultItem.setChangeId(changeId); |
|
|
|
resultItem.setBudgetAmount(realAmt); |
|
|
|
resultItem.setChangeFlag((ne1 || ne2)?1:0); |
|
|
|
resultItem.setNewBudgetAmount(budgetAmount.getBudgetAmount()); |
|
|
|
resultItem.setNewPreDispatchAmount(budgetAmount.getPreDispatchAmount()); |
|
|
|
resultItem.setCategoryNames(paramItem.getCategoryNames()); |
|
|
|
resultItem.setBrandNames(paramItem.getBrandNames()); |
|
|
|
resultItem.setSeriesNames(paramItem.getSeriesNames()); |
|
|
|
resultItem.setRemark(paramItem.getRemark()); |
|
|
|
changeScheduleItemList.add(resultItem); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -428,23 +428,18 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
if(StringUtils.hasText(values)){ |
|
|
|
String[] valueArr = values.replace(",",",").split(","); |
|
|
|
for (String val : valueArr) { |
|
|
|
boolean exist = existingConditionList.stream().anyMatch( |
|
|
|
a->a.getTargetName().equals(val)||a.getTargetCode().equals(val) |
|
|
|
); |
|
|
|
if(!exist){ |
|
|
|
GoodsCategory goodsCategory = categoryMap.get(val); |
|
|
|
if(goodsCategory!=null){ |
|
|
|
TbsBudgetChangeCondition budgetChangeCondition = new TbsBudgetChangeCondition(); |
|
|
|
budgetChangeCondition.setChangeId(changeId); |
|
|
|
budgetChangeCondition.setBudgetId(budgetId); |
|
|
|
budgetChangeCondition.setTargetType(targetType); |
|
|
|
budgetChangeCondition.setTargetId(goodsCategory.getId()); |
|
|
|
budgetChangeCondition.setTargetCode(goodsCategory.getCode()); |
|
|
|
budgetChangeCondition.setTargetName(goodsCategory.getName()); |
|
|
|
budgetChangeCondition.setTargetLevelPathIds(goodsCategory.getLevelPath()); |
|
|
|
budgetChangeCondition.setTargetLevelPathNames(goodsCategory.getLevelPathNames()); |
|
|
|
changeConditionList.add(budgetChangeCondition); |
|
|
|
} |
|
|
|
GoodsCategory goodsCategory = categoryMap.get(targetType+"_"+val); |
|
|
|
if(goodsCategory!=null){ |
|
|
|
TbsBudgetChangeCondition budgetChangeCondition = new TbsBudgetChangeCondition(); |
|
|
|
budgetChangeCondition.setChangeId(changeId); |
|
|
|
budgetChangeCondition.setBudgetId(budgetId); |
|
|
|
budgetChangeCondition.setTargetType(targetType); |
|
|
|
budgetChangeCondition.setTargetId(goodsCategory.getId()); |
|
|
|
budgetChangeCondition.setTargetCode(goodsCategory.getCode()); |
|
|
|
budgetChangeCondition.setTargetName(goodsCategory.getName()); |
|
|
|
budgetChangeCondition.setTargetLevelPathIds(goodsCategory.getLevelPath()); |
|
|
|
budgetChangeCondition.setTargetLevelPathNames(goodsCategory.getLevelPathNames()); |
|
|
|
changeConditionList.add(budgetChangeCondition); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -456,7 +451,7 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
if(StringUtils.hasText(paramItem.getBrandNames())){ |
|
|
|
String[] values = paramItem.getBrandNames().split(","); |
|
|
|
for (String value : values) { |
|
|
|
GoodsCategory category = categoryMap.get(value); |
|
|
|
GoodsCategory category = categoryMap.get(TbsGoodsType.brand.name()+"_"+value); |
|
|
|
TbsBudgetCondition budgetCondition = new TbsBudgetCondition(); |
|
|
|
budgetCondition.setBudgetId(budgetId); |
|
|
|
budgetCondition.setTargetType(TbsGoodsType.brand.name()); |
|
|
@ -471,7 +466,7 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
if(StringUtils.hasText(paramItem.getCategoryNames())){ |
|
|
|
String[] values = paramItem.getCategoryNames().split(","); |
|
|
|
for (String value : values) { |
|
|
|
GoodsCategory category = categoryMap.get(value); |
|
|
|
GoodsCategory category = categoryMap.get(TbsGoodsType.category.name()+"_"+value); |
|
|
|
TbsBudgetCondition budgetCondition = new TbsBudgetCondition(); |
|
|
|
budgetCondition.setBudgetId(budgetId); |
|
|
|
budgetCondition.setTargetType(TbsGoodsType.category.name()); |
|
|
@ -486,7 +481,7 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
if(StringUtils.hasText(paramItem.getSeriesNames())){ |
|
|
|
String[] values = paramItem.getSeriesNames().split(","); |
|
|
|
for (String value : values) { |
|
|
|
GoodsCategory category = categoryMap.get(value); |
|
|
|
GoodsCategory category = categoryMap.get(TbsGoodsType.series.name()+"_"+value); |
|
|
|
TbsBudgetCondition budgetCondition = new TbsBudgetCondition(); |
|
|
|
budgetCondition.setBudgetId(budgetId); |
|
|
|
budgetCondition.setTargetType(TbsGoodsType.series.name()); |
|
|
@ -567,120 +562,121 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
*/ |
|
|
|
private Map<String,GoodsCategory> loadGoodsCategoryMap(TbsBudgetBatchBo param) { |
|
|
|
List<TbsBudgetBatchBo.BudgetMain> paramBudgetList = param.getBudgetList(); |
|
|
|
Set<String> goodsCategoryNames = new HashSet<>(); |
|
|
|
//初始化三个维度的品类
|
|
|
|
List<String> allBandNameList = new ArrayList<>(), |
|
|
|
allCategoryNameList = new ArrayList<>(), |
|
|
|
allSeriesNameList = new ArrayList<>(); |
|
|
|
for (TbsBudgetBatchBo.BudgetMain budgetMain : paramBudgetList) { |
|
|
|
String bandNames = budgetMain.getBrandNames(); |
|
|
|
String categoryNames = budgetMain.getCategoryNames(); |
|
|
|
String seriesNames = budgetMain.getSeriesNames(); |
|
|
|
initCategorySet(goodsCategoryNames, bandNames); |
|
|
|
initCategorySet(goodsCategoryNames, categoryNames); |
|
|
|
initCategorySet(goodsCategoryNames, seriesNames); |
|
|
|
allBandNameList.addAll(initCategorySet(bandNames)); |
|
|
|
allCategoryNameList.addAll(initCategorySet(categoryNames)); |
|
|
|
allSeriesNameList.addAll(initCategorySet(seriesNames)); |
|
|
|
} |
|
|
|
if(goodsCategoryNames.size()<1){ |
|
|
|
if(CollUtil.isEmpty(allBandNameList) |
|
|
|
&& CollUtil.isEmpty(allCategoryNameList) |
|
|
|
&& CollUtil.isEmpty(allSeriesNameList)){ |
|
|
|
return new HashMap<>(); |
|
|
|
} |
|
|
|
List<GoodsCategory> goodsCategories = goodsCategoryService.list( |
|
|
|
new LambdaQueryWrapper<GoodsCategory>() |
|
|
|
.in(GoodsCategory::getName,goodsCategoryNames) |
|
|
|
.or() |
|
|
|
.in(GoodsCategory::getCode,goodsCategoryNames) |
|
|
|
); |
|
|
|
if(goodsCategories.size()!= goodsCategoryNames.size()){ |
|
|
|
for (String categoryName : goodsCategoryNames) { |
|
|
|
List<GoodsCategory> tempList = goodsCategories.stream() |
|
|
|
.filter(a->a.getName().equals(categoryName)).collect(Collectors.toList()); |
|
|
|
if(tempList.size()<1){ |
|
|
|
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){ |
|
|
|
budgetMain.getErrorInfos().add("无效的品牌:"+categoryName); |
|
|
|
param.setErrorFlag(true); |
|
|
|
break; |
|
|
|
} |
|
|
|
if(categoryNamesFlag){ |
|
|
|
budgetMain.getErrorInfos().add("无效的品类:"+categoryName); |
|
|
|
param.setErrorFlag(true); |
|
|
|
break; |
|
|
|
} |
|
|
|
if(seriesNamesFlag){ |
|
|
|
budgetMain.getErrorInfos().add("无效的系列:"+categoryName); |
|
|
|
param.setErrorFlag(true); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
//查询类目
|
|
|
|
List<GoodsCategory> bandList = this.queryCategory(1,allBandNameList); |
|
|
|
List<GoodsCategory> categoryList = this.queryCategory(2,allCategoryNameList); |
|
|
|
List<GoodsCategory> seriesList = this.queryCategory(3,allSeriesNameList); |
|
|
|
|
|
|
|
for (TbsBudgetBatchBo.BudgetMain budgetMain : paramBudgetList) { |
|
|
|
String bandNames = budgetMain.getBrandNames(); |
|
|
|
String categoryNames = budgetMain.getCategoryNames(); |
|
|
|
String seriesNames = budgetMain.getSeriesNames(); |
|
|
|
|
|
|
|
List<String> bandNameItemList = initCategorySet(bandNames); |
|
|
|
List<String> categoryNameItemList = initCategorySet(categoryNames); |
|
|
|
List<String> seriesNameItemList = initCategorySet(seriesNames); |
|
|
|
checkMchError(1,param, budgetMain,bandList, bandNameItemList); |
|
|
|
checkMchError(2,param, budgetMain,categoryList, categoryNameItemList); |
|
|
|
checkMchError(3,param, budgetMain,seriesList, seriesNameItemList); |
|
|
|
} |
|
|
|
|
|
|
|
Map<String,GoodsCategory> categoryMap = new HashMap<>(); |
|
|
|
for (GoodsCategory category : bandList) { |
|
|
|
categoryMap.put(TbsGoodsType.brand.name()+"_"+category.getName(),category); |
|
|
|
} |
|
|
|
for (GoodsCategory category : categoryList) { |
|
|
|
categoryMap.put(TbsGoodsType.category.name()+"_"+category.getName(),category); |
|
|
|
} |
|
|
|
for (GoodsCategory category : seriesList) { |
|
|
|
categoryMap.put(TbsGoodsType.series.name()+"_"+category.getName(),category); |
|
|
|
} |
|
|
|
return categoryMap; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验查询结果 |
|
|
|
* @param level |
|
|
|
* @param param |
|
|
|
* @param budgetMain |
|
|
|
* @param bandList |
|
|
|
* @param cateNames |
|
|
|
*/ |
|
|
|
private void checkMchError(int level,TbsBudgetBatchBo param, |
|
|
|
TbsBudgetBatchBo.BudgetMain budgetMain, |
|
|
|
List<GoodsCategory> bandList, |
|
|
|
List<String> cateNames) { |
|
|
|
for (String name : cateNames) { |
|
|
|
boolean mch = false; |
|
|
|
for (GoodsCategory category : bandList) { |
|
|
|
if(name.equals(category.getName())){ |
|
|
|
mch = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}else{ |
|
|
|
for (String categoryName : goodsCategoryNames) { |
|
|
|
List<GoodsCategory> tempList = goodsCategories.stream() |
|
|
|
.filter(a->a.getName().equals(categoryName)).collect(Collectors.toList()); |
|
|
|
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){ |
|
|
|
boolean isTrue = false; |
|
|
|
for (GoodsCategory category : tempList) { |
|
|
|
if(category.getLevel().equals(1)){ |
|
|
|
isTrue = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if(!isTrue){ |
|
|
|
budgetMain.getErrorInfos().add("无效的品牌:"+categoryName); |
|
|
|
param.setErrorFlag(true); |
|
|
|
} |
|
|
|
} |
|
|
|
if(categoryNamesFlag){ |
|
|
|
boolean isTrue = false; |
|
|
|
for (GoodsCategory category : tempList) { |
|
|
|
if(category.getLevel().equals(2)){ |
|
|
|
isTrue = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if(!isTrue){ |
|
|
|
budgetMain.getErrorInfos().add("无效的品类:"+categoryName); |
|
|
|
param.setErrorFlag(true); |
|
|
|
} |
|
|
|
} |
|
|
|
if(seriesNamesFlag){ |
|
|
|
boolean isTrue = false; |
|
|
|
for (GoodsCategory category : tempList) { |
|
|
|
if(category.getLevel().equals(3)){ |
|
|
|
isTrue = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if(!isTrue){ |
|
|
|
budgetMain.getErrorInfos().add("无效的系列:"+categoryName); |
|
|
|
param.setErrorFlag(true); |
|
|
|
} |
|
|
|
} |
|
|
|
if(!mch){ |
|
|
|
if(level==1){ |
|
|
|
budgetMain.getErrorInfos().add("无效的品牌:"+name); |
|
|
|
}else if (level==2){ |
|
|
|
budgetMain.getErrorInfos().add("无效的品类:"+name); |
|
|
|
}else { |
|
|
|
budgetMain.getErrorInfos().add("无效的系列:"+name); |
|
|
|
} |
|
|
|
param.setErrorFlag(true); |
|
|
|
} |
|
|
|
} |
|
|
|
Map<String,GoodsCategory> categoryMap = new HashMap<>(goodsCategories.size()); |
|
|
|
for (GoodsCategory category : goodsCategories) { |
|
|
|
categoryMap.put(category.getName(),category); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询品类 |
|
|
|
* @param level 等级1-品牌 2-类目 3-系列 |
|
|
|
* @param nameOrCodes |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private List<GoodsCategory> queryCategory(int level,List<String> nameOrCodes) { |
|
|
|
if(CollUtil.isEmpty(nameOrCodes)){ |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
return categoryMap; |
|
|
|
List<GoodsCategory> list = goodsCategoryService.list( |
|
|
|
new LambdaQueryWrapper<GoodsCategory>() |
|
|
|
.eq(GoodsCategory::getLevel,level) |
|
|
|
.and(cn->{ |
|
|
|
cn.in(GoodsCategory::getName,nameOrCodes) |
|
|
|
.or() |
|
|
|
.in(GoodsCategory::getCode,nameOrCodes); |
|
|
|
}) |
|
|
|
); |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 初始化set |
|
|
|
* @param goodsCategories |
|
|
|
* @param categoryString |
|
|
|
*/ |
|
|
|
private void initCategorySet(Set<String> goodsCategories, String categoryString) { |
|
|
|
private List<String> initCategorySet(String categoryString) { |
|
|
|
if(StringUtils.hasText(categoryString)){ |
|
|
|
String[] values = categoryString |
|
|
|
.replace(",",",") |
|
|
|
.split(","); |
|
|
|
goodsCategories.addAll(Arrays.asList(values)); |
|
|
|
return Arrays.asList(values); |
|
|
|
} |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
|
|
|
|
private Map<String,TbsSchedule> loadScheduleMap(List<String> scheduleNames,TbsBudgetBatchBo param) { |
|
|
|