|
|
@ -1,5 +1,6 @@ |
|
|
|
package com.qs.serve.modules.tbs.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.qs.serve.common.config.properties.ProjectProperties; |
|
|
@ -21,9 +22,12 @@ import com.qs.serve.modules.seeyon.service.SeeYonRequestService; |
|
|
|
import com.qs.serve.modules.sys.entity.SysUser; |
|
|
|
import com.qs.serve.modules.sys.service.SysUserService; |
|
|
|
import com.qs.serve.modules.tbs.common.TbsBudgetCheckState; |
|
|
|
import com.qs.serve.modules.tbs.common.TbsGoodsType; |
|
|
|
import com.qs.serve.modules.tbs.common.TbsSeeYonConst; |
|
|
|
import com.qs.serve.modules.tbs.entity.*; |
|
|
|
import com.qs.serve.modules.tbs.entity.bo.TbsBudgetBatchBo; |
|
|
|
import com.qs.serve.modules.tbs.entity.dto.TbsBudgetLogWithAmount; |
|
|
|
import com.qs.serve.modules.tbs.mapper.TbsScheduleItemBudgetMapper; |
|
|
|
import com.qs.serve.modules.tbs.service.*; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
@ -32,6 +36,7 @@ import org.springframework.stereotype.Service; |
|
|
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetBatchMapper; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
@ -57,6 +62,10 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
private final TbsScheduleItemService tbsScheduleItemService; |
|
|
|
private final TbsScheduleItemBudgetService tbsScheduleItemBudgetService; |
|
|
|
private final GoodsCategoryService goodsCategoryService; |
|
|
|
private final TbsBudgetChangeService tbsBudgetChangeService; |
|
|
|
private final TbsBudgetChangeConditionService tbsBudgetChangeConditionService; |
|
|
|
private final TbsScheduleItemBudgetMapper tbsScheduleItemBudgetMapper; |
|
|
|
private final TbsBudgetChangeScheduleItemService tbsBudgetChangeScheduleItemService; |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@ -172,8 +181,44 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
} |
|
|
|
final Long budgetId = budget.getId(); |
|
|
|
if(budget.getBudgetState().equals(1)){ |
|
|
|
//生成更变记录
|
|
|
|
|
|
|
|
//适配更变记录
|
|
|
|
TbsBudgetChange budgetChange = TbsBudgetChange.toNewObject(budget); |
|
|
|
budgetChange.setChangeCode("BU"+CodeGenUtil.generate(CodeGenUtil.SourceKey.BudgetChange)); |
|
|
|
budgetChange.setUserId(sysUser.getId()); |
|
|
|
budgetChange.setUserCode(sysUser.getCode()); |
|
|
|
budgetChange.setUserName(sysUser.getName()); |
|
|
|
budgetChange.setBudgetCheckState(TbsBudgetCheckState.State_1_apply); |
|
|
|
boolean notChangeTitle = paramItem.getBudgetName()!=null&& paramItem.getBudgetName().equals(budget.getBudgetCode()); |
|
|
|
if(!notChangeTitle){ |
|
|
|
budgetChange.setNewBudgetTitle(paramItem.getBudgetName()); |
|
|
|
} |
|
|
|
tbsBudgetChangeService.save(budgetChange); |
|
|
|
Long changeId = budgetChange.getId(); |
|
|
|
//添加品类条件
|
|
|
|
if(budget.getConditionFlag().equals(1)){ |
|
|
|
List<TbsBudgetCondition> existingConditionList = tbsBudgetConditionService |
|
|
|
.list(new LambdaQueryWrapper<TbsBudgetCondition>() |
|
|
|
.eq(TbsBudgetCondition::getBudgetId,budgetId)); |
|
|
|
String bandNames = paramItem.getBandNames(); |
|
|
|
String categoryNames = paramItem.getCategoryNames(); |
|
|
|
String seriesNames = paramItem.getSeriesNames(); |
|
|
|
//设置changeConditionList参数
|
|
|
|
List<TbsBudgetChangeCondition> changeConditionList = new ArrayList<>(); |
|
|
|
this.buildChangeConditionList(categoryMap, budgetId, changeId, changeConditionList, existingConditionList, |
|
|
|
bandNames, TbsGoodsType.brand.name()); |
|
|
|
this.buildChangeConditionList(categoryMap, budgetId, changeId, changeConditionList, existingConditionList, |
|
|
|
categoryNames, TbsGoodsType.category.name()); |
|
|
|
this.buildChangeConditionList(categoryMap, budgetId, changeId, changeConditionList, existingConditionList, |
|
|
|
seriesNames, TbsGoodsType.series.name()); |
|
|
|
if(CollUtil.isNotEmpty(changeConditionList)){ |
|
|
|
tbsBudgetChangeConditionService.saveBatch(changeConditionList); |
|
|
|
} |
|
|
|
} |
|
|
|
List<TbsBudgetChangeScheduleItem> changeScheduleItemList = new ArrayList<>(); |
|
|
|
this.buildChangeSchduleBudgetList(paramItem, budgetId, changeId, changeScheduleItemList); |
|
|
|
if(CollUtil.isNotEmpty(changeScheduleItemList)){ |
|
|
|
tbsBudgetChangeScheduleItemService.saveBatch(changeScheduleItemList); |
|
|
|
} |
|
|
|
}else { |
|
|
|
//修改后为新增类型提交
|
|
|
|
tbsBudgetService.removeById(budgetId); |
|
|
@ -230,6 +275,68 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
private void buildChangeSchduleBudgetList(TbsBudgetBatchBo.BudgetMain paramItem, Long budgetId, Long changeId, List<TbsBudgetChangeScheduleItem> changeScheduleItemList) { |
|
|
|
//预算参数
|
|
|
|
List<TbsBudgetBatchBo.BudgetAmount> scheduleAmountList = paramItem.getScheduleAmount(); |
|
|
|
//预算项
|
|
|
|
List<TbsScheduleItemBudget> scheduleItemBudgetList = tbsScheduleItemBudgetService |
|
|
|
.list(new LambdaQueryWrapper<TbsScheduleItemBudget>() |
|
|
|
.eq(TbsScheduleItemBudget::getBudgetId, budgetId)); |
|
|
|
List<Long> scheduleItemBudgetIds = scheduleItemBudgetList.stream() |
|
|
|
.map(TbsScheduleItemBudget::getId).collect(Collectors.toList()); |
|
|
|
//实际发布预算
|
|
|
|
List<TbsBudgetLogWithAmount> budgetLogWithAmountList = tbsScheduleItemBudgetMapper.getAllByScheduleItemIdList(scheduleItemBudgetIds); |
|
|
|
|
|
|
|
for (TbsScheduleItemBudget itemBudget : scheduleItemBudgetList) { |
|
|
|
BigDecimal realAmt = BigDecimal.ZERO; |
|
|
|
for (TbsBudgetLogWithAmount withAmount : budgetLogWithAmountList) { |
|
|
|
if(withAmount.getId().equals(itemBudget.getId())){ |
|
|
|
realAmt = withAmount.getAmt(); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
for (TbsBudgetBatchBo.BudgetAmount budgetAmount : scheduleAmountList) { |
|
|
|
if(budgetAmount.getScheduleItemName().equals(itemBudget.getItemName())){ |
|
|
|
boolean ne1 = ! itemBudget.getPreDispatchAmount().equals(budgetAmount.getPreDispatchAmount()); |
|
|
|
boolean ne2 = ! realAmt.equals(budgetAmount.getBudgetAmount()); |
|
|
|
if(ne1 || ne2){ |
|
|
|
TbsBudgetChangeScheduleItem resultItem = TbsBudgetChangeScheduleItem.toNewObject(itemBudget); |
|
|
|
resultItem.setChangeId(changeId); |
|
|
|
resultItem.setNewBudgetAmount(realAmt); |
|
|
|
resultItem.setNewPreDispatchAmount(budgetAmount.getPreDispatchAmount()); |
|
|
|
changeScheduleItemList.add(resultItem); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void buildChangeConditionList(Map<String, GoodsCategory> categoryMap, Long budgetId, Long changeId, List<TbsBudgetChangeCondition> changeConditionList, List<TbsBudgetCondition> existingConditionList, String values, String targetType) { |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@NotNull |
|
|
|
private List<TbsBudgetCondition> createTbsBudgetConditions(Map<String, GoodsCategory> categoryMap, TbsBudgetBatchBo.BudgetMain paramItem, Long budgetId) { |
|
|
|
List<TbsBudgetCondition> conditionList = new ArrayList<>(); |
|
|
@ -326,7 +433,10 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
initCategorySet(goodsCategoryNames, seriesNames); |
|
|
|
} |
|
|
|
List<GoodsCategory> goodsCategories = goodsCategoryService.list( |
|
|
|
new LambdaQueryWrapper<GoodsCategory>().in(GoodsCategory::getName,goodsCategoryNames) |
|
|
|
new LambdaQueryWrapper<GoodsCategory>() |
|
|
|
.in(GoodsCategory::getName,goodsCategoryNames) |
|
|
|
.or() |
|
|
|
.in(GoodsCategory::getCode,goodsCategoryNames) |
|
|
|
); |
|
|
|
if(goodsCategories.size()!= goodsCategoryNames.size()){ |
|
|
|
for (String categoryName : goodsCategoryNames) { |
|
|
|