From 942897faa6b558e65343db3075d7bbe3c2cb411a Mon Sep 17 00:00:00 2001 From: liuy <37787198+LiuyCodes@users.noreply.github.com> Date: Wed, 20 Nov 2024 17:03:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(plugin):=20=E6=96=B0=E5=A2=9E=20TOC?= =?UTF-8?q?=E9=80=80=E8=B4=A7=E8=AE=A1=E7=AE=97=E5=85=AC=E5=BC=8F=E5=8F=8A?= =?UTF-8?q?=E4=BC=98=E6=83=A0=E9=87=91=E9=A2=9D=E4=BF=9D=E5=AD=98=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 TocofsReturngoodsDetailedEntity 中添加计算应收、计算公式等字段 - 修改批量插入或更新 SQL,支持新字段- 优化销售出库插件初始化器,增加计算公式和优惠金额保存逻辑 - 更新测试用例,验证新功能 --- .../TocofsReturngoodsDetailedEntity.xml | 24 ++++-- .../sales/SoSaleOutPluginInitializerToC.java | 2 +- .../SoSaleReturnPluginInitializerToC.java | 74 ++++++++++++++----- .../lets/u8cdto/GoodsRertunSonDetailsDto.java | 14 ++++ .../SoSaleOutPluginInitializerToBTest.java | 4 +- 5 files changed, 91 insertions(+), 27 deletions(-) diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsReturngoodsDetailedEntity.xml b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsReturngoodsDetailedEntity.xml index 404a5b36..d19c124c 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsReturngoodsDetailedEntity.xml +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsReturngoodsDetailedEntity.xml @@ -879,10 +879,10 @@ - insert into tocofs_returngoods_detailed(id,newPushDate3,newTransmitInfo3,newState3,newSystemNumber3,newSystemPrimary3) + insert into tocofs_returngoods_detailed(id,newPushDate3,newTransmitInfo3,newState3,newSystemNumber3,newSystemPrimary3,def7,def8,def9,def10,def11,def12) values - (#{entity.id},#{entity.newpushdate3},#{entity.newtransmitinfo3},#{entity.newstate3},#{entity.newsystemnumber3},#{entity.newsystemprimary3}) + (#{entity.id},#{entity.newpushdate3},#{entity.newtransmitinfo3},#{entity.newstate3},#{entity.newsystemnumber3},#{entity.newsystemprimary3},#{entity.def7},#{entity.def8},#{entity.def9},#{entity.def10},#{entity.def11},#{entity.def12}) on duplicate key update id = values(id), @@ -890,15 +890,21 @@ newTransmitInfo3 = values(newTransmitInfo3), newState3 = values(newState3), newSystemNumber3 = values(newSystemNumber3), - newSystemPrimary3 = values(newSystemPrimary3) + newSystemPrimary3 = values(newSystemPrimary3), + def7 = values(def7), + def8 = values(def8), + def9 = values(def9), + def10 = values(def10), + def11 = values(def11), + def12 = values(def12) - insert into tocofs_returngoods_detailed(id,newPushDate4,newTransmitInfo4,newState4,newSystemNumber4,newSystemPrimary4) + insert into tocofs_returngoods_detailed(id,newPushDate4,newTransmitInfo4,newState4,newSystemNumber4,newSystemPrimary4,def7,def8,def9,def10,def11,def12) values - (#{entity.id},#{entity.newpushdate4},#{entity.newtransmitinfo4},#{entity.newstate4},#{entity.newsystemnumber4},#{entity.newsystemprimary4}) + (#{entity.id},#{entity.newpushdate4},#{entity.newtransmitinfo4},#{entity.newstate4},#{entity.newsystemnumber4},#{entity.newsystemprimary4},#{entity.def7},#{entity.def8},#{entity.def9},#{entity.def10},#{entity.def11},#{entity.def12}) on duplicate key update id = values(id), @@ -906,7 +912,13 @@ newTransmitInfo4 = values(newTransmitInfo4), newState4 = values(newState4), newSystemNumber4 = values(newSystemNumber4), - newSystemPrimary4 = values(newSystemPrimary4) + newSystemPrimary4 = values(newSystemPrimary4), + def7 = values(def7), + def8 = values(def8), + def9 = values(def9), + def10 = values(def10), + def11 = values(def11), + def12 = values(def12) diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToC.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToC.java index 730c4717..0f800cd6 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToC.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToC.java @@ -3165,7 +3165,7 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity { if (poOrderBEntity != null) { String norgtaxprice = poOrderBEntity.getNorgtaxprice(); Assert.notNull(norgtaxprice, "U8C采购订单明细行存在「原币含税单价」为空"); - if (!"0".equals(new BigDecimal(norgtaxprice).stripTrailingZeros().toPlainString())) { + if (norgtaxprice != null && !"0".equals(new BigDecimal(norgtaxprice).stripTrailingZeros().toPlainString())) { String format = StrUtil.format("{}*{}", norgtaxprice, sonDetailsDto.getShipQty()); calculationFormulaStr.append(format); BigDecimal totalPayAmountBigDecimal = new BigDecimal(norgtaxprice).multiply(new BigDecimal(sonDetailsDto.getShipQty())).setScale(2, BigDecimal.ROUND_HALF_UP); diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToC.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToC.java index 7f662cc5..8bc10a31 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToC.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToC.java @@ -133,10 +133,9 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { if (ProfilesActiveConstant.LETS_PROFILES_ACTIVE.equals(PROD_FILED)) { //默认被定时器执行,每天晚上凌晨0点5分 //暂定先同步TOC销售库存、再推送TOC销售确认收入 - //TODO 暂时注释掉 -// List startAndEndVos = calculateCalculateEntireDayPeriod(null); -// startImplementStockByTime(startAndEndVos.get(0).getStart_time(), startAndEndVos.get(0).getEnd_time()); -// startImplementByTradeTime(startAndEndVos.get(0).getStart_time(), startAndEndVos.get(0).getEnd_time()); + List startAndEndVos = calculateCalculateEntireDayPeriod(null); + startImplementStockByTime(startAndEndVos.get(0).getStart_time(), startAndEndVos.get(0).getEnd_time()); + startImplementByTradeTime(startAndEndVos.get(0).getStart_time(), startAndEndVos.get(0).getEnd_time()); } } } catch (Exception e) { @@ -1500,30 +1499,43 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { BigDecimal groupShipQty = new BigDecimal("0"); for (int i = 0; i < sonDetailsDtoList.size(); i++) { - GoodsRertunSonDetailsDto goodsRertunSonDetailsDto = sonDetailsDtoList.get(i); + GoodsRertunSonDetailsDto goodsRertunSonDetailsDto = sonDetailsDtoList.get(i);//O售后入库单明细行 StockinOrderSearchResponse.StockinOrder.StockinH header = goodsRertunSonDetailsDto.getHeader();//O售后入库单表头 + RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = header.getRerturnGoodsOrderSearchData();//OFS售后订单 + RerturnGoodsOrderSearchHeader header1 = rerturnGoodsOrderSearchData.getHeader();//OFS售后订单表头对象 + List details = rerturnGoodsOrderSearchData.getDetails();//OFS售后订单表体对象 //存货管理档案 BdInvmandocEntity bdInvmandocEntity = goodsRertunSonDetailsDto.getBdInvmandocEntity(); + //根据OFS售后入库单明细行,查找匹配OFS售后订单明细行 + RerturnGoodsOrderSearchDetails ofsOrderDetail = findOfsOrderDetail(details, goodsRertunSonDetailsDto); //取对应的售后订单明细,主要是取这个价格 - String totalAmount = getFloorPrice(isCheckShopChoose, bdInvmandocEntity, header, goodsRertunSonDetailsDto, mapList); + StringBuffer calculationFormulaStr = new StringBuffer(); + String totalAmount = getFloorPrice(isCheckShopChoose, bdInvmandocEntity, header, goodsRertunSonDetailsDto, mapList, calculationFormulaStr); if (totalAmount == null) { + calculationFormulaStr.append("取O实退金额:"); //取O实退金额 // RerturnGoodsOrderSearchDetails afterSalesOrder = findAfterSalesOrderV2(goodsRertunSonDetailsDto, rerturnGoodsOrderSearchData); // totalAmount = afterSalesOrder.getTotalAmount(); - totalAmount = accumulatedDiscounts(goodsRertunSonDetailsDto, rerturnGoodsOrderSearchData); + totalAmount = accumulatedDiscounts(goodsRertunSonDetailsDto, rerturnGoodsOrderSearchData, calculationFormulaStr); } - - //实付金额/实发数量 Assert.notNull(totalAmount, "实退金额不能为空 明细行主键:{}", goodsRertunSonDetailsDto.getId()); Assert.notNull(goodsRertunSonDetailsDto.getReceivedQty(), "实收数量不能为空 明细行主键:{}", goodsRertunSonDetailsDto.getId()); + BigDecimal totalPayAmountBigDecimal = new BigDecimal(totalAmount); BigDecimal shipQtyBigDecimal = new BigDecimal(goodsRertunSonDetailsDto.getReceivedQty()); groupTotalPayAmount = groupTotalPayAmount.add(totalPayAmountBigDecimal); groupShipQty = groupShipQty.add(shipQtyBigDecimal); + + goodsRertunSonDetailsDto.setCalculateAccountsReceivable(totalAmount); + goodsRertunSonDetailsDto.setCalculationFormula(calculationFormulaStr.toString()); + goodsRertunSonDetailsDto.setPlatformDiscounts(ofsOrderDetail.getPlatformDiscounts()); + goodsRertunSonDetailsDto.setMerchantDiscounts(ofsOrderDetail.getMerchantDiscounts()); + goodsRertunSonDetailsDto.setExpertDiscounts(ofsOrderDetail.getExpertDiscounts()); + goodsRertunSonDetailsDto.setPayDiscounts(ofsOrderDetail.getPayDiscounts()); } GoodsRertunSonDetailsDto goodsRertunSonDetailsDto = sonDetailsDtoList.get(0); goodsRertunSonDetailsDto.setGroupShipQty(groupShipQty); @@ -2064,6 +2076,12 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { tocofsReturngoodsDetailedEntity.setNewpushdate3(getNewDateStr()); tocofsReturngoodsDetailedEntity.setNewtransmitinfo3(finalNewTransmitInfo); tocofsReturngoodsDetailedEntity.setNewstate3(newstate); + tocofsReturngoodsDetailedEntity.setDef7(goodsRertunSonDetailsDto.getCalculateAccountsReceivable()); + tocofsReturngoodsDetailedEntity.setDef8(goodsRertunSonDetailsDto.getCalculationFormula()); + tocofsReturngoodsDetailedEntity.setDef9(goodsRertunSonDetailsDto.getPlatformDiscounts()); + tocofsReturngoodsDetailedEntity.setDef10(goodsRertunSonDetailsDto.getPayDiscounts()); + tocofsReturngoodsDetailedEntity.setDef11(goodsRertunSonDetailsDto.getExpertDiscounts()); + tocofsReturngoodsDetailedEntity.setDef12(goodsRertunSonDetailsDto.getMerchantDiscounts()); if (successY.equals(newstate)) { tocofsReturngoodsDetailedEntity.setNewsystemnumber3(newsystemnumber); tocofsReturngoodsDetailedEntity.setNewsystemprimary3(newsystemprimary); @@ -2119,6 +2137,12 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { tocofsReturngoodsDetailedEntity.setNewpushdate4(getNewDateStr()); tocofsReturngoodsDetailedEntity.setNewtransmitinfo4(finalNewTransmitInfo); tocofsReturngoodsDetailedEntity.setNewstate4(newstate); + tocofsReturngoodsDetailedEntity.setDef7(goodsRertunSonDetailsDto.getCalculateAccountsReceivable()); + tocofsReturngoodsDetailedEntity.setDef8(goodsRertunSonDetailsDto.getCalculationFormula()); + tocofsReturngoodsDetailedEntity.setDef9(goodsRertunSonDetailsDto.getPlatformDiscounts()); + tocofsReturngoodsDetailedEntity.setDef10(goodsRertunSonDetailsDto.getPayDiscounts()); + tocofsReturngoodsDetailedEntity.setDef11(goodsRertunSonDetailsDto.getExpertDiscounts()); + tocofsReturngoodsDetailedEntity.setDef12(goodsRertunSonDetailsDto.getMerchantDiscounts()); if (successY.equals(newstate)) { tocofsReturngoodsDetailedEntity.setNewsystemnumber4(newsystemnumber); tocofsReturngoodsDetailedEntity.setNewsystemprimary4(newsystemprimary); @@ -2128,7 +2152,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { //以50行为一个批次,推送到Mysql if (tocofsReturngoodsDetailedEntityArrayList.size() > 0) { - List> splitListByCount = SplitListByCountUtil.splitListByCount(tocofsReturngoodsDetailedEntityArrayList, 50); + List> splitListByCount = SplitListByCountUtil.splitListByCount(tocofsReturngoodsDetailedEntityArrayList, 200); for (int i = 0; i < splitListByCount.size(); i++) { List tocofsReturngoodsDetailedEntities = splitListByCount.get(i); iTocofsReturngoodsDetailedDao.entityInsertOrUpdateBatchByTocRerturnTran(tocofsReturngoodsDetailedEntities); @@ -2519,13 +2543,15 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { * @param mapList 索引为0结存价为1采购价 * @author liuyang */ - private String getFloorPrice(Boolean isCheckShopChoose, BdInvmandocEntity bdInvmandocEntity, StockinOrderSearchResponse.StockinOrder.StockinH header, GoodsRertunSonDetailsDto sonDetailsDto, List mapList) throws Exception { + private String getFloorPrice(Boolean isCheckShopChoose, BdInvmandocEntity bdInvmandocEntity, StockinOrderSearchResponse.StockinOrder.StockinH header, GoodsRertunSonDetailsDto sonDetailsDto, List mapList, StringBuffer calculationFormulaStr) throws Exception { Assert.notNull(isCheckShopChoose, "isCheckShopChoose不能为空"); Assert.notNull(bdInvmandocEntity, "bdInvmandocEntity不能为空"); Assert.notNull(header, "header不能为空"); Assert.notNull(sonDetailsDto, "detailsDto不能为空"); Assert.notNull(mapList, "mapList不能为空"); + Assert.notNull(calculationFormulaStr, "calculationFormulaStr不能为空"); + //此处只能为金额 String totalPayAmount = null; if (isCheckShopChoose) { IaPeriodaccountEntity iaPeriodaccountEntity1 = null; @@ -2536,6 +2562,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { if (iaPeriodaccountEntity1 != null) { //取结存价 logger.info("店铺:{} 取O结存价", header.getStoreCode()); + calculationFormulaStr.append("取结存价:"); //结存金额 String nabmny = iaPeriodaccountEntity1.getNabmny(); @@ -2552,16 +2579,20 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { BigDecimal nabnumBigDecimal = new BigDecimal(nabnum); if (!"0".equals(nabmnyBigDecimal.stripTrailingZeros().toPlainString()) && !"0".equals(nabnumBigDecimal.stripTrailingZeros().toPlainString())) { - //得到结存单价 - BigDecimal bigDecimal = nabmnyBigDecimal.divide(nabnumBigDecimal, 20, BigDecimal.ROUND_HALF_UP).setScale(4, BigDecimal.ROUND_HALF_UP); - totalPayAmount = bigDecimal.stripTrailingZeros().toPlainString(); + String format = StrUtil.format("{}/{}*{}", nabmnyBigDecimal.stripTrailingZeros().toPlainString(), nabnumBigDecimal.stripTrailingZeros().toPlainString(), sonDetailsDto.getReceivedQty()); + calculationFormulaStr.append(format); + BigDecimal bigDecimal = nabmnyBigDecimal.divide(nabnumBigDecimal, 20, BigDecimal.ROUND_HALF_UP); + BigDecimal totalPayAmountBigDecimal = bigDecimal.multiply(new BigDecimal(sonDetailsDto.getReceivedQty())).setScale(2, BigDecimal.ROUND_HALF_UP); + totalPayAmount = totalPayAmountBigDecimal.stripTrailingZeros().toPlainString(); } else { //如果结存金额为或者数量为0,则设置为0 + calculationFormulaStr.append("0"); totalPayAmount = "0"; } } else { //取采购价 logger.info("店铺:{} 取O采购价", header.getStoreCode()); + calculationFormulaStr.append("取采购价:"); PoOrderBEntity poOrderBEntity = null; if (mapList != null && mapList.size() > 0) { Map poOrderBEntityList = (Map) mapList.get(1); @@ -2571,11 +2602,16 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { } if (poOrderBEntity != null) { String norgtaxprice = poOrderBEntity.getNorgtaxprice(); - if ("0".equals(new BigDecimal(norgtaxprice).stripTrailingZeros().toPlainString())) { + Assert.notNull(norgtaxprice, "U8C采购订单明细行存在「原币含税单价」为空"); + if (norgtaxprice != null && !"0".equals(new BigDecimal(norgtaxprice).stripTrailingZeros().toPlainString())) { + String format = StrUtil.format("{}*{}", norgtaxprice, sonDetailsDto.getReceivedQty()); + calculationFormulaStr.append(format); + BigDecimal totalPayAmountBigDecimal = new BigDecimal(norgtaxprice).multiply(new BigDecimal(sonDetailsDto.getReceivedQty())).setScale(2, BigDecimal.ROUND_HALF_UP); + totalPayAmount = totalPayAmountBigDecimal.stripTrailingZeros().toPlainString(); + } else { //如果采购单价都为0,那么金额也为0 totalPayAmount = "0"; - } else { - totalPayAmount = norgtaxprice; + calculationFormulaStr.append("0"); } } else { Assert.state(false, "店铺:{} 存货管理档案主键:{} 既没有结存价、也没有采购价!", header.getStoreCode(), bdInvmandocEntity.getPkInvmandoc()); @@ -2590,11 +2626,13 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { * * @param goodsRertunSonDetailsDto OFS售后入库单明细行 * @param rerturnGoodsOrderSearchData OFS售后订单 + * @param calculationFormulaStr 计算公式 * @author liuyang */ - private String accumulatedDiscounts(GoodsRertunSonDetailsDto goodsRertunSonDetailsDto, RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData) throws Exception { + private String accumulatedDiscounts(GoodsRertunSonDetailsDto goodsRertunSonDetailsDto, RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData, StringBuffer calculationFormulaStr) throws Exception { Assert.notNull(goodsRertunSonDetailsDto, "goodsRertunSonDetailsDto OFS售后入库单明细行不能为空!"); Assert.notNull(rerturnGoodsOrderSearchData, "rerturnGoodsOrderSearchData OFS售后订单不能为空!"); + Assert.notNull(calculationFormulaStr, "calculationFormulaStr不能为空!"); //O售后入库单表头 StockinOrderSearchResponse.StockinOrder.StockinH header1 = goodsRertunSonDetailsDto.getHeader(); diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/u8cdto/GoodsRertunSonDetailsDto.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/u8cdto/GoodsRertunSonDetailsDto.java index 3d048c8a..2e2ed977 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/u8cdto/GoodsRertunSonDetailsDto.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/u8cdto/GoodsRertunSonDetailsDto.java @@ -131,4 +131,18 @@ public class GoodsRertunSonDetailsDto extends StockinOrderSearchResponse.Stockin //累加商家优惠 private BigDecimal vdef7; + + //把销售订单明细行对应的优惠金额保存到销售出库单明细行一份,便于存储到中台的底表 + //计算应收 + private String calculateAccountsReceivable; + //计算公式 + private String calculationFormula; + //平台优惠 + private String platformDiscounts; + //商家优惠 + private String merchantDiscounts; + //达人优惠 + private String expertDiscounts; + //支付优惠 + private String payDiscounts; } \ No newline at end of file diff --git a/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToBTest.java b/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToBTest.java index b9f108d7..ddf1a76f 100644 --- a/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToBTest.java +++ b/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToBTest.java @@ -83,8 +83,8 @@ public class SoSaleOutPluginInitializerToBTest { // soSaleOutPluginInitializerToB.startImplementByStockTime("2024-10-23 16:09:59", "2024-10-23 16:10:01"); - String aaa = "LETS-SH2024102100023018"; - soSaleOutPluginInitializerToB.startImplementByCode(aaa, "tran"); + String aaa = "LETS-SH2024111900014827"; + soSaleOutPluginInitializerToB.startImplementByCode(aaa, "stock"); // soSaleOutPluginInitializerToB.startImplementByTranTime("2024-10-28 00:00:00", "2024-10-28 23:59:59"); // soSaleOutPluginInitializerToB.startImplementByStockTime("2024-10-31 14:48:41", "2024-10-31 14:48:41");