优化销售订单优惠金额分摊和推送逻辑
- 完善了优惠金额分摊逻辑,确保分摊后的金额保留两位小数- 在推送销售订单到U8C时,增加了对优惠金额的处理,确保金额为0时不推送 - 优化了代码结构,增加了测试和日志记录功能
This commit is contained in:
parent
7b154fc238
commit
4b3f3c8437
|
@ -261,6 +261,7 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity {
|
|||
queryOfsSoSaleOutVo.setCode(code);
|
||||
ofsStandardUtil.queryOfsSaleOrder(queryOfsSoSaleOutVo, headerDetailsDtoList, 1L, "ofs.shipment.search");
|
||||
logger.info("数据返回行数:{}", headerDetailsDtoList.size());
|
||||
|
||||
if (headerDetailsDtoList.size() > 0) {
|
||||
if (sceneType.equals("stock")) {
|
||||
getSetStock(headerDetailsDtoList);
|
||||
|
@ -837,7 +838,6 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity {
|
|||
// saleorderRequestChildrenDto.setCrecwareid(bdStordocEntity1.getPkStordoc());//收货仓库
|
||||
// saleorderRequestChildrenDto.setVdef2(bdCostsubjEntity.getCostname());//收支项目
|
||||
// saleorderRequestChildrenDto.setPk_defdoc2(bdCostsubjEntity.getPkCostsubj());
|
||||
|
||||
//如果优惠金额为0,则传0
|
||||
if (sonDetailsDto != null && !"0".equals(sonDetailsDto.getVdef4().stripTrailingZeros().toPlainString())) {
|
||||
saleorderRequestChildrenDto.setVdef4(sonDetailsDto.getVdef4().stripTrailingZeros().toPlainString());
|
||||
|
@ -862,6 +862,10 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity {
|
|||
saleorderRequestChildrenDtoList.add(saleorderRequestChildrenDto);
|
||||
|
||||
//销售订单单据推送到u8c
|
||||
//TODO 测试
|
||||
if (true) {
|
||||
continue;
|
||||
}
|
||||
List<SaleorderRequestDto> saleorderRequestDtoList = new ArrayList<>();
|
||||
saleorderRequestDtoList.add(saleorderRequestDto);
|
||||
|
||||
|
@ -1689,6 +1693,27 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity {
|
|||
|
||||
// saleorderRequestChildrenDto.setVdef2(bdCostsubjEntity.getCostname());//收支项目
|
||||
// saleorderRequestChildrenDto.setPk_defdoc2(bdCostsubjEntity.getPkCostsubj());
|
||||
//如果优惠金额为0,则传0
|
||||
if (sonDetailsDto != null && !"0".equals(sonDetailsDto.getVdef4().stripTrailingZeros().toPlainString())) {
|
||||
saleorderRequestChildrenDto.setVdef4("-" + sonDetailsDto.getVdef4().stripTrailingZeros().toPlainString());
|
||||
} else {
|
||||
saleorderRequestChildrenDto.setVdef4("0");
|
||||
}
|
||||
if (sonDetailsDto != null && !"0".equals(sonDetailsDto.getVdef5().stripTrailingZeros().toPlainString())) {
|
||||
saleorderRequestChildrenDto.setVdef5("-" + sonDetailsDto.getVdef5().stripTrailingZeros().toPlainString());
|
||||
} else {
|
||||
saleorderRequestChildrenDto.setVdef5("0");
|
||||
}
|
||||
if (sonDetailsDto != null && !"0".equals(sonDetailsDto.getVdef6().stripTrailingZeros().toPlainString())) {
|
||||
saleorderRequestChildrenDto.setVdef6("-" + sonDetailsDto.getVdef6().stripTrailingZeros().toPlainString());
|
||||
} else {
|
||||
saleorderRequestChildrenDto.setVdef6("0");
|
||||
}
|
||||
if (sonDetailsDto != null && !"0".equals(sonDetailsDto.getVdef7().stripTrailingZeros().toPlainString())) {
|
||||
saleorderRequestChildrenDto.setVdef7("-" + sonDetailsDto.getVdef7().stripTrailingZeros().toPlainString());
|
||||
} else {
|
||||
saleorderRequestChildrenDto.setVdef7("0");
|
||||
}
|
||||
saleorderRequestChildrenDtoList.add(saleorderRequestChildrenDto);
|
||||
|
||||
//销售订单单据推送到u8c
|
||||
|
@ -1816,6 +1841,27 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity {
|
|||
saleorderRequestChildrenDto.setNtaxrate(new BigDecimal(bdTaxitemsEntity1.getTaxratio()).stripTrailingZeros().toPlainString());//税率
|
||||
// saleorderRequestChildrenDto.setCreccalbodyid(bdCalbodyEntity1.getPkCalbody());//收货库存组织:2024年8月7日 16:21:48 和佳妮、道品一起测试,收货库存组织、收货仓库 是不需要传递的
|
||||
// saleorderRequestChildrenDto.setCrecwareid(bdStordocEntity1.getPkStordoc());//收货仓库
|
||||
//如果优惠金额为0,则传0
|
||||
if (sonDetailsDto != null && !"0".equals(sonDetailsDto.getVdef4().stripTrailingZeros().toPlainString())) {
|
||||
saleorderRequestChildrenDto.setVdef4(sonDetailsDto.getVdef4().stripTrailingZeros().toPlainString());
|
||||
} else {
|
||||
saleorderRequestChildrenDto.setVdef4("0");
|
||||
}
|
||||
if (sonDetailsDto != null && !"0".equals(sonDetailsDto.getVdef5().stripTrailingZeros().toPlainString())) {
|
||||
saleorderRequestChildrenDto.setVdef5(sonDetailsDto.getVdef5().stripTrailingZeros().toPlainString());
|
||||
} else {
|
||||
saleorderRequestChildrenDto.setVdef5("0");
|
||||
}
|
||||
if (sonDetailsDto != null && !"0".equals(sonDetailsDto.getVdef6().stripTrailingZeros().toPlainString())) {
|
||||
saleorderRequestChildrenDto.setVdef6(sonDetailsDto.getVdef6().stripTrailingZeros().toPlainString());
|
||||
} else {
|
||||
saleorderRequestChildrenDto.setVdef6("0");
|
||||
}
|
||||
if (sonDetailsDto != null && !"0".equals(sonDetailsDto.getVdef7().stripTrailingZeros().toPlainString())) {
|
||||
saleorderRequestChildrenDto.setVdef7(sonDetailsDto.getVdef7().stripTrailingZeros().toPlainString());
|
||||
} else {
|
||||
saleorderRequestChildrenDto.setVdef7("0");
|
||||
}
|
||||
saleorderRequestChildrenDtoList.add(saleorderRequestChildrenDto);
|
||||
|
||||
//销售订单单据推送到u8c
|
||||
|
@ -2383,6 +2429,7 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity {
|
|||
com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDto header = headerDetailsDto.getHeader();
|
||||
List<com.hzya.frame.ttxofs.dto.ofssalesordersearch.DetailsDto> details = headerDetailsDto.getDetails();
|
||||
|
||||
//四舍五入保留2位
|
||||
com.hzya.frame.ttxofs.dto.ofssalesordersearch.DetailsDto ofsOrderDetail = findOfsOrderDetail(details, sonDetailsDto);
|
||||
if (ofsOrderDetail.getShareTargetPlatformDiscounts() != null) {
|
||||
totalShareTargetPlatformDiscounts = totalShareTargetPlatformDiscounts.add(ofsOrderDetail.getShareTargetPlatformDiscounts());
|
||||
|
@ -2396,12 +2443,18 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity {
|
|||
if (ofsOrderDetail.getShareTargetPayDiscounts() != null) {
|
||||
totalShareTargetPayDiscounts = totalShareTargetPayDiscounts.add(ofsOrderDetail.getShareTargetPayDiscounts());
|
||||
}
|
||||
logger.info("对应的销售订单明细行主键:{}", ofsOrderDetail.getId());
|
||||
}
|
||||
|
||||
sonDetailsDtoList.get(0).setVdef4(totalShareTargetPlatformDiscounts);
|
||||
sonDetailsDtoList.get(0).setVdef5(totalShareTargetMerchantDiscounts);
|
||||
sonDetailsDtoList.get(0).setVdef6(totalShareTargetExpertDiscounts);
|
||||
sonDetailsDtoList.get(0).setVdef7(totalShareTargetPayDiscounts);
|
||||
SonDetailsDto sonDetailsDto = sonDetailsDtoList.get(0);
|
||||
HeaderDto header = sonDetailsDto.getHeader();
|
||||
|
||||
sonDetailsDto.setVdef4(totalShareTargetPlatformDiscounts.setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
sonDetailsDto.setVdef5(totalShareTargetMerchantDiscounts.setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
sonDetailsDto.setVdef6(totalShareTargetExpertDiscounts.setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
sonDetailsDto.setVdef7(totalShareTargetPayDiscounts.setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
|
||||
logger.info("出库单明细主键:{} 出库单号:{} 最终汇总好的平台优惠:{}、支付优惠:{}、达人优惠:{}、商家优惠:{}", sonDetailsDto.getId(), header.getCode(), sonDetailsDto.getVdef4(), sonDetailsDto.getVdef5(), sonDetailsDto.getVdef6(), sonDetailsDto.getVdef7());
|
||||
} else {
|
||||
logger.info("accumulationDiscountAmount方法对应的sonDetailsDtoList.size为零!");
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.hzya.frame.plugin.lets.util;
|
|||
import cn.hutool.core.lang.Assert;
|
||||
import com.hzya.frame.beanutil.BeanUtil;
|
||||
import com.hzya.frame.ttxofs.dto.ofssalesordersearch.DetailsDto;
|
||||
import com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto;
|
||||
import com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDto;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -42,6 +43,9 @@ public class OfsOrderSaleAmountAllocationUtil {
|
|||
logger.error("batchTocSalesAmountAllocation方法抛出异常,批量处理TOC销售金额分摊异常", e);
|
||||
}
|
||||
});
|
||||
logger.info("=记录优惠金额分摊结果开始=");
|
||||
printAmountOfMoneyNum(headerDetailsDtoList);
|
||||
logger.info("=记录优惠金额分摊结果完成=");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,6 +57,13 @@ public class OfsOrderSaleAmountAllocationUtil {
|
|||
public void tocSalesAmountAllocation(com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto headerDetailsDto) throws Exception {
|
||||
logger.info("==TOC销售金额分摊开始==");
|
||||
|
||||
//TODO 测试
|
||||
HeaderDto header1 = headerDetailsDto.getHeader();
|
||||
header1.setPlatformDiscounts("2.3");
|
||||
header1.setMerchantDiscounts("4.9");
|
||||
header1.setExpertDiscounts("1.2");
|
||||
header1.setPayDiscounts("6.7");
|
||||
|
||||
Assert.notNull(headerDetailsDto, "OFS销售订单对象不能为空");
|
||||
HeaderDto header = headerDetailsDto.getHeader();
|
||||
List<DetailsDto> detailsOld = headerDetailsDto.getDetails();
|
||||
|
@ -110,28 +121,28 @@ public class OfsOrderSaleAmountAllocationUtil {
|
|||
BigDecimal shareTargetExpertDiscounts = null;
|
||||
BigDecimal shareTargetPayDiscounts = null;
|
||||
if (sharingRatio != null && targetPlatformDiscounts != null) {
|
||||
shareTargetPlatformDiscounts = targetPlatformDiscounts.multiply(sharingRatio).setScale(8, BigDecimal.ROUND_HALF_UP);
|
||||
shareTargetPlatformDiscounts = targetPlatformDiscounts.multiply(sharingRatio).setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
detailsDto.setOriginalTargetPlatformDiscounts(targetPlatformDiscounts);
|
||||
detailsDto.setShareTargetPlatformDiscounts(shareTargetPlatformDiscounts);
|
||||
|
||||
totalShareTargetPlatformDiscounts = totalShareTargetPlatformDiscounts.add(shareTargetPlatformDiscounts);
|
||||
}
|
||||
if (sharingRatio != null && targetMerchantDiscounts != null) {
|
||||
shareTargetMerchantDiscounts = targetMerchantDiscounts.multiply(sharingRatio).setScale(8, BigDecimal.ROUND_HALF_UP);
|
||||
shareTargetMerchantDiscounts = targetMerchantDiscounts.multiply(sharingRatio).setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
detailsDto.setOriginalTargetMerchantDiscounts(targetMerchantDiscounts);
|
||||
detailsDto.setShareTargetMerchantDiscounts(shareTargetMerchantDiscounts);
|
||||
|
||||
totalShareTargetMerchantDiscounts = totalShareTargetMerchantDiscounts.add(shareTargetMerchantDiscounts);
|
||||
}
|
||||
if (sharingRatio != null && targetExpertDiscounts != null) {
|
||||
shareTargetExpertDiscounts = targetExpertDiscounts.multiply(sharingRatio).setScale(8, BigDecimal.ROUND_HALF_UP);
|
||||
shareTargetExpertDiscounts = targetExpertDiscounts.multiply(sharingRatio).setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
detailsDto.setOriginalTargetExpertDiscounts(targetExpertDiscounts);
|
||||
detailsDto.setShareTargetExpertDiscounts(shareTargetExpertDiscounts);
|
||||
|
||||
totalShareTargetExpertDiscounts = totalShareTargetExpertDiscounts.add(shareTargetExpertDiscounts);
|
||||
}
|
||||
if (sharingRatio != null && targetPayDiscounts != null) {
|
||||
shareTargetPayDiscounts = targetPayDiscounts.multiply(sharingRatio).setScale(8, BigDecimal.ROUND_HALF_UP);
|
||||
shareTargetPayDiscounts = targetPayDiscounts.multiply(sharingRatio).setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
detailsDto.setOriginalTargetPayDiscounts(targetPayDiscounts);
|
||||
detailsDto.setShareTargetPayDiscounts(shareTargetPayDiscounts);
|
||||
|
||||
|
@ -282,4 +293,61 @@ public class OfsOrderSaleAmountAllocationUtil {
|
|||
logger.error("copyDetailsDtoOld方法newDetails或者detailsOld为空!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印金额参数
|
||||
*
|
||||
* @param headerDetailsDtoList OFS销售订单号
|
||||
*/
|
||||
public void printAmountOfMoneyNum(List<HeaderDetailsDto> headerDetailsDtoList) {
|
||||
try {
|
||||
if (headerDetailsDtoList != null && headerDetailsDtoList.size() > 0) {
|
||||
for (int i = 0; i < headerDetailsDtoList.size(); i++) {
|
||||
HeaderDetailsDto headerDetailsDto = headerDetailsDtoList.get(i);
|
||||
HeaderDto header = headerDetailsDto.getHeader();
|
||||
List<DetailsDto> details = headerDetailsDto.getDetails();
|
||||
|
||||
logger.info("OFS销售订单号:{} 平台优惠:{} 商家优惠:{} 达人优惠:{} 支付优惠:{}", header.getCode(), header.getPlatformDiscounts(), header.getMerchantDiscounts(), header.getExpertDiscounts(), header.getPayDiscounts());
|
||||
if (details != null && details.size() > 0) {
|
||||
for (int j = 0; j < details.size(); j++) {
|
||||
DetailsDto detailsDto = details.get(j);
|
||||
|
||||
logger.info("start================================");
|
||||
logger.info("OFS销售订单明细主键:{}", detailsDto.getId());
|
||||
if (detailsDto.getSharingRatio() != null) {
|
||||
logger.info("分摊比例:{}", detailsDto.getSharingRatio().stripTrailingZeros().toPlainString());
|
||||
} else {
|
||||
logger.info("分摊比例:无");
|
||||
}
|
||||
logger.info("商品金额:{}", detailsDto.getItemTotalAmount());
|
||||
if (detailsDto.getShareTargetPlatformDiscounts() != null) {
|
||||
logger.info("分摊平台优惠:{}", detailsDto.getShareTargetPlatformDiscounts().stripTrailingZeros().toPlainString());
|
||||
} else {
|
||||
logger.info("分摊平台优惠:无");
|
||||
}
|
||||
if (detailsDto.getShareTargetMerchantDiscounts() != null) {
|
||||
logger.info("分摊商家优惠:{}", detailsDto.getShareTargetMerchantDiscounts().stripTrailingZeros().toPlainString());
|
||||
} else {
|
||||
logger.info("分摊商家优惠:无");
|
||||
}
|
||||
if (detailsDto.getShareTargetExpertDiscounts() != null) {
|
||||
logger.info("分摊达人优惠:{}", detailsDto.getShareTargetExpertDiscounts().stripTrailingZeros().toPlainString());
|
||||
} else {
|
||||
logger.info("分摊达人优惠:无");
|
||||
}
|
||||
if (detailsDto.getShareTargetPayDiscounts() != null) {
|
||||
logger.info("分摊支付优惠:{}", detailsDto.getShareTargetPayDiscounts().stripTrailingZeros().toPlainString());
|
||||
} else {
|
||||
logger.info("分摊支付优惠:无");
|
||||
}
|
||||
logger.info("end================================");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("printNum方法抛出异常", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -73,57 +73,12 @@ public class OfsOrderSaleAmountAllocationUtilTest {
|
|||
//测试六:优惠金额全部都为0
|
||||
// ofsOrderSaleAmountAllocationUtil.tocSalesAmountAllocation(data.get(0));
|
||||
|
||||
printNum(data);
|
||||
// ofsOrderSaleAmountAllocationUtil.printAmountOfMoneyNum(data);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void printNum(List<HeaderDetailsDto> headerDetailsDtoList) {
|
||||
try {
|
||||
for (int i = 0; i < headerDetailsDtoList.size(); i++) {
|
||||
HeaderDetailsDto headerDetailsDto = headerDetailsDtoList.get(i);
|
||||
HeaderDto header = headerDetailsDto.getHeader();
|
||||
List<DetailsDto> details = headerDetailsDto.getDetails();
|
||||
|
||||
logger.info("OFS销售订单号:{} 平台优惠:{} 商家优惠:{} 达人优惠:{} 支付优惠:{}", header.getCode(), header.getPlatformDiscounts(), header.getMerchantDiscounts(), header.getExpertDiscounts(), header.getPayDiscounts());
|
||||
for (int j = 0; j < details.size(); j++) {
|
||||
DetailsDto detailsDto = details.get(j);
|
||||
|
||||
logger.info("start================================");
|
||||
if (detailsDto.getSharingRatio() != null) {
|
||||
logger.info("分摊比例:{}", detailsDto.getSharingRatio().stripTrailingZeros().toPlainString());
|
||||
} else {
|
||||
logger.info("分摊比例:无");
|
||||
}
|
||||
logger.info("商品金额:{}", detailsDto.getItemTotalAmount());
|
||||
if (detailsDto.getShareTargetPlatformDiscounts() != null) {
|
||||
logger.info("分摊平台优惠:{}", detailsDto.getShareTargetPlatformDiscounts().stripTrailingZeros().toPlainString());
|
||||
} else {
|
||||
logger.info("分摊平台优惠:无");
|
||||
}
|
||||
if (detailsDto.getShareTargetMerchantDiscounts() != null) {
|
||||
logger.info("分摊商家优惠:{}", detailsDto.getShareTargetMerchantDiscounts().stripTrailingZeros().toPlainString());
|
||||
} else {
|
||||
logger.info("分摊商家优惠:无");
|
||||
}
|
||||
if (detailsDto.getShareTargetExpertDiscounts() != null) {
|
||||
logger.info("分摊达人优惠:{}", detailsDto.getShareTargetExpertDiscounts().stripTrailingZeros().toPlainString());
|
||||
} else {
|
||||
logger.info("分摊达人优惠:无");
|
||||
}
|
||||
if (detailsDto.getShareTargetPayDiscounts() != null) {
|
||||
logger.info("分摊支付优惠:{}", detailsDto.getShareTargetPayDiscounts().stripTrailingZeros().toPlainString());
|
||||
} else {
|
||||
logger.info("分摊支付优惠:无");
|
||||
}
|
||||
logger.info("end================================");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("printNum方法抛出异常", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package com.hzya.frame.ttxofs.dto.ofssalesordersearch;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -8,24 +10,8 @@ import java.util.List;
|
|||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
@Data
|
||||
public class HeaderDetailsDto {
|
||||
|
||||
private HeaderDto header;
|
||||
private List<DetailsDto> details;
|
||||
|
||||
public void setHeader(HeaderDto header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
public HeaderDto getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
public void setDetails(List<DetailsDto> details) {
|
||||
this.details = details;
|
||||
}
|
||||
|
||||
public List<DetailsDto> getDetails() {
|
||||
return details;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue