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 0f08fcbe..7eadd97b 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 @@ -97,12 +97,14 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { @Override public String getPluginName() { - return "OFS售后入库单(TOC)生成U8C红字销售订单"; +// return "OFS售后入库单(TOC)生成U8C红字销售订单"; + return "OFS售后入库单(TOC)生成U8C红字销售订单或应收单"; } - + @Override public String getPluginLabel() { - return "OFS售后入库单(TOC)生成U8C红字销售订单"; +// return "OFS售后入库单(TOC)生成U8C红字销售订单"; + return "OFS售后入库单(TOC)生成U8C红字销售订单或应收单"; } @Override @@ -316,9 +318,10 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { if (ProfilesActiveConstant.FILTER_COMPANY.contains(header.getCompanyCode().trim())) { return true; } - if (sceneType.equals("tran") && (header.getClosedAt() == null || "".equals(header.getClosedAt().trim()))) { - return true; - } + //2025 年 3 月 20 日 18:25:25 改为生成红字应收单,不过滤先退款后退款的场景 +// if (sceneType.equals("tran") && (header.getClosedAt() == null || "".equals(header.getClosedAt().trim()))) { +// return true; +// } } return false; } @@ -797,7 +800,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { Boolean isCheckShopChoose = balanceUnitPriceUtil.checkOfsShop(header.getStoreCode()); //把汇总好的出库单明细行合并成一行 - GoodsRertunSonDetailsDto goodsRertunSonDetailsDto = groupMergeDetailedRows(oldValue, isCheckShopChoose); + GoodsRertunSonDetailsDto goodsRertunSonDetailsDto = groupMergeDetailedRows(oldValue, isCheckShopChoose, sceneType); //存货管理档案:取发货公司的存货管理档案 BdInvmandocEntity bdInvmandocEntity = oldValue.get(0).getBdInvmandocEntity(); //存货基础档案 @@ -1036,51 +1039,71 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { String generateBusinessDate = createSuccessFulTradeDate(header); SaleorderRequestDto saleorderRequestDto = new SaleorderRequestDto(); - SaleorderRequestParentDto saleorderRequestParentDto = new SaleorderRequestParentDto(); - saleorderRequestParentDto.setDbilldate(generateBusinessDate);//单据日期 - saleorderRequestParentDto.setBretinvflag("Y");//退货标记 - saleorderRequestParentDto.setCbiztype(bdBusitypeEntity.getPkBusitype());//业务流程 - saleorderRequestParentDto.setCcalbodyid(bdCalbodyEntity.getPkCalbody());//库存组织 - saleorderRequestParentDto.setCcustomerid(bdCumandocEntity.getPkCumandoc());//客户=开票单位=收货单位=表体收货单位=收货单位 - saleorderRequestParentDto.setCdeptid(bdDeptdocEntity.getPkDeptdoc());//部门 - saleorderRequestParentDto.setCemployeeid(null);//业务员 - saleorderRequestParentDto.setCoperatorid(OverallConstant.getOverAllValue("u8cApiZdrPK"));//制单人 - saleorderRequestParentDto.setCreceiptcorpid(bdCumandocEntity.getPkCumandoc());//开票单位 - saleorderRequestParentDto.setCreceiptcustomerid(bdCumandocEntity.getPkCumandoc());//收货单位 - saleorderRequestParentDto.setCsalecorpid(bdSalestruEntity.getCsalestruid());//销售组织 - saleorderRequestParentDto.setCwarehouseid(bdStordocEntity.getPkStordoc());//仓库 - saleorderRequestParentDto.setDapprovedate(generateBusinessDate);//审核日期 - saleorderRequestParentDto.setNdiscountrate("100.000000");//整单折扣 - saleorderRequestParentDto.setPk_corp(bdCorpEntity.getPkCorp());//公司id - //汇总单号=汇总维度 - saleorderRequestParentDto.setVdef18(keyGroup); - //平台 - saleorderRequestParentDto.setPk_defdoc2(platformArchives.getPkDefdoc()); - saleorderRequestParentDto.setVdef2(platformArchives.getDocname()); - saleorderRequestParentDto.setVdef17(ProfilesActiveConstant.sourceSystem1);//来源系统 +// SaleorderRequestParentDto saleorderRequestParentDto = new SaleorderRequestParentDto(); +// saleorderRequestParentDto.setDbilldate(generateBusinessDate);//单据日期 +// saleorderRequestParentDto.setBretinvflag("Y");//退货标记 +// saleorderRequestParentDto.setCbiztype(bdBusitypeEntity.getPkBusitype());//业务流程 +// saleorderRequestParentDto.setCcalbodyid(bdCalbodyEntity.getPkCalbody());//库存组织 +// saleorderRequestParentDto.setCcustomerid(bdCumandocEntity.getPkCumandoc());//客户=开票单位=收货单位=表体收货单位=收货单位 +// saleorderRequestParentDto.setCdeptid(bdDeptdocEntity.getPkDeptdoc());//部门 +// saleorderRequestParentDto.setCemployeeid(null);//业务员 +// saleorderRequestParentDto.setCoperatorid(OverallConstant.getOverAllValue("u8cApiZdrPK"));//制单人 +// saleorderRequestParentDto.setCreceiptcorpid(bdCumandocEntity.getPkCumandoc());//开票单位 +// saleorderRequestParentDto.setCreceiptcustomerid(bdCumandocEntity.getPkCumandoc());//收货单位 +// saleorderRequestParentDto.setCsalecorpid(bdSalestruEntity.getCsalestruid());//销售组织 +// saleorderRequestParentDto.setCwarehouseid(bdStordocEntity.getPkStordoc());//仓库 +// saleorderRequestParentDto.setDapprovedate(generateBusinessDate);//审核日期 +// saleorderRequestParentDto.setNdiscountrate("100.000000");//整单折扣 +// saleorderRequestParentDto.setPk_corp(bdCorpEntity.getPkCorp());//公司id +// //汇总单号=汇总维度 +// saleorderRequestParentDto.setVdef18(keyGroup); +// //平台 +// saleorderRequestParentDto.setPk_defdoc2(platformArchives.getPkDefdoc()); +// saleorderRequestParentDto.setVdef2(platformArchives.getDocname()); +// saleorderRequestParentDto.setVdef17(ProfilesActiveConstant.sourceSystem1);//来源系统 +// +// //收发类别 +// saleorderRequestParentDto.setPk_defdoc3(bdRdclEntity.getPkRdcl()); +// saleorderRequestParentDto.setVdef3(bdRdclEntity.getRdname()); +// +// //2024年8月8日 17:17:58 店铺档案自定义项1,先不传,后续维护好之后再传! +// //店铺 +// saleorderRequestParentDto.setPk_defdoc1(shopArchives.getPkDefdoc()); +// saleorderRequestParentDto.setVdef1(shopArchives.getDocname()); +// +// //单据红字标识 +// saleorderRequestParentDto.setPk_defdoc16(OverallConstant.getOverAllValue("u8c自定义项档案-单据红字标识-Y主键")); +// saleorderRequestParentDto.setVdef16(OverallConstant.getOverAllValue("u8c自定义项档案-单据红字标识-Y名称")); +// +// saleorderRequestDto.setParentvo(saleorderRequestParentDto); + //改为红字应收单表头 + //组装应收单表头 + ArapDjzbVO.Parentt parentVo = new ArapDjzbVO.Parentt(); + parentVo.setDjrq(generateBusinessDate);//单据日期 + parentVo.setDwbm(bdCorpEntity.getUnitcode());//公司 + parentVo.setLrr(OverallConstant.getOverAllValue("u8cApiZdrCode"));//录入人 + parentVo.setWldx("0");//往来对象标识 固定为:客户 + parentVo.setDeptid(bdDeptdocEntity.getDeptcode());//部门 + parentVo.setShr(OverallConstant.getOverAllValue("u8cApiZdrCode"));//审批人 + parentVo.setShrq(generateBusinessDate);//审核日期 + parentVo.setDjlxbm("D0");//单据类型编码 + parentVo.setXslxbm(bdBusitypeEntity.getBusicode());//业务流程 + parentVo.setFeinvstatus("0");//开票状态 + parentVo.setHbbm(bdCubasdocEntity.getCustcode());//客商主键 + parentVo.setZyx1(shopArchives.getDoccode());//店铺档案 + parentVo.setZyx2(platformArchives.getDoccode());//来源平台 + parentVo.setZyx3(bdRdclEntity.getRdcode());//收发类别 + parentVo.setZyx16("1");//单据红字标识 + parentVo.setZyx17(ProfilesActiveConstant.sourceSystem1);//来源系统 + parentVo.setZyx18(keyGroup);//汇总维度 - //收发类别 - saleorderRequestParentDto.setPk_defdoc3(bdRdclEntity.getPkRdcl()); - saleorderRequestParentDto.setVdef3(bdRdclEntity.getRdname()); - - //2024年8月8日 17:17:58 店铺档案自定义项1,先不传,后续维护好之后再传! - //店铺 - saleorderRequestParentDto.setPk_defdoc1(shopArchives.getPkDefdoc()); - saleorderRequestParentDto.setVdef1(shopArchives.getDocname()); - - //单据红字标识 - saleorderRequestParentDto.setPk_defdoc16(OverallConstant.getOverAllValue("u8c自定义项档案-单据红字标识-Y主键")); - saleorderRequestParentDto.setVdef16(OverallConstant.getOverAllValue("u8c自定义项档案-单据红字标识-Y名称")); - - saleorderRequestDto.setParentvo(saleorderRequestParentDto); - - List saleorderRequestChildrenDtoList = new ArrayList<>(); - saleorderRequestDto.setChildrenvo(saleorderRequestChildrenDtoList); +// List saleorderRequestChildrenDtoList = new ArrayList<>(); +// saleorderRequestDto.setChildrenvo(saleorderRequestChildrenDtoList); //验证是否为指定的店铺,如果为true,则取结存价 Boolean isCheckShopChoose = balanceUnitPriceUtil.checkOfsShop(header.getStoreCode()); //把汇总好的出库单明细行合并成一行 - GoodsRertunSonDetailsDto goodsRertunSonDetailsDto = groupMergeDetailedRows(oldValue, isCheckShopChoose); + GoodsRertunSonDetailsDto goodsRertunSonDetailsDto = groupMergeDetailedRows(oldValue, isCheckShopChoose, sceneType); //存货管理档案:取发货公司的存货管理档案 BdInvmandocEntity bdInvmandocEntity = oldValue.get(0).getBdInvmandocEntity(); @@ -1111,58 +1134,70 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { // } //判断是否为赠品 - Boolean isblargessflag = false; - if ("0".equals(goodsRertunSonDetailsDto.getGroupTotalPayAmount().setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString())) { - isblargessflag = true; - } +// Boolean isblargessflag = false; +// if ("0".equals(goodsRertunSonDetailsDto.getGroupTotalPayAmount().setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString())) { +// isblargessflag = true; +// } - SaleorderRequestChildrenDto saleorderRequestChildrenDto = new SaleorderRequestChildrenDto(); - saleorderRequestChildrenDto.setBlargessflag(isblargessflag);//是否赠品 - saleorderRequestChildrenDto.setCadvisecalbodyid(bdCalbodyEntity.getPkCalbody());//发货库存组织 - saleorderRequestChildrenDto.setCbodywarehouseid(bdStordocEntity.getPkStordoc());//发货仓库 - saleorderRequestChildrenDto.setCconsigncorpid(deliverGoodsCorp.getPkCorp());//发货公司 - saleorderRequestChildrenDto.setCcurrencytypeid("00010000000000000001");//币种 - saleorderRequestChildrenDto.setCinventoryid(bdInvmandocEntity.getPkInvmandoc());//存货id - saleorderRequestChildrenDto.setCreceiptcorpid(bdCumandocEntity.getPkCumandoc());//收货单位 - saleorderRequestChildrenDto.setDconsigndate(generateBusinessDate);//计划发货日期 - saleorderRequestChildrenDto.setDdeliverdate(generateBusinessDate);// 要求收货日期 - saleorderRequestChildrenDto.setNexchangeotobrate("1.00000000");//折本汇率 - saleorderRequestChildrenDto.setNitemdiscountrate("100.000000");//单品折扣 - saleorderRequestChildrenDto.setNnumber("-" + goodsRertunSonDetailsDto.getGroupShipQty().stripTrailingZeros().toPlainString());//数量 - saleorderRequestChildrenDto.setNoriginalcurdiscountmny("0");//折扣额 -// saleorderRequestChildrenDto.setNoriginalcurmny("-" + noriginalcurmny.stripTrailingZeros().toPlainString());//无税金额 -// saleorderRequestChildrenDto.setNoriginalcurnetprice(noriginalcurprice.stripTrailingZeros().toPlainString());//无税净价 -// saleorderRequestChildrenDto.setNoriginalcurprice(noriginalcurprice.stripTrailingZeros().toPlainString());//无税单价 -// saleorderRequestChildrenDto.setNoriginalcursummny("-" + noriginalcursummny.stripTrailingZeros().toPlainString());//价税合计 - saleorderRequestChildrenDto.setNoriginalcursummny("-" + goodsRertunSonDetailsDto.getGroupTotalPayAmount().setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString());//价税合计 新逻辑 -// saleorderRequestChildrenDto.setNoriginalcurtaxmny("-" + noriginalcurtaxmny.stripTrailingZeros().toPlainString());//税额 -// saleorderRequestChildrenDto.setNoriginalcurtaxnetprice(noriginalcurtaxprice.stripTrailingZeros().toPlainString());//含税净价 -// saleorderRequestChildrenDto.setNoriginalcurtaxprice(noriginalcurtaxprice.stripTrailingZeros().toPlainString());//含税单价 -// saleorderRequestChildrenDto.setNtaxrate(new BigDecimal(bdTaxitemsEntity1.getTaxratio()).stripTrailingZeros().toPlainString());//税率 -// saleorderRequestChildrenDto.setVdef2(bdCostsubjEntity.getCostname());//收支项目 -// saleorderRequestChildrenDto.setPk_defdoc2(bdCostsubjEntity.getPkCostsubj()); - //如果优惠金额为0,则传0 - if (!"0".equals(goodsRertunSonDetailsDto.getVdef4().stripTrailingZeros().toPlainString())) { - saleorderRequestChildrenDto.setVdef4("-" + goodsRertunSonDetailsDto.getVdef4().stripTrailingZeros().toPlainString()); - } else { - saleorderRequestChildrenDto.setVdef4("0"); - } - if (!"0".equals(goodsRertunSonDetailsDto.getVdef5().stripTrailingZeros().toPlainString())) { - saleorderRequestChildrenDto.setVdef5("-" + goodsRertunSonDetailsDto.getVdef5().stripTrailingZeros().toPlainString()); - } else { - saleorderRequestChildrenDto.setVdef5("0"); - } - if (!"0".equals(goodsRertunSonDetailsDto.getVdef6().stripTrailingZeros().toPlainString())) { - saleorderRequestChildrenDto.setVdef6("-" + goodsRertunSonDetailsDto.getVdef6().stripTrailingZeros().toPlainString()); - } else { - saleorderRequestChildrenDto.setVdef6("0"); - } - if (!"0".equals(goodsRertunSonDetailsDto.getVdef7().stripTrailingZeros().toPlainString())) { - saleorderRequestChildrenDto.setVdef7("-" + goodsRertunSonDetailsDto.getVdef7().stripTrailingZeros().toPlainString()); - } else { - saleorderRequestChildrenDto.setVdef7("0"); - } - saleorderRequestChildrenDtoList.add(saleorderRequestChildrenDto); +// SaleorderRequestChildrenDto saleorderRequestChildrenDto = new SaleorderRequestChildrenDto(); +// saleorderRequestChildrenDto.setBlargessflag(isblargessflag);//是否赠品 +// saleorderRequestChildrenDto.setCadvisecalbodyid(bdCalbodyEntity.getPkCalbody());//发货库存组织 +// saleorderRequestChildrenDto.setCbodywarehouseid(bdStordocEntity.getPkStordoc());//发货仓库 +// saleorderRequestChildrenDto.setCconsigncorpid(deliverGoodsCorp.getPkCorp());//发货公司 +// saleorderRequestChildrenDto.setCcurrencytypeid("00010000000000000001");//币种 +// saleorderRequestChildrenDto.setCinventoryid(bdInvmandocEntity.getPkInvmandoc());//存货id +// saleorderRequestChildrenDto.setCreceiptcorpid(bdCumandocEntity.getPkCumandoc());//收货单位 +// saleorderRequestChildrenDto.setDconsigndate(generateBusinessDate);//计划发货日期 +// saleorderRequestChildrenDto.setDdeliverdate(generateBusinessDate);// 要求收货日期 +// saleorderRequestChildrenDto.setNexchangeotobrate("1.00000000");//折本汇率 +// saleorderRequestChildrenDto.setNitemdiscountrate("100.000000");//单品折扣 +// saleorderRequestChildrenDto.setNnumber("-" + goodsRertunSonDetailsDto.getGroupShipQty().stripTrailingZeros().toPlainString());//数量 +// saleorderRequestChildrenDto.setNoriginalcurdiscountmny("0");//折扣额 +//// saleorderRequestChildrenDto.setNoriginalcurmny("-" + noriginalcurmny.stripTrailingZeros().toPlainString());//无税金额 +//// saleorderRequestChildrenDto.setNoriginalcurnetprice(noriginalcurprice.stripTrailingZeros().toPlainString());//无税净价 +//// saleorderRequestChildrenDto.setNoriginalcurprice(noriginalcurprice.stripTrailingZeros().toPlainString());//无税单价 +//// saleorderRequestChildrenDto.setNoriginalcursummny("-" + noriginalcursummny.stripTrailingZeros().toPlainString());//价税合计 +// saleorderRequestChildrenDto.setNoriginalcursummny("-" + goodsRertunSonDetailsDto.getGroupTotalPayAmount().setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString());//价税合计 新逻辑 +//// saleorderRequestChildrenDto.setNoriginalcurtaxmny("-" + noriginalcurtaxmny.stripTrailingZeros().toPlainString());//税额 +//// saleorderRequestChildrenDto.setNoriginalcurtaxnetprice(noriginalcurtaxprice.stripTrailingZeros().toPlainString());//含税净价 +//// saleorderRequestChildrenDto.setNoriginalcurtaxprice(noriginalcurtaxprice.stripTrailingZeros().toPlainString());//含税单价 +//// saleorderRequestChildrenDto.setNtaxrate(new BigDecimal(bdTaxitemsEntity1.getTaxratio()).stripTrailingZeros().toPlainString());//税率 +//// saleorderRequestChildrenDto.setVdef2(bdCostsubjEntity.getCostname());//收支项目 +//// saleorderRequestChildrenDto.setPk_defdoc2(bdCostsubjEntity.getPkCostsubj()); +// //如果优惠金额为0,则传0 +// if (!"0".equals(goodsRertunSonDetailsDto.getVdef4().stripTrailingZeros().toPlainString())) { +// saleorderRequestChildrenDto.setVdef4("-" + goodsRertunSonDetailsDto.getVdef4().stripTrailingZeros().toPlainString()); +// } else { +// saleorderRequestChildrenDto.setVdef4("0"); +// } +// if (!"0".equals(goodsRertunSonDetailsDto.getVdef5().stripTrailingZeros().toPlainString())) { +// saleorderRequestChildrenDto.setVdef5("-" + goodsRertunSonDetailsDto.getVdef5().stripTrailingZeros().toPlainString()); +// } else { +// saleorderRequestChildrenDto.setVdef5("0"); +// } +// if (!"0".equals(goodsRertunSonDetailsDto.getVdef6().stripTrailingZeros().toPlainString())) { +// saleorderRequestChildrenDto.setVdef6("-" + goodsRertunSonDetailsDto.getVdef6().stripTrailingZeros().toPlainString()); +// } else { +// saleorderRequestChildrenDto.setVdef6("0"); +// } +// if (!"0".equals(goodsRertunSonDetailsDto.getVdef7().stripTrailingZeros().toPlainString())) { +// saleorderRequestChildrenDto.setVdef7("-" + goodsRertunSonDetailsDto.getVdef7().stripTrailingZeros().toPlainString()); +// } else { +// saleorderRequestChildrenDto.setVdef7("0"); +// } +// saleorderRequestChildrenDtoList.add(saleorderRequestChildrenDto); + + //修改为生成红字应收单表体 + List childrennArrayList = new ArrayList<>(); + ArapDjzbVO.Childrenn arapDjzbVOChildrenn = new ArapDjzbVO.Childrenn(); + childrennArrayList.add(arapDjzbVOChildrenn); + arapDjzbVOChildrenn.setCinventoryid(bdInvbasdocEntity.getInvcode());//存货管理档案 + arapDjzbVOChildrenn.setJfbbje("-" + goodsRertunSonDetailsDto.getGroupTotalPayAmount().setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString());//借方本币金额 + arapDjzbVOChildrenn.setJfybje("-" + goodsRertunSonDetailsDto.getGroupTotalPayAmount().setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString());//借方原币金额 +// arapDjzbVOChildrenn.setJfbbsj("-" + noriginalcurmny.stripTrailingZeros().toPlainString());//借方本币税金 +// arapDjzbVOChildrenn.setJfybsj("-" + noriginalcurmny.stripTrailingZeros().toPlainString());//借方原币税金 +// arapDjzbVOChildrenn.setWbfbbje("-" + noriginalcurtaxmny.stripTrailingZeros().toPlainString());//借方本币无税金额 +// arapDjzbVOChildrenn.setJfybwsje("-" + noriginalcurtaxmny.stripTrailingZeros().toPlainString());//借方原币无税金额 //退货没有邮费金额,已经向万万确认 //平台优惠 @@ -1178,7 +1213,8 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { //补充:平台优惠-存货 BigDecimal absAccumulatedPostage = vdef4.abs(); BigDecimal negativeValue = absAccumulatedPostage.negate(); - queryAdditionUtil.additional(saleorderRequestChildrenDtoList, bdInvmandocEntity1, bdInvbasdocEntity1, negativeValue, "-1", bdTaxitemsEntity); +// queryAdditionUtil.additional(saleorderRequestChildrenDtoList, bdInvmandocEntity1, bdInvbasdocEntity1, negativeValue, "-1", bdTaxitemsEntity); + queryAdditionUtil.additionalV3(childrennArrayList, bdInvmandocEntity1, bdInvbasdocEntity1, negativeValue, bdTaxitemsEntity); } } //达人优惠 @@ -1194,7 +1230,8 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { //补充:达人优惠-存货 BigDecimal absAccumulatedPostage = vdef6.abs(); BigDecimal negativeValue = absAccumulatedPostage.negate(); - queryAdditionUtil.additional(saleorderRequestChildrenDtoList, bdInvmandocEntity1, bdInvbasdocEntity1, negativeValue, "-1", bdTaxitemsEntity); +// queryAdditionUtil.additional(saleorderRequestChildrenDtoList, bdInvmandocEntity1, bdInvbasdocEntity1, negativeValue, "-1", bdTaxitemsEntity); + queryAdditionUtil.additionalV3(childrennArrayList, bdInvmandocEntity1, bdInvbasdocEntity1, negativeValue, bdTaxitemsEntity); } } //支付优惠 @@ -1210,27 +1247,48 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { //补充:支付优惠-存货 BigDecimal absAccumulatedPostage = vdef5.abs(); BigDecimal negativeValue = absAccumulatedPostage.negate(); - queryAdditionUtil.additional(saleorderRequestChildrenDtoList, bdInvmandocEntity1, bdInvbasdocEntity1, negativeValue, "-1", bdTaxitemsEntity); +// queryAdditionUtil.additional(saleorderRequestChildrenDtoList, bdInvmandocEntity1, bdInvbasdocEntity1, negativeValue, "-1", bdTaxitemsEntity); + queryAdditionUtil.additionalV3(childrennArrayList, bdInvmandocEntity1, bdInvbasdocEntity1, negativeValue, bdTaxitemsEntity); } } if (ProfilesActiveConstant.PUSH_SCENE_TYPE_1.equals(pushScenarioType) || ProfilesActiveConstant.PUSH_SCENE_TYPE_2.equals(pushScenarioType)) { - //推送U8C - List saleorderRequestDtoList = new ArrayList<>(); - saleorderRequestDtoList.add(saleorderRequestDto); - Map> stringStringMap = new HashMap<>(); - stringStringMap.put("saleorder", saleorderRequestDtoList); - SoSaleResultRootDto soSaleResultRootDto = sendU8CTOCOrder(JSON.toJSONString(stringStringMap)); - String vreceiptcode = null; - String pk_corp = null; - String csaleid = null; - if (soSaleResultRootDto != null && soSaleResultRootDto.getParentvo() != null) { - vreceiptcode = soSaleResultRootDto.getParentvo().getVreceiptcode(); - pk_corp = soSaleResultRootDto.getParentvo().getPk_corp(); - csaleid = soSaleResultRootDto.getParentvo().getCsaleid(); + //推送U8C生成红字应收单 +// List saleorderRequestDtoList = new ArrayList<>(); +// saleorderRequestDtoList.add(saleorderRequestDto); +// Map> stringStringMap = new HashMap<>(); +// stringStringMap.put("saleorder", saleorderRequestDtoList); +// SoSaleResultRootDto soSaleResultRootDto = sendU8CTOCOrder(JSON.toJSONString(stringStringMap)); +// String vreceiptcode = null; +// String pk_corp = null; +// String csaleid = null; +// if (soSaleResultRootDto != null && soSaleResultRootDto.getParentvo() != null) { +// vreceiptcode = soSaleResultRootDto.getParentvo().getVreceiptcode(); +// pk_corp = soSaleResultRootDto.getParentvo().getPk_corp(); +// csaleid = soSaleResultRootDto.getParentvo().getCsaleid(); +// } +// logger.info("TOC销售订单编号:{} 销售订单主键:{} 销售公司:{}", vreceiptcode, csaleid, pk_corp); + List arapDjzbVOList = new ArrayList<>(); + ArapDjzbVO arapDjzbVO = new ArapDjzbVO(); + arapDjzbVO.setParentvo(parentVo); + arapDjzbVO.setChildren(childrennArrayList); + arapDjzbVOList.add(arapDjzbVO); + + Map> listMap = new HashMap<>(); + listMap.put("djzbvo", arapDjzbVOList); + + ArapDjzb arapDjzb = sendU8cRedReceivable(JSON.toJSONString(listMap)); + String djbh = null; + String dwbm = null; + String vouchid = null; + if (arapDjzb != null && arapDjzb.getParentvo() != null) { + djbh = arapDjzb.getParentvo().getDjbh(); + dwbm = arapDjzb.getParentvo().getDwbm(); + vouchid = arapDjzb.getParentvo().getVouchid(); } - logger.info("TOC销售订单编号:{} 销售订单主键:{} 销售公司:{}", vreceiptcode, csaleid, pk_corp); - updateSuccessOrFail2(oldValue, "Y", "success", vreceiptcode, csaleid); + logger.info("TOC红字应收单:{} 销售订单主键:{} 销售公司:{}", djbh, vouchid, dwbm); + + updateSuccessOrFail2(oldValue, "Y", "success", djbh, vouchid); } else if (ProfilesActiveConstant.PUSH_SCENE_TYPE_0.equals(pushScenarioType)) { //不推送U8C,单据暂存 String vreceiptcode = "暂存"; @@ -1748,7 +1806,8 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { private BdBusitypeEntity u8cOperationFlowV2() throws Exception { //查询业务流程 //2024年8月6日 11:33:07 具体的业务流程名称,还需要实施提供 - String processName = "TOC售后完成"; +// String processName = "TOC售后完成"; + String processName = "TOC销售退款"; BdBusitypeEntity bdBusitypeEntity = queryBdBusitypeUtil.queryBdBusitype(processName); Assert.notNull(bdBusitypeEntity, "根据业务流程名称({})没有查询到业务流程", processName); return bdBusitypeEntity; @@ -1798,7 +1857,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { * @param isCheckShopChoose true取建议零售价、false取实付金额 * @author liuyang */ - private GoodsRertunSonDetailsDto groupMergeDetailedRows(List sonDetailsDtoList, Boolean isCheckShopChoose) throws Exception { + private GoodsRertunSonDetailsDto groupMergeDetailedRows(List sonDetailsDtoList, Boolean isCheckShopChoose, String sceneType) throws Exception { Assert.notNull(sonDetailsDtoList, "sonDetailsDtoList不能为空"); Assert.notNull(isCheckShopChoose, "isCheckShopChoose不能为空"); // Assert.notNull(mapList, "mapLists不能为空"); @@ -1828,8 +1887,13 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { //取《U8C存货基本档案-参考售价》 totalAmount = getRefsaleprice(bdInvmandocEntity, bdInvbasdocEntity, calculationFormulaStr, goodsRertunSonDetailsDto, header); } else { - //取《O实退》 - totalAmount = accumulatedDiscounts(goodsRertunSonDetailsDto, rerturnGoodsOrderSearchData, calculationFormulaStr); + if (sceneType.equals("tran")) { + //取《O实退金额》 + totalAmount = accumulatedDiscountsV2(goodsRertunSonDetailsDto, rerturnGoodsOrderSearchData, calculationFormulaStr); + } else { + //取《O实退金额/O请求数量*O实收数量》 + totalAmount = accumulatedDiscounts(goodsRertunSonDetailsDto, rerturnGoodsOrderSearchData, calculationFormulaStr); + } } //取对应的售后订单明细,主要是取这个价格 @@ -2950,6 +3014,70 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { return totalPayAmount; } + + /** + * 累加应收金额=实退金额+达人优惠+支付优惠+平台优惠 + * + * @param goodsRertunSonDetailsDto OFS售后入库单明细行 + * @param rerturnGoodsOrderSearchData OFS售后订单 + * @param calculationFormulaStr 计算公式 + * @author liuyang + */ + private String accumulatedDiscountsV2(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(); + + //O售后订单表头+明细行 + RerturnGoodsOrderSearchHeader header = rerturnGoodsOrderSearchData.getHeader(); + List details = rerturnGoodsOrderSearchData.getDetails(); + + //根据「入库单明细」匹配「售后订单明细行」 + RerturnGoodsOrderSearchDetails targetDetails = null; + for (int i = 0; i < details.size(); i++) { + RerturnGoodsOrderSearchDetails rerturnGoodsOrderSearchDetails = details.get(i); + if (goodsRertunSonDetailsDto.getRefOrderDetailId() != null && rerturnGoodsOrderSearchDetails.getId() != null) { + if (rerturnGoodsOrderSearchDetails.getId().equals(goodsRertunSonDetailsDto.getRefOrderDetailId())) { + targetDetails = rerturnGoodsOrderSearchDetails; + } + } + } + Assert.notNull(targetDetails, "根据OFS售后入库单细行(refOrderDetailId)无法匹配售后订单明细行", goodsRertunSonDetailsDto.getRefOrderDetailId()); + + //售后订单明细行-退货金额 + String totalAmount = targetDetails.getTotalAmount();//实退金额 + Assert.notNull(totalAmount, "售后订单:{} 存货明细行:{} 退货金额不能为空!", header.getCode(), targetDetails.getSkuCode()); + Assert.state(!"".equals(totalAmount), "售后订单:{} 存货明细行:{} 退货金额不能为空!", header.getCode(), targetDetails.getSkuCode()); + //售后订单明细行-请求数量 + //实退数量存在可能为0的情况,如果用退货金额/实退数量可能会抛出异常 +// String requestQty = targetDetails.getRequestQty();//请求数量 +// Assert.notNull(requestQty, "售后订单:{} 存货明细行:{} 请求数量不能为空!", header.getCode(), targetDetails.getSkuCode()); +// Assert.state(!"".equals(requestQty), "售后订单:{} 存货明细行:{} 请求数量不能为空!", header.getCode(), targetDetails.getSkuCode()); + + //测试 +// goodsRertunSonDetailsDto.setReceivedQty("1"); + +// String receivedQty = goodsRertunSonDetailsDto.getReceivedQty(); +// Assert.notNull(receivedQty, "售后订单:{} 存货明细行:{} 请求数量不能为空!", header1.getCode(), goodsRertunSonDetailsDto.getId()); +// Assert.state(!"".equals(receivedQty), header1.getCode(), goodsRertunSonDetailsDto.getId()); +// if ("0".equals(new BigDecimal(receivedQty).stripTrailingZeros().toPlainString())) { +// Assert.state(false, "售后订单:{} 存货明细行:{} 实退数量不能为0!", header1.getCode(), goodsRertunSonDetailsDto.getId()); +// } + //O含税单价=通过退货金额/请求数量 +// BigDecimal unitPriceIncludingTax = new BigDecimal(totalAmount).divide(new BigDecimal(requestQty), 20, BigDecimal.ROUND_HALF_UP); + //实退金额=O含税单价*(O售后入库单)这里保留 4 位小数的用途是便于暴露问题给后续方法,后续方法会变成 2 位小数(0.0034) +// BigDecimal actualRefundAmount = unitPriceIncludingTax.multiply(new BigDecimal(receivedQty)).setScale(4, BigDecimal.ROUND_HALF_UP); + //出库对应的实退=含税单价(actualRefundAmount)*出库单实退数量 +// BigDecimal actualRefundAmountBigDecimal = new BigDecimal(receivedQty).multiply(actualRefundAmount).setScale(2, BigDecimal.ROUND_HALF_UP); + String format = StrUtil.format("{}", totalAmount); + calculationFormulaStr.append(format); + + return totalAmount; + } + /** * 累加应收金额=实退金额+达人优惠+支付优惠+平台优惠 * @@ -3265,4 +3393,59 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { } return filteredList; } + + /** + * 2025 年 3 月 13 日 14:08:20 + * 推送U8红字应收单方法 + * + * @author liuyang + */ + public ArapDjzb sendU8cRedReceivable(String param) { + long startLong = System.currentTimeMillis(); + logger.info("TOC推送开始,推送参数:" + param + ",U8C_URL:" + OverallConstant.getOverAllValue("u8c_url")); + String apiCode = "8000370069"; + String result = HttpRequest.post(OverallConstant.getOverAllValue("u8c_url")).header("appId", OverallConstant.getOverAllValue("appId"))//头信息,多个头信息多次调用此方法即可 + .header("usercode", OverallConstant.getOverAllValue("u8cApiUsercodeCode")).header("password", OverallConstant.getOverAllValue("u8cApiPasswordCode")).header("system", OverallConstant.getOverAllValue("u8cApiSystemCode")).header("trantype", OverallConstant.getOverAllValue("u8cApiTrantypeCode")).header("apiCode", apiCode)//头信息,多个头信息多次调用此方法即可 + .header("publicKey", OverallConstant.getOverAllValue("publicKey"))//头信息,多个头信息多次调用此方法即可 + .header("secretKey", OverallConstant.getOverAllValue("secretKey"))//头信息,多个头信息多次调用此方法即可 + .body(param)//表单内容 + .timeout(600000)//超时,毫秒 + .execute().body(); + logger.info("TOC推送结束,返回参数:" + result); + long endLong = System.currentTimeMillis(); + logger.info("TOC接口请求耗时:" + (endLong - startLong)); + + JSONObject jsonObject = JSON.parseObject(result); + result = String.valueOf(jsonObject.get("attribute")); + + boolean isSuccess = false; + ArapDjzb arapDjzb = null; + if (result != null && !"".equals(result)) { + ReusltStrDto reusltStrDto = JSON.parseObject(result, ReusltStrDto.class); + if ("success".equals(reusltStrDto.getStatus())) { + arapDjzb = resultDataHandle2(reusltStrDto.getData()); + isSuccess = true; + } + } + if (!isSuccess) { + Assert.state(false, "TOC无源入库单生成红字应收单失败 接口返回结果:{}", result); + } + return arapDjzb; + } + + private ArapDjzb resultDataHandle2(String resultData) { + try { + if (resultData != null && !"".equals(resultData)) { + if (resultData.contains("[")) { + resultData = resultData.substring(1, resultData.length() - 1); + } + return JSON.parseObject(resultData, ArapDjzb.class); + } + } catch (Exception e) { + e.printStackTrace(); + logger.error("解析返回参数失败的错误", e); + //如果解析失败,记录原因,但是不能影响结果的记录 + } + return null; + } } \ No newline at end of file diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/bak/SoSaleReturnPluginInitializerToC.bak b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/bak/SoSaleReturnPluginInitializerToC.bak new file mode 100644 index 00000000..0f08fcbe --- /dev/null +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/bak/SoSaleReturnPluginInitializerToC.bak @@ -0,0 +1,3268 @@ +package com.hzya.frame.plugin.lets.plugin.sales; + +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpRequest; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Lists; +import com.hzya.frame.base.PluginBaseEntity; +import com.hzya.frame.beanutil.BeanUtil; +import com.hzya.frame.plugin.lets.constant.OverallConstant; +import com.hzya.frame.plugin.lets.constant.ProfilesActiveConstant; +import com.hzya.frame.plugin.lets.entity.*; +import com.hzya.frame.plugin.lets.ofs.dao.ITocofsReturngoodsDao; +import com.hzya.frame.plugin.lets.ofs.dao.ITocofsReturngoodsDetailedDao; +import com.hzya.frame.plugin.lets.ofs.entity.TocofsReturngoodsDetailedEntity; +import com.hzya.frame.plugin.lets.ofs.entity.TocofsReturngoodsEntity; +import com.hzya.frame.plugin.lets.ofs.entity.TocofsSaleoutDetailedEntity; +import com.hzya.frame.plugin.lets.ofsvo.QueryOfsSoSaleOutVo; +import com.hzya.frame.plugin.lets.queryvo.StartAndEndVo; +import com.hzya.frame.plugin.lets.resultvo.CacheTocMapVoV2; +import com.hzya.frame.plugin.lets.resultvo.CalculateDateVo; +import com.hzya.frame.plugin.lets.u8cdto.*; +import com.hzya.frame.plugin.lets.util.*; +import com.hzya.frame.split.SplitListByCountUtil; +import com.hzya.frame.ttxofs.dto.ofssaleorderoutsearch.HeaderDetailsDto; +import com.hzya.frame.ttxofs.dto.ofssaleorderoutsearch.HeaderDto; +import com.hzya.frame.ttxofs.dto.ofssalesordersearch.DetailsDto; +import com.hzya.frame.ttxofs.dto.returngoodordersearch.RerturnGoodsOrderSearchData; +import com.hzya.frame.ttxofs.dto.returngoodordersearch.RerturnGoodsOrderSearchDetails; +import com.hzya.frame.ttxofs.dto.returngoodordersearch.RerturnGoodsOrderSearchHeader; +import com.hzya.frame.ttxofs.dto.stock.StockinOrderSearchResponse; +import com.hzya.frame.ttxofs.service.OfsUnifiedService; +import com.hzya.frame.web.entity.BaseResult; +import com.hzya.frame.web.entity.JsonResultEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.concurrent.locks.ReentrantLock; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +/** + * OFS售后入库单(TOC)生成U8C红字销售订单、交易成功关联原单 + * + * @author makejava + * @since 2023-08-16 15:49:55 + */ +public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { + + Logger logger = LoggerFactory.getLogger(SoSaleReturnPluginInitializerToC.class); + +// private static final ReentrantLock LOCK = new ReentrantLock(true); + + private static final ReentrantLock LOCK1 = new ReentrantLock(true); + + private static final ReentrantLock LOCK2 = new ReentrantLock(true); + + private static final String STOCK = "stock"; + + private static final String TRAN = "tran"; + + private static final String PROD_FILED = "prod"; + + @Autowired + private BalanceUnitPriceUtil balanceUnitPriceUtil; + + @Autowired + private QueryU8CEntityUtil queryU8CEntityUtil; + + @Autowired + private QueryAdditionUtil queryAdditionUtil; + + @Override + public void initialize() { + logger.info(getPluginLabel() + "執行初始化方法initialize()"); + } + + @Override + public void destroy() { + logger.info(getPluginLabel() + "執行銷毀方法destroy()"); + } + + @Override + public String getPluginId() { + return "sales.SoSaleReturnPluginInitializerToC"; + } + + @Override + public String getPluginName() { + return "OFS售后入库单(TOC)生成U8C红字销售订单"; + } + + @Override + public String getPluginLabel() { + return "OFS售后入库单(TOC)生成U8C红字销售订单"; + } + + @Override + public String getPluginType() { + return "3"; + } + + @Override + public JsonResultEntity executeBusiness(JSONObject requestJson) throws Exception { + logger.info("触发调用:{}" + getPluginName()); + try { + String requestJsonParam = String.valueOf(requestJson.get("param")); + + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + long startMillis = System.currentTimeMillis(); + logger.info("executeBusiness方法调用开始:" + getPluginName() + "-插件"); + + try { + String param = String.valueOf(requestJson.get("param")); + String sceneType = String.valueOf(requestJson.get("sceneType"));//sceneType:stock、tran + String pushScenarioType = String.valueOf(requestJson.get("pushScenarioType")); + if (ProfilesActiveConstant.TYPE_VBILLCODE.equals(requestJson.get("type"))) { + //按单号 + if (param != null && !"".equals(param)) { + startImplementByCode(param, sceneType); + } + } else if (ProfilesActiveConstant.TYPE_TIME_FRAME.equals(requestJson.get("type"))) { + //前台页面功能日期推送,或者接口调用也行 + String craeteDateStr = computingTime(param); + if (craeteDateStr != null && !"".equals(craeteDateStr)) { + splitDateAndPush(craeteDateStr, sceneType, pushScenarioType); + } + } else { + if (ProfilesActiveConstant.LETS_PROFILES_ACTIVE.equals(PROD_FILED)) { + //默认被定时器执行,每天晚上凌晨0点5分 + //暂定先同步TOC销售库存、再推送TOC销售确认收入 + List startAndEndVos = calculateCalculateEntireDayPeriod(null); + //TODO 1号上线注释掉 +// startImplementStockByTime(startAndEndVos.get(0).getStart_time(), startAndEndVos.get(0).getEnd_time(), "0"); +// startImplementByTradeTime(startAndEndVos.get(0).getStart_time(), startAndEndVos.get(0).getEnd_time(), "0"); + } + } + } catch (Exception e) { + logger.error("executeBusiness方法异常", e); + } + long endMillis = System.currentTimeMillis(); + logger.info("executeBusiness方法调用结束:" + getPluginName() + "-插件 执行耗时:{}", (endMillis - startMillis)); +// return null; + } + }, "执行插件:" + getPluginName() + " " + requestJsonParam); + thread.start(); + + if (requestJson != null && requestJson.get("type") != null && ProfilesActiveConstant.TYPE_DETAIL_ERROR.equals(requestJson.get("type"))) { + try { + thread.join(); + } catch (Exception e) { + logger.error("thread.join();抛出异常", e); + } + } + } catch (Exception e) { + logger.error("executeBusiness方法抛出异常", e); + } + return BaseResult.getSuccessMessageEntity("插件执行成功"); + } + + @Autowired + private OfsUnifiedService ofsUnifiedService; + + @Autowired + private QueryBdBusitypeUtil queryBdBusitypeUtil; + + private static final String NOTHING = "无"; + + private static final String ADD = "&"; + + @Autowired + private ITocofsReturngoodsDao iTocofsReturngoodsDao; + + @Autowired + private ITocofsReturngoodsDetailedDao iTocofsReturngoodsDetailedDao; + + @Autowired + private TocReturnBasicArchivesCacheUtil tocReturnBasicArchivesCacheUtil; + + @Autowired + private ShopTobOrToCUtil shopTobOrToCUtil; + + @Autowired + private OfsStandardUtil ofsStandardUtil; + + @Autowired + private AfterSalesOrderUtil afterSalesOrderUtil; + + @Autowired + private RdclUtil rdclUtil; + + @Autowired + private OfsOrderAfterSalesAmountAllocationUtil ofsOrderAfterSalesAmountAllocationUtil; + + /** + * 库存同步,根据时间范围拉取 + * + * @author liuyang + */ + public void startImplementStockByTime(String startTime, String endTime, String pushScenarioType) throws Exception { + try { + long startMillis = System.currentTimeMillis(); + String threadNameStrStart = StrUtil.format("开始-OFS销售出库(TOC)同步U8C销售订单 开始时间:{} 结束时间:{}", startTime, endTime); + logger.info(threadNameStrStart); + + Assert.notNull(startTime, "开始时间不能为空"); + Assert.notNull(endTime, "结束时间不能为空"); + Assert.notNull(pushScenarioType, "pushScenarioType不能为空"); +// CalculateDateVo calculateDateVo = DateStrUtil.calculateCalculateEntireDayPeriod(dateStr); + List returnGoodHeaderDetailsDataDtoArrayList = new ArrayList<>(); + if (ProfilesActiveConstant.PUSH_SCENE_TYPE_0.equals(pushScenarioType) || ProfilesActiveConstant.PUSH_SCENE_TYPE_2.equals(pushScenarioType)) { + String tocShop = shopTobOrToCUtil.getCommaShop("TOC"); + QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo(); + queryOfsSoSaleOutVo.setClosedAt_start(startTime); + queryOfsSoSaleOutVo.setClosedAt_end(endTime); + queryOfsSoSaleOutVo.setClientCode("LETS"); +// queryOfsSoSaleOutVo.setInternalInstructionType("SALES"); + //2024年8月22日 14:02:13 已经和O确认,这个字段取消传递! +// queryOfsSoSaleOutVo.setCompanyCode("SHLZ"); + queryOfsSoSaleOutVo.setStatus(900L); + queryOfsSoSaleOutVo.setPageNo(1L); + queryOfsSoSaleOutVo.setPageSize(50L); + queryOfsSoSaleOutVo.setStoreCode(tocShop); + queryOfsSoSaleOutVo.setInternalInstructionType("RETURN"); +// queryOfsSoSaleOutVo.setCode("LETS-RE2024071600000001"); + ofsStandardUtil.queryOfsReturnGoods(queryOfsSoSaleOutVo, returnGoodHeaderDetailsDataDtoArrayList, 1L, "ofs.receipt.search"); + } else if (ProfilesActiveConstant.PUSH_SCENE_TYPE_1.equals(pushScenarioType)) { + TocofsReturngoodsDetailedEntity tocofsReturngoodsDetailedEntity = new TocofsReturngoodsDetailedEntity(); + if (startTime.length() == 19) { + tocofsReturngoodsDetailedEntity.setBusinessDateStart(startTime); + } else { + tocofsReturngoodsDetailedEntity.setBusinessDateStart(startTime + " 00:00:00"); + } + if (endTime.length() == 19) { + tocofsReturngoodsDetailedEntity.setBusinessDateEnd(endTime); + } else { + tocofsReturngoodsDetailedEntity.setBusinessDateEnd(endTime + " 23:59:59"); + } + tocofsReturngoodsDetailedEntity.setBusinesstype("TOC_RETURN"); + returnGoodHeaderDetailsDataDtoArrayList = queryTocofsReturngoodsDetailed(tocofsReturngoodsDetailedEntity); + } else { + Assert.state(false, "未知的场景类型!"); + } + logger.info("TOC退货数据返回行数:{}", returnGoodHeaderDetailsDataDtoArrayList.size()); + if (returnGoodHeaderDetailsDataDtoArrayList.size() > 0) { + returnGoodHeaderDetailsDataDtoArrayList.removeIf(new Predicate() { + @Override + public boolean test(StockinOrderSearchResponse.StockinOrder headerDetailsDto) { + StockinOrderSearchResponse.StockinOrder.StockinH header = headerDetailsDto.getHeader(); + if (header != null && header.getCompanyCode() != null) { + if (ProfilesActiveConstant.FILTER_COMPANY.contains(header.getCompanyCode().trim())) { + return true; + } + } + return false; + } + }); + getSetStock(returnGoodHeaderDetailsDataDtoArrayList, pushScenarioType); + } else { + logger.info("没有查询到任何数据!不需要同步"); + } + long endMillis = System.currentTimeMillis(); + String threadNameStrEnd = StrUtil.format("结束-OFS销售出库(TOC)同步U8C销售订单 开始时间:{} 结束时间:{} 耗时:{}", startTime, endTime, (endMillis - startMillis)); + logger.info(threadNameStrEnd); + } catch (Exception e) { + logger.error("startImplementStockByTime方法抛出异常", e); + } + } + + /** + * 根据编码、场景类型拉取 + * + * @param code 编码 + * @param sceneType 场景类型 + * @author liuyang + */ + public void startImplementByCode(String code, String sceneType) throws Exception { + long startMillis = System.currentTimeMillis(); + String threadNameStrStart = StrUtil.format("开始-OFS销售出库(TOC)同步U8C销售订单 同步单据号:{} 业务场景:{}", code, sceneType); + logger.info(threadNameStrStart); + + Assert.notNull(code, "code不能为空"); + Assert.notNull(sceneType, "sceneType不能为空"); + + String tocShop = shopTobOrToCUtil.getCommaShop("TOC"); + + List returnGoodHeaderDetailsDataDtoList = new ArrayList<>(); + QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo(); + queryOfsSoSaleOutVo.setClientCode("LETS"); +// queryOfsSoSaleOutVo.setStatus(900L); + queryOfsSoSaleOutVo.setPageNo(1L); + queryOfsSoSaleOutVo.setPageSize(50L); + queryOfsSoSaleOutVo.setStoreCode(tocShop); + queryOfsSoSaleOutVo.setCode(code); + queryOfsSoSaleOutVo.setInternalInstructionType("RETURN"); + ofsStandardUtil.queryOfsReturnGoods(queryOfsSoSaleOutVo, returnGoodHeaderDetailsDataDtoList, 1L, "ofs.receipt.search"); + logger.info("数据返回行数:{}", returnGoodHeaderDetailsDataDtoList.size()); + if (returnGoodHeaderDetailsDataDtoList.size() > 0) { + returnGoodHeaderDetailsDataDtoList.removeIf(new Predicate() { + @Override + public boolean test(StockinOrderSearchResponse.StockinOrder headerDetailsDto) { + StockinOrderSearchResponse.StockinOrder.StockinH header = headerDetailsDto.getHeader(); + if (header != null && header.getCompanyCode() != null) { + if (ProfilesActiveConstant.FILTER_COMPANY.contains(header.getCompanyCode().trim())) { + return true; + } + if (sceneType.equals("tran") && (header.getClosedAt() == null || "".equals(header.getClosedAt().trim()))) { + return true; + } + } + return false; + } + }); + if (sceneType.equals("stock")) { + getSetStock(returnGoodHeaderDetailsDataDtoList, "2"); + } else if (sceneType.equals("tran")) { + getSetTran(returnGoodHeaderDetailsDataDtoList, "2"); + } + } else { + logger.info("没有查询到任何数据!不需要同步"); + } + + long endMillis = System.currentTimeMillis(); + String threadNameStrEnd = StrUtil.format("结束-OFS销售出库(TOC)同步U8C销售订单 同步单据号:{} 业务场景:{} 耗时:{}", code, sceneType, (endMillis - startMillis)); + logger.info(threadNameStrEnd); + } + + /** + * 交易采购,按指定时间拉取 + * + * @author liuyang + */ + public void startImplementByTradeTime(String startTime, String endTime, String pushScenarioType) throws Exception { + try { + long startMillis = System.currentTimeMillis(); + String threadNameStrStart = StrUtil.format("OFS售后入库(TOB)同步U8C销售订单(库存同步) 开始时间:{} 结束时间:{}", startTime, endTime); + logger.info(threadNameStrStart); + + Assert.notNull(startTime, "startTime不能为空"); + Assert.notNull(endTime, "endTime不能为空"); + List returnGoodHeaderDetailsDataDtoArrayList = new ArrayList<>(); + + if (ProfilesActiveConstant.PUSH_SCENE_TYPE_0.equals(pushScenarioType) || ProfilesActiveConstant.PUSH_SCENE_TYPE_2.equals(pushScenarioType)) { + //生成一个时间范围 +// StartAndEndVo startAndEndVo = offsetTimeTime.offsetTime(); + //2024年8月19日 15:47:51 查询出U8C里标记的店铺TOB属性 + String tocShop = shopTobOrToCUtil.getCommaShop("TOC"); + QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo(); + queryOfsSoSaleOutVo.setRefundedAt_start(startTime); + queryOfsSoSaleOutVo.setRefundedAt_end(endTime); + queryOfsSoSaleOutVo.setClientCode("LETS"); + queryOfsSoSaleOutVo.setPageNo(1L); + queryOfsSoSaleOutVo.setPageSize(50L); + queryOfsSoSaleOutVo.setStoreCode(tocShop); + queryOfsSoSaleOutVo.setInternalInstructionType("RETURN"); + queryOfsSoSaleOutVo.setRefundStatus("900"); +// queryOfsSoSaleOutVo.setCode("LETS-RE2024081900000001"); + ofsStandardUtil.queryOfsReturnGoods(queryOfsSoSaleOutVo, returnGoodHeaderDetailsDataDtoArrayList, 1L, "ofs.receipt.search"); + } else if (ProfilesActiveConstant.PUSH_SCENE_TYPE_1.equals(pushScenarioType)) { + TocofsReturngoodsDetailedEntity tocofsReturngoodsDetailedEntity = new TocofsReturngoodsDetailedEntity(); + if (startTime.length() == 19) { + tocofsReturngoodsDetailedEntity.setRefundedAtStart(startTime); + } else { + tocofsReturngoodsDetailedEntity.setRefundedAtStart(startTime + " 00:00:00"); + } + if (endTime.length() == 19) { + tocofsReturngoodsDetailedEntity.setRefundedAtEnd(endTime); + } else { + tocofsReturngoodsDetailedEntity.setRefundedAtEnd(endTime + " 23:59:59"); + } + tocofsReturngoodsDetailedEntity.setBusinesstype("TOC_RETURN"); + returnGoodHeaderDetailsDataDtoArrayList = queryTocofsReturngoodsDetailed(tocofsReturngoodsDetailedEntity); + } else { + Assert.state(false, "未知的场景类型!"); + } + logger.info("数据返回行数:{}", returnGoodHeaderDetailsDataDtoArrayList.size()); + if (returnGoodHeaderDetailsDataDtoArrayList.size() > 0) { + returnGoodHeaderDetailsDataDtoArrayList.removeIf(new Predicate() { + @Override + public boolean test(StockinOrderSearchResponse.StockinOrder headerDetailsDto) { + StockinOrderSearchResponse.StockinOrder.StockinH header = headerDetailsDto.getHeader(); + if (header != null && header.getCompanyCode() != null) { + //过滤掉不需要的公司 + if (ProfilesActiveConstant.FILTER_COMPANY.contains(header.getCompanyCode().trim())) { + return true; + } + //过滤掉入库日期为空的单据 + if (header.getClosedAt() == null || "".equals(header.getClosedAt().trim())) { + return true; + } + } + return false; + } + }); + getSetTran(returnGoodHeaderDetailsDataDtoArrayList, pushScenarioType); + } else { + logger.info("没有查询到任何数据!不需要同步"); + } + + long endMillis = System.currentTimeMillis(); + String threadNameStrEnd = StrUtil.format("OFS售后入库(TOB)同步U8C销售订单(库存同步) 开始时间:{} 结束时间:{} 耗时:{}", startTime, endTime, (endMillis - startMillis)); + logger.info(threadNameStrEnd); + } catch (Exception e) { + logger.error("startImplementByTradeTime方法抛出异常", e); + } + } + + /** + * 库存同步,预备执行逻辑 + * + * @author liuyang + */ + private void getSetStock(List returnGoodHeaderDetailsDataDtoArrayList, String pushScenarioType) throws Exception { + LOCK1.lock(); + try { + //过滤成功的数据 + List stockinOrderList = filterDataStock(returnGoodHeaderDetailsDataDtoArrayList); + //保存到mysql + if (!ProfilesActiveConstant.PUSH_SCENE_TYPE_1.equals(pushScenarioType)) { + batchInsert(stockinOrderList); + } + //执行推送主逻辑 + implementStock(stockinOrderList, pushScenarioType); + } catch (Exception e) { + logger.error("TOC退货-库存:getSetStock方法抛出异常", e); + } finally { + LOCK1.unlock(); + } + } + + /** + * 确认收入:预备执行逻辑 + * + * @author liuyang + */ + private void getSetTran(List returnGoodHeaderDetailsDataDtoArrayList, String pushScenarioType) throws Exception { + LOCK2.lock(); + try { + //过滤成功的数据 + List stockinOrderList = filterDataTran(returnGoodHeaderDetailsDataDtoArrayList); + //保存到mysql + if (!ProfilesActiveConstant.PUSH_SCENE_TYPE_1.equals(pushScenarioType)) { + batchInsert(stockinOrderList); + } + //执行推送主逻辑 + implementTran(stockinOrderList, pushScenarioType); + } catch (Exception e) { + logger.error("TOC退货-确认收入:getSetTran方法抛出异常", e); + } finally { + LOCK2.unlock(); + } + } + + /** + * 库存同步,过滤掉成功的数据 + * + * @author liuyang + */ + private List filterDataStock(List returnGoodHeaderDetailsDataDtoArrayList) throws Exception { +// List headerDetailsDtoList1 = new ArrayList<>(); + List tocofsReturngoodsDetailedEntityList = new ArrayList<>(); + if (returnGoodHeaderDetailsDataDtoArrayList != null && returnGoodHeaderDetailsDataDtoArrayList.size() > 0) { + List> splitListByCount = SplitListByCountUtil.splitListByCount(returnGoodHeaderDetailsDataDtoArrayList, 1000); + for (int i = 0; i < splitListByCount.size(); i++) { + List stockinOrderList = splitListByCount.get(i); + String idStr = commaConcatenatedPrimaryKeyStock(stockinOrderList); + List tocofsReturngoodsDetailedEntities = queryStockTocOutLog(idStr); + tocofsReturngoodsDetailedEntityList.addAll(tocofsReturngoodsDetailedEntities); + } + } + return filterDataRowsAsPushOrFailedStock(tocofsReturngoodsDetailedEntityList, returnGoodHeaderDetailsDataDtoArrayList); + } + + /** + * 确认收入,过滤掉成功的数据 + * + * @author liuyang + */ + private List filterDataTran(List returnGoodHeaderDetailsDataDtoArrayList) throws Exception { + List tocofsReturngoodsDetailedEntityList = new ArrayList<>(); + if (returnGoodHeaderDetailsDataDtoArrayList != null && returnGoodHeaderDetailsDataDtoArrayList.size() > 0) { + List> splitListByCount = SplitListByCountUtil.splitListByCount(returnGoodHeaderDetailsDataDtoArrayList, 100); + for (int i = 0; i < splitListByCount.size(); i++) { + List stockinOrderList = splitListByCount.get(i); + String idStr = commaConcatenatedPrimaryKeyStock(stockinOrderList); + List tocofsReturngoodsDetailedEntities = queryStockTocOutLog(idStr); + tocofsReturngoodsDetailedEntityList.addAll(tocofsReturngoodsDetailedEntities); + } + } + return filterDataRowsAsPushOrFailedTran(tocofsReturngoodsDetailedEntityList, returnGoodHeaderDetailsDataDtoArrayList); + } + + /** + * 逗号拼接字符串主键,作为批处理的一部分,方便下一步的批量查询操作 + * + * @author liuyang + */ + private String commaConcatenatedPrimaryKeyStock(List headerDetailsDtoList2) throws Exception { + StringBuffer idStr = new StringBuffer(); + if (headerDetailsDtoList2 != null && headerDetailsDtoList2.size() > 0) { + for (int i = 0; i < headerDetailsDtoList2.size(); i++) { + StockinOrderSearchResponse.StockinOrder stockinOrder = headerDetailsDtoList2.get(i); + StockinOrderSearchResponse.StockinOrder.StockinH header = stockinOrder.getHeader(); + List details = stockinOrder.getDetails(); + for (int j = 0; j < details.size(); j++) { + StockinOrderSearchResponse.StockinOrder.StockinB stockinB = details.get(j); + Assert.notNull(stockinB.getId(), "O明细主键不能为空!"); + Assert.state(!"".equals(stockinB.getId()), "O明细主键不能为空!"); + + idStr.append("'"); + idStr.append(stockinB.getId()); + idStr.append("'"); + idStr.append(","); + } + } + } + if (idStr.length() > 0) { + return idStr.substring(0, idStr.length() - 1); + } + return null; + } + + /** + * 批查询toc退货入库日志,查询的量由splitListByCount方法控制 + * + * @author liuyang + */ + private List queryStockTocOutLog(String idStr) throws Exception { + List tocofsReturngoodsDetailedEntities = null; + if (idStr != null && !"".equals(idStr.trim())) { + TocofsReturngoodsDetailedEntity tocofsReturngoodsDetailedEntity = new TocofsReturngoodsDetailedEntity(); + tocofsReturngoodsDetailedEntity.setIds(idStr); + tocofsReturngoodsDetailedEntities = iTocofsReturngoodsDetailedDao.query(tocofsReturngoodsDetailedEntity); + } else { + logger.error("idStr为空,无法查询数据!"); + } + return tocofsReturngoodsDetailedEntities; + } + + /** + * 保存抓取到的数据到mysql底表,如果底表里已经存在,则会忽略 + * + * @param returnGoodHeaderDetailsDataDtoArrayList mysql数据行 + */ + private void batchInsert(List returnGoodHeaderDetailsDataDtoArrayList) throws Exception { + if (returnGoodHeaderDetailsDataDtoArrayList != null && returnGoodHeaderDetailsDataDtoArrayList.size() > 0) { + List headerDetailsDtoList1 = new ArrayList<>(); + List headerDetailsDtoList2 = new ArrayList<>(); + + for (StockinOrderSearchResponse.StockinOrder index : returnGoodHeaderDetailsDataDtoArrayList) { + StockinOrderSearchResponse.StockinOrder.StockinH header = index.getHeader();// 主表 + List details = index.getDetails();//明细表 + for (int i = 0; i < details.size(); i++) { + StockinOrderSearchResponse.StockinOrder.StockinB stockinB = details.get(i); + stockinB.setReturnGoodSearchHeaderDto(header); + } + headerDetailsDtoList1.add(header); + headerDetailsDtoList2.addAll(details); + } + + //每250作为一个批次插入主表,根据主键(id)判断是否重复,如果重复的,则不进行插入 + List> lists = SplitListByCountUtil.splitListByCount(headerDetailsDtoList1, 100); + for (int i = 0; i < lists.size(); i++) { + List stockinHS = lists.get(i); + long startTime = System.currentTimeMillis(); + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + try { + List tocofsReturngoodsEntities = copyHeaderDto(stockinHS); + if (tocofsReturngoodsEntities.size() > 0) { + logger.info("插入底表{}个对象(表头)", tocofsReturngoodsEntities.size()); + iTocofsReturngoodsDao.entityInsertOrUpdateBatch(tocofsReturngoodsEntities); + } else { + logger.info("tocofsReturngoodsEntities:没有对象被插入表头底表"); + } + } catch (Exception e) { + logger.error("线程保存TOC退货主表抛出异常", e); + } + } + }); + thread.start(); + try { + thread.join(); + } catch (Exception e) { + logger.error("线程保存TOC退货主表抛出异常", e); + } + long endTime = System.currentTimeMillis(); + logger.info("插入或更新TOC退货入库表头-耗时:{}", (endTime - startTime)); + } + + //插入明细表 + List> lists1 = SplitListByCountUtil.splitListByCount(headerDetailsDtoList2, 100); + for (int i = 0; i < lists1.size(); i++) { + List stockinBS = lists1.get(i); + List tocofsReturngoodsDetailedEntities = copyDetailsDto(stockinBS); + long startTime = System.currentTimeMillis(); + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + try { + if (tocofsReturngoodsDetailedEntities.size() > 0) { + logger.info("插入底表{}个对象(表体)", tocofsReturngoodsDetailedEntities.size()); + iTocofsReturngoodsDetailedDao.entityInsertOrUpdateBatch(tocofsReturngoodsDetailedEntities); + } else { + logger.info("tocofsReturngoodsDetailedEntities:没有对象被插入表头底表"); + } + } catch (Exception e) { + logger.error("线程保存TOC退货明细抛出异常", e); + } + } + }); + thread.start(); + try { + thread.join(); + } catch (Exception e) { + logger.error("线程保存TOC退货明细抛出异常", e); + } + long endTime = System.currentTimeMillis(); + logger.info("插入或更新TOC退货入库表体-耗时:{}", (endTime - startTime)); + } + } + } + + /** + * 查询OFS售后退货入库单 + * + * @param queryOfsSoSaleOutVo 查询参数 + * @param headerDetailsDtoList 查询结果集 + * @param pageNo 从第pageNo页开始查询 + */ +// private void queryOfsReturnGoods(QueryOfsSoSaleOutVo queryOfsSoSaleOutVo, List headerDetailsDtoList, Long pageNo) throws Exception { +// +// Long pageSize = 200L; +// queryOfsSoSaleOutVo.setPageNo(pageNo); +// queryOfsSoSaleOutVo.setPageSize(pageSize); +// +// InterfaceParamDto interfaceParamDto = new InterfaceParamDto(); +// interfaceParamDto.setApi("ofs.receipt.search"); +// interfaceParamDto.setData(JSON.toJSONString(queryOfsSoSaleOutVo)); +// RertunGoodsRootBean rertunGoodsRootBean = (RertunGoodsRootBean) ofsUnifiedService.unified(interfaceParamDto); +// if (rertunGoodsRootBean != null) { +// if ("false".equals(rertunGoodsRootBean.getError()) && "0".equals(rertunGoodsRootBean.getCode()) && "Success".equals(rertunGoodsRootBean.getMsg())) { +// List returnGoodHeaderDetailsDataDtoList = rertunGoodsRootBean.getData(); +// if (returnGoodHeaderDetailsDataDtoList != null && returnGoodHeaderDetailsDataDtoList.size() > 0) { +// headerDetailsDtoList.addAll(returnGoodHeaderDetailsDataDtoList); +// +// //OFS没有提供分页字段,等待开发 +// } +// } else { +// logger.error("查询失败,失败原因:{}", JSON.toJSON(interfaceParamDto)); +// } +// } else { +// logger.error("rertunGoodsRootBean为空!interfaceParamDto对象的结果集json:{}", JSON.toJSON(interfaceParamDto)); +// } +// } + +// public void queryOfsSaleOrder() throws Exception { +// QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo(); +// queryOfsSoSaleOutVo.setCreated_start("2024-07-05 16:38:00"); +// queryOfsSoSaleOutVo.setCreated_end("2024-07-05 16:40:30"); +// queryOfsSoSaleOutVo.setClientCode("LETS"); +//// queryOfsSoSaleOutVo.setInternalInstructionType("SALES"); +// queryOfsSoSaleOutVo.setCompanyCode("SHLZ"); +//// queryOfsSoSaleOutVo.setStatus(900L); +// queryOfsSoSaleOutVo.setPageNo(1L); +// queryOfsSoSaleOutVo.setPageSize(50L); +// queryOfsSoSaleOutVo.setCode("LETS-SH2024070500000003"); +// +// InterfaceParamDto interfaceParamDto = new InterfaceParamDto(); +// interfaceParamDto.setApi("ofs.shipment.search"); +// interfaceParamDto.setData(JSON.toJSONString(queryOfsSoSaleOutVo)); +// SaleOutReturnMessageDto saleOutReturnMessageDto = (SaleOutReturnMessageDto) ofsUnifiedService.unified(interfaceParamDto); +// System.out.println(saleOutReturnMessageDto); +// } + + /** + * 库存同步,代码同步逻辑 + * + * @param returnGoodHeaderDetailsDataDtoList1 查询得到的O售后入库单对象 + * @param pushScenarioType 推送阶段场景 + * @author liuyang + */ + private void implementStock(List returnGoodHeaderDetailsDataDtoList1, String pushScenarioType) throws Exception { + Assert.notNull(pushScenarioType, "pushScenarioType不能为空"); + if (returnGoodHeaderDetailsDataDtoList1 != null) { + logger.info("TOC退货业务:{}行需要进行数据转换", returnGoodHeaderDetailsDataDtoList1.size()); + } + if (returnGoodHeaderDetailsDataDtoList1 != null && returnGoodHeaderDetailsDataDtoList1.size() > 0) { + try { + // 查询基本档案 + String sceneType = "stock"; + List goodsRertunSonDetailsDtos = queryBasicArchivesStock(returnGoodHeaderDetailsDataDtoList1, sceneType); + // 分组汇总 + String dimension = null; +// dimension = "1001&dy-intoyou&B2CHA20240033&6973391733588&SALES&002"; + Map> summaryDimensionMap = groupSummary(goodsRertunSonDetailsDtos, dimension); + // 查询U8C业务流程 + BdBusitypeEntity bdBusitypeEntity = u8cOperationFlow(); + // 查询销售收发类别 +// BdRdclEntity bdRdclEntity = rdclUtil.queryRdClObject("202"); + //初始化所有存货管理档案对应的结存价+采购价 +// List mapList = initAllBalancePricePurchasePrice(); + //查询「平台运费」、「平台优惠」、「支付优惠」、「达人优惠」存货基本档案(注意没有商家优惠) + List bdInvbasdocEntities = queryAdditionUtil.queryStockBasicArchives(); + Map mapBdInvbasdocEntity = bdInvbasdocEntities.stream().collect(Collectors.toMap(BdInvbasdocEntity::getInvcode, entity -> entity)); + String pkInvbasdocStr = bdInvbasdocEntities.stream().map(entity -> "'" + entity.getInvcode() + "'").collect(Collectors.joining(",")); + //查询存货对应的税目 + Map stringBdTaxitemsEntityMap = queryAdditionUtil.queryBatchBdTaxitems(pkInvbasdocStr); + //查询「平台运费」对应的税率 +// BdTaxitemsEntity bdTaxitemsEntity = queryBdTaxitems(bdInvbasdocEntity1.getInvcode()); + //查询「平台运费」、「平台优惠」、「支付优惠」、「达人优惠」所有公司的存货管理档案 + Map stringBdInvmandocEntityMap = queryAdditionUtil.queryInventoryMan(bdInvbasdocEntities); + + if (bdBusitypeEntity != null && summaryDimensionMap != null) { + Iterator>> iterator = summaryDimensionMap.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry> entry = iterator.next(); + String keyGroup = entry.getKey(); + List oldValue = entry.getValue(); + + StockinOrderSearchResponse.StockinOrder.StockinH header = oldValue.get(0).getHeader(); + BdCorpEntity bdCorpEntity = oldValue.get(0).getBdCorpEntity();//表头销售公司 + BdCorpEntity deliverGoodsCorp = oldValue.get(0).getDeliverGoodsCorp();//发货公司 + BdCalbodyEntity bdCalbodyEntity = oldValue.get(0).getBdCalbodyEntity();//发货仓库组织 + BdStordocEntity bdStordocEntity = oldValue.get(0).getBdStordocEntity();//发货仓库 + BdCalbodyEntity bdCalbodyEntity1 = oldValue.get(0).getBdCalbodyEntity1();//收货库存组织 + BdStordocEntity bdStordocEntity1 = oldValue.get(0).getBdStordocEntity1();//收货仓库 + BdSalestruEntity bdSalestruEntity = oldValue.get(0).getBdSalestruEntity();//销售组织 + BdDeptdocEntity bdDeptdocEntity = oldValue.get(0).getBdDeptdocEntity();//业务部门 + BdCumandocEntity bdCumandocEntity = oldValue.get(0).getBdCumandocEntity();//客商管理档案 + BdCubasdocEntity bdCubasdocEntity = oldValue.get(0).getBdCubasdocEntity();//客商基本档案 + BdDefdocEntity platformArchives = oldValue.get(0).getPlatformArchives();//U8C平台档案 + BdDefdocEntity shopArchives = oldValue.get(0).getShopArchives();//U8C店铺档案 + BdRdclEntity bdRdclEntity = oldValue.get(0).getBdRdclEntity();//U8C收发类别 + + try { +// checkArchives(oldValue.get(0)); + //生成业务日期 + String generateBusinessDate = createGenerateBusinessDate(header); + + SaleorderRequestDto saleorderRequestDto = new SaleorderRequestDto(); + SaleorderRequestParentDto saleorderRequestParentDto = new SaleorderRequestParentDto(); + saleorderRequestParentDto.setDbilldate(generateBusinessDate);//单据日期 + saleorderRequestParentDto.setBretinvflag("Y");//退货标记 + saleorderRequestParentDto.setCbiztype(bdBusitypeEntity.getPkBusitype());//业务流程 + saleorderRequestParentDto.setCcalbodyid(bdCalbodyEntity.getPkCalbody());//库存组织 + saleorderRequestParentDto.setCcustomerid(bdCumandocEntity.getPkCumandoc());//客户=开票单位=收货单位=表体收货单位=收货单位 + saleorderRequestParentDto.setCdeptid(bdDeptdocEntity.getPkDeptdoc());//部门 + saleorderRequestParentDto.setCemployeeid(null);//业务员 + saleorderRequestParentDto.setCoperatorid(OverallConstant.getOverAllValue("u8cApiZdrPK"));//制单人 + saleorderRequestParentDto.setCreceiptcorpid(bdCumandocEntity.getPkCumandoc());//开票单位 + saleorderRequestParentDto.setCreceiptcustomerid(bdCumandocEntity.getPkCumandoc());//收货单位 + saleorderRequestParentDto.setCsalecorpid(bdSalestruEntity.getCsalestruid());//销售组织 + saleorderRequestParentDto.setCwarehouseid(bdStordocEntity.getPkStordoc());//仓库 + saleorderRequestParentDto.setDapprovedate(generateBusinessDate);//审核日期 + saleorderRequestParentDto.setNdiscountrate("100.000000");//整单折扣 + saleorderRequestParentDto.setPk_corp(bdCorpEntity.getPkCorp());//公司id + //汇总单号=汇总维度 + saleorderRequestParentDto.setVdef18(keyGroup); + //平台 + saleorderRequestParentDto.setPk_defdoc2(platformArchives.getPkDefdoc()); + saleorderRequestParentDto.setVdef2(platformArchives.getDocname()); + saleorderRequestParentDto.setVdef17(ProfilesActiveConstant.sourceSystem1);//来源系统 + + //收发类别 + saleorderRequestParentDto.setPk_defdoc3(bdRdclEntity.getPkRdcl()); + saleorderRequestParentDto.setVdef3(bdRdclEntity.getRdname()); + + //2024年8月8日 17:17:58 店铺档案自定义项1,先不传,后续维护好之后再传! + //店铺 + saleorderRequestParentDto.setPk_defdoc1(shopArchives.getPkDefdoc()); + saleorderRequestParentDto.setVdef1(shopArchives.getDocname()); + + //单据红字标识 + saleorderRequestParentDto.setPk_defdoc16(OverallConstant.getOverAllValue("u8c自定义项档案-单据红字标识-Y主键")); + saleorderRequestParentDto.setVdef16(OverallConstant.getOverAllValue("u8c自定义项档案-单据红字标识-Y名称")); + + saleorderRequestDto.setParentvo(saleorderRequestParentDto); + + List saleorderRequestChildrenDtoList = new ArrayList<>(); + saleorderRequestDto.setChildrenvo(saleorderRequestChildrenDtoList); + + //验证是否为指定的店铺,如果为true,则取结存价 + Boolean isCheckShopChoose = balanceUnitPriceUtil.checkOfsShop(header.getStoreCode()); + + //把汇总好的出库单明细行合并成一行 + GoodsRertunSonDetailsDto goodsRertunSonDetailsDto = groupMergeDetailedRows(oldValue, isCheckShopChoose); + //存货管理档案:取发货公司的存货管理档案 + BdInvmandocEntity bdInvmandocEntity = oldValue.get(0).getBdInvmandocEntity(); + //存货基础档案 + BdInvbasdocEntity bdInvbasdocEntity = oldValue.get(0).getBdInvbasdocEntity(); + //根据存货基础档案编码,查询当前存货的税率 + BdTaxitemsEntity bdTaxitemsEntity1 = oldValue.get(0).getBdTaxitemsEntity(); + //查询收支项目 +// BdInvclEntity bdInvclEntity = queryU8CEntityUtil.queryBdInvbasdocByBdInvcl(bdInvbasdocEntity); +// BdCostsubjEntity bdCostsubjEntity = queryU8CEntityUtil.queryBdCostsubj(bdInvclEntity); + +// String tax = new BigDecimal(bdTaxitemsEntity1.getTaxratio()).divide(new BigDecimal(100), 20, BigDecimal.ROUND_HALF_UP).setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString(); +// +// BigDecimal noriginalcurprice = null;//无税单价 +// BigDecimal noriginalcurmny = null;//无税金额 +// BigDecimal noriginalcurtaxprice = null;//含税单价 +// BigDecimal noriginalcursummny = null;//价税合计 +// BigDecimal noriginalcurtaxmny = null;//税额=价税合计-无税金额 +// try { +// noriginalcurtaxprice = goodsRertunSonDetailsDto.getGroupTotalPayAmount().divide(goodsRertunSonDetailsDto.getGroupShipQty(), 20, BigDecimal.ROUND_HALF_UP).setScale(4, BigDecimal.ROUND_HALF_UP); +// noriginalcurprice = noriginalcurtaxprice.divide(new BigDecimal(1).add(new BigDecimal(tax)), 20, BigDecimal.ROUND_HALF_UP).setScale(4, BigDecimal.ROUND_HALF_UP); +// noriginalcurmny = noriginalcurprice.multiply(goodsRertunSonDetailsDto.getGroupShipQty()).setScale(2, BigDecimal.ROUND_HALF_UP); +// noriginalcursummny = noriginalcurtaxprice.multiply(goodsRertunSonDetailsDto.getGroupShipQty()).setScale(2, BigDecimal.ROUND_HALF_UP); +// noriginalcurtaxmny = noriginalcursummny.subtract(noriginalcurmny).setScale(2, BigDecimal.ROUND_HALF_UP); +// } catch (Exception e) { +// logger.error("TOC金额计算错误", e); +// Assert.state(false, "U8C红字销售订单,金额计算错误,原因:{}", e.getMessage()); +// } + + //判断是否为赠品 + Boolean isblargessflag = false; + if ("0".equals(goodsRertunSonDetailsDto.getGroupTotalPayAmount().setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString())) { + isblargessflag = true; + } + + SaleorderRequestChildrenDto saleorderRequestChildrenDto = new SaleorderRequestChildrenDto(); + saleorderRequestChildrenDto.setBlargessflag(isblargessflag);//是否赠品 + saleorderRequestChildrenDto.setCadvisecalbodyid(bdCalbodyEntity.getPkCalbody());//发货库存组织 + saleorderRequestChildrenDto.setCbodywarehouseid(bdStordocEntity.getPkStordoc());//发货仓库 + saleorderRequestChildrenDto.setCconsigncorpid(deliverGoodsCorp.getPkCorp());//发货公司 + saleorderRequestChildrenDto.setCcurrencytypeid("00010000000000000001");//币种 + saleorderRequestChildrenDto.setCinventoryid(bdInvmandocEntity.getPkInvmandoc());//存货id + saleorderRequestChildrenDto.setCreceiptcorpid(bdCumandocEntity.getPkCumandoc());//收货单位 + saleorderRequestChildrenDto.setDconsigndate(generateBusinessDate);//计划发货日期 + saleorderRequestChildrenDto.setDdeliverdate(generateBusinessDate);// 要求收货日期 + saleorderRequestChildrenDto.setNexchangeotobrate("1.00000000");//折本汇率 + saleorderRequestChildrenDto.setNitemdiscountrate("100.000000");//单品折扣 + saleorderRequestChildrenDto.setNnumber("-" + goodsRertunSonDetailsDto.getGroupShipQty().stripTrailingZeros().toPlainString());//数量 + saleorderRequestChildrenDto.setNoriginalcurdiscountmny("0");//折扣额 +// saleorderRequestChildrenDto.setNoriginalcurmny("-" + noriginalcurmny.stripTrailingZeros().toPlainString());//无税金额 +// saleorderRequestChildrenDto.setNoriginalcurnetprice(noriginalcurprice.stripTrailingZeros().toPlainString());//无税净价 +// saleorderRequestChildrenDto.setNoriginalcurprice(noriginalcurprice.stripTrailingZeros().toPlainString());//无税单价 +// saleorderRequestChildrenDto.setNoriginalcursummny("-" + noriginalcursummny.stripTrailingZeros().toPlainString());//价税合计 + saleorderRequestChildrenDto.setNoriginalcursummny("-" + goodsRertunSonDetailsDto.getGroupTotalPayAmount().setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString());//价税合计 新逻辑 +// saleorderRequestChildrenDto.setNoriginalcurtaxmny("-" + noriginalcurtaxmny.stripTrailingZeros().toPlainString());//税额 +// saleorderRequestChildrenDto.setNoriginalcurtaxnetprice(noriginalcurtaxprice.stripTrailingZeros().toPlainString());//含税净价 +// saleorderRequestChildrenDto.setNoriginalcurtaxprice(noriginalcurtaxprice.stripTrailingZeros().toPlainString());//含税单价 +// saleorderRequestChildrenDto.setNtaxrate(new BigDecimal(bdTaxitemsEntity1.getTaxratio()).stripTrailingZeros().toPlainString());//税率 +// saleorderRequestChildrenDto.setVdef2(bdCostsubjEntity.getCostname());//收支项目 +// saleorderRequestChildrenDto.setPk_defdoc2(bdCostsubjEntity.getPkCostsubj()); + //如果优惠金额为0,则传0 + if (!"0".equals(goodsRertunSonDetailsDto.getVdef4().stripTrailingZeros().toPlainString())) { + saleorderRequestChildrenDto.setVdef4("-" + goodsRertunSonDetailsDto.getVdef4().stripTrailingZeros().toPlainString()); + } else { + saleorderRequestChildrenDto.setVdef4("0"); + } + if (!"0".equals(goodsRertunSonDetailsDto.getVdef5().stripTrailingZeros().toPlainString())) { + saleorderRequestChildrenDto.setVdef5("-" + goodsRertunSonDetailsDto.getVdef5().stripTrailingZeros().toPlainString()); + } else { + saleorderRequestChildrenDto.setVdef5("0"); + } + if (!"0".equals(goodsRertunSonDetailsDto.getVdef6().stripTrailingZeros().toPlainString())) { + saleorderRequestChildrenDto.setVdef6("-" + goodsRertunSonDetailsDto.getVdef6().stripTrailingZeros().toPlainString()); + } else { + saleorderRequestChildrenDto.setVdef6("0"); + } + if (!"0".equals(goodsRertunSonDetailsDto.getVdef7().stripTrailingZeros().toPlainString())) { + saleorderRequestChildrenDto.setVdef7("-" + goodsRertunSonDetailsDto.getVdef7().stripTrailingZeros().toPlainString()); + } else { + saleorderRequestChildrenDto.setVdef7("0"); + } + saleorderRequestChildrenDtoList.add(saleorderRequestChildrenDto); + + //平台优惠 + if (goodsRertunSonDetailsDto.getVdef4() != null) { + BigDecimal vdef4 = goodsRertunSonDetailsDto.getVdef4(); + if (vdef4.compareTo(BigDecimal.ZERO) > 0) { + //发货运费-存货基本档案 + BdInvbasdocEntity bdInvbasdocEntity1 = mapBdInvbasdocEntity.get("FY01"); + //存货管理档案 + BdInvmandocEntity bdInvmandocEntity1 = stringBdInvmandocEntityMap.get(bdInvbasdocEntity1.getInvcode() + deliverGoodsCorp.getPkCorp()); + //存货对应的税率 + BdTaxitemsEntity bdTaxitemsEntity = stringBdTaxitemsEntityMap.get("FY01"); + //补充:平台优惠-存货 + BigDecimal absAccumulatedPostage = vdef4.abs(); + BigDecimal negativeValue = absAccumulatedPostage.negate(); + queryAdditionUtil.additional(saleorderRequestChildrenDtoList, bdInvmandocEntity1, bdInvbasdocEntity1, negativeValue, "-1", bdTaxitemsEntity); + } + } + //达人优惠 + if (goodsRertunSonDetailsDto.getVdef6() != null) { + BigDecimal vdef6 = goodsRertunSonDetailsDto.getVdef6(); + if (vdef6.compareTo(BigDecimal.ZERO) > 0) { + //发货运费-存货基本档案 + BdInvbasdocEntity bdInvbasdocEntity1 = mapBdInvbasdocEntity.get("FY02"); + //存货管理档案 + BdInvmandocEntity bdInvmandocEntity1 = stringBdInvmandocEntityMap.get(bdInvbasdocEntity1.getInvcode() + deliverGoodsCorp.getPkCorp()); + //存货对应的税率 + BdTaxitemsEntity bdTaxitemsEntity = stringBdTaxitemsEntityMap.get("FY02"); + //补充:达人优惠-存货 + BigDecimal absAccumulatedPostage = vdef6.abs(); + BigDecimal negativeValue = absAccumulatedPostage.negate(); + queryAdditionUtil.additional(saleorderRequestChildrenDtoList, bdInvmandocEntity1, bdInvbasdocEntity1, negativeValue, "-1", bdTaxitemsEntity); + } + } + //支付优惠 + if (goodsRertunSonDetailsDto.getVdef5() != null) { + BigDecimal vdef5 = goodsRertunSonDetailsDto.getVdef5(); + if (vdef5.compareTo(BigDecimal.ZERO) > 0) { + //发货运费-存货基本档案 + BdInvbasdocEntity bdInvbasdocEntity1 = mapBdInvbasdocEntity.get("FY04"); + //存货管理档案 + BdInvmandocEntity bdInvmandocEntity1 = stringBdInvmandocEntityMap.get(bdInvbasdocEntity1.getInvcode() + deliverGoodsCorp.getPkCorp()); + //存货对应的税率 + BdTaxitemsEntity bdTaxitemsEntity = stringBdTaxitemsEntityMap.get("FY04"); + //补充:支付优惠-存货 + BigDecimal absAccumulatedPostage = vdef5.abs(); + BigDecimal negativeValue = absAccumulatedPostage.negate(); + queryAdditionUtil.additional(saleorderRequestChildrenDtoList, bdInvmandocEntity1, bdInvbasdocEntity1, negativeValue, "-1", bdTaxitemsEntity); + } + } + if (ProfilesActiveConstant.PUSH_SCENE_TYPE_1.equals(pushScenarioType) || ProfilesActiveConstant.PUSH_SCENE_TYPE_2.equals(pushScenarioType)) { + //推送u8c + List saleorderRequestDtoList = new ArrayList<>(); + saleorderRequestDtoList.add(saleorderRequestDto); + Map> stringStringMap = new HashMap<>(); + stringStringMap.put("saleorder", saleorderRequestDtoList); + SoSaleResultRootDto soSaleResultRootDto = sendU8CTOCOrder(JSON.toJSONString(stringStringMap)); + String vreceiptcode = null; + String pk_corp = null; + String csaleid = null; + if (soSaleResultRootDto != null && soSaleResultRootDto.getParentvo() != null) { + vreceiptcode = soSaleResultRootDto.getParentvo().getVreceiptcode(); + pk_corp = soSaleResultRootDto.getParentvo().getPk_corp(); + csaleid = soSaleResultRootDto.getParentvo().getCsaleid(); + } + logger.info("TOC销售订单编号:{} 主键:{} 销售公司:{}", vreceiptcode, csaleid, pk_corp); + updateSuccessOrFail1(oldValue, "Y", "success", vreceiptcode, csaleid); + } else if (ProfilesActiveConstant.PUSH_SCENE_TYPE_0.equals(pushScenarioType)) { + //选择暂存等待下次发起 + String vreceiptcode = "暂存"; + String csaleid = "暂存"; + String newstate = "S"; + String newTransmitInfo = "暂存"; + updateSuccessOrFail1(oldValue, newstate, newTransmitInfo, vreceiptcode, csaleid); + } else { + Assert.state(false, "未知的场景类型 pushScenarioType={}", pushScenarioType); + } + } catch (Exception e) { + //记录失败 + logger.error("TOC退货业务转换成U8C对象过程中、或者单据推送到U8C出现异常!", e); + String message = e.getMessage(); + if (message == null) { + message = "未知错误"; + } + updateSuccessOrFail1(oldValue, "N", message, null, null); + } + } + } else { + //2024年8月6日 11:28:54此处不记录失败,不认为是错误 + logger.info("summaryDimensionMap变量或者bdBusitypeEntity变量为空,因此主要的推送逻辑不会被执行!"); + } + } catch (Exception e) { + logger.error("外层转换逻辑抛出异常", e); + } + } + } + + /** + * 到账成功:代码同步逻辑 + * + * @param returnGoodHeaderDetailsDataDtoList1 查询得到的O售后入库单对象 + * @author liuyang + */ + private void implementTran(List returnGoodHeaderDetailsDataDtoList1, String pushScenarioType) throws Exception { + Assert.notNull(pushScenarioType, "pushScenarioType不能为空"); + if (returnGoodHeaderDetailsDataDtoList1 != null && returnGoodHeaderDetailsDataDtoList1.size() > 0) { + logger.info("TOC退货业务:{}行需要进行数据转换", returnGoodHeaderDetailsDataDtoList1.size()); + + try { + // 查询基本档案 + String sceneType = "tran"; + List goodsRertunSonDetailsDtos = queryBasicArchivesStock(returnGoodHeaderDetailsDataDtoList1, sceneType); + // 分组汇总 + String dimension = null; + Map> summaryDimensionMap = groupSummary(goodsRertunSonDetailsDtos, dimension); + // 查询U8C业务流程 + BdBusitypeEntity bdBusitypeEntity = u8cOperationFlowV2(); + //初始化所有存货管理档案对应的结存价+采购价 +// List mapList = initAllBalancePricePurchasePrice(); + //查询「平台运费」、「平台优惠」、「支付优惠」、「达人优惠」存货基本档案(注意没有商家优惠) + List bdInvbasdocEntities = queryAdditionUtil.queryStockBasicArchives(); + Map mapBdInvbasdocEntity = bdInvbasdocEntities.stream().collect(Collectors.toMap(BdInvbasdocEntity::getInvcode, entity -> entity)); + String pkInvbasdocStr = bdInvbasdocEntities.stream().map(entity -> "'" + entity.getInvcode() + "'").collect(Collectors.joining(",")); + //查询存货对应的税目 + Map stringBdTaxitemsEntityMap = queryAdditionUtil.queryBatchBdTaxitems(pkInvbasdocStr); + //查询「平台运费」对应的税率 +// BdTaxitemsEntity bdTaxitemsEntity = queryBdTaxitems(bdInvbasdocEntity1.getInvcode()); + //查询「平台运费」、「平台优惠」、「支付优惠」、「达人优惠」所有公司的存货管理档案 + Map stringBdInvmandocEntityMap = queryAdditionUtil.queryInventoryMan(bdInvbasdocEntities); + + if (bdBusitypeEntity != null && summaryDimensionMap != null) { + Iterator>> iterator = summaryDimensionMap.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry> entry = iterator.next(); + String keyGroup = entry.getKey(); + List oldValue = entry.getValue(); + + StockinOrderSearchResponse.StockinOrder.StockinH header = oldValue.get(0).getHeader(); + BdCorpEntity bdCorpEntity = oldValue.get(0).getBdCorpEntity();//表头销售公司 + BdCorpEntity deliverGoodsCorp = oldValue.get(0).getDeliverGoodsCorp();//发货公司 + BdCalbodyEntity bdCalbodyEntity = oldValue.get(0).getBdCalbodyEntity();//发货仓库组织 + BdStordocEntity bdStordocEntity = oldValue.get(0).getBdStordocEntity();//发货仓库 + BdCalbodyEntity bdCalbodyEntity1 = oldValue.get(0).getBdCalbodyEntity1();//收货库存组织 + BdStordocEntity bdStordocEntity1 = oldValue.get(0).getBdStordocEntity1();//收货仓库 + BdSalestruEntity bdSalestruEntity = oldValue.get(0).getBdSalestruEntity();//销售组织 + BdDeptdocEntity bdDeptdocEntity = oldValue.get(0).getBdDeptdocEntity();//业务部门 + BdCumandocEntity bdCumandocEntity = oldValue.get(0).getBdCumandocEntity();//客商管理档案 + BdCubasdocEntity bdCubasdocEntity = oldValue.get(0).getBdCubasdocEntity();//客商基本档案 + BdDefdocEntity platformArchives = oldValue.get(0).getPlatformArchives();//U8C平台档案 + BdDefdocEntity shopArchives = oldValue.get(0).getShopArchives();//U8C店铺档案 + BdRdclEntity bdRdclEntity = oldValue.get(0).getBdRdclEntity();//U8C收发类别 + + try { +// checkArchives(oldValue.get(0)); + //生成业务日期 + String generateBusinessDate = createSuccessFulTradeDate(header); + + SaleorderRequestDto saleorderRequestDto = new SaleorderRequestDto(); + SaleorderRequestParentDto saleorderRequestParentDto = new SaleorderRequestParentDto(); + saleorderRequestParentDto.setDbilldate(generateBusinessDate);//单据日期 + saleorderRequestParentDto.setBretinvflag("Y");//退货标记 + saleorderRequestParentDto.setCbiztype(bdBusitypeEntity.getPkBusitype());//业务流程 + saleorderRequestParentDto.setCcalbodyid(bdCalbodyEntity.getPkCalbody());//库存组织 + saleorderRequestParentDto.setCcustomerid(bdCumandocEntity.getPkCumandoc());//客户=开票单位=收货单位=表体收货单位=收货单位 + saleorderRequestParentDto.setCdeptid(bdDeptdocEntity.getPkDeptdoc());//部门 + saleorderRequestParentDto.setCemployeeid(null);//业务员 + saleorderRequestParentDto.setCoperatorid(OverallConstant.getOverAllValue("u8cApiZdrPK"));//制单人 + saleorderRequestParentDto.setCreceiptcorpid(bdCumandocEntity.getPkCumandoc());//开票单位 + saleorderRequestParentDto.setCreceiptcustomerid(bdCumandocEntity.getPkCumandoc());//收货单位 + saleorderRequestParentDto.setCsalecorpid(bdSalestruEntity.getCsalestruid());//销售组织 + saleorderRequestParentDto.setCwarehouseid(bdStordocEntity.getPkStordoc());//仓库 + saleorderRequestParentDto.setDapprovedate(generateBusinessDate);//审核日期 + saleorderRequestParentDto.setNdiscountrate("100.000000");//整单折扣 + saleorderRequestParentDto.setPk_corp(bdCorpEntity.getPkCorp());//公司id + //汇总单号=汇总维度 + saleorderRequestParentDto.setVdef18(keyGroup); + //平台 + saleorderRequestParentDto.setPk_defdoc2(platformArchives.getPkDefdoc()); + saleorderRequestParentDto.setVdef2(platformArchives.getDocname()); + saleorderRequestParentDto.setVdef17(ProfilesActiveConstant.sourceSystem1);//来源系统 + + //收发类别 + saleorderRequestParentDto.setPk_defdoc3(bdRdclEntity.getPkRdcl()); + saleorderRequestParentDto.setVdef3(bdRdclEntity.getRdname()); + + //2024年8月8日 17:17:58 店铺档案自定义项1,先不传,后续维护好之后再传! + //店铺 + saleorderRequestParentDto.setPk_defdoc1(shopArchives.getPkDefdoc()); + saleorderRequestParentDto.setVdef1(shopArchives.getDocname()); + + //单据红字标识 + saleorderRequestParentDto.setPk_defdoc16(OverallConstant.getOverAllValue("u8c自定义项档案-单据红字标识-Y主键")); + saleorderRequestParentDto.setVdef16(OverallConstant.getOverAllValue("u8c自定义项档案-单据红字标识-Y名称")); + + saleorderRequestDto.setParentvo(saleorderRequestParentDto); + + List saleorderRequestChildrenDtoList = new ArrayList<>(); + saleorderRequestDto.setChildrenvo(saleorderRequestChildrenDtoList); + + //验证是否为指定的店铺,如果为true,则取结存价 + Boolean isCheckShopChoose = balanceUnitPriceUtil.checkOfsShop(header.getStoreCode()); + //把汇总好的出库单明细行合并成一行 + GoodsRertunSonDetailsDto goodsRertunSonDetailsDto = groupMergeDetailedRows(oldValue, isCheckShopChoose); + + //存货管理档案:取发货公司的存货管理档案 + BdInvmandocEntity bdInvmandocEntity = oldValue.get(0).getBdInvmandocEntity(); + //存货基础档案 + BdInvbasdocEntity bdInvbasdocEntity = oldValue.get(0).getBdInvbasdocEntity(); + //根据存货基础档案编码,查询当前存货的税率 + BdTaxitemsEntity bdTaxitemsEntity1 = oldValue.get(0).getBdTaxitemsEntity(); + //查询收支项目 +// BdInvclEntity bdInvclEntity = queryU8CEntityUtil.queryBdInvbasdocByBdInvcl(bdInvbasdocEntity); +// BdCostsubjEntity bdCostsubjEntity = queryU8CEntityUtil.queryBdCostsubj(bdInvclEntity); + +// String tax = new BigDecimal(bdTaxitemsEntity1.getTaxratio()).divide(new BigDecimal(100), 20, BigDecimal.ROUND_HALF_UP).setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString(); +// +// BigDecimal noriginalcurprice = null;//无税单价 +// BigDecimal noriginalcurmny = null;//无税金额 +// BigDecimal noriginalcurtaxprice = null;//含税单价 +// BigDecimal noriginalcursummny = null;//价税合计 +// BigDecimal noriginalcurtaxmny = null;//税额=价税合计-无税金额 +// try { +// noriginalcurtaxprice = goodsRertunSonDetailsDto.getGroupTotalPayAmount().divide(goodsRertunSonDetailsDto.getGroupShipQty(), 20, BigDecimal.ROUND_HALF_UP).setScale(4, BigDecimal.ROUND_HALF_UP); +// noriginalcurprice = noriginalcurtaxprice.divide(new BigDecimal(1).add(new BigDecimal(tax)), 20, BigDecimal.ROUND_HALF_UP).setScale(4, BigDecimal.ROUND_HALF_UP); +// noriginalcurmny = noriginalcurprice.multiply(goodsRertunSonDetailsDto.getGroupShipQty()).setScale(2, BigDecimal.ROUND_HALF_UP); +// noriginalcursummny = noriginalcurtaxprice.multiply(goodsRertunSonDetailsDto.getGroupShipQty()).setScale(2, BigDecimal.ROUND_HALF_UP); +// noriginalcurtaxmny = noriginalcursummny.subtract(noriginalcurmny).setScale(2, BigDecimal.ROUND_HALF_UP); +// } catch (Exception e) { +// logger.error("TOC退货-确认收入,金额计算错误", e); +// Assert.state(false, "U8C红字销售订单,金额计算错误,原因:{}", e.getMessage()); +// } + + //判断是否为赠品 + Boolean isblargessflag = false; + if ("0".equals(goodsRertunSonDetailsDto.getGroupTotalPayAmount().setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString())) { + isblargessflag = true; + } + + SaleorderRequestChildrenDto saleorderRequestChildrenDto = new SaleorderRequestChildrenDto(); + saleorderRequestChildrenDto.setBlargessflag(isblargessflag);//是否赠品 + saleorderRequestChildrenDto.setCadvisecalbodyid(bdCalbodyEntity.getPkCalbody());//发货库存组织 + saleorderRequestChildrenDto.setCbodywarehouseid(bdStordocEntity.getPkStordoc());//发货仓库 + saleorderRequestChildrenDto.setCconsigncorpid(deliverGoodsCorp.getPkCorp());//发货公司 + saleorderRequestChildrenDto.setCcurrencytypeid("00010000000000000001");//币种 + saleorderRequestChildrenDto.setCinventoryid(bdInvmandocEntity.getPkInvmandoc());//存货id + saleorderRequestChildrenDto.setCreceiptcorpid(bdCumandocEntity.getPkCumandoc());//收货单位 + saleorderRequestChildrenDto.setDconsigndate(generateBusinessDate);//计划发货日期 + saleorderRequestChildrenDto.setDdeliverdate(generateBusinessDate);// 要求收货日期 + saleorderRequestChildrenDto.setNexchangeotobrate("1.00000000");//折本汇率 + saleorderRequestChildrenDto.setNitemdiscountrate("100.000000");//单品折扣 + saleorderRequestChildrenDto.setNnumber("-" + goodsRertunSonDetailsDto.getGroupShipQty().stripTrailingZeros().toPlainString());//数量 + saleorderRequestChildrenDto.setNoriginalcurdiscountmny("0");//折扣额 +// saleorderRequestChildrenDto.setNoriginalcurmny("-" + noriginalcurmny.stripTrailingZeros().toPlainString());//无税金额 +// saleorderRequestChildrenDto.setNoriginalcurnetprice(noriginalcurprice.stripTrailingZeros().toPlainString());//无税净价 +// saleorderRequestChildrenDto.setNoriginalcurprice(noriginalcurprice.stripTrailingZeros().toPlainString());//无税单价 +// saleorderRequestChildrenDto.setNoriginalcursummny("-" + noriginalcursummny.stripTrailingZeros().toPlainString());//价税合计 + saleorderRequestChildrenDto.setNoriginalcursummny("-" + goodsRertunSonDetailsDto.getGroupTotalPayAmount().setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString());//价税合计 新逻辑 +// saleorderRequestChildrenDto.setNoriginalcurtaxmny("-" + noriginalcurtaxmny.stripTrailingZeros().toPlainString());//税额 +// saleorderRequestChildrenDto.setNoriginalcurtaxnetprice(noriginalcurtaxprice.stripTrailingZeros().toPlainString());//含税净价 +// saleorderRequestChildrenDto.setNoriginalcurtaxprice(noriginalcurtaxprice.stripTrailingZeros().toPlainString());//含税单价 +// saleorderRequestChildrenDto.setNtaxrate(new BigDecimal(bdTaxitemsEntity1.getTaxratio()).stripTrailingZeros().toPlainString());//税率 +// saleorderRequestChildrenDto.setVdef2(bdCostsubjEntity.getCostname());//收支项目 +// saleorderRequestChildrenDto.setPk_defdoc2(bdCostsubjEntity.getPkCostsubj()); + //如果优惠金额为0,则传0 + if (!"0".equals(goodsRertunSonDetailsDto.getVdef4().stripTrailingZeros().toPlainString())) { + saleorderRequestChildrenDto.setVdef4("-" + goodsRertunSonDetailsDto.getVdef4().stripTrailingZeros().toPlainString()); + } else { + saleorderRequestChildrenDto.setVdef4("0"); + } + if (!"0".equals(goodsRertunSonDetailsDto.getVdef5().stripTrailingZeros().toPlainString())) { + saleorderRequestChildrenDto.setVdef5("-" + goodsRertunSonDetailsDto.getVdef5().stripTrailingZeros().toPlainString()); + } else { + saleorderRequestChildrenDto.setVdef5("0"); + } + if (!"0".equals(goodsRertunSonDetailsDto.getVdef6().stripTrailingZeros().toPlainString())) { + saleorderRequestChildrenDto.setVdef6("-" + goodsRertunSonDetailsDto.getVdef6().stripTrailingZeros().toPlainString()); + } else { + saleorderRequestChildrenDto.setVdef6("0"); + } + if (!"0".equals(goodsRertunSonDetailsDto.getVdef7().stripTrailingZeros().toPlainString())) { + saleorderRequestChildrenDto.setVdef7("-" + goodsRertunSonDetailsDto.getVdef7().stripTrailingZeros().toPlainString()); + } else { + saleorderRequestChildrenDto.setVdef7("0"); + } + saleorderRequestChildrenDtoList.add(saleorderRequestChildrenDto); + + //退货没有邮费金额,已经向万万确认 + //平台优惠 + if (goodsRertunSonDetailsDto.getVdef4() != null) { + BigDecimal vdef4 = goodsRertunSonDetailsDto.getVdef4(); + if (vdef4.compareTo(BigDecimal.ZERO) > 0) { + //发货运费-存货基本档案 + BdInvbasdocEntity bdInvbasdocEntity1 = mapBdInvbasdocEntity.get("FY01"); + //存货管理档案 + BdInvmandocEntity bdInvmandocEntity1 = stringBdInvmandocEntityMap.get(bdInvbasdocEntity1.getInvcode() + deliverGoodsCorp.getPkCorp()); + //存货对应的税率 + BdTaxitemsEntity bdTaxitemsEntity = stringBdTaxitemsEntityMap.get("FY01"); + //补充:平台优惠-存货 + BigDecimal absAccumulatedPostage = vdef4.abs(); + BigDecimal negativeValue = absAccumulatedPostage.negate(); + queryAdditionUtil.additional(saleorderRequestChildrenDtoList, bdInvmandocEntity1, bdInvbasdocEntity1, negativeValue, "-1", bdTaxitemsEntity); + } + } + //达人优惠 + if (goodsRertunSonDetailsDto.getVdef6() != null) { + BigDecimal vdef6 = goodsRertunSonDetailsDto.getVdef6(); + if (vdef6.compareTo(BigDecimal.ZERO) > 0) { + //发货运费-存货基本档案 + BdInvbasdocEntity bdInvbasdocEntity1 = mapBdInvbasdocEntity.get("FY02"); + //存货管理档案 + BdInvmandocEntity bdInvmandocEntity1 = stringBdInvmandocEntityMap.get(bdInvbasdocEntity1.getInvcode() + deliverGoodsCorp.getPkCorp()); + //存货对应的税率 + BdTaxitemsEntity bdTaxitemsEntity = stringBdTaxitemsEntityMap.get("FY02"); + //补充:达人优惠-存货 + BigDecimal absAccumulatedPostage = vdef6.abs(); + BigDecimal negativeValue = absAccumulatedPostage.negate(); + queryAdditionUtil.additional(saleorderRequestChildrenDtoList, bdInvmandocEntity1, bdInvbasdocEntity1, negativeValue, "-1", bdTaxitemsEntity); + } + } + //支付优惠 + if (goodsRertunSonDetailsDto.getVdef5() != null) { + BigDecimal vdef5 = goodsRertunSonDetailsDto.getVdef5(); + if (vdef5.compareTo(BigDecimal.ZERO) > 0) { + //发货运费-存货基本档案 + BdInvbasdocEntity bdInvbasdocEntity1 = mapBdInvbasdocEntity.get("FY04"); + //存货管理档案 + BdInvmandocEntity bdInvmandocEntity1 = stringBdInvmandocEntityMap.get(bdInvbasdocEntity1.getInvcode() + deliverGoodsCorp.getPkCorp()); + //存货对应的税率 + BdTaxitemsEntity bdTaxitemsEntity = stringBdTaxitemsEntityMap.get("FY04"); + //补充:支付优惠-存货 + BigDecimal absAccumulatedPostage = vdef5.abs(); + BigDecimal negativeValue = absAccumulatedPostage.negate(); + queryAdditionUtil.additional(saleorderRequestChildrenDtoList, bdInvmandocEntity1, bdInvbasdocEntity1, negativeValue, "-1", bdTaxitemsEntity); + } + } + + if (ProfilesActiveConstant.PUSH_SCENE_TYPE_1.equals(pushScenarioType) || ProfilesActiveConstant.PUSH_SCENE_TYPE_2.equals(pushScenarioType)) { + //推送U8C + List saleorderRequestDtoList = new ArrayList<>(); + saleorderRequestDtoList.add(saleorderRequestDto); + Map> stringStringMap = new HashMap<>(); + stringStringMap.put("saleorder", saleorderRequestDtoList); + SoSaleResultRootDto soSaleResultRootDto = sendU8CTOCOrder(JSON.toJSONString(stringStringMap)); + String vreceiptcode = null; + String pk_corp = null; + String csaleid = null; + if (soSaleResultRootDto != null && soSaleResultRootDto.getParentvo() != null) { + vreceiptcode = soSaleResultRootDto.getParentvo().getVreceiptcode(); + pk_corp = soSaleResultRootDto.getParentvo().getPk_corp(); + csaleid = soSaleResultRootDto.getParentvo().getCsaleid(); + } + logger.info("TOC销售订单编号:{} 销售订单主键:{} 销售公司:{}", vreceiptcode, csaleid, pk_corp); + updateSuccessOrFail2(oldValue, "Y", "success", vreceiptcode, csaleid); + } else if (ProfilesActiveConstant.PUSH_SCENE_TYPE_0.equals(pushScenarioType)) { + //不推送U8C,单据暂存 + String vreceiptcode = "暂存"; + String csaleid = "暂存"; + String newstate = "S"; + String newTransmitInfo = "暂存"; + updateSuccessOrFail2(oldValue, newstate, newTransmitInfo, vreceiptcode, csaleid); + } else { + Assert.state(false, "未知的场景类型 pushScenarioType={}", pushScenarioType); + } + } catch (Exception e) { + logger.error("TOC退货业务转换成U8C对象过程中、或者单据推送到U8C出现异常!", e); + //记录失败 + String message = e.getMessage(); + if (message == null) { + message = "未知错误"; + } + updateSuccessOrFail2(oldValue, "N", message, null, null); + } + } + } else { + //2024年8月6日 11:28:54此处不记录失败,不认为是错误 + logger.info("summaryDimensionMap变量或者bdBusitypeEntity变量为空,因此主要的推送逻辑不会被执行!"); + } + } catch (Exception e) { + logger.error("外层转换逻辑抛出异常", e); + } + } + } + + /** + * 2024年8月9日 15:43:13 + * 生成业务日期:取「入库时间」、还是取「结束收货时间」 + * + * @author liuyang + */ + private String createGenerateBusinessDate(StockinOrderSearchResponse.StockinOrder.StockinH header) { + //测试 +// header.setClosedAt("2024-11-29 10:00:12"); + String code = null; + if (header != null && header.getCode() != null) { + code = header.getCode(); + } + if (header != null && header.getClosedAt() != null) { + //TOC以出库日期作为业务日期 + String closedAt = header.getClosedAt(); + String businessFormat = null; + try { + Date dbill = DateUtil.parse(closedAt); + businessFormat = DateUtil.format(dbill, "yyyy-MM-dd"); + } catch (Exception e) { + logger.error("业务日期生成失败closedAt(O关单时间)解析异常:{} O售后入库单号:{}", e.getMessage(), code); + Assert.state(false, "业务日期生成失败closedAt(O关单时间)解析异常:{} O售后入库单号:{}", e.getMessage(), code); + } + return businessFormat; + } else { + logger.error("业务日期生成失败closedAt(O关单时间)不能为空 O售后入库单号:{}", code); + Assert.state(false, "业务日期生成失败closedAt(O关单时间)不能为空 O售后入库单号:{}", code); + return null; + } + } + + /** + * 2024年8月28日 17:17:33 + * 生成业务日期,以交易成功时间作为业务日期 + * + * @author liuyang + */ + private String createSuccessFulTradeDate(StockinOrderSearchResponse.StockinOrder.StockinH stockinH) { + String code = null; + if (stockinH != null && stockinH.getCode() != null) { + code = stockinH.getCode(); + } + if (stockinH != null && stockinH.getRefundedAt() != null) { + String refundedAt = stockinH.getRefundedAt(); + + String businessFormat = null; + try { + //2025年1月22日 17:44:55 先暂时还是使用旧逻辑 + Date dbill = DateUtil.parse(refundedAt); +// Date dbill = DateUtil.parse(timeJudgment(stockinH)); + businessFormat = DateUtil.format(dbill, "yyyy-MM-dd"); + } catch (Exception e) { + logger.error("业务日期生成失败refundedAt(O退款完成时间)解析异常:{} O售后入库单编码:{}", e.getMessage(), code); + Assert.state(false, "业务日期生成失败refundedAt(O退款完成时间)解析异常:{} O售后入库单编码:{}", e.getMessage(), code); + } + return businessFormat; + } else { + logger.error("业务日期生成失败refundedAt(O退款完成时间)不能为空! O售后入库单编码:{}", code); + Assert.state(false, "业务日期生成失败refundedAt(O退款完成时间)不能为空! O售后入库单编码:{}", code); + return null; + } + } + + /** + * 先退款后退货场景时间判断 + */ + public String timeJudgment(StockinOrderSearchResponse.StockinOrder.StockinH stockinH) throws Exception { + Assert.notNull(stockinH, "stockinH不能为空!"); + Assert.notNull(stockinH.getRefundedAt(), "退款完成时间不能为空 O售后入库单号:{}", stockinH.getCode()); + Assert.notNull(stockinH.getClosedAt(), "入库完成时间(关单时间)不能为空 O售后入库单号:{}", stockinH.getCode()); + //退款完成时间 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date refundedAtDate = sdf.parse(stockinH.getRefundedAt()); + + //入库完成时间 + SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date closedAtDate = sdf2.parse(stockinH.getClosedAt()); + + if (refundedAtDate.before(closedAtDate)) { + logger.info("O售后入库单:{} 入库时间:{} 退款完成时间:{} 「先退款」后退货", stockinH.getCode(), stockinH.getClosedAt(), stockinH.getRefundedAt()); + return stockinH.getClosedAt(); + } else { + logger.info("O售后入库单:{} 入库时间:{} 退款完成时间:{} 「先退货」后退款", stockinH.getCode(), stockinH.getClosedAt(), stockinH.getRefundedAt()); + return stockinH.getRefundedAt(); + } + } + + /** + * 档案转换(OFS->U8C) + * + * @param returnGoodHeaderDetailsDataDtoList1 OFS售后入库单对象 + * @author liuyang + */ + private List queryBasicArchivesStock(List returnGoodHeaderDetailsDataDtoList1, String sceneType) { + Assert.notNull(returnGoodHeaderDetailsDataDtoList1, "returnGoodHeaderDetailsDataDtoList1不能为空"); + Assert.notNull(sceneType, "sceneType不能为空"); + + List sonDetailsDtoList = new ArrayList<>(); + List errorHeaderDetailsDtoDtoList = new ArrayList<>(); + + if (returnGoodHeaderDetailsDataDtoList1 != null && returnGoodHeaderDetailsDataDtoList1.size() > 0) { + try { + //初始化档案缓存 + CacheTocMapVoV2 cacheTocMapVoV2 = tocReturnBasicArchivesCacheUtil.initCache(returnGoodHeaderDetailsDataDtoList1); + //查询OFS售后入库单对应的售后订单 + List rerturnGoodsOrderSearchData = queryBatchAfterSalesOrder(returnGoodHeaderDetailsDataDtoList1); + findAfterSalesOrder(rerturnGoodsOrderSearchData, returnGoodHeaderDetailsDataDtoList1); + if ("tran".equals(sceneType)) { + returnGoodHeaderDetailsDataDtoList1 = filterForSale(returnGoodHeaderDetailsDataDtoList1); + } + //测试 +// RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData2 = rerturnGoodsOrderSearchData.get(0); +// List details2 = rerturnGoodsOrderSearchData2.getDetails(); +// for (int i = 0; i < details2.size(); i++) { +// RerturnGoodsOrderSearchDetails rerturnGoodsOrderSearchDetails = details2.get(i); +// +// rerturnGoodsOrderSearchDetails.setPlatformDiscounts("1"); +// rerturnGoodsOrderSearchDetails.setMerchantDiscounts("1"); +// rerturnGoodsOrderSearchDetails.setExpertDiscounts("1"); +// rerturnGoodsOrderSearchDetails.setPayDiscounts("1"); +// } + //查询OFS售后订单对应的OFS销售订单 + List headerDetailsDtos = queryBatchOfsOrder(returnGoodHeaderDetailsDataDtoList1); + findOfsOrder(headerDetailsDtos, returnGoodHeaderDetailsDataDtoList1); + //计算OFS销售订单优惠金额分摊到明细行 +// ofsOrderAfterSalesAmountAllocationUtil.batchTocSalesAmountAllocation(rerturnGoodsOrderSearchData); + //初始化公司档案对照关系 +// Map comparisonCompanyArchives = queryU8CEntityUtil.queryBdDefDocByPkDefDocAll(); + + //测试 +// StockinOrderSearchResponse.StockinOrder stockinOrder1 = returnGoodHeaderDetailsDataDtoList1.get(0); +// List details2 = stockinOrder1.getDetails(); +// for (int i = 0; i < details2.size(); i++) { +// StockinOrderSearchResponse.StockinOrder.StockinB stockinB = details2.get(i); +// stockinB.setReceivedQty(stockinB.getRequestQty()); +// } + + for (int i = 0; i < returnGoodHeaderDetailsDataDtoList1.size(); i++) { + StockinOrderSearchResponse.StockinOrder stockinOrder = returnGoodHeaderDetailsDataDtoList1.get(i); + StockinOrderSearchResponse.StockinOrder.StockinH header = stockinOrder.getHeader(); + List details = stockinOrder.getDetails(); + + try { + //OFS售后订单 + RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData1 = header.getRerturnGoodsOrderSearchData(); + Assert.notNull(header.getCode(), "OFS售后订单对应的code不能为空"); + Assert.notNull(rerturnGoodsOrderSearchData1, "无法关联到OFS售后订单 售后入库单号:{}", header.getCode().trim()); + //OFS销售订单 + com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto headerDetailsDto = header.getHeaderDetailsDto(); + com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDto header1 = headerDetailsDto.getHeader(); + List details1 = headerDetailsDto.getDetails(); + Assert.notNull(headerDetailsDto, "无法关联到OFS销售订单 售后入库单号:{}", header.getCode().trim()); + + //如果不存在,则默认一个 + if (header1.getSubOrderType() == null || "".equals(header1.getSubOrderType())) { + header1.setSubOrderType("SALES"); + } + BdRdclEntity bdRdclEntity = cacheTocMapVoV2.getStringBdRdclEntityMap().get(header1.getSubOrderType().trim()); + Assert.notNull(bdRdclEntity, "根据业务类型({})没有匹配到U8C业务类型", header1.getSubOrderType().trim()); + + String companyCode = header.getCompanyCode(); + Assert.notNull(companyCode, "O货主编码不能为空"); + //查找是否替换公司 +// String targetCorp = comparisonCompanyArchives.get(companyCode); +// if (targetCorp != null) { +// companyCode = targetCorp; +// } + BdCorpEntity bdCorpEntity = cacheTocMapVoV2.getStringBdCorpEntityMap().get(companyCode.trim()); + Assert.notNull(bdCorpEntity, "根据O公司编码(货主编码)({})没有匹配到U8C公司档案", header.getCompanyCode()); + + //发货库存组织 + BdCalbodyEntity bdCalbodyEntity = cacheTocMapVoV2.getStringBdCalbodyEntityMap().get(bdCorpEntity.getPkCorp()); + Assert.notNull(bdCalbodyEntity, "根据公司主键没有查询到发货库存组织 公司主键:{}", bdCorpEntity.getPkCorp()); + + //发货公司,暂时把O表头公司作为发货公司,正常情况下需要把O库存地点对于的公司作为发货公司 + + //发货仓库 + //2024年8月5日 15:06:38 仓库O与U两边仓库编码是一致的,和妮姐确认过了 + String facilityCode = header.getFacilityCode(); + Assert.notNull(facilityCode, "O仓库编码不能为空"); + BdStordocEntity bdStordocEntity = cacheTocMapVoV2.getStringBdStordocEntityMap().get(facilityCode.trim() + bdCalbodyEntity.getPkCalbody()); + Assert.notNull(bdStordocEntity, "没有匹配到发货仓库 O库存地点编码:{} 发货库存组织主键:{} ", facilityCode, bdCalbodyEntity.getPkCalbody()); + + //2024年8月5日 15:25:07 收货库存组织、收货仓库、默认和发货库存组织、发货仓库一致,已经和佳妮确认 + //收货库存组织:速网来看收货库存组织对应表头工具 + //收货仓库:通过收货库存组织+仓库编码,确定收货仓库 + + //销售组织2024年8月5日 15:33:40 和妮姐确认,销售组织和表头公司,作为一对一的关系, + BdSalestruEntity bdSalestruEntity = cacheTocMapVoV2.getStringBdSalestruEntityMap().get(bdCorpEntity.getUnitname()); + Assert.notNull(bdSalestruEntity, "无匹配到销售组织 表头公司名称:{}", bdCorpEntity.getUnitname()); + + //业务部门:暂定的部门名称:其他,2024年8月5日 15:39:42 已经和妮姐确认 + BdDeptdocEntity bdDeptdocEntity = null; + if (header1.getDepartmentType() == null || "".equals(header1.getDepartmentType().trim())) { + //默认业务部门 + logger.info("OFS销售订单号:{} 不存在部门字段!", header1.getCode()); + bdDeptdocEntity = cacheTocMapVoV2.getStringBdDeptdocEntityMap().get(bdCorpEntity.getPkCorp()); + Assert.notNull(bdDeptdocEntity, "无法匹配到业务部门 部门名称:其他 对应公司名称:{}", bdCorpEntity.getPkCorp()); + } else { + logger.info("OFS销售订单号:{} 存在部门字段:{}!", header1.getCode(), header1.getDepartmentType()); + String deptCode = header1.getDepartmentType().trim(); + bdDeptdocEntity = cacheTocMapVoV2.getStringBdDeptdocEntityMapByDeptCode().get(deptCode); + } + + //客商基本档案 + //2024年8月8日 12:05:10 O店铺的业务编码=U8C客商自定义项1,O没有店铺信息查询接口,因此无法通过出库单的店铺编码,查询到O店铺档案对应的业务编码,接口上线之后需要补充这一部分逻辑 +// String custName = "天猫intoyou旗舰店-自营"; + String storeCode = header.getStoreCode(); + Assert.notNull(storeCode, "O店铺编码不能为空,没有办法完成业务逻辑!"); + Assert.state(!"".equals(storeCode.trim()), "O店铺编码不能为空,没有办法完成业务逻辑!"); + BdCubasdocEntity bdCubasdocEntity = cacheTocMapVoV2.getStringBdCubasdocEntityMap().get(storeCode.trim()); + Assert.notNull(bdCubasdocEntity, "无法匹配到客户档案 客商名称:{}", storeCode); + + //客商管理档案:2024年8月5日 15:41:54 TOC店铺名称查询U8C客商档案,已经和妮姐确认 + //2024年8月5日 15:49:49 先根据O店铺编码,得到店铺档案信息,取到名称,通过U8C接口查询出来 + //目前O店铺信息查询接口还没有,等待开发,所以我这里先写所一个名字 + BdCumandocEntity bdCumandocEntity = cacheTocMapVoV2.getStringBdCumandocEntityMap().get(bdCubasdocEntity.getPkCubasdoc() + bdCorpEntity.getPkCorp()); + Assert.notNull(bdCumandocEntity, "无法匹配到客商档案 店铺名称:{}", "天猫intoyou旗舰店-自营"); + + //查找平台 + String sourcePlatformCode = header.getSourcePlatformCode(); + Assert.notNull(sourcePlatformCode, "O平台编码不能为空!"); + BdDefdocEntity bdDefdocEntity = cacheTocMapVoV2.getStringBdDefdocEntityMap().get(sourcePlatformCode.trim()); + Assert.notNull(bdDefdocEntity, "根据O平台编码({})无法匹配到U8C平台档案", header.getSourcePlatformCode()); + + //查找店铺 +// String storeCode2 = header.getStoreCode(); +// Assert.notNull(storeCode2, "O店铺编码不能为空!"); + BdDefdocEntity bdDefdocEntity1 = cacheTocMapVoV2.getStringBdDefdocEntityMap1().get(storeCode.trim()); + Assert.notNull(bdDefdocEntity1, "根据O店铺编码({})无法匹配到U8C店铺档案", storeCode.trim()); + + //字段拷贝 + for (int j = 0; j < details.size(); j++) { + StockinOrderSearchResponse.StockinOrder.StockinB stockinB = details.get(j); + + //存货管理档案,是发货公司的存货档案 + Assert.notNull(stockinB.getSkuCode(), "skucode不能为空"); + BdInvmandocEntity bdInvmandocEntity = cacheTocMapVoV2.getStringBdInvmandocEntityMap().get(stockinB.getSkuCode().trim() + bdCorpEntity.getPkCorp()); + Assert.notNull(bdInvmandocEntity, "无法匹配到存货管理档案 货品sku:{} 公司:{}", stockinB.getSkuCode().trim(), bdCorpEntity.getPkCorp()); + //存货基本档案 + BdInvbasdocEntity bdInvbasdocEntity = cacheTocMapVoV2.getStringBdInvbasdocEntityMap().get(stockinB.getSkuCode().trim()); + Assert.notNull(bdInvbasdocEntity, "无法匹配到存货基本档案 存货编码:{}", stockinB.getSkuCode().trim()); + //存货税率 + BdTaxitemsEntity bdTaxitemsEntity = cacheTocMapVoV2.getStringBdTaxitemsEntityMap().get(bdInvmandocEntity.getInvcode()); + Assert.notNull(bdTaxitemsEntity, "无法匹配到存货税率 存货编码:{}", bdInvmandocEntity.getInvcode()); + + //2024年8月6日 10:16:22 通过O出库单的表头,查询得出U8C档案,放在表体的原因是方便分组汇总 + //下一个步骤的分组汇总,是通过表体明细完成的 + GoodsRertunSonDetailsDto goodsRertunSonDetailsDto = new GoodsRertunSonDetailsDto(); + goodsRertunSonDetailsDto.setHeader(header); + goodsRertunSonDetailsDto.setBdCorpEntity(bdCorpEntity); + goodsRertunSonDetailsDto.setDeliverGoodsCorp(bdCorpEntity); + goodsRertunSonDetailsDto.setBdCalbodyEntity(bdCalbodyEntity); + goodsRertunSonDetailsDto.setBdStordocEntity(bdStordocEntity); + goodsRertunSonDetailsDto.setBdCalbodyEntity1(bdCalbodyEntity); + goodsRertunSonDetailsDto.setBdStordocEntity1(bdStordocEntity); + goodsRertunSonDetailsDto.setBdSalestruEntity(bdSalestruEntity); + goodsRertunSonDetailsDto.setBdDeptdocEntity(bdDeptdocEntity); + goodsRertunSonDetailsDto.setBdCumandocEntity(bdCumandocEntity); + goodsRertunSonDetailsDto.setBdCubasdocEntity(bdCubasdocEntity); + goodsRertunSonDetailsDto.setPlatformArchives(bdDefdocEntity); + goodsRertunSonDetailsDto.setBdRdclEntity(bdRdclEntity); + goodsRertunSonDetailsDto.setShopArchives(bdDefdocEntity1); + goodsRertunSonDetailsDto.setBdInvmandocEntity(bdInvmandocEntity); + goodsRertunSonDetailsDto.setBdInvbasdocEntity(bdInvbasdocEntity); + goodsRertunSonDetailsDto.setBdTaxitemsEntity(bdTaxitemsEntity); + + BeanUtil.copyPropertiesV2(stockinB, goodsRertunSonDetailsDto); + sonDetailsDtoList.add(goodsRertunSonDetailsDto); + //成功收集进入到集合 + } + } catch (Exception e) { + logger.error("档案转换抛出异常", e); + + //失败 + String message = e.getMessage(); + if (message == null) { + message = "未知错误"; + } + ErrorHeaderDetailsDtoDtoV2 errorHeaderDetailsDtoDto = new ErrorHeaderDetailsDtoDtoV2(); + errorHeaderDetailsDtoDto.setNewPushDate(getNewDateStr()); + errorHeaderDetailsDtoDto.setNewTransmitInfo(message); + errorHeaderDetailsDtoDto.setNewstate("N"); + errorHeaderDetailsDtoDto.setHeader(header); + errorHeaderDetailsDtoDto.setDetails(details); + errorHeaderDetailsDtoDtoList.add(errorHeaderDetailsDtoDto); + } + } + } catch (Exception e) { + logger.error("OFS销售出库单关联查询U8C档案失败", e); + } + } else { + logger.info("queryBasicArchives方法headerDetailsDtoList.size为0"); + } + //错误日志同步到数据 + if (errorHeaderDetailsDtoDtoList.size() > 0) { + updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry(errorHeaderDetailsDtoDtoList, sceneType); + } + return sonDetailsDtoList; + } + + /** + * 对象拷贝 bean copy + * 2024年8月9日 11:23:57 + */ + private List copyHeaderDto(List stockinHS) { + List tocofsReturngoodsEntityArrayList = new ArrayList<>(); + if (stockinHS != null && stockinHS.size() > 0) { + for (int i = 0; i < stockinHS.size(); i++) { + StockinOrderSearchResponse.StockinOrder.StockinH stockinH = stockinHS.get(i); + + TocofsReturngoodsEntity tocofsReturngoodsEntity = new TocofsReturngoodsEntity(); + BeanUtil.copyPropertiesV2(stockinH, tocofsReturngoodsEntity); + tocofsReturngoodsEntityArrayList.add(tocofsReturngoodsEntity); + } + } else { + logger.info("需要复制{}个bean对象(O表头)", stockinHS.size()); + } + return tocofsReturngoodsEntityArrayList; + } + + /** + * 对象拷贝 bean copy + * 2024年8月9日 11:24:01 + */ + private List copyDetailsDto(List stockinBS) { + List tocofsSaleoutDetailedEntityArrayList = new ArrayList<>(); + if (stockinBS != null && stockinBS.size() > 0) { + for (int i = 0; i < stockinBS.size(); i++) { + StockinOrderSearchResponse.StockinOrder.StockinB stockinB = stockinBS.get(i); + + //表头 + StockinOrderSearchResponse.StockinOrder.StockinH returnGoodSearchHeaderDto = stockinB.getReturnGoodSearchHeaderDto(); + + TocofsReturngoodsDetailedEntity tocofsReturngoodsDetailedEntity = new TocofsReturngoodsDetailedEntity(); + BeanUtil.copyPropertiesV2(stockinB, tocofsReturngoodsDetailedEntity); + //补充额外的字段信息 + createPrimaryKeyAndBusinessDateAndBusinessType(tocofsReturngoodsDetailedEntity, returnGoodSearchHeaderDto); + tocofsSaleoutDetailedEntityArrayList.add(tocofsReturngoodsDetailedEntity); + } + } else { + logger.info("需要复制{}个bean对象(O表体)", tocofsSaleoutDetailedEntityArrayList.size()); + } + return tocofsSaleoutDetailedEntityArrayList; + } + + /** + * 分组汇总:公司+店铺+仓库+SKU+出库类型,数量合并相加 + * 修改为:公司+店铺+仓库+SKU+收发类别+部门,数量合并相加 + * + * @author liuyang + */ + private Map> groupSummary(List goodsRertunSonDetailsDtos, String dimension) { + if (goodsRertunSonDetailsDtos != null && goodsRertunSonDetailsDtos.size() > 0) { + for (int i = 0; i < goodsRertunSonDetailsDtos.size(); i++) { + GoodsRertunSonDetailsDto goodsRertunSonDetailsDto = goodsRertunSonDetailsDtos.get(i); + //2024年8月6日 10:35:25表头对象用于带出表头相关的分组汇总信息 + StockinOrderSearchResponse.StockinOrder.StockinH header = goodsRertunSonDetailsDto.getHeader(); + RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = header.getRerturnGoodsOrderSearchData();//OFS售后订单 + com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto headerDetailsDto = header.getHeaderDetailsDto();//OFS销售订单 + + //公司 + BdCorpEntity bdCorpEntity = goodsRertunSonDetailsDto.getBdCorpEntity(); + //店铺(主要是店铺编码) + String storeCode = header.getStoreCode(); + //仓库 + String facilityCode = header.getFacilityCode(); + //SKU + String skuCode = goodsRertunSonDetailsDto.getSkuCode(); + //出库类型 +// String refOrderType = header.getRefOrderType(); + //收发类别 + BdRdclEntity bdRdclEntity = goodsRertunSonDetailsDto.getBdRdclEntity(); + //部门 + BdDeptdocEntity bdDeptdocEntity = goodsRertunSonDetailsDto.getBdDeptdocEntity(); + + StringBuffer summaryDimensionStr = new StringBuffer(); + if (bdCorpEntity != null && bdCorpEntity.getPkCorp() != null) { + summaryDimensionStr.append(bdCorpEntity.getPkCorp()); + } else { + summaryDimensionStr.append(NOTHING); + } + summaryDimensionStr.append(ADD); + + if (storeCode != null && !"".equals(storeCode)) { + summaryDimensionStr.append(storeCode); + } else { + summaryDimensionStr.append(NOTHING); + } + summaryDimensionStr.append(ADD); + + if (facilityCode != null && !"".equals(facilityCode)) { + summaryDimensionStr.append(facilityCode); + } else { + summaryDimensionStr.append(NOTHING); + } + summaryDimensionStr.append(ADD); + + if (skuCode != null && !"".equals(skuCode)) { + summaryDimensionStr.append(skuCode); + } else { + summaryDimensionStr.append(NOTHING); + } + summaryDimensionStr.append(ADD); + +// if (refOrderType != null && !"".equals(refOrderType)) { +// summaryDimensionStr.append(refOrderType); +// } else { +// summaryDimensionStr.append(NOTHING); +// } + + if (bdRdclEntity != null && bdRdclEntity.getRdcode() != null) { + summaryDimensionStr.append(bdRdclEntity.getRdcode()); + } else { + summaryDimensionStr.append(NOTHING); + } + summaryDimensionStr.append(ADD); + + if (bdDeptdocEntity != null && bdDeptdocEntity.getDeptcode() != null) { + summaryDimensionStr.append(bdDeptdocEntity.getDeptcode()); + } else { + summaryDimensionStr.append(NOTHING); + } + + goodsRertunSonDetailsDto.setSummaryDimensionStr(summaryDimensionStr.toString()); + } + logger.info("TOC:{} 个出库单对象需要汇总", goodsRertunSonDetailsDtos.size()); + if (dimension == null) { + return goodsRertunSonDetailsDtos.stream().collect(Collectors.groupingBy(GoodsRertunSonDetailsDto::getSummaryDimensionStr)); + } else { + Map> collect = goodsRertunSonDetailsDtos.stream().collect(Collectors.groupingBy(GoodsRertunSonDetailsDto::getSummaryDimensionStr)); + keepOnlyNeededKeys(collect, dimension); + return collect; + } + } + logger.info("TOC:0个对象需要汇总"); + return null; + } + + /** + * 移除不需要的键 + * + * @author liuyang + */ + private static void keepOnlyNeededKeys(Map> map, String... neededKeys) { + Iterator>> iterator = map.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry> entry = iterator.next(); + // 如果不是需要的键,则移除 + if (!contains(neededKeys, entry.getKey())) { + iterator.remove(); + } + } + } + + private static boolean contains(String[] array, String targetValue) { + for (String value : array) { + if (value.equals(targetValue)) { + return true; + } + } + return false; + } + + /** + * 2024年8月6日 10:59:03 查询U8C业务流程 + * + * @author liuyang + */ + public BdBusitypeEntity u8cOperationFlow() throws Exception { + //查询业务流程 + //2024年8月6日 11:33:07 具体的业务流程名称,还需要实施提供 + String processName = "TOC销售退货"; + BdBusitypeEntity bdBusitypeEntity = queryBdBusitypeUtil.queryBdBusitype(processName); + Assert.notNull(bdBusitypeEntity, "根据业务流程名称({})没有查询到业务流程", processName); + return bdBusitypeEntity; + } + + /** + * 2024年8月6日 10:59:03 查询U8C业务流程 + * + * @author liuyang + */ + private BdBusitypeEntity u8cOperationFlowV2() throws Exception { + //查询业务流程 + //2024年8月6日 11:33:07 具体的业务流程名称,还需要实施提供 + String processName = "TOC售后完成"; + BdBusitypeEntity bdBusitypeEntity = queryBdBusitypeUtil.queryBdBusitype(processName); + Assert.notNull(bdBusitypeEntity, "根据业务流程名称({})没有查询到业务流程", processName); + return bdBusitypeEntity; + } + + /** + * 检查参数是否为空 + * 2024年8月6日 11:40:19 保险的做法,最好还是验证一下 + * + * @author liuyang + */ + private void checkArchives(GoodsRertunSonDetailsDto sonDetailsDto) { + Assert.notNull(sonDetailsDto, "sonDetailsDto不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getHeader(), "header对象不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getBdCorpEntity(), "表头公司不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getBdCalbodyEntity(), "发货库存组织不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getBdStordocEntity(), "发货仓库不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getBdCalbodyEntity1(), "收货库存组织不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getBdStordocEntity1(), "收货库存不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getBdSalestruEntity(), "销售组织不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getBdDeptdocEntity(), "业务部门不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getBdCumandocEntity(), "客商档案不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + } + + /** + * 查询存货管理档案 + * + * @param pkCorp 发货公司主键 + * @param goodsRertunSonDetailsDto 出库单存货明细行 + * @author liuyang + */ +// private BdInvmandocEntity queryInventoryMan(GoodsRertunSonDetailsDto goodsRertunSonDetailsDto, String pkCorp) { +// Assert.notNull(goodsRertunSonDetailsDto, "sonDetailsDto不能为空"); +// Assert.notNull(goodsRertunSonDetailsDto.getSkuCode(), "O存货商家编码不能为空"); +// Assert.notNull(pkCorp, "发货公司主键不能为空"); +// +// BdInvmandocEntity bdInvmandocEntity = TocReturnBasicArchivesCacheUtil.stringBdInvmandocEntityMap.get(goodsRertunSonDetailsDto.getSkuCode() + pkCorp); +// Assert.notNull(bdInvmandocEntity, "无法匹配到存货管理档案 存货商家编码:{} 存货发货公司:{}", goodsRertunSonDetailsDto.getSkuCode(), pkCorp); +// return bdInvmandocEntity; +// } + + /** + * 合并明细行 + * 单价计算公式:sum(实付金额/实发数量) 最后除以条数 + * + * @param sonDetailsDtoList 汇总过后的售后入库单明细 + * @param isCheckShopChoose true取建议零售价、false取实付金额 + * @author liuyang + */ + private GoodsRertunSonDetailsDto groupMergeDetailedRows(List sonDetailsDtoList, Boolean isCheckShopChoose) throws Exception { + Assert.notNull(sonDetailsDtoList, "sonDetailsDtoList不能为空"); + Assert.notNull(isCheckShopChoose, "isCheckShopChoose不能为空"); +// Assert.notNull(mapList, "mapLists不能为空"); + + if (sonDetailsDtoList != null && sonDetailsDtoList.size() > 0) { + BigDecimal groupTotalPayAmount = new BigDecimal("0"); + BigDecimal groupShipQty = new BigDecimal("0"); + + for (int i = 0; i < sonDetailsDtoList.size(); 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 bdInvmandocEntity1 = goodsRertunSonDetailsDto.getBdInvmandocEntity();//存货管理档案 + BdInvbasdocEntity bdInvbasdocEntity = goodsRertunSonDetailsDto.getBdInvbasdocEntity();//存货基本档案 + BdInvmandocEntity bdInvmandocEntity = goodsRertunSonDetailsDto.getBdInvmandocEntity();//存货管理档案 + + //根据OFS售后入库单明细行,查找匹配OFS售后订单明细行 + RerturnGoodsOrderSearchDetails ofsOrderDetail = findOfsOrderDetail(details, goodsRertunSonDetailsDto); + + String totalAmount = null; + StringBuffer calculationFormulaStr = new StringBuffer(); + if (isCheckShopChoose) { + //取《U8C存货基本档案-参考售价》 + totalAmount = getRefsaleprice(bdInvmandocEntity, bdInvbasdocEntity, calculationFormulaStr, goodsRertunSonDetailsDto, header); + } else { + //取《O实退》 + totalAmount = accumulatedDiscounts(goodsRertunSonDetailsDto, rerturnGoodsOrderSearchData, calculationFormulaStr); + } + + //取对应的售后订单明细,主要是取这个价格 +// String totalAmount = getFloorPrice(isCheckShopChoose, bdInvmandocEntity, header, goodsRertunSonDetailsDto, mapList, calculationFormulaStr); +// if (totalAmount == null) { +// calculationFormulaStr.append("取O实退金额:"); +// //取O实退金额 +//// RerturnGoodsOrderSearchDetails afterSalesOrder = findAfterSalesOrderV2(goodsRertunSonDetailsDto, rerturnGoodsOrderSearchData); +//// totalAmount = afterSalesOrder.getTotalAmount(); +// //测试 +//// goodsRertunSonDetailsDto.setReceivedQty("1"); +// totalAmount = accumulatedDiscounts(goodsRertunSonDetailsDto, rerturnGoodsOrderSearchData, calculationFormulaStr); +// } + //测试 +// goodsRertunSonDetailsDto.setReceivedQty("1"); + + 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); + goodsRertunSonDetailsDto.setGroupTotalPayAmount(groupTotalPayAmount); + + //累加优惠金额 +// accumulationDiscountAmount(sonDetailsDtoList); + accumulatedDiscountAmountDef(sonDetailsDtoList); + +// logger.info("TOB{}个明细行发生了合并!", sonDetailsDtoList.size()); + return goodsRertunSonDetailsDto; + } else { + logger.info("sonDetailsDtoList集合是空的!"); + } + return null; + } + + /** + * 2024年8月7日 10:25:29 + * 查询基础档案,根据公司、管理档案主键查询 + * + * @author liuyang + */ +// private BdInvbasdocEntity queryStockBasicArchives(String pkInvmandoc, String pkCorp) { +// Assert.notNull(pkInvmandoc, "存货管理档案不能为空"); +// Assert.notNull(pkCorp, "公司档案不能为空"); +// BdInvbasdocEntity bdInvbasdocEntity = TocReturnBasicArchivesCacheUtil.stringBdInvbasdocEntityHashMap.get(pkInvmandoc + pkCorp); +// Assert.notNull(bdInvbasdocEntity, "根据公司主键:{} 和存货管理档案主键:{} 没有查询到存货基本档案", pkCorp, pkInvmandoc); +// return bdInvbasdocEntity; +// } + + /** + * 2024年8月7日 14:58:34 + * 查询税目档案 + * + * @author liuyang + */ +// private BdTaxitemsEntity queryBdTaxitems(String invcode) { +// Assert.notNull(invcode, "存货编码不能为空"); +// BdTaxitemsEntity bdTaxitemsEntity = TocReturnBasicArchivesCacheUtil.stringBdTaxitemsEntityHashMap.get(invcode); +// Assert.notNull(bdTaxitemsEntity, "根据存货编码({}),无法匹配到税率!", invcode); +// return bdTaxitemsEntity; +// } + + /** + * 2024年8月8日 10:54:48 + * 推送U8C销售订单方法 + * + * @author liuyang + */ + public SoSaleResultRootDto sendU8CTOCOrder(String param) { + long startLong = System.currentTimeMillis(); + logger.info("TOC推送开始,推送参数:" + param + ",U8C_URL:" + OverallConstant.getOverAllValue("u8c_url")); + String apiCode = "8000370006"; + String result = HttpRequest.post(OverallConstant.getOverAllValue("u8c_url")).header("appId", OverallConstant.getOverAllValue("appId"))//头信息,多个头信息多次调用此方法即可 + .header("usercode", OverallConstant.getOverAllValue("u8cApiUsercodePK")).header("password", OverallConstant.getOverAllValue("u8cApiPasswordPK")).header("system", OverallConstant.getOverAllValue("u8cApiSystemPK")).header("trantype", OverallConstant.getOverAllValue("u8cApiTrantypePK")).header("apiCode", apiCode)//头信息,多个头信息多次调用此方法即可 + .header("publicKey", OverallConstant.getOverAllValue("publicKey"))//头信息,多个头信息多次调用此方法即可 + .header("secretKey", OverallConstant.getOverAllValue("secretKey"))//头信息,多个头信息多次调用此方法即可 + .body(param)//表单内容 + .timeout(600000)//超时,毫秒 + .execute().body(); + logger.info("TOC推送结束,返回参数:" + result); + long endLong = System.currentTimeMillis(); + logger.info("TOC接口请求耗时:" + (endLong - startLong)); + + JSONObject jsonObject = JSON.parseObject(result); + result = String.valueOf(jsonObject.get("attribute")); + + boolean isSuccess = false; + SoSaleResultRootDto soSaleResultRootDto = null; + if (result != null && !"".equals(result)) { + ReusltStrDto reusltStrDto = JSON.parseObject(result, ReusltStrDto.class); + if ("success".equals(reusltStrDto.getStatus())) { + soSaleResultRootDto = resultDataHandle(reusltStrDto.getData()); + isSuccess = true; + } + } + if (!isSuccess) { + Assert.state(false, "TOC业务O出库单推送U8C销售订单失败 接口返回结果:{}", result); + } + return soSaleResultRootDto; + } + + /** + * 返回结果解析处理,在确认了success后调用 + * + * @author liuyang + */ + private SoSaleResultRootDto resultDataHandle(String resultData) { + try { + if (resultData != null && !"".equals(resultData)) { + if (resultData.contains("[")) { + resultData = resultData.substring(1, resultData.length() - 1); + } + return JSON.parseObject(resultData, SoSaleResultRootDto.class); + } + } catch (Exception e) { + e.printStackTrace(); + logger.error("解析返回参数失败的错误", e); + //如果解析失败,记录原因,但是不能影响结果的记录 + } + return null; + } + + /** + * 填充主表主键、业务日期、业务类型 + * 2024年8月15日 17:31:54 + * + * @param tocofsReturngoodsDetailedEntity dao明细行对象 + * @param returnGoodSearchHeaderDto OFS售后入库单表头对象 + */ + private void createPrimaryKeyAndBusinessDateAndBusinessType(TocofsReturngoodsDetailedEntity tocofsReturngoodsDetailedEntity, StockinOrderSearchResponse.StockinOrder.StockinH returnGoodSearchHeaderDto) { + if (tocofsReturngoodsDetailedEntity != null && returnGoodSearchHeaderDto != null) { + //主表主键 + if (returnGoodSearchHeaderDto.getId() != null) { + tocofsReturngoodsDetailedEntity.setMaintableid(returnGoodSearchHeaderDto.getId()); + } + //业务日期-入库时间 + if (returnGoodSearchHeaderDto.getClosedAt() != null) { + tocofsReturngoodsDetailedEntity.setBusinessdate(returnGoodSearchHeaderDto.getClosedAt()); + } + //业务日期-退款完成时间 + if (returnGoodSearchHeaderDto.getRefundedAt() != null) { + tocofsReturngoodsDetailedEntity.setRefundedat(returnGoodSearchHeaderDto.getRefundedAt()); + } + //业务类型 + tocofsReturngoodsDetailedEntity.setBusinesstype("TOC_RETURN"); + } + } + + /** + * 通过OFS销售出库单,联查OFS销售订单 + * + * @param headerDetailsDtoList OFS销售出库单 + */ + private List queryOfsOrder(List headerDetailsDtoList) throws Exception { + List allHeaderDetailsDtoArrayList = new ArrayList<>(); + try { + if (headerDetailsDtoList != null && headerDetailsDtoList.size() > 0) { + List> splitListByCount = SplitListByCountUtil.splitListByCount(headerDetailsDtoList, 100); + for (int i = 0; i < splitListByCount.size(); i++) { + List headerDetailsDtos = splitListByCount.get(i); + + StringBuffer stringBuffer = new StringBuffer(); + if (headerDetailsDtos != null && headerDetailsDtos.size() > 0) { + for (int j = 0; j < headerDetailsDtos.size(); j++) { + HeaderDetailsDto headerDetailsDto = headerDetailsDtos.get(j); + HeaderDto header = headerDetailsDto.getHeader(); +// List details = headerDetailsDto.getDetails(); +// stringBuffer.append("'"); + stringBuffer.append(header.getRefOrderCode()); +// stringBuffer.append("'"); + stringBuffer.append(","); + } + } + String substring = stringBuffer.substring(0, stringBuffer.length()); + + List headerDetailsDtoArrayList = new ArrayList<>(); + QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo(); + queryOfsSoSaleOutVo.setCode(substring); + ofsStandardUtil.getOfsSaleOrder(queryOfsSoSaleOutVo, headerDetailsDtoArrayList, 1L); + allHeaderDetailsDtoArrayList.addAll(headerDetailsDtoArrayList); + } + } + } catch (Exception e) { + logger.error("queryOfsOrder方法抛出异常", e); + } + return allHeaderDetailsDtoArrayList; + } + + /** + * 批量查询售后订单 + * + * @param returnGoodHeaderDetailsDataDtoList1 OFS售后入库单 + * @author liuyang + */ + private List queryBatchAfterSalesOrder(List returnGoodHeaderDetailsDataDtoList1) { + List rerturnGoodsOrderSearchDataList = new ArrayList<>(); + if (returnGoodHeaderDetailsDataDtoList1 != null && returnGoodHeaderDetailsDataDtoList1.size() > 0) { + try { + //完成去重 + Set refOrderCodeSet = new HashSet<>(); +// List> splitListByCount = SplitListByCountUtil.splitListByCount(returnGoodHeaderDetailsDataDtoList1, 50); +// for (int i = 0; i < splitListByCount.size(); i++) { +// List stockinOrderList = splitListByCount.get(i); +// //50个原始一个批次进行分割 +// StringBuffer idStr = new StringBuffer(); +// for (int j = 0; j < stockinOrderList.size(); j++) { +// StockinOrderSearchResponse.StockinOrder stockinOrder = stockinOrderList.get(j); +// StockinOrderSearchResponse.StockinOrder.StockinH header = stockinOrder.getHeader(); +//// List details = stockinOrder.getDetails(); +// idStr.append(header.getRefOrderCode()); +// idStr.append(","); +// } +// String idsStr = idStr.substring(0, idStr.length() - 1); +// +// QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo(); +// queryOfsSoSaleOutVo.setCode(idsStr); +// afterSalesOrderUtil.getBatchOfsRertunOrder(queryOfsSoSaleOutVo, rerturnGoodsOrderSearchDataList, 1L); +// } + //已经和万万确认,售后入库单明细行不会有合单的情况 + for (int i = 0; i < returnGoodHeaderDetailsDataDtoList1.size(); i++) { + StockinOrderSearchResponse.StockinOrder stockinOrder = returnGoodHeaderDetailsDataDtoList1.get(i); + StockinOrderSearchResponse.StockinOrder.StockinH header = stockinOrder.getHeader(); + List details = stockinOrder.getDetails(); + String refOrderCode = header.getRefOrderCode(); + if (refOrderCode != null && !"".equals(refOrderCode.trim())) { + refOrderCodeSet.add(refOrderCode.trim()); + } + } + if (refOrderCodeSet.size() > 0) { + List stringList = refOrderCodeSet.stream().collect(Collectors.toList()); + List> lists = SplitListByCountUtil.splitListByCount(stringList, 100); + for (int i = 0; i < lists.size(); i++) { + List strings = lists.get(i); + String result = strings.stream().map(s -> s.trim()).collect(Collectors.joining(",")); + if (result != null && result.length() > 0) { + QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo(); + queryOfsSoSaleOutVo.setCode(result); + afterSalesOrderUtil.getBatchOfsRertunOrder(queryOfsSoSaleOutVo, rerturnGoodsOrderSearchDataList, 1L); + } + } + } + } catch (Exception e) { + logger.error("批量查询关联售后订单抛出异常", e); + } + } + return rerturnGoodsOrderSearchDataList; + } + + /** + * 匹配售后订单 + * + * @param rerturnGoodsOrderSearchDataList OFS售后订单集合 + * @param returnGoodHeaderDetailsDataDtoList1 OFS售后入库单集合 + * @author liuyang + */ + private void findAfterSalesOrder(List rerturnGoodsOrderSearchDataList, List returnGoodHeaderDetailsDataDtoList1) throws Exception { + if (rerturnGoodsOrderSearchDataList != null && rerturnGoodsOrderSearchDataList.size() > 0 && returnGoodHeaderDetailsDataDtoList1 != null && returnGoodHeaderDetailsDataDtoList1.size() > 0) { + try { + //key为售后订单主键,如果id为空,则这里会报错,所以把id设置为"" + rerturnGoodsOrderSearchDataList.forEach(dto -> { + if (dto.getHeader() != null && dto.getHeader().getId() == null) { + dto.getHeader().setId(""); + } + }); + Map collect = rerturnGoodsOrderSearchDataList.stream().collect(Collectors.toMap(dto -> dto.getHeader().getId(), dto -> dto)); + + for (int i = 0; i < returnGoodHeaderDetailsDataDtoList1.size(); i++) { + StockinOrderSearchResponse.StockinOrder stockinOrder = returnGoodHeaderDetailsDataDtoList1.get(i); + StockinOrderSearchResponse.StockinOrder.StockinH header = stockinOrder.getHeader(); + List details = stockinOrder.getDetails(); + +// Assert.notNull(header.getId(), "OFS售后入库单主键不能为空!"); +// for (int j = 0; j < rerturnGoodsOrderSearchDataList.size(); j++) { +// RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = rerturnGoodsOrderSearchDataList.get(j); +// RerturnGoodsOrderSearchHeader header1 = rerturnGoodsOrderSearchData.getHeader(); +// List details1 = rerturnGoodsOrderSearchData.getDetails(); +// if (header.getRefOrderId().equals(header1.getId())) { +// header.setRerturnGoodsOrderSearchData(rerturnGoodsOrderSearchData); +// } +// } + String refOrderId = header.getRefOrderId(); + if (refOrderId != null && !"".equals(refOrderId)) { + RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = collect.get(refOrderId); + if (rerturnGoodsOrderSearchData != null) { + header.setRerturnGoodsOrderSearchData(rerturnGoodsOrderSearchData); + } + } + } + } catch (Exception e) { + logger.error("findAfterSalesOrder方法抛出异常", e); + } + } + } + + /** + * 通过售后入库单明细行,查找售后订单明细行 + * + * @param stockinB 售后订单明细行 + * @param ofsRertunOrder OFS售后订单 + * @author liuyang + */ + private RerturnGoodsOrderSearchDetails findAfterSalesOrderV2(StockinOrderSearchResponse.StockinOrder.StockinB stockinB, RerturnGoodsOrderSearchData ofsRertunOrder) { + Assert.notNull(stockinB, "stockinB不能为空!"); + Assert.notNull(ofsRertunOrder, "saleOrderMessageDto不能为空!"); + + Assert.notNull(ofsRertunOrder.getHeader(), "售后订表头不能为空!"); + Assert.notNull(ofsRertunOrder.getDetails(), "售后订单表头"); + RerturnGoodsOrderSearchHeader header = ofsRertunOrder.getHeader(); + List details1 = ofsRertunOrder.getDetails(); + if (details1 == null || details1.size() == 0) { + Assert.state(false, "售后订单明细行不能为空,size不能为0!"); + } + for (int i = 0; i < details1.size(); i++) { + RerturnGoodsOrderSearchDetails rerturnGoodsOrderSearchDetails = details1.get(i); + if (rerturnGoodsOrderSearchDetails.getId().equals(stockinB.getRefOrderDetailId())) { + return rerturnGoodsOrderSearchDetails; + } + } + Assert.state(false, "通过售后入库单号({})无法匹配到售后订单", stockinB.getId()); + return null; + } + + /** + * 通过售后入库单对应的售后订单,查询OFS销售订单 + * + * @param returnGoodHeaderDetailsDataDtoList1 OFS售后入库单集合 + * @author liuyang + */ + private List queryBatchOfsOrder(List returnGoodHeaderDetailsDataDtoList1) throws Exception { + List headerDetailsDtoArrayList = new ArrayList<>(); + + if (returnGoodHeaderDetailsDataDtoList1 != null && returnGoodHeaderDetailsDataDtoList1.size() > 0) { + try { + Set refOrderCodeSet = new HashSet<>(); + for (int i = 0; i < returnGoodHeaderDetailsDataDtoList1.size(); i++) { + StockinOrderSearchResponse.StockinOrder stockinOrder = returnGoodHeaderDetailsDataDtoList1.get(i); + StockinOrderSearchResponse.StockinOrder.StockinH header = stockinOrder.getHeader(); + List details = stockinOrder.getDetails(); + if (header.getRerturnGoodsOrderSearchData() != null) { + RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = header.getRerturnGoodsOrderSearchData();//OFS售后入库单对应的「售后订单」 + RerturnGoodsOrderSearchHeader header1 = rerturnGoodsOrderSearchData.getHeader(); + List details1 = rerturnGoodsOrderSearchData.getDetails(); + //得到「售后订单」关联的销售订单号 + if (header1.getRefOrderCode() != null && !"".equals(header1.getRefOrderCode())) { + refOrderCodeSet.add(header1.getRefOrderCode().trim()); + } + } + } + + //每50个作为一批,拆分 +// List> splitListByCount = SplitListByCountUtil.splitListByCount(returnGoodHeaderDetailsDataDtoList1, 50); +// for (int i = 0; i < splitListByCount.size(); i++) { +// List stockinOrderList = splitListByCount.get(i); +// +// StringBuffer codes = new StringBuffer(); +// for (int j = 0; j < stockinOrderList.size(); j++) { +// StockinOrderSearchResponse.StockinOrder stockinOrder = stockinOrderList.get(j); +// StockinOrderSearchResponse.StockinOrder.StockinH header = stockinOrder.getHeader(); +// List details = stockinOrder.getDetails(); +// RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData1 = header.getRerturnGoodsOrderSearchData();//OFS售后订单 +// if (rerturnGoodsOrderSearchData1 != null) { +// RerturnGoodsOrderSearchHeader header1 = rerturnGoodsOrderSearchData1.getHeader(); +// List details1 = rerturnGoodsOrderSearchData1.getDetails(); +// codes.append(header1.getRefOrderCode()); +// codes.append(","); +// } +// } +// String codesStr = codes.substring(0, codes.length() - 1); +// +// QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo(); +// queryOfsSoSaleOutVo.setCode(codesStr); +// ofsStandardUtil.getOfsSaleOrder(queryOfsSoSaleOutVo, headerDetailsDtoArrayList, 1L); +// } + + //Set集合转List集合 + if (refOrderCodeSet.size() > 0) { + List stringList = refOrderCodeSet.stream().collect(Collectors.toList()); + List> lists = SplitListByCountUtil.splitListByCount(stringList, 100); + for (int i = 0; i < lists.size(); i++) { + List strings = lists.get(i); + String result = strings.stream().map(s -> s.trim()).collect(Collectors.joining(",")); + if (result != null && result.length() > 0) { + QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo(); + queryOfsSoSaleOutVo.setCode(result); + ofsStandardUtil.getOfsSaleOrder(queryOfsSoSaleOutVo, headerDetailsDtoArrayList, 1L); + } + } + } + } catch (Exception e) { + logger.error("queryBatchOfsOrder方法抛出异常", e); + } + } + return headerDetailsDtoArrayList; + } + + /** + * 匹配OFS销售订单 + * + * @param headerDetailsDtoList OFS销售订单 + * @param returnGoodHeaderDetailsDataDtoList1 ofs售后入库单 + * @author liuyang + */ + private void findOfsOrder(List headerDetailsDtoList, List returnGoodHeaderDetailsDataDtoList1) { + if (headerDetailsDtoList != null && headerDetailsDtoList.size() > 0 && returnGoodHeaderDetailsDataDtoList1 != null && returnGoodHeaderDetailsDataDtoList1.size() > 0) { + try { + headerDetailsDtoList.forEach(dto -> { + if (dto.getHeader() != null && dto.getHeader().getId() == null) { + dto.getHeader().setId(""); + } + }); + Map collect = headerDetailsDtoList.stream().collect(Collectors.toMap(dto -> dto.getHeader().getId(), dto -> dto)); + + for (int i = 0; i < returnGoodHeaderDetailsDataDtoList1.size(); i++) { + StockinOrderSearchResponse.StockinOrder stockinOrder = returnGoodHeaderDetailsDataDtoList1.get(i); + StockinOrderSearchResponse.StockinOrder.StockinH header = stockinOrder.getHeader(); + List details = stockinOrder.getDetails(); + + RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = header.getRerturnGoodsOrderSearchData();//OFS售后订单 + RerturnGoodsOrderSearchHeader header2 = rerturnGoodsOrderSearchData.getHeader(); + List details2 = rerturnGoodsOrderSearchData.getDetails(); +// for (int j = 0; j < headerDetailsDtoList.size(); j++) { +// com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto headerDetailsDto = headerDetailsDtoList.get(j); +// com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDto header1 = headerDetailsDto.getHeader(); +// List details1 = headerDetailsDto.getDetails(); +// if (header2.getRefOrderId().equals(header1.getId())) { +// header.setHeaderDetailsDto(headerDetailsDto); +// } +// } + if (header2.getRefOrderId() != null && !"".equals(header2.getRefOrderId().trim())) { + com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto headerDetailsDto = collect.get(header2.getRefOrderId().trim()); + if (headerDetailsDto != null) { + header.setHeaderDetailsDto(headerDetailsDto); + } + } + } + } catch (Exception e) { + logger.error("findOfsOrder方法抛出异常", e); + } + } + } + + /** + * 生成当前日期 + * + * @author liuyang + */ + private String getNewDateStr() { + LocalDateTime now = LocalDateTime.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + return now.format(formatter); + } + + /** + * 批量修改成功、或者失败,适合档案查询的部分 + * + * @param errorHeaderDetailsDtoDtoList 错误日志 + * @param sceneType 场景类型 + * @author liuyang + */ + private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry(List errorHeaderDetailsDtoDtoList, String sceneType) { + Assert.notNull(errorHeaderDetailsDtoDtoList, "errorHeaderDetailsDtoDtoList不能为空!"); + + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + try { + if (errorHeaderDetailsDtoDtoList != null && errorHeaderDetailsDtoDtoList.size() > 0) { + List tocofsSaleoutDetailedEntityList = new ArrayList<>(); + for (int i = 0; i < errorHeaderDetailsDtoDtoList.size(); i++) { + ErrorHeaderDetailsDtoDtoV2 errorHeaderDetailsDtoDtoV2 = errorHeaderDetailsDtoDtoList.get(i); + StockinOrderSearchResponse.StockinOrder.StockinH header = errorHeaderDetailsDtoDtoV2.getHeader(); + List details = errorHeaderDetailsDtoDtoV2.getDetails(); + String newstate = errorHeaderDetailsDtoDtoV2.getNewstate(); + String newPushDate = errorHeaderDetailsDtoDtoV2.getNewPushDate(); + String newTransmitInfo = errorHeaderDetailsDtoDtoV2.getNewTransmitInfo(); + + //如果报错内容太长了,则仅保留500个长度 + if (newTransmitInfo != null && !"".equals(newTransmitInfo.trim()) && newTransmitInfo.length() >= 400) { + newTransmitInfo = newTransmitInfo.substring(0, 400); + } + + for (int j = 0; j < details.size(); j++) { + StockinOrderSearchResponse.StockinOrder.StockinB stockinB = details.get(j); + + TocofsReturngoodsDetailedEntity tocofsReturngoodsDetailedEntity = new TocofsReturngoodsDetailedEntity(); + + tocofsReturngoodsDetailedEntity.setId(stockinB.getId()); + if (sceneType.equals("stock")) { + tocofsReturngoodsDetailedEntity.setNewpushdate3(newPushDate); + tocofsReturngoodsDetailedEntity.setNewtransmitinfo3(newTransmitInfo); + tocofsReturngoodsDetailedEntity.setNewstate3(newstate); + tocofsReturngoodsDetailedEntity.setNewsystemnumber3(null); + tocofsReturngoodsDetailedEntity.setNewsystemprimary3(null); + } else if (sceneType.equals("tran")) { + tocofsReturngoodsDetailedEntity.setNewpushdate4(newPushDate); + tocofsReturngoodsDetailedEntity.setNewtransmitinfo4(newTransmitInfo); + tocofsReturngoodsDetailedEntity.setNewstate4(newstate); + tocofsReturngoodsDetailedEntity.setNewsystemnumber4(null); + tocofsReturngoodsDetailedEntity.setNewsystemprimary4(null); + } + tocofsSaleoutDetailedEntityList.add(tocofsReturngoodsDetailedEntity); + } + } + + //以50行为一个批次更新状态 + if (tocofsSaleoutDetailedEntityList.size() > 0) { + List> splitListByCount = SplitListByCountUtil.splitListByCount(tocofsSaleoutDetailedEntityList, 50); + for (int i = 0; i < splitListByCount.size(); i++) { + List tocofsReturngoodsDetailedEntities = splitListByCount.get(i); + if (sceneType.equals("stock")) { + //库存 + iTocofsReturngoodsDetailedDao.entityInsertOrUpdateBatchByTocRerturnStock(tocofsReturngoodsDetailedEntities); + } else if (sceneType.equals("tran")) { + //确认收入 + iTocofsReturngoodsDetailedDao.entityInsertOrUpdateBatchByTocRerturnTran(tocofsReturngoodsDetailedEntities); + } + } + } + } + } catch (Exception e) { + logger.error("TOB业务,填充出库明细日志抛出异常", e); + } + } + }); + thread.start(); + try { + thread.join(); + } catch (Exception e) { + logger.error("updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry方法现场抛出异常", e); + } + } + + /** + * 处理TOC-库存同步的成功、失败错误逻辑 + * + * @author liuyang + */ + private void updateSuccessOrFail1(List sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) { + if (newTransmitInfo != null && !"".equals(newTransmitInfo.trim()) && newTransmitInfo.length() >= 400) { + newTransmitInfo = newTransmitInfo.substring(0, 400); + } + + String finalNewTransmitInfo = newTransmitInfo; + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + try { + String successY = "Y"; + if (sonDetailsDtoList != null && sonDetailsDtoList.size() > 0) { + List tocofsReturngoodsDetailedEntityArrayList = new ArrayList<>(); + for (int i = 0; i < sonDetailsDtoList.size(); i++) { + GoodsRertunSonDetailsDto goodsRertunSonDetailsDto = sonDetailsDtoList.get(i); + + TocofsReturngoodsDetailedEntity tocofsReturngoodsDetailedEntity = new TocofsReturngoodsDetailedEntity(); + tocofsReturngoodsDetailedEntity.setId(goodsRertunSonDetailsDto.getId()); + 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); + } + tocofsReturngoodsDetailedEntityArrayList.add(tocofsReturngoodsDetailedEntity); + } + + //以50行为一个批次,推送到Mysql + if (tocofsReturngoodsDetailedEntityArrayList.size() > 0) { + List> splitListByCount = SplitListByCountUtil.splitListByCount(tocofsReturngoodsDetailedEntityArrayList, 50); + for (int i = 0; i < splitListByCount.size(); i++) { + List tocofsReturngoodsDetailedEntities = splitListByCount.get(i); + iTocofsReturngoodsDetailedDao.entityInsertOrUpdateBatchByTocRerturnStock(tocofsReturngoodsDetailedEntities); + } + } + } + } catch (Exception e) { + logger.error("TOC库存同步日志,抛出异常", e); + } + } + }); + thread.start(); + try { + thread.join(); + } catch (Exception e) { + logger.error("updateSuccessOrFail1方法现场抛出异常", e); + } + } + + /** + * 处理TOC-库存同步的成功、失败错误逻辑 + * + * @author liuyang + */ + private void updateSuccessOrFail2(List sonDetailsDtoList, String newstate, String newTransmitInfo, String newsystemnumber, String newsystemprimary) { + if (newTransmitInfo != null && !"".equals(newTransmitInfo.trim()) && newTransmitInfo.length() >= 400) { + newTransmitInfo = newTransmitInfo.substring(0, 400); + } + + String finalNewTransmitInfo = newTransmitInfo; + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + try { + String successY = "Y"; + if (sonDetailsDtoList != null && sonDetailsDtoList.size() > 0) { + List tocofsReturngoodsDetailedEntityArrayList = new ArrayList<>(); + for (int i = 0; i < sonDetailsDtoList.size(); i++) { + GoodsRertunSonDetailsDto goodsRertunSonDetailsDto = sonDetailsDtoList.get(i); + + TocofsReturngoodsDetailedEntity tocofsReturngoodsDetailedEntity = new TocofsReturngoodsDetailedEntity(); + tocofsReturngoodsDetailedEntity.setId(goodsRertunSonDetailsDto.getId()); + 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); + } + tocofsReturngoodsDetailedEntityArrayList.add(tocofsReturngoodsDetailedEntity); + } + + //以50行为一个批次,推送到Mysql + if (tocofsReturngoodsDetailedEntityArrayList.size() > 0) { + List> splitListByCount = SplitListByCountUtil.splitListByCount(tocofsReturngoodsDetailedEntityArrayList, 200); + for (int i = 0; i < splitListByCount.size(); i++) { + List tocofsReturngoodsDetailedEntities = splitListByCount.get(i); + iTocofsReturngoodsDetailedDao.entityInsertOrUpdateBatchByTocRerturnTran(tocofsReturngoodsDetailedEntities); + } + } + } + } catch (Exception e) { + logger.error("TOC确认收入同步日志,抛出异常", e); + } + } + }); + thread.start(); + try { + thread.join(); + } catch (Exception e) { + logger.error("updateSuccessOrFail1方法现场抛出异常", e); + } + } + + /** + * 筛选出未推送、或者失败的数据行,过滤库存同步业务 + * + * @param tocofsReturngoodsDetailedEntityList 日志行状态 + * @param returnGoodHeaderDetailsDataDtoArrayList 返回结果 + * @author liuyang + */ + private List filterDataRowsAsPushOrFailedStock(List tocofsReturngoodsDetailedEntityList, List returnGoodHeaderDetailsDataDtoArrayList) throws Exception { + List targetHeaderDetailsDtoList = new ArrayList<>(); + + if (returnGoodHeaderDetailsDataDtoArrayList != null && returnGoodHeaderDetailsDataDtoArrayList.size() > 0) { + List resultList = tocofsReturngoodsDetailedEntityList.stream().map(obj -> { + if (obj.getNewstate3() == null) { + obj.setNewstate3(""); + } + return obj; + }).collect(Collectors.toList()); + Map no2NameMap = resultList.stream().collect(Collectors.toMap(TocofsReturngoodsDetailedEntity::getId, TocofsReturngoodsDetailedEntity::getNewstate3)); + + //字段Y(成功)或者为H(待处理)可以视为成功,完成了小段业务闭环的数据行 + String succeseeY = "Y"; + String succeseeH = "H"; + for (int i = 0; i < returnGoodHeaderDetailsDataDtoArrayList.size(); i++) { + StockinOrderSearchResponse.StockinOrder stockinOrder = returnGoodHeaderDetailsDataDtoArrayList.get(i); + StockinOrderSearchResponse.StockinOrder.StockinH header = stockinOrder.getHeader(); + List details = stockinOrder.getDetails(); + + List targetDetails = new ArrayList<>(); + for (int j = 0; j < details.size(); j++) { + StockinOrderSearchResponse.StockinOrder.StockinB stockinB = details.get(j); + Boolean isSuccess = false; + String newstate = null; +// if (tocofsReturngoodsDetailedEntityList != null && tocofsReturngoodsDetailedEntityList.size() > 0) { +// for (int k = 0; k < tocofsReturngoodsDetailedEntityList.size(); k++) { +// TocofsReturngoodsDetailedEntity tocofsReturngoodsDetailedEntity = tocofsReturngoodsDetailedEntityList.get(k); +// if (tocofsReturngoodsDetailedEntity.getId().equals(stockinB.getId())) { +// newstate = tocofsReturngoodsDetailedEntity.getNewstate3(); +// if (succeseeY.equals(newstate) || succeseeH.equals(newstate)) { +// isSuccess = true; +// } +// } +// } +// } + newstate = no2NameMap.get(stockinB.getId()); + if (newstate != null && !"".equals(newstate) && (succeseeY.equals(newstate) || succeseeH.equals(newstate))) { + isSuccess = true; + } + if (!isSuccess) { + stockinB.setNewstate3(newstate); + targetDetails.add(stockinB); + } + } + if (targetDetails.size() > 0) { + //如果明细行中,还存在未推送或者失败的数据,则需要更新明细行 + stockinOrder.setDetails(targetDetails); + targetHeaderDetailsDtoList.add(stockinOrder); + } + } + } + return targetHeaderDetailsDtoList; + } + + /** + * 筛选出未推送、或者失败的数据行,过滤库存同步业务 + * + * @param tocofsReturngoodsDetailedEntityList 日志行状态 + * @param returnGoodHeaderDetailsDataDtoArrayList 返回结果 + * @author liuyang + */ + private List filterDataRowsAsPushOrFailedTran(List tocofsReturngoodsDetailedEntityList, List returnGoodHeaderDetailsDataDtoArrayList) throws Exception { + Assert.notNull(tocofsReturngoodsDetailedEntityList, "tocofsReturngoodsDetailedEntityList不能为空"); + Assert.notNull(returnGoodHeaderDetailsDataDtoArrayList, "returnGoodHeaderDetailsDataDtoArrayList不能为空"); + + List targetHeaderDetailsDtoList = new ArrayList<>(); + if (tocofsReturngoodsDetailedEntityList != null && returnGoodHeaderDetailsDataDtoArrayList != null && returnGoodHeaderDetailsDataDtoArrayList.size() > 0) { + List collect = tocofsReturngoodsDetailedEntityList.stream().map(obj -> { + if (obj.getNewstate4() == null) { + obj.setNewstate4(""); + } + return obj; + }).collect(Collectors.toList()); + Map no2NameMap2 = collect.stream().collect(Collectors.toMap(TocofsReturngoodsDetailedEntity::getId, TocofsReturngoodsDetailedEntity::getNewstate4)); + + //字段Y(成功)或者为H(待处理)可以视为成功,完成了小段业务闭环的数据行 + String succeseeY = "Y"; + String succeseeH = "H"; + for (int i = 0; i < returnGoodHeaderDetailsDataDtoArrayList.size(); i++) { + StockinOrderSearchResponse.StockinOrder stockinOrder = returnGoodHeaderDetailsDataDtoArrayList.get(i); + StockinOrderSearchResponse.StockinOrder.StockinH header = stockinOrder.getHeader(); + List details = stockinOrder.getDetails(); + + List targetDetails = new ArrayList<>(); + for (int j = 0; j < details.size(); j++) { + StockinOrderSearchResponse.StockinOrder.StockinB stockinB = details.get(j); + Boolean isSuccess = false; + String newstate = null; +// for (int k = 0; k < tocofsReturngoodsDetailedEntityList.size(); k++) { +// TocofsReturngoodsDetailedEntity tocofsReturngoodsDetailedEntity = tocofsReturngoodsDetailedEntityList.get(k); +// if (tocofsReturngoodsDetailedEntity.getId().equals(stockinB.getId())) { +// newstate = tocofsReturngoodsDetailedEntity.getNewstate4(); +// if (succeseeY.equals(newstate) || succeseeH.equals(newstate)) { +// isSuccess = true; +// } +// } +// } + newstate = no2NameMap2.get(stockinB.getId()); + if (newstate != null && !"".equals(newstate) && (succeseeY.equals(newstate) || succeseeH.equals(newstate))) { + isSuccess = true; + } + + if (!isSuccess) { + stockinB.setNewstate4(newstate); + targetDetails.add(stockinB); + } + } + if (targetDetails.size() > 0) { + //如果明细行中,还存在未推送或者失败的数据,则需要更新明细行 + stockinOrder.setDetails(targetDetails); + targetHeaderDetailsDtoList.add(stockinOrder); + } + } + } + return targetHeaderDetailsDtoList; + } + + /** + * 计算时间间隔 + * + * @author liuyang + */ + public String computingTime(String param) { + if (param != null && !"".equals(param)) { + String[] split = param.split("/"); + if (!(split.length == 2)) { + Assert.state(false, "传递的日期格式不完整 格式参考:2024-04-01/2024-04-30"); + } + + LocalDate startDate = LocalDate.parse(split[0]); + LocalDate endDate = LocalDate.parse(split[1]); + + List stringArrayList = new ArrayList<>(); + List dateRange = getDateRange(startDate, endDate); + if (dateRange != null && dateRange.size() > 0) { + for (int i = 0; i < dateRange.size(); i++) { + String dateStr = dateRange.get(i); + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append(dateStr); + stringBuffer.append(" 00:00:00"); + stringBuffer.append(","); + stringBuffer.append(dateStr); + stringBuffer.append(" 23:59:59"); + stringArrayList.add(stringBuffer.toString()); + } + } + String collectDateStr = stringArrayList.stream().collect(Collectors.joining("*")); + logger.info("类型:time_frame 生成的日期范围:" + collectDateStr); + return collectDateStr; + } + return null; + } + + /** + * 分割日期之后,再进行推送 + * + * @author liuyang + */ + public void splitDateAndPush(String param, String sceneType, String pushScenarioType) throws Exception { + try { + Assert.notNull(param, "param不能为空!"); + Assert.state(!"".equals(param), "param不能为空!"); + + Assert.notNull(sceneType, "sceneType不能为空!"); + Assert.state(!"".equals(sceneType), "sceneType不能为空!"); + + Assert.notNull(pushScenarioType, "pushScenarioType不能为空!"); + Assert.state(!"".equals(pushScenarioType), "pushScenarioType不能为空!"); + + if (param.contains("*")) { + String[] params = param.split("\\*"); + if (params.length > 0) { + for (int i = 0; i < params.length; i++) { + String indexStr = params[i]; + String[] split = indexStr.split(","); + logger.info("splitDateAndPush方法正在执行主要的逻辑 开始时间:{} 结束时间:{}", split[0], split[1]); + if (sceneType.equals(STOCK)) { + startImplementStockByTime(split[0], split[1], pushScenarioType); + } else if (sceneType.equals(TRAN)) { + startImplementByTradeTime(split[0], split[1], pushScenarioType); + } + } + } + } else { + String[] split = param.split(","); + logger.info("splitDateAndPush方法正在执行主要的逻辑 开始时间:{} 结束时间:{}", split[0], split[1]); + if (sceneType.equals(STOCK)) { + startImplementStockByTime(split[0], split[1], pushScenarioType); + } else if (sceneType.equals(TRAN)) { + startImplementByTradeTime(split[0], split[1], pushScenarioType); + } + } + } catch (Exception e) { + logger.error("记录splitDateAndPush方法抛出的异常", e); + } + } + + /** + * 计算全天时间段 + * + * @author liuyang + */ + public List calculateCalculateEntireDayPeriod(String dateStr) { + List startAndEnd = new ArrayList<>(); + + String calculateYesterdayStr = null; + if (dateStr != null) { + calculateYesterdayStr = dateStr; + } else { + calculateYesterdayStr = calculateYesterdayDate();//拉取'昨天'的日期 + } + logger.info("OFS销售出库单同步U8C销售订单,目标拉取时间:" + calculateYesterdayStr); + + StartAndEndVo startAndEndVo = new StartAndEndVo(); + startAndEndVo.setStart_time(calculateYesterdayStr + " 00:00:00"); + startAndEndVo.setEnd_time(calculateYesterdayStr + " 23:59:59"); + startAndEnd.add(startAndEndVo); + +// for (int i = 0; i <= 23; i++) { +// String iStr = null; +// if (i <= 9) { +// iStr = "0" + i; +// } else { +// iStr = String.valueOf(i); +// } +// String startTime = calculateYesterdayStr + " " + iStr + ":00:00"; +// String endTime = calculateYesterdayStr + " " + iStr + ":59:59"; +// +// StartAndEndVo startAndEndVo = new StartAndEndVo(); +// startAndEndVo.setStart_time(startTime); +// startAndEndVo.setEnd_time(endTime); +// startAndEnd.add(startAndEndVo); +// } + return startAndEnd; + } + + /** + * 计算昨天的单据日期,基于定时器在凌晨5分执行的情况下 + * + * @author liuyang + */ + public String calculateYesterdayDate() { + DateTime yesterdayDate = DateUtil.yesterday(); + return DateUtil.format(yesterdayDate, "yyyy-MM-dd"); + } + + /** + * 计算时间范围对应的字符串集合 + * + * @author liuyang + */ + private List getDateRange(LocalDate startDate, LocalDate endDate) { + List dateRange = new ArrayList<>(); + LocalDate currentDate = startDate; + while (!currentDate.isAfter(endDate)) { + dateRange.add(currentDate.format(DateTimeFormatter.ISO_DATE)); + currentDate = currentDate.plusDays(1); + } + return dateRange; + } + + /** + * 累加平台优惠 + * + * @param sonDetailsDtoList OFS售后入库单 + * @author liuyang + */ + private void accumulationDiscountAmount(List sonDetailsDtoList) throws Exception { + Assert.notNull(sonDetailsDtoList, "sonDetailsDtoList不能为空"); + + if (sonDetailsDtoList.size() > 0) { + BigDecimal totalShareTargetPlatformDiscounts = new BigDecimal("0"); + BigDecimal totalShareTargetMerchantDiscounts = new BigDecimal("0"); + BigDecimal totalShareTargetExpertDiscounts = new BigDecimal("0"); + BigDecimal totalShareTargetPayDiscounts = new BigDecimal("0"); + + for (int i = 0; i < sonDetailsDtoList.size(); i++) { + //OFS售后入库单表体 + GoodsRertunSonDetailsDto goodsRertunSonDetailsDto = sonDetailsDtoList.get(i); + //OFS售后入库单表头 + StockinOrderSearchResponse.StockinOrder.StockinH header1 = goodsRertunSonDetailsDto.getHeader(); + Assert.notNull(header1, "OFS售后入库单表头不能为空!"); + //OFS售后订单 + RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = header1.getRerturnGoodsOrderSearchData(); + Assert.notNull(rerturnGoodsOrderSearchData, "通过OFS售后入库单号无法关联批量到OFS售后订单! OFS售后入库单编码:{} OFS售后订单号:{}", header1.getCode(), header1.getRefOrderCode()); + RerturnGoodsOrderSearchHeader header = rerturnGoodsOrderSearchData.getHeader(); + List details = rerturnGoodsOrderSearchData.getDetails(); + + //四舍五入保留2位 + RerturnGoodsOrderSearchDetails ofsOrderDetail = findOfsOrderDetail(details, goodsRertunSonDetailsDto); + if (ofsOrderDetail.getShareTargetPlatformDiscounts() != null) { + totalShareTargetPlatformDiscounts = totalShareTargetPlatformDiscounts.add(ofsOrderDetail.getShareTargetPlatformDiscounts()); + } + if (ofsOrderDetail.getShareTargetMerchantDiscounts() != null) { + totalShareTargetMerchantDiscounts = totalShareTargetMerchantDiscounts.add(ofsOrderDetail.getShareTargetMerchantDiscounts()); + } + if (ofsOrderDetail.getShareTargetExpertDiscounts() != null) { + totalShareTargetExpertDiscounts = totalShareTargetExpertDiscounts.add(ofsOrderDetail.getShareTargetExpertDiscounts()); + } + if (ofsOrderDetail.getShareTargetPayDiscounts() != null) { + totalShareTargetPayDiscounts = totalShareTargetPayDiscounts.add(ofsOrderDetail.getShareTargetPayDiscounts()); + } + logger.info("对应的售后入库单明细行主键:{}", goodsRertunSonDetailsDto.getId()); + } + + GoodsRertunSonDetailsDto goodsRertunSonDetailsDto = sonDetailsDtoList.get(0); + StockinOrderSearchResponse.StockinOrder.StockinH header = goodsRertunSonDetailsDto.getHeader(); + + goodsRertunSonDetailsDto.setVdef4(totalShareTargetPlatformDiscounts.setScale(2, BigDecimal.ROUND_HALF_UP)); + goodsRertunSonDetailsDto.setVdef5(totalShareTargetMerchantDiscounts.setScale(2, BigDecimal.ROUND_HALF_UP)); + goodsRertunSonDetailsDto.setVdef6(totalShareTargetExpertDiscounts.setScale(2, BigDecimal.ROUND_HALF_UP)); + goodsRertunSonDetailsDto.setVdef7(totalShareTargetPayDiscounts.setScale(2, BigDecimal.ROUND_HALF_UP)); + + logger.info("售后入库明细主键:{} 售后入库单号:{} 最终汇总好的平台优惠:{}、支付优惠:{}、达人优惠:{}、商家优惠:{}", goodsRertunSonDetailsDto.getId(), header.getCode(), goodsRertunSonDetailsDto.getVdef4(), goodsRertunSonDetailsDto.getVdef5(), goodsRertunSonDetailsDto.getVdef6(), goodsRertunSonDetailsDto.getVdef7()); + } else { + logger.info("accumulationDiscountAmount方法对应的sonDetailsDtoList.size为零!"); + } + } + + /** + * 根据OFS售后入库单明细行,查找匹配OFS售后订单明细行 + * + * @param details OFS售后订单明细行 + * @param goodsRertunSonDetailsDto OFS售后入库单明细对象 + * @author liuyang + */ + private RerturnGoodsOrderSearchDetails findOfsOrderDetail(List details, GoodsRertunSonDetailsDto goodsRertunSonDetailsDto) { + Assert.notNull(details, "details不能为空"); + Assert.notNull(goodsRertunSonDetailsDto, "goodsRertunSonDetailsDto不能为空"); + + for (int i = 0; i < details.size(); i++) { + RerturnGoodsOrderSearchDetails rerturnGoodsOrderSearchDetails = details.get(i); + if (goodsRertunSonDetailsDto.getRefOrderDetailId() != null && rerturnGoodsOrderSearchDetails.getId() != null) { + if (goodsRertunSonDetailsDto.getRefOrderDetailId().equals(rerturnGoodsOrderSearchDetails.getId())) { + return rerturnGoodsOrderSearchDetails; + } + } + } + Assert.state(false, "根据OFS售后入库单明细行,无法查找OFS售后订单明细行 来源明细行主键:{} 来源单据主键:{}", goodsRertunSonDetailsDto.getRefOrderDetailId(), goodsRertunSonDetailsDto.getRefOrderId()); + return null; + } + + /** + * 初始化所有存货管理档案对应的结存价、采购价 + * + * @author liuyang + */ + private List initAllBalancePricePurchasePrice() throws Exception { + List mapList = new ArrayList<>(); + Map stringIaPeriodaccountEntityMap = balanceUnitPriceUtil.initBalancePrice(); + Map stringPoOrderBEntityMap = balanceUnitPriceUtil.initPurchasePrice(); + mapList.add(stringIaPeriodaccountEntityMap); + mapList.add(stringPoOrderBEntityMap); + return mapList; + } + + /** + * 获取结存金额或者采购金额 + * + * @param isCheckShopChoose true取OFS实付金额、false取结存金额或者采购价 + * @param bdInvmandocEntity 存货基本档案 + * @param header 对应的销售入库单表头 + * @param sonDetailsDto 对应的销售入库单明细行对象 + * @param mapList 索引为0结存价为1采购价 + * @author liuyang + */ + 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; + if (mapList != null && mapList.size() > 0) { + Map stringIaPeriodaccountEntityMap = (Map) mapList.get(0); + iaPeriodaccountEntity1 = stringIaPeriodaccountEntityMap.get(bdInvmandocEntity.getPkInvmandoc()); + } + if (iaPeriodaccountEntity1 != null) { + //取结存价 + logger.info("店铺:{} 取O结存价", header.getStoreCode()); + calculationFormulaStr.append("取结存价:"); + + //结存金额 + String nabmny = iaPeriodaccountEntity1.getNabmny(); + if (nabmny == null || "".equals(nabmny)) { + nabmny = "0"; + } + BigDecimal nabmnyBigDecimal = new BigDecimal(nabmny); + + //结存数量 + String nabnum = iaPeriodaccountEntity1.getNabnum(); + if (nabnum == null || "".equals(nabnum)) { + nabnum = "0"; + } + BigDecimal nabnumBigDecimal = new BigDecimal(nabnum); + + if (!"0".equals(nabmnyBigDecimal.stripTrailingZeros().toPlainString()) && !"0".equals(nabnumBigDecimal.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); + if (poOrderBEntityList != null && poOrderBEntityList.size() > 0) { + poOrderBEntity = poOrderBEntityList.get(bdInvmandocEntity.getPkInvmandoc()); + } + } + if (poOrderBEntity != null) { + String norgtaxprice = poOrderBEntity.getNorgtaxprice(); + 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"; + calculationFormulaStr.append("0"); + } + } else { + Assert.state(false, "店铺:{} 存货管理档案主键:{} 既没有结存价、也没有采购价!", header.getStoreCode(), bdInvmandocEntity.getPkInvmandoc()); + } + } + } + return totalPayAmount; + } + + /** + * 累加应收金额=实退金额+达人优惠+支付优惠+平台优惠 + * + * @param goodsRertunSonDetailsDto OFS售后入库单明细行 + * @param rerturnGoodsOrderSearchData OFS售后订单 + * @param calculationFormulaStr 计算公式 + * @author liuyang + */ + 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(); + + //O售后订单表头+明细行 + RerturnGoodsOrderSearchHeader header = rerturnGoodsOrderSearchData.getHeader(); + List details = rerturnGoodsOrderSearchData.getDetails(); + + //根据「入库单明细」匹配「售后订单明细行」 + RerturnGoodsOrderSearchDetails targetDetails = null; + for (int i = 0; i < details.size(); i++) { + RerturnGoodsOrderSearchDetails rerturnGoodsOrderSearchDetails = details.get(i); + if (goodsRertunSonDetailsDto.getRefOrderDetailId() != null && rerturnGoodsOrderSearchDetails.getId() != null) { + if (rerturnGoodsOrderSearchDetails.getId().equals(goodsRertunSonDetailsDto.getRefOrderDetailId())) { + targetDetails = rerturnGoodsOrderSearchDetails; + } + } + } + Assert.notNull(targetDetails, "根据OFS售后入库单细行(refOrderDetailId)无法匹配售后订单明细行", goodsRertunSonDetailsDto.getRefOrderDetailId()); + + //售后订单明细行-退货金额 + String totalAmount = targetDetails.getTotalAmount();//实退金额 + Assert.notNull(totalAmount, "售后订单:{} 存货明细行:{} 退货金额不能为空!", header.getCode(), targetDetails.getSkuCode()); + Assert.state(!"".equals(totalAmount), "售后订单:{} 存货明细行:{} 退货金额不能为空!", header.getCode(), targetDetails.getSkuCode()); + //售后订单明细行-请求数量 + //实退数量存在可能为0的情况,如果用退货金额/实退数量可能会抛出异常 + String requestQty = targetDetails.getRequestQty();//请求数量 + Assert.notNull(requestQty, "售后订单:{} 存货明细行:{} 请求数量不能为空!", header.getCode(), targetDetails.getSkuCode()); + Assert.state(!"".equals(requestQty), "售后订单:{} 存货明细行:{} 请求数量不能为空!", header.getCode(), targetDetails.getSkuCode()); + + //测试 +// goodsRertunSonDetailsDto.setReceivedQty("1"); + + String receivedQty = goodsRertunSonDetailsDto.getReceivedQty(); + Assert.notNull(receivedQty, "售后订单:{} 存货明细行:{} 请求数量不能为空!", header1.getCode(), goodsRertunSonDetailsDto.getId()); + Assert.state(!"".equals(receivedQty), header1.getCode(), goodsRertunSonDetailsDto.getId()); + if ("0".equals(new BigDecimal(receivedQty).stripTrailingZeros().toPlainString())) { + Assert.state(false, "售后订单:{} 存货明细行:{} 实退数量不能为0!", header1.getCode(), goodsRertunSonDetailsDto.getId()); + } + //O含税单价=通过退货金额/请求数量 + BigDecimal unitPriceIncludingTax = new BigDecimal(totalAmount).divide(new BigDecimal(requestQty), 20, BigDecimal.ROUND_HALF_UP); + //实退金额=O含税单价*(O售后入库单)这里保留 4 位小数的用途是便于暴露问题给后续方法,后续方法会变成 2 位小数(0.0034) + BigDecimal actualRefundAmount = unitPriceIncludingTax.multiply(new BigDecimal(receivedQty)).setScale(4, BigDecimal.ROUND_HALF_UP); + //出库对应的实退=含税单价(actualRefundAmount)*出库单实退数量 +// BigDecimal actualRefundAmountBigDecimal = new BigDecimal(receivedQty).multiply(actualRefundAmount).setScale(2, BigDecimal.ROUND_HALF_UP); + String format = StrUtil.format("{}/{}*{}", totalAmount, requestQty, receivedQty); + calculationFormulaStr.append(format); + +// //商家优惠:不处理!!!仅保存 +// String merchantDiscounts = targetDetails.getMerchantDiscounts(); +// //达人优惠 +// String expertDiscounts = targetDetails.getExpertDiscounts(); +// //支付优惠 +// String payDiscounts = targetDetails.getPayDiscounts(); +// //平台优惠 +// String platformDiscounts = targetDetails.getPlatformDiscounts(); +// +// BigDecimal totalBigDecimal = new BigDecimal("0");//相加总和 +// BigDecimal totalPayAmountBigDecimal = new BigDecimal("0");//实退金额 +// BigDecimal expertDiscountsBigDecimal = new BigDecimal("0");//达人优惠 +// BigDecimal payDiscountsBigDecimal = new BigDecimal("0");//支付优惠 +// BigDecimal platformDiscountsBigDecimal = new BigDecimal("0");//平台优惠 +// +// if (actualRefundAmount != null) { +// totalPayAmountBigDecimal = actualRefundAmount; +// } +// if (expertDiscounts != null && !"".equals(expertDiscounts)) { +// expertDiscountsBigDecimal = new BigDecimal(expertDiscounts); +// } +// if (payDiscounts != null && !"".equals(payDiscounts)) { +// payDiscountsBigDecimal = new BigDecimal(payDiscounts); +// } +// if (platformDiscounts != null && !"".equals(platformDiscounts)) { +// platformDiscountsBigDecimal = new BigDecimal(platformDiscounts); +// } +// +// //总和累加 +// totalBigDecimal = totalBigDecimal.add(totalPayAmountBigDecimal); +// totalBigDecimal = totalBigDecimal.add(expertDiscountsBigDecimal); +// totalBigDecimal = totalBigDecimal.add(payDiscountsBigDecimal); +// totalBigDecimal = totalBigDecimal.add(platformDiscountsBigDecimal); +// return totalBigDecimal.stripTrailingZeros().toPlainString(); + return actualRefundAmount.stripTrailingZeros().toPlainString(); + } + + /** + * 累加优惠金额,放在自定义项里最后传给U8C + * + * @param sonDetailsDtoList OFS售后入库单明细行List集合(按纬度汇总好的) + * @author liuyang + */ + private void accumulatedDiscountAmountDef(List sonDetailsDtoList) throws Exception { + Assert.notNull(sonDetailsDtoList, "sonDetailsDtoList不能为空"); + + if (sonDetailsDtoList.size() > 0) { + BigDecimal platformDiscountsBigDecimal = new BigDecimal("0");//平台 + BigDecimal merchantDiscountsBigDecimal = new BigDecimal("0");//商家 + BigDecimal expertDiscountsBigDecimal = new BigDecimal("0");//达人 + BigDecimal payDiscountsBigDecimal = new BigDecimal("0");//支付 + for (int i = 0; i < sonDetailsDtoList.size(); i++) { + GoodsRertunSonDetailsDto goodsRertunSonDetailsDto = sonDetailsDtoList.get(i); + StockinOrderSearchResponse.StockinOrder.StockinH header = goodsRertunSonDetailsDto.getHeader();//O售后入库单表头 + RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = header.getRerturnGoodsOrderSearchData();//OFS售后订单 + + Assert.notNull(rerturnGoodsOrderSearchData, "O售后订单不能为空 O售后入库单编码:{}", header.getCode()); + List details = rerturnGoodsOrderSearchData.getDetails();//OFS售后订单明细行 + if (details != null && details.size() > 0) { + for (int j = 0; j < details.size(); j++) { + RerturnGoodsOrderSearchDetails rerturnGoodsOrderSearchDetails = details.get(j); + if (goodsRertunSonDetailsDto.getRefOrderDetailId() != null && rerturnGoodsOrderSearchDetails.getId() != null) { + if (goodsRertunSonDetailsDto.getRefOrderDetailId().equals(rerturnGoodsOrderSearchDetails.getId())) { + //累加优惠 + String platformDiscounts = rerturnGoodsOrderSearchDetails.getPlatformDiscounts(); + String merchantDiscounts = rerturnGoodsOrderSearchDetails.getMerchantDiscounts(); + String expertDiscounts = rerturnGoodsOrderSearchDetails.getExpertDiscounts(); + String payDiscounts = rerturnGoodsOrderSearchDetails.getPayDiscounts(); + + if (platformDiscounts == null || "".equals(platformDiscounts.trim())) { + platformDiscounts = "0"; + } + if (merchantDiscounts == null || "".equals(merchantDiscounts.trim())) { + merchantDiscounts = "0"; + } + if (expertDiscounts == null || "".equals(expertDiscounts.trim())) { + expertDiscounts = "0"; + } + if (payDiscounts == null || "".equals(payDiscounts.trim())) { + payDiscounts = "0"; + } + + platformDiscountsBigDecimal = platformDiscountsBigDecimal.add(new BigDecimal(platformDiscounts)); + merchantDiscountsBigDecimal = merchantDiscountsBigDecimal.add(new BigDecimal(merchantDiscounts)); + expertDiscountsBigDecimal = expertDiscountsBigDecimal.add(new BigDecimal(expertDiscounts)); + payDiscountsBigDecimal = payDiscountsBigDecimal.add(new BigDecimal(payDiscounts)); + } + } + } + } + } + sonDetailsDtoList.get(0).setVdef4(platformDiscountsBigDecimal);//平台 + sonDetailsDtoList.get(0).setVdef5(payDiscountsBigDecimal);//支付 + sonDetailsDtoList.get(0).setVdef6(expertDiscountsBigDecimal);//达人 + sonDetailsDtoList.get(0).setVdef7(merchantDiscountsBigDecimal);//商家 + } + } + + /** + * 获取参考售价 + * + * @param bdInvmandocEntity 存货管理档案 + * @param bdInvbasdocEntity 存货基本档案 + * @param calculationFormulaStr 计算公式 + * @param goodsRertunSonDetailsDto O售后入库单明细行 + * @param header O售后入库单表头 + * @author liuyang + */ + private String getRefsaleprice(BdInvmandocEntity bdInvmandocEntity, BdInvbasdocEntity bdInvbasdocEntity, StringBuffer calculationFormulaStr, GoodsRertunSonDetailsDto goodsRertunSonDetailsDto, StockinOrderSearchResponse.StockinOrder.StockinH header) throws Exception { + Assert.notNull(bdInvmandocEntity, "bdInvmandocEntity不能为空!"); + Assert.notNull(bdInvbasdocEntity, "bdInvbasdocEntity不能为空!"); + Assert.notNull(calculationFormulaStr, "calculationFormulaStr不能为空!"); + Assert.notNull(goodsRertunSonDetailsDto, "goodsRertunSonDetailsDto不能为空!"); + Assert.notNull(header, "header不能为空"); + + //U参考售价 + String refsaleprice = bdInvmandocEntity.getRefsaleprice(); + Assert.notNull(refsaleprice, "存货:{} 公司:{} 不存在参考售价,请维护!", bdInvbasdocEntity.getInvname(), bdInvmandocEntity.getPkCorp()); + + //O实收数量 + String receivedQty = goodsRertunSonDetailsDto.getReceivedQty(); + Assert.notNull(receivedQty, "O实收数量不能为空 O售后入库单编码:{} O明细行主键:{}", header.getCode(), goodsRertunSonDetailsDto.getId()); + Assert.state(!"".equals(receivedQty), "O实收数量不能为空 O售后入库单编码:{} O明细行主键:{}", header.getCode(), goodsRertunSonDetailsDto.getId()); + + BigDecimal amountOfMoney = new BigDecimal(refsaleprice).multiply(new BigDecimal(receivedQty)); + String format = StrUtil.format("取U参考售价:{}*{}", refsaleprice, receivedQty); + calculationFormulaStr.append(format); + return amountOfMoney.stripTrailingZeros().toPlainString(); + } + + /** + * 查询OFS底表的O售后入库单数据 + * + * @author liuyang + */ + public List queryTocofsReturngoodsDetailed(TocofsReturngoodsDetailedEntity tocofsReturngoodsDetailedEntity) throws Exception { + Assert.notNull(tocofsReturngoodsDetailedEntity, "tocofsReturngoodsDetailedEntity不能为空"); + + //底表O售后入库单表头对象 + List allTocofsReturngoodsEntityList = new ArrayList<>(); + //底表O售后入库单明细行 + List tocofsReturngoodsDetailedEntityList = iTocofsReturngoodsDetailedDao.query(tocofsReturngoodsDetailedEntity); + if (tocofsReturngoodsDetailedEntityList != null && tocofsReturngoodsDetailedEntityList.size() > 0) { + Set mainTableIdSet = tocofsReturngoodsDetailedEntityList.stream().map(TocofsReturngoodsDetailedEntity::getMaintableid).collect(Collectors.toSet()); + List mainTableIdList = Lists.newArrayList(mainTableIdSet); + + List> splitListByCount = SplitListByCountUtil.splitListByCount(mainTableIdList, 1000); +// List> splitListByCount = SplitListByCountUtil.splitListByCount(tocofsReturngoodsDetailedEntityList, 1000); + for (int i = 0; i < splitListByCount.size(); i++) { + List strings = splitListByCount.get(i); +// Set mainTableIdSet = tocofsReturngoodsDetailedEntityList1.stream().map(TocofsReturngoodsDetailedEntity::getMaintableid).collect(Collectors.toSet()); + String mainTableIds = strings.stream().map(id -> "'" + id + "'").collect(Collectors.joining(",")); + //查询对应的O售后入库单表头 + TocofsReturngoodsEntity tocofsReturngoodsEntity = new TocofsReturngoodsEntity(); + tocofsReturngoodsEntity.setIds(mainTableIds); + List tocofsReturngoodsEntityList = iTocofsReturngoodsDao.query(tocofsReturngoodsEntity); + allTocofsReturngoodsEntityList.addAll(tocofsReturngoodsEntityList); + } + } + + //通过「O售后入库单表头」匹配「O售后入库单明细」 + if (allTocofsReturngoodsEntityList.size() > 0) { + Map> stringListMap = convertToMap(tocofsReturngoodsDetailedEntityList); + for (int i = 0; i < allTocofsReturngoodsEntityList.size(); i++) { + TocofsReturngoodsEntity tocofsReturngoodsEntity = allTocofsReturngoodsEntityList.get(i); + //性能太差了,使用Map搜索 +// List tocofsReturngoodsDetailedEntityList1 = new ArrayList<>(); +// for (int j = 0; j < tocofsReturngoodsDetailedEntityList.size(); j++) { +// TocofsReturngoodsDetailedEntity tocofsReturngoodsDetailedEntity1 = tocofsReturngoodsDetailedEntityList.get(j); +// if (tocofsReturngoodsDetailedEntity1.getMaintableid().equals(tocofsReturngoodsEntity.getId())) { +// tocofsReturngoodsDetailedEntityList1.add(tocofsReturngoodsDetailedEntity1); +// } +// } +// tocofsReturngoodsEntity.setTocofsReturngoodsDetailedEntityList(tocofsReturngoodsDetailedEntityList1); + List tocofsReturngoodsDetailedEntities = stringListMap.get(tocofsReturngoodsEntity.getId()); + tocofsReturngoodsEntity.setTocofsReturngoodsDetailedEntityList(tocofsReturngoodsDetailedEntities); + } + } + + //转换为OFS售后入库单对象 + List returnGoodHeaderDetailsDataDtoArrayList = new ArrayList<>(); + if (allTocofsReturngoodsEntityList.size() > 0) { + for (int i = 0; i < allTocofsReturngoodsEntityList.size(); i++) { + + StockinOrderSearchResponse.StockinOrder stockinOrder = new StockinOrderSearchResponse.StockinOrder(); + returnGoodHeaderDetailsDataDtoArrayList.add(stockinOrder); + + //处理表头 + TocofsReturngoodsEntity tocofsReturngoodsEntity = allTocofsReturngoodsEntityList.get(i); + StockinOrderSearchResponse.StockinOrder.StockinH stockinH = new StockinOrderSearchResponse.StockinOrder.StockinH(); + stockinH.setId(tocofsReturngoodsEntity.getId()); + BeanUtil.copyPropertiesV2(tocofsReturngoodsEntity, stockinH); + stockinOrder.setHeader(stockinH); + + //处理明细行 + List tocofsReturngoodsDetailedEntityList1 = tocofsReturngoodsEntity.getTocofsReturngoodsDetailedEntityList(); + List stockinB = new ArrayList<>(); + stockinOrder.setDetails(stockinB); + for (int j = 0; j < tocofsReturngoodsDetailedEntityList1.size(); j++) { + TocofsReturngoodsDetailedEntity tocofsReturngoodsDetailedEntity1 = tocofsReturngoodsDetailedEntityList1.get(j); + + StockinOrderSearchResponse.StockinOrder.StockinB stockinB1 = new StockinOrderSearchResponse.StockinOrder.StockinB(); + BeanUtil.copyPropertiesV2(tocofsReturngoodsDetailedEntity1, stockinB1); + stockinB1.setId(tocofsReturngoodsDetailedEntity1.getId()); + stockinB.add(stockinB1); + } + } + } + return returnGoodHeaderDetailsDataDtoArrayList; + } + + /** + * 存在相同Maintableid汇总在一起 + * + * @author liuyang + */ + public static Map> convertToMap(List tocofsReturngoodsDetailedEntityList) { + Map> map = new HashMap<>(); + for (TocofsReturngoodsDetailedEntity entity : tocofsReturngoodsDetailedEntityList) { + String maintableid = entity.getMaintableid(); + map.computeIfAbsent(maintableid, k -> new ArrayList<>()).add(entity); + } + return map; + } + + /** + * 如果售后入库单对应的售后订单状态为售中节点,则过滤掉不传递 + * + * @throws Exception 抛出可能的异常 + * @author liuyang + */ + public List filterForSale(List returnGoodHeaderDetailsDataDtoList1) throws Exception { + List filteredList = null; + if (returnGoodHeaderDetailsDataDtoList1 != null && returnGoodHeaderDetailsDataDtoList1.size() > 0) { + filteredList = returnGoodHeaderDetailsDataDtoList1.stream().filter(stockinOrder -> { + StockinOrderSearchResponse.StockinOrder.StockinH header = stockinOrder.getHeader(); + if (header == null) { + // 如果 StockinH 为空,保留该对象 + return true; + } + RerturnGoodsOrderSearchData returnData = header.getRerturnGoodsOrderSearchData(); + if (returnData == null || returnData.getHeader() == null) { + // 如果 RerturnGoodsOrderSearchData 为空,保留该对象 + return true; + } + if (returnData.getHeader().getReturnNode() == null) { + // 如果 RerturnGoodsOrderSearchData 为空,保留该对象 + return true; + } + // 检查 returnNode 是否不等于 200,若不等于则保留 + return !"200".equals(returnData.getHeader().getReturnNode().trim()); + }).collect(Collectors.toList()); + } + return filteredList; + } +} \ No newline at end of file diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/QueryAdditionUtil.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/QueryAdditionUtil.java index 3e64b730..3124df2b 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/QueryAdditionUtil.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/QueryAdditionUtil.java @@ -228,4 +228,60 @@ public class QueryAdditionUtil { } // } } + + /** + * 增加平台运费,优惠金额这些存货一起保存进U8C销售订单 + * + * @param bdInvmandocEntity1 存货管理档案 + * @param bdInvbasdocEntity1 存货基本档案 + * @param pushScenarioType 需要推送给U8C红字应收单明细行表体 + * @param noriginalcursummny 价税合计(只能传金额) + * @param bdTaxitemsEntity 存货对应的税率 + * @author liuyang + */ + public void additionalV3(List pushScenarioType, BdInvmandocEntity bdInvmandocEntity1, BdInvbasdocEntity bdInvbasdocEntity1, BigDecimal noriginalcursummny, BdTaxitemsEntity bdTaxitemsEntity) { + Assert.notNull(pushScenarioType, "pushScenarioType不能为空!"); + Assert.notNull(bdInvmandocEntity1, "bdInvmandocEntity1不能为空"); + Assert.notNull(bdInvbasdocEntity1, "bdInvbasdocEntity1不能为空"); + Assert.notNull(noriginalcursummny, "noriginalcursummny不能为空"); + + //如果size=0则不正常 +// if (pushScenarioType.size() > 0) { +// ArapDjzbVO.Childrenn childrenn = pushScenarioType.get(0); + + //拷贝SaleorderRequestChildrenDto对象 + ArapDjzbVO.Childrenn arapDjzbVOChildrenn = new ArapDjzbVO.Childrenn(); +// BeanUtil.copyPropertiesV2(childrenn, arapDjzbVOChildrenn); + + //修改存货、数量、税率、价税合计、优惠金额设置为0 + //存货id、存货编码 + arapDjzbVOChildrenn.setCinventoryid(bdInvbasdocEntity1.getInvcode()); + +// String tax = null;//税率 +// BigDecimal noriginalcurmny = null;//无税金额 +// BigDecimal noriginalcurtaxmny = null;//税额 +// try { +// tax = new BigDecimal(bdTaxitemsEntity.getTaxratio()).divide(new BigDecimal(100), 20, BigDecimal.ROUND_HALF_UP).setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString(); +// noriginalcurmny = noriginalcursummny.divide(new BigDecimal(1).add(new BigDecimal(tax)), 20, BigDecimal.ROUND_HALF_UP).setScale(2, BigDecimal.ROUND_HALF_UP); +// noriginalcurtaxmny = noriginalcursummny.subtract(noriginalcurmny).setScale(2, BigDecimal.ROUND_HALF_UP); +// } catch (Exception e) { +// logger.error("金额计算失败", e); +// Assert.state(false, "金额计算失败 异常:{}", e.getMessage()); +// } + + //金额计算 + arapDjzbVOChildrenn.setJfbbje(noriginalcursummny.stripTrailingZeros().toPlainString());//借方本币金额 + arapDjzbVOChildrenn.setJfybje(noriginalcursummny.stripTrailingZeros().toPlainString());//借方原币金额 +// arapDjzbVOChildrenn.setJfbbsj(noriginalcurmny.stripTrailingZeros().toPlainString());//借方本币税金 +// arapDjzbVOChildrenn.setJfybsj(noriginalcurmny.stripTrailingZeros().toPlainString());//借方原币税金 +// arapDjzbVOChildrenn.setWbfbbje(noriginalcurtaxmny.stripTrailingZeros().toPlainString());//借方本币无税金额 +// arapDjzbVOChildrenn.setJfybwsje(noriginalcurtaxmny.stripTrailingZeros().toPlainString());//借方原币无税金额 + + //2025年2月17日 10:37:37 如果四舍五入保留2位后,如果为0,则不推送U8C,处理0.0033保留2位为0的问题 + //和李佳妮、还有丽知-山海沟通确定的 + if (!"0".equals(noriginalcursummny.setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString())) { + pushScenarioType.add(arapDjzbVOChildrenn); + } +// } + } } 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 0da58e0d..313dc52b 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 @@ -89,7 +89,7 @@ public class SoSaleOutPluginInitializerToBTest { // soSaleOutPluginInitializerToB.startImplementByStockTime("2024-10-31 14:48:41", "2024-10-31 14:48:41"); - soSaleOutPluginInitializerToB.startImplementByCode("LETS-SH2025020600020284", "tran"); + soSaleOutPluginInitializerToB.startImplementByCode("LETS-SH2025031200015584", "stock"); // soSaleOutPluginInitializerToB.startImplementByStockTime("2024-11-08 19:18:02", "2024-11-08 19:18:02"); diff --git a/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToCTest.java b/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToCTest.java index 0b9c772f..c2a345bd 100644 --- a/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToCTest.java +++ b/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleReturnPluginInitializerToCTest.java @@ -36,7 +36,12 @@ public class SoSaleReturnPluginInitializerToCTest { public void startImplement() { // soSaleReturnPluginInitializerToC.startImplement(null, null); try { - String code = "LETS-RE2025022000001336"; + //带优惠金额场景 +// String code = "LETS-RE2025030100000112"; +// soSaleReturnPluginInitializerToC.startImplementByCode(code, "tran"); + + //无优惠金额场景 + String code = "LETS-RE2025031900000002"; soSaleReturnPluginInitializerToC.startImplementByCode(code, "tran"); } catch (Exception e) { e.printStackTrace(); @@ -72,7 +77,7 @@ public class SoSaleReturnPluginInitializerToCTest { // String s = soSaleReturnPluginInitializerToC.timeJudgment(header2); // System.out.println(s); - soSaleReturnPluginInitializerToC.u8cOperationFlow(); +// soSaleReturnPluginInitializerToC.u8cOperationFlow(); } catch (Exception e) { e.printStackTrace(); }