|
|
@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.qs.serve.common.util.Assert; |
|
|
|
import com.qs.serve.common.util.CollectionUtil; |
|
|
|
import com.qs.serve.common.util.CopierUtil; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsCostCenter; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsSubject; |
|
|
|
import com.qs.serve.modules.bms.service.BmsCostCenterService; |
|
|
|
import com.qs.serve.modules.bms.service.BmsSubjectService; |
|
|
@ -18,16 +17,18 @@ import com.qs.serve.modules.goods.service.GoodsSkuService; |
|
|
|
import com.qs.serve.modules.goods.service.GoodsSpuService; |
|
|
|
import com.qs.serve.modules.tbs.common.TbsGoodsType; |
|
|
|
import com.qs.serve.modules.tbs.entity.*; |
|
|
|
import com.qs.serve.modules.tbs.entity.bo.TbsActivityGoodsBo; |
|
|
|
import com.qs.serve.modules.tbs.entity.bo.TbsBudgetBo; |
|
|
|
import com.qs.serve.modules.tbs.entity.bo.TbsBudgetExcelBo; |
|
|
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetMapper; |
|
|
|
import com.qs.serve.modules.tbs.service.*; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetMapper; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -41,8 +42,6 @@ import java.util.stream.Collectors; |
|
|
|
public class TbsBudgetServiceImpl extends ServiceImpl<TbsBudgetMapper,TbsBudget> implements TbsBudgetService { |
|
|
|
|
|
|
|
private final BmsSubjectService subjectService; |
|
|
|
private final BmsCostCenterService costCenterService; |
|
|
|
|
|
|
|
private final TbsScheduleService scheduleService; |
|
|
|
private final TbsBudgetConditionService budgetConditionService; |
|
|
|
private final TbsScheduleItemBudgetService scheduleItemBudgetService; |
|
|
@ -63,33 +62,16 @@ public class TbsBudgetServiceImpl extends ServiceImpl<TbsBudgetMapper,TbsBudget> |
|
|
|
if(budget==null){ |
|
|
|
Assert.throwEx("预算不存在或被移除"); |
|
|
|
} |
|
|
|
if(budget.getBudgetState().equals(1)){ |
|
|
|
Assert.throwEx("已开启的预算无法编辑"); |
|
|
|
} |
|
|
|
}else { |
|
|
|
budget = CopierUtil.copy(budgetBo,new TbsBudget()); |
|
|
|
} |
|
|
|
BmsSubject subject = subjectService.getById(budgetBo.getSubjectId()); |
|
|
|
TbsCenterDto centerDto = tbsCenterDtoService.getCenterDto(budgetBo.getCenterType(),budgetBo.getCenterId()); |
|
|
|
TbsSchedule schedule = scheduleService.getById(budgetBo.getScheduleId()); |
|
|
|
budget.setSubjectId(subject.getId()); |
|
|
|
budget.setSubjectCode(subject.getSubjectCode()); |
|
|
|
budget.setSubjectName(subject.getSubjectName()); |
|
|
|
budget.setCenterId(centerDto.getId()); |
|
|
|
budget.setCenterCode(centerDto.getCenterCode()); |
|
|
|
budget.setCenterName(centerDto.getCenterName()); |
|
|
|
budget.setScheduleId(schedule.getId()); |
|
|
|
budget.setScheduleCode(schedule.getCode()); |
|
|
|
budget.setScheduleName(schedule.getName()); |
|
|
|
//删除条件
|
|
|
|
if(budget.getId()!=null){ |
|
|
|
LambdaQueryWrapper<TbsBudgetCondition> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(TbsBudgetCondition::getBudgetId,budget.getId()); |
|
|
|
budgetConditionService.remove(lqw); |
|
|
|
//删除 费用项
|
|
|
|
LambdaQueryWrapper<TbsScheduleItemBudget> lqw2 = new LambdaQueryWrapper<>(); |
|
|
|
lqw2.eq(TbsScheduleItemBudget::getBudgetId,budget.getId()); |
|
|
|
scheduleItemBudgetService.remove(lqw2); |
|
|
|
} |
|
|
|
this.saveOrUpdate(budget); |
|
|
|
|
|
|
|
initEmptyBudget(budget,subject,centerDto,schedule); |
|
|
|
//保存 费用项
|
|
|
|
List<TbsScheduleItem> scheduleItems = scheduleItemService.listByScheduleId(schedule.getId()); |
|
|
|
List<TbsScheduleItemBudget> scheduleItemBudgets = new ArrayList<>(); |
|
|
@ -111,16 +93,222 @@ public class TbsBudgetServiceImpl extends ServiceImpl<TbsBudgetMapper,TbsBudget> |
|
|
|
} |
|
|
|
scheduleItemBudgetService.saveBatch(scheduleItemBudgets); |
|
|
|
//设置条件
|
|
|
|
List<Long> skuIds = budgetBo.getSkuIds(); |
|
|
|
List<Long> spuIds = budgetBo.getSpuIds(); |
|
|
|
List<Long> seriesIds = budgetBo.getSeriesIds(); |
|
|
|
List<Long> brandIds = budgetBo.getBrandIds(); |
|
|
|
List<Long> categoryIds = budgetBo.getCategoryIds(); |
|
|
|
buildCondition(budget.getId(),brandIds,categoryIds,seriesIds,spuIds,skuIds); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public TbsBudget getByCode(String code) { |
|
|
|
LambdaQueryWrapper<TbsBudget> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(TbsBudget::getBudgetCode,code); |
|
|
|
return getOne(lqw,false); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 建立类目条件 |
|
|
|
* @param budgetId |
|
|
|
* @param categoryIds |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public List<TbsBudgetCondition> buildCategoryCondition(Long budgetId,List<Long> categoryIds,String targetType){ |
|
|
|
List<TbsBudgetCondition> budgetConditions = new ArrayList<>(); |
|
|
|
if(CollectionUtil.isNotEmpty(categoryIds)){ |
|
|
|
List<GoodsCategory> categoryList = goodsCategoryService.listByIds(categoryIds); |
|
|
|
for (GoodsCategory category : categoryList) { |
|
|
|
TbsBudgetCondition condition = new TbsBudgetCondition(); |
|
|
|
condition.setBudgetId(budgetId); |
|
|
|
condition.setTargetType(targetType); |
|
|
|
condition.setTargetId(category.getId()); |
|
|
|
condition.setTargetCode(category.getCode()); |
|
|
|
condition.setTargetName(category.getName()); |
|
|
|
condition.setTargetLevelPathIds(category.getLevelPath()); |
|
|
|
condition.setTargetLevelPathNames(category.getLevelPathNames()); |
|
|
|
budgetConditions.add(condition); |
|
|
|
} |
|
|
|
} |
|
|
|
return budgetConditions; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void modifyByExcel(TbsBudgetExcelBo budgetBo) { |
|
|
|
TbsBudget budget = this.getByCode(budgetBo.getBudgetCode()); |
|
|
|
if(budget!=null){ |
|
|
|
if(budget.getBudgetState().equals(1)){ |
|
|
|
Assert.throwEx("已开启的预算无法编辑"); |
|
|
|
} |
|
|
|
}else { |
|
|
|
budget = new TbsBudget(); |
|
|
|
budget.setBudgetCode(budgetBo.getBudgetCode()); |
|
|
|
} |
|
|
|
List<Long> skuIds = null; |
|
|
|
List<Long> spuIds = null; |
|
|
|
if(CollectionUtil.isNotEmpty(budgetBo.getSkuCodes())){ |
|
|
|
List<GoodsSku> goodsSkus = goodsSkuService.listByIds(budgetBo.getSkuCodes()); |
|
|
|
if(goodsSkus.size()!=budgetBo.getSkuCodes().size()){ |
|
|
|
Assert.throwEx("部分存货编码不存在"); |
|
|
|
} |
|
|
|
skuIds = goodsSkus.stream().map(GoodsSku::getId).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
if(CollectionUtil.isNotEmpty(budgetBo.getSpuNames())){ |
|
|
|
spuIds = new ArrayList<>(); |
|
|
|
for (String spuName : budgetBo.getSpuNames()) { |
|
|
|
GoodsSpu goodsSpu = goodsSpuService.getByName(spuName); |
|
|
|
if(goodsSpu==null){ |
|
|
|
Assert.throwEx("["+spuName+"]单品不存在"); |
|
|
|
} |
|
|
|
spuIds.add(goodsSpu.getId()); |
|
|
|
} |
|
|
|
} |
|
|
|
List<Long> brandIds = this.selectCategory(budgetBo.getBrandNames(),1); |
|
|
|
List<Long> categoryIds = this.selectCategory(budgetBo.getBrandNames(),2); |
|
|
|
List<Long> seriesIds = this.selectCategory(budgetBo.getBrandNames(),3); |
|
|
|
|
|
|
|
BmsSubject subject = subjectService.getByName(budgetBo.getSubjectName()); |
|
|
|
TbsCenterDto centerDto = tbsCenterDtoService.getCenterDtoByName( |
|
|
|
budgetBo.getCenterType(), |
|
|
|
budgetBo.getCenterName(), |
|
|
|
budgetBo.getBudgetCode(), |
|
|
|
budgetBo.getCenterRegionLevel()); |
|
|
|
TbsSchedule schedule = scheduleService.getByName(budgetBo.getScheduleName()); |
|
|
|
initEmptyBudget(budget,subject,centerDto,schedule); |
|
|
|
//保存 费用项
|
|
|
|
List<TbsScheduleItem> scheduleItems = scheduleItemService.listByScheduleId(schedule.getId()); |
|
|
|
List<TbsScheduleItemBudget> scheduleItemBudgets = new ArrayList<>(); |
|
|
|
for (TbsScheduleItem scheduleItem : scheduleItems) { |
|
|
|
TbsScheduleItemBudget itemBudget = CopierUtil.copy(scheduleItem,new TbsScheduleItemBudget()); |
|
|
|
itemBudget.setId(null); |
|
|
|
itemBudget.setScheduleItemId(scheduleItem.getId()); |
|
|
|
itemBudget.setBudgetId(budget.getId()); |
|
|
|
if(scheduleItem.getItemName().equals("M1")){ |
|
|
|
itemBudget.setBudgetAmount(budgetBo.getAmountM1()); |
|
|
|
}else if (scheduleItem.getItemName().equals("M2")){ |
|
|
|
itemBudget.setBudgetAmount(budgetBo.getAmountM2()); |
|
|
|
}else if (scheduleItem.getItemName().equals("M3")){ |
|
|
|
itemBudget.setBudgetAmount(budgetBo.getAmountM3()); |
|
|
|
}else if (scheduleItem.getItemName().equals("M4")){ |
|
|
|
itemBudget.setBudgetAmount(budgetBo.getAmountM4()); |
|
|
|
}else if (scheduleItem.getItemName().equals("M5")){ |
|
|
|
itemBudget.setBudgetAmount(budgetBo.getAmountM5()); |
|
|
|
}else if (scheduleItem.getItemName().equals("M6")){ |
|
|
|
itemBudget.setBudgetAmount(budgetBo.getAmountM6()); |
|
|
|
}else if (scheduleItem.getItemName().equals("M7")){ |
|
|
|
itemBudget.setBudgetAmount(budgetBo.getAmountM7()); |
|
|
|
}else if (scheduleItem.getItemName().equals("M8")){ |
|
|
|
itemBudget.setBudgetAmount(budgetBo.getAmountM8()); |
|
|
|
}else if (scheduleItem.getItemName().equals("M9")){ |
|
|
|
itemBudget.setBudgetAmount(budgetBo.getAmountM9()); |
|
|
|
}else if (scheduleItem.getItemName().equals("M10")){ |
|
|
|
itemBudget.setBudgetAmount(budgetBo.getAmountM10()); |
|
|
|
}else if (scheduleItem.getItemName().equals("M11")){ |
|
|
|
itemBudget.setBudgetAmount(budgetBo.getAmountM11()); |
|
|
|
}else if (scheduleItem.getItemName().equals("M12")){ |
|
|
|
itemBudget.setBudgetAmount(budgetBo.getAmountM12()); |
|
|
|
}else if (scheduleItem.getItemName().equals("Q1")){ |
|
|
|
itemBudget.setBudgetAmount(budgetBo.getAmountQ1()); |
|
|
|
}else if (scheduleItem.getItemName().equals("Q2")){ |
|
|
|
itemBudget.setBudgetAmount(budgetBo.getAmountQ2()); |
|
|
|
}else if (scheduleItem.getItemName().equals("Q3")){ |
|
|
|
itemBudget.setBudgetAmount(budgetBo.getAmountQ3()); |
|
|
|
}else if (scheduleItem.getItemName().equals("Q4")){ |
|
|
|
itemBudget.setBudgetAmount(budgetBo.getAmountQ4()); |
|
|
|
}else if (scheduleItem.getItemName().equals("Y")){ |
|
|
|
itemBudget.setBudgetAmount(budgetBo.getAmountYear()); |
|
|
|
} |
|
|
|
if(itemBudget.getBudgetAmount()==null){ |
|
|
|
itemBudget.setBudgetAmount(BigDecimal.ZERO); |
|
|
|
} |
|
|
|
scheduleItemBudgets.add(itemBudget); |
|
|
|
} |
|
|
|
scheduleItemBudgetService.saveBatch(scheduleItemBudgets); |
|
|
|
//设置条件
|
|
|
|
buildCondition(budget.getId(),brandIds,categoryIds,seriesIds,spuIds,skuIds); |
|
|
|
} |
|
|
|
|
|
|
|
private List<Long> selectCategory(List<String> names,Integer level){ |
|
|
|
if(CollectionUtil.isNotEmpty(names)){ |
|
|
|
List<Long> ids = new ArrayList<>(); |
|
|
|
for (String name : names) { |
|
|
|
GoodsCategory category = goodsCategoryService.getByName(name,level); |
|
|
|
if(category==null){ |
|
|
|
if(level==1){ |
|
|
|
Assert.throwEx("品牌["+name+"]不存在"); |
|
|
|
}else if (level==2){ |
|
|
|
Assert.throwEx("品牌["+name+"]不存在"); |
|
|
|
}else if (level==3){ |
|
|
|
Assert.throwEx("系列["+name+"]不存在"); |
|
|
|
} |
|
|
|
} |
|
|
|
ids.add(category.getId()); |
|
|
|
} |
|
|
|
return ids; |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 初始化空预算 |
|
|
|
* @param budget |
|
|
|
* @param subject |
|
|
|
* @param centerDto |
|
|
|
* @param schedule |
|
|
|
*/ |
|
|
|
private void initEmptyBudget(TbsBudget budget,BmsSubject subject,TbsCenterDto centerDto,TbsSchedule schedule){ |
|
|
|
if(subject==null){ |
|
|
|
Assert.throwEx("科目不存在"); |
|
|
|
} |
|
|
|
if(schedule==null){ |
|
|
|
Assert.throwEx("考核期不存在"); |
|
|
|
} |
|
|
|
budget.setSubjectId(subject.getId()); |
|
|
|
budget.setSubjectCode(subject.getSubjectCode()); |
|
|
|
budget.setSubjectName(subject.getSubjectName()); |
|
|
|
budget.setCenterId(centerDto.getId()); |
|
|
|
budget.setCenterCode(centerDto.getCenterCode()); |
|
|
|
budget.setCenterName(centerDto.getCenterName()); |
|
|
|
budget.setScheduleId(schedule.getId()); |
|
|
|
budget.setScheduleCode(schedule.getCode()); |
|
|
|
budget.setScheduleName(schedule.getName()); |
|
|
|
//删除条件
|
|
|
|
if(budget.getId()!=null){ |
|
|
|
LambdaQueryWrapper<TbsBudgetCondition> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(TbsBudgetCondition::getBudgetId,budget.getId()); |
|
|
|
budgetConditionService.remove(lqw); |
|
|
|
//删除 费用项
|
|
|
|
LambdaQueryWrapper<TbsScheduleItemBudget> lqw2 = new LambdaQueryWrapper<>(); |
|
|
|
lqw2.eq(TbsScheduleItemBudget::getBudgetId,budget.getId()); |
|
|
|
scheduleItemBudgetService.remove(lqw2); |
|
|
|
} |
|
|
|
this.saveOrUpdate(budget); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 建立条件数据 |
|
|
|
* @param budgetId |
|
|
|
* @param brandIds |
|
|
|
* @param categoryIds |
|
|
|
* @param seriesIds |
|
|
|
* @param spuIds |
|
|
|
* @param skuIds |
|
|
|
*/ |
|
|
|
private void buildCondition(Long budgetId,List<Long> brandIds,List<Long> categoryIds,List<Long> seriesIds,List<Long> spuIds,List<Long> skuIds){ |
|
|
|
List<TbsBudgetCondition> budgetConditions = new ArrayList<>(); |
|
|
|
if(CollectionUtil.isNotEmpty(budgetBo.getSkuIds())){ |
|
|
|
List<GoodsSku> skuList = goodsSkuService.listByIds(budgetBo.getSkuIds()); |
|
|
|
if (CollectionUtil.isNotEmpty(skuIds)) { |
|
|
|
List<GoodsSku> skuList = goodsSkuService.listByIds(skuIds); |
|
|
|
for (GoodsSku sku : skuList) { |
|
|
|
GoodsSpu goodsSpu = goodsSpuService.getById(sku.getSpuId()); |
|
|
|
GoodsCategory category1 = goodsCategoryService.getById(goodsSpu.getCategoryFirst()); |
|
|
|
GoodsCategory category2 = goodsCategoryService.getById(goodsSpu.getCategorySecond()); |
|
|
|
GoodsCategory category3 = goodsCategoryService.getById(goodsSpu.getCategoryThird()); |
|
|
|
TbsBudgetCondition condition = new TbsBudgetCondition(); |
|
|
|
condition.setBudgetId(budget.getId()); |
|
|
|
condition.setBudgetId(budgetId); |
|
|
|
condition.setTargetType(TbsGoodsType.sku.name()); |
|
|
|
condition.setTargetId(sku.getId()); |
|
|
|
condition.setTargetCode(sku.getSkuCode()); |
|
|
@ -130,14 +318,14 @@ public class TbsBudgetServiceImpl extends ServiceImpl<TbsBudgetMapper,TbsBudget> |
|
|
|
budgetConditions.add(condition); |
|
|
|
} |
|
|
|
} |
|
|
|
if(CollectionUtil.isNotEmpty(budgetBo.getSpuIds())){ |
|
|
|
List<GoodsSpu> spuList = goodsSpuService.listByIds(budgetBo.getSpuIds()); |
|
|
|
if (CollectionUtil.isNotEmpty(spuIds)) { |
|
|
|
List<GoodsSpu> spuList = goodsSpuService.listByIds(spuIds); |
|
|
|
for (GoodsSpu goodsSpu : spuList) { |
|
|
|
GoodsCategory category1 = goodsCategoryService.getById(goodsSpu.getCategoryFirst()); |
|
|
|
GoodsCategory category2 = goodsCategoryService.getById(goodsSpu.getCategorySecond()); |
|
|
|
GoodsCategory category3 = goodsCategoryService.getById(goodsSpu.getCategoryThird()); |
|
|
|
TbsBudgetCondition condition = new TbsBudgetCondition(); |
|
|
|
condition.setBudgetId(budget.getId()); |
|
|
|
condition.setBudgetId(budgetId); |
|
|
|
condition.setTargetType(TbsGoodsType.spu.name()); |
|
|
|
condition.setTargetId(goodsSpu.getId()); |
|
|
|
condition.setTargetCode(goodsSpu.getSpuCode()); |
|
|
@ -147,37 +335,11 @@ public class TbsBudgetServiceImpl extends ServiceImpl<TbsBudgetMapper,TbsBudget> |
|
|
|
budgetConditions.add(condition); |
|
|
|
} |
|
|
|
} |
|
|
|
budgetConditions.addAll(buildCategoryCondition(budget.getId(),budgetBo.getSeriesIds(),TbsGoodsType.series.name())); |
|
|
|
budgetConditions.addAll(buildCategoryCondition(budget.getId(),budgetBo.getCategoryIds(),TbsGoodsType.category.name())); |
|
|
|
budgetConditions.addAll(buildCategoryCondition(budget.getId(),budgetBo.getBrandIds(),TbsGoodsType.brand.name())); |
|
|
|
budgetConditions.addAll(buildCategoryCondition(budgetId, seriesIds, TbsGoodsType.series.name())); |
|
|
|
budgetConditions.addAll(buildCategoryCondition(budgetId, categoryIds, TbsGoodsType.category.name())); |
|
|
|
budgetConditions.addAll(buildCategoryCondition(budgetId, brandIds, TbsGoodsType.brand.name())); |
|
|
|
budgetConditionService.saveBatch(budgetConditions); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 建立类目条件 |
|
|
|
* @param budgetId |
|
|
|
* @param categoryIds |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public List<TbsBudgetCondition> buildCategoryCondition(Long budgetId,List<Long> categoryIds,String targetType){ |
|
|
|
List<TbsBudgetCondition> budgetConditions = new ArrayList<>(); |
|
|
|
if(CollectionUtil.isNotEmpty(categoryIds)){ |
|
|
|
List<GoodsCategory> categoryList = goodsCategoryService.listByIds(categoryIds); |
|
|
|
for (GoodsCategory category : categoryList) { |
|
|
|
TbsBudgetCondition condition = new TbsBudgetCondition(); |
|
|
|
condition.setBudgetId(budgetId); |
|
|
|
condition.setTargetType(targetType); |
|
|
|
condition.setTargetId(category.getId()); |
|
|
|
condition.setTargetCode(category.getCode()); |
|
|
|
condition.setTargetName(category.getName()); |
|
|
|
condition.setTargetLevelPathIds(category.getLevelPath()); |
|
|
|
condition.setTargetLevelPathNames(category.getLevelPathNames()); |
|
|
|
budgetConditions.add(condition); |
|
|
|
} |
|
|
|
} |
|
|
|
return budgetConditions; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|