diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/OfsPassiveorderDetailEntity.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/OfsPassiveorderDetailEntity.java index c28d6fc6..429fd4c9 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/OfsPassiveorderDetailEntity.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/OfsPassiveorderDetailEntity.java @@ -53,6 +53,10 @@ public class OfsPassiveorderDetailEntity extends BaseEntity { * 业务日期 */ private String businessdate; + /** + * 交易时间 + */ + private String transactionDate; /** * 业务类型 */ @@ -387,5 +391,12 @@ public class OfsPassiveorderDetailEntity extends BaseEntity { this.newsystemprimary2 = newsystemprimary2; } + public String getTransactionDate() { + return transactionDate; + } + + public void setTransactionDate(String transactionDate) { + this.transactionDate = transactionDate; + } } diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/OfsPassiveorderDetailEntity.xml b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/OfsPassiveorderDetailEntity.xml index cf750cf5..68d3bf38 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/OfsPassiveorderDetailEntity.xml +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/OfsPassiveorderDetailEntity.xml @@ -287,10 +287,10 @@ - insert into ofs_passiveorder_detail(id,newPushDate, newTransmitInfo, newState, newsystemnumber, newsystemprimary,def1,def2,def3,def4,def5,def6,def7,def8,def9,def10) + insert into ofs_passiveorder_detail(id,newPushDate, newTransmitInfo, newState, newsystemnumber, newsystemprimary,transactionDate,def1,def2,def3,def4,def5,def6,def7,def8,def9,def10) values - (#{entity.id},#{entity.newpushdate},#{entity.newtransmitinfo},#{entity.newstate},#{entity.newsystemnumber},#{entity.newsystemprimary},#{entity.def1},#{entity.def1},#{entity.def2},#{entity.def3},#{entity.def4},#{entity.def5},#{entity.def6},#{entity.def7},#{entity.def8},#{entity.def9},#{entity.def10}) + (#{entity.id},#{entity.newpushdate},#{entity.newtransmitinfo},#{entity.newstate},#{entity.newsystemnumber},#{entity.newsystemprimary},#{entity.transactionDate},#{entity.def1},#{entity.def2},#{entity.def3},#{entity.def4},#{entity.def5},#{entity.def6},#{entity.def7},#{entity.def8},#{entity.def9},#{entity.def10}) on duplicate key update id = values(id), @@ -299,6 +299,7 @@ newState = values(newState), newsystemnumber = values(newsystemnumber), newsystemprimary = values(newsystemprimary), + transactionDate = values(transactionDate), def1 = values(def1), def2 = values(def2), def3 = values(def3), @@ -313,10 +314,10 @@ - insert into ofs_passiveorder_detail(id,newPushDate2, newTransmitInfo2, newState2, newsystemnumber2, newsystemprimary2,def1,def2,def3,def4,def5,def6,def7,def8,def9,def10) + insert into ofs_passiveorder_detail(id,newPushDate2, newTransmitInfo2, newState2, newsystemnumber2, newsystemprimary2,transactionDate,def1,def2,def3,def4,def5,def6,def7,def8,def9,def10) values - (#{entity.id},#{entity.newpushdate2},#{entity.newtransmitinfo2},#{entity.newstate2},#{entity.newsystemnumber2},#{entity.newsystemprimary2},#{entity.def1},#{entity.def1},#{entity.def2},#{entity.def3},#{entity.def4},#{entity.def5},#{entity.def6},#{entity.def7},#{entity.def8},#{entity.def9},#{entity.def10}) + (#{entity.id},#{entity.newpushdate2},#{entity.newtransmitinfo2},#{entity.newstate2},#{entity.newsystemnumber2},#{entity.newsystemprimary2},#{entity.transactionDate},#{entity.def1},#{entity.def2},#{entity.def3},#{entity.def4},#{entity.def5},#{entity.def6},#{entity.def7},#{entity.def8},#{entity.def9},#{entity.def10}) on duplicate key update id = values(id), @@ -325,6 +326,7 @@ newState2 = values(newState2), newsystemnumber2 = values(newsystemnumber2), newsystemprimary2 = values(newsystemprimary2), + transactionDate = values(transactionDate), def1 = values(def1), def2 = values(def2), def3 = values(def3), diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/PassiveWarehouseReceiptToC.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/PassiveWarehouseReceiptToC.java index 8d34c349..d8cc5d19 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/PassiveWarehouseReceiptToC.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/PassiveWarehouseReceiptToC.java @@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpRequest; +import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.google.common.collect.Lists; @@ -163,1147 +164,1032 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity { @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); -// } + 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("插件执行成功"); } -// /** -// * 无源件库存同步,根据时间范围拉取 -// * -// * @author liuyang -// */ -// public void startImplementStockByTime(String startTime, String endTime) throws Exception { -// try { -// long startMillis = System.currentTimeMillis(); -// String threadNameStrStart = StrUtil.format("开始-TOC无源入库单同步U8C红字销售订单 关联开始时间:{} 关联结束时间:{}", startTime, endTime); -// logger.info(threadNameStrStart); + /** + * 无源件库存同步,根据时间范围拉取 + * + * @author liuyang + */ + public void startImplementStockByTime(String startTime, String endTime) throws Exception { + try { + long startMillis = System.currentTimeMillis(); + String threadNameStrStart = StrUtil.format("开始-TOC无源入库单同步U8C红字销售订单 关联开始时间:{} 关联结束时间:{}", startTime, endTime); + logger.info(threadNameStrStart); + + Assert.notNull(startTime, "开始时间不能为空"); + Assert.notNull(endTime, "结束时间不能为空"); + List passiveStorageResponseDataList = new ArrayList<>(); + + String tocShop = shopTobOrToCUtil.getCommaShop("TOC"); + QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo(); + queryOfsSoSaleOutVo.setRelatedAt_start(startTime); + queryOfsSoSaleOutVo.setRelatedAt_end(endTime); + queryOfsSoSaleOutVo.setClientCode("LETS"); + queryOfsSoSaleOutVo.setPageNo(1L); + queryOfsSoSaleOutVo.setPageSize(50L); + queryOfsSoSaleOutVo.setStoreCode(tocShop); + ofsStandardUtil.queryOfsPassiveComponents(queryOfsSoSaleOutVo, passiveStorageResponseDataList, 1L, "ofs.passive.order.search"); + + logger.info("TOC退货数据返回行数:{}", passiveStorageResponseDataList.size()); + if (passiveStorageResponseDataList.size() > 0) { + passiveStorageResponseDataList.removeIf(new Predicate() { + @Override + public boolean test(PassiveStorageResponse.Data headerDetailsDto) { + PassiveStorageResponse.Header header = headerDetailsDto.getHeader(); + if (header != null && header.getCompanyCode() != null) { + if (ProfilesActiveConstant.FILTER_COMPANY.contains(header.getCompanyCode().trim())) { + return true; + } + } + return false; + } + }); + getSetStock(passiveStorageResponseDataList); + } else { + logger.info("没有查询到任何数据!不需要同步"); + } + long endMillis = System.currentTimeMillis(); + String threadNameStrEnd = StrUtil.format("结束-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不能为空"); + + List passiveStorageResponseDataList = new ArrayList<>(); + + QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo(); + queryOfsSoSaleOutVo.setCode(code); + queryOfsSoSaleOutVo.setClientCode("LETS"); + queryOfsSoSaleOutVo.setPageNo(1L); + queryOfsSoSaleOutVo.setPageSize(50L); + ofsStandardUtil.queryOfsPassiveComponents(queryOfsSoSaleOutVo, passiveStorageResponseDataList, 1L, "ofs.passive.order.search"); + + logger.info("数据返回行数:{}", passiveStorageResponseDataList.size()); + if (passiveStorageResponseDataList.size() > 0) { + passiveStorageResponseDataList.removeIf(new Predicate() { + @Override + public boolean test(PassiveStorageResponse.Data headerDetailsDto) { + PassiveStorageResponse.Header header = headerDetailsDto.getHeader(); + if (header != null && header.getCompanyCode() != null) { + //过滤掉业务上不需要的公司 + if (ProfilesActiveConstant.FILTER_COMPANY.contains(header.getCompanyCode().trim())) { + return true; + } + } + return false; + } + }); + if (sceneType.equals("stock")) { + getSetStock(passiveStorageResponseDataList); + } else if (sceneType.equals("tran")) { + getSetTran(passiveStorageResponseDataList); + } + } 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) 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 passiveStorageResponseDataList = new ArrayList<>(); + + String tocShop = shopTobOrToCUtil.getCommaShop("TOC"); + QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo(); + queryOfsSoSaleOutVo.setRelatedAt_start(startTime); + queryOfsSoSaleOutVo.setRelatedAt_end(endTime); + queryOfsSoSaleOutVo.setClientCode("LETS"); + queryOfsSoSaleOutVo.setPageNo(1L); + queryOfsSoSaleOutVo.setPageSize(50L); + queryOfsSoSaleOutVo.setStoreCode(tocShop); + ofsStandardUtil.queryOfsPassiveComponents(queryOfsSoSaleOutVo, passiveStorageResponseDataList, 1L, "ofs.passive.order.search"); + logger.info("数据返回行数:{}", passiveStorageResponseDataList.size()); + + if (passiveStorageResponseDataList.size() > 0) { + passiveStorageResponseDataList.removeIf(new Predicate() { + @Override + public boolean test(PassiveStorageResponse.Data headerDetailsDto) { + PassiveStorageResponse.Header header = headerDetailsDto.getHeader(); + if (header != null && header.getCompanyCode() != null) { + //过滤掉不需要的公司 + if (ProfilesActiveConstant.FILTER_COMPANY.contains(header.getCompanyCode().trim())) { + return true; + } + } + return false; + } + }); + getSetTran(passiveStorageResponseDataList); + } 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); + } + } + + /** + * 无源件库存同步getSetStock方法发现逻辑 + * + * @author liuyang + */ + private void getSetStock(List returnGoodHeaderDetailsDataDtoArrayList) throws Exception { + LOCK1.lock(); + try { + //过滤成功的数据 + List data = filterDataStock(returnGoodHeaderDetailsDataDtoArrayList); + //保存到mysql底表 + batchInsert(data); + //执行推送主逻辑 + implementStock(data); + } catch (Exception e) { + logger.error("TOC退货-库存:getSetStock方法抛出异常", e); + } finally { + LOCK1.unlock(); + } + } + + /** + * 确认收入:预备执行逻辑 + * + * @param passiveStorageResponseDataDtoArrayList O无源入库单 + * @author liuyang + */ + private void getSetTran(List passiveStorageResponseDataDtoArrayList) throws Exception { + LOCK2.lock(); + try { + //过滤成功的数据 + List data = filterDataTran(passiveStorageResponseDataDtoArrayList); + //保存到mysql + batchInsert(data); + //执行推送主逻辑 + implementTran(data); + } catch (Exception e) { + logger.error("TOC退货-确认收入:getSetTran方法抛出异常", e); + } finally { + LOCK2.unlock(); + } + } + + /** + * 库存同步,过滤掉成功的数据 + * + * @author liuyang + */ + private List filterDataStock(List passiveStorageResponseDataDtoArrayList) throws Exception { + List ofsPassiveorderDetailEntitiesList = new ArrayList<>(); + //查询每行无源入库单,对应的推送状态 + if (passiveStorageResponseDataDtoArrayList != null && passiveStorageResponseDataDtoArrayList.size() > 0) { + List> lists = SplitListByCountUtil.splitListByCount(passiveStorageResponseDataDtoArrayList, 1000); + for (int i = 0; i < lists.size(); i++) { + List data = lists.get(i); + String idStr = commaConcatenatedPrimaryKeyStock(data); + List ofsPassiveorderDetailEntities = queryStockTocOutLog(idStr); + ofsPassiveorderDetailEntitiesList.addAll(ofsPassiveorderDetailEntities); + } + } + return filterDataRowsAsPushOrFailedStock(ofsPassiveorderDetailEntitiesList, passiveStorageResponseDataDtoArrayList); + } + + /** + * 确认收入,过滤掉成功的数据 + * + * @author liuyang + */ + private List filterDataTran(List passiveStorageResponseDataDtoArrayList) throws Exception { + List tocofsReturngoodsDetailedEntityList = new ArrayList<>(); + if (passiveStorageResponseDataDtoArrayList != null && passiveStorageResponseDataDtoArrayList.size() > 0) { + List> lists = SplitListByCountUtil.splitListByCount(passiveStorageResponseDataDtoArrayList, 100); + for (int i = 0; i < lists.size(); i++) { + List data = lists.get(i); + String idStr = commaConcatenatedPrimaryKeyStock(data); + List ofsPassiveorderDetailEntities = queryStockTocOutLog(idStr); + tocofsReturngoodsDetailedEntityList.addAll(ofsPassiveorderDetailEntities); + } + } + return filterDataRowsAsPushOrFailedTran(tocofsReturngoodsDetailedEntityList, passiveStorageResponseDataDtoArrayList); + } + + /** + * 逗号拼接字符串主键,作为批处理的一部分,方便下一步的批量查询操作 + * 入库和退款导致完成都可以通用 + * + * @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++) { + PassiveStorageResponse.Data data = headerDetailsDtoList2.get(i); + PassiveStorageResponse.Header header = data.getHeader(); + List details = data.getDetails(); + for (int j = 0; j < details.size(); j++) { + PassiveStorageResponse.Details details1 = details.get(j); + Assert.notNull(details1.getId(), "O明细主键不能为空!"); + Assert.state(!"".equals(details1.getId()), "O明细主键不能为空!"); + + idStr.append("'"); + idStr.append(details1.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())) { + OfsPassiveorderDetailEntity ofsPassiveorderDetailEntity = new OfsPassiveorderDetailEntity(); + ofsPassiveorderDetailEntity.setIds(idStr); + tocofsReturngoodsDetailedEntities = iOfsPassiveorderDetailDao.query(ofsPassiveorderDetailEntity); + } else { + logger.error("idStr为空,无法查询数据!"); + } + return tocofsReturngoodsDetailedEntities; + } + + /** + * 保存抓取到的数据到mysql底表,如果底表里已经存在,则会忽略,并且发生更新 + * + * @param passiveStorageResponseDataDtoArrayList 需要保存到 Mysql 底表的数据行,采用批量插入的方式 + * @author liuyang + */ + private void batchInsert(List passiveStorageResponseDataDtoArrayList) throws Exception { + if (passiveStorageResponseDataDtoArrayList != null && passiveStorageResponseDataDtoArrayList.size() > 0) { + List headerDetailsDtoList1 = new ArrayList<>(); + List headerDetailsDtoList2 = new ArrayList<>(); + + for (PassiveStorageResponse.Data index : passiveStorageResponseDataDtoArrayList) { + //主表、明细表 + PassiveStorageResponse.Header header = index.getHeader(); + List details = index.getDetails(); + if (details != null && details.size() > 0) { + for (PassiveStorageResponse.Details passiveStorageResponseDetails : details) { + passiveStorageResponseDetails.setHeader(header); + } + } + headerDetailsDtoList1.add(header); + headerDetailsDtoList2.addAll(details); + } + + //每100作为一个批次插入主表,根据主键(id)判断是否重复,如果重复的,则不进行插入 + List> lists = SplitListByCountUtil.splitListByCount(headerDetailsDtoList1, 100); + for (int i = 0; i < lists.size(); i++) { + List headers = lists.get(i); + + final Throwable[] childException = {null}; + long startTime = System.currentTimeMillis(); + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + try { + List ofsPassiveorderHeaderEntities = copyHeaderDto(headers); + if (ofsPassiveorderHeaderEntities.size() > 0) { + logger.info("插入底表{}个对象(表头)", ofsPassiveorderHeaderEntities.size()); + iOfsPassiveorderHeaderDao.entityInsertOrUpdateBatch(ofsPassiveorderHeaderEntities); + } else { + logger.info("ofsPassiveorderHeaderEntities:没有对象被插入表头底表"); + } + } catch (Exception e) { + logger.error("线程保存无源件主表抛出异常", e); + childException[0] = e; + } + } + }); + thread.start(); + try { + thread.join(); + } catch (Exception e) { + logger.error("线程保存TOC退货主表抛出异常", e); + childException[0] = e; + } + long endTime = System.currentTimeMillis(); + logger.info("插入或更新无源入库单表-耗时:{}", (endTime - startTime)); + + //如果子线程抛出异常,则反馈到主线程方便排查 + if (childException[0] != null) { + Assert.state(false, childException[0].getMessage()); + } + } + + //插入明细表 + List> lists1 = SplitListByCountUtil.splitListByCount(headerDetailsDtoList2, 100); + for (int i = 0; i < lists1.size(); i++) { + List details = lists1.get(i); + List ofsPassiveorderDetailEntities = copyDetailsDto(details); + + final Throwable[] childException = {null}; + long startTime = System.currentTimeMillis(); + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + try { + if (ofsPassiveorderDetailEntities.size() > 0) { + logger.info("插入底表{}个对象(表体)", ofsPassiveorderDetailEntities.size()); + iOfsPassiveorderDetailDao.entityInsertOrUpdateBatch(ofsPassiveorderDetailEntities); + } else { + logger.info("ofsPassiveorderDetailEntities:没有对象被插入表头底表"); + } + } catch (Exception e) { + logger.error("线程保存TOC退货明细抛出异常", e); + childException[0] = e; + } + } + }); + thread.start(); + try { + thread.join(); + } catch (Exception e) { + logger.error("线程保存无源件明细表抛出异常", e); + childException[0] = e; + } + long endTime = System.currentTimeMillis(); + logger.info("插入或更新TOC退货入库表体-耗时:{}", (endTime - startTime)); + //如果子线程抛出异常,则反馈到主线程方便排查 + if (childException[0] != null) { + Assert.state(false, childException[0].getMessage()); + } + } + } + } + + /** + * 查询OFS售后退货入库单 + * + * @param queryOfsSoSaleOutVo 查询参数 + * @param headerDetailsDtoList 查询结果集 + * @param pageNo 从第pageNo页开始查询 + */ +// private void queryOfsReturnGoods(QueryOfsSoSaleOutVo queryOfsSoSaleOutVo, List headerDetailsDtoList, Long pageNo) throws Exception { // -// Assert.notNull(startTime, "开始时间不能为空"); -// Assert.notNull(endTime, "结束时间不能为空"); +// Long pageSize = 200L; +// queryOfsSoSaleOutVo.setPageNo(pageNo); +// queryOfsSoSaleOutVo.setPageSize(pageSize); // -// List passiveStorageResponseDataList = new ArrayList<>(); +// 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); // -// String tocShop = shopTobOrToCUtil.getCommaShop("TOC"); -// QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo(); -// queryOfsSoSaleOutVo.setRelatedAt_start(startTime); -// queryOfsSoSaleOutVo.setRelatedAt_end(endTime); -// queryOfsSoSaleOutVo.setClientCode("LETS"); -// queryOfsSoSaleOutVo.setPageNo(1L); -// queryOfsSoSaleOutVo.setPageSize(50L); -//// queryOfsSoSaleOutVo.setStoreCode(tocShop); -// ofsStandardUtil.queryOfsPassiveComponents(queryOfsSoSaleOutVo, passiveStorageResponseDataList, 1L, "ofs.passive.order.search"); -// -// logger.info("TOC退货数据返回行数:{}", passiveStorageResponseDataList.size()); -// if (passiveStorageResponseDataList.size() > 0) { -// passiveStorageResponseDataList.removeIf(new Predicate() { -// @Override -// public boolean test(PassiveStorageResponse.Data headerDetailsDto) { -// PassiveStorageResponse.Header header = headerDetailsDto.getHeader(); -// if (header != null && header.getCompanyCode() != null) { -// if (ProfilesActiveConstant.FILTER_COMPANY.contains(header.getCompanyCode().trim())) { -// return true; -// } -// } -// return false; -// } -// }); -// getSetStock(passiveStorageResponseDataList); +// //OFS没有提供分页字段,等待开发 +// } // } else { -// logger.info("没有查询到任何数据!不需要同步"); +// logger.error("查询失败,失败原因:{}", JSON.toJSON(interfaceParamDto)); // } -// long endMillis = System.currentTimeMillis(); -// String threadNameStrEnd = StrUtil.format("结束-TOC无源入库单同步U8C红字销售订单 关联开始时间:{} 关联结束时间:{} 耗时:{}", startTime, endTime, (endMillis - startMillis)); -// logger.info(threadNameStrEnd); -// } catch (Exception e) { -// logger.error("startImplementStockByTime方法抛出异常", e); +// } else { +// logger.error("rertunGoodsRootBean为空!interfaceParamDto对象的结果集json:{}", JSON.toJSON(interfaceParamDto)); // } // } -// -// /** -// * 根据编码、场景类型拉取 -// * -// * @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<>(); + +// 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.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("没有查询到任何数据!不需要同步"); -// } +// queryOfsSoSaleOutVo.setCode("LETS-SH2024070500000003"); // -// long endMillis = System.currentTimeMillis(); -// String threadNameStrEnd = StrUtil.format("结束-OFS销售出库(TOC)同步U8C销售订单 同步单据号:{} 业务场景:{} 耗时:{}", code, sceneType, (endMillis - startMillis)); -// logger.info(threadNameStrEnd); +// InterfaceParamDto interfaceParamDto = new InterfaceParamDto(); +// interfaceParamDto.setApi("ofs.shipment.search"); +// interfaceParamDto.setData(JSON.toJSONString(queryOfsSoSaleOutVo)); +// SaleOutReturnMessageDto saleOutReturnMessageDto = (SaleOutReturnMessageDto) ofsUnifiedService.unified(interfaceParamDto); +// System.out.println(saleOutReturnMessageDto); // } -// -// /** -// * 交易采购,按指定时间拉取 -// * -// * @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.setTradeSuccessAt_start(startTime); -// queryOfsSoSaleOutVo.setTradeSuccessAt_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.passive.order.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); -// } -// } -// -// /** -// * 无源件库存同步getSetStock方法发现逻辑 -// * -// * @author liuyang -// */ -// private void getSetStock(List returnGoodHeaderDetailsDataDtoArrayList) throws Exception { -// LOCK1.lock(); -// try { -// //过滤成功的数据 -// List data = filterDataStock(returnGoodHeaderDetailsDataDtoArrayList); -// //保存到mysql底表 -// batchInsert(data); -// //执行推送主逻辑 -// implementStock(data); -// } 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 passiveStorageResponseDataDtoArrayList) throws Exception { -// List ofsPassiveorderDetailEntitiesList = new ArrayList<>(); -// //查询每行无源入库单,对应的推送状态 -// if (passiveStorageResponseDataDtoArrayList != null && passiveStorageResponseDataDtoArrayList.size() > 0) { -// List> lists = SplitListByCountUtil.splitListByCount(passiveStorageResponseDataDtoArrayList, 1000); -// for (int i = 0; i < lists.size(); i++) { -// List data = lists.get(i); -// String idStr = commaConcatenatedPrimaryKeyStock(data); -// List ofsPassiveorderDetailEntities = queryStockTocOutLog(idStr); -// ofsPassiveorderDetailEntitiesList.addAll(ofsPassiveorderDetailEntities); -// } -// } -// return filterDataRowsAsPushOrFailedStock(ofsPassiveorderDetailEntitiesList, passiveStorageResponseDataDtoArrayList); -// } -// -// /** -// * 确认收入,过滤掉成功的数据 -// * -// * @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); -// return null; -// } -// -// /** -// * 逗号拼接字符串主键,作为批处理的一部分,方便下一步的批量查询操作 -// * -// * @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++) { -// PassiveStorageResponse.Data data = headerDetailsDtoList2.get(i); -// PassiveStorageResponse.Header header = data.getHeader(); -// List details = data.getDetails(); -// for (int j = 0; j < details.size(); j++) { -// PassiveStorageResponse.Details details1 = details.get(j); -// Assert.notNull(details1.getId(), "O明细主键不能为空!"); -// Assert.state(!"".equals(details1.getId()), "O明细主键不能为空!"); -// -// idStr.append("'"); -// idStr.append(details1.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())) { -// OfsPassiveorderDetailEntity ofsPassiveorderDetailEntity = new OfsPassiveorderDetailEntity(); -// ofsPassiveorderDetailEntity.setIds(idStr); -// tocofsReturngoodsDetailedEntities = iOfsPassiveorderDetailService.query(ofsPassiveorderDetailEntity); -// } else { -// logger.error("idStr为空,无法查询数据!"); -// } -// return tocofsReturngoodsDetailedEntities; -// } -// -// /** -// * 保存抓取到的数据到mysql底表,如果底表里已经存在,则会忽略,并且发生更新 -// * -// * @param passiveStorageResponseDataDtoArrayList 需要保存到 Mysql 底表的数据行 -// * @author liuyang -// */ -// private void batchInsert(List passiveStorageResponseDataDtoArrayList) throws Exception { -// if (passiveStorageResponseDataDtoArrayList != null && passiveStorageResponseDataDtoArrayList.size() > 0) { -// List headerDetailsDtoList1 = new ArrayList<>(); -// List headerDetailsDtoList2 = new ArrayList<>(); -// -// for (PassiveStorageResponse.Data index : passiveStorageResponseDataDtoArrayList) { -// //主表、明细表 -// PassiveStorageResponse.Header header = index.getHeader(); -// List details = index.getDetails(); -// if (details != null && details.size() > 0) { -// for (PassiveStorageResponse.Details passiveStorageResponseDetails : details) { -// passiveStorageResponseDetails.setHeader(header); -// } -// } -// headerDetailsDtoList1.add(header); -// headerDetailsDtoList2.addAll(details); -// } -// -// //每100作为一个批次插入主表,根据主键(id)判断是否重复,如果重复的,则不进行插入 -// List> lists = SplitListByCountUtil.splitListByCount(headerDetailsDtoList1, 100); -// for (int i = 0; i < lists.size(); i++) { -// List headers = lists.get(i); -// -// final Throwable[] childException = {null}; -// long startTime = System.currentTimeMillis(); -// Thread thread = new Thread(new Runnable() { -// @Override -// public void run() { -// try { -// List ofsPassiveorderHeaderEntities = copyHeaderDto(headers); -// if (ofsPassiveorderHeaderEntities.size() > 0) { -// logger.info("插入底表{}个对象(表头)", ofsPassiveorderHeaderEntities.size()); -// iOfsPassiveorderHeaderDao.entityInsertOrUpdateBatch(ofsPassiveorderHeaderEntities); -// } else { -// logger.info("ofsPassiveorderHeaderEntities:没有对象被插入表头底表"); -// } -// } catch (Exception e) { -// logger.error("线程保存无源件主表抛出异常", e); -// childException[0] = e; -// } -// } -// }); -// thread.start(); -// try { -// thread.join(); -// } catch (Exception e) { -// logger.error("线程保存TOC退货主表抛出异常", e); -// childException[0] = e; -// } -// long endTime = System.currentTimeMillis(); -// logger.info("插入或更新无源入库单表-耗时:{}", (endTime - startTime)); -// -// //如果子线程抛出异常,则反馈到主线程方便排查 -// if (childException[0] != null) { -// Assert.state(false, childException[0].getMessage()); -// } -// } -// -// //插入明细表 -// List> lists1 = SplitListByCountUtil.splitListByCount(headerDetailsDtoList2, 100); -// for (int i = 0; i < lists1.size(); i++) { -// List details = lists1.get(i); -// List ofsPassiveorderDetailEntities = copyDetailsDto(details); -// -// final Throwable[] childException = {null}; -// long startTime = System.currentTimeMillis(); -// Thread thread = new Thread(new Runnable() { -// @Override -// public void run() { -// try { -// if (ofsPassiveorderDetailEntities.size() > 0) { -// logger.info("插入底表{}个对象(表体)", ofsPassiveorderDetailEntities.size()); -// iOfsPassiveorderDetailDao.entityInsertOrUpdateBatch(ofsPassiveorderDetailEntities); -// } else { -// logger.info("ofsPassiveorderDetailEntities:没有对象被插入表头底表"); -// } -// } catch (Exception e) { -// logger.error("线程保存TOC退货明细抛出异常", e); -// childException[0] = e; -// } -// } -// }); -// thread.start(); -// try { -// thread.join(); -// } catch (Exception e) { -// logger.error("线程保存无源件明细表抛出异常", e); -// childException[0] = e; -// } -// long endTime = System.currentTimeMillis(); -// logger.info("插入或更新TOC退货入库表体-耗时:{}", (endTime - startTime)); -// //如果子线程抛出异常,则反馈到主线程方便排查 -// if (childException[0] != null) { -// Assert.state(false, childException[0].getMessage()); -// } -// } -// } -// } -// -// /** -// * 查询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 passiveStorageResponseList O无源入库单对象 -// * @author liuyang -// */ -// private void implementStock(List passiveStorageResponseList) throws Exception { -// Assert.notNull(passiveStorageResponseList, "passiveStorageResponseList不能为空"); -// logger.info("TOC无源件退货入库:{} 行需要进行数据转换", passiveStorageResponseList.size()); -// -// if (passiveStorageResponseList != null && passiveStorageResponseList.size() > 0) { -// try { -// // 查询基本档案 -// String sceneType = "stock"; -// List passiveStorageSonDetailsDtos = queryBasicArchivesStock(passiveStorageResponseList, sceneType); -// // 分组汇总 -// String dimension = null; -//// dimension = "1001&dy-intoyou&B2CHA20240033&6973391733588&SALES&002"; -// Map> stringListMap = groupSummary(passiveStorageSonDetailsDtos, 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 && stringListMap != null) { -// Iterator>> iterator = stringListMap.entrySet().iterator(); -// while (iterator.hasNext()) { -// Map.Entry> next = iterator.next(); -// String keyGroup = next.getKey(); -// List value = next.getValue(); -// -// PassiveStorageResponse.Header header = value.get(0).getHeader(); -// BdCorpEntity bdCorpEntity = value.get(0).getBdCorpEntity();//表头销售公司 -// BdCorpEntity deliverGoodsCorp = value.get(0).getDeliverGoodsCorp();//发货公司 -// BdCalbodyEntity bdCalbodyEntity = value.get(0).getBdCalbodyEntity();//发货仓库组织 -// BdStordocEntity bdStordocEntity = value.get(0).getBdStordocEntity();//发货仓库 -// BdCalbodyEntity bdCalbodyEntity1 = value.get(0).getBdCalbodyEntity1();//收货库存组织 -// BdStordocEntity bdStordocEntity1 = value.get(0).getBdStordocEntity1();//收货仓库 -// BdSalestruEntity bdSalestruEntity = value.get(0).getBdSalestruEntity();//销售组织 -// BdDeptdocEntity bdDeptdocEntity = value.get(0).getBdDeptdocEntity();//业务部门 -// BdCumandocEntity bdCumandocEntity = value.get(0).getBdCumandocEntity();//客商管理档案 -// BdCubasdocEntity bdCubasdocEntity = value.get(0).getBdCubasdocEntity();//客商基本档案 -// BdDefdocEntity platformArchives = value.get(0).getPlatformArchives();//U8C平台档案 -// BdDefdocEntity shopArchives = value.get(0).getShopArchives();//U8C店铺档案 -// BdRdclEntity bdRdclEntity = value.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()); -// -// //把汇总好的出库单明细行合并成一行 -// PassiveStorageSonDetailsDto passiveStorageSonDetailsDto = groupMergeDetailedRows(value, isCheckShopChoose); -// //存货管理档案:取发货公司的存货管理档案 -// BdInvmandocEntity bdInvmandocEntity = value.get(0).getBdInvmandocEntity(); -// //存货基础档案 -// BdInvbasdocEntity bdInvbasdocEntity = value.get(0).getBdInvbasdocEntity(); -// //根据存货基础档案编码,查询当前存货的税率 -// BdTaxitemsEntity bdTaxitemsEntity1 = value.get(0).getBdTaxitemsEntity(); -// -// //判断是否为赠品 -// Boolean isblargessflag = false; -// if ("0".equals(passiveStorageSonDetailsDto.getGroupTotalPayAmount().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("-" + passiveStorageSonDetailsDto.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("-" + passiveStorageSonDetailsDto.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(passiveStorageSonDetailsDto.getVdef4().stripTrailingZeros().toPlainString())) { -// saleorderRequestChildrenDto.setVdef4("-" + passiveStorageSonDetailsDto.getVdef4().stripTrailingZeros().toPlainString()); -// } else { -// saleorderRequestChildrenDto.setVdef4("0"); -// } -// if (!"0".equals(passiveStorageSonDetailsDto.getVdef5().stripTrailingZeros().toPlainString())) { -// saleorderRequestChildrenDto.setVdef5("-" + passiveStorageSonDetailsDto.getVdef5().stripTrailingZeros().toPlainString()); -// } else { -// saleorderRequestChildrenDto.setVdef5("0"); -// } -// if (!"0".equals(passiveStorageSonDetailsDto.getVdef6().stripTrailingZeros().toPlainString())) { -// saleorderRequestChildrenDto.setVdef6("-" + passiveStorageSonDetailsDto.getVdef6().stripTrailingZeros().toPlainString()); -// } else { -// saleorderRequestChildrenDto.setVdef6("0"); -// } -// if (!"0".equals(passiveStorageSonDetailsDto.getVdef7().stripTrailingZeros().toPlainString())) { -// saleorderRequestChildrenDto.setVdef7("-" + passiveStorageSonDetailsDto.getVdef7().stripTrailingZeros().toPlainString()); -// } else { -// saleorderRequestChildrenDto.setVdef7("0"); -// } -// saleorderRequestChildrenDtoList.add(saleorderRequestChildrenDto); -// -// //平台优惠 -// if (passiveStorageSonDetailsDto.getVdef4() != null) { -// BigDecimal vdef4 = passiveStorageSonDetailsDto.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 (passiveStorageSonDetailsDto.getVdef6() != null) { -// BigDecimal vdef6 = passiveStorageSonDetailsDto.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 (passiveStorageSonDetailsDto.getVdef5() != null) { -// BigDecimal vdef5 = passiveStorageSonDetailsDto.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); -// } -// } -// //推送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(value, "Y", "success", vreceiptcode, csaleid); -// } catch (Exception e) { -// //记录失败 -// logger.error("无源件业务转换成U8C对象过程中、或者单据推送到U8C出现异常!", e); -// String message = e.getMessage(); -// if (message == null) { -// message = "未知错误"; -// } -// updateSuccessOrFail1(value, "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); -// } -// } -// } -// -// /** -// * 2025 年 3 月 12 日 15:53:27 -// * 生成业务日期:取「关联时间」,只能取关联时间,否则会存在跨月问题 -// * -// * @author liuyang -// */ -// private String createGenerateBusinessDate(PassiveStorageResponse.Header header) { -// String code = null; -// if (header != null && header.getReceiptCode() != null) { -// code = header.getReceiptCode(); -// } -// if (header != null && header.getRelatedAt() != null) { -// String closedAt = header.getRelatedAt(); -// String businessFormat = null; -// try { -// Date dbill = DateUtil.parse(closedAt); -// businessFormat = DateUtil.format(dbill, "yyyy-MM-dd"); -// } catch (Exception e) { -// logger.error("业务日期生成失败relatedAt(O 关联时间)解析异常:{} O 无源入库单号:{}", e.getMessage(), code); -// Assert.state(false, "业务日期生成失败closedAt(O 关联时间)解析异常:{} O 无源入库单号:{}", e.getMessage(), code); -// } -// return businessFormat; -// } else { -// logger.error("业务日期生成失败relatedAt(O 关联时间)不能为空 O 无源入库单号:{}", code); -// Assert.state(false, "业务日期生成失败relatedAt(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; -// } -// } -// -// /** -// * 先退款后退货场景时间判断 -// */ + + /** + * 库存同步,代码同步逻辑 + * + * @param passiveStorageResponseList O无源入库单对象 + * @author liuyang + */ + private void implementStock(List passiveStorageResponseList) throws Exception { + Assert.notNull(passiveStorageResponseList, "passiveStorageResponseList不能为空"); + logger.info("TOC无源件退货入库:{} 行需要进行数据转换", passiveStorageResponseList.size()); + + if (passiveStorageResponseList != null && passiveStorageResponseList.size() > 0) { + try { + // 查询基本档案 + String sceneType = "stock"; + List passiveStorageSonDetailsDtos = queryBasicArchivesStock(passiveStorageResponseList, sceneType); + // 分组汇总 + String dimension = null; +// dimension = "1001&dy-intoyou&B2CHA20240033&6973391733588&SALES&002"; + Map> stringListMap = groupSummary(passiveStorageSonDetailsDtos, 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 && stringListMap != null) { + Iterator>> iterator = stringListMap.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry> next = iterator.next(); + String keyGroup = next.getKey(); + List value = next.getValue(); + + PassiveStorageResponse.Header header = value.get(0).getHeader(); + BdCorpEntity bdCorpEntity = value.get(0).getBdCorpEntity();//表头销售公司 + BdCorpEntity deliverGoodsCorp = value.get(0).getDeliverGoodsCorp();//发货公司 + BdCalbodyEntity bdCalbodyEntity = value.get(0).getBdCalbodyEntity();//发货仓库组织 + BdStordocEntity bdStordocEntity = value.get(0).getBdStordocEntity();//发货仓库 + BdCalbodyEntity bdCalbodyEntity1 = value.get(0).getBdCalbodyEntity1();//收货库存组织 + BdStordocEntity bdStordocEntity1 = value.get(0).getBdStordocEntity1();//收货仓库 + BdSalestruEntity bdSalestruEntity = value.get(0).getBdSalestruEntity();//销售组织 + BdDeptdocEntity bdDeptdocEntity = value.get(0).getBdDeptdocEntity();//业务部门 + BdCumandocEntity bdCumandocEntity = value.get(0).getBdCumandocEntity();//客商管理档案 + BdCubasdocEntity bdCubasdocEntity = value.get(0).getBdCubasdocEntity();//客商基本档案 + BdDefdocEntity platformArchives = value.get(0).getPlatformArchives();//U8C平台档案 + BdDefdocEntity shopArchives = value.get(0).getShopArchives();//U8C店铺档案 + BdRdclEntity bdRdclEntity = value.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()); + + //把汇总好的出库单明细行合并成一行 + PassiveStorageSonDetailsDto passiveStorageSonDetailsDto = groupMergeDetailedRows(value, isCheckShopChoose); + //存货管理档案:取发货公司的存货管理档案 + BdInvmandocEntity bdInvmandocEntity = value.get(0).getBdInvmandocEntity(); + //存货基础档案 + BdInvbasdocEntity bdInvbasdocEntity = value.get(0).getBdInvbasdocEntity(); + //根据存货基础档案编码,查询当前存货的税率 + BdTaxitemsEntity bdTaxitemsEntity1 = value.get(0).getBdTaxitemsEntity(); + + //判断是否为赠品 + Boolean isblargessflag = false; + if ("0".equals(passiveStorageSonDetailsDto.getGroupTotalPayAmount().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("-" + passiveStorageSonDetailsDto.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("-" + passiveStorageSonDetailsDto.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(passiveStorageSonDetailsDto.getVdef4().stripTrailingZeros().toPlainString())) { + saleorderRequestChildrenDto.setVdef4("-" + passiveStorageSonDetailsDto.getVdef4().stripTrailingZeros().toPlainString()); + } else { + saleorderRequestChildrenDto.setVdef4("0"); + } + if (!"0".equals(passiveStorageSonDetailsDto.getVdef5().stripTrailingZeros().toPlainString())) { + saleorderRequestChildrenDto.setVdef5("-" + passiveStorageSonDetailsDto.getVdef5().stripTrailingZeros().toPlainString()); + } else { + saleorderRequestChildrenDto.setVdef5("0"); + } + if (!"0".equals(passiveStorageSonDetailsDto.getVdef6().stripTrailingZeros().toPlainString())) { + saleorderRequestChildrenDto.setVdef6("-" + passiveStorageSonDetailsDto.getVdef6().stripTrailingZeros().toPlainString()); + } else { + saleorderRequestChildrenDto.setVdef6("0"); + } + if (!"0".equals(passiveStorageSonDetailsDto.getVdef7().stripTrailingZeros().toPlainString())) { + saleorderRequestChildrenDto.setVdef7("-" + passiveStorageSonDetailsDto.getVdef7().stripTrailingZeros().toPlainString()); + } else { + saleorderRequestChildrenDto.setVdef7("0"); + } + saleorderRequestChildrenDtoList.add(saleorderRequestChildrenDto); + + //平台优惠 + if (passiveStorageSonDetailsDto.getVdef4() != null) { + BigDecimal vdef4 = passiveStorageSonDetailsDto.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 (passiveStorageSonDetailsDto.getVdef6() != null) { + BigDecimal vdef6 = passiveStorageSonDetailsDto.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 (passiveStorageSonDetailsDto.getVdef5() != null) { + BigDecimal vdef5 = passiveStorageSonDetailsDto.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); + } + } + //推送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(value, "Y", "success", vreceiptcode, csaleid); + } catch (Exception e) { + //记录失败 + logger.error("无源件业务转换成U8C对象过程中、或者单据推送到U8C出现异常!", e); + String message = e.getMessage(); + if (message == null) { + message = "未知错误"; + } + updateSuccessOrFail1(value, "N", message, null, null); + } + } + } else { + //2024年8月6日 11:28:54此处不记录失败,不认为是错误 + logger.info("summaryDimensionMap变量或者bdBusitypeEntity变量为空,因此主要的推送逻辑不会被执行!"); + } + } catch (Exception e) { + logger.error("外层转换逻辑抛出异常", e); + } + } + } + + /** + * 到账成功:代码同步逻辑 + * + * @param passiveStorageResponseDataList O无源入库单推送转换 + * @author liuyang + */ + private void implementTran(List passiveStorageResponseDataList) throws Exception { + if (passiveStorageResponseDataList != null && passiveStorageResponseDataList.size() > 0) { + logger.info("TOC无源件业务:{}行需要进行数据转换", passiveStorageResponseDataList.size()); + + try { + // 查询基本档案 + String sceneType = "tran"; + List passiveStorageSonDetailsDtos = queryBasicArchivesStock(passiveStorageResponseDataList, sceneType); + // 分组汇总 + String dimension = null; + Map> stringListMap = groupSummary(passiveStorageSonDetailsDtos, 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 && stringListMap != null) { + Iterator>> iterator = stringListMap.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry> next = iterator.next(); + String key = next.getKey(); + List value = next.getValue(); + PassiveStorageResponse.Header header = value.get(0).getHeader(); + + BdCorpEntity bdCorpEntity = value.get(0).getBdCorpEntity();//表头销售公司 + BdCorpEntity deliverGoodsCorp = value.get(0).getDeliverGoodsCorp();//发货公司 + BdCalbodyEntity bdCalbodyEntity = value.get(0).getBdCalbodyEntity();//发货仓库组织 + BdStordocEntity bdStordocEntity = value.get(0).getBdStordocEntity();//发货仓库 + BdCalbodyEntity bdCalbodyEntity1 = value.get(0).getBdCalbodyEntity1();//收货库存组织 + BdStordocEntity bdStordocEntity1 = value.get(0).getBdStordocEntity1();//收货仓库 + BdSalestruEntity bdSalestruEntity = value.get(0).getBdSalestruEntity();//销售组织 + BdDeptdocEntity bdDeptdocEntity = value.get(0).getBdDeptdocEntity();//业务部门 + BdCumandocEntity bdCumandocEntity = value.get(0).getBdCumandocEntity();//客商管理档案 + BdCubasdocEntity bdCubasdocEntity = value.get(0).getBdCubasdocEntity();//客商基本档案 + BdDefdocEntity platformArchives = value.get(0).getPlatformArchives();//U8C平台档案 + BdDefdocEntity shopArchives = value.get(0).getShopArchives();//U8C店铺档案 + BdRdclEntity bdRdclEntity = value.get(0).getBdRdclEntity();//U8C收发类别 + + try { + //生成业务日期 + String generateBusinessDate = createSuccessFulTradeDate(header); + + //组装应收单表头 + ArapDjzbVO.Parentt parentVo = new ArapDjzbVO.Parentt(); + parentVo.setDjrq(generateBusinessDate);//单据日期 + parentVo.setDwbm(bdCorpEntity.getPkCorp());//公司 + parentVo.setLrr(OverallConstant.getOverAllValue("u8cApiZdrPK"));//录入人 + parentVo.setWldx("0");//往来对象标识 固定为:客户 + parentVo.setDeptid(bdDeptdocEntity.getPkDeptdoc());//部门 + parentVo.setShr(OverallConstant.getOverAllValue("u8cApiZdrPK"));//审批人 + parentVo.setShrq(generateBusinessDate);//审核日期 + parentVo.setDjlxbm("D0");//单据类型编码 + parentVo.setXslxbm(bdBusitypeEntity.getPkBusitype());//业务流程 + parentVo.setFeinvstatus("0");//开票状态 + parentVo.setHbbm(bdCumandocEntity.getPkCumandoc());//客商主键 + //店铺档案 + parentVo.setZyx1(shopArchives.getPkDefdoc()); + parentVo.setDef1(shopArchives.getDocname()); + //来源平台 + parentVo.setZyx2(platformArchives.getPkDefdoc()); + parentVo.setDef2(platformArchives.getDocname()); + //收发类别 + parentVo.setZyx3(bdRdclEntity.getPkRdcl()); + parentVo.setDef3(bdRdclEntity.getRdname()); + //单据红字标识 + parentVo.setZyx16(OverallConstant.getOverAllValue("u8c自定义项档案-单据红字标识-Y主键")); + parentVo.setDef16(OverallConstant.getOverAllValue("u8c自定义项档案-单据红字标识-Y名称")); +// parentVo.setZyx19();//自定义项19 OFS单号不传,因为是汇总的 + + //验证是否为指定的店铺,如果为true,则取结存价 + Boolean isCheckShopChoose = balanceUnitPriceUtil.checkOfsShop(header.getStoreCode()); + //把汇总好的出库单明细行合并成一行 + PassiveStorageSonDetailsDto passiveStorageSonDetailsDto = groupMergeDetailedRows(value, isCheckShopChoose); + //存货管理档案:取发货公司的存货管理档案 + BdInvmandocEntity bdInvmandocEntity = value.get(0).getBdInvmandocEntity(); + //存货基础档案 + BdInvbasdocEntity bdInvbasdocEntity = value.get(0).getBdInvbasdocEntity(); + //根据存货基础档案编码,查询当前存货的税率 + BdTaxitemsEntity bdTaxitemsEntity1 = value.get(0).getBdTaxitemsEntity(); + + String tax = null;//税率 + BigDecimal noriginalcurmny = null;//无税金额 + BigDecimal noriginalcurtaxmny = null;//税额 + try { + tax = new BigDecimal(bdTaxitemsEntity1.getTaxratio()).divide(new BigDecimal(100), 20, BigDecimal.ROUND_HALF_UP).setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString(); + noriginalcurmny = passiveStorageSonDetailsDto.getGroupTotalPayAmount().divide(new BigDecimal(1).add(new BigDecimal(tax)), 20, BigDecimal.ROUND_HALF_UP).setScale(2, BigDecimal.ROUND_HALF_UP); + noriginalcurtaxmny = passiveStorageSonDetailsDto.getGroupTotalPayAmount().subtract(noriginalcurmny).setScale(2, BigDecimal.ROUND_HALF_UP); + } catch (Exception e) { + logger.error("金额计算失败", e); + Assert.state(false, "金额计算失败 跑出异常:{}", e.getMessage()); + } + + //组装应收单表体 + List pushScenarioType = new ArrayList<>(); + ArapDjzbVO.Childrenn arapDjzbVOChildrenn = new ArapDjzbVO.Childrenn(); + pushScenarioType.add(arapDjzbVOChildrenn); + arapDjzbVOChildrenn.setCinventoryid(bdInvmandocEntity.getPkInvmandoc());//存货管理档案 + arapDjzbVOChildrenn.setJfbbje("-" + passiveStorageSonDetailsDto.getGroupTotalPayAmount());//借方本币金额 + arapDjzbVOChildrenn.setJfybje("-" + passiveStorageSonDetailsDto.getGroupTotalPayAmount());//借方原币金额 + arapDjzbVOChildrenn.setJfbbsj("-" + noriginalcurmny.stripTrailingZeros().toPlainString());//借方本币税金 + arapDjzbVOChildrenn.setJfybsj("-" + noriginalcurmny.stripTrailingZeros().toPlainString());//借方原币税金 + arapDjzbVOChildrenn.setWbfbbje("-" + noriginalcurtaxmny.stripTrailingZeros().toPlainString());//借方本币无税金额 + arapDjzbVOChildrenn.setJfybwsje("-" + noriginalcurtaxmny.stripTrailingZeros().toPlainString());//借方原币无税金额 + + //退货没有邮费金额,已经向万万确认 + //平台优惠 + if (passiveStorageSonDetailsDto.getVdef4() != null) { + BigDecimal vdef4 = passiveStorageSonDetailsDto.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.additionalV2(pushScenarioType, bdInvmandocEntity1, bdInvbasdocEntity1, negativeValue, bdTaxitemsEntity); + } + } + //达人优惠 + if (passiveStorageSonDetailsDto.getVdef6() != null) { + BigDecimal vdef6 = passiveStorageSonDetailsDto.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.additionalV2(pushScenarioType, bdInvmandocEntity1, bdInvbasdocEntity1, negativeValue, bdTaxitemsEntity); + } + } + //支付优惠 + if (passiveStorageSonDetailsDto.getVdef5() != null) { + BigDecimal vdef5 = passiveStorageSonDetailsDto.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.additionalV2(pushScenarioType, bdInvmandocEntity1, bdInvbasdocEntity1, negativeValue, bdTaxitemsEntity); + } + } + + //推送U8C + ArapDjzbVO arapDjzbVO = new ArapDjzbVO(); + arapDjzbVO.setParentvo(parentVo); + arapDjzbVO.setChildren(pushScenarioType); + String mapStr = "{\"djzbvo\":[" + JSONUtil.toJsonStr(arapDjzbVO) + "]}"; + + ArapDjzb arapDjzb = sendU8cRedReceivable(JSON.toJSONString(mapStr)); + 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红字应收单:{} 销售订单主键:{} 销售公司:{}", djbh, vouchid, dwbm); + updateSuccessOrFail2(value, "Y", "success", djbh, vouchid); + } catch (Exception e) { + logger.error("TOC红字应收单转换成U8C对象过程中、或者单据推送到U8C出现异常!", e); + //记录失败 + String message = e.getMessage(); + if (message == null) { + message = "未知错误"; + } + updateSuccessOrFail2(value, "N", message, null, null); + } + } + } else { + //2024年8月6日 11:28:54此处不记录失败,不认为是错误 + logger.info("summaryDimensionMap变量或者bdBusitypeEntity变量为空,因此主要的推送逻辑不会被执行!"); + } + } catch (Exception e) { + logger.error("外层转换逻辑抛出异常", e); + } + } + } + + /** + * 2025 年 3 月 12 日 15:53:27 + * 生成业务日期:取「关联时间」,只能取关联时间,否则会存在跨月问题 + * + * @author liuyang + */ + private String createGenerateBusinessDate(PassiveStorageResponse.Header header) { + String code = null; + if (header != null && header.getReceiptCode() != null) { + code = header.getReceiptCode(); + } + if (header != null && header.getRelatedAt() != null) { + String closedAt = header.getRelatedAt(); + String businessFormat = null; + try { + Date dbill = DateUtil.parse(closedAt); + businessFormat = DateUtil.format(dbill, "yyyy-MM-dd"); + } catch (Exception e) { + logger.error("业务日期生成失败relatedAt(O 关联时间)解析异常:{} O 无源入库单号:{}", e.getMessage(), code); + Assert.state(false, "业务日期生成失败closedAt(O 关联时间)解析异常:{} O 无源入库单号:{}", e.getMessage(), code); + } + return businessFormat; + } else { + logger.error("业务日期生成失败relatedAt(O 关联时间)不能为空 O 无源入库单号:{}", code); + Assert.state(false, "业务日期生成失败relatedAt(O 关联时间)不能为空 O 无源入库单号:{}", code); + return null; + } + } + + /** + * 2025 年 3 月 13 日 11:09:20 + * 无源件退款完成部分,取关联时间、作为 U8C 的退款时间、已经和万万、还有财务确认过这块逻辑 + * + * @author liuyang + */ + private String createSuccessFulTradeDate(PassiveStorageResponse.Header stockinH) { + String code = null; + if (stockinH != null && stockinH.getReceiptCode() != null) { + code = stockinH.getReceiptCode(); + } + if (stockinH != null && stockinH.getRelatedAt() != null) { + String relatedAt = stockinH.getRelatedAt(); + + String businessFormat = null; + try { + Date dbill = DateUtil.parse(relatedAt); + businessFormat = DateUtil.format(dbill, "yyyy-MM-dd"); + } catch (Exception e) { + logger.error("生成退款业务日期失败(O关联时间)解析异常:{} 无源入库单编码:{}", e.getMessage(), code); + Assert.state(false, "生成退款业务日期失败(O关联时间)解析异常:{} 无源入库单编码:{}", e.getMessage(), code); + } + return businessFormat; + } else { + logger.error("生成退款业务日期失败O关联时间不能为空! 无源件单据编码:{}", code); + Assert.state(false, "生成退款业务日期失败O关联时间不能为空! 无源件单据编码:{}", code); + return null; + } + } + + /** + * 先退款后退货场景时间判断 + */ // public String timeJudgment(StockinOrderSearchResponse.StockinOrder.StockinH stockinH) throws Exception { // Assert.notNull(stockinH, "stockinH不能为空!"); // Assert.notNull(stockinH.getRefundedAt(), "退款完成时间不能为空 O售后入库单号:{}", stockinH.getCode()); @@ -1324,393 +1210,396 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity { // return stockinH.getRefundedAt(); // } // } -// -// /** -// * 档案转换(OFS->U8C) -// * -// * @param passiveStorageResponseDataList OFS无源入库单 -// * @param sceneType 推送场景 -// * @author liuyang -// */ -// private List queryBasicArchivesStock(List passiveStorageResponseDataList, String sceneType) { -// Assert.notNull(passiveStorageResponseDataList, "returnGoodHeaderDetailsDataDtoList1不能为空"); -// Assert.notNull(sceneType, "sceneType不能为空"); -// -// List sonDetailsDtoList = new ArrayList<>(); -// List errorHeaderDetailsDtoDtoList = new ArrayList<>(); -// -// if (passiveStorageResponseDataList != null && passiveStorageResponseDataList.size() > 0) { -// try { -// //查询OFS无源入库单对应的售后订单,并关联无源无源入库单对象 -// List rerturnGoodsOrderSearchData = queryBatchAfterSalesOrder(passiveStorageResponseDataList); -// findAfterSalesOrder(rerturnGoodsOrderSearchData, passiveStorageResponseDataList); -// //查询OFS售后订单对应的OFS销售订单 -// List headerDetailsDtos = queryBatchOfsOrder(passiveStorageResponseDataList); -// findOfsOrder(headerDetailsDtos, passiveStorageResponseDataList); -// -// //初始化档案缓存 -// CacheTocMapVoV2 cacheTocMapVoV2 = passiveComponentsArchivesCacheUtil.initCache(passiveStorageResponseDataList); -// -// //初始化公司档案对照关系 -// Map comparisonCompanyArchives = queryU8CEntityUtil.queryBdDefDocByPkDefDocAll(); -// -// for (int i = 0; i < passiveStorageResponseDataList.size(); i++) { -// PassiveStorageResponse.Data data = passiveStorageResponseDataList.get(i); -// PassiveStorageResponse.Header header = data.getHeader(); -// List details = data.getDetails(); -// -// try { -// //OFS售后订单 -// RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData1 = header.getRerturnGoodsOrderSearchData(); -// Assert.notNull(rerturnGoodsOrderSearchData1, "无法关联到OFS售后订单 售后无源入库单:{}", header.getReceiptCode().trim()); -// RerturnGoodsOrderSearchHeader header2 = rerturnGoodsOrderSearchData1.getHeader(); -// List details2 = rerturnGoodsOrderSearchData1.getDetails(); -// -// //OFS销售订单 -// com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto headerDetailsDto = header.getHeaderDetailsDto(); -// Assert.notNull(headerDetailsDto, "无法关联到OFS销售订单 售后无源入库单:{}", header.getReceiptCode().trim()); -// com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDto header1 = headerDetailsDto.getHeader(); -// List details1 = headerDetailsDto.getDetails(); -// -// //如果不存在,则默认收发类别 -// 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 = header2.getSourcePlatformCode(); -// Assert.notNull(sourcePlatformCode, "O平台编码不能为空!"); -// BdDefdocEntity bdDefdocEntity = cacheTocMapVoV2.getStringBdDefdocEntityMap().get(sourcePlatformCode.trim()); -// Assert.notNull(bdDefdocEntity, "根据O平台编码({})无法匹配到U8C平台档案", header2.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++) { -// PassiveStorageResponse.Details details3 = details.get(j); -// -// //存货管理档案,是发货公司的存货档案 -// Assert.notNull(details3.getSkuCode(), "skucode不能为空"); -// BdInvmandocEntity bdInvmandocEntity = cacheTocMapVoV2.getStringBdInvmandocEntityMap().get(details3.getSkuCode().trim() + bdCorpEntity.getPkCorp()); -// Assert.notNull(bdInvmandocEntity, "无法匹配到存货管理档案 货品sku:{} 公司:{}", details3.getSkuCode().trim(), bdCorpEntity.getPkCorp()); -// //存货基本档案 -// BdInvbasdocEntity bdInvbasdocEntity = cacheTocMapVoV2.getStringBdInvbasdocEntityMap().get(details3.getSkuCode().trim()); -// Assert.notNull(bdInvbasdocEntity, "无法匹配到存货基本档案 存货编码:{}", details3.getSkuCode().trim()); -// //存货税率 -// BdTaxitemsEntity bdTaxitemsEntity = cacheTocMapVoV2.getStringBdTaxitemsEntityMap().get(bdInvmandocEntity.getInvcode()); -// Assert.notNull(bdTaxitemsEntity, "无法匹配到存货税率 存货编码:{}", bdInvmandocEntity.getInvcode()); -// -// //2024年8月6日 10:16:22 通过O出库单的表头,查询得出U8C档案,放在表体的原因是方便分组汇总 -// //下一个步骤的分组汇总,是通过表体明细完成的 -// PassiveStorageSonDetailsDto goodsRertunSonDetailsDto = new PassiveStorageSonDetailsDto(); -// 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(details3, goodsRertunSonDetailsDto); -// sonDetailsDtoList.add(goodsRertunSonDetailsDto); -// //成功收集进入到集合 -// } -// } catch (Exception e) { -// logger.error("档案转换抛出异常", e); -// -// //失败 -// String message = e.getMessage(); -// if (message == null) { -// message = "未知错误"; -// } -// ErrorHeaderDetailsDtoDtoV3 errorHeaderDetailsDtoDto = new ErrorHeaderDetailsDtoDtoV3(); -// 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方法passiveStorageResponseDataList.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 ofsPassiveorderHeaderEntityArrayList = new ArrayList<>(); -// if (stockinHS != null && stockinHS.size() > 0) { -// for (int i = 0; i < stockinHS.size(); i++) { -// PassiveStorageResponse.Header header = stockinHS.get(i); -// -// OfsPassiveorderHeaderEntity ofsPassiveorderHeaderEntity = new OfsPassiveorderHeaderEntity(); -// BeanUtil.copyPropertiesV2(header, ofsPassiveorderHeaderEntity); -// ofsPassiveorderHeaderEntityArrayList.add(ofsPassiveorderHeaderEntity); -// } -// } else { -// logger.info("需要复制{}个bean对象(O表头)", stockinHS.size()); -// } -// return ofsPassiveorderHeaderEntityArrayList; -// } -// -// /** -// * 对象拷贝 bean copy -// * -// * @author liuyang -// */ -// private List copyDetailsDto(List stockinBS) { -// List ofsPassiveorderDetailEntityArrayList = new ArrayList<>(); -// if (stockinBS != null && stockinBS.size() > 0) { -// for (int i = 0; i < stockinBS.size(); i++) { -// PassiveStorageResponse.Details details = stockinBS.get(i); -// //表头 -// PassiveStorageResponse.Header header = details.getHeader(); -// //拷贝对象 -// OfsPassiveorderDetailEntity tocofsReturngoodsDetailedEntity = new OfsPassiveorderDetailEntity(); -// BeanUtil.copyPropertiesV2(details, tocofsReturngoodsDetailedEntity); -// //补充额外的字段信息 -// createPrimaryKeyAndBusinessDateAndBusinessType(tocofsReturngoodsDetailedEntity, header); -// ofsPassiveorderDetailEntityArrayList.add(tocofsReturngoodsDetailedEntity); -// } -// } else { -// logger.info("需要复制{}个bean对象(O表体)", ofsPassiveorderDetailEntityArrayList.size()); -// } -// return ofsPassiveorderDetailEntityArrayList; -// } -// -// /** -// * 分组汇总:公司+店铺+仓库+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++) { -// PassiveStorageSonDetailsDto passiveStorageSonDetailsDto = goodsRertunSonDetailsDtos.get(i); -// //2024年8月6日 10:35:25表头对象用于带出表头相关的分组汇总信息 -// PassiveStorageResponse.Header header = passiveStorageSonDetailsDto.getHeader(); -// RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = header.getRerturnGoodsOrderSearchData();//OFS售后订单 -// com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto headerDetailsDto = header.getHeaderDetailsDto();//OFS销售订单 -// -// //公司 -// BdCorpEntity bdCorpEntity = passiveStorageSonDetailsDto.getBdCorpEntity(); -// //店铺(主要是店铺编码) -// String storeCode = header.getStoreCode(); -// //仓库 -// String facilityCode = header.getFacilityCode(); -// //SKU -// String skuCode = passiveStorageSonDetailsDto.getSkuCode(); -// //出库类型 -//// String refOrderType = header.getRefOrderType(); -// //收发类别 -// BdRdclEntity bdRdclEntity = passiveStorageSonDetailsDto.getBdRdclEntity(); -// //部门 -// BdDeptdocEntity bdDeptdocEntity = passiveStorageSonDetailsDto.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 (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); -// } -// -// passiveStorageSonDetailsDto.setSummaryDimensionStr(summaryDimensionStr.toString()); -// } -// logger.info("无源件:{} 个出库单对象需要汇总", goodsRertunSonDetailsDtos.size()); -// if (dimension == null) { -// return goodsRertunSonDetailsDtos.stream().collect(Collectors.groupingBy(PassiveStorageSonDetailsDto::getSummaryDimensionStr)); -// } else { -// Map> collect = goodsRertunSonDetailsDtos.stream().collect(Collectors.groupingBy(PassiveStorageSonDetailsDto::getSummaryDimensionStr)); -// keepOnlyNeededKeys(collect, dimension); -// return collect; -// } -// } -// logger.info("无源件: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 -// */ + + /** + * 档案转换(OFS->U8C) + * + * @param passiveStorageResponseDataList OFS无源入库单 + * @param sceneType 推送场景 + * @author liuyang + */ + private List queryBasicArchivesStock(List passiveStorageResponseDataList, String sceneType) { + Assert.notNull(passiveStorageResponseDataList, "returnGoodHeaderDetailsDataDtoList1不能为空"); + Assert.notNull(sceneType, "sceneType不能为空"); + + List sonDetailsDtoList = new ArrayList<>(); + List errorHeaderDetailsDtoDtoList = new ArrayList<>(); + + if (passiveStorageResponseDataList != null && passiveStorageResponseDataList.size() > 0) { + try { + //查询OFS无源入库单对应的售后订单,并关联无源无源入库单对象 + List rerturnGoodsOrderSearchData = queryBatchAfterSalesOrder(passiveStorageResponseDataList); + findAfterSalesOrder(rerturnGoodsOrderSearchData, passiveStorageResponseDataList); + //查询OFS售后订单对应的OFS销售订单 + List headerDetailsDtos = queryBatchOfsOrder(passiveStorageResponseDataList); + findOfsOrder(headerDetailsDtos, passiveStorageResponseDataList); + + //初始化档案缓存 + CacheTocMapVoV2 cacheTocMapVoV2 = passiveComponentsArchivesCacheUtil.initCache(passiveStorageResponseDataList); + + //初始化公司档案对照关系 + Map comparisonCompanyArchives = queryU8CEntityUtil.queryBdDefDocByPkDefDocAll(); + + for (int i = 0; i < passiveStorageResponseDataList.size(); i++) { + PassiveStorageResponse.Data data = passiveStorageResponseDataList.get(i); + PassiveStorageResponse.Header header = data.getHeader(); + List details = data.getDetails(); + +// String transactionDate = null; + try { + //OFS售后订单 + RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData1 = header.getRerturnGoodsOrderSearchData(); + Assert.notNull(rerturnGoodsOrderSearchData1, "无法关联到OFS售后订单 售后无源入库单:{}", header.getReceiptCode().trim()); + RerturnGoodsOrderSearchHeader header2 = rerturnGoodsOrderSearchData1.getHeader(); + List details2 = rerturnGoodsOrderSearchData1.getDetails(); + //用于抛出异常时,记录交易成功时间 +// transactionDate = header2.getRefundedAt(); + + //OFS销售订单 + com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto headerDetailsDto = header.getHeaderDetailsDto(); + Assert.notNull(headerDetailsDto, "无法关联到OFS销售订单 售后无源入库单:{}", header.getReceiptCode().trim()); + com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDto header1 = headerDetailsDto.getHeader(); + List details1 = headerDetailsDto.getDetails(); + + //如果不存在,则默认收发类别 + 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 = header2.getSourcePlatformCode(); + Assert.notNull(sourcePlatformCode, "O平台编码不能为空!"); + BdDefdocEntity bdDefdocEntity = cacheTocMapVoV2.getStringBdDefdocEntityMap().get(sourcePlatformCode.trim()); + Assert.notNull(bdDefdocEntity, "根据O平台编码({})无法匹配到U8C平台档案", header2.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++) { + PassiveStorageResponse.Details details3 = details.get(j); + + //存货管理档案,是发货公司的存货档案 + Assert.notNull(details3.getSkuCode(), "skucode不能为空"); + BdInvmandocEntity bdInvmandocEntity = cacheTocMapVoV2.getStringBdInvmandocEntityMap().get(details3.getSkuCode().trim() + bdCorpEntity.getPkCorp()); + Assert.notNull(bdInvmandocEntity, "无法匹配到存货管理档案 货品sku:{} 公司:{}", details3.getSkuCode().trim(), bdCorpEntity.getPkCorp()); + //存货基本档案 + BdInvbasdocEntity bdInvbasdocEntity = cacheTocMapVoV2.getStringBdInvbasdocEntityMap().get(details3.getSkuCode().trim()); + Assert.notNull(bdInvbasdocEntity, "无法匹配到存货基本档案 存货编码:{}", details3.getSkuCode().trim()); + //存货税率 + BdTaxitemsEntity bdTaxitemsEntity = cacheTocMapVoV2.getStringBdTaxitemsEntityMap().get(bdInvmandocEntity.getInvcode()); + Assert.notNull(bdTaxitemsEntity, "无法匹配到存货税率 存货编码:{}", bdInvmandocEntity.getInvcode()); + + //2024年8月6日 10:16:22 通过O出库单的表头,查询得出U8C档案,放在表体的原因是方便分组汇总 + //下一个步骤的分组汇总,是通过表体明细完成的 + PassiveStorageSonDetailsDto goodsRertunSonDetailsDto = new PassiveStorageSonDetailsDto(); + 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(details3, goodsRertunSonDetailsDto); + sonDetailsDtoList.add(goodsRertunSonDetailsDto); + //成功收集进入到集合 + } + } catch (Exception e) { + //失败部分处理 + logger.error("档案转换抛出异常", e); + String message = e.getMessage(); + if (message == null) { + message = "未知错误"; + } + ErrorHeaderDetailsDtoDtoV3 errorHeaderDetailsDtoDto = new ErrorHeaderDetailsDtoDtoV3(); + errorHeaderDetailsDtoDto.setNewPushDate(getNewDateStr()); + errorHeaderDetailsDtoDto.setNewTransmitInfo(message); + errorHeaderDetailsDtoDto.setNewstate("N"); + errorHeaderDetailsDtoDto.setHeader(header); + errorHeaderDetailsDtoDto.setDetails(details); +// errorHeaderDetailsDtoDto.setTransactionDate(transactionDate); + errorHeaderDetailsDtoDtoList.add(errorHeaderDetailsDtoDto); + } + } + } catch (Exception e) { + logger.error("OFS无源入库单关联查询U8C档案失败", e); + } + } else { + logger.info("queryBasicArchives方法passiveStorageResponseDataList.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 ofsPassiveorderHeaderEntityArrayList = new ArrayList<>(); + if (stockinHS != null && stockinHS.size() > 0) { + for (int i = 0; i < stockinHS.size(); i++) { + PassiveStorageResponse.Header header = stockinHS.get(i); + + OfsPassiveorderHeaderEntity ofsPassiveorderHeaderEntity = new OfsPassiveorderHeaderEntity(); + BeanUtil.copyPropertiesV2(header, ofsPassiveorderHeaderEntity); + ofsPassiveorderHeaderEntityArrayList.add(ofsPassiveorderHeaderEntity); + } + } else { + logger.info("需要复制{}个bean对象(O表头)", stockinHS.size()); + } + return ofsPassiveorderHeaderEntityArrayList; + } + + /** + * 对象拷贝 bean copy + * + * @author liuyang + */ + private List copyDetailsDto(List stockinBS) { + List ofsPassiveorderDetailEntityArrayList = new ArrayList<>(); + if (stockinBS != null && stockinBS.size() > 0) { + for (int i = 0; i < stockinBS.size(); i++) { + PassiveStorageResponse.Details details = stockinBS.get(i); + //表头 + PassiveStorageResponse.Header header = details.getHeader(); + //拷贝对象 + OfsPassiveorderDetailEntity tocofsReturngoodsDetailedEntity = new OfsPassiveorderDetailEntity(); + BeanUtil.copyPropertiesV2(details, tocofsReturngoodsDetailedEntity); + //补充额外的字段信息 + createPrimaryKeyAndBusinessDateAndBusinessType(tocofsReturngoodsDetailedEntity, header); + ofsPassiveorderDetailEntityArrayList.add(tocofsReturngoodsDetailedEntity); + } + } else { + logger.info("需要复制{}个bean对象(O表体)", ofsPassiveorderDetailEntityArrayList.size()); + } + return ofsPassiveorderDetailEntityArrayList; + } + + /** + * 分组汇总:公司+店铺+仓库+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++) { + PassiveStorageSonDetailsDto passiveStorageSonDetailsDto = goodsRertunSonDetailsDtos.get(i); + //2024年8月6日 10:35:25表头对象用于带出表头相关的分组汇总信息 + PassiveStorageResponse.Header header = passiveStorageSonDetailsDto.getHeader(); + RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = header.getRerturnGoodsOrderSearchData();//OFS售后订单 + com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto headerDetailsDto = header.getHeaderDetailsDto();//OFS销售订单 + + //公司 + BdCorpEntity bdCorpEntity = passiveStorageSonDetailsDto.getBdCorpEntity(); + //店铺(主要是店铺编码) + String storeCode = header.getStoreCode(); + //仓库 + String facilityCode = header.getFacilityCode(); + //SKU + String skuCode = passiveStorageSonDetailsDto.getSkuCode(); + //出库类型 +// String refOrderType = header.getRefOrderType(); + //收发类别 + BdRdclEntity bdRdclEntity = passiveStorageSonDetailsDto.getBdRdclEntity(); + //部门 + BdDeptdocEntity bdDeptdocEntity = passiveStorageSonDetailsDto.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 (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); + } + + passiveStorageSonDetailsDto.setSummaryDimensionStr(summaryDimensionStr.toString()); + } + logger.info("无源件:{} 个出库单对象需要汇总", goodsRertunSonDetailsDtos.size()); + if (dimension == null) { + return goodsRertunSonDetailsDtos.stream().collect(Collectors.groupingBy(PassiveStorageSonDetailsDto::getSummaryDimensionStr)); + } else { + Map> collect = goodsRertunSonDetailsDtos.stream().collect(Collectors.groupingBy(PassiveStorageSonDetailsDto::getSummaryDimensionStr)); + keepOnlyNeededKeys(collect, dimension); + return collect; + } + } + logger.info("无源件: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)); @@ -1723,211 +1612,266 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity { // 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, "发货公司主键不能为空"); // -// /** -// * 查询存货管理档案 -// * -// * @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 PassiveStorageSonDetailsDto groupMergeDetailedRows(List sonDetailsDtoList, Boolean isCheckShopChoose) throws Exception { -// Assert.notNull(sonDetailsDtoList, "sonDetailsDtoList不能为空"); -// Assert.notNull(isCheckShopChoose, "isCheckShopChoose不能为空"); -// -// if (sonDetailsDtoList != null && sonDetailsDtoList.size() > 0) { -// BigDecimal groupTotalPayAmount = new BigDecimal("0"); -// BigDecimal groupShipQty = new BigDecimal("0"); -// -// for (int i = 0; i < sonDetailsDtoList.size(); i++) { -// PassiveStorageSonDetailsDto passiveStorageSonDetailsDto = sonDetailsDtoList.get(i); -// PassiveStorageResponse.Header header = passiveStorageSonDetailsDto.getHeader(); -// -// RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = header.getRerturnGoodsOrderSearchData();//OFS售后订单 -// RerturnGoodsOrderSearchHeader header1 = rerturnGoodsOrderSearchData.getHeader();//OFS售后订单表头对象 -// List details = rerturnGoodsOrderSearchData.getDetails();//OFS售后订单表体对象 -// -//// BdInvmandocEntity bdInvmandocEntity1 = goodsRertunSonDetailsDto.getBdInvmandocEntity();//存货管理档案 -// BdInvbasdocEntity bdInvbasdocEntity = passiveStorageSonDetailsDto.getBdInvbasdocEntity();//存货基本档案 -// BdInvmandocEntity bdInvmandocEntity = passiveStorageSonDetailsDto.getBdInvmandocEntity();//存货管理档案 -// -// //根据OFS售后入库单明细行,查找匹配OFS售后订单明细行 -// RerturnGoodsOrderSearchDetails ofsOrderDetail = findOfsOrderDetail(details, passiveStorageSonDetailsDto); -// -// String totalAmount = null; -// StringBuffer calculationFormulaStr = new StringBuffer(); -// if (isCheckShopChoose) { -// //取《U8C存货基本档案-参考售价》 -// totalAmount = getRefsaleprice(bdInvmandocEntity, bdInvbasdocEntity, calculationFormulaStr, passiveStorageSonDetailsDto); -// } else { -// //取《O实退》 -// totalAmount = accumulatedDiscounts(passiveStorageSonDetailsDto, rerturnGoodsOrderSearchData, calculationFormulaStr); -// } -// -// Assert.notNull(totalAmount, "计算出来的实退金额不能为空"); -// Assert.notNull(passiveStorageSonDetailsDto.getQuantity(), "实收数量不能为空"); -// -// BigDecimal totalPayAmountBigDecimal = new BigDecimal(totalAmount); -// BigDecimal quantityBigDecimal = new BigDecimal(passiveStorageSonDetailsDto.getQuantity()); -// -// groupTotalPayAmount = groupTotalPayAmount.add(totalPayAmountBigDecimal); -// groupShipQty = groupShipQty.add(quantityBigDecimal); -// -// passiveStorageSonDetailsDto.setCalculateAccountsReceivable(totalAmount); -// passiveStorageSonDetailsDto.setCalculationFormula(calculationFormulaStr.toString()); -// -// passiveStorageSonDetailsDto.setPlatformDiscounts(ofsOrderDetail.getPlatformDiscounts()); -// passiveStorageSonDetailsDto.setMerchantDiscounts(ofsOrderDetail.getMerchantDiscounts()); -// passiveStorageSonDetailsDto.setExpertDiscounts(ofsOrderDetail.getExpertDiscounts()); -// passiveStorageSonDetailsDto.setPayDiscounts(ofsOrderDetail.getPayDiscounts()); -// } -// -// PassiveStorageSonDetailsDto passiveStorageSonDetailsDto = sonDetailsDtoList.get(0); -// passiveStorageSonDetailsDto.setGroupShipQty(groupShipQty); -// passiveStorageSonDetailsDto.setGroupTotalPayAmount(groupTotalPayAmount); -// -// //汇总好之后,相同的sku累加优惠金额 -// accumulatedDiscountAmountDef(sonDetailsDtoList); -// -// return passiveStorageSonDetailsDto; -// } else { -// logger.info("sonDetailsDtoList集合是空的!"); -// } -// return null; +// BdInvmandocEntity bdInvmandocEntity = TocReturnBasicArchivesCacheUtil.stringBdInvmandocEntityMap.get(goodsRertunSonDetailsDto.getSkuCode() + pkCorp); +// Assert.notNull(bdInvmandocEntity, "无法匹配到存货管理档案 存货商家编码:{} 存货发货公司:{}", goodsRertunSonDetailsDto.getSkuCode(), pkCorp); +// return bdInvmandocEntity; // } -// -// /** -// * 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; + + /** + * 合并明细行 + * 单价计算公式:sum(实付金额/实发数量) 最后除以条数 + * + * @param sonDetailsDtoList 汇总过后的售后入库单明细 + * @param isCheckShopChoose true取建议零售价、false取实付金额 + * @author liuyang + */ + private PassiveStorageSonDetailsDto groupMergeDetailedRows(List sonDetailsDtoList, Boolean isCheckShopChoose) throws Exception { + Assert.notNull(sonDetailsDtoList, "sonDetailsDtoList不能为空"); + Assert.notNull(isCheckShopChoose, "isCheckShopChoose不能为空"); + + if (sonDetailsDtoList != null && sonDetailsDtoList.size() > 0) { + BigDecimal groupTotalPayAmount = new BigDecimal("0"); + BigDecimal groupShipQty = new BigDecimal("0"); + + for (int i = 0; i < sonDetailsDtoList.size(); i++) { + PassiveStorageSonDetailsDto passiveStorageSonDetailsDto = sonDetailsDtoList.get(i); + PassiveStorageResponse.Header header = passiveStorageSonDetailsDto.getHeader(); + + RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = header.getRerturnGoodsOrderSearchData();//OFS售后订单 + RerturnGoodsOrderSearchHeader header1 = rerturnGoodsOrderSearchData.getHeader();//OFS售后订单表头对象 + List details = rerturnGoodsOrderSearchData.getDetails();//OFS售后订单表体对象 + +// BdInvmandocEntity bdInvmandocEntity1 = goodsRertunSonDetailsDto.getBdInvmandocEntity();//存货管理档案 + BdInvbasdocEntity bdInvbasdocEntity = passiveStorageSonDetailsDto.getBdInvbasdocEntity();//存货基本档案 + BdInvmandocEntity bdInvmandocEntity = passiveStorageSonDetailsDto.getBdInvmandocEntity();//存货管理档案 + + //根据OFS售后入库单明细行,查找匹配OFS售后订单明细行 + RerturnGoodsOrderSearchDetails ofsOrderDetail = findOfsOrderDetail(details, passiveStorageSonDetailsDto); + + String totalAmount = null; + StringBuffer calculationFormulaStr = new StringBuffer(); + if (isCheckShopChoose) { + //取《U8C存货基本档案-参考售价》 + totalAmount = getRefsaleprice(bdInvmandocEntity, bdInvbasdocEntity, calculationFormulaStr, passiveStorageSonDetailsDto); + } else { + //取《O实退》 + totalAmount = accumulatedDiscounts(passiveStorageSonDetailsDto, rerturnGoodsOrderSearchData, calculationFormulaStr); + } + + Assert.notNull(totalAmount, "计算出来的实退金额不能为空"); + Assert.notNull(passiveStorageSonDetailsDto.getQuantity(), "实收数量不能为空"); + + BigDecimal totalPayAmountBigDecimal = new BigDecimal(totalAmount); + BigDecimal quantityBigDecimal = new BigDecimal(passiveStorageSonDetailsDto.getQuantity()); + + groupTotalPayAmount = groupTotalPayAmount.add(totalPayAmountBigDecimal); + groupShipQty = groupShipQty.add(quantityBigDecimal); + + passiveStorageSonDetailsDto.setCalculateAccountsReceivable(totalAmount); + passiveStorageSonDetailsDto.setCalculationFormula(calculationFormulaStr.toString()); + + passiveStorageSonDetailsDto.setPlatformDiscounts(ofsOrderDetail.getPlatformDiscounts()); + passiveStorageSonDetailsDto.setMerchantDiscounts(ofsOrderDetail.getMerchantDiscounts()); + passiveStorageSonDetailsDto.setExpertDiscounts(ofsOrderDetail.getExpertDiscounts()); + passiveStorageSonDetailsDto.setPayDiscounts(ofsOrderDetail.getPayDiscounts()); + } + + PassiveStorageSonDetailsDto passiveStorageSonDetailsDto = sonDetailsDtoList.get(0); + passiveStorageSonDetailsDto.setGroupShipQty(groupShipQty); + passiveStorageSonDetailsDto.setGroupTotalPayAmount(groupTotalPayAmount); + + //汇总好之后,相同的sku累加优惠金额 + accumulatedDiscountAmountDef(sonDetailsDtoList); + + return passiveStorageSonDetailsDto; + } 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; // } -// -// /** -// * 返回结果解析处理,在确认了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月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月15日 17:31:54 -// * -// * @param ofsPassiveorderDetailEntity 无源件明细表 dao 对象 -// * @param header O 无源件明细原始对象 -// */ -// private void createPrimaryKeyAndBusinessDateAndBusinessType(OfsPassiveorderDetailEntity ofsPassiveorderDetailEntity, PassiveStorageResponse.Header header) { -// if (ofsPassiveorderDetailEntity != null && header != null) { -// //主表主键 -// if (header.getId() != null) { -// ofsPassiveorderDetailEntity.setHeaderid(header.getId()); -// } -// //业务日期 -// if (header.getRelatedAt() != null) { -// ofsPassiveorderDetailEntity.setBusinessdate(header.getRelatedAt()); -// } -// //业务类型 -// ofsPassiveorderDetailEntity.setBusinesstype("TOC_ORDER"); -// } -// } -// -// /** -// * 通过OFS销售出库单,联查OFS销售订单 -// * -// * @param headerDetailsDtoList OFS销售出库单 -// */ + + /** + * 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; + } + + /** + * 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("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; + 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; + } + + /** + * 返回结果解析处理,在确认了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; + } + + 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; + } + + /** + * 填充主表主键、业务日期、业务类型 + * 2024年8月15日 17:31:54 + * + * @param ofsPassiveorderDetailEntity 无源件明细表 dao 对象 + * @param header O 无源件明细原始对象 + */ + private void createPrimaryKeyAndBusinessDateAndBusinessType(OfsPassiveorderDetailEntity ofsPassiveorderDetailEntity, PassiveStorageResponse.Header header) { + if (ofsPassiveorderDetailEntity != null && header != null) { + //主表主键 + if (header.getId() != null) { + ofsPassiveorderDetailEntity.setHeaderid(header.getId()); + } + //业务日期 + if (header.getRelatedAt() != null) { + ofsPassiveorderDetailEntity.setBusinessdate(header.getRelatedAt()); + } + //业务类型 + ofsPassiveorderDetailEntity.setBusinesstype("TOC_ORDER"); + } + } + + /** + * 通过OFS销售出库单,联查OFS销售订单 + * + * @param headerDetailsDtoList OFS销售出库单 + */ // private List queryOfsOrder(List headerDetailsDtoList) throws Exception { // List allHeaderDetailsDtoArrayList = new ArrayList<>(); // try { @@ -1962,108 +1906,117 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity { // } // return allHeaderDetailsDtoArrayList; // } -// -// /** -// * 批量查询售后订单 -// * -// * @param returnGoodHeaderDetailsDataDtoList1 OFS售后入库单 -// * @author liuyang -// */ -// private List queryBatchAfterSalesOrder(List returnGoodHeaderDetailsDataDtoList1) { -// List rerturnGoodsOrderSearchDataList = new ArrayList<>(); -// if (returnGoodHeaderDetailsDataDtoList1 != null && returnGoodHeaderDetailsDataDtoList1.size() > 0) { -// try { -// //完成去重,已经和万万确认,售后入库单明细行不会有合单的情况 -// Set returnOrderCodeSet = new HashSet<>(); -// for (int i = 0; i < returnGoodHeaderDetailsDataDtoList1.size(); i++) { -// PassiveStorageResponse.Data data = returnGoodHeaderDetailsDataDtoList1.get(i); -// PassiveStorageResponse.Header header = data.getHeader(); -// List details = data.getDetails(); -// -// String returnOrderCode = header.getReturnOrderCode(); -// if (returnOrderCode != null && !"".equals(returnOrderCode.trim())) { -// returnOrderCodeSet.add(returnOrderCode.trim()); -// } -// } -// -// if (returnOrderCodeSet.size() > 0) { -// List stringList = returnOrderCodeSet.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); -// Assert.state(false, "批量查询售后订单跑出异常,异常原因:{}", e.getMessage()); -// } -// } -// return rerturnGoodsOrderSearchDataList; -// } -// -// /** -// * 匹配售后订单 -// * -// * @param rerturnGoodsOrderSearchDataList OFS售后订单集合 -// * @param passiveStorageResponseList 无源入库单对象 -// * @author liuyang -// */ -// private void findAfterSalesOrder(List rerturnGoodsOrderSearchDataList, List passiveStorageResponseList) throws Exception { -// if (rerturnGoodsOrderSearchDataList != null && rerturnGoodsOrderSearchDataList.size() > 0 && passiveStorageResponseList != null && passiveStorageResponseList.size() > 0) { -// try { -// //key为售后订单主键,如果id为空,则这里会报错,所以把id设置为"" -// //使用 stream 完成快速查找 -// rerturnGoodsOrderSearchDataList.forEach(dto -> { -// if (dto.getHeader() != null && dto.getHeader().getId() == null) { -// dto.getHeader().setId(""); -// } -// }); -// Map collect = rerturnGoodsOrderSearchDataList.stream().collect(Collectors.toMap(dto -> dto.getHeader().getCode(), dto -> dto)); -// -// //查询关联匹配 -// for (int i = 0; i < passiveStorageResponseList.size(); i++) { -// PassiveStorageResponse.Data data = passiveStorageResponseList.get(i); -// PassiveStorageResponse.Header header = data.getHeader(); -// List details = data.getDetails(); -// -// String returnOrderCode = header.getReturnOrderCode(); -// if (returnOrderCode != null && !"".equals(returnOrderCode)) { -// RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = collect.get(returnOrderCode); -// if (rerturnGoodsOrderSearchData != null) { -// header.setRerturnGoodsOrderSearchData(rerturnGoodsOrderSearchData); -// } -// } -// } -// -// //去死皮 -// for (PassiveStorageResponse.Data data : passiveStorageResponseList) { -// PassiveStorageResponse.Header header = data.getHeader(); -// String returnOrderCode = header.getReturnOrderCode(); -// -// RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = header.getRerturnGoodsOrderSearchData(); -// if (rerturnGoodsOrderSearchData == null) { -// Assert.state(false, "无源入库单{}无法匹配到售后订单号 售后订单号:{}", header.getReceiptCode(), header.getReturnOrderCode()); -// } -// } -// } catch (Exception e) { -// logger.error("findAfterSalesOrder方法抛出异常", e); -// } -// } -// } -// -// /** -// * 通过售后入库单明细行,查找售后订单明细行 -// * -// * @param stockinB 售后订单明细行 -// * @param ofsRertunOrder OFS售后订单 -// * @author liuyang -// */ + + /** + * 批量查询售后订单 + * + * @param returnGoodHeaderDetailsDataDtoList1 OFS售后入库单 + * @author liuyang + */ + private List queryBatchAfterSalesOrder(List returnGoodHeaderDetailsDataDtoList1) { + List rerturnGoodsOrderSearchDataList = new ArrayList<>(); + if (returnGoodHeaderDetailsDataDtoList1 != null && returnGoodHeaderDetailsDataDtoList1.size() > 0) { + try { + //完成去重,已经和万万确认,售后入库单明细行不会有合单的情况 + Set returnOrderCodeSet = new HashSet<>(); + for (int i = 0; i < returnGoodHeaderDetailsDataDtoList1.size(); i++) { + PassiveStorageResponse.Data data = returnGoodHeaderDetailsDataDtoList1.get(i); + PassiveStorageResponse.Header header = data.getHeader(); + List details = data.getDetails(); + + String returnOrderCode = header.getReturnOrderCode(); + if (returnOrderCode != null && !"".equals(returnOrderCode.trim())) { + returnOrderCodeSet.add(returnOrderCode.trim()); + } + } + + if (returnOrderCodeSet.size() > 0) { + List stringList = returnOrderCodeSet.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); + Assert.state(false, "批量查询售后订单跑出异常,异常原因:{}", e.getMessage()); + } + } + return rerturnGoodsOrderSearchDataList; + } + + /** + * 匹配售后订单 + * + * @param rerturnGoodsOrderSearchDataList OFS售后订单集合 + * @param passiveStorageResponseList 无源入库单对象 + * @author liuyang + */ + private void findAfterSalesOrder(List rerturnGoodsOrderSearchDataList, List passiveStorageResponseList) throws Exception { + if (rerturnGoodsOrderSearchDataList != null && rerturnGoodsOrderSearchDataList.size() > 0 && passiveStorageResponseList != null && passiveStorageResponseList.size() > 0) { + try { + //key为售后订单主键,如果id为空,则这里会报错,所以把id设置为"" + //使用 stream 完成快速查找 + rerturnGoodsOrderSearchDataList.forEach(dto -> { + if (dto.getHeader() != null && dto.getHeader().getId() == null) { + dto.getHeader().setId(""); + } + }); + Map collect = rerturnGoodsOrderSearchDataList.stream().collect(Collectors.toMap(dto -> dto.getHeader().getCode(), dto -> dto)); + + //O无源入库单关联售后订单 + //O 售后订单表头交易成功时间,导入到无源入库单明细行 + for (int i = 0; i < passiveStorageResponseList.size(); i++) { + PassiveStorageResponse.Data data = passiveStorageResponseList.get(i); + PassiveStorageResponse.Header header = data.getHeader(); + List details = data.getDetails(); + + String returnOrderCode = header.getReturnOrderCode(); + if (returnOrderCode != null && !"".equals(returnOrderCode)) { + RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = collect.get(returnOrderCode); + if (rerturnGoodsOrderSearchData != null) { + header.setRerturnGoodsOrderSearchData(rerturnGoodsOrderSearchData); + + RerturnGoodsOrderSearchHeader header1 = rerturnGoodsOrderSearchData.getHeader(); + List details1 = rerturnGoodsOrderSearchData.getDetails(); + + String refundedAt = header1.getRefundedAt(); + for (PassiveStorageResponse.Details passiveStorage : details) { + passiveStorage.setRefundedAt(refundedAt); + } + } + } + } + + //去死皮 + for (PassiveStorageResponse.Data data : passiveStorageResponseList) { + PassiveStorageResponse.Header header = data.getHeader(); + String returnOrderCode = header.getReturnOrderCode(); + + RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = header.getRerturnGoodsOrderSearchData(); + if (rerturnGoodsOrderSearchData == null) { + Assert.state(false, "无源入库单{}无法匹配到售后订单号 售后订单号:{}", header.getReceiptCode(), header.getReturnOrderCode()); + } + } + } 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不能为空!"); @@ -2084,585 +2037,586 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity { // 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++) { -// PassiveStorageResponse.Data data = returnGoodHeaderDetailsDataDtoList1.get(i); -// PassiveStorageResponse.Header header = data.getHeader(); -// List details = data.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()); -// } -// } -// } -// -// //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 O无源入库单 -// * @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++) { -// PassiveStorageResponse.Data data = returnGoodHeaderDetailsDataDtoList1.get(i); -// PassiveStorageResponse.Header header = data.getHeader(); -// List details = data.getDetails(); -// -// //OFS售后订单 -// RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = header.getRerturnGoodsOrderSearchData(); -// RerturnGoodsOrderSearchHeader header2 = rerturnGoodsOrderSearchData.getHeader(); -// List details2 = rerturnGoodsOrderSearchData.getDetails(); -// 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); -// Assert.state(false, "findOfsOrder方法抛出异常 错误详情:{}", e.getMessage()); -// } -// } -// } -// -// /** -// * 生成当前日期 -// * -// * @author liuyang -// */ -// private String getNewDateStr() { -// LocalDateTime now = LocalDateTime.now(); -// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); -// return now.format(formatter); -// } -// -// /** -// * 批量修改成功、或者失败,适合档案查询的部分 -// * -// * @param errorHeaderDetailsDtoDtoV3List 错误日志 -// * @param sceneType 场景类型 -// * @author liuyang -// */ -// private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry(List errorHeaderDetailsDtoDtoV3List, String sceneType) { -// Assert.notNull(errorHeaderDetailsDtoDtoV3List, "errorHeaderDetailsDtoDtoV3List不能为空!"); -// Assert.notNull(sceneType, "sceneType不能为空!"); -// -// Thread thread = new Thread(new Runnable() { -// @Override -// public void run() { -// try { -// if (errorHeaderDetailsDtoDtoV3List != null && errorHeaderDetailsDtoDtoV3List.size() > 0) { -// List tocofsSaleoutDetailedEntityList = new ArrayList<>(); -// for (int i = 0; i < errorHeaderDetailsDtoDtoV3List.size(); i++) { -// ErrorHeaderDetailsDtoDtoV3 errorHeaderDetailsDtoDtoV3 = errorHeaderDetailsDtoDtoV3List.get(i); -// PassiveStorageResponse.Header header = errorHeaderDetailsDtoDtoV3.getHeader(); -// List details = errorHeaderDetailsDtoDtoV3.getDetails(); -// -// String newstate = errorHeaderDetailsDtoDtoV3.getNewstate(); -// String newPushDate = errorHeaderDetailsDtoDtoV3.getNewPushDate(); -// String newTransmitInfo = errorHeaderDetailsDtoDtoV3.getNewTransmitInfo(); -// String newsystemnumber = errorHeaderDetailsDtoDtoV3.getNewsystemnumber(); -// String newsystemprimary = errorHeaderDetailsDtoDtoV3.getNewsystemprimary(); -// -// //如果报错内容太长了,则仅保留400个长度,维护数据库性能,缓解资源公平使用 -// if (newTransmitInfo != null && !"".equals(newTransmitInfo.trim()) && newTransmitInfo.length() >= 400) { -// newTransmitInfo = newTransmitInfo.substring(0, 400); -// } -// -// for (int j = 0; j < details.size(); j++) { -// PassiveStorageResponse.Details details1 = details.get(j); -// -// OfsPassiveorderDetailEntity ofsPassiveorderDetailEntity = new OfsPassiveorderDetailEntity(); -// ofsPassiveorderDetailEntity.setId(details1.getId()); -// if (sceneType.equals("stock")) { -// ofsPassiveorderDetailEntity.setNewpushdate(newPushDate); -// ofsPassiveorderDetailEntity.setNewtransmitinfo(newTransmitInfo); -// ofsPassiveorderDetailEntity.setNewstate(newstate); -// if (!"N".equals(newstate)) { -// ofsPassiveorderDetailEntity.setNewsystemnumber(newsystemnumber); -// ofsPassiveorderDetailEntity.setNewsystemprimary(newsystemprimary); -// } -// -// } else if (sceneType.equals("tran")) { -// ofsPassiveorderDetailEntity.setNewpushdate2(newPushDate); -// ofsPassiveorderDetailEntity.setNewtransmitinfo2(newTransmitInfo); -// ofsPassiveorderDetailEntity.setNewstate2(newstate); -// if (!"N".equals(newstate)) { -// ofsPassiveorderDetailEntity.setNewsystemnumber2(newsystemnumber); -// ofsPassiveorderDetailEntity.setNewsystemprimary2(newTransmitInfo); -// } -// } -// tocofsSaleoutDetailedEntityList.add(ofsPassiveorderDetailEntity); -// } -// } -// -// //以50行为一个批次更新状态,并且入库和确认收入调用不同的方法 -// if (tocofsSaleoutDetailedEntityList.size() > 0) { -// List> lists = SplitListByCountUtil.splitListByCount(tocofsSaleoutDetailedEntityList, 50); -// for (int i = 0; i < lists.size(); i++) { -// List ofsPassiveorderDetailEntities = lists.get(i); -// if (sceneType.equals("stock")) { -// iOfsPassiveorderDetailDao.entityInsertOrUpdateBatchByStock(ofsPassiveorderDetailEntities); -// } else if (sceneType.equals("tran")) { -// iOfsPassiveorderDetailDao.entityInsertOrUpdateBatchByTran(ofsPassiveorderDetailEntities); -// } + + /** + * 通过售后入库单对应的售后订单,查询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++) { + PassiveStorageResponse.Data data = returnGoodHeaderDetailsDataDtoList1.get(i); + PassiveStorageResponse.Header header = data.getHeader(); + List details = data.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()); + } + } + } + + //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 O无源入库单 + * @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++) { + PassiveStorageResponse.Data data = returnGoodHeaderDetailsDataDtoList1.get(i); + PassiveStorageResponse.Header header = data.getHeader(); + List details = data.getDetails(); + + //把O无源入库单表头关联O销售订单 + RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = header.getRerturnGoodsOrderSearchData(); + RerturnGoodsOrderSearchHeader header2 = rerturnGoodsOrderSearchData.getHeader(); + List details2 = rerturnGoodsOrderSearchData.getDetails(); + 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); + Assert.state(false, "findOfsOrder方法抛出异常 错误详情:{}", e.getMessage()); + } + } + } + + /** + * 生成当前日期 + * + * @author liuyang + */ + private String getNewDateStr() { + LocalDateTime now = LocalDateTime.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + return now.format(formatter); + } + + /** + * 批量修改成功、或者失败,适合档案查询的部分 + * + * @param errorHeaderDetailsDtoDtoV3List 错误日志 + * @param sceneType 场景类型 + * @author liuyang + */ + private void updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry(List errorHeaderDetailsDtoDtoV3List, String sceneType) { + Assert.notNull(errorHeaderDetailsDtoDtoV3List, "errorHeaderDetailsDtoDtoV3List不能为空!"); + Assert.notNull(sceneType, "sceneType不能为空!"); + + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + try { + if (errorHeaderDetailsDtoDtoV3List != null && errorHeaderDetailsDtoDtoV3List.size() > 0) { + List tocofsSaleoutDetailedEntityList = new ArrayList<>(); + for (int i = 0; i < errorHeaderDetailsDtoDtoV3List.size(); i++) { + ErrorHeaderDetailsDtoDtoV3 errorHeaderDetailsDtoDtoV3 = errorHeaderDetailsDtoDtoV3List.get(i); + PassiveStorageResponse.Header header = errorHeaderDetailsDtoDtoV3.getHeader(); + List details = errorHeaderDetailsDtoDtoV3.getDetails(); + + String newstate = errorHeaderDetailsDtoDtoV3.getNewstate(); + String newPushDate = errorHeaderDetailsDtoDtoV3.getNewPushDate(); + String newTransmitInfo = errorHeaderDetailsDtoDtoV3.getNewTransmitInfo(); + String newsystemnumber = errorHeaderDetailsDtoDtoV3.getNewsystemnumber(); + String newsystemprimary = errorHeaderDetailsDtoDtoV3.getNewsystemprimary(); +// String transactionDate = errorHeaderDetailsDtoDtoV3.getTransactionDate(); + + //如果报错内容太长了,则仅保留400个长度,维护数据库性能,缓解资源公平使用 + if (newTransmitInfo != null && !"".equals(newTransmitInfo.trim()) && newTransmitInfo.length() >= 400) { + newTransmitInfo = newTransmitInfo.substring(0, 400); + } + + for (int j = 0; j < details.size(); j++) { + PassiveStorageResponse.Details details1 = details.get(j); + + OfsPassiveorderDetailEntity ofsPassiveorderDetailEntity = new OfsPassiveorderDetailEntity(); + ofsPassiveorderDetailEntity.setId(details1.getId()); + ofsPassiveorderDetailEntity.setTransactionDate(details1.getRefundedAt()); + if (sceneType.equals("stock")) { + ofsPassiveorderDetailEntity.setNewpushdate(newPushDate); + ofsPassiveorderDetailEntity.setNewtransmitinfo(newTransmitInfo); + ofsPassiveorderDetailEntity.setNewstate(newstate); + if (!"N".equals(newstate)) { + ofsPassiveorderDetailEntity.setNewsystemnumber(newsystemnumber); + ofsPassiveorderDetailEntity.setNewsystemprimary(newsystemprimary); + } + } else if (sceneType.equals("tran")) { + ofsPassiveorderDetailEntity.setNewpushdate2(newPushDate); + ofsPassiveorderDetailEntity.setNewtransmitinfo2(newTransmitInfo); + ofsPassiveorderDetailEntity.setNewstate2(newstate); + if (!"N".equals(newstate)) { + ofsPassiveorderDetailEntity.setNewsystemnumber2(newsystemnumber); + ofsPassiveorderDetailEntity.setNewsystemprimary2(newTransmitInfo); + } + } + tocofsSaleoutDetailedEntityList.add(ofsPassiveorderDetailEntity); + } + } + + //以50行为一个批次更新状态,并且入库和确认收入调用不同的方法 + if (tocofsSaleoutDetailedEntityList.size() > 0) { + List> lists = SplitListByCountUtil.splitListByCount(tocofsSaleoutDetailedEntityList, 50); + for (int i = 0; i < lists.size(); i++) { + List ofsPassiveorderDetailEntities = lists.get(i); + if (sceneType.equals("stock")) { + iOfsPassiveorderDetailDao.entityInsertOrUpdateBatchByStock(ofsPassiveorderDetailEntities); + } else if (sceneType.equals("tran")) { + iOfsPassiveorderDetailDao.entityInsertOrUpdateBatchByTran(ofsPassiveorderDetailEntities); + } + } + } + } + } catch (Exception e) { + logger.error("无源件业务填充出库明细日志抛出异常", e); + } + } + }); + thread.start(); + try { + thread.join(); + } catch (Exception e) { + logger.error("updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry方法调用join 跑出异常", 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 ofsPassiveorderDetailEntityArrayList = new ArrayList<>(); + + for (int i = 0; i < sonDetailsDtoList.size(); i++) { + PassiveStorageSonDetailsDto passiveStorageSonDetailsDto = sonDetailsDtoList.get(i); + + OfsPassiveorderDetailEntity ofsPassiveorderDetailEntity = new OfsPassiveorderDetailEntity(); + ofsPassiveorderDetailEntity.setId(passiveStorageSonDetailsDto.getId()); + ofsPassiveorderDetailEntity.setTransactionDate(passiveStorageSonDetailsDto.getRefundedAt()); + ofsPassiveorderDetailEntity.setNewpushdate(getNewDateStr()); + ofsPassiveorderDetailEntity.setNewtransmitinfo(finalNewTransmitInfo); + ofsPassiveorderDetailEntity.setNewstate(newstate); + if (successY.equals(newstate)) { + ofsPassiveorderDetailEntity.setNewsystemnumber(newsystemnumber); + ofsPassiveorderDetailEntity.setNewsystemprimary(newsystemprimary); + } + + ofsPassiveorderDetailEntity.setDef1(passiveStorageSonDetailsDto.getCalculateAccountsReceivable()); + ofsPassiveorderDetailEntity.setDef2(passiveStorageSonDetailsDto.getCalculationFormula()); + ofsPassiveorderDetailEntity.setDef3(passiveStorageSonDetailsDto.getPlatformDiscounts()); + ofsPassiveorderDetailEntity.setDef4(passiveStorageSonDetailsDto.getPayDiscounts()); + ofsPassiveorderDetailEntity.setDef5(passiveStorageSonDetailsDto.getExpertDiscounts()); + ofsPassiveorderDetailEntity.setDef6(passiveStorageSonDetailsDto.getMerchantDiscounts()); + + ofsPassiveorderDetailEntityArrayList.add(ofsPassiveorderDetailEntity); + } + + //以50行为一个批次,推送到Mysql + if (ofsPassiveorderDetailEntityArrayList.size() > 0) { + List> lists = SplitListByCountUtil.splitListByCount(ofsPassiveorderDetailEntityArrayList, 50); + for (int i = 0; i < lists.size(); i++) { + List ofsPassiveorderDetailEntities = lists.get(i); + iOfsPassiveorderDetailDao.entityInsertOrUpdateBatchByStock(ofsPassiveorderDetailEntities); + } + } + } + } catch (Exception e) { + logger.error("无源件日志同步,抛出异常", e); + } + } + }); + thread.start(); + try { + thread.join(); + } catch (Exception e) { + logger.error("updateSuccessOrFail1方法现场抛出异常", e); + } + } + + /** + * 处理TOC-库存同步的成功、失败错误逻辑 + * + * @author liuyang + */ + private void updateSuccessOrFail2(List value, 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 (value != null && value.size() > 0) { + List ofsPassiveorderDetailEntityArrayList = new ArrayList<>(); + for (int i = 0; i < value.size(); i++) { + PassiveStorageSonDetailsDto passiveStorageSonDetailsDto = value.get(i); + + OfsPassiveorderDetailEntity ofsPassiveorderDetailEntity = new OfsPassiveorderDetailEntity(); + ofsPassiveorderDetailEntity.setId(passiveStorageSonDetailsDto.getId()); + ofsPassiveorderDetailEntity.setTransactionDate(passiveStorageSonDetailsDto.getRefundedAt()); + ofsPassiveorderDetailEntity.setNewpushdate2(getNewDateStr()); + ofsPassiveorderDetailEntity.setNewtransmitinfo2(finalNewTransmitInfo); + ofsPassiveorderDetailEntity.setNewstate2(newstate); + if (successY.equals(newstate)) { + ofsPassiveorderDetailEntity.setNewsystemnumber2(newsystemnumber); + ofsPassiveorderDetailEntity.setNewsystemprimary2(newsystemprimary); + } + ofsPassiveorderDetailEntity.setDef1(passiveStorageSonDetailsDto.getCalculateAccountsReceivable()); + ofsPassiveorderDetailEntity.setDef2(passiveStorageSonDetailsDto.getCalculationFormula()); + ofsPassiveorderDetailEntity.setDef3(passiveStorageSonDetailsDto.getPlatformDiscounts()); + ofsPassiveorderDetailEntity.setDef4(passiveStorageSonDetailsDto.getPayDiscounts()); + ofsPassiveorderDetailEntity.setDef5(passiveStorageSonDetailsDto.getExpertDiscounts()); + ofsPassiveorderDetailEntity.setDef6(passiveStorageSonDetailsDto.getMerchantDiscounts()); + ofsPassiveorderDetailEntityArrayList.add(ofsPassiveorderDetailEntity); + } + + //以50行为一个批次,推送到Mysql + if (ofsPassiveorderDetailEntityArrayList.size() > 0) { + List> lists = SplitListByCountUtil.splitListByCount(ofsPassiveorderDetailEntityArrayList, 50); + for (int i = 0; i < lists.size(); i++) { + List ofsPassiveorderDetailEntities = lists.get(i); + iOfsPassiveorderDetailDao.entityInsertOrUpdateBatchByTran(ofsPassiveorderDetailEntities); + } + } + } + } catch (Exception e) { + logger.error("TOC确认收入同步日志,抛出异常", e); + } + } + }); + thread.start(); + try { + thread.join(); + } catch (Exception e) { + logger.error("updateSuccessOrFail1方法现场抛出异常", e); + } + } + + /** + * 过滤库存同步业务,筛选出未推送、或者失败的数据行,使用批处理并且直接在内存中计算这样比较高效 + * + * @param tocofsReturngoodsDetailedEntityList 无源入库单推送状态信息 + * @param returnGoodHeaderDetailsDataDtoArrayList O 无源入库单对象封装 + * @author liuyang + */ + private List filterDataRowsAsPushOrFailedStock(List tocofsReturngoodsDetailedEntityList, List returnGoodHeaderDetailsDataDtoArrayList) throws Exception { + List targetHeaderDetailsDtoList = new ArrayList<>(); + + if (returnGoodHeaderDetailsDataDtoArrayList != null && returnGoodHeaderDetailsDataDtoArrayList.size() > 0) { + //如果推送状态为 null,则赋予"",便于 stream 计算 + List resultList = tocofsReturngoodsDetailedEntityList.stream().map(obj -> { + if (obj.getNewstate() == null) { + obj.setNewstate(""); + } + return obj; + }).collect(Collectors.toList()); + //汇总每个 id 对应的推送状态 + Map no2NameMap = resultList.stream().collect(Collectors.toMap(OfsPassiveorderDetailEntity::getId, OfsPassiveorderDetailEntity::getNewstate)); + + //字段Y(成功)或者为H(待处理)可以视为成功,完成了小段业务闭环的数据行 + String succeseeY = "Y"; + String succeseeH = "H"; + for (int i = 0; i < returnGoodHeaderDetailsDataDtoArrayList.size(); i++) { + PassiveStorageResponse.Data data = returnGoodHeaderDetailsDataDtoArrayList.get(i); + PassiveStorageResponse.Header header = data.getHeader(); + List details = data.getDetails(); + + List targetDetails = new ArrayList<>(); + for (int j = 0; j < details.size(); j++) { + PassiveStorageResponse.Details details1 = details.get(j); + Boolean isSuccess = false; + + String newstate = no2NameMap.get(details1.getId()); + if (newstate != null && !"".equals(newstate) && (succeseeY.equals(newstate) || succeseeH.equals(newstate))) { + isSuccess = true; + } + if (!isSuccess) { + targetDetails.add(details1); + } + } + if (targetDetails.size() > 0) { + //如果明细行中,还存在未推送或者失败的数据,则需要更新明细行 + //相当于覆盖对应的对象 + data.setDetails(targetDetails); + targetHeaderDetailsDtoList.add(data); + } + } + } + return targetHeaderDetailsDtoList; + } + + /** + * 筛选出未推送、或者失败的数据行,过滤库存同步业务 + * + * @param ofsPassiveorderDetailEntityList 无源入库单日志行状态 + * @param passiveStorageResponseDataDtoArrayList O无源入库单对象 + * @author liuyang + */ + private List filterDataRowsAsPushOrFailedTran(List ofsPassiveorderDetailEntityList, List passiveStorageResponseDataDtoArrayList) throws Exception { + Assert.notNull(ofsPassiveorderDetailEntityList, "tocofsReturngoodsDetailedEntityList不能为空"); + Assert.notNull(passiveStorageResponseDataDtoArrayList, "returnGoodHeaderDetailsDataDtoArrayList不能为空"); + + List passiveStorageResponseData = new ArrayList<>(); + if (ofsPassiveorderDetailEntityList != null && passiveStorageResponseDataDtoArrayList != null && ofsPassiveorderDetailEntityList.size() > 0) { + List collect = ofsPassiveorderDetailEntityList.stream().map(obj -> { + if (obj.getNewstate2() == null) { + obj.setNewstate2(""); + } + return obj; + }).collect(Collectors.toList()); + Map no2NameMap2 = collect.stream().collect(Collectors.toMap(OfsPassiveorderDetailEntity::getId, OfsPassiveorderDetailEntity::getNewstate2)); + + //字段Y(成功)或者为H(待处理)可以视为成功,完成了小段业务闭环的数据行 + String succeseeY = "Y"; + String succeseeH = "H"; + for (int i = 0; i < passiveStorageResponseDataDtoArrayList.size(); i++) { + PassiveStorageResponse.Data data = passiveStorageResponseDataDtoArrayList.get(i); + PassiveStorageResponse.Header header = data.getHeader(); + List details = data.getDetails(); + + List targetDetails = new ArrayList<>(); + for (int j = 0; j < details.size(); j++) { + PassiveStorageResponse.Details details1 = 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; // } // } // } -// } catch (Exception e) { -// logger.error("无源件业务填充出库明细日志抛出异常", e); -// } + newstate = no2NameMap2.get(details1.getId()); + if (newstate != null && !"".equals(newstate) && (succeseeY.equals(newstate) || succeseeH.equals(newstate))) { + isSuccess = true; + } + if (!isSuccess) { + targetDetails.add(details1); + } + } + if (targetDetails.size() > 0) { + //如果明细行中,还存在未推送或者失败的数据,则需要更新明细行 + data.setDetails(targetDetails); + passiveStorageResponseData.add(data); + } + } + } + return passiveStorageResponseData; + } + + /** + * 计算时间间隔 + * + * @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]); + } else if (sceneType.equals(TRAN)) { + startImplementByTradeTime(split[0], split[1]); + } + } + } + } else { + String[] split = param.split(","); + logger.info("splitDateAndPush方法正在执行主要的逻辑 开始时间:{} 结束时间:{}", split[0], split[1]); + if (sceneType.equals(STOCK)) { + startImplementStockByTime(split[0], split[1]); + } else if (sceneType.equals(TRAN)) { + startImplementByTradeTime(split[0], split[1]); + } + } + } 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); // } -// }); -// thread.start(); -// try { -// thread.join(); -// } catch (Exception e) { -// logger.error("updateFailOrSuccessTocofsSaleoutDetailedArchiveInquiry方法调用join 跑出异常", e); +// 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); // } -// } -// -// /** -// * 处理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 ofsPassiveorderDetailEntityArrayList = new ArrayList<>(); -// -// for (int i = 0; i < sonDetailsDtoList.size(); i++) { -// PassiveStorageSonDetailsDto passiveStorageSonDetailsDto = sonDetailsDtoList.get(i); -// -// OfsPassiveorderDetailEntity ofsPassiveorderDetailEntity = new OfsPassiveorderDetailEntity(); -// ofsPassiveorderDetailEntity.setId(passiveStorageSonDetailsDto.getId()); -// ofsPassiveorderDetailEntity.setNewpushdate(getNewDateStr()); -// ofsPassiveorderDetailEntity.setNewtransmitinfo(finalNewTransmitInfo); -// ofsPassiveorderDetailEntity.setNewstate(newstate); -// if (successY.equals(newstate)) { -// ofsPassiveorderDetailEntity.setNewsystemnumber(newsystemnumber); -// ofsPassiveorderDetailEntity.setNewsystemprimary(newsystemprimary); -// } -// -// ofsPassiveorderDetailEntity.setDef1(passiveStorageSonDetailsDto.getCalculateAccountsReceivable()); -// ofsPassiveorderDetailEntity.setDef2(passiveStorageSonDetailsDto.getCalculationFormula()); -// ofsPassiveorderDetailEntity.setDef3(passiveStorageSonDetailsDto.getPlatformDiscounts()); -// ofsPassiveorderDetailEntity.setDef4(passiveStorageSonDetailsDto.getPayDiscounts()); -// ofsPassiveorderDetailEntity.setDef5(passiveStorageSonDetailsDto.getExpertDiscounts()); -// ofsPassiveorderDetailEntity.setDef6(passiveStorageSonDetailsDto.getMerchantDiscounts()); -// -// ofsPassiveorderDetailEntityArrayList.add(ofsPassiveorderDetailEntity); -// } -// -// //以50行为一个批次,推送到Mysql -// if (ofsPassiveorderDetailEntityArrayList.size() > 0) { -// List> lists = SplitListByCountUtil.splitListByCount(ofsPassiveorderDetailEntityArrayList, 50); -// for (int i = 0; i < lists.size(); i++) { -// List ofsPassiveorderDetailEntities = lists.get(i); -// iOfsPassiveorderDetailDao.entityInsertOrUpdateBatchByStock(ofsPassiveorderDetailEntities); -// } -// } -// } -// } catch (Exception e) { -// logger.error("无源件日志同步,抛出异常", 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 O 无源入库单对象封装 -// * @author liuyang -// */ -// private List filterDataRowsAsPushOrFailedStock(List tocofsReturngoodsDetailedEntityList, List returnGoodHeaderDetailsDataDtoArrayList) throws Exception { -// List targetHeaderDetailsDtoList = new ArrayList<>(); -// -// if (returnGoodHeaderDetailsDataDtoArrayList != null && returnGoodHeaderDetailsDataDtoArrayList.size() > 0) { -// //如果推送状态为 null,则赋予"",便于 stream 计算 -// List resultList = tocofsReturngoodsDetailedEntityList.stream().map(obj -> { -// if (obj.getNewstate() == null) { -// obj.setNewstate(""); -// } -// return obj; -// }).collect(Collectors.toList()); -// //汇总每个 id 对应的推送状态 -// Map no2NameMap = resultList.stream().collect(Collectors.toMap(OfsPassiveorderDetailEntity::getId, OfsPassiveorderDetailEntity::getNewstate)); -// -// //字段Y(成功)或者为H(待处理)可以视为成功,完成了小段业务闭环的数据行 -// String succeseeY = "Y"; -// String succeseeH = "H"; -// for (int i = 0; i < returnGoodHeaderDetailsDataDtoArrayList.size(); i++) { -// PassiveStorageResponse.Data data = returnGoodHeaderDetailsDataDtoArrayList.get(i); -// PassiveStorageResponse.Header header = data.getHeader(); -// List details = data.getDetails(); -// -// List targetDetails = new ArrayList<>(); -// for (int j = 0; j < details.size(); j++) { -// PassiveStorageResponse.Details details1 = details.get(j); -// Boolean isSuccess = false; -// -// String newstate = no2NameMap.get(details1.getId()); -// if (newstate != null && !"".equals(newstate) && (succeseeY.equals(newstate) || succeseeH.equals(newstate))) { -// isSuccess = true; -// } -// if (!isSuccess) { -// targetDetails.add(details1); -// } -// } -// if (targetDetails.size() > 0) { -// //如果明细行中,还存在未推送或者失败的数据,则需要更新明细行 -// //相当于覆盖对应的对象 -// data.setDetails(targetDetails); -// targetHeaderDetailsDtoList.add(data); -// } -// } -// } -// 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 -// */ + 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不能为空"); // @@ -2714,36 +2668,36 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity { // logger.info("accumulationDiscountAmount方法对应的sonDetailsDtoList.size为零!"); // } // } -// -// /** -// * 根据OFS售后入库单明细行,查找匹配OFS售后订单明细行 -// * -// * @param details OFS售后订单明细行 -// * @param goodsRertunSonDetailsDto OFS售后入库单明细对象 -// * @author liuyang -// */ -// private RerturnGoodsOrderSearchDetails findOfsOrderDetail(List details, PassiveStorageSonDetailsDto goodsRertunSonDetailsDto) { -// Assert.notNull(details, "details不能为空"); -// Assert.notNull(goodsRertunSonDetailsDto, "goodsRertunSonDetailsDto不能为空"); -// -// for (int i = 0; i < details.size(); i++) { -// RerturnGoodsOrderSearchDetails rerturnGoodsOrderSearchDetails = details.get(i); -// if (goodsRertunSonDetailsDto.getSkuCode() != null && rerturnGoodsOrderSearchDetails.getSkuCode() != null) { -// if (goodsRertunSonDetailsDto.getSkuCode().equals(rerturnGoodsOrderSearchDetails.getSkuCode())) { -// return rerturnGoodsOrderSearchDetails; -// } -// } -// } -//// Assert.state(false, "根据OFS售后入库单明细行,无法查找OFS售后订单明细行 来源明细行主键:{} 来源单据主键:{}", goodsRertunSonDetailsDto.getRefOrderDetailId(), goodsRertunSonDetailsDto.getRefOrderId()); -// Assert.state(false, "无源入库单明细行存货 sku:{} 名称:{} 无法匹配售后订单明细行 sku", goodsRertunSonDetailsDto.getSkuCode(), goodsRertunSonDetailsDto.getSkuName()); -// return null; -// } -// -// /** -// * 初始化所有存货管理档案对应的结存价、采购价 -// * -// * @author liuyang -// */ + + /** + * 根据OFS售后入库单明细行,查找匹配OFS售后订单明细行 + * + * @param details OFS售后订单明细行 + * @param goodsRertunSonDetailsDto OFS售后入库单明细对象 + * @author liuyang + */ + private RerturnGoodsOrderSearchDetails findOfsOrderDetail(List details, PassiveStorageSonDetailsDto goodsRertunSonDetailsDto) { + Assert.notNull(details, "details不能为空"); + Assert.notNull(goodsRertunSonDetailsDto, "goodsRertunSonDetailsDto不能为空"); + + for (int i = 0; i < details.size(); i++) { + RerturnGoodsOrderSearchDetails rerturnGoodsOrderSearchDetails = details.get(i); + if (goodsRertunSonDetailsDto.getSkuCode() != null && rerturnGoodsOrderSearchDetails.getSkuCode() != null) { + if (goodsRertunSonDetailsDto.getSkuCode().equals(rerturnGoodsOrderSearchDetails.getSkuCode())) { + return rerturnGoodsOrderSearchDetails; + } + } + } +// Assert.state(false, "根据OFS售后入库单明细行,无法查找OFS售后订单明细行 来源明细行主键:{} 来源单据主键:{}", goodsRertunSonDetailsDto.getRefOrderDetailId(), goodsRertunSonDetailsDto.getRefOrderId()); + Assert.state(false, "无源入库单明细行存货 sku:{} 名称:{} 无法匹配售后订单明细行 sku", goodsRertunSonDetailsDto.getSkuCode(), goodsRertunSonDetailsDto.getSkuName()); + return null; + } + + /** + * 初始化所有存货管理档案对应的结存价、采购价 + * + * @author liuyang + */ // private List initAllBalancePricePurchasePrice() throws Exception { // List mapList = new ArrayList<>(); // Map stringIaPeriodaccountEntityMap = balanceUnitPriceUtil.initBalancePrice(); @@ -2752,17 +2706,17 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity { // mapList.add(stringPoOrderBEntityMap); // return mapList; // } -// -// /** -// * 获取结存金额或者采购金额 -// * -// * @param isCheckShopChoose true取OFS实付金额、false取结存金额或者采购价 -// * @param bdInvmandocEntity 存货基本档案 -// * @param header 对应的销售入库单表头 -// * @param sonDetailsDto 对应的销售入库单明细行对象 -// * @param mapList 索引为0结存价为1采购价 -// * @author liuyang -// */ + + /** + * 获取结存金额或者采购金额 + * + * @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不能为空"); @@ -2840,164 +2794,163 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity { // } // return totalPayAmount; // } -// -// /** -// * 累加应收金额=实退金额+达人优惠+支付优惠+平台优惠 -// * -// * @param passiveStorageSonDetailsDto O无源入库单 -// * @param rerturnGoodsOrderSearchData OFS售后订单 -// * @param calculationFormulaStr 计算公式 -// * @author liuyang -// */ -// private String accumulatedDiscounts(PassiveStorageSonDetailsDto passiveStorageSonDetailsDto, RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData, StringBuffer calculationFormulaStr) throws Exception { -// Assert.notNull(passiveStorageSonDetailsDto, "goodsRertunSonDetailsDto OFS售后入库单明细行不能为空!"); -// Assert.notNull(rerturnGoodsOrderSearchData, "rerturnGoodsOrderSearchData OFS售后订单不能为空!"); -// Assert.notNull(calculationFormulaStr, "calculationFormulaStr不能为空!"); -// -// //O 无源入库单表头 -// PassiveStorageResponse.Header header1 = passiveStorageSonDetailsDto.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 (passiveStorageSonDetailsDto.getSkuCode() != null && rerturnGoodsOrderSearchDetails.getSkuCode() != null) { -// if (passiveStorageSonDetailsDto.getSkuCode().equals(rerturnGoodsOrderSearchDetails.getSkuCode())) { -// targetDetails = rerturnGoodsOrderSearchDetails; -// } -// } -// } -// Assert.notNull(targetDetails, "根据OFS无源入库单单细行(sku匹配)无法匹配售后订单明细行", passiveStorageSonDetailsDto.getSkuCode()); -// -// //售后订单明细行-退货金额 -// 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()); -// -// String quantity = passiveStorageSonDetailsDto.getQuantity(); -// Assert.notNull(quantity, "无源入库单:{} sku:{} 实退数量不能为空", passiveStorageSonDetailsDto.getQuantity(), passiveStorageSonDetailsDto.getSkuName()); -// Assert.state(!"".equals(quantity), "无源入库单:{} sku:{} 实退数量不能为空", passiveStorageSonDetailsDto.getQuantity(), passiveStorageSonDetailsDto.getSkuName()); -// if ("0".equals(new BigDecimal(quantity).stripTrailingZeros().toPlainString())) { -// Assert.state(false, "无源入库单:{} sku:{} 实退数量不能为0!", passiveStorageSonDetailsDto.getQuantity(), passiveStorageSonDetailsDto.getSkuName()); -// } -// -// //O含税单价=通过退货金额/请求数量 -// BigDecimal unitPriceIncludingTax = new BigDecimal(totalAmount).divide(new BigDecimal(requestQty), 20, BigDecimal.ROUND_HALF_UP); -// //实退金额=O含税单价*(O售后入库单)实退数量 -// BigDecimal actualRefundAmount = unitPriceIncludingTax.multiply(new BigDecimal(quantity)).setScale(4, BigDecimal.ROUND_HALF_UP); -// String format = StrUtil.format("{}/{}*{}", totalAmount, requestQty, quantity); -// calculationFormulaStr.append(format); -// return actualRefundAmount.stripTrailingZeros().toPlainString(); -// } -// -// /** -// * 汇总好之后,相同的 sku,累加优惠金额,放在自定义项里最后传给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++) { -// PassiveStorageSonDetailsDto passiveStorageSonDetailsDto = sonDetailsDtoList.get(i); -// PassiveStorageResponse.Header header = passiveStorageSonDetailsDto.getHeader();//O无源入库单表头 -// RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = header.getRerturnGoodsOrderSearchData();//OFS售后订单 -// Assert.notNull(rerturnGoodsOrderSearchData, "O售后订单不能为空!"); -// 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 (passiveStorageSonDetailsDto.getSkuCode() != null && rerturnGoodsOrderSearchDetails.getSkuCode() != null) { -// if (passiveStorageSonDetailsDto.getSkuCode().equals(rerturnGoodsOrderSearchDetails.getSkuCode())) { -// //累加优惠 -// 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 passiveStorageSonDetailsDto O 无源入库单 -// * @param header O售后入库单表头 -// * @author liuyang -// */ -// private String getRefsaleprice(BdInvmandocEntity bdInvmandocEntity, BdInvbasdocEntity bdInvbasdocEntity, StringBuffer calculationFormulaStr, PassiveStorageSonDetailsDto passiveStorageSonDetailsDto) throws Exception { -// Assert.notNull(bdInvmandocEntity, "bdInvmandocEntity不能为空!"); -// Assert.notNull(bdInvbasdocEntity, "bdInvbasdocEntity不能为空!"); -// Assert.notNull(calculationFormulaStr, "calculationFormulaStr不能为空!"); -// Assert.notNull(passiveStorageSonDetailsDto, "passiveStorageSonDetailsDto不能为空!"); -//// Assert.notNull(header, "header不能为空"); -// -// //U参考售价 -// String refsaleprice = bdInvmandocEntity.getRefsaleprice(); -// Assert.notNull(refsaleprice, "存货:{} 公司:{} 不存在参考售价,请维护!", bdInvbasdocEntity.getInvname(), bdInvmandocEntity.getPkCorp()); -// -// //O无源入库单实收数量 -// String receivedQty = passiveStorageSonDetailsDto.getQuantity(); -// Assert.notNull(receivedQty, "O实收数量不能为空 O 无源入库单编码:{}", passiveStorageSonDetailsDto.getReceiptCode()); -// Assert.state(!"".equals(receivedQty), "O实收数量不能为空 O 无源入库单编码:{}", passiveStorageSonDetailsDto.getReceiptCode()); -// -// 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 -// */ + + /** + * 累加应收金额=实退金额+达人优惠+支付优惠+平台优惠 + * + * @param passiveStorageSonDetailsDto O无源入库单 + * @param rerturnGoodsOrderSearchData OFS售后订单 + * @param calculationFormulaStr 计算公式 + * @author liuyang + */ + private String accumulatedDiscounts(PassiveStorageSonDetailsDto passiveStorageSonDetailsDto, RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData, StringBuffer calculationFormulaStr) throws Exception { + Assert.notNull(passiveStorageSonDetailsDto, "goodsRertunSonDetailsDto OFS售后入库单明细行不能为空!"); + Assert.notNull(rerturnGoodsOrderSearchData, "rerturnGoodsOrderSearchData OFS售后订单不能为空!"); + Assert.notNull(calculationFormulaStr, "calculationFormulaStr不能为空!"); + + //O 无源入库单表头 + PassiveStorageResponse.Header header1 = passiveStorageSonDetailsDto.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 (passiveStorageSonDetailsDto.getSkuCode() != null && rerturnGoodsOrderSearchDetails.getSkuCode() != null) { + if (passiveStorageSonDetailsDto.getSkuCode().equals(rerturnGoodsOrderSearchDetails.getSkuCode())) { + targetDetails = rerturnGoodsOrderSearchDetails; + } + } + } + Assert.notNull(targetDetails, "根据OFS无源入库单单细行(sku匹配)无法匹配售后订单明细行", passiveStorageSonDetailsDto.getSkuCode()); + + //售后订单明细行-退货金额 + 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()); + + String quantity = passiveStorageSonDetailsDto.getQuantity(); + Assert.notNull(quantity, "无源入库单:{} sku:{} 实退数量不能为空", passiveStorageSonDetailsDto.getQuantity(), passiveStorageSonDetailsDto.getSkuName()); + Assert.state(!"".equals(quantity), "无源入库单:{} sku:{} 实退数量不能为空", passiveStorageSonDetailsDto.getQuantity(), passiveStorageSonDetailsDto.getSkuName()); + if ("0".equals(new BigDecimal(quantity).stripTrailingZeros().toPlainString())) { + Assert.state(false, "无源入库单:{} sku:{} 实退数量不能为0!", passiveStorageSonDetailsDto.getQuantity(), passiveStorageSonDetailsDto.getSkuName()); + } + + //O含税单价=通过退货金额/请求数量 + BigDecimal unitPriceIncludingTax = new BigDecimal(totalAmount).divide(new BigDecimal(requestQty), 20, BigDecimal.ROUND_HALF_UP); + //实退金额=O含税单价*(O售后入库单)实退数量 + BigDecimal actualRefundAmount = unitPriceIncludingTax.multiply(new BigDecimal(quantity)).setScale(4, BigDecimal.ROUND_HALF_UP); + String format = StrUtil.format("{}/{}*{}", totalAmount, requestQty, quantity); + calculationFormulaStr.append(format); + return actualRefundAmount.stripTrailingZeros().toPlainString(); + } + + /** + * 汇总好之后,相同的 sku,累加优惠金额,放在自定义项里最后传给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++) { + PassiveStorageSonDetailsDto passiveStorageSonDetailsDto = sonDetailsDtoList.get(i); + PassiveStorageResponse.Header header = passiveStorageSonDetailsDto.getHeader();//O无源入库单表头 + RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = header.getRerturnGoodsOrderSearchData();//OFS售后订单 + Assert.notNull(rerturnGoodsOrderSearchData, "O售后订单不能为空!"); + 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 (passiveStorageSonDetailsDto.getSkuCode() != null && rerturnGoodsOrderSearchDetails.getSkuCode() != null) { + if (passiveStorageSonDetailsDto.getSkuCode().equals(rerturnGoodsOrderSearchDetails.getSkuCode())) { + //累加优惠 + 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 passiveStorageSonDetailsDto O 无源入库单 + * @author liuyang + */ + private String getRefsaleprice(BdInvmandocEntity bdInvmandocEntity, BdInvbasdocEntity bdInvbasdocEntity, StringBuffer calculationFormulaStr, PassiveStorageSonDetailsDto passiveStorageSonDetailsDto) throws Exception { + Assert.notNull(bdInvmandocEntity, "bdInvmandocEntity不能为空!"); + Assert.notNull(bdInvbasdocEntity, "bdInvbasdocEntity不能为空!"); + Assert.notNull(calculationFormulaStr, "calculationFormulaStr不能为空!"); + Assert.notNull(passiveStorageSonDetailsDto, "passiveStorageSonDetailsDto不能为空!"); +// Assert.notNull(header, "header不能为空"); + + //U参考售价 + String refsaleprice = bdInvmandocEntity.getRefsaleprice(); + Assert.notNull(refsaleprice, "存货:{} 公司:{} 不存在参考售价,请维护!", bdInvbasdocEntity.getInvname(), bdInvmandocEntity.getPkCorp()); + + //O无源入库单实收数量 + String receivedQty = passiveStorageSonDetailsDto.getQuantity(); + Assert.notNull(receivedQty, "O实收数量不能为空 O 无源入库单编码:{}", passiveStorageSonDetailsDto.getReceiptCode()); + Assert.state(!"".equals(receivedQty), "O实收数量不能为空 O 无源入库单编码:{}", passiveStorageSonDetailsDto.getReceiptCode()); + + 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不能为空"); // @@ -3073,12 +3026,12 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity { // } // return returnGoodHeaderDetailsDataDtoArrayList; // } -// -// /** -// * 存在相同Maintableid汇总在一起 -// * -// * @author liuyang -// */ + + /** + * 存在相同Maintableid汇总在一起 + * + * @author liuyang + */ // public static Map> convertToMap(List tocofsReturngoodsDetailedEntityList) { // Map> map = new HashMap<>(); // for (TocofsReturngoodsDetailedEntity entity : tocofsReturngoodsDetailedEntityList) { @@ -3087,4 +3040,4 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity { // } // return map; // } -} +} \ No newline at end of file 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 ca560583..c7ab984c 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 @@ -3236,9 +3236,10 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { /** * 如果售后入库单对应的售后订单状态为售中节点,则过滤掉不传递 * + * @throws Exception 抛出可能的异常 * @author liuyang */ - public List filterForSale(List returnGoodHeaderDetailsDataDtoList1) { + public List filterForSale(List returnGoodHeaderDetailsDataDtoList1) throws Exception { List filteredList = null; if (returnGoodHeaderDetailsDataDtoList1 != null && returnGoodHeaderDetailsDataDtoList1.size() > 0) { filteredList = returnGoodHeaderDetailsDataDtoList1.stream().filter(stockinOrder -> { @@ -3247,9 +3248,12 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { // 如果 StockinH 为空,保留该对象 return true; } - // 获取 RerturnGoodsOrderSearchData 对象 RerturnGoodsOrderSearchData returnData = header.getRerturnGoodsOrderSearchData(); - if (returnData == null) { + if (returnData == null || returnData.getHeader() == null) { + // 如果 RerturnGoodsOrderSearchData 为空,保留该对象 + return true; + } + if (returnData.getHeader().getReturnNode() == null) { // 如果 RerturnGoodsOrderSearchData 为空,保留该对象 return true; } diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/u8cdto/ArapDjzbVO.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/u8cdto/ArapDjzbVO.java index 94490fc6..510f20f1 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/u8cdto/ArapDjzbVO.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/u8cdto/ArapDjzbVO.java @@ -79,6 +79,11 @@ public class ArapDjzbVO { private String zyx7;//自定义项7(档案类型的传pk) private String zyx8;//自定义项8(档案类型的传pk) private String zyx9;//自定义项9(档案类型的传pk) + + private String def1; + private String def2; + private String def3; + private String def16; } @Data diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/u8cdto/ErrorHeaderDetailsDtoDtoV3.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/u8cdto/ErrorHeaderDetailsDtoDtoV3.java index 8a15a59e..fb18309e 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/u8cdto/ErrorHeaderDetailsDtoDtoV3.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/u8cdto/ErrorHeaderDetailsDtoDtoV3.java @@ -40,4 +40,6 @@ public class ErrorHeaderDetailsDtoDtoV3 extends PassiveStorageResponse.Data { private String newsystemnumber; //下游主键 private String newsystemprimary; + //交易成功时间 +// private String transactionDate; } 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 bba7614c..06c31dda 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 @@ -9,7 +9,11 @@ import com.hzya.frame.plugin.lets.dao.IBdTaxitemsDao; import com.hzya.frame.plugin.lets.entity.BdInvbasdocEntity; import com.hzya.frame.plugin.lets.entity.BdInvmandocEntity; import com.hzya.frame.plugin.lets.entity.BdTaxitemsEntity; +import com.hzya.frame.plugin.lets.plugin.sales.PassiveWarehouseReceiptToC; +import com.hzya.frame.plugin.lets.u8cdto.ArapDjzbVO; import com.hzya.frame.plugin.lets.u8cdto.SaleorderRequestChildrenDto; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -30,6 +34,8 @@ import java.util.stream.Collectors; @Component public class QueryAdditionUtil { + Logger logger = LoggerFactory.getLogger(QueryAdditionUtil.class); + @Autowired private IBdInvbasdocDao iBdInvbasdocDao; @@ -110,7 +116,7 @@ public class QueryAdditionUtil { } /** - * 增加平台运费,优惠金额这些存货一起保存进U8C销售订单 + * 增加平台运费,优惠金额这些存货一起保存进U8C销售订单,TOC业务 * * @param bdInvmandocEntity1 存货管理档案 * @param bdInvbasdocEntity1 存货基本档案 @@ -149,7 +155,7 @@ public class QueryAdditionUtil { //税率 saleorderRequestChildrenDto1.setNtaxrate(new BigDecimal(bdTaxitemsEntity.getTaxratio()).stripTrailingZeros().toPlainString()); - + //优惠字段 saleorderRequestChildrenDto1.setVdef4("0"); saleorderRequestChildrenDto1.setVdef5("0"); @@ -166,4 +172,60 @@ public class QueryAdditionUtil { } } } + + /** + * 增加平台运费,优惠金额这些存货一起保存进U8C销售订单 + * + * @param bdInvmandocEntity1 存货管理档案 + * @param bdInvbasdocEntity1 存货基本档案 + * @param pushScenarioType 需要推送给U8C红字应收单明细行表体 + * @param noriginalcursummny 价税合计(只能传金额) + * @param bdTaxitemsEntity 存货对应的税率 + * @author liuyang + */ + public void additionalV2(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(bdInvmandocEntity1.getPkInvmandoc()); + + 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/service/src/main/java/com/hzya/frame/ttxofs/dto/passivestorage/PassiveStorageResponse.java b/service/src/main/java/com/hzya/frame/ttxofs/dto/passivestorage/PassiveStorageResponse.java index dc162c93..a47118a2 100644 --- a/service/src/main/java/com/hzya/frame/ttxofs/dto/passivestorage/PassiveStorageResponse.java +++ b/service/src/main/java/com/hzya/frame/ttxofs/dto/passivestorage/PassiveStorageResponse.java @@ -68,6 +68,9 @@ public class PassiveStorageResponse extends ReturnMessageBasics { private String createdBy; private String lastUpdated; private String lastUpdatedBy; + //无源件表头 private PassiveStorageResponse.Header header; + //退款完成时间 + private String refundedAt; } }