|
|
@ -19,6 +19,7 @@ import com.qs.serve.modules.tbs.common.TbsGoodsType; |
|
|
|
import com.qs.serve.modules.tbs.entity.*; |
|
|
|
import com.qs.serve.modules.tbs.entity.bo.TbsBudgetBo; |
|
|
|
import com.qs.serve.modules.tbs.entity.bo.TbsBudgetExcelBo; |
|
|
|
import com.qs.serve.modules.tbs.entity.vo.TbsBudgetVo; |
|
|
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetMapper; |
|
|
|
import com.qs.serve.modules.tbs.service.*; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
@ -29,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -48,6 +50,9 @@ public class TbsBudgetServiceImpl extends ServiceImpl<TbsBudgetMapper,TbsBudget> |
|
|
|
private final TbsScheduleItemService scheduleItemService; |
|
|
|
private final TbsCenterDtoService tbsCenterDtoService; |
|
|
|
|
|
|
|
private TbsBudgetConditionService tbsBudgetConditionService; |
|
|
|
private TbsScheduleItemBudgetService tbsScheduleItemBudgetService; |
|
|
|
|
|
|
|
private final GoodsSkuService goodsSkuService; |
|
|
|
private final GoodsSpuService goodsSpuService; |
|
|
|
private final GoodsCategoryService goodsCategoryService; |
|
|
@ -109,6 +114,139 @@ public class TbsBudgetServiceImpl extends ServiceImpl<TbsBudgetMapper,TbsBudget> |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public List<TbsBudgetExcelBo> listBudgetExcel(List<Long> budgetIds) { |
|
|
|
if (budgetIds==null||budgetIds.size()<1){ |
|
|
|
return null; |
|
|
|
} |
|
|
|
//考核期项
|
|
|
|
List<TbsBudget> budgetList = this.listByIds(budgetIds); |
|
|
|
LambdaQueryWrapper<TbsScheduleItemBudget> lqw2 = new LambdaQueryWrapper<>(); |
|
|
|
lqw2.in(TbsScheduleItemBudget::getBudgetId,budgetIds); |
|
|
|
List<TbsScheduleItemBudget> scheduleItemBudgets = tbsScheduleItemBudgetService.list(lqw2); |
|
|
|
Map<Long,List<TbsScheduleItemBudget>> listScheduleMapByBudgetId = scheduleItemBudgets.stream().collect(Collectors.groupingBy(TbsScheduleItemBudget::getBudgetId)); |
|
|
|
//加载条件
|
|
|
|
LambdaQueryWrapper<TbsBudgetCondition> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.in(TbsBudgetCondition::getBudgetId,budgetIds); |
|
|
|
List<TbsBudgetCondition> budgetConditions = tbsBudgetConditionService.list(lqw); |
|
|
|
Map<Long,List<TbsBudgetCondition>> listConditionMapByBudgetId = budgetConditions.stream().collect(Collectors.groupingBy(TbsBudgetCondition::getBudgetId)); |
|
|
|
//拼装
|
|
|
|
return budgetList.stream().map(budget->{ |
|
|
|
TbsBudgetExcelBo excelBo = new TbsBudgetExcelBo(); |
|
|
|
excelBo.setBudgetCode(budget.getBudgetCode()); |
|
|
|
excelBo.setSubjectName(budget.getSubjectName()); |
|
|
|
excelBo.setCenterType(budget.getCenterType()); |
|
|
|
excelBo.setCenterName(budget.getCenterName()); |
|
|
|
excelBo.setCenterCode(budget.getCenterCode()); |
|
|
|
excelBo.setScheduleName(budget.getScheduleName()); |
|
|
|
excelBo.setRemark(budget.getRemark()); |
|
|
|
|
|
|
|
//拼装条件
|
|
|
|
List<TbsBudgetCondition> budgetConditionsOfBudget = listConditionMapByBudgetId.get(budget.getId()); |
|
|
|
if(budgetConditionsOfBudget!=null){ |
|
|
|
Map<String,List<TbsBudgetCondition>> listMap = budgetConditionsOfBudget.stream().collect(Collectors.groupingBy(TbsBudgetCondition::getTargetType)); |
|
|
|
List<TbsBudgetCondition> brandConditions = listMap.get(TbsGoodsType.brand.name()); |
|
|
|
List<TbsBudgetCondition> categoryConditions = listMap.get(TbsGoodsType.category.name()); |
|
|
|
List<TbsBudgetCondition> seriesConditions = listMap.get(TbsGoodsType.series.name()); |
|
|
|
List<TbsBudgetCondition> spuConditions = listMap.get(TbsGoodsType.spu.name()); |
|
|
|
List<TbsBudgetCondition> skuConditions = listMap.get(TbsGoodsType.sku.name()); |
|
|
|
|
|
|
|
excelBo.setBrandNames(getConditionNames(brandConditions)); |
|
|
|
excelBo.setCategoryNames(getConditionNames(categoryConditions)); |
|
|
|
excelBo.setSeriesNames(getConditionNames(seriesConditions)); |
|
|
|
excelBo.setSpuNames(getConditionNames(spuConditions)); |
|
|
|
excelBo.setSkuCodes(getConditionCodes(skuConditions)); |
|
|
|
} |
|
|
|
|
|
|
|
//拼装考核期项
|
|
|
|
List<TbsScheduleItemBudget> scheduleItemBudgetList = listScheduleMapByBudgetId.get(budget.getId()); |
|
|
|
if(scheduleItemBudgetList!=null){ |
|
|
|
for (TbsScheduleItemBudget itemBudget : scheduleItemBudgetList) { |
|
|
|
if(itemBudget.getItemName().equals("M1")){ |
|
|
|
excelBo.setAmountM1(itemBudget.getBudgetAmount()); |
|
|
|
}else if (itemBudget.getItemName().equals("M2")){ |
|
|
|
excelBo.setAmountM2(itemBudget.getBudgetAmount()); |
|
|
|
}else if (itemBudget.getItemName().equals("M3")){ |
|
|
|
excelBo.setAmountM3(itemBudget.getBudgetAmount()); |
|
|
|
}else if (itemBudget.getItemName().equals("M4")){ |
|
|
|
excelBo.setAmountM4(itemBudget.getBudgetAmount()); |
|
|
|
}else if (itemBudget.getItemName().equals("M5")){ |
|
|
|
excelBo.setAmountM5(itemBudget.getBudgetAmount()); |
|
|
|
}else if (itemBudget.getItemName().equals("M6")){ |
|
|
|
excelBo.setAmountM6(itemBudget.getBudgetAmount()); |
|
|
|
}else if (itemBudget.getItemName().equals("M7")){ |
|
|
|
excelBo.setAmountM7(itemBudget.getBudgetAmount()); |
|
|
|
}else if (itemBudget.getItemName().equals("M8")){ |
|
|
|
excelBo.setAmountM8(itemBudget.getBudgetAmount()); |
|
|
|
}else if (itemBudget.getItemName().equals("M9")){ |
|
|
|
excelBo.setAmountM9(itemBudget.getBudgetAmount()); |
|
|
|
}else if (itemBudget.getItemName().equals("M10")){ |
|
|
|
excelBo.setAmountM10(itemBudget.getBudgetAmount()); |
|
|
|
}else if (itemBudget.getItemName().equals("M11")){ |
|
|
|
excelBo.setAmountM11(itemBudget.getBudgetAmount()); |
|
|
|
}else if (itemBudget.getItemName().equals("M12")){ |
|
|
|
excelBo.setAmountM12(itemBudget.getBudgetAmount()); |
|
|
|
}else if (itemBudget.getItemName().equals("Q1")){ |
|
|
|
excelBo.setAmountQ1(itemBudget.getBudgetAmount()); |
|
|
|
}else if (itemBudget.getItemName().equals("Q2")){ |
|
|
|
excelBo.setAmountQ2(itemBudget.getBudgetAmount()); |
|
|
|
}else if (itemBudget.getItemName().equals("Q3")){ |
|
|
|
excelBo.setAmountQ3(itemBudget.getBudgetAmount()); |
|
|
|
}else if (itemBudget.getItemName().equals("Q4")){ |
|
|
|
excelBo.setAmountQ4(itemBudget.getBudgetAmount()); |
|
|
|
}else if (itemBudget.getItemName().equals("Y")){ |
|
|
|
excelBo.setAmountYear(itemBudget.getBudgetAmount()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return excelBo; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
|
|
|
|
private List<String> getConditionNames(List<TbsBudgetCondition> conditions){ |
|
|
|
if(CollectionUtil.isNotEmpty(conditions)){ |
|
|
|
return conditions.stream().map(TbsBudgetCondition::getTargetName).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
private List<String> getConditionCodes(List<TbsBudgetCondition> conditions){ |
|
|
|
if(CollectionUtil.isNotEmpty(conditions)){ |
|
|
|
return conditions.stream().map(TbsBudgetCondition::getTargetCode).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public TbsBudgetVo toVoEntity(TbsBudget budget) { |
|
|
|
LambdaQueryWrapper<TbsBudgetCondition> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(TbsBudgetCondition::getBudgetId,budget.getId()); |
|
|
|
List<TbsBudgetCondition> budgetConditions = tbsBudgetConditionService.list(lqw); |
|
|
|
Map<String,List<TbsBudgetCondition>> listMap = budgetConditions.stream().collect(Collectors.groupingBy(TbsBudgetCondition::getTargetType)); |
|
|
|
TbsBudgetVo budgetVo = CopierUtil.copy(budget,new TbsBudgetVo()); |
|
|
|
budgetVo.setBrandConditions(listMap.get(TbsGoodsType.brand.name())); |
|
|
|
budgetVo.setCategoryConditions(listMap.get(TbsGoodsType.category.name())); |
|
|
|
budgetVo.setSeriesConditions(listMap.get(TbsGoodsType.series.name())); |
|
|
|
List<TbsBudgetCondition> skuCondition = listMap.get(TbsGoodsType.sku.name()); |
|
|
|
if(skuCondition!=null){ |
|
|
|
for (TbsBudgetCondition budgetCondition : skuCondition) { |
|
|
|
try { |
|
|
|
String[] names = budgetCondition.getTargetLevelPathNames().split("_"); |
|
|
|
budgetCondition.setSkuName(names[names.length-1]); |
|
|
|
budgetCondition.setSpuName(names[names.length-2]); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("格式错误:{}",budgetCondition.getTargetLevelPathNames()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
budgetVo.setSkuConditions(skuCondition); |
|
|
|
budgetVo.setSpuConditions(listMap.get(TbsGoodsType.spu.name())); |
|
|
|
LambdaQueryWrapper<TbsScheduleItemBudget> lqw2 = new LambdaQueryWrapper<>(); |
|
|
|
lqw2.eq(TbsScheduleItemBudget::getBudgetId,budget.getId()); |
|
|
|
List<TbsScheduleItemBudget> scheduleItemBudgets = tbsScheduleItemBudgetService.list(lqw2); |
|
|
|
budgetVo.setScheduleItem(scheduleItemBudgets); |
|
|
|
return budgetVo; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 建立类目条件 |
|
|
@ -141,9 +279,9 @@ public class TbsBudgetServiceImpl extends ServiceImpl<TbsBudgetMapper,TbsBudget> |
|
|
|
public void modifyByExcel(TbsBudgetExcelBo budgetBo) { |
|
|
|
TbsBudget budget = this.getByCode(budgetBo.getBudgetCode()); |
|
|
|
if(budget!=null){ |
|
|
|
if(budget.getBudgetState().equals(1)){ |
|
|
|
Assert.throwEx("已开启的预算无法编辑"); |
|
|
|
} |
|
|
|
// if(budget.getBudgetState().equals(1)){
|
|
|
|
// Assert.throwEx("已开启的预算无法编辑");
|
|
|
|
// }
|
|
|
|
}else { |
|
|
|
budget = new TbsBudget(); |
|
|
|
budget.setBudgetCode(budgetBo.getBudgetCode()); |
|
|
@ -151,7 +289,7 @@ public class TbsBudgetServiceImpl extends ServiceImpl<TbsBudgetMapper,TbsBudget> |
|
|
|
List<Long> skuIds = null; |
|
|
|
List<Long> spuIds = null; |
|
|
|
if(CollectionUtil.isNotEmpty(budgetBo.getSkuCodes())){ |
|
|
|
List<GoodsSku> goodsSkus = goodsSkuService.listByIds(budgetBo.getSkuCodes()); |
|
|
|
List<GoodsSku> goodsSkus = goodsSkuService.getByCodes(budgetBo.getSkuCodes()); |
|
|
|
if(goodsSkus.size()!=budgetBo.getSkuCodes().size()){ |
|
|
|
Assert.throwEx("部分存货编码不存在"); |
|
|
|
} |
|
|
@ -168,15 +306,15 @@ public class TbsBudgetServiceImpl extends ServiceImpl<TbsBudgetMapper,TbsBudget> |
|
|
|
} |
|
|
|
} |
|
|
|
List<Long> brandIds = this.selectCategory(budgetBo.getBrandNames(),1); |
|
|
|
List<Long> categoryIds = this.selectCategory(budgetBo.getBrandNames(),2); |
|
|
|
List<Long> seriesIds = this.selectCategory(budgetBo.getBrandNames(),3); |
|
|
|
List<Long> categoryIds = this.selectCategory(budgetBo.getCategoryNames(),2); |
|
|
|
List<Long> seriesIds = this.selectCategory(budgetBo.getSeriesNames(),3); |
|
|
|
|
|
|
|
BmsSubject subject = subjectService.getByName(budgetBo.getSubjectName()); |
|
|
|
TbsCenterDto centerDto = tbsCenterDtoService.getCenterDtoByName( |
|
|
|
budgetBo.getCenterType(), |
|
|
|
budgetBo.getCenterName(), |
|
|
|
budgetBo.getBudgetCode(), |
|
|
|
budgetBo.getCenterRegionLevel()); |
|
|
|
null); |
|
|
|
TbsSchedule schedule = scheduleService.getByName(budgetBo.getScheduleName()); |
|
|
|
initEmptyBudget(budget,subject,centerDto,schedule); |
|
|
|
//保存 费用项
|
|
|
@ -241,7 +379,7 @@ public class TbsBudgetServiceImpl extends ServiceImpl<TbsBudgetMapper,TbsBudget> |
|
|
|
if(level==1){ |
|
|
|
Assert.throwEx("品牌["+name+"]不存在"); |
|
|
|
}else if (level==2){ |
|
|
|
Assert.throwEx("品牌["+name+"]不存在"); |
|
|
|
Assert.throwEx("分类["+name+"]不存在"); |
|
|
|
}else if (level==3){ |
|
|
|
Assert.throwEx("系列["+name+"]不存在"); |
|
|
|
} |
|
|
|