@ -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 ;
@ -29,6 +30,7 @@ import com.qs.serve.modules.bms.mapper.BmsSupplierMapper;
import com.qs.serve.modules.bms.mapper.BmsSupplierTargetMapper ;
import com.qs.serve.modules.bms.mapper.BmsSupplierTargetMapper ;
import com.qs.serve.modules.erp.entity.dto.ErpDispatchSumVo ;
import com.qs.serve.modules.erp.entity.dto.ErpDispatchSumVo ;
import com.qs.serve.modules.erp.mapper.ErpDispatchDataMapper ;
import com.qs.serve.modules.erp.mapper.ErpDispatchDataMapper ;
import com.qs.serve.modules.goods.entity.dto.TbsCenterDto ;
import com.qs.serve.modules.tbs.common.util.QuarterUtil ;
import com.qs.serve.modules.tbs.common.util.QuarterUtil ;
import com.qs.serve.modules.tbs.entity.* ;
import com.qs.serve.modules.tbs.entity.* ;
import com.qs.serve.modules.tbs.entity.dto.CusTargetRateDTO ;
import com.qs.serve.modules.tbs.entity.dto.CusTargetRateDTO ;
@ -38,6 +40,7 @@ import com.qs.serve.modules.tzc.entity.TzcPolicy;
import com.qs.serve.modules.tzc.entity.TzcPolicyItem ;
import com.qs.serve.modules.tzc.entity.TzcPolicyItem ;
import com.qs.serve.modules.tzc.mapper.TzcPolicyItemMapper ;
import com.qs.serve.modules.tzc.mapper.TzcPolicyItemMapper ;
import com.qs.serve.modules.tzc.mapper.TzcPolicyMapper ;
import com.qs.serve.modules.tzc.mapper.TzcPolicyMapper ;
import com.qs.serve.modules.tzc.service.TzcPolicyService ;
import lombok.AllArgsConstructor ;
import lombok.AllArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.stereotype.Service ;
import org.springframework.stereotype.Service ;
@ -113,6 +116,132 @@ public class BirCenterRateServiceImpl implements BirCenterRateService {
return centerDataList ;
return centerDataList ;
}
}
@Override
public List < BirCostApplyRateVo > selectCostApplyRateVoList ( Long costApplyId , Long policyId ) {
List < TbsCenterDto > centerDtoList = null ;
String supplierId = null ;
if ( costApplyId ! = null ) {
TbsCostApply costApply = tbsCostApplyMapper . selectById ( costApplyId ) ;
LambdaQueryWrapper < TbsActivityCenter > acLqw = new LambdaQueryWrapper < > ( ) ;
acLqw . eq ( TbsActivityCenter : : getCostApplyId , costApplyId ) ;
List < TbsActivityCenter > activityCenterList = tbsActivityCenterMapper . selectList ( acLqw ) ;
supplierId = costApply . getSupplierId ( ) + "" ;
centerDtoList = activityCenterList . stream ( ) . map ( a - > {
TbsCenterDto centerDto = new TbsCenterDto ( ) ;
centerDto . setId ( a . getCenterId ( ) ) ;
centerDto . setCenterCode ( a . getCenterCode ( ) ) ;
centerDto . setCenterName ( a . getCenterName ( ) ) ;
centerDto . setCenterType ( a . getCenterType ( ) ) ;
return centerDto ;
} ) . collect ( Collectors . toList ( ) ) ;
} else {
//加载政策
TzcPolicy policy = tzcPolicyMapper . selectById ( policyId ) ;
supplierId = policy . getSupplierId ( ) + "" ;
LambdaQueryWrapper < TzcPolicyItem > lqw = new LambdaQueryWrapper < > ( ) ;
lqw . eq ( TzcPolicyItem : : getPolicyId , policyId ) ;
List < TzcPolicyItem > policyItemList = tzcPolicyItemMapper . selectList ( lqw ) ;
centerDtoList = policyItemList . stream ( ) . map ( a - > {
TbsCenterDto centerDto = new TbsCenterDto ( ) ;
centerDto . setId ( a . getCenterId ( ) ) ;
centerDto . setCenterCode ( a . getCenterCode ( ) ) ;
centerDto . setCenterName ( a . getCenterName ( ) ) ;
centerDto . setCenterType ( a . getCenterType ( ) ) ;
return centerDto ;
} ) . collect ( Collectors . toList ( ) ) ;
}
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 , centerDtoList ) ;
List < BirCostApplyRateVo > seasonList = this . buildCostApplyRateList (
"quarter" , quarterStartNum , quarterEndNum ,
supplierId , centerDtoList ) ;
List < BirCostApplyRateVo > monthList = this . buildCostApplyRateList (
"month" , currMonthNum , currMonthNum ,
supplierId , centerDtoList ) ;
resultList . addAll ( yearList ) ;
resultList . addAll ( seasonList ) ;
resultList . addAll ( monthList ) ;
return resultList ;
}
/ * *
* 获取费率详情
* @param scheduleType 年季月 , year , quarter , month
* @param startMonthNum 格式如 20231
* @param endMonthNum 格式如 202312
* @param supplierId
* @param centerDtoList
* @return
* /
private List < BirCostApplyRateVo > buildCostApplyRateList ( String scheduleType , int startMonthNum , int endMonthNum , String supplierId ,
List < TbsCenterDto > centerDtoList ) {
List < BirCostApplyRateVo > costApplyRateVoList = new ArrayList < > ( ) ;
for ( TbsCenterDto center : centerDtoList ) {
BirCostApplyRateVo costApplyRateVo = new BirCostApplyRateVo ( scheduleType , center ) ;
//周期内使用金额合计,成本中心
LambdaQueryWrapper < BirActivityCenterGoods > birCenterLwq = new LambdaQueryWrapper < > ( ) ;
birCenterLwq . eq ( BirActivityCenterGoods : : getCenterId , center . getId ( ) ) ;
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 . getId ( ) ) ) ;
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 ) {