|
@ -14,6 +14,7 @@ import com.qs.serve.modules.bir.entity.dto.BirRoiCostDTO; |
|
|
import com.qs.serve.modules.bir.entity.so.BirCostRoiSo; |
|
|
import com.qs.serve.modules.bir.entity.so.BirCostRoiSo; |
|
|
import com.qs.serve.modules.bir.entity.so.BirMonthCusCenterSo; |
|
|
import com.qs.serve.modules.bir.entity.so.BirMonthCusCenterSo; |
|
|
import com.qs.serve.modules.bir.entity.vo.BirActivityCenterGoodsMonthVo; |
|
|
import com.qs.serve.modules.bir.entity.vo.BirActivityCenterGoodsMonthVo; |
|
|
|
|
|
import com.qs.serve.modules.bir.entity.vo.BirCostApplyRateVo; |
|
|
import com.qs.serve.modules.bir.entity.vo.BirRoiCostItemVo; |
|
|
import com.qs.serve.modules.bir.entity.vo.BirRoiCostItemVo; |
|
|
import com.qs.serve.modules.bir.entity.vo.YtdQtdToOAVo; |
|
|
import com.qs.serve.modules.bir.entity.vo.YtdQtdToOAVo; |
|
|
import com.qs.serve.modules.bir.mapper.BirActivityCenterGoodsMapper; |
|
|
import com.qs.serve.modules.bir.mapper.BirActivityCenterGoodsMapper; |
|
@ -113,6 +114,95 @@ public class BirCenterRateServiceImpl implements BirCenterRateService { |
|
|
return centerDataList; |
|
|
return centerDataList; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public List<BirCostApplyRateVo> selectCostApplyRateVoList(Long costApplyId, Long policyId) { |
|
|
|
|
|
|
|
|
|
|
|
TbsCostApply costApply = tbsCostApplyMapper.selectById(costApplyId); |
|
|
|
|
|
final String supplierId = costApply.getSupplierId()+""; |
|
|
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<TbsActivityCenter> acLqw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
acLqw.eq(TbsActivityCenter::getCostApplyId,costApplyId); |
|
|
|
|
|
List<TbsActivityCenter> activityCenterList = tbsActivityCenterMapper.selectList(acLqw); |
|
|
|
|
|
|
|
|
|
|
|
LocalDate nowDate = LocalDate.now(); |
|
|
|
|
|
int year = nowDate.getYear(); |
|
|
|
|
|
int month = nowDate.getMonthValue(); |
|
|
|
|
|
month = month>1?month:1; |
|
|
|
|
|
//年
|
|
|
|
|
|
int yearStartNum = year*100 + 1; |
|
|
|
|
|
int yearEndNum = year*100 + month; |
|
|
|
|
|
//当月
|
|
|
|
|
|
int currMonthNum = yearEndNum; |
|
|
|
|
|
//当季度
|
|
|
|
|
|
List<Integer> numbers = QuarterUtil.getQuarterNumbers(year,month); |
|
|
|
|
|
int quarterStartNum = numbers.get(0); |
|
|
|
|
|
int quarterEndNum = numbers.get(2); |
|
|
|
|
|
|
|
|
|
|
|
List<BirCostApplyRateVo> resultList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
List<BirCostApplyRateVo> yearList = this.buildCostApplyRateList( |
|
|
|
|
|
"year",yearStartNum, yearEndNum, |
|
|
|
|
|
supplierId, activityCenterList); |
|
|
|
|
|
|
|
|
|
|
|
List<BirCostApplyRateVo> seasonList = this.buildCostApplyRateList( |
|
|
|
|
|
"quarter",quarterStartNum, quarterEndNum, |
|
|
|
|
|
supplierId, activityCenterList); |
|
|
|
|
|
|
|
|
|
|
|
List<BirCostApplyRateVo> monthList = this.buildCostApplyRateList( |
|
|
|
|
|
"month",currMonthNum, currMonthNum, |
|
|
|
|
|
supplierId, activityCenterList); |
|
|
|
|
|
|
|
|
|
|
|
resultList.addAll(yearList); |
|
|
|
|
|
resultList.addAll(seasonList); |
|
|
|
|
|
resultList.addAll(monthList); |
|
|
|
|
|
return resultList; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<BirCostApplyRateVo> buildCostApplyRateList(String scheduleType,int startMonthNum, int endMonthNum, String supplierId, List<TbsActivityCenter> activityCenterList) { |
|
|
|
|
|
List<BirCostApplyRateVo> costApplyRateVoList = new ArrayList<>(); |
|
|
|
|
|
for (TbsActivityCenter center : activityCenterList) { |
|
|
|
|
|
BirCostApplyRateVo costApplyRateVo = new BirCostApplyRateVo(scheduleType,center); |
|
|
|
|
|
//周期内使用金额合计,成本中心
|
|
|
|
|
|
LambdaQueryWrapper<BirActivityCenterGoods> birCenterLwq = new LambdaQueryWrapper<>(); |
|
|
|
|
|
birCenterLwq.eq(BirActivityCenterGoods::getCenterId,center.getCenterId()); |
|
|
|
|
|
birCenterLwq.eq(BirActivityCenterGoods::getCenterType,center.getCenterType()); |
|
|
|
|
|
birCenterLwq.ge(BirActivityCenterGoods::getKeyNum, startMonthNum); |
|
|
|
|
|
birCenterLwq.le(BirActivityCenterGoods::getKeyNum, endMonthNum); |
|
|
|
|
|
List<BirActivityCenterGoods> birCenterCost = birActivityCenterGoodsMapper.selectList(birCenterLwq); |
|
|
|
|
|
BigDecimal centerUsedCost = birCenterCost.stream().map(BirActivityCenterGoods::getSplitUsedAmount).reduce(BigDecimal.ZERO,BigDecimal::add); |
|
|
|
|
|
//周期内使用金额合计,客户
|
|
|
|
|
|
LambdaQueryWrapper<BirActivityCenterGoods> birSupplierLwq = new LambdaQueryWrapper<>(); |
|
|
|
|
|
birSupplierLwq.eq(BirActivityCenterGoods::getSupplierId, supplierId); |
|
|
|
|
|
birSupplierLwq.ge(BirActivityCenterGoods::getKeyNum, startMonthNum); |
|
|
|
|
|
birSupplierLwq.le(BirActivityCenterGoods::getKeyNum, endMonthNum); |
|
|
|
|
|
List<BirActivityCenterGoods> birSupplierCost = birActivityCenterGoodsMapper.selectList(birSupplierLwq); |
|
|
|
|
|
BigDecimal supplierUsedCost = birSupplierCost.stream().map(BirActivityCenterGoods::getSplitUsedAmount).reduce(BigDecimal.ZERO,BigDecimal::add); |
|
|
|
|
|
|
|
|
|
|
|
//客户维度发货金额
|
|
|
|
|
|
List<ErpDispatchSumVo> dispatchSumSupplierVos = dispatchDataMapper.querySumCost(startMonthNum, endMonthNum,Arrays.asList(supplierId)); |
|
|
|
|
|
BigDecimal dispatchSumSupplierAmt = dispatchSumSupplierVos.stream().map(ErpDispatchSumVo::getDispatchSumCost).reduce(BigDecimal.ZERO,BigDecimal::add); |
|
|
|
|
|
|
|
|
|
|
|
//成本中心维度发货金额
|
|
|
|
|
|
List<String> supplierCodeList = birRoiRateService.getSupplierCodesByCenter( |
|
|
|
|
|
new BirRoiCostDTO(),center.getCenterType(), Arrays.asList(center.getCenterId())); |
|
|
|
|
|
List<ErpDispatchSumVo> dispatchSumCenterVos = dispatchDataMapper.querySumCost(startMonthNum, endMonthNum,supplierCodeList); |
|
|
|
|
|
BigDecimal dispatchSumCenterAmt = dispatchSumCenterVos.stream().map(ErpDispatchSumVo::getDispatchSumCost).reduce(BigDecimal.ZERO,BigDecimal::add); |
|
|
|
|
|
|
|
|
|
|
|
costApplyRateVo.setCusCostAmt(supplierUsedCost); |
|
|
|
|
|
costApplyRateVo.setCusDisAmt(dispatchSumSupplierAmt); |
|
|
|
|
|
costApplyRateVo.setCenterCostAmt(centerUsedCost); |
|
|
|
|
|
costApplyRateVo.setCenterDisAmt(dispatchSumCenterAmt); |
|
|
|
|
|
if(dispatchSumSupplierAmt.compareTo(BigDecimal.ZERO)!=0){ |
|
|
|
|
|
costApplyRateVo.setCusRate(supplierUsedCost.divide(dispatchSumSupplierAmt,2,RoundingMode.DOWN)); |
|
|
|
|
|
} |
|
|
|
|
|
if(dispatchSumCenterAmt.compareTo(BigDecimal.ZERO)!=0){ |
|
|
|
|
|
costApplyRateVo.setCenterRate(centerUsedCost.divide(dispatchSumCenterAmt,2,RoundingMode.DOWN)); |
|
|
|
|
|
} |
|
|
|
|
|
costApplyRateVoList.add(costApplyRateVo); |
|
|
|
|
|
} |
|
|
|
|
|
return costApplyRateVoList; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public TbsCostSubItem.CostCenterTranStr buildCostCenter(String centerType, String centerId, String centerName, String supplierCode) { |
|
|
public TbsCostSubItem.CostCenterTranStr buildCostCenter(String centerType, String centerId, String centerName, String supplierCode) { |
|
|
|
|
|
|
|
|