|
|
@ -41,264 +41,263 @@ import java.util.stream.Collectors; |
|
|
|
@AllArgsConstructor |
|
|
|
public class BmsSupplierApplicationService { |
|
|
|
|
|
|
|
private BmsRegionMapper regionMapper; |
|
|
|
private BmsRegion2Mapper bmsRegion2Mapper; |
|
|
|
private TbsBudgetLogService budgetLogService; |
|
|
|
private TbsCostUnItemService costUnItemService; |
|
|
|
private TbsBudgetMapper budgetMapper; |
|
|
|
private TbsBudgetConditionMapper budgetConditionMapper; |
|
|
|
private TbsScheduleItemBudgetMapper scheduleItemBudgetMapper; |
|
|
|
private TbsActivityMapper activityMapper; |
|
|
|
// private BmsRegionMapper regionMapper;
|
|
|
|
// private BmsRegion2Mapper bmsRegion2Mapper;
|
|
|
|
// private TbsCostUnItemService costUnItemService;
|
|
|
|
// private TbsBudgetMapper budgetMapper;
|
|
|
|
// private TbsBudgetConditionMapper budgetConditionMapper;
|
|
|
|
// private TbsScheduleItemBudgetMapper scheduleItemBudgetMapper;
|
|
|
|
// private TbsActivityMapper activityMapper;
|
|
|
|
private BmsSupplierMapper bmsSupplierMapper; |
|
|
|
|
|
|
|
/** |
|
|
|
* 客户更新区域时,预算政策统计 |
|
|
|
* @param supplierId |
|
|
|
* @param regionType |
|
|
|
* @param orgRegionId |
|
|
|
* @param newRegionId |
|
|
|
*/ |
|
|
|
public void migratePolicyBudget(String supplierId, String regionType, String orgRegionId, String newRegionId){ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 客户更新区域时,预算统计调整 |
|
|
|
* @param supplierId |
|
|
|
* @param regionType |
|
|
|
* @param orgRegionId |
|
|
|
* @param newRegionId |
|
|
|
*/ |
|
|
|
public void migrateRegion(String supplierId, String regionType, String orgRegionId, String newRegionId) { |
|
|
|
LocalDateTime nowTime = LocalDateTime.now(); |
|
|
|
String newRegionCode; |
|
|
|
String newRegionName; |
|
|
|
if(regionType.equals(TbsCenterType.saleRegion.name())){ |
|
|
|
BmsRegion bmsRegion = regionMapper.selectById(newRegionId); |
|
|
|
newRegionCode = bmsRegion.getCode(); |
|
|
|
newRegionName = bmsRegion.getName(); |
|
|
|
}else { |
|
|
|
BmsRegion2 bmsRegion2 = bmsRegion2Mapper.selectById(newRegionId); |
|
|
|
newRegionCode = bmsRegion2.getCode(); |
|
|
|
newRegionName = bmsRegion2.getName(); |
|
|
|
} |
|
|
|
//this.migrateActivityBudget(supplierId, regionType, orgRegionId, newRegionId, nowTime, newRegionCode, newRegionName);
|
|
|
|
//this.migratePolicyBudget(supplierId, regionType, orgRegionId, newRegionId, nowTime, newRegionCode, newRegionName);
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 调整政策预算 |
|
|
|
* @param supplierId |
|
|
|
* @param regionType |
|
|
|
* @param orgRegionId |
|
|
|
* @param newRegionId |
|
|
|
* @param nowTime |
|
|
|
* @param newRegionCode |
|
|
|
* @param newRegionName |
|
|
|
*/ |
|
|
|
private void migratePolicyBudget(String supplierId, String regionType, String orgRegionId, String newRegionId, LocalDateTime nowTime, String newRegionCode, String newRegionName) { |
|
|
|
//TODO 方案未落实
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 调整活动预算 |
|
|
|
* @param supplierId |
|
|
|
* @param regionType |
|
|
|
* @param orgRegionId |
|
|
|
* @param newRegionId |
|
|
|
* @param nowTime |
|
|
|
* @param newRegionCode |
|
|
|
* @param newRegionName |
|
|
|
*/ |
|
|
|
private void migrateActivityBudget(String supplierId, String regionType, String orgRegionId, String newRegionId, LocalDateTime nowTime, String newRegionCode, String newRegionName) { |
|
|
|
LambdaQueryWrapper<TbsBudgetLog> lqw4log = new LambdaQueryWrapper<>(); |
|
|
|
lqw4log.eq(TbsBudgetLog::getMigrateFlag,0); |
|
|
|
lqw4log.eq(TbsBudgetLog::getRollbackFlag,0); |
|
|
|
lqw4log.eq(TbsBudgetLog::getSupplierId, supplierId); |
|
|
|
lqw4log.eq(TbsBudgetLog::getCenterType, regionType); |
|
|
|
lqw4log.eq(TbsBudgetLog::getCenterId, orgRegionId); |
|
|
|
lqw4log.isNotNull(TbsBudgetLog::getActivityId); |
|
|
|
List<TbsBudgetLog> budgetLogList = budgetLogService.list(lqw4log); |
|
|
|
if(CollectionUtil.isNotEmpty(budgetLogList)){ |
|
|
|
//查找符合条件的活动
|
|
|
|
final List<Long> activityIds = budgetLogList.stream().map(TbsBudgetLog::getActivityId).distinct().collect(Collectors.toList()); |
|
|
|
LambdaQueryWrapper<TbsActivity> lqwAct = new LambdaQueryWrapper<>(); |
|
|
|
lqwAct.in(TbsActivity::getId,activityIds); |
|
|
|
List<TbsActivity> activityList = activityMapper.selectList(lqwAct); |
|
|
|
//查询符合条件的预算
|
|
|
|
final List<Long> subjectIds = budgetLogList.stream().map(TbsBudgetLog::getSubjectId).distinct().collect(Collectors.toList()); |
|
|
|
LambdaQueryWrapper<TbsBudget> lqwBudget = new LambdaQueryWrapper<>(); |
|
|
|
lqwBudget.eq(TbsBudget::getCenterType, regionType); |
|
|
|
lqwBudget.eq(TbsBudget::getCenterId, newRegionId); |
|
|
|
lqwBudget.eq(TbsBudget::getBudgetState,1); |
|
|
|
lqwBudget.and(wq->{ |
|
|
|
wq.eq(TbsBudget::getSubjectId,0).or().in(TbsBudget::getSubjectId,subjectIds); |
|
|
|
}); |
|
|
|
// 将有科目条件的前置
|
|
|
|
lqwBudget.orderByDesc(TbsBudget::getSubjectId); |
|
|
|
List<TbsBudget> budgetList = budgetMapper.selectList(lqwBudget); |
|
|
|
//查询预算考核期
|
|
|
|
List<Long> budgetIds = budgetList.stream().map(TbsBudget::getId).distinct().collect(Collectors.toList()); |
|
|
|
Map<Long,List<TbsScheduleItemBudget>> scheduleItemBudgetsMap = null; |
|
|
|
if(CollectionUtil.isNotEmpty(budgetIds)){ |
|
|
|
LambdaQueryWrapper<TbsScheduleItemBudget> budgetItemLqw = new LambdaQueryWrapper<>(); |
|
|
|
budgetItemLqw.in(TbsScheduleItemBudget::getBudgetId,budgetIds); |
|
|
|
List<TbsScheduleItemBudget> scheduleItemBudgets = scheduleItemBudgetMapper.selectList(budgetItemLqw); |
|
|
|
scheduleItemBudgetsMap = scheduleItemBudgets.stream().collect(Collectors.groupingBy(TbsScheduleItemBudget::getBudgetId)); |
|
|
|
} |
|
|
|
//查询预算条件
|
|
|
|
List<Long> conditionBudgetIds = budgetList.stream() |
|
|
|
.filter(a->a.getConditionFlag().equals(1)) |
|
|
|
.map(TbsBudget::getId).distinct().collect(Collectors.toList()); |
|
|
|
Map<Long,List<TbsBudgetCondition>> budgetConditionsMap = null; |
|
|
|
if(conditionBudgetIds.size()>0){ |
|
|
|
LambdaQueryWrapper<TbsBudgetCondition> conditionLqw = new LambdaQueryWrapper<>(); |
|
|
|
conditionLqw.in(TbsBudgetCondition::getBudgetId,conditionBudgetIds); |
|
|
|
List<TbsBudgetCondition> budgetConditions = budgetConditionMapper.selectList(conditionLqw); |
|
|
|
budgetConditionsMap = budgetConditions.stream().collect(Collectors.groupingBy(TbsBudgetCondition::getBudgetId)); |
|
|
|
} |
|
|
|
//用于循环筛选条件
|
|
|
|
TbsGoodsType[] goodsTypes = new TbsGoodsType[]{ |
|
|
|
TbsGoodsType.sku, |
|
|
|
TbsGoodsType.spu, |
|
|
|
TbsGoodsType.series, |
|
|
|
TbsGoodsType.category, |
|
|
|
TbsGoodsType.brand |
|
|
|
}; |
|
|
|
//已占用预算进行调增
|
|
|
|
final BudgetLogOptFlag optType4Diff = regionType.equals(TbsCenterType.saleRegion.name())? |
|
|
|
BudgetLogOptFlag.State_8:BudgetLogOptFlag.State_10; |
|
|
|
final BudgetLogOptFlag optType4Add = regionType.equals(TbsCenterType.saleRegion.name())? |
|
|
|
BudgetLogOptFlag.State_7:BudgetLogOptFlag.State_9; |
|
|
|
List<TbsBudgetLog> budgetLog4Adds = budgetLogList.stream().map(budgetLog->{ |
|
|
|
TbsBudgetLog obj = CopierUtil.copy(budgetLog,new TbsBudgetLog()); |
|
|
|
obj.setId(null); |
|
|
|
obj.setOptType(optType4Add.getCode()); |
|
|
|
obj.setMigrateFlag(1); |
|
|
|
obj.setMigrateTime(nowTime); |
|
|
|
obj.setAmount(TbsBudgetLogBuildUtil.buildAmount(obj.getAmount(),optType4Add)); |
|
|
|
return obj; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
//规则:品类条件比科目条件优先级更高
|
|
|
|
List<TbsBudgetLog> budgetLog4Diff = new ArrayList<>(); |
|
|
|
//无匹配的费用支出
|
|
|
|
List<TbsCostUnItem> costUnItemList = new ArrayList<>(); |
|
|
|
for (TbsBudgetLog budgetLog : budgetLogList) { |
|
|
|
//当前活动
|
|
|
|
TbsActivity currActivity = null; |
|
|
|
for (TbsActivity activity : activityList) { |
|
|
|
if(budgetLog.getActivityId().equals(activity.getId())){ |
|
|
|
currActivity = activity; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
//(数据结构:value=预算id列表,key=商品类型)
|
|
|
|
Map<String,List<Long>> matchConditionBudgetIdsMap = new HashMap<>(); |
|
|
|
if(budgetConditionsMap!=null){ |
|
|
|
for (Long budgetId : budgetConditionsMap.keySet()) { |
|
|
|
List<TbsBudgetCondition> budgetConditions = budgetConditionsMap.get(budgetId); |
|
|
|
String pathName = budgetLog.getTargetLevelPathNames(); |
|
|
|
for (TbsBudgetCondition condition : budgetConditions) { |
|
|
|
if(pathName.contains(condition.getTargetLevelPathNames())){ |
|
|
|
List<Long> tempList = matchConditionBudgetIdsMap.get(condition.getTargetType()); |
|
|
|
if(tempList==null){ |
|
|
|
tempList = new ArrayList<>(); |
|
|
|
} |
|
|
|
tempList.add(budgetId); |
|
|
|
matchConditionBudgetIdsMap.put(condition.getTargetType(),tempList); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//记录匹配品类条件的预算
|
|
|
|
List<TbsBudget> matchBudgetConditionList = new ArrayList<>(); |
|
|
|
List<TbsBudget> matchBudgetConditionList_tmp = new ArrayList<>(); |
|
|
|
for (TbsBudget budget : budgetList) { |
|
|
|
if(budget.getConditionFlag().equals(1)){ |
|
|
|
for (TbsGoodsType goodsType : goodsTypes) { |
|
|
|
List<Long> tempList = matchConditionBudgetIdsMap.get(goodsType.name()); |
|
|
|
if(CollectionUtil.isNotEmpty(tempList)){ |
|
|
|
for (Long budgetId01 : tempList) { |
|
|
|
if(budgetId01.equals(budget.getId())){ |
|
|
|
matchBudgetConditionList.add(budget); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}else { |
|
|
|
matchBudgetConditionList_tmp.add(budget); |
|
|
|
} |
|
|
|
} |
|
|
|
//有条件预算优先级更高
|
|
|
|
matchBudgetConditionList.addAll(matchBudgetConditionList_tmp); |
|
|
|
//第一个预算为最有匹配预算
|
|
|
|
TbsBudget matchBudget = null; |
|
|
|
TbsScheduleItemBudget matchItemBudget = null; |
|
|
|
//记录匹配到的预算
|
|
|
|
if(scheduleItemBudgetsMap!=null){ |
|
|
|
for (TbsBudget budget : matchBudgetConditionList) { |
|
|
|
if(matchBudget!=null){ |
|
|
|
break; |
|
|
|
} |
|
|
|
List<TbsScheduleItemBudget> scheduleItemBudgets = scheduleItemBudgetsMap.get(budget.getId()); |
|
|
|
for (TbsScheduleItemBudget itemBudget : scheduleItemBudgets) { |
|
|
|
LocalDateTime actStartDate = currActivity.getPreStartDate().atStartOfDay(); |
|
|
|
LocalDateTime actEndDate = LocalDateTime.of(currActivity.getPreStartDate(), LocalTime.MAX); |
|
|
|
if(actStartDate.isAfter(itemBudget.getStartDate())&&actEndDate.isBefore(itemBudget.getEndDate())){ |
|
|
|
matchBudget = budget; |
|
|
|
matchItemBudget = itemBudget; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if(matchBudget!=null){ |
|
|
|
//有匹配的预算
|
|
|
|
TbsBudgetLog newLog = CopierUtil.copy(budgetLog,new TbsBudgetLog()); |
|
|
|
newLog.setId(null); |
|
|
|
newLog.setOptType(optType4Diff.getCode()); |
|
|
|
newLog.setBudgetId(matchBudget.getId()); |
|
|
|
newLog.setBudgetCode(matchBudget.getBudgetCode()); |
|
|
|
newLog.setScheduleOrgId(budgetLog.getScheduleId()); |
|
|
|
newLog.setScheduleItemOrgId(budgetLog.getScheduleItemId()); |
|
|
|
newLog.setScheduleItemBudgetOrgId(budgetLog.getScheduleItemBudgetId()); |
|
|
|
//匹配到的项
|
|
|
|
newLog.setScheduleId(matchItemBudget.getScheduleId()); |
|
|
|
newLog.setScheduleItemId(matchItemBudget.getScheduleItemId()); |
|
|
|
newLog.setScheduleItemBudgetId(matchItemBudget.getId()); |
|
|
|
//设置新的成本中心
|
|
|
|
newLog.setCenterOrgId(newLog.getCenterId()); |
|
|
|
newLog.setCenterOrgCode(newLog.getCenterCode()); |
|
|
|
newLog.setCenterOrgName(newLog.getCenterName()); |
|
|
|
newLog.setCenterId(newRegionId); |
|
|
|
newLog.setCenterCode(newRegionCode); |
|
|
|
newLog.setCenterName(newRegionName); |
|
|
|
budgetLog4Diff.add(newLog); |
|
|
|
}else { |
|
|
|
//无匹配的预算
|
|
|
|
TbsCostUnItem costUnItem = budgetLog.toTbsCostUnItem(currActivity); |
|
|
|
costUnItemList.add(costUnItem); |
|
|
|
} |
|
|
|
} |
|
|
|
//保存
|
|
|
|
budgetLogService.saveBatch(budgetLog4Adds); |
|
|
|
if(CollectionUtil.isNotEmpty(budgetLog4Diff)){ |
|
|
|
budgetLogService.saveBatch(budgetLog4Diff); |
|
|
|
} |
|
|
|
if(CollectionUtil.isNotEmpty(costUnItemList)){ |
|
|
|
costUnItemService.saveBatch(costUnItemList); |
|
|
|
} |
|
|
|
//设置已迁移状态
|
|
|
|
List<Long> budgetLogIds = budgetLogList.stream().map(TbsBudgetLog::getId).collect(Collectors.toList()); |
|
|
|
TbsBudgetLog updLogParam = new TbsBudgetLog(); |
|
|
|
updLogParam.setMigrateFlag(1); |
|
|
|
updLogParam.setMigrateTime(nowTime); |
|
|
|
LambdaQueryWrapper<TbsBudgetLog> updLogLqw = new LambdaQueryWrapper<>(); |
|
|
|
updLogLqw.in(TbsBudgetLog::getId,budgetLogIds); |
|
|
|
budgetLogService.update(updLogParam,updLogLqw); |
|
|
|
} |
|
|
|
} |
|
|
|
// /**
|
|
|
|
// * 客户更新区域时,预算政策统计
|
|
|
|
// * @param supplierId
|
|
|
|
// * @param regionType
|
|
|
|
// * @param orgRegionId
|
|
|
|
// * @param newRegionId
|
|
|
|
// */
|
|
|
|
// public void migratePolicyBudget(String supplierId, String regionType, String orgRegionId, String newRegionId){
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// /**
|
|
|
|
// * 客户更新区域时,预算统计调整
|
|
|
|
// * @param supplierId
|
|
|
|
// * @param regionType
|
|
|
|
// * @param orgRegionId
|
|
|
|
// * @param newRegionId
|
|
|
|
// */
|
|
|
|
// public void migrateRegion(String supplierId, String regionType, String orgRegionId, String newRegionId) {
|
|
|
|
// LocalDateTime nowTime = LocalDateTime.now();
|
|
|
|
// String newRegionCode;
|
|
|
|
// String newRegionName;
|
|
|
|
// if(regionType.equals(TbsCenterType.saleRegion.name())){
|
|
|
|
// BmsRegion bmsRegion = regionMapper.selectById(newRegionId);
|
|
|
|
// newRegionCode = bmsRegion.getCode();
|
|
|
|
// newRegionName = bmsRegion.getName();
|
|
|
|
// }else {
|
|
|
|
// BmsRegion2 bmsRegion2 = bmsRegion2Mapper.selectById(newRegionId);
|
|
|
|
// newRegionCode = bmsRegion2.getCode();
|
|
|
|
// newRegionName = bmsRegion2.getName();
|
|
|
|
// }
|
|
|
|
// //this.migrateActivityBudget(supplierId, regionType, orgRegionId, newRegionId, nowTime, newRegionCode, newRegionName);
|
|
|
|
// //this.migratePolicyBudget(supplierId, regionType, orgRegionId, newRegionId, nowTime, newRegionCode, newRegionName);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// /**
|
|
|
|
// * 调整政策预算
|
|
|
|
// * @param supplierId
|
|
|
|
// * @param regionType
|
|
|
|
// * @param orgRegionId
|
|
|
|
// * @param newRegionId
|
|
|
|
// * @param nowTime
|
|
|
|
// * @param newRegionCode
|
|
|
|
// * @param newRegionName
|
|
|
|
// */
|
|
|
|
// private void migratePolicyBudget(String supplierId, String regionType, String orgRegionId, String newRegionId, LocalDateTime nowTime, String newRegionCode, String newRegionName) {
|
|
|
|
// //TODO 方案未落实
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// /**
|
|
|
|
// * 调整活动预算
|
|
|
|
// * @param supplierId
|
|
|
|
// * @param regionType
|
|
|
|
// * @param orgRegionId
|
|
|
|
// * @param newRegionId
|
|
|
|
// * @param nowTime
|
|
|
|
// * @param newRegionCode
|
|
|
|
// * @param newRegionName
|
|
|
|
// */
|
|
|
|
// private void migrateActivityBudget(String supplierId, String regionType, String orgRegionId, String newRegionId, LocalDateTime nowTime, String newRegionCode, String newRegionName) {
|
|
|
|
// LambdaQueryWrapper<TbsBudgetLog> lqw4log = new LambdaQueryWrapper<>();
|
|
|
|
// lqw4log.eq(TbsBudgetLog::getMigrateFlag,0);
|
|
|
|
// lqw4log.eq(TbsBudgetLog::getRollbackFlag,0);
|
|
|
|
// lqw4log.eq(TbsBudgetLog::getSupplierId, supplierId);
|
|
|
|
// lqw4log.eq(TbsBudgetLog::getCenterType, regionType);
|
|
|
|
// lqw4log.eq(TbsBudgetLog::getCenterId, orgRegionId);
|
|
|
|
// lqw4log.isNotNull(TbsBudgetLog::getActivityId);
|
|
|
|
// List<TbsBudgetLog> budgetLogList = budgetLogService.list(lqw4log);
|
|
|
|
// if(CollectionUtil.isNotEmpty(budgetLogList)){
|
|
|
|
// //查找符合条件的活动
|
|
|
|
// final List<Long> activityIds = budgetLogList.stream().map(TbsBudgetLog::getActivityId).distinct().collect(Collectors.toList());
|
|
|
|
// LambdaQueryWrapper<TbsActivity> lqwAct = new LambdaQueryWrapper<>();
|
|
|
|
// lqwAct.in(TbsActivity::getId,activityIds);
|
|
|
|
// List<TbsActivity> activityList = activityMapper.selectList(lqwAct);
|
|
|
|
// //查询符合条件的预算
|
|
|
|
// final List<Long> subjectIds = budgetLogList.stream().map(TbsBudgetLog::getSubjectId).distinct().collect(Collectors.toList());
|
|
|
|
// LambdaQueryWrapper<TbsBudget> lqwBudget = new LambdaQueryWrapper<>();
|
|
|
|
// lqwBudget.eq(TbsBudget::getCenterType, regionType);
|
|
|
|
// lqwBudget.eq(TbsBudget::getCenterId, newRegionId);
|
|
|
|
// lqwBudget.eq(TbsBudget::getBudgetState,1);
|
|
|
|
// lqwBudget.and(wq->{
|
|
|
|
// wq.eq(TbsBudget::getSubjectId,0).or().in(TbsBudget::getSubjectId,subjectIds);
|
|
|
|
// });
|
|
|
|
// // 将有科目条件的前置
|
|
|
|
// lqwBudget.orderByDesc(TbsBudget::getSubjectId);
|
|
|
|
// List<TbsBudget> budgetList = budgetMapper.selectList(lqwBudget);
|
|
|
|
// //查询预算考核期
|
|
|
|
// List<Long> budgetIds = budgetList.stream().map(TbsBudget::getId).distinct().collect(Collectors.toList());
|
|
|
|
// Map<Long,List<TbsScheduleItemBudget>> scheduleItemBudgetsMap = null;
|
|
|
|
// if(CollectionUtil.isNotEmpty(budgetIds)){
|
|
|
|
// LambdaQueryWrapper<TbsScheduleItemBudget> budgetItemLqw = new LambdaQueryWrapper<>();
|
|
|
|
// budgetItemLqw.in(TbsScheduleItemBudget::getBudgetId,budgetIds);
|
|
|
|
// List<TbsScheduleItemBudget> scheduleItemBudgets = scheduleItemBudgetMapper.selectList(budgetItemLqw);
|
|
|
|
// scheduleItemBudgetsMap = scheduleItemBudgets.stream().collect(Collectors.groupingBy(TbsScheduleItemBudget::getBudgetId));
|
|
|
|
// }
|
|
|
|
// //查询预算条件
|
|
|
|
// List<Long> conditionBudgetIds = budgetList.stream()
|
|
|
|
// .filter(a->a.getConditionFlag().equals(1))
|
|
|
|
// .map(TbsBudget::getId).distinct().collect(Collectors.toList());
|
|
|
|
// Map<Long,List<TbsBudgetCondition>> budgetConditionsMap = null;
|
|
|
|
// if(conditionBudgetIds.size()>0){
|
|
|
|
// LambdaQueryWrapper<TbsBudgetCondition> conditionLqw = new LambdaQueryWrapper<>();
|
|
|
|
// conditionLqw.in(TbsBudgetCondition::getBudgetId,conditionBudgetIds);
|
|
|
|
// List<TbsBudgetCondition> budgetConditions = budgetConditionMapper.selectList(conditionLqw);
|
|
|
|
// budgetConditionsMap = budgetConditions.stream().collect(Collectors.groupingBy(TbsBudgetCondition::getBudgetId));
|
|
|
|
// }
|
|
|
|
// //用于循环筛选条件
|
|
|
|
// TbsGoodsType[] goodsTypes = new TbsGoodsType[]{
|
|
|
|
// TbsGoodsType.sku,
|
|
|
|
// TbsGoodsType.spu,
|
|
|
|
// TbsGoodsType.series,
|
|
|
|
// TbsGoodsType.category,
|
|
|
|
// TbsGoodsType.brand
|
|
|
|
// };
|
|
|
|
// //已占用预算进行调增
|
|
|
|
// final BudgetLogOptFlag optType4Diff = regionType.equals(TbsCenterType.saleRegion.name())?
|
|
|
|
// BudgetLogOptFlag.State_8:BudgetLogOptFlag.State_10;
|
|
|
|
// final BudgetLogOptFlag optType4Add = regionType.equals(TbsCenterType.saleRegion.name())?
|
|
|
|
// BudgetLogOptFlag.State_7:BudgetLogOptFlag.State_9;
|
|
|
|
// List<TbsBudgetLog> budgetLog4Adds = budgetLogList.stream().map(budgetLog->{
|
|
|
|
// TbsBudgetLog obj = CopierUtil.copy(budgetLog,new TbsBudgetLog());
|
|
|
|
// obj.setId(null);
|
|
|
|
// obj.setOptType(optType4Add.getCode());
|
|
|
|
// obj.setMigrateFlag(1);
|
|
|
|
// obj.setMigrateTime(nowTime);
|
|
|
|
// obj.setAmount(TbsBudgetLogBuildUtil.buildAmount(obj.getAmount(),optType4Add));
|
|
|
|
// return obj;
|
|
|
|
// }).collect(Collectors.toList());
|
|
|
|
// //规则:品类条件比科目条件优先级更高
|
|
|
|
// List<TbsBudgetLog> budgetLog4Diff = new ArrayList<>();
|
|
|
|
// //无匹配的费用支出
|
|
|
|
// List<TbsCostUnItem> costUnItemList = new ArrayList<>();
|
|
|
|
// for (TbsBudgetLog budgetLog : budgetLogList) {
|
|
|
|
// //当前活动
|
|
|
|
// TbsActivity currActivity = null;
|
|
|
|
// for (TbsActivity activity : activityList) {
|
|
|
|
// if(budgetLog.getActivityId().equals(activity.getId())){
|
|
|
|
// currActivity = activity;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// //(数据结构:value=预算id列表,key=商品类型)
|
|
|
|
// Map<String,List<Long>> matchConditionBudgetIdsMap = new HashMap<>();
|
|
|
|
// if(budgetConditionsMap!=null){
|
|
|
|
// for (Long budgetId : budgetConditionsMap.keySet()) {
|
|
|
|
// List<TbsBudgetCondition> budgetConditions = budgetConditionsMap.get(budgetId);
|
|
|
|
// String pathName = budgetLog.getTargetLevelPathNames();
|
|
|
|
// for (TbsBudgetCondition condition : budgetConditions) {
|
|
|
|
// if(pathName.contains(condition.getTargetLevelPathNames())){
|
|
|
|
// List<Long> tempList = matchConditionBudgetIdsMap.get(condition.getTargetType());
|
|
|
|
// if(tempList==null){
|
|
|
|
// tempList = new ArrayList<>();
|
|
|
|
// }
|
|
|
|
// tempList.add(budgetId);
|
|
|
|
// matchConditionBudgetIdsMap.put(condition.getTargetType(),tempList);
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// //记录匹配品类条件的预算
|
|
|
|
// List<TbsBudget> matchBudgetConditionList = new ArrayList<>();
|
|
|
|
// List<TbsBudget> matchBudgetConditionList_tmp = new ArrayList<>();
|
|
|
|
// for (TbsBudget budget : budgetList) {
|
|
|
|
// if(budget.getConditionFlag().equals(1)){
|
|
|
|
// for (TbsGoodsType goodsType : goodsTypes) {
|
|
|
|
// List<Long> tempList = matchConditionBudgetIdsMap.get(goodsType.name());
|
|
|
|
// if(CollectionUtil.isNotEmpty(tempList)){
|
|
|
|
// for (Long budgetId01 : tempList) {
|
|
|
|
// if(budgetId01.equals(budget.getId())){
|
|
|
|
// matchBudgetConditionList.add(budget);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }else {
|
|
|
|
// matchBudgetConditionList_tmp.add(budget);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// //有条件预算优先级更高
|
|
|
|
// matchBudgetConditionList.addAll(matchBudgetConditionList_tmp);
|
|
|
|
// //第一个预算为最有匹配预算
|
|
|
|
// TbsBudget matchBudget = null;
|
|
|
|
// TbsScheduleItemBudget matchItemBudget = null;
|
|
|
|
// //记录匹配到的预算
|
|
|
|
// if(scheduleItemBudgetsMap!=null){
|
|
|
|
// for (TbsBudget budget : matchBudgetConditionList) {
|
|
|
|
// if(matchBudget!=null){
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// List<TbsScheduleItemBudget> scheduleItemBudgets = scheduleItemBudgetsMap.get(budget.getId());
|
|
|
|
// for (TbsScheduleItemBudget itemBudget : scheduleItemBudgets) {
|
|
|
|
// LocalDateTime actStartDate = currActivity.getPreStartDate().atStartOfDay();
|
|
|
|
// LocalDateTime actEndDate = LocalDateTime.of(currActivity.getPreStartDate(), LocalTime.MAX);
|
|
|
|
// if(actStartDate.isAfter(itemBudget.getStartDate())&&actEndDate.isBefore(itemBudget.getEndDate())){
|
|
|
|
// matchBudget = budget;
|
|
|
|
// matchItemBudget = itemBudget;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// if(matchBudget!=null){
|
|
|
|
// //有匹配的预算
|
|
|
|
// TbsBudgetLog newLog = CopierUtil.copy(budgetLog,new TbsBudgetLog());
|
|
|
|
// newLog.setId(null);
|
|
|
|
// newLog.setOptType(optType4Diff.getCode());
|
|
|
|
// newLog.setBudgetId(matchBudget.getId());
|
|
|
|
// newLog.setBudgetCode(matchBudget.getBudgetCode());
|
|
|
|
// newLog.setScheduleOrgId(budgetLog.getScheduleId());
|
|
|
|
// newLog.setScheduleItemOrgId(budgetLog.getScheduleItemId());
|
|
|
|
// newLog.setScheduleItemBudgetOrgId(budgetLog.getScheduleItemBudgetId());
|
|
|
|
// //匹配到的项
|
|
|
|
// newLog.setScheduleId(matchItemBudget.getScheduleId());
|
|
|
|
// newLog.setScheduleItemId(matchItemBudget.getScheduleItemId());
|
|
|
|
// newLog.setScheduleItemBudgetId(matchItemBudget.getId());
|
|
|
|
// //设置新的成本中心
|
|
|
|
// newLog.setCenterOrgId(newLog.getCenterId());
|
|
|
|
// newLog.setCenterOrgCode(newLog.getCenterCode());
|
|
|
|
// newLog.setCenterOrgName(newLog.getCenterName());
|
|
|
|
// newLog.setCenterId(newRegionId);
|
|
|
|
// newLog.setCenterCode(newRegionCode);
|
|
|
|
// newLog.setCenterName(newRegionName);
|
|
|
|
// budgetLog4Diff.add(newLog);
|
|
|
|
// }else {
|
|
|
|
// //无匹配的预算
|
|
|
|
// TbsCostUnItem costUnItem = budgetLog.toTbsCostUnItem(currActivity);
|
|
|
|
// costUnItemList.add(costUnItem);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// //保存
|
|
|
|
// budgetLogService.saveBatch(budgetLog4Adds);
|
|
|
|
// if(CollectionUtil.isNotEmpty(budgetLog4Diff)){
|
|
|
|
// budgetLogService.saveBatch(budgetLog4Diff);
|
|
|
|
// }
|
|
|
|
// if(CollectionUtil.isNotEmpty(costUnItemList)){
|
|
|
|
// costUnItemService.saveBatch(costUnItemList);
|
|
|
|
// }
|
|
|
|
// //设置已迁移状态
|
|
|
|
// List<Long> budgetLogIds = budgetLogList.stream().map(TbsBudgetLog::getId).collect(Collectors.toList());
|
|
|
|
// TbsBudgetLog updLogParam = new TbsBudgetLog();
|
|
|
|
// updLogParam.setMigrateFlag(1);
|
|
|
|
// updLogParam.setMigrateTime(nowTime);
|
|
|
|
// LambdaQueryWrapper<TbsBudgetLog> updLogLqw = new LambdaQueryWrapper<>();
|
|
|
|
// updLogLqw.in(TbsBudgetLog::getId,budgetLogIds);
|
|
|
|
// budgetLogService.update(updLogParam,updLogLqw);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
public List<BmsSupplier> listByRegionIds(List<String> regionIds, Integer level) { |
|
|
|
if(regionIds.size()>0){ |
|
|
|