diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/RefundOnlyPluginInitializer.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/RefundOnlyPluginInitializer.java index 14c4de86..a4f6ab85 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/RefundOnlyPluginInitializer.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/RefundOnlyPluginInitializer.java @@ -219,6 +219,7 @@ public class RefundOnlyPluginInitializer extends PluginBaseEntity { /** * 退款时间区间 + * * @param startTime * @param endTime */ @@ -259,7 +260,7 @@ public class RefundOnlyPluginInitializer extends PluginBaseEntity { /** * 保存数据 */ - public void saveData(List refundOnlyData){ + public void saveData(List refundOnlyData) { //过滤原始表 List filterOriginalOrders = filterOriginal(refundOnlyData); //底表存数据库 @@ -267,6 +268,7 @@ public class RefundOnlyPluginInitializer extends PluginBaseEntity { save(filterOriginalOrders); } } + /** * 过滤元数据底表,只过滤表头 * @@ -290,14 +292,15 @@ public class RefundOnlyPluginInitializer extends PluginBaseEntity { /** * returnType:0 不退货、exchangeType:0 不换货、refundInd:1 退款 + * * @param rerturnGoodsOrderSearchData * @return */ - public List filterRefundOnly(List rerturnGoodsOrderSearchData){ + public List filterRefundOnly(List rerturnGoodsOrderSearchData) { List filterRefundOnly = new ArrayList<>(); for (RerturnGoodsOrderSearchData rerturnGoodsOrderSearchDatum : rerturnGoodsOrderSearchData) { RerturnGoodsOrderSearchHeader header = rerturnGoodsOrderSearchDatum.getHeader(); - if("0".equals(header.getReturnType())&&"0".equals(header.getExchangeType())&&"1".equals(header.getRefundInd())){ + if ("0".equals(header.getReturnType()) && "0".equals(header.getExchangeType()) && "1".equals(header.getRefundInd())) { filterRefundOnly.add(rerturnGoodsOrderSearchDatum); } } @@ -395,7 +398,7 @@ public class RefundOnlyPluginInitializer extends PluginBaseEntity { ArapDjzbVO.Parentt parentvo = new ArapDjzbVO.Parentt(); //djrq 单据日期 format = split[3];//暂时取创建时间,refundAt没返回 - format = "2024-09-27"; + format = "2024-09-29"; parentvo.setDjrq(format); //dwbm 公司 parentvo.setDwbm(split[0]); @@ -420,6 +423,9 @@ public class RefundOnlyPluginInitializer extends PluginBaseEntity { parentvo.setDjlxbm("D0"); //xslxbm 业务流程 parentvo.setXslxbm("JTK");//TOC仅退款 + //feinvstatus 开票状态 + parentvo.setFeinvstatus("0"); + //zyx1店铺 parentvo.setZyx1(split[1]); @@ -427,9 +433,10 @@ public class RefundOnlyPluginInitializer extends PluginBaseEntity { parentvo.setZyx2(v.get(0).getSourcePlatformCode()); //zyx3 收发类别 销售出库,写死:SALES parentvo.setZyx3("SALES"); + //zyx16 单据红字标识 1Y 2N + parentvo.setZyx16("1"); //子表,需要通过多个主表的id找到多个子表,且退货金额==0的不要 - List children = new ArrayList<>(); List ofsDetails = new ArrayList<>(); for (RerturnGoodsOrderSearchHeader rerturnGoodsOrderSearchHeader : v) { allDetail.stream().forEach(index -> { @@ -440,94 +447,153 @@ public class RefundOnlyPluginInitializer extends PluginBaseEntity { } logDetails.addAll(ofsDetails); + List children = new ArrayList<>(); - for (RerturnGoodsOrderSearchDetails ofsDetail : ofsDetails) { - ArapDjzbVO.Childrenn childrenn = new ArapDjzbVO.Childrenn(); + //按sku分组 + Map> collectSKU = ofsDetails.stream().collect(Collectors.groupingBy(index -> index.getSkuCode())); - //ddh 订单号 - childrenn.setDdh(ofsDetail.getReturnOrderCode()); + Set>> entries = collectSKU.entrySet(); + for (Map.Entry> entry : entries) { + children.clear(); + String kk = entry.getKey(); + List vv = entry.getValue(); + //kk是sku编码,vv是sku相同的子表 + try { + ArapDjzbVO.Childrenn childrenn = new ArapDjzbVO.Childrenn(); + //cinventoryid 存货 + childrenn.setCinventoryid(kk); + + //sum:jfbbje jfybje 借方本币金额/借方原币金额 + BigDecimal sum_jfbbje = new BigDecimal(0); + //sum:jfbbsj jfybsj 借方本币税金/借方原币税金 默认(0.13) + BigDecimal sum_jfbbsj = new BigDecimal(0); + //sum:wbfbbje jfybwsje 借方本币无税金额/借方原币无税金额 + BigDecimal sum_wbfbbje = new BigDecimal(0); + //sum:zyx4 平台优惠 + BigDecimal sum_zyx4 = new BigDecimal(0); + //sum:zyx5 支付优惠 + BigDecimal sum_zyx5 = new BigDecimal(0); + //sum:zyx6 达人优惠 + BigDecimal sum_zyx6 = new BigDecimal(0); + //sum:zyx7 商家优惠 + BigDecimal sum_zyx7 = new BigDecimal(0); + + //金额计算 + for (RerturnGoodsOrderSearchDetails detail : vv) { + sum_jfbbje = sum_jfbbje.add(new BigDecimal(detail.getTotalAmount())); + + BigDecimal sj = new BigDecimal(detail.getTotalAmount()).multiply(new BigDecimal(0.13)).setScale(2, RoundingMode.FLOOR); + sum_jfbbsj = sum_jfbbsj.add(sj); + + BigDecimal ws = new BigDecimal(detail.getTotalAmount()).subtract(sj); + sum_wbfbbje = sum_wbfbbje.add(ws); + + if(detail.getShareTargetPlatformDiscounts()!=null){ + sum_zyx4 = sum_zyx4.add(detail.getShareTargetPlatformDiscounts()); + } + if(detail.getShareTargetMerchantDiscounts()!=null){ + sum_zyx5 = sum_zyx5.add(detail.getShareTargetMerchantDiscounts()); + } + if(detail.getShareTargetExpertDiscounts()!=null){ + sum_zyx6 = sum_zyx6.add(detail.getShareTargetExpertDiscounts()); + } + if(detail.getShareTargetPayDiscounts()!=null){ + sum_zyx7 = sum_zyx7.add(detail.getShareTargetPayDiscounts()); + } + } + childrenn.setJfbbje("-" + sum_jfbbje); + childrenn.setJfybje("-" + sum_jfbbje); + childrenn.setJfbbsj("-" + sum_jfbbsj); + childrenn.setJfybsj("-" + sum_jfbbsj); + childrenn.setWbfbbje("-" + sum_wbfbbje); + childrenn.setJfybwsje("-" + sum_wbfbbje); + childrenn.setZyx4(String.valueOf(sum_zyx4)); + childrenn.setZyx5(String.valueOf(sum_zyx5)); + childrenn.setZyx6(String.valueOf(sum_zyx6)); + childrenn.setZyx7(String.valueOf(sum_zyx7)); + children.add(childrenn); + + //推送 + arapDjzbVO.setParentvo(parentvo); + arapDjzbVO.setChildren(children); + System.out.println(arapDjzbVO); + mapStr = "{\"djzbvo\":[" + JSONUtil.toJsonStr(arapDjzbVO) + "]}"; + System.out.println(mapStr); + //推送 + ZTResult ztResult = pushU8CByApiCode.pushByCode(OverallConstant.getOverAllValue("arapYsInsertApproveCode"), mapStr); + //两层判断,一层中台转发,一层u8c返回 + if ("false".equals(ztResult.getFlag())) { + //转发失败 + response = JSONUtil.toJsonStr(ztResult.getAttribute()); + Assert.state(false, "丽知:售后订单(仅退款)--->U8C红字应收单,中台转发失败,失败原因:{}", ztResult.getAttribute()); + } + Attribute attribute = ztResult.getAttribute(); + System.out.println(attribute); + boolean isSuccess = false; + String djbh = ""; + String vouchid = ""; + if ("success".equals(attribute.getStatus())) { + isSuccess = true; + String data = attribute.getData(); + ArapDjzb arapDj = resultDataHandle(data); + System.out.println(arapDj); + djbh = arapDj.getParentvo().getDjbh(); + vouchid = arapDj.getParentvo().getVouchid(); + } + if (!isSuccess) { + Assert.state(false, "推送U8C--> 丽知:售后订单(仅退款)--->U8C红字应收单 失败 接口返回结果:{} 接口入参:{}", response, mapStr); + } + + //成功 + for (RerturnGoodsOrderSearchDetails ofsDetail : vv) { + IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = new IntegrationTaskLivingDetailsEntity(); + integrationTaskLivingDetailsEntity.setNewState(ProfilesActiveConstant.LOG_STATUS_Y); + integrationTaskLivingDetailsEntity.setRootAppNewData(mapStr); + integrationTaskLivingDetailsEntity.setNewTransmitInfo(response); + integrationTaskLivingDetailsEntity.setNewPushDate(new Date()); + integrationTaskLivingDetailsEntity.setBusinessDate(format); + integrationTaskLivingDetailsEntity.setRootAppPk(ofsDetail.getReturnOrderCode() + "_" + ofsDetail.getSkuCode()); + integrationTaskLivingDetailsEntity.setRootAppBill(ofsDetail.getReturnOrderCode());//仅退款单号 + integrationTaskLivingDetailsEntity.setNewSystemNumber(djbh); + integrationTaskLivingDetailsEntity.setNewSystemPrimary(vouchid); + integrationTaskLivingDetailsEntity.setPluginId(getPluginId()); + saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity); + } + } catch (Exception e) { + logger.error("推送U8C,丽知:售后订单(仅退款)--->U8C红字应收单失败,失败原因:" + e); + //失败,则该k下的所有子表记录失败 + ReusltStrDto reusltStrDto = JSON.parseObject(response, ReusltStrDto.class); + String ErrMessage = ""; + if (reusltStrDto != null) { + ErrMessage = "推送U8C,丽知:售后订单(仅退款)--->U8C红字应收单失败,失败原因:" + reusltStrDto.getErrormsg(); + } else { + ErrMessage = "推送U8C,丽知:售后订单(仅退款)--->U8C红字应收单失败,失败原因:" + e.getMessage(); + } + //失败 批量新增 ofsDetails + for (RerturnGoodsOrderSearchDetails logDetail : vv) { + IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = new IntegrationTaskLivingDetailsEntity(); + integrationTaskLivingDetailsEntity.setNewState(ProfilesActiveConstant.LOG_STATUS_N); + integrationTaskLivingDetailsEntity.setRootAppNewData(mapStr); + integrationTaskLivingDetailsEntity.setNewTransmitInfo(ErrMessage); + integrationTaskLivingDetailsEntity.setNewPushDate(new Date()); + integrationTaskLivingDetailsEntity.setBusinessDate(format); + integrationTaskLivingDetailsEntity.setRootAppPk(logDetail.getReturnOrderCode() + "_" + logDetail.getSkuCode()); + integrationTaskLivingDetailsEntity.setRootAppBill(logDetail.getReturnOrderCode()); + integrationTaskLivingDetailsEntity.setPluginId(getPluginId()); + saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity); + } + } - //cinventoryid 存货 - childrenn.setCinventoryid(ofsDetail.getSkuCode()); - //jfbbje jfybje 借方本币金额/借方原币金额 - childrenn.setJfbbje("-" + ofsDetail.getTotalAmount()); - childrenn.setJfybje("-" + ofsDetail.getTotalAmount()); - //jfbbsj jfybsj 借方本币税金/借方原币税金 默认(0.13) - BigDecimal sj = new BigDecimal(ofsDetail.getTotalAmount()).multiply(new BigDecimal(0.13)).setScale(2, RoundingMode.FLOOR); - childrenn.setJfbbsj("-" + String.valueOf(sj)); - childrenn.setJfybsj("-" + String.valueOf(sj)); - //wbfbbje jfybwsje 借方本币无税金额/借方原币无税金额 - BigDecimal ws = new BigDecimal(ofsDetail.getTotalAmount()).subtract(sj); - childrenn.setWbfbbje("-" + ws); - childrenn.setJfybwsje("-" + ws); - //zyx4 平台优惠 - childrenn.setZyx4(String.valueOf(ofsDetail.getShareTargetPlatformDiscounts())); - //zyx5 支付优惠 - childrenn.setZyx5(String.valueOf(ofsDetail.getShareTargetPlatformDiscounts())); - //zyx6 达人优惠 - childrenn.setZyx6(String.valueOf(ofsDetail.getShareTargetPlatformDiscounts())); - //zyx7 商家优惠 - childrenn.setZyx7(String.valueOf(ofsDetail.getShareTargetPlatformDiscounts())); - children.add(childrenn); } - - arapDjzbVO.setParentvo(parentvo); - arapDjzbVO.setChildren(children); - System.out.println(arapDjzbVO); - mapStr = "{\"djzbvo\":[" + JSONUtil.toJsonStr(arapDjzbVO) + "]}"; - System.out.println(mapStr); - - //推送 - ZTResult ztResult = pushU8CByApiCode.pushByCode(OverallConstant.getOverAllValue("arapYsInsertApproveCode"), mapStr); - //两层判断,一层中台转发,一层u8c返回 - if ("false".equals(ztResult.getFlag())) { - //转发失败 - response = JSONUtil.toJsonStr(ztResult.getAttribute()); - Assert.state(false, "丽知:售后订单(仅退款)--->U8C红字应收单,中台转发失败,失败原因:{}", ztResult.getAttribute()); - } - Attribute attribute = ztResult.getAttribute(); - System.out.println(attribute); - boolean isSuccess = false; - String djbh = ""; - String vouchid = ""; - if ("success".equals(attribute.getStatus())) { - isSuccess = true; - String data = attribute.getData(); - ArapDjzb arapDj = resultDataHandle(data); - System.out.println(arapDj); - djbh = arapDj.getParentvo().getDjbh(); - vouchid = arapDj.getParentvo().getVouchid(); - } - if (!isSuccess) { - Assert.state(false, "推送U8C--> 丽知:售后订单(仅退款)--->U8C红字应收单 失败 接口返回结果:{} 接口入参:{}", response, mapStr); - } - - //成功 批量新增 ofsDetails - for (RerturnGoodsOrderSearchDetails ofsDetail : ofsDetails) { - IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = new IntegrationTaskLivingDetailsEntity(); - integrationTaskLivingDetailsEntity.setNewState(ProfilesActiveConstant.LOG_STATUS_Y); - integrationTaskLivingDetailsEntity.setRootAppNewData(mapStr); - integrationTaskLivingDetailsEntity.setNewTransmitInfo(response); - integrationTaskLivingDetailsEntity.setNewPushDate(new Date()); - integrationTaskLivingDetailsEntity.setBusinessDate(format); - integrationTaskLivingDetailsEntity.setRootAppPk(ofsDetail.getReturnOrderCode() + "_" + ofsDetail.getSkuCode()); - integrationTaskLivingDetailsEntity.setRootAppBill(ofsDetail.getReturnOrderCode());//仅退款单号 - integrationTaskLivingDetailsEntity.setNewSystemNumber(djbh); - integrationTaskLivingDetailsEntity.setNewSystemPrimary(vouchid); - integrationTaskLivingDetailsEntity.setPluginId(getPluginId()); - saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity); - } - } catch (Exception e) { - logger.error("推送U8C,丽知:售后订单(仅退款)--->U8C红字应收单失败,失败原因:" + e); - //失败 - + logger.error("推送U8C,丽知:售后订单(仅退款)--->U8C红字应收单最外层失败,失败原因:" + e); + //失败,最外层,则该k下的所有子表记录失败 ReusltStrDto reusltStrDto = JSON.parseObject(response, ReusltStrDto.class); String ErrMessage = ""; if (reusltStrDto != null) { - ErrMessage = "推送U8C,丽知:OFS调整入库(组装入库)--->U8C组装订单失败,失败原因:" + reusltStrDto.getErrormsg(); + ErrMessage = "推送U8C,丽知:售后订单(仅退款)--->U8C红字应收单最外层失败,失败原因:" + reusltStrDto.getErrormsg(); } else { - ErrMessage = "推送U8C,丽知:OFS调整入库(组装入库)--->U8C组装订单失败,失败原因:" + e.getMessage(); + ErrMessage = "推送U8C,丽知:售后订单(仅退款)--->U8C红字应收单最外层失败,失败原因:" + e.getMessage(); } //失败 批量新增 ofsDetails for (RerturnGoodsOrderSearchDetails logDetail : logDetails) { @@ -542,70 +608,8 @@ public class RefundOnlyPluginInitializer extends PluginBaseEntity { integrationTaskLivingDetailsEntity.setPluginId(getPluginId()); saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity); } - - } }); - -// //分摊后的明细 -// List ofsDetailsAll=new ArrayList<>(); -// -// -// for (RerturnGoodsOrderSearchData returnGoodsOrder : filterReturnGoodsOrders) { -// -// RerturnGoodsOrderSearchHeader ofsHeader = returnGoodsOrder.getHeader(); -// -// //平台优惠 platformDiscounts -// BigDecimal platform = new BigDecimal(ofsHeader.getPlatformDiscounts()); -// //商家优惠 merchantDiscounts -// BigDecimal merchant = new BigDecimal(ofsHeader.getMerchantDiscounts()); -// //达人优惠 expertDiscounts -// BigDecimal expert = new BigDecimal(ofsHeader.getExpertDiscounts()); -// //支付优惠 payDiscounts -// BigDecimal pay = new BigDecimal(ofsHeader.getPayDiscounts()); -// -// List ofsDetails = returnGoodsOrder.getDetails(); -// ofsDetails.stream().forEach(detail->{//表头的四个优惠放到表体 -//// detail.setOriginalTargetPlatformDiscounts(platform); -//// detail.setOriginalTargetMerchantDiscounts(merchant); -//// detail.setOriginalTargetExpertDiscounts(expert); -//// detail.setOriginalTargetPayDiscounts(pay); -// detail.setOriginalTargetPlatformDiscounts(BigDecimal.valueOf(4)); -// detail.setOriginalTargetMerchantDiscounts(BigDecimal.valueOf(5)); -// detail.setOriginalTargetExpertDiscounts(BigDecimal.valueOf(6)); -// detail.setOriginalTargetPayDiscounts(BigDecimal.valueOf(7)); -// }); -// -// //总金额 -// BigDecimal totalCount = new BigDecimal(0); -// for (RerturnGoodsOrderSearchDetails ofsDetail : ofsDetails) { -// //请求数量*商品零售价 -// BigDecimal count=new BigDecimal(ofsDetail.getRequestQty()).multiply(new BigDecimal(ofsDetail.getMsrPrice())); -// totalCount.add(count); -// } -// -// //分摊,总比重1,最后货品时,分摊比例= 1-之前的 -// BigDecimal ratioSurplus= new BigDecimal(1); -// for (int i = 0; i < ofsDetails.size(); i++) { -// if(i!=ofsDetails.size()){//最后一个直接取 -// //给存货分摊比例,总金额/(数量*单价) -// BigDecimal ratio -// = totalCount.divide(new BigDecimal(ofsDetails.get(i).getRequestQty()).multiply(new BigDecimal(ofsDetails.get(i).getMsrPrice()))); -// ratioSurplus.subtract(ratio); -// } -// //四个分摊优惠 按零售价摊 -// //shareTargetPlatformDiscounts 分摊平台优惠 -//// ofsDetails.get(i).setShareTargetPlatformDiscounts(); -// //shareTargetMerchantDiscounts 分摊商家优惠 -// //shareTargetExpertDiscounts 分摊达人优惠 -// //shareTargetPayDiscounts 分摊支付优惠 -// -// -// } -// } -// - - System.out.println(1); } /**