Browse Source

客户的成本中心维度费率

v1.0
Yen 2 years ago
parent
commit
f97f890003
  1. 18
      src/main/java/com/qs/serve/modules/bir/entity/so/BirMonthCusCenterSo.java
  2. 26
      src/main/java/com/qs/serve/modules/bir/entity/vo/BirActivityCenterGoodsMonthVo.java
  3. 5
      src/main/java/com/qs/serve/modules/bir/mapper/BirActivityCenterGoodsMapper.java
  4. 12
      src/main/java/com/qs/serve/modules/bir/service/BirActivityCenterGoodsService.java
  5. 11
      src/main/java/com/qs/serve/modules/bir/service/BirCenterRateService.java
  6. 7
      src/main/java/com/qs/serve/modules/bir/service/impl/BirActivityCenterGoodsServiceImpl.java
  7. 150
      src/main/java/com/qs/serve/modules/bir/service/impl/BirCenterRateServiceImpl.java
  8. 3
      src/main/java/com/qs/serve/modules/bms/entity/BmsSupplierAddress.java
  9. 9
      src/main/java/com/qs/serve/modules/tbs/controller/TbsCostApplyController.java
  10. 17
      src/main/java/com/qs/serve/modules/tbs/entity/dto/CusTargetRateDTO.java
  11. 19
      src/main/java/com/qs/serve/modules/tbs/entity/dto/TbsCostSubItem.java
  12. 24
      src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java
  13. 14
      src/main/resources/mapper/bir/BirActivityCenterGoodsMapper.xml

18
src/main/java/com/qs/serve/modules/bir/entity/so/BirMonthCusCenterSo.java

@ -0,0 +1,18 @@
package com.qs.serve.modules.bir.entity.so;
import lombok.Data;
/**
* @author YenHex
* @since 2023/9/15
*/
@Data
public class BirMonthCusCenterSo {
String supplierCode;
String centerType;
String centerId;
Integer startYearMonth;
Integer endYearMonth;
}

26
src/main/java/com/qs/serve/modules/bir/entity/vo/BirActivityCenterGoodsMonthVo.java

@ -0,0 +1,26 @@
package com.qs.serve.modules.bir.entity.vo;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author YenHex
* @since 2023/9/15
*/
@Data
public class BirActivityCenterGoodsMonthVo {
/** 年月 */
private Integer keyNum;
/** 费用申请 */
private BigDecimal totalCostAmt;
/** 释放 */
private BigDecimal totalReleaseAmt;
/** 核销 */
private BigDecimal totalUsedAmt;
}

5
src/main/java/com/qs/serve/modules/bir/mapper/BirActivityCenterGoodsMapper.java

@ -2,6 +2,8 @@ package com.qs.serve.modules.bir.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qs.serve.modules.bir.entity.BirActivityCenterGoods;
import com.qs.serve.modules.bir.entity.so.BirMonthCusCenterSo;
import com.qs.serve.modules.bir.entity.vo.BirActivityCenterGoodsMonthVo;
import com.qs.serve.modules.tbs.entity.TbsActivityCenterGoods;
import org.apache.ibatis.annotations.Param;
@ -26,5 +28,8 @@ public interface BirActivityCenterGoodsMapper extends BaseMapper<BirActivityCent
@Param("costApplyId")Long costApplyId);
List<BirActivityCenterGoods> selectNoExistCenterGoods();
List<BirActivityCenterGoodsMonthVo> listMonthCusCenterVo(@Param("query") BirMonthCusCenterSo param);
}

12
src/main/java/com/qs/serve/modules/bir/service/BirActivityCenterGoodsService.java

@ -2,6 +2,11 @@ package com.qs.serve.modules.bir.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.qs.serve.modules.bir.entity.BirActivityCenterGoods;
import com.qs.serve.modules.bir.entity.so.BirMonthCusCenterSo;
import com.qs.serve.modules.bir.entity.vo.BirActivityCenterGoodsMonthVo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 服务接口
@ -17,5 +22,12 @@ public interface BirActivityCenterGoodsService extends IService<BirActivityCente
*/
void buildReport(int year, int month);
/**
* 查询客户维度
* @param param
* @return
*/
List<BirActivityCenterGoodsMonthVo> listMonthCusCenterVo(BirMonthCusCenterSo param);
}

11
src/main/java/com/qs/serve/modules/bir/service/BirCenterRateService.java

@ -5,7 +5,18 @@ import com.qs.serve.modules.tbs.entity.dto.TbsCostSubItem;
import java.util.List;
public interface BirCenterRateService {
TbsCostSubItem.CostCenterTranStr buildCostCenter(String centerType, String centerId, String centerName);
/**
* 拓展方法
* @param centerType
* @param centerId
* @param centerName
* @param supplierCode 如果不为空计算客户的成本中心维度数据
* @return
*/
TbsCostSubItem.CostCenterTranStr buildCostCenter(String centerType, String centerId, String centerName,String supplierCode);
List<TbsCostSubItem.CostCenterTranStr> findCostCenterDataByCostApplyId(Long costApplyId,Long policyId);
}

7
src/main/java/com/qs/serve/modules/bir/service/impl/BirActivityCenterGoodsServiceImpl.java

@ -9,6 +9,8 @@ import com.qs.serve.common.util.PageUtil;
import com.qs.serve.modules.bir.entity.BirBaseActivity;
import com.qs.serve.modules.bir.entity.BirRemoveId;
import com.qs.serve.modules.bir.entity.dto.BirCenterGoodSplitDTO;
import com.qs.serve.modules.bir.entity.so.BirMonthCusCenterSo;
import com.qs.serve.modules.bir.entity.vo.BirActivityCenterGoodsMonthVo;
import com.qs.serve.modules.bir.mapper.BirRemoveIdMapper;
import com.qs.serve.modules.bms.entity.BmsCostCenter;
import com.qs.serve.modules.bms.entity.BmsRegion;
@ -413,5 +415,10 @@ public class BirActivityCenterGoodsServiceImpl extends ServiceImpl<BirActivityCe
return goodSplitDTO;
}
@Override
public List<BirActivityCenterGoodsMonthVo> listMonthCusCenterVo(BirMonthCusCenterSo param) {
return baseMapper.listMonthCusCenterVo(param);
}
}

150
src/main/java/com/qs/serve/modules/bir/service/impl/BirCenterRateServiceImpl.java

@ -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);
}
}

3
src/main/java/com/qs/serve/modules/bms/entity/BmsSupplierAddress.java

@ -79,6 +79,9 @@ public class BmsSupplierAddress implements Serializable {
@Length(max = 30,message = "收件人长度不能超过30字")
private String receiver;
/** 物流系统的id */
private String tmsSysId;
/** 备注 */
@Length(max = 255,message = "备注长度不能超过255字")
private String remark;

9
src/main/java/com/qs/serve/modules/tbs/controller/TbsCostApplyController.java

@ -74,6 +74,7 @@ public class TbsCostApplyController {
private SysPostUserService postUserService;
private TbsCostApplyOperationServiceImpl tbsCostApplyOperationServiceImpl;
private TbsBudgetMatchApplication tbsBudgetMatchApplication;
private TbsBudgetCostItemService tbsBudgetCostItemService;
/**
@ -364,8 +365,12 @@ public class TbsCostApplyController {
if(entity.getCancelFlag().equals(1)||entity.getChangeExtendId()!=null||entity.getChangeSourceId()!=null){
return R.error("异动记录不可删除");
}
if(!entity.getChargeState().equals(0)&&
!entity.getChargeState().equals(TbsCostApplyState.State_5_stop.getCode())){
boolean stateFlag = !entity.getChargeState().equals(0)&&
!entity.getChargeState().equals(TbsCostApplyState.State_5_stop.getCode());
LambdaQueryWrapper<TbsBudgetCostItem> lqwCostItem = new LambdaQueryWrapper<>();
lqwCostItem.eq(TbsBudgetCostItem::getCostApplyId,id);
long countItem = tbsBudgetCostItemService.count(lqwCostItem);
if(stateFlag&&countItem>0){
return R.error("占用预算的申请,不支持删除");
}
//模板类直接删除

17
src/main/java/com/qs/serve/modules/tbs/entity/dto/CusTargetRateDTO.java

@ -0,0 +1,17 @@
package com.qs.serve.modules.tbs.entity.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* @author YenHex
* @since 2023/9/15
*/
@Data
@AllArgsConstructor
public class CusTargetRateDTO {
String cusTargetRateQty;
String cusTargetRate;
}

19
src/main/java/com/qs/serve/modules/tbs/entity/dto/TbsCostSubItem.java

@ -163,6 +163,25 @@ public class TbsCostSubItem {
//实际费用率
private String mtdRealExpenseRate;
// 季度客户所属成本中心费用金额
private String qtdCusCenterCost;
// 季度客户实际发货金额
private String qtdCusCenterSend;
// 季度客户所属成本中心费用率
private String qtdCusCenterExpenseRate;
// 季度客户所属成本中心目标费用率
private String qtdCusCenterTargetExpenseRate;
// 年度客户所属成本中心费用金额
private String ytdCusCenterCost;
// 年度客户实际发货金额
private String ytdCusCenterSend;
// 年度客户所属成本中心费用率
private String ytdCusCenterExpenseRate;
// 年度客户所属成本中心目标费用率
private String ytdCusCenterTargetExpenseRate;
}
}

24
src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java

@ -625,12 +625,12 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC
subList.add(toDoItem);
}
//构造客户维度的 年度、季度合计
try {
List<TbsContractCostSubItem.CusCenterRate> cusCenterRateList = buildCusRateMain(supplier);
subList.addAll(cusCenterRateList);
} catch (Exception e) {
log.error("[构造客户维度的 年度、季度合计]异常:{}",e.getMessage());
}
// try {
// List<TbsContractCostSubItem.CusCenterRate> cusCenterRateList = buildCusRateMain(supplier);
// subList.addAll(cusCenterRateList);
// } catch (Exception e) {
// log.error("[构造客户维度的 年度、季度合计]异常:{}",e.getMessage());
// }
//关联
data.put("sub", subList);
}
@ -913,12 +913,12 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC
log.error("【费用申请,创建子表数据】:{}",e.getMessage());
}
//构造客户维度的 年度、季度合计
try {
List<TbsContractCostSubItem.CusCenterRate> cusCenterRateList = buildCusRateMain(supplier);
subList.addAll(cusCenterRateList);
} catch (Exception e) {
log.error("【费用申请,创建客户维度费率数据】:{}",e.getMessage());
}
// try {
// List<TbsContractCostSubItem.CusCenterRate> cusCenterRateList = buildCusRateMain(supplier);
// subList.addAll(cusCenterRateList);
// } catch (Exception e) {
// log.error("【费用申请,创建客户维度费率数据】:{}",e.getMessage());
// }
//创建商品抬头列表
List<TbsActivityGoods> tbsActivityGoods = tbsActivityGoodsService.listByCostApplyId(Long.parseLong(id));
Set<String> bands = new HashSet<>();

14
src/main/resources/mapper/bir/BirActivityCenterGoodsMapper.xml

@ -153,5 +153,19 @@
and tbs_cost_apply.charge_state not in (2,3)
)
</select>
<select id="listMonthCusCenterVo"
resultType="com.qs.serve.modules.bir.entity.vo.BirActivityCenterGoodsMonthVo">
select
key_num,
sum(split_amount) as total_cost_amt,
sum(split_release_amount) as total_release_amt,
sum(split_used_amount) as total_used_amt,
from bir_activity_center_goods
where supplier_code = ''
and center_type = ''
and center_code = ''
group by key_num
</select>
</mapper>

Loading…
Cancel
Save