|
|
@ -4,12 +4,16 @@ 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.model.enums.BudgetLogOptFlag; |
|
|
|
import com.qs.serve.common.model.enums.MonthValues; |
|
|
|
import com.qs.serve.common.util.CopierUtil; |
|
|
|
import com.qs.serve.common.util.SpringUtils; |
|
|
|
import com.qs.serve.common.util.StringUtils; |
|
|
|
import com.qs.serve.modules.bir.entity.BirActivityCenterGoods; |
|
|
|
import com.qs.serve.modules.bir.entity.BirRoiRate; |
|
|
|
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.BirMonthCusCenterSo; |
|
|
|
import com.qs.serve.modules.bir.entity.vo.BirActivityCenterGoodsMonthVo; |
|
|
|
import com.qs.serve.modules.bir.entity.vo.BirRoiCostItemVo; |
|
|
|
import com.qs.serve.modules.bir.entity.vo.YtdQtdToOAVo; |
|
|
|
import com.qs.serve.modules.bir.mapper.BirActivityCenterGoodsMapper; |
|
|
@ -19,17 +23,17 @@ import com.qs.serve.modules.bir.service.BirCenterRateService; |
|
|
|
import com.qs.serve.modules.bir.service.BirRoiRateService; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsCenterRegion; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsSupplierTarget; |
|
|
|
import com.qs.serve.modules.bms.mapper.BmsCenterRegionMapper; |
|
|
|
import com.qs.serve.modules.bms.mapper.BmsSupplierMapper; |
|
|
|
import com.qs.serve.modules.bms.mapper.BmsSupplierTargetMapper; |
|
|
|
import com.qs.serve.modules.erp.entity.dto.ErpDispatchSumVo; |
|
|
|
import com.qs.serve.modules.erp.mapper.ErpDispatchDataMapper; |
|
|
|
import com.qs.serve.modules.tbs.common.util.QuarterUtil; |
|
|
|
import com.qs.serve.modules.tbs.entity.*; |
|
|
|
import com.qs.serve.modules.tbs.entity.dto.CusTargetRateDTO; |
|
|
|
import com.qs.serve.modules.tbs.entity.dto.TbsCostSubItem; |
|
|
|
import com.qs.serve.modules.tbs.mapper.TbsActivityCenterMapper; |
|
|
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetLogMapper; |
|
|
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetMapper; |
|
|
|
import com.qs.serve.modules.tbs.mapper.TbsScheduleItemBudgetMapper; |
|
|
|
import com.qs.serve.modules.tbs.mapper.*; |
|
|
|
import com.qs.serve.modules.tzc.entity.TzcPolicyItem; |
|
|
|
import com.qs.serve.modules.tzc.mapper.TzcPolicyItemMapper; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
@ -61,6 +65,8 @@ public class BirCenterRateServiceImpl implements BirCenterRateService { |
|
|
|
private TbsActivityCenterMapper tbsActivityCenterMapper; |
|
|
|
private TzcPolicyItemMapper tzcPolicyItemMapper; |
|
|
|
private TbsBudgetLogMapper tbsBudgetLogMapper; |
|
|
|
private BmsSupplierTargetMapper bmsSupplierTargetMapper; |
|
|
|
private TbsScheduleItemMapper tbsScheduleItemMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<TbsCostSubItem.CostCenterTranStr> findCostCenterDataByCostApplyId(Long costApplyId,Long policyId){ |
|
|
@ -101,9 +107,8 @@ public class BirCenterRateServiceImpl implements BirCenterRateService { |
|
|
|
return centerDataList; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public TbsCostSubItem.CostCenterTranStr buildCostCenter(String centerType, String centerId, String centerName){ |
|
|
|
public TbsCostSubItem.CostCenterTranStr buildCostCenter(String centerType, String centerId, String centerName, String supplierCode) { |
|
|
|
|
|
|
|
int year = LocalDate.now().getYear(); |
|
|
|
int month = LocalDate.now().getMonthValue(); |
|
|
@ -157,7 +162,9 @@ public class BirCenterRateServiceImpl implements BirCenterRateService { |
|
|
|
// costCenter.setMtdTargetSales(BigDecimal.ZERO);
|
|
|
|
// costCenter.setMtdTargetExpenseRate(BigDecimal.ZERO);
|
|
|
|
/* ------------------------------------------------------------------------- */ |
|
|
|
|
|
|
|
//实际发贷数
|
|
|
|
//supplierCodeList 指成本中心维度的客户,需要和参数supplierCode作区分
|
|
|
|
List<String> supplierCodeList = birRoiRateService.getSupplierCodesByCenter(costDTO,centerType, Arrays.asList(centerId)); |
|
|
|
List<ErpDispatchSumVo> dispatchSumVos = dispatchDataMapper.querySumCost(startMonthNum,endMonthNum,supplierCodeList); |
|
|
|
|
|
|
@ -207,8 +214,139 @@ public class BirCenterRateServiceImpl implements BirCenterRateService { |
|
|
|
mtdRealExpenseRate = mtdRealCost.divide(mtdRealDipatch, 2, BigDecimal.ROUND_HALF_DOWN); |
|
|
|
costCenter.setMtdRealExpenseRate(mtdRealExpenseRate.toString()); |
|
|
|
} |
|
|
|
//创建客户的费率
|
|
|
|
if(StringUtils.hasText(supplierCode)){ |
|
|
|
try { |
|
|
|
this.buildCustomerCenterTargetData(centerType, centerId, costCenter, supplierCode, dispatchSumVos); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("[{}]创建客户成本中心的费率出现异常:{}",supplierCode,e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
return costCenter; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public TbsCostSubItem.CostCenterTranStr buildCostCenter(String centerType, String centerId, String centerName){ |
|
|
|
return this.buildCostCenter(centerType, centerId, centerName,null); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 创建客户成本中心维度的目标数据 |
|
|
|
* @param centerType |
|
|
|
* @param centerId |
|
|
|
* @param costCenter |
|
|
|
* @param supplierCode |
|
|
|
* @param dispatchSumVos |
|
|
|
*/ |
|
|
|
private void buildCustomerCenterTargetData(String centerType, String centerId, TbsCostSubItem.CostCenterTranStr costCenter,String supplierCode, List<ErpDispatchSumVo> dispatchSumVos) { |
|
|
|
LocalDate nowTime = LocalDate.now(); |
|
|
|
int curYear = nowTime.getYear(); |
|
|
|
int curMonth = nowTime.getMonthValue(); |
|
|
|
String curMonthString = curMonth>9?curMonth+"":"0"+curMonth; |
|
|
|
int startMonth = Integer.parseInt(curYear+"01"); |
|
|
|
int endMonth = Integer.parseInt(curYear+curMonthString); |
|
|
|
int[] currQ = MonthValues.getQArr(curMonth); |
|
|
|
BirMonthCusCenterSo queryCusCenterRate = new BirMonthCusCenterSo(); |
|
|
|
queryCusCenterRate.setSupplierCode(supplierCode); |
|
|
|
queryCusCenterRate.setCenterType(centerType); |
|
|
|
queryCusCenterRate.setCenterId(centerId); |
|
|
|
queryCusCenterRate.setStartYearMonth(startMonth); |
|
|
|
queryCusCenterRate.setEndYearMonth(endMonth); |
|
|
|
//年目标费率
|
|
|
|
CusTargetRateDTO targetRateDTO = this.buildCusCenterTargetData(supplierCode); |
|
|
|
List<BirActivityCenterGoodsMonthVo> centerGoodsMonthVoList = birActivityCenterGoodsMapper.listMonthCusCenterVo(queryCusCenterRate); |
|
|
|
BigDecimal totalCostQty = BigDecimal.ZERO; |
|
|
|
BigDecimal totalDispatchQty = BigDecimal.ZERO; |
|
|
|
for (int monthNumber : currQ) { |
|
|
|
String tmp = monthNumber>9?monthNumber+"":"0"+monthNumber; |
|
|
|
int currYearMonth = Integer.parseInt(curYear+tmp); |
|
|
|
//计算发货金额
|
|
|
|
for (ErpDispatchSumVo dispatchSumVo : dispatchSumVos) { |
|
|
|
if(dispatchSumVo.getYearMonth()==currYearMonth){ |
|
|
|
totalDispatchQty = totalDispatchQty.add(dispatchSumVo.getDispatchSumCost()); |
|
|
|
} |
|
|
|
} |
|
|
|
//计算费用金额
|
|
|
|
for (BirActivityCenterGoodsMonthVo goodsMonthVo : centerGoodsMonthVoList) { |
|
|
|
if(goodsMonthVo.getKeyNum()==currYearMonth){ |
|
|
|
totalCostQty = totalCostQty.add(goodsMonthVo.getTotalCostAmt()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//计算年
|
|
|
|
BigDecimal totalCostYear = BigDecimal.ZERO; |
|
|
|
BigDecimal totalDispatchYear = BigDecimal.ZERO; |
|
|
|
for (BirActivityCenterGoodsMonthVo monthVo : centerGoodsMonthVoList) { |
|
|
|
totalCostYear = totalCostYear.add(monthVo.getTotalCostAmt()); |
|
|
|
} |
|
|
|
for (ErpDispatchSumVo dispatchSumVo : dispatchSumVos) { |
|
|
|
totalDispatchYear = totalDispatchYear.add(dispatchSumVo.getDispatchSumCost()); |
|
|
|
} |
|
|
|
//计算客户维度费率
|
|
|
|
costCenter.setQtdCusCenterCost(totalCostQty.toString()); |
|
|
|
costCenter.setQtdCusCenterSend(totalDispatchQty.toString()); |
|
|
|
costCenter.setQtdCusCenterExpenseRate(totalCostQty.divide(totalDispatchQty,RoundingMode.DOWN).toString()); |
|
|
|
costCenter.setQtdCusCenterTargetExpenseRate(targetRateDTO.getCusTargetRateQty()); |
|
|
|
costCenter.setYtdCusCenterCost(totalCostYear.toString()); |
|
|
|
costCenter.setYtdCusCenterSend(totalDispatchYear.toString()); |
|
|
|
costCenter.setYtdCusCenterExpenseRate(totalCostYear.divide(totalDispatchYear,RoundingMode.DOWN).toString()); |
|
|
|
costCenter.setYtdCusCenterTargetExpenseRate(targetRateDTO.getCusTargetRate()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 计算客户目标费率 |
|
|
|
* @param supplierCode |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public CusTargetRateDTO buildCusCenterTargetData(String supplierCode){ |
|
|
|
String cusTargetRateQty=null; |
|
|
|
String cusTargetRate=null; |
|
|
|
LocalDate nowTime = LocalDate.now(); |
|
|
|
int curYear = nowTime.getYear(); |
|
|
|
int curMonth = nowTime.getMonthValue(); |
|
|
|
int[] currQ = MonthValues.getQArr(curMonth); |
|
|
|
List<BmsSupplierTarget> supplierTargetList = bmsSupplierTargetMapper.selectList( |
|
|
|
new LambdaQueryWrapper<BmsSupplierTarget>() |
|
|
|
.in(BmsSupplierTarget::getSupplierCode, supplierCode) |
|
|
|
); |
|
|
|
List<Long> scheduleItemIds = supplierTargetList.stream().map(BmsSupplierTarget::getScheduleItemId).collect(Collectors.toList()); |
|
|
|
List<Long> scheduleIds = supplierTargetList.stream().map(BmsSupplierTarget::getScheduleId).collect(Collectors.toList()); |
|
|
|
Map<Long,TbsScheduleItem> scheduleItems = new HashMap<>(); |
|
|
|
if(scheduleItemIds.size()>0&&scheduleIds.size()>0){ |
|
|
|
LambdaQueryWrapper<TbsScheduleItem> scheduleItemsLqw = new LambdaQueryWrapper<>(); |
|
|
|
scheduleItemsLqw.in(TbsScheduleItem::getId,scheduleItemIds); |
|
|
|
scheduleItemsLqw.in(TbsScheduleItem::getScheduleId,scheduleIds); |
|
|
|
List<TbsScheduleItem> scheduleItemList = tbsScheduleItemMapper.selectList(scheduleItemsLqw); |
|
|
|
for (TbsScheduleItem scheduleItem : scheduleItemList) { |
|
|
|
scheduleItems.put(scheduleItem.getId(),scheduleItem); |
|
|
|
} |
|
|
|
} |
|
|
|
BigDecimal cusDispatchTarget = BigDecimal.ZERO; |
|
|
|
BigDecimal cusCostTarget = BigDecimal.ZERO; |
|
|
|
//季度
|
|
|
|
BigDecimal cusDispatchTargetQty = BigDecimal.ZERO; |
|
|
|
BigDecimal cusCostTargetQty = BigDecimal.ZERO; |
|
|
|
for (BmsSupplierTarget supplierTarget : supplierTargetList) { |
|
|
|
cusDispatchTarget = cusDispatchTarget.add(supplierTarget.getTargetCostAmount()); |
|
|
|
cusCostTarget = cusCostTarget.add(supplierTarget.getTargetCostAmount()); |
|
|
|
TbsScheduleItem itm = scheduleItems.get(supplierTarget.getScheduleItemId()); |
|
|
|
int itmYear =itm.getStartDate().getYear(); |
|
|
|
if(itmYear==curYear){ |
|
|
|
int itmMonth =itm.getStartDate().getMonthValue(); |
|
|
|
if(Arrays.stream(currQ).anyMatch(i->itmMonth==i)){ |
|
|
|
cusDispatchTargetQty = cusDispatchTargetQty.add(supplierTarget.getTargetCostAmount()); |
|
|
|
cusCostTargetQty = cusCostTargetQty.add(supplierTarget.getTargetCostAmount()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if(cusCostTarget.compareTo(BigDecimal.ZERO)!=0&&cusDispatchTarget.compareTo(BigDecimal.ZERO)!=0){ |
|
|
|
cusTargetRate = cusCostTarget.divide(cusDispatchTarget,RoundingMode.DOWN).toString(); |
|
|
|
} |
|
|
|
if(cusCostTargetQty.compareTo(BigDecimal.ZERO)!=0&&cusDispatchTargetQty.compareTo(BigDecimal.ZERO)!=0){ |
|
|
|
cusTargetRateQty = cusCostTargetQty.divide(cusDispatchTargetQty,RoundingMode.DOWN).toString(); |
|
|
|
} |
|
|
|
return new CusTargetRateDTO(cusTargetRateQty,cusTargetRate); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|