|
@ -7,7 +7,6 @@ import com.qs.serve.common.util.AuthContextUtils; |
|
|
import com.qs.serve.common.util.CollectionUtil; |
|
|
import com.qs.serve.common.util.CollectionUtil; |
|
|
import com.qs.serve.common.util.CopierUtil; |
|
|
import com.qs.serve.common.util.CopierUtil; |
|
|
import com.qs.serve.modules.bms.entity.BmsSubject; |
|
|
import com.qs.serve.modules.bms.entity.BmsSubject; |
|
|
import com.qs.serve.modules.bms.service.BmsCostCenterService; |
|
|
|
|
|
import com.qs.serve.modules.bms.service.BmsSubjectService; |
|
|
import com.qs.serve.modules.bms.service.BmsSubjectService; |
|
|
import com.qs.serve.modules.goods.entity.GoodsCategory; |
|
|
import com.qs.serve.modules.goods.entity.GoodsCategory; |
|
|
import com.qs.serve.modules.goods.entity.GoodsSku; |
|
|
import com.qs.serve.modules.goods.entity.GoodsSku; |
|
@ -19,9 +18,9 @@ import com.qs.serve.modules.goods.service.GoodsSpuService; |
|
|
import com.qs.serve.modules.sys.entity.SysUser; |
|
|
import com.qs.serve.modules.sys.entity.SysUser; |
|
|
import com.qs.serve.modules.sys.service.SysUserService; |
|
|
import com.qs.serve.modules.sys.service.SysUserService; |
|
|
import com.qs.serve.modules.tbs.common.TbsGoodsType; |
|
|
import com.qs.serve.modules.tbs.common.TbsGoodsType; |
|
|
|
|
|
import com.qs.serve.modules.tbs.common.consts.ConditionMapEnum; |
|
|
import com.qs.serve.modules.tbs.entity.*; |
|
|
import com.qs.serve.modules.tbs.entity.*; |
|
|
import com.qs.serve.modules.tbs.entity.bo.TbsBudgetBo; |
|
|
import com.qs.serve.modules.tbs.entity.bo.TbsBudgetBo; |
|
|
import com.qs.serve.modules.tbs.entity.bo.TbsBudgetExcelBatchDto; |
|
|
|
|
|
import com.qs.serve.modules.tbs.entity.bo.TbsBudgetExcelBo; |
|
|
import com.qs.serve.modules.tbs.entity.bo.TbsBudgetExcelBo; |
|
|
import com.qs.serve.modules.tbs.entity.vo.TbsBudgetVo; |
|
|
import com.qs.serve.modules.tbs.entity.vo.TbsBudgetVo; |
|
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetMapper; |
|
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetMapper; |
|
@ -82,6 +81,16 @@ public class TbsBudgetServiceImpl extends ServiceImpl<TbsBudgetMapper,TbsBudget> |
|
|
}else { |
|
|
}else { |
|
|
budget = CopierUtil.copy(budgetBo,new TbsBudget()); |
|
|
budget = CopierUtil.copy(budgetBo,new TbsBudget()); |
|
|
} |
|
|
} |
|
|
|
|
|
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(); |
|
|
|
|
|
//添加条件拦截
|
|
|
|
|
|
boolean sameCondition = filterSameCondition(budget,skuIds, spuIds, seriesIds, brandIds, categoryIds); |
|
|
|
|
|
if(sameCondition){ |
|
|
|
|
|
Assert.throwEx("已存在相同条件预算"); |
|
|
|
|
|
} |
|
|
BmsSubject subject = null; |
|
|
BmsSubject subject = null; |
|
|
if(budget.getSubjectId()!=0L){ |
|
|
if(budget.getSubjectId()!=0L){ |
|
|
subject = subjectService.getById(budgetBo.getSubjectId()); |
|
|
subject = subjectService.getById(budgetBo.getSubjectId()); |
|
@ -110,14 +119,103 @@ public class TbsBudgetServiceImpl extends ServiceImpl<TbsBudgetMapper,TbsBudget> |
|
|
} |
|
|
} |
|
|
scheduleItemBudgetService.saveBatch(scheduleItemBudgets); |
|
|
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); |
|
|
buildCondition(budget.getId(),brandIds,categoryIds,seriesIds,spuIds,skuIds); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 拦截相同条件的预算 |
|
|
|
|
|
* @param budget |
|
|
|
|
|
* @param skuIds |
|
|
|
|
|
* @param spuIds |
|
|
|
|
|
* @param seriesIds |
|
|
|
|
|
* @param brandIds |
|
|
|
|
|
* @param categoryIds |
|
|
|
|
|
* @return 满足无条件的返回true |
|
|
|
|
|
*/ |
|
|
|
|
|
private boolean filterSameCondition(TbsBudget budget,List<Long> skuIds, List<Long> spuIds, List<Long> seriesIds, List<Long> brandIds, List<Long> categoryIds) { |
|
|
|
|
|
boolean hasCondition = CollectionUtil.isNotEmpty(skuIds)|| |
|
|
|
|
|
CollectionUtil.isNotEmpty(spuIds)|| |
|
|
|
|
|
CollectionUtil.isNotEmpty(seriesIds)|| |
|
|
|
|
|
CollectionUtil.isNotEmpty(brandIds)|| |
|
|
|
|
|
CollectionUtil.isNotEmpty(categoryIds); |
|
|
|
|
|
LambdaQueryWrapper<TbsBudget> lqw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
lqw.eq(TbsBudget::getSubjectId,budget.getSubjectId()); |
|
|
|
|
|
lqw.eq(TbsBudget::getCenterType,budget.getCenterType()); |
|
|
|
|
|
lqw.eq(TbsBudget::getCenterId,budget.getCenterId()); |
|
|
|
|
|
//忽略更新情况
|
|
|
|
|
|
if(budget.getId()!=null){ |
|
|
|
|
|
lqw.ne(TbsBudget::getId,budget.getId()); |
|
|
|
|
|
} |
|
|
|
|
|
//区分有无条件情况
|
|
|
|
|
|
if(hasCondition){ |
|
|
|
|
|
lqw.eq(TbsBudget::getConditionFlag,1); |
|
|
|
|
|
lqw.select(TbsBudget::getId); |
|
|
|
|
|
List<TbsBudget> budgetList = this.list(lqw); |
|
|
|
|
|
if(budgetList.size()<1){return false;} |
|
|
|
|
|
List<Long> budgetIds = budgetList.stream().map(TbsBudget::getId).collect(Collectors.toList()); |
|
|
|
|
|
//存储相同条件的预算id
|
|
|
|
|
|
budgetIds = baseFilterBudgetIds(brandIds,TbsGoodsType.brand.name(),budgetIds); |
|
|
|
|
|
if(CollectionUtil.isNotEmpty(budgetIds)){ |
|
|
|
|
|
budgetIds = baseFilterBudgetIds(seriesIds,TbsGoodsType.series.name(),budgetIds); |
|
|
|
|
|
if(CollectionUtil.isNotEmpty(budgetIds)){ |
|
|
|
|
|
budgetIds = baseFilterBudgetIds(categoryIds,TbsGoodsType.category.name(),budgetIds); |
|
|
|
|
|
if(CollectionUtil.isNotEmpty(budgetIds)){ |
|
|
|
|
|
budgetIds = baseFilterBudgetIds(spuIds,TbsGoodsType.spu.name(),budgetIds); |
|
|
|
|
|
if(CollectionUtil.isNotEmpty(budgetIds)){ |
|
|
|
|
|
budgetIds = baseFilterBudgetIds(skuIds,TbsGoodsType.sku.name(),budgetIds); |
|
|
|
|
|
if(CollectionUtil.isNotEmpty(budgetIds)){ |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}else { |
|
|
|
|
|
//满足无条件的返回true
|
|
|
|
|
|
lqw.eq(TbsBudget::getConditionFlag,0); |
|
|
|
|
|
return this.count(lqw)>0; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 根据品类获取预算id列表 |
|
|
|
|
|
* @param targetIds |
|
|
|
|
|
* @param targetType |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
private List<Long> baseFilterBudgetIds(List<Long> targetIds, String targetType, List<Long> budgetIds){ |
|
|
|
|
|
if(CollectionUtil.isNotEmpty(targetIds)&&CollectionUtil.isNotEmpty(budgetIds)){ |
|
|
|
|
|
LambdaQueryWrapper<TbsBudgetCondition> lqw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
lqw.select(TbsBudgetCondition::getBudgetId); |
|
|
|
|
|
lqw.eq(TbsBudgetCondition::getTargetType,targetType); |
|
|
|
|
|
lqw.in(TbsBudgetCondition::getTargetId, targetIds); |
|
|
|
|
|
lqw.in(TbsBudgetCondition::getBudgetId,budgetIds); |
|
|
|
|
|
List<TbsBudgetCondition> conditions = tbsBudgetConditionService.list(lqw); |
|
|
|
|
|
if(conditions.size()<1){ |
|
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
|
} |
|
|
|
|
|
budgetIds = conditions.stream().map(TbsBudgetCondition::getBudgetId).distinct().collect(Collectors.toList()); |
|
|
|
|
|
//排插被包含关系
|
|
|
|
|
|
LambdaQueryWrapper<TbsBudgetCondition> lqw2 = new LambdaQueryWrapper<>(); |
|
|
|
|
|
lqw2.eq(TbsBudgetCondition::getTargetType,targetType); |
|
|
|
|
|
lqw2.in(TbsBudgetCondition::getBudgetId,budgetIds); |
|
|
|
|
|
List<TbsBudgetCondition> conditions2 = tbsBudgetConditionService.list(lqw2); |
|
|
|
|
|
Map<Long,List<TbsBudgetCondition>> conditions2Map = conditions2.stream() |
|
|
|
|
|
.collect(Collectors.groupingBy(TbsBudgetCondition::getBudgetId)); |
|
|
|
|
|
List<Long> selectBudgetIds = new ArrayList<>(); |
|
|
|
|
|
for (Long budgetId : conditions2Map.keySet()) { |
|
|
|
|
|
int size = conditions2Map.get(budgetId).size(); |
|
|
|
|
|
if(size==targetIds.size()){ |
|
|
|
|
|
selectBudgetIds.add(budgetId); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
budgetIds = selectBudgetIds; |
|
|
|
|
|
return budgetIds; |
|
|
|
|
|
} |
|
|
|
|
|
return budgetIds; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void startBudget(Long id) { |
|
|
public void startBudget(Long id) { |
|
|
TbsBudget budget = this.getById(id); |
|
|
TbsBudget budget = this.getById(id); |
|
|