|
|
@ -11,6 +11,8 @@ import com.qs.serve.common.model.consts.BudgetLogRollbackFlag; |
|
|
|
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.bir.entity.BirActivityCenterGoods; |
|
|
|
import com.qs.serve.modules.bir.entity.dto.BirRoiCostDTO; |
|
|
|
import com.qs.serve.modules.bir.entity.vo.YtdQtdToOAVo; |
|
|
|
import com.qs.serve.modules.bir.service.BirRoiRateService; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsRegion; |
|
|
@ -21,6 +23,8 @@ import com.qs.serve.modules.bms.mapper.BmsRegion2Mapper; |
|
|
|
import com.qs.serve.modules.bms.mapper.BmsRegionMapper; |
|
|
|
import com.qs.serve.modules.bms.service.BmsSubjectService; |
|
|
|
import com.qs.serve.modules.bms.service.BmsSupplierService; |
|
|
|
import com.qs.serve.modules.erp.entity.dto.ErpDispatchSumVo; |
|
|
|
import com.qs.serve.modules.erp.mapper.ErpDispatchDataMapper; |
|
|
|
import com.qs.serve.modules.seeyon.entity.BaseCreateCallbackBo; |
|
|
|
import com.qs.serve.modules.seeyon.entity.BaseCreateProcessBo; |
|
|
|
import com.qs.serve.modules.seeyon.service.SeeYonRequestService; |
|
|
@ -31,15 +35,17 @@ import com.qs.serve.modules.sys.service.SysUserService; |
|
|
|
import com.qs.serve.modules.tbs.common.TbsActivityState; |
|
|
|
import com.qs.serve.modules.tbs.common.TbsCostApplyState; |
|
|
|
import com.qs.serve.modules.tbs.common.TbsSeeYonConst; |
|
|
|
import com.qs.serve.modules.tbs.common.util.QuarterUtil; |
|
|
|
import com.qs.serve.modules.tbs.common.util.TbsBudgetLogBuildUtil; |
|
|
|
import com.qs.serve.modules.tbs.entity.*; |
|
|
|
import com.qs.serve.modules.tbs.entity.bo.TbsAffairCommitBo; |
|
|
|
import com.qs.serve.modules.tbs.entity.dto.TbsCenterGoodBirDTO; |
|
|
|
import com.qs.serve.modules.tbs.entity.dto.TbsBudgetCostResult; |
|
|
|
import com.qs.serve.modules.tbs.entity.dto.TbsCostSubItem; |
|
|
|
import com.qs.serve.modules.tbs.mapper.*; |
|
|
|
import com.qs.serve.modules.tbs.service.*; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
import org.springframework.beans.BeansException; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
@ -81,6 +87,7 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC |
|
|
|
private BirRoiRateService birRoiRateService; |
|
|
|
private TbsCostPercentMapper tbsCostPercentMapper; |
|
|
|
private TbsScheduleItemBudgetMapper tbsScheduleItemBudgetMapper; |
|
|
|
private final ErpDispatchDataMapper dispatchDataMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@ -221,48 +228,8 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC |
|
|
|
data.put("exsp1",TbsSeeYonConst.CostApplyConf.Code()); |
|
|
|
data.put("money",tbsCostApply.getTotalActivityAmount()); |
|
|
|
|
|
|
|
//记录费率参数
|
|
|
|
YtdQtdToOAVo ytdQtdToOAVo = birRoiRateService.buildYtdAndQtdData(tbsCostApply); |
|
|
|
// data.put("ytdCusExpenseRate",ytdQtdToOAVo.getYtdCustomerPercent()==null?
|
|
|
|
// BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdCustomerPercent()));
|
|
|
|
// data.put("ytdEmpExpenseRate",ytdQtdToOAVo.getYtdUserPercent()==null?
|
|
|
|
// BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdUserPercent()));
|
|
|
|
// data.put("ytdAdminiExpenseRate",ytdQtdToOAVo.getYtdRegionPercent()==null?
|
|
|
|
// BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdRegionPercent()));
|
|
|
|
// data.put("ytdSalesExpenseRate",ytdQtdToOAVo.getYtdRegion2Percent()==null?
|
|
|
|
// BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdRegion2Percent()));
|
|
|
|
// data.put("cusExpenseRate",ytdQtdToOAVo.getQtdCustomerPercent()==null?
|
|
|
|
// BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdCustomerPercent()));
|
|
|
|
// data.put("empExpenseRate",ytdQtdToOAVo.getQtdUserPercent()==null?
|
|
|
|
// BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdUserPercent()));
|
|
|
|
// data.put("salesExpenseRate",ytdQtdToOAVo.getQtdRegionPercent()==null?
|
|
|
|
// BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdRegionPercent()));
|
|
|
|
// data.put("adminiExpenseRate",ytdQtdToOAVo.getQtdRegion2Percent()==null?
|
|
|
|
// BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdRegion2Percent()));
|
|
|
|
|
|
|
|
//插入记录表前移除历史记录
|
|
|
|
tbsCostPercentMapper.delByCostApplyId(tbsCostApply.getId()); |
|
|
|
TbsCostPercent costPercent = new TbsCostPercent(); |
|
|
|
costPercent.setCostApplyId(tbsCostApply.getId()); |
|
|
|
costPercent.setYtdCustomerPercent(ytdQtdToOAVo.getYtdCustomerPercent()==null? |
|
|
|
BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdCustomerPercent())); |
|
|
|
costPercent.setYtdUserPercent(ytdQtdToOAVo.getYtdUserPercent()==null? |
|
|
|
BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdUserPercent())); |
|
|
|
costPercent.setYtdRegion2Percent(ytdQtdToOAVo.getYtdRegion2Percent()==null? |
|
|
|
BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdRegion2Percent())); |
|
|
|
costPercent.setYtdRegionPercent(ytdQtdToOAVo.getYtdRegionPercent()==null? |
|
|
|
BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdRegionPercent())); |
|
|
|
costPercent.setQtdCustomerPercent(ytdQtdToOAVo.getQtdCustomerPercent()==null? |
|
|
|
BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdCustomerPercent())); |
|
|
|
costPercent.setQtdUserPercent(ytdQtdToOAVo.getQtdUserPercent()==null? |
|
|
|
BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdUserPercent())); |
|
|
|
costPercent.setQtdRegion2Percent(ytdQtdToOAVo.getQtdRegion2Percent()==null? |
|
|
|
BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdRegion2Percent())); |
|
|
|
costPercent.setQtdRegionPercent(ytdQtdToOAVo.getQtdRegionPercent()==null? |
|
|
|
BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdRegionPercent())); |
|
|
|
|
|
|
|
tbsCostPercentMapper.insert(costPercent); |
|
|
|
|
|
|
|
//记录主表费率参数
|
|
|
|
this.buildMainData4ROI(tbsCostApply, data); |
|
|
|
|
|
|
|
//拓展添加审批关联区域
|
|
|
|
String saleRegionId = supplier.handleSaleRegionId(); |
|
|
@ -289,60 +256,15 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC |
|
|
|
List<TbsActivitySubject> tbsActivitySubjects = tbsActivitySubjectService.listByCostApplyId(Long.parseLong(id)); |
|
|
|
List<String> subjectNames = tbsActivitySubjects.stream().map(TbsActivitySubject::getSubjectName).distinct().collect(Collectors.toList()); |
|
|
|
List<Object> subList = new ArrayList<>(); |
|
|
|
for (String subjectName : subjectNames) { |
|
|
|
subList.add(new TbsCostSubItem.Subject(subjectName)); |
|
|
|
} |
|
|
|
|
|
|
|
//目标费率和成本中心统计
|
|
|
|
List<TbsBudgetCostItem> tbsBudgetCostItems = result.getBudgetMatchList(); |
|
|
|
List<Long> scheduleItemBudgetIds = tbsBudgetCostItems.stream().map(a->a.getScheduleItemBudgetId()).distinct().collect(Collectors.toList()); |
|
|
|
List<TbsScheduleItemBudget> tbsScheduleItemBudgets = tbsScheduleItemBudgetMapper.selectBatchIds(scheduleItemBudgetIds); |
|
|
|
/*for(TbsScheduleItemBudget tbsScheduleItemBudget : tbsScheduleItemBudgets){ |
|
|
|
subList.add( |
|
|
|
new TbsCostSubItem.Amount( |
|
|
|
tbsScheduleItemBudget.getBudgetAmount(), |
|
|
|
tbsScheduleItemBudget.getPreDispatchAmount(), |
|
|
|
tbsScheduleItemBudget.compareTargetExpenseRate() |
|
|
|
) |
|
|
|
); |
|
|
|
}*/ |
|
|
|
for (TbsActivityCenter activityCenter : tbsActivityCenters) { |
|
|
|
TbsCostSubItem.CostCenter costCenter = new TbsCostSubItem.CostCenter(activityCenter.getCenterName(), |
|
|
|
activityCenter.getCenterType()+"_"+ activityCenter.getCenterId()); |
|
|
|
for (TbsBudget budget : result.getBudgetList()) { |
|
|
|
boolean eqType = activityCenter.getCenterType().equals(budget.getCenterType()); |
|
|
|
boolean eqCost = activityCenter.getCenterId().equals(budget.getCenterId()); |
|
|
|
if(eqType&&eqCost){ |
|
|
|
BigDecimal totalBudgetAmount = BigDecimal.ZERO; |
|
|
|
BigDecimal totalPreDispatchAmount = BigDecimal.ZERO; |
|
|
|
for (TbsScheduleItemBudget itemBudget : tbsScheduleItemBudgets) { |
|
|
|
if(itemBudget.getBudgetId().equals(budget.getId())){ |
|
|
|
if(itemBudget.getBudgetAmount()!=null){ |
|
|
|
totalBudgetAmount = totalBudgetAmount.add(itemBudget.getBudgetAmount()); |
|
|
|
} |
|
|
|
if(itemBudget.getPreDispatchAmount()!=null){ |
|
|
|
totalPreDispatchAmount = totalBudgetAmount.add(itemBudget.getPreDispatchAmount()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
costCenter.setAreaBudget(totalBudgetAmount); |
|
|
|
costCenter.setTargetSales(totalPreDispatchAmount); |
|
|
|
if(totalPreDispatchAmount.compareTo(BigDecimal.ZERO)!=0){ |
|
|
|
costCenter.setTargetExpenseRate(totalBudgetAmount.divide(totalPreDispatchAmount,BigDecimal.ROUND_DOWN)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
subList.add(costCenter); |
|
|
|
} |
|
|
|
|
|
|
|
//创建子表数据
|
|
|
|
this.buildSubList(result, tbsActivityCenters, subjectNames, subList); |
|
|
|
//创建商品抬头列表
|
|
|
|
List<TbsActivityGoods> tbsActivityGoods = tbsActivityGoodsService.listByCostApplyId(Long.parseLong(id)); |
|
|
|
Set<String> bands = new HashSet<>(); |
|
|
|
for (TbsActivityGoods tbsActivityGood : tbsActivityGoods) { |
|
|
|
String band = tbsActivityGood.getTargetLevelPathNames().split("_")[0]; |
|
|
|
bands.add(band); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String goods = bands.stream().collect(Collectors.joining(",")); |
|
|
|
data.put("chanPinPinLei",goods); |
|
|
|
data.put("sub",subList); |
|
|
@ -429,6 +351,234 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 记录主表费率参数 |
|
|
|
* @param tbsCostApply |
|
|
|
* @param data |
|
|
|
*/ |
|
|
|
private void buildMainData4ROI(TbsCostApply tbsCostApply, Map<String, Object> data) { |
|
|
|
YtdQtdToOAVo ytdQtdToOAVo = birRoiRateService.buildYtdAndQtdData(tbsCostApply); |
|
|
|
data.put("ytdCusExpenseRate",ytdQtdToOAVo.getYtdCustomerPercent()==null? |
|
|
|
BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdCustomerPercent())); |
|
|
|
data.put("ytdEmpExpenseRate",ytdQtdToOAVo.getYtdUserPercent()==null? |
|
|
|
BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdUserPercent())); |
|
|
|
data.put("ytdAdminiExpenseRate",ytdQtdToOAVo.getYtdRegionPercent()==null? |
|
|
|
BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdRegionPercent())); |
|
|
|
data.put("ytdSalesExpenseRate",ytdQtdToOAVo.getYtdRegion2Percent()==null? |
|
|
|
BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdRegion2Percent())); |
|
|
|
data.put("cusExpenseRate",ytdQtdToOAVo.getQtdCustomerPercent()==null? |
|
|
|
BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdCustomerPercent())); |
|
|
|
data.put("empExpenseRate",ytdQtdToOAVo.getQtdUserPercent()==null? |
|
|
|
BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdUserPercent())); |
|
|
|
data.put("salesExpenseRate",ytdQtdToOAVo.getQtdRegionPercent()==null? |
|
|
|
BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdRegionPercent())); |
|
|
|
data.put("adminiExpenseRate",ytdQtdToOAVo.getQtdRegion2Percent()==null? |
|
|
|
BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdRegion2Percent())); |
|
|
|
|
|
|
|
//插入记录表前移除历史记录
|
|
|
|
// tbsCostPercentMapper.delByCostApplyId(tbsCostApply.getId());
|
|
|
|
// TbsCostPercent costPercent = new TbsCostPercent();
|
|
|
|
// costPercent.setCostApplyId(tbsCostApply.getId());
|
|
|
|
// costPercent.setYtdCustomerPercent(ytdQtdToOAVo.getYtdCustomerPercent()==null?
|
|
|
|
// BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdCustomerPercent()));
|
|
|
|
// costPercent.setYtdUserPercent(ytdQtdToOAVo.getYtdUserPercent()==null?
|
|
|
|
// BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdUserPercent()));
|
|
|
|
// costPercent.setYtdRegion2Percent(ytdQtdToOAVo.getYtdRegion2Percent()==null?
|
|
|
|
// BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdRegion2Percent()));
|
|
|
|
// costPercent.setYtdRegionPercent(ytdQtdToOAVo.getYtdRegionPercent()==null?
|
|
|
|
// BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getYtdRegionPercent()));
|
|
|
|
// costPercent.setQtdCustomerPercent(ytdQtdToOAVo.getQtdCustomerPercent()==null?
|
|
|
|
// BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdCustomerPercent()));
|
|
|
|
// costPercent.setQtdUserPercent(ytdQtdToOAVo.getQtdUserPercent()==null?
|
|
|
|
// BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdUserPercent()));
|
|
|
|
// costPercent.setQtdRegion2Percent(ytdQtdToOAVo.getQtdRegion2Percent()==null?
|
|
|
|
// BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdRegion2Percent()));
|
|
|
|
// costPercent.setQtdRegionPercent(ytdQtdToOAVo.getQtdRegionPercent()==null?
|
|
|
|
// BigDecimal.ZERO:BigDecimal.valueOf(ytdQtdToOAVo.getQtdRegionPercent()));
|
|
|
|
// tbsCostPercentMapper.insert(costPercent);
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 创建子表数据 |
|
|
|
* @param result |
|
|
|
* @param tbsActivityCenters |
|
|
|
* @param subjectNames |
|
|
|
* @param subList |
|
|
|
*/ |
|
|
|
private void buildSubList(TbsBudgetCostResult result, List<TbsActivityCenter> tbsActivityCenters, List<String> subjectNames, List<Object> subList) { |
|
|
|
for (String subjectName : subjectNames) { |
|
|
|
subList.add(new TbsCostSubItem.Subject(subjectName)); |
|
|
|
} |
|
|
|
|
|
|
|
//目标费率和成本中心统计
|
|
|
|
List<TbsBudgetCostItem> tbsBudgetCostItems = result.getBudgetMatchList(); |
|
|
|
List<Long> scheduleItemBudgetIds = tbsBudgetCostItems.stream().map(a->a.getScheduleItemBudgetId()).distinct().collect(Collectors.toList()); |
|
|
|
List<TbsScheduleItemBudget> tbsScheduleItemBudgets = tbsScheduleItemBudgetMapper.selectBatchIds(scheduleItemBudgetIds); |
|
|
|
/*for(TbsScheduleItemBudget tbsScheduleItemBudget : tbsScheduleItemBudgets){ |
|
|
|
subList.add( |
|
|
|
new TbsCostSubItem.Amount( |
|
|
|
tbsScheduleItemBudget.getBudgetAmount(), |
|
|
|
tbsScheduleItemBudget.getPreDispatchAmount(), |
|
|
|
tbsScheduleItemBudget.compareTargetExpenseRate() |
|
|
|
) |
|
|
|
); |
|
|
|
}*/ |
|
|
|
|
|
|
|
//查询发货金额,并按月份分割
|
|
|
|
int year = LocalDate.now().getYear(); |
|
|
|
int month = LocalDate.now().getMonthValue(); |
|
|
|
int startMonthNum = Integer.parseInt(year+"01"); |
|
|
|
int endMonthNum = Integer.parseInt(year+"01"); |
|
|
|
tbsActivityCenters.stream().collect(Collectors.groupingBy(TbsActivityCenter::getCenterType)); |
|
|
|
BirRoiRateService roiRateService = SpringUtils.getBean(BirRoiRateService.class); |
|
|
|
BirRoiCostDTO costDTO = new BirRoiCostDTO(); |
|
|
|
costDTO.setStartMonthNum(startMonthNum); |
|
|
|
costDTO.setEndMonthNum(endMonthNum); |
|
|
|
/*成本中心维度*/ |
|
|
|
//发货单
|
|
|
|
Map<String,List<ErpDispatchSumVo>> supplierCodeMapWithCenterType = new HashMap<>(); |
|
|
|
Map<String,List<TbsActivityCenter>> centerMapList = tbsActivityCenters.stream().collect(Collectors.groupingBy(TbsActivityCenter::getCenterType)); |
|
|
|
for (String centerType : centerMapList.keySet()) { |
|
|
|
List<String> centerIds =centerMapList.get(centerType).stream().map(a->a.getCenterId()).collect(Collectors.toList()); |
|
|
|
List<String> supplierCodeList = roiRateService.getSupplierCodesByCenter(costDTO,centerType,centerIds); |
|
|
|
//发货单
|
|
|
|
List<ErpDispatchSumVo> dispatchSumVos = null; |
|
|
|
if(supplierCodeList.size()>0){ |
|
|
|
dispatchSumVos = dispatchDataMapper.querySumCost(startMonthNum,endMonthNum,supplierCodeList); |
|
|
|
supplierCodeMapWithCenterType.put(centerType,dispatchSumVos); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//查询ROI底表,并拼接DTO
|
|
|
|
List<TbsCenterGoodBirDTO> centerGoodDTOS = new ArrayList<>(); |
|
|
|
List<BirActivityCenterGoods> birActivityCenterGoodsList = new ArrayList<>(); |
|
|
|
//按成本中心维度分组
|
|
|
|
Map<String,List<BirActivityCenterGoods>> birGroupByCenter = birActivityCenterGoodsList.stream() |
|
|
|
.collect(Collectors.groupingBy(a->a.getCenterType()+"_"+a.getCenterId())); |
|
|
|
|
|
|
|
for (TbsActivityCenter activityCenter : tbsActivityCenters) { |
|
|
|
String centerKey = activityCenter.getCenterType()+"_"+activityCenter.getCenterId(); |
|
|
|
//创建成本中心维度对象
|
|
|
|
TbsCostSubItem.CostCenter costCenter = this.buildCostCenterParam(result, tbsScheduleItemBudgets, |
|
|
|
year, month, supplierCodeMapWithCenterType, birGroupByCenter, activityCenter, centerKey); |
|
|
|
subList.add(costCenter); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 创建成本中心维度对象 |
|
|
|
* @param result |
|
|
|
* @param tbsScheduleItemBudgets |
|
|
|
* @param year |
|
|
|
* @param month |
|
|
|
* @param supplierCodeMapWithCenterType |
|
|
|
* @param birGroupByCenter |
|
|
|
* @param activityCenter |
|
|
|
* @param centerKey |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@NotNull |
|
|
|
private TbsCostSubItem.CostCenter buildCostCenterParam(TbsBudgetCostResult result, List<TbsScheduleItemBudget> tbsScheduleItemBudgets, int year, int month, Map<String, List<ErpDispatchSumVo>> supplierCodeMapWithCenterType, Map<String, List<BirActivityCenterGoods>> birGroupByCenter, TbsActivityCenter activityCenter, String centerKey) { |
|
|
|
TbsCostSubItem.CostCenter costCenter = new TbsCostSubItem.CostCenter(activityCenter.getCenterName(), |
|
|
|
activityCenter.getCenterType()+"_"+ activityCenter.getCenterId()); |
|
|
|
//设置目标销量、目标预算
|
|
|
|
for (TbsBudget budget : result.getBudgetList()) { |
|
|
|
boolean eqType = activityCenter.getCenterType().equals(budget.getCenterType()); |
|
|
|
boolean eqCost = activityCenter.getCenterId().equals(budget.getCenterId()); |
|
|
|
if (eqType && eqCost) { |
|
|
|
BigDecimal totalBudgetAmount = BigDecimal.ZERO; |
|
|
|
BigDecimal totalPreDispatchAmount = BigDecimal.ZERO; |
|
|
|
for (TbsScheduleItemBudget itemBudget : tbsScheduleItemBudgets) { |
|
|
|
if (itemBudget.getBudgetId().equals(budget.getId())) { |
|
|
|
if (itemBudget.getBudgetAmount() != null) { |
|
|
|
totalBudgetAmount = totalBudgetAmount.add(itemBudget.getBudgetAmount()); |
|
|
|
} |
|
|
|
if (itemBudget.getPreDispatchAmount() != null) { |
|
|
|
totalPreDispatchAmount = totalBudgetAmount.add(itemBudget.getPreDispatchAmount()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
costCenter.setAreaBudget(totalBudgetAmount); |
|
|
|
costCenter.setTargetSales(totalPreDispatchAmount); |
|
|
|
if (totalPreDispatchAmount.compareTo(BigDecimal.ZERO) != 0) { |
|
|
|
costCenter.setTargetExpenseRate(totalBudgetAmount.divide(totalPreDispatchAmount, BigDecimal.ROUND_DOWN)); |
|
|
|
} |
|
|
|
//暂保持目标相关数据一致
|
|
|
|
costCenter.setYtdTargetSales(costCenter.getTargetSales()); |
|
|
|
costCenter.setYtdTargetBudget(costCenter.getAreaBudget()); |
|
|
|
costCenter.setYtdTargetExpenseRate(costCenter.getTargetExpenseRate()); |
|
|
|
costCenter.setQtdTargetSales(costCenter.getTargetSales()); |
|
|
|
costCenter.setQtdTargetBudget(costCenter.getAreaBudget()); |
|
|
|
costCenter.setQtdTargetExpenseRate(costCenter.getTargetExpenseRate()); |
|
|
|
// costCenter.setMtdTargetSales();
|
|
|
|
// costCenter.setMtdTargetBudget();
|
|
|
|
// costCenter.setMtdTargetExpenseRate();
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
//发货金额
|
|
|
|
List<ErpDispatchSumVo> erpDispatchSumVoList = supplierCodeMapWithCenterType.get(centerKey); |
|
|
|
|
|
|
|
//年费率
|
|
|
|
List<BirActivityCenterGoods> centerGoods = birGroupByCenter.get(centerKey); |
|
|
|
TbsCenterGoodBirDTO bir4Year = this.getTbsCenterGoodBirDTO(centerGoods,erpDispatchSumVoList); |
|
|
|
costCenter.setYtdRealSales(bir4Year.getRealSales()); |
|
|
|
costCenter.setYtdRealCost(bir4Year.getRealCost()); |
|
|
|
costCenter.setYtdRealExpenseRate(bir4Year.getRealExpenseRate()); |
|
|
|
|
|
|
|
//季度
|
|
|
|
List<Integer> yearMonthList =QuarterUtil.getQuarterNumbers(year, month); |
|
|
|
List<BirActivityCenterGoods> centerGoodsQuarter = centerGoods.stream() |
|
|
|
.filter(a-> yearMonthList.contains(a.getKeyNum())) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
TbsCenterGoodBirDTO bir4Quarter = this.getTbsCenterGoodBirDTO(centerGoodsQuarter,erpDispatchSumVoList); |
|
|
|
costCenter.setQtdRealSales(bir4Quarter.getRealSales()); |
|
|
|
costCenter.setQtdRealCost(bir4Quarter.getRealCost()); |
|
|
|
costCenter.setQtdRealExpenseRate(bir4Quarter.getRealExpenseRate()); |
|
|
|
|
|
|
|
//月份
|
|
|
|
String mStr = month >9? month +"":"0"+ month; |
|
|
|
Integer currYearMonth = Integer.parseInt(year +mStr); |
|
|
|
List<BirActivityCenterGoods> centerGoodsM = centerGoods.stream() |
|
|
|
.filter(a-> currYearMonth.equals(a.getKeyNum())) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
TbsCenterGoodBirDTO bir4Month = this.getTbsCenterGoodBirDTO(centerGoodsM,erpDispatchSumVoList); |
|
|
|
costCenter.setMtdRealSales(bir4Month.getRealSales()); |
|
|
|
costCenter.setMtdRealCost(bir4Month.getRealCost()); |
|
|
|
costCenter.setMtdRealExpenseRate(bir4Month.getRealExpenseRate()); |
|
|
|
return costCenter; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 创建 成本中心 DTO |
|
|
|
* @param centerGoods |
|
|
|
* @param erpDispatchSumVoList |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@NotNull |
|
|
|
private TbsCenterGoodBirDTO getTbsCenterGoodBirDTO(List<BirActivityCenterGoods> centerGoods,List<ErpDispatchSumVo> erpDispatchSumVoList) { |
|
|
|
BigDecimal totalRealDispatch = BigDecimal.ZERO; |
|
|
|
BigDecimal totalRealCost; |
|
|
|
BigDecimal totalRealCheck = BigDecimal.ZERO; |
|
|
|
BigDecimal totalRealRelease = BigDecimal.ZERO; |
|
|
|
for (BirActivityCenterGoods centerGood : centerGoods) { |
|
|
|
totalRealCheck = totalRealCheck.add(centerGood.getSplitUsedAmount()); |
|
|
|
totalRealRelease = totalRealRelease.add(centerGood.getSplitReleaseAmount()); |
|
|
|
for (ErpDispatchSumVo dispatchSumVo : erpDispatchSumVoList) { |
|
|
|
if(centerGood.getKeyNum().equals(dispatchSumVo.getYearMonth())){ |
|
|
|
totalRealDispatch = totalRealDispatch.add(dispatchSumVo.getDispatchSumCost()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
totalRealCost = totalRealCheck.add(totalRealRelease); |
|
|
|
TbsCenterGoodBirDTO birDTO = new TbsCenterGoodBirDTO(); |
|
|
|
birDTO.setRealCost(totalRealCost); |
|
|
|
birDTO.setRealCheck(totalRealCheck); |
|
|
|
birDTO.setRealRelease(totalRealRelease); |
|
|
|
birDTO.initRealExpenseRate(); |
|
|
|
return birDTO; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|