|
|
@ -1,5 +1,7 @@ |
|
|
|
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; |
|
|
|
import com.qs.serve.common.framework.manager.AsyncFactory; |
|
|
@ -7,27 +9,37 @@ import com.qs.serve.common.framework.manager.AsyncManager; |
|
|
|
import com.qs.serve.common.model.dto.R; |
|
|
|
import com.qs.serve.common.util.*; |
|
|
|
import com.qs.serve.common.util.model.DateFormatString; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsSubject; |
|
|
|
import com.qs.serve.modules.bms.service.BmsSubjectService; |
|
|
|
import com.qs.serve.modules.goods.common.GoodsType; |
|
|
|
import com.qs.serve.modules.goods.entity.GoodsCategory; |
|
|
|
import com.qs.serve.modules.goods.entity.GoodsSpu; |
|
|
|
import com.qs.serve.modules.goods.entity.dto.TbsCenterDto; |
|
|
|
import com.qs.serve.modules.goods.service.GoodsCategoryService; |
|
|
|
import com.qs.serve.modules.seeyon.entity.BaseCreateCallbackBo; |
|
|
|
import com.qs.serve.modules.seeyon.entity.BaseCreateProcessBo; |
|
|
|
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.TbsBudgetBatchItem; |
|
|
|
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; |
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import com.qs.serve.modules.tbs.entity.TbsBudgetBatch; |
|
|
|
import com.qs.serve.modules.tbs.service.TbsBudgetBatchService; |
|
|
|
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.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* 批量申请 服务实现类 |
|
|
@ -42,32 +54,31 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
private final SysUserService sysUserService; |
|
|
|
private final SeeYonRequestService seeYonService; |
|
|
|
private final ProjectProperties projectProperties; |
|
|
|
private final TbsBudgetService tbsBudgetService; |
|
|
|
private final TbsBudgetConditionService tbsBudgetConditionService; |
|
|
|
private final BmsSubjectService bmsSubjectService; |
|
|
|
private final TbsCenterDtoService tbsCenterDtoService; |
|
|
|
private final TbsScheduleService tbsScheduleService; |
|
|
|
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; |
|
|
|
private final TbsBudgetBatchItemService tbsBudgetBatchItemService; |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Object commit(TbsBudgetBatchBo param) { |
|
|
|
|
|
|
|
SysUser sysUser = sysUserService.getById(AuthContextUtils.getSysUserId()); |
|
|
|
String batchCode = CodeGenUtil.generate(CodeGenUtil.SourceKey.BudgetBatch); |
|
|
|
String templateCode = TbsSeeYonConst.BudgetBatchApplyConf.Code(); |
|
|
|
//构建Batch
|
|
|
|
TbsBudgetBatch budgetBatch = new TbsBudgetBatch(); |
|
|
|
budgetBatch.setBatchTitle(sysUser.getName()+"发起了批量导入预算"); |
|
|
|
budgetBatch.setBatchCode(batchCode); |
|
|
|
budgetBatch.setBatchState(TbsBudgetCheckState.State_0_unPublish); |
|
|
|
//budgetBatch.setSyFormId();
|
|
|
|
budgetBatch.setUserId(sysUser.getId()); |
|
|
|
budgetBatch.setUserCode(sysUser.getCode()); |
|
|
|
budgetBatch.setUserName(sysUser.getName()); |
|
|
|
budgetBatch.setSubmitTime(LocalDateTime.now()); |
|
|
|
budgetBatch.setRemark(param.getRemark()); |
|
|
|
|
|
|
|
TbsBudgetBatch budgetBatch = buildBatchData(param, batchCode, sysUser); |
|
|
|
//保存后赋值
|
|
|
|
Long budgetBatchId = budgetBatch.getId(); |
|
|
|
//新增的生成为草稿
|
|
|
|
//修改的生成为更变记录
|
|
|
|
|
|
|
|
//构建BatchItems
|
|
|
|
List<TbsBudgetBatchItem> batchItems = new ArrayList<>(); |
|
|
|
|
|
|
|
Map<String,Object> data = new HashMap<>(); |
|
|
|
data.put("exsp5", batchCode); |
|
|
@ -112,5 +123,414 @@ public class TbsBudgetBatchServiceImpl extends ServiceImpl<TbsBudgetBatchMapper, |
|
|
|
AsyncManager.me().execute(AsyncFactory.submitBudgetBatch(budgetBatchId+"")); |
|
|
|
return budgetBatch; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public TbsBudgetBatch buildBatchData(TbsBudgetBatchBo param,String batchCode,SysUser sysUser){ |
|
|
|
List<TbsBudgetBatchBo.BudgetMain> paramBudgetList = param.getBudgetList(); |
|
|
|
TbsBudgetBatch budgetBatch = new TbsBudgetBatch(); |
|
|
|
budgetBatch.setBatchTitle(sysUser.getName()+"发起了批量导入预算"); |
|
|
|
budgetBatch.setBatchCode(batchCode); |
|
|
|
budgetBatch.setBatchState(TbsBudgetCheckState.State_0_unPublish); |
|
|
|
//budgetBatch.setSyFormId();
|
|
|
|
budgetBatch.setUserId(sysUser.getId()); |
|
|
|
budgetBatch.setUserCode(sysUser.getCode()); |
|
|
|
budgetBatch.setUserName(sysUser.getName()); |
|
|
|
budgetBatch.setSubmitTime(LocalDateTime.now()); |
|
|
|
budgetBatch.setRemark(param.getRemark()); |
|
|
|
//构建BatchItems
|
|
|
|
List<TbsBudgetBatchItem> batchItems = new ArrayList<>(); |
|
|
|
//加载 周期信息
|
|
|
|
List<String> scheduleNames = paramBudgetList.stream() |
|
|
|
.map(TbsBudgetBatchBo.BudgetMain::getScheduleName).distinct().collect(Collectors.toList()); |
|
|
|
Map<String,TbsSchedule> scheduleMap = loadScheduleMap(scheduleNames); |
|
|
|
//加载 科目
|
|
|
|
Map<String,BmsSubject> subjectMap = loadSubjectMapWithFilterInvalid(param); |
|
|
|
//加载 成本中心
|
|
|
|
Map<String,TbsCenterDto> centerDtoMap = new HashMap<>(); |
|
|
|
for (TbsBudgetBatchBo.BudgetMain budgetMain : paramBudgetList) { |
|
|
|
TbsCenterDto centerDto = tbsCenterDtoService.getCenterDtoByName(budgetMain.getCenterType(),budgetMain.getCenterName(),true); |
|
|
|
//key=> budgetMain.getCenterType()+"_&_"+budgetMain.getCenterName()
|
|
|
|
centerDtoMap.put(budgetMain.getCenterType()+"_&_"+budgetMain.getCenterName(),centerDto); |
|
|
|
} |
|
|
|
//加载 品类
|
|
|
|
Map<String,GoodsCategory> categoryMap = loadGoodsCategoryMap(paramBudgetList); |
|
|
|
|
|
|
|
//修改的生成为更变记录
|
|
|
|
List<TbsBudgetBatchBo.BudgetMain> updBudgetList = paramBudgetList.stream() |
|
|
|
.filter(a->StringUtils.hasText(a.getBudgetNumber())).collect(Collectors.toList()); |
|
|
|
if(updBudgetList.size()>0){ |
|
|
|
List<String> budgetNumbers = updBudgetList.stream() |
|
|
|
.map(TbsBudgetBatchBo.BudgetMain::getBudgetNumber).collect(Collectors.toList()); |
|
|
|
List<TbsBudget> budgetList = tbsBudgetService.list( |
|
|
|
new LambdaQueryWrapper<TbsBudget>().in( |
|
|
|
TbsBudget::getBudgetNumber,budgetNumbers |
|
|
|
) |
|
|
|
); |
|
|
|
for (TbsBudget budget : budgetList) { |
|
|
|
if(budget.getBudgetCheckState()==TbsBudgetCheckState.State_1_apply){ |
|
|
|
Assert.throwEx("预算["+budget.getBudgetCode()+"]审批中,无法导入修改"); |
|
|
|
} |
|
|
|
} |
|
|
|
for (TbsBudget budget : budgetList) { |
|
|
|
TbsBudgetBatchBo.BudgetMain paramItem = null; |
|
|
|
for (TbsBudgetBatchBo.BudgetMain budgetMain : updBudgetList) { |
|
|
|
if(budgetMain.getBudgetNumber().equals(budget.getBudgetNumber())){ |
|
|
|
paramItem = budgetMain; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
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(); |
|
|
|
//添加品类条件
|
|
|
|
this.toSaveChangeCondition(categoryMap, budget, paramItem, budgetId, changeId); |
|
|
|
List<TbsBudgetChangeScheduleItem> changeScheduleItemList = new ArrayList<>(); |
|
|
|
this.buildChangeSchduleBudgetList(paramItem, budgetId, changeId, changeScheduleItemList); |
|
|
|
if(CollUtil.isNotEmpty(changeScheduleItemList)){ |
|
|
|
tbsBudgetChangeScheduleItemService.saveBatch(changeScheduleItemList); |
|
|
|
} |
|
|
|
TbsBudgetBatchItem batchItem = new TbsBudgetBatchItem(); |
|
|
|
batchItem.setBudgetId(budgetId); |
|
|
|
batchItem.setChangeId(changeId); |
|
|
|
batchItem.setBatchState(TbsBudgetCheckState.State_1_apply); |
|
|
|
batchItem.setUserId(sysUser.getId()); |
|
|
|
batchItem.setUserCode(sysUser.getCode()); |
|
|
|
batchItem.setUserName(sysUser.getName()); |
|
|
|
batchItems.add(batchItem); |
|
|
|
|
|
|
|
}else { |
|
|
|
//修改后为新增类型提交
|
|
|
|
this.toUpdateBudgetInfo(sysUser, scheduleMap, subjectMap, centerDtoMap, categoryMap, paramItem, budgetId); |
|
|
|
TbsBudgetBatchItem batchItem = new TbsBudgetBatchItem(); |
|
|
|
batchItem.setBudgetId(budgetId); |
|
|
|
batchItem.setBatchState(TbsBudgetCheckState.State_1_apply); |
|
|
|
batchItem.setUserId(sysUser.getId()); |
|
|
|
batchItem.setUserCode(sysUser.getCode()); |
|
|
|
batchItem.setUserName(sysUser.getName()); |
|
|
|
batchItems.add(batchItem); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//新增的生成为草稿
|
|
|
|
List<TbsBudgetBatchBo.BudgetMain> addBudgetList = paramBudgetList.stream() |
|
|
|
.filter(a->!StringUtils.hasText(a.getBudgetNumber())).collect(Collectors.toList()); |
|
|
|
for (TbsBudgetBatchBo.BudgetMain budgetMain : addBudgetList) { |
|
|
|
TbsBudget newBudget = new TbsBudget(); |
|
|
|
tbsBudgetService.save(newBudget); |
|
|
|
Long budgetId = newBudget.getId(); |
|
|
|
TbsSchedule schedule = scheduleMap.get(budgetMain.getScheduleName()); |
|
|
|
this.initBudget4Update(sysUser,schedule, subjectMap, centerDtoMap, budgetMain, newBudget); |
|
|
|
//创建新条件
|
|
|
|
List<TbsBudgetCondition> conditionList = this.createTbsBudgetConditions(categoryMap, budgetMain, budgetId); |
|
|
|
//创建新预算周期
|
|
|
|
List<TbsScheduleItemBudget> scheduleItemBudgetList = this.createTbsScheduleItemBudgetList(budgetMain, budgetId, schedule); |
|
|
|
//数据持久化
|
|
|
|
if(CollectionUtil.isNotEmpty(conditionList)){ |
|
|
|
tbsBudgetConditionService.saveBatch(conditionList); |
|
|
|
} |
|
|
|
tbsScheduleItemBudgetService.saveBatch(scheduleItemBudgetList); |
|
|
|
|
|
|
|
TbsBudgetBatchItem batchItem = new TbsBudgetBatchItem(); |
|
|
|
batchItem.setBudgetId(budgetId); |
|
|
|
batchItem.setBatchState(TbsBudgetCheckState.State_1_apply); |
|
|
|
batchItem.setUserId(sysUser.getId()); |
|
|
|
batchItem.setUserCode(sysUser.getCode()); |
|
|
|
batchItem.setUserName(sysUser.getName()); |
|
|
|
batchItems.add(batchItem); |
|
|
|
} |
|
|
|
this.save(budgetBatch); |
|
|
|
//保存后赋值
|
|
|
|
Long batchId = budgetBatch.getId(); |
|
|
|
batchItems.forEach(batchItem->batchItem.setBatchId(batchId)); |
|
|
|
tbsBudgetBatchItemService.saveBatch(batchItems); |
|
|
|
return budgetBatch; |
|
|
|
} |
|
|
|
|
|
|
|
private void toUpdateBudgetInfo(SysUser sysUser, Map<String, TbsSchedule> scheduleMap, Map<String, BmsSubject> subjectMap, Map<String, TbsCenterDto> centerDtoMap, Map<String, GoodsCategory> categoryMap, TbsBudgetBatchBo.BudgetMain paramItem, Long budgetId) { |
|
|
|
tbsBudgetService.removeById(budgetId); |
|
|
|
tbsBudgetConditionService.remove( |
|
|
|
new LambdaQueryWrapper<TbsBudgetCondition>() |
|
|
|
.eq(TbsBudgetCondition::getBudgetId, budgetId) |
|
|
|
); |
|
|
|
tbsScheduleItemBudgetService.remove( |
|
|
|
new LambdaQueryWrapper<TbsScheduleItemBudget>() |
|
|
|
.eq(TbsScheduleItemBudget::getBudgetId, budgetId) |
|
|
|
); |
|
|
|
//设置新的值
|
|
|
|
TbsBudget newBudget = new TbsBudget(); |
|
|
|
newBudget.setId(budgetId); |
|
|
|
TbsSchedule schedule = scheduleMap.get(paramItem.getScheduleName()); |
|
|
|
this.initBudget4Update(sysUser,schedule, subjectMap, centerDtoMap, paramItem, newBudget); |
|
|
|
//创建新条件
|
|
|
|
List<TbsBudgetCondition> conditionList = this.createTbsBudgetConditions(categoryMap, paramItem, budgetId); |
|
|
|
//创建新预算周期
|
|
|
|
List<TbsScheduleItemBudget> scheduleItemBudgetList = this.createTbsScheduleItemBudgetList(paramItem, budgetId, schedule); |
|
|
|
//数据持久化
|
|
|
|
tbsBudgetService.updateById(newBudget); |
|
|
|
if(CollectionUtil.isNotEmpty(conditionList)){ |
|
|
|
tbsBudgetConditionService.saveBatch(conditionList); |
|
|
|
} |
|
|
|
tbsScheduleItemBudgetService.saveBatch(scheduleItemBudgetList); |
|
|
|
} |
|
|
|
|
|
|
|
private void toSaveChangeCondition(Map<String, GoodsCategory> categoryMap, TbsBudget budget, TbsBudgetBatchBo.BudgetMain paramItem, Long budgetId, Long changeId) { |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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<>(); |
|
|
|
if(StringUtils.hasText(paramItem.getBandNames())){ |
|
|
|
String[] values = paramItem.getBandNames().split(","); |
|
|
|
for (String value : values) { |
|
|
|
GoodsCategory category = categoryMap.get(value); |
|
|
|
TbsBudgetCondition budgetCondition = new TbsBudgetCondition(); |
|
|
|
budgetCondition.setBudgetId(budgetId); |
|
|
|
budgetCondition.setTargetType(GoodsType.Brand.name()); |
|
|
|
budgetCondition.setTargetId(category.getId()); |
|
|
|
budgetCondition.setTargetCode(category.getCode()); |
|
|
|
budgetCondition.setTargetName(category.getName()); |
|
|
|
budgetCondition.setTargetLevelPathIds(category.getLevelPath()); |
|
|
|
budgetCondition.setTargetLevelPathNames(category.getLevelPathNames()); |
|
|
|
conditionList.add(budgetCondition); |
|
|
|
} |
|
|
|
} |
|
|
|
return conditionList; |
|
|
|
} |
|
|
|
|
|
|
|
@NotNull |
|
|
|
private List<TbsScheduleItemBudget> createTbsScheduleItemBudgetList(TbsBudgetBatchBo.BudgetMain paramItem, Long budgetId, TbsSchedule schedule) { |
|
|
|
List<TbsScheduleItemBudget> scheduleItemBudgetList = new ArrayList<>(); |
|
|
|
for (TbsScheduleItem scheduleItem : schedule.getScheduleItemlist()) { |
|
|
|
for (TbsBudgetBatchBo.BudgetAmount amountItem : paramItem.getScheduleAmount()) { |
|
|
|
if(scheduleItem.getItemName().equals(amountItem.getScheduleItemName())){ |
|
|
|
TbsScheduleItemBudget scheduleItemBudget = new TbsScheduleItemBudget(); |
|
|
|
scheduleItemBudget.setScheduleId(schedule.getId()); |
|
|
|
scheduleItemBudget.setScheduleItemId(scheduleItem.getId()); |
|
|
|
scheduleItemBudget.setItemName(scheduleItem.getItemName()); |
|
|
|
scheduleItemBudget.setStartDate(scheduleItem.getStartDate()); |
|
|
|
scheduleItemBudget.setEndDate(scheduleItem.getEndDate()); |
|
|
|
scheduleItemBudget.setBudgetId(budgetId); |
|
|
|
scheduleItemBudget.setBudgetAmount(amountItem.getBudgetAmount()); |
|
|
|
scheduleItemBudget.setPreDispatchAmount(amountItem.getPreDispatchAmount()); |
|
|
|
scheduleItemBudget.setPreDispatchAmountFirst(amountItem.getPreDispatchAmount()); |
|
|
|
scheduleItemBudgetList.add(scheduleItemBudget); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return scheduleItemBudgetList; |
|
|
|
} |
|
|
|
|
|
|
|
private void initBudget4Update(SysUser sysUser, TbsSchedule schedule, Map<String, BmsSubject> subjectMap, Map<String, TbsCenterDto> centerDtoMap, TbsBudgetBatchBo.BudgetMain paramItem, TbsBudget newBudget) { |
|
|
|
if(StringUtils.hasText(paramItem.getBudgetName())){ |
|
|
|
newBudget.setBudgetCode(paramItem.getBudgetName()); |
|
|
|
} |
|
|
|
newBudget.setBudgetNumber(paramItem.getBudgetNumber()); |
|
|
|
newBudget.setBudgetState(0); |
|
|
|
newBudget.setBudgetCheckState(TbsBudgetCheckState.State_1_apply); |
|
|
|
if(StringUtils.hasText(paramItem.getSubjectName())){ |
|
|
|
BmsSubject bmsSubject = subjectMap.get(paramItem.getSubjectName()); |
|
|
|
if(bmsSubject==null){ |
|
|
|
|
|
|
|
} |
|
|
|
newBudget.setSubjectId(bmsSubject.getId()); |
|
|
|
newBudget.setSubjectCode(bmsSubject.getSubjectCode()); |
|
|
|
newBudget.setSubjectName(bmsSubject.getSubjectName()); |
|
|
|
} |
|
|
|
String centerKey = paramItem.getCenterType()+"_&_"+ paramItem.getCenterName(); |
|
|
|
TbsCenterDto centerDto = centerDtoMap.get(centerKey); |
|
|
|
newBudget.setCenterId(centerDto.getId()); |
|
|
|
newBudget.setCenterType(centerDto.getCenterType()); |
|
|
|
newBudget.setCenterCode(centerDto.getCenterCode()); |
|
|
|
newBudget.setCenterName(centerDto.getCenterName()); |
|
|
|
newBudget.setScheduleId(schedule.getId()); |
|
|
|
newBudget.setScheduleCode(schedule.getCode()); |
|
|
|
newBudget.setScheduleName(schedule.getName()); |
|
|
|
boolean conditionFlag = StringUtils.hasText(paramItem.getCategoryNames()) |
|
|
|
||StringUtils.hasText(paramItem.getSeriesNames()) |
|
|
|
||StringUtils.hasText(paramItem.getBandNames()); |
|
|
|
newBudget.setConditionFlag(conditionFlag?0:1); |
|
|
|
newBudget.setUserId(sysUser.getId()); |
|
|
|
newBudget.setUserCode(sysUser.getCode()); |
|
|
|
newBudget.setUserName(sysUser.getName()); |
|
|
|
newBudget.setSubmitTime(LocalDateTime.now()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 加载类目 |
|
|
|
* @param paramBudgetList |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private Map<String,GoodsCategory> loadGoodsCategoryMap(List<TbsBudgetBatchBo.BudgetMain> paramBudgetList) { |
|
|
|
Set<String> goodsCategoryNames = new HashSet<>(); |
|
|
|
for (TbsBudgetBatchBo.BudgetMain budgetMain : paramBudgetList) { |
|
|
|
String bandNames = budgetMain.getBandNames(); |
|
|
|
String categoryNames = budgetMain.getCategoryNames(); |
|
|
|
String seriesNames = budgetMain.getSeriesNames(); |
|
|
|
initCategorySet(goodsCategoryNames, bandNames); |
|
|
|
initCategorySet(goodsCategoryNames, categoryNames); |
|
|
|
initCategorySet(goodsCategoryNames, seriesNames); |
|
|
|
} |
|
|
|
List<GoodsCategory> goodsCategories = goodsCategoryService.list( |
|
|
|
new LambdaQueryWrapper<GoodsCategory>() |
|
|
|
.in(GoodsCategory::getName,goodsCategoryNames) |
|
|
|
.or() |
|
|
|
.in(GoodsCategory::getCode,goodsCategoryNames) |
|
|
|
); |
|
|
|
if(goodsCategories.size()!= goodsCategoryNames.size()){ |
|
|
|
for (String categoryName : goodsCategoryNames) { |
|
|
|
boolean exist = goodsCategories.stream().anyMatch(a->a.getName().equals(categoryName)); |
|
|
|
if(!exist){ |
|
|
|
Assert.throwEx("无效的品类:"+categoryName); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Map<String,GoodsCategory> categoryMap = new HashMap<>(goodsCategories.size()); |
|
|
|
for (GoodsCategory category : goodsCategories) { |
|
|
|
categoryMap.put(category.getName(),category); |
|
|
|
} |
|
|
|
return categoryMap; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 初始化set |
|
|
|
* @param goodsCategories |
|
|
|
* @param categoryString |
|
|
|
*/ |
|
|
|
private void initCategorySet(Set<String> goodsCategories, String categoryString) { |
|
|
|
if(StringUtils.hasText(categoryString)){ |
|
|
|
String[] values = categoryString |
|
|
|
.replace(",",",") |
|
|
|
.split(","); |
|
|
|
goodsCategories.addAll(Arrays.asList(values)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private Map<String,TbsSchedule> loadScheduleMap(List<String> scheduleNames) { |
|
|
|
List<TbsSchedule> schedules = tbsScheduleService.list( |
|
|
|
new LambdaQueryWrapper<TbsSchedule>().in(TbsSchedule::getName, scheduleNames) |
|
|
|
); |
|
|
|
if(scheduleNames.size()!=schedules.size()){ |
|
|
|
for (String scheduleName : scheduleNames) { |
|
|
|
boolean exist = schedules.stream().anyMatch(a->a.getName().equals(scheduleName)); |
|
|
|
if(!exist){ |
|
|
|
Assert.throwEx("预算周期不存在:["+scheduleName+"]"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Map<String,TbsSchedule> scheduleMap = new HashMap<>(scheduleNames.size()); |
|
|
|
for (TbsSchedule schedule : schedules) { |
|
|
|
List<TbsScheduleItem> scheduleItems = tbsScheduleItemService.listByScheduleId(schedule.getId()); |
|
|
|
schedule.setScheduleItemlist(scheduleItems); |
|
|
|
scheduleMap.put(schedule.getName(),schedule); |
|
|
|
} |
|
|
|
return scheduleMap; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 加载param的所有科目(过滤无效的) |
|
|
|
* @param param |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private Map<String,BmsSubject> loadSubjectMapWithFilterInvalid(TbsBudgetBatchBo param){ |
|
|
|
List<String> subjectCodes = param.getBudgetList().stream().filter(a->a.getSubjectName()!=null) |
|
|
|
.map(TbsBudgetBatchBo.BudgetMain::getSubjectName) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
return bmsSubjectService.loadByNameOrCode(subjectCodes,true); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|