diff --git a/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsBudgetBatchServiceImpl.java b/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsBudgetBatchServiceImpl.java index 1e2eecdd..8fcfc705 100644 --- a/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsBudgetBatchServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsBudgetBatchServiceImpl.java @@ -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 existingConditionList = tbsBudgetConditionService + .list(new LambdaQueryWrapper() + .eq(TbsBudgetCondition::getBudgetId,budgetId)); + String bandNames = paramItem.getBandNames(); + String categoryNames = paramItem.getCategoryNames(); + String seriesNames = paramItem.getSeriesNames(); + //设置changeConditionList参数 + List 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 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 changeScheduleItemList) { + //预算参数 + List scheduleAmountList = paramItem.getScheduleAmount(); + //预算项 + List scheduleItemBudgetList = tbsScheduleItemBudgetService + .list(new LambdaQueryWrapper() + .eq(TbsScheduleItemBudget::getBudgetId, budgetId)); + List scheduleItemBudgetIds = scheduleItemBudgetList.stream() + .map(TbsScheduleItemBudget::getId).collect(Collectors.toList()); + //实际发布预算 + List 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 categoryMap, Long budgetId, Long changeId, List changeConditionList, List 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 createTbsBudgetConditions(Map categoryMap, TbsBudgetBatchBo.BudgetMain paramItem, Long budgetId) { List conditionList = new ArrayList<>(); @@ -326,7 +433,10 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl goodsCategories = goodsCategoryService.list( - new LambdaQueryWrapper().in(GoodsCategory::getName,goodsCategoryNames) + new LambdaQueryWrapper() + .in(GoodsCategory::getName,goodsCategoryNames) + .or() + .in(GoodsCategory::getCode,goodsCategoryNames) ); if(goodsCategories.size()!= goodsCategoryNames.size()){ for (String categoryName : goodsCategoryNames) {