From a80fea45ed728440d64a4753511f8afb641b4af9 Mon Sep 17 00:00:00 2001 From: liuy <37787198+LiuyCodes@users.noreply.github.com> Date: Tue, 13 Aug 2024 18:21:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4TOB=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/lets/constant/ExportConstant.java | 22 + .../TocofsReturngoodsDetailedEntity.java | 27 +- .../TocofsReturngoodsDetailedEntity.xml | 43 +- .../entity/TocofsSaleoutDetailedEntity.java | 29 + .../entity/TocofsSaleoutDetailedEntity.xml | 31 +- .../sales/SoSaleOutPluginInitializerToB.java | 937 ++++++++++++++++++ .../sales/SoSaleOutPluginInitializerToC.java | 7 +- .../SoSaleReturnPluginInitializerToC.java | 4 +- .../lets/u8cdto/OrderOutTobHeaderDto.java | 74 ++ .../lets/spring/spring-sowow-plugin.xml | 5 +- .../SoSaleOutPluginInitializerToBTest.java | 31 + .../ttxofs/service/OfsUnifiedService.java | 2 +- 12 files changed, 1174 insertions(+), 38 deletions(-) create mode 100644 buildpackage/src/main/java/com/hzya/frame/plugin/lets/constant/ExportConstant.java create mode 100644 buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToB.java create mode 100644 buildpackage/src/main/java/com/hzya/frame/plugin/lets/u8cdto/OrderOutTobHeaderDto.java create mode 100644 buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToBTest.java diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/constant/ExportConstant.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/constant/ExportConstant.java new file mode 100644 index 00000000..1d74e1bc --- /dev/null +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/constant/ExportConstant.java @@ -0,0 +1,22 @@ +package com.hzya.frame.plugin.lets.constant; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Author:liuyang + * @Package:com.hzya.frame.plugin.lets.constant + * @Project:kangarooDataCenterV3 + * @name:ExportConstant + * @Date:2024/8/13 18:00 + * @Filename:ExportConstant + */ +public class ExportConstant { + + public static final Map exportConstant = new HashMap<>(); + + static { + exportConstant.put("xuni-intoyou-japan", "xuni-intoyou-japan"); + exportConstant.put("B2BFX20240001", "B2BFX20240001"); + } +} \ No newline at end of file diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsReturngoodsDetailedEntity.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsReturngoodsDetailedEntity.java index 04e4b418..90097f2c 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsReturngoodsDetailedEntity.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsReturngoodsDetailedEntity.java @@ -149,10 +149,21 @@ public class TocofsReturngoodsDetailedEntity extends BaseEntity { * 业务日期 */ private String businessDate; + /** * 主表主键 */ - private String returngoodsId; +// private String returngoodsId; + + private String businessType; + + public String getBusinessType() { + return businessType; + } + + public void setBusinessType(String businessType) { + this.businessType = businessType; + } public String getReceiptId() { return receiptId; @@ -434,12 +445,12 @@ public class TocofsReturngoodsDetailedEntity extends BaseEntity { this.businessDate = businessDate; } - public String getReturngoodsId() { - return returngoodsId; - } - - public void setReturngoodsId(String returngoodsId) { - this.returngoodsId = returngoodsId; - } +// public String getReturngoodsId() { +// return returngoodsId; +// } +// +// public void setReturngoodsId(String returngoodsId) { +// this.returngoodsId = returngoodsId; +// } } \ No newline at end of file diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsReturngoodsDetailedEntity.xml b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsReturngoodsDetailedEntity.xml index d9390e4a..dfd0b4cd 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsReturngoodsDetailedEntity.xml +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsReturngoodsDetailedEntity.xml @@ -39,8 +39,9 @@ - + + id @@ -78,9 +79,10 @@ ,new_system_number ,new_system_primary ,primary_key - ,business_date - ,returngoods_id + ,business_date + ,business_type + select @@ -120,6 +126,8 @@ and newSystemNumber = #{newSystemNumber} and newSystemPrimary = #{newSystemPrimary} and primaryKey = #{primaryKey} + and businessType = #{businessType} + and businessDate = #{businessDate} @@ -165,6 +173,8 @@ and newSystemNumber = #{newSystemNumber} and newSystemPrimary = #{newSystemPrimary} and primaryKey = #{primaryKey} + and businessType = #{businessType} + and businessDate = #{businessDate} @@ -212,6 +222,8 @@ and newSystemNumber like concat('%',#{newSystemNumber},'%') and newSystemPrimary like concat('%',#{newSystemPrimary},'%') and primaryKey like concat('%',#{primaryKey},'%') + and businessType like concat('%',#{businessType},'%') + and businessDate like concat('%',#{businessDate},'%') @@ -259,6 +271,8 @@ or newSystemNumber = #{newSystemNumber} or newSystemPrimary = #{newSystemPrimary} or primaryKey = #{primaryKey} + or businessType = #{businessType} + or businessDate = #{businessDate} @@ -348,19 +362,19 @@ - insert IGNORE into tocofs_saleout_detailed(clientCode, companyCode, facilityCode, shipmentCode, refOrderId, refOrderDetailId, refOrderCode, allocInvId, skuCode, skuName, sourceOrderCode, inventorySts, isGift, requestQty, shipQty, quantityUM, listPrice, itemTotalAmount, totalPayAmount, totalWeight, totalVolume, totalVolumeWeight, weightUM, volumeUM, created, createdBy, lastUpdated, lastUpdatedBy,newTransmitInfo,newPushDate,newState,newSystemNumber,newSystemPrimary,primaryKey) + insert IGNORE into tocofs_saleout_detailed(clientCode, companyCode, facilityCode, shipmentCode, refOrderId, refOrderDetailId, refOrderCode, allocInvId, skuCode, skuName, sourceOrderCode, inventorySts, isGift, requestQty, shipQty, quantityUM, listPrice, itemTotalAmount, totalPayAmount, totalWeight, totalVolume, totalVolumeWeight, weightUM, volumeUM, created, createdBy, lastUpdated, lastUpdatedBy,newTransmitInfo,newPushDate,newState,newSystemNumber,newSystemPrimary,primaryKey,businessType,businessDate) values - (#{entity.clientcode},#{entity.companycode},#{entity.facilitycode},#{entity.shipmentcode},#{entity.reforderid},#{entity.reforderdetailid},#{entity.refordercode},#{entity.allocinvid},#{entity.skucode},#{entity.skuname},#{entity.sourceordercode},#{entity.inventorysts},#{entity.isgift},#{entity.requestqty},#{entity.shipqty},#{entity.quantityum},#{entity.listprice},#{entity.itemtotalamount},#{entity.totalpayamount},#{entity.totalweight},#{entity.totalvolume},#{entity.totalvolumeweight},#{entity.weightum},#{entity.volumeum},#{entity.created},#{entity.createdby},#{entity.lastupdated},#{entity.lastupdatedby},#{entity.newTransmitInfo},#{entity.newPushDate},#{entity.newState},#{entity.newSystemNumber},#{entity.newSystemPrimary},#{entity.primaryKey}) + (#{entity.clientcode},#{entity.companycode},#{entity.facilitycode},#{entity.shipmentcode},#{entity.reforderid},#{entity.reforderdetailid},#{entity.refordercode},#{entity.allocinvid},#{entity.skucode},#{entity.skuname},#{entity.sourceordercode},#{entity.inventorysts},#{entity.isgift},#{entity.requestqty},#{entity.shipqty},#{entity.quantityum},#{entity.listprice},#{entity.itemtotalamount},#{entity.totalpayamount},#{entity.totalweight},#{entity.totalvolume},#{entity.totalvolumeweight},#{entity.weightum},#{entity.volumeum},#{entity.created},#{entity.createdby},#{entity.lastupdated},#{entity.lastupdatedby},#{entity.newTransmitInfo},#{entity.newPushDate},#{entity.newState},#{entity.newSystemNumber},#{entity.newSystemPrimary},#{entity.primaryKey},#{entity.businessType},#{entity.businessDate}) - insert into tocofs_saleout_detailed(clientCode, companyCode, facilityCode, shipmentCode, refOrderId, refOrderDetailId, refOrderCode, allocInvId, skuCode, skuName, sourceOrderCode, inventorySts, isGift, requestQty, shipQty, quantityUM, listPrice, itemTotalAmount, totalPayAmount, totalWeight, totalVolume, totalVolumeWeight, weightUM, volumeUM, created, createdBy, lastUpdated, lastUpdatedBy,newTransmitInfo,newPushDate,newState,newSystemNumber,newSystemPrimary,primaryKey) + insert into tocofs_saleout_detailed(clientCode, companyCode, facilityCode, shipmentCode, refOrderId, refOrderDetailId, refOrderCode, allocInvId, skuCode, skuName, sourceOrderCode, inventorySts, isGift, requestQty, shipQty, quantityUM, listPrice, itemTotalAmount, totalPayAmount, totalWeight, totalVolume, totalVolumeWeight, weightUM, volumeUM, created, createdBy, lastUpdated, lastUpdatedBy,newTransmitInfo,newPushDate,newState,newSystemNumber,newSystemPrimary,primaryKey,businessType,businessDate) values - (#{entity.clientcode},#{entity.companycode},#{entity.facilitycode},#{entity.shipmentcode},#{entity.reforderid},#{entity.reforderdetailid},#{entity.refordercode},#{entity.allocinvid},#{entity.skucode},#{entity.skuname},#{entity.sourceordercode},#{entity.inventorysts},#{entity.isgift},#{entity.requestqty},#{entity.shipqty},#{entity.quantityum},#{entity.listprice},#{entity.itemtotalamount},#{entity.totalpayamount},#{entity.totalweight},#{entity.totalvolume},#{entity.totalvolumeweight},#{entity.weightum},#{entity.volumeum},#{entity.created},#{entity.createdby},#{entity.lastupdatedby},#{entity.lastupdated},#{entity.newTransmitInfo},#{entity.newPushDate},#{entity.newState},#{entity.newSystemNumber},#{entity.newSystemPrimary},#{entity.primaryKey}) + (#{entity.clientcode},#{entity.companycode},#{entity.facilitycode},#{entity.shipmentcode},#{entity.reforderid},#{entity.reforderdetailid},#{entity.refordercode},#{entity.allocinvid},#{entity.skucode},#{entity.skuname},#{entity.sourceordercode},#{entity.inventorysts},#{entity.isgift},#{entity.requestqty},#{entity.shipqty},#{entity.quantityum},#{entity.listprice},#{entity.itemtotalamount},#{entity.totalpayamount},#{entity.totalweight},#{entity.totalvolume},#{entity.totalvolumeweight},#{entity.weightum},#{entity.volumeum},#{entity.created},#{entity.createdby},#{entity.lastupdatedby},#{entity.lastupdated},#{entity.newTransmitInfo},#{entity.newPushDate},#{entity.newState},#{entity.newSystemNumber},#{entity.newSystemPrimary},#{entity.primaryKey},#{entity.businessType},#{entity.businessDate}) on duplicate key update clientCode = values(clientCode), @@ -396,8 +410,11 @@ newState = values(newState), newSystemNumber = values(newSystemNumber), newSystemPrimary = values(newSystemPrimary), - primaryKey = values(primaryKey) + primaryKey = values(primaryKey), + businessType = values(businessType), + businessDate = values(businessDate) + update tocofs_saleout_detailed set @@ -436,6 +453,8 @@ update tocofs_saleout_detailed set newSystemNumber = #{newSystemNumber}, newSystemPrimary = #{newSystemPrimary}, primaryKey = #{primaryKey}, + businessType = #{businessType}, + businessDate = #{businessDate} where rootId = #{rootid} @@ -484,6 +503,8 @@ update tocofs_saleout_detailed set sts= 'N' ,modify_time = #{modify_time},modif and newSystemNumber = #{newSystemNumber} and newSystemPrimary = #{newSystemPrimary} and primaryKey = #{primaryKey} + and businessType = #{businessType} + and businessDate = #{businessDate} diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToB.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToB.java new file mode 100644 index 00000000..9e8537ba --- /dev/null +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToB.java @@ -0,0 +1,937 @@ +package com.hzya.frame.plugin.lets.plugin.sales; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpRequest; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hzya.frame.base.PluginBaseEntity; +import com.hzya.frame.beanutil.BeanUtil; +import com.hzya.frame.plugin.lets.constant.ExportConstant; +import com.hzya.frame.plugin.lets.constant.ProfilesActiveConstant; +import com.hzya.frame.plugin.lets.dao.*; +import com.hzya.frame.plugin.lets.entity.*; +import com.hzya.frame.plugin.lets.ofs.dao.ITocofsSaleoutDao; +import com.hzya.frame.plugin.lets.ofs.dao.ITocofsSaleoutDetailedDao; +import com.hzya.frame.plugin.lets.ofs.entity.TocofsSaleoutDetailedEntity; +import com.hzya.frame.plugin.lets.ofs.entity.TocofsSaleoutEntity; +import com.hzya.frame.plugin.lets.ofs.service.ITocofsSaleoutService; +import com.hzya.frame.plugin.lets.ofsvo.QueryOfsSoSaleOutVo; +import com.hzya.frame.plugin.lets.resultvo.CalculateDateVo; +import com.hzya.frame.plugin.lets.u8cdto.*; +import com.hzya.frame.plugin.lets.util.DateStrUtil; +import com.hzya.frame.plugin.lets.util.QueryBdBusitypeUtil; +import com.hzya.frame.plugin.lets.util.TocOrderBasicArchivesCacheUtil; +import com.hzya.frame.split.SplitListByCountUtil; +import com.hzya.frame.ttxofs.dto.InterfaceParamDto; +import com.hzya.frame.ttxofs.dto.ofssaleorderoutsearch.DetailsDto; +import com.hzya.frame.ttxofs.dto.ofssaleorderoutsearch.HeaderDetailsDto; +import com.hzya.frame.ttxofs.dto.ofssaleorderoutsearch.HeaderDto; +import com.hzya.frame.ttxofs.dto.ofssaleorderoutsearch.SaleOutReturnMessageDto; +import com.hzya.frame.ttxofs.service.OfsUnifiedService; +import com.hzya.frame.web.entity.JsonResultEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +import java.math.BigDecimal; +import java.util.*; +import java.util.concurrent.locks.ReentrantLock; +import java.util.stream.Collectors; + +/** + * OFS销售出库单(TOB)生成U8C销售订单 + * + * @author makejava + * @since 2024年8月12日 15:03:51 + */ +public class SoSaleOutPluginInitializerToB extends PluginBaseEntity { + + Logger logger = LoggerFactory.getLogger(SoSaleOutPluginInitializerToB.class); + + private static final ReentrantLock LOCK = new ReentrantLock(true); + + @Autowired + private IBdCorpDao iBdCorpDao; + + @Autowired + private IBdInvbasdocDao iBdInvbasdocDao; + + @Override + public void initialize() { + logger.info(getPluginLabel() + "執行初始化方法initialize()"); + } + + @Override + public void destroy() { + logger.info(getPluginLabel() + "執行銷毀方法destroy()"); + } + + @Override + public String getPluginId() { + return "com.hzya.frame.plugin.lets.plugin.sales.SoSaleOutPluginInitializerToB"; + } + + @Override + public String getPluginName() { + return "OFS销售出库单(TOB)生成U8C销售订单"; + } + + @Override + public String getPluginLabel() { + return "OFS销售出库单(TOB)生成U8C销售订单"; + } + + @Override + public String getPluginType() { + return "3"; + } + + @Override + public JsonResultEntity executeBusiness(JSONObject requestJson) throws Exception { + return null; + } + + @Autowired + private OfsUnifiedService ofsUnifiedService; + + @Autowired + private IBdTaxitemsDao iBdTaxitemsDao; + + @Autowired + private IBdCalbodyDao iBdCalbodyDao; + + @Autowired + private TocOrderBasicArchivesCacheUtil basicArchivesCacheUtil; + + @Autowired + private ITocofsSaleoutDao iTocofsSaleoutDao; + + @Autowired + private ITocofsSaleoutDetailedDao iTocofsSaleoutDetailedDao; + + @Autowired + private QueryBdBusitypeUtil queryBdBusitypeUtil; + + @Autowired + private IBdStordocDao iBdStordocDao; + + @Autowired + private IBdSalestruDao iBdSalestruDao; + + private static final String NOTHING = "无"; + + private static final String ADD = "+"; + + @Autowired + private IBdCumandocDao iBdCumandocDao; + + @Autowired + private IBdDeptdocDao iBdDeptdocDao; + + @Autowired + private IBdCubasdocDao iBdCubasdocDao; + + @Autowired + private IBdDefdocDao iBdDefdocDao; + + @Autowired + private IBdInvmandocDao iBdInvmandocDao; + + /** + * 按指定时间拉取 + * + * @author liuyang + */ + public void startImplement(String dateStr, String summaryOrderNumber) { + String threadNameStr = StrUtil.format("OFS销售出库(TOB)同步U8C销售订单 同步日期:{} 汇总维度:{}", dateStr, summaryOrderNumber); + logger.info(threadNameStr); + + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + LOCK.lock(); + try { + // TODO 注意过滤TOB店铺 + CalculateDateVo calculateDateVo = DateStrUtil.calculateCalculateEntireDayPeriod(dateStr); + + List headerDetailsDtoList = new ArrayList<>(); + QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo(); + queryOfsSoSaleOutVo.setCreated_start("2024-01-02 00:58:22"); + queryOfsSoSaleOutVo.setCreated_end("2024-01-02 11:58:23"); + queryOfsSoSaleOutVo.setClientCode("LETS"); + // queryOfsSoSaleOutVo.setInternalInstructionType("SALES"); + queryOfsSoSaleOutVo.setCompanyCode("SHLZ"); + // queryOfsSoSaleOutVo.setStatus(900L); + queryOfsSoSaleOutVo.setPageNo(1L); + queryOfsSoSaleOutVo.setPageSize(50L); + queryOfsSoSaleOutVo.setCode("LETS-SH2024010200000004"); + queryOfsSaleOrder(queryOfsSoSaleOutVo, headerDetailsDtoList, 1L); + logger.info("数据返回行数:{}", headerDetailsDtoList.size()); + if (headerDetailsDtoList.size() > 0) { + //保存到mysql + batchInsert(headerDetailsDtoList); + //过滤成功的数据 + List headerDetailsDtos = filterData(headerDetailsDtoList); + //执行推送主逻辑 + implement(headerDetailsDtos); + } else { + logger.info("没有查询到任何数据!不需要同步"); + } + } catch (Exception e) { + logger.error("startImplement方法抛出异常", e); + } finally { + LOCK.unlock(); + } + } + }, threadNameStr); + thread.start(); + try { + thread.join(); + } catch (Exception e) { + logger.error("thread.join()异常", e); + } + } + + /** + * 过滤掉成功的数据 + * + * @author liuyang + */ + private List filterData(List headerDetailsDtoList) { + List headerDetailsDtoList1 = new ArrayList<>(); + if (headerDetailsDtoList != null && headerDetailsDtoList.size() > 0) { + //TODO 出库单明细主键,需要O返回,目前没有,已经提需求 + headerDetailsDtoList1.addAll(headerDetailsDtoList); + } + return headerDetailsDtoList1; + } + + /** + * 保存抓取到的数据到mysql底表,如果底表里已经存在,则会忽略 + * + * @param headerDetailsDtoList 数据行 + */ + private void batchInsert(List headerDetailsDtoList) throws Exception { + if (headerDetailsDtoList != null && headerDetailsDtoList.size() > 0) { + List headerDetailsDtoList1 = new ArrayList<>(); + List headerDetailsDtoList2 = new ArrayList<>(); + + for (HeaderDetailsDto index : headerDetailsDtoList) { + HeaderDto header = index.getHeader();// 主表 + List details = index.getDetails();//明细表 + + headerDetailsDtoList1.add(header); + headerDetailsDtoList2.addAll(details); + } + + //每250作为一个批次插入主表,根据主键(id)判断是否重复,如果重复的,则不进行插入 + List> ofssaleorderoutsearchList = SplitListByCountUtil.splitListByCount(headerDetailsDtoList1, 250); + for (int i = 0; i < ofssaleorderoutsearchList.size(); i++) { + List headerDtoList = ofssaleorderoutsearchList.get(i); + List tocofsSaleoutEntityList = copyHeaderDto(headerDtoList); + if (tocofsSaleoutEntityList.size() > 0) { + logger.info("TOBofsSaleoutDetailedEntities:插入底表{}个对象(表头)", tocofsSaleoutEntityList.size()); + iTocofsSaleoutDao.entityInsertBatchV2(tocofsSaleoutEntityList); + } else { + logger.info("TOBofsSaleoutEntityList:没有对象被插入表头底表"); + } + } + + //插入明细表 + List> detailsDtoList = SplitListByCountUtil.splitListByCount(headerDetailsDtoList2, 250); + for (int i = 0; i < detailsDtoList.size(); i++) { + List detailsDtos = detailsDtoList.get(i); + List tocofsSaleoutDetailedEntities = copyDetailsDto(detailsDtos); + if (tocofsSaleoutDetailedEntities.size() > 0) { + logger.info("TOBofsSaleoutDetailedEntities:插入底表{}个对象(表体)", tocofsSaleoutDetailedEntities.size()); + iTocofsSaleoutDetailedDao.entityInsertBatchV2(tocofsSaleoutDetailedEntities); + } else { + logger.info("TOBofsSaleoutDetailedEntities:没有对象被插入表头底表"); + } + } + } + } + + /** + * 查询OFS结果集 + * + * @param queryOfsSoSaleOutVo 查询参数 + * @param headerDetailsDtoList 查询结果集 + * @param pageNo 从第pageNo页开始查询 + */ + private void queryOfsSaleOrder(QueryOfsSoSaleOutVo queryOfsSoSaleOutVo, List headerDetailsDtoList, Long pageNo) throws Exception { + + Long pageSize = 200L; + queryOfsSoSaleOutVo.setPageNo(pageNo); + queryOfsSoSaleOutVo.setPageSize(pageSize); + + InterfaceParamDto interfaceParamDto = new InterfaceParamDto(); + interfaceParamDto.setApi("ofs.shipment.search"); + interfaceParamDto.setData(JSON.toJSONString(queryOfsSoSaleOutVo)); + SaleOutReturnMessageDto saleOutReturnMessageDto = (SaleOutReturnMessageDto) ofsUnifiedService.unified(interfaceParamDto); + if (saleOutReturnMessageDto != null) { + if ("false".equals(saleOutReturnMessageDto.getError()) && "0".equals(saleOutReturnMessageDto.getCode()) && "Success".equals(saleOutReturnMessageDto.getMsg())) { + List headerDetailsDtoList1 = saleOutReturnMessageDto.getData(); + if (headerDetailsDtoList1 != null && headerDetailsDtoList1.size() > 0) { + headerDetailsDtoList.addAll(headerDetailsDtoList1); + + //TODO OFS没有提供分页字段 + } + } else { + //2024年7月30日 13:47:04 查询失败 + logger.error("查询失败,失败原因:{}", JSON.toJSON(saleOutReturnMessageDto)); + } + } else { + logger.error("returnMessageBasics为空!queryOfsSoSaleOutVo对象结果:{}", JSON.toJSON(queryOfsSoSaleOutVo)); + } + } + +// 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 headerDetailsDtos 查询得到的O出库单对象 + * @author liuyang + */ + private void implement(List headerDetailsDtos) throws Exception { + if (headerDetailsDtos != null && headerDetailsDtos.size() > 0) { + try { + // 查询基本档案 + List orderOutTobHeaderDtos = queryBasicArchives(headerDetailsDtos); + // 查询U8C业务流程 + BdBusitypeEntity bdBusitypeEntity = u8cOperationFlow(); + + try { + for (int i = 0; i < orderOutTobHeaderDtos.size(); i++) { + OrderOutTobHeaderDto orderOutTobHeaderDto = orderOutTobHeaderDtos.get(i); + HeaderDto header = orderOutTobHeaderDto.getHeader(); + List details = orderOutTobHeaderDto.getDetails(); + + //销售公司、发货公司 + BdCorpEntity bdCorpEntity = orderOutTobHeaderDto.getBdCorpEntity(); + //发货库存组织 + BdCalbodyEntity bdCalbodyEntity = orderOutTobHeaderDto.getBdCalbodyEntity(); + //入库参数 + BdStordocEntity bdStordocEntity = orderOutTobHeaderDto.getBdStordocEntity(); + //销售组织 + BdSalestruEntity bdSalestruEntity = orderOutTobHeaderDto.getBdSalestruEntity(); + //业务部门 + BdDeptdocEntity bdDeptdocEntity = orderOutTobHeaderDto.getBdDeptdocEntity(); + //客商基本档案 + BdCubasdocEntity bdCubasdocEntity = orderOutTobHeaderDto.getBdCubasdocEntity(); + //客商基本档案 + BdCumandocEntity bdCumandocEntity = orderOutTobHeaderDto.getBdCumandocEntity(); + //发货公司 + BdCorpEntity deliverGoodsCorp = orderOutTobHeaderDto.getDeliverGoodsCorp(); + //平台档案 + BdDefdocEntity platformArchives = orderOutTobHeaderDto.getPlatformArchives(); + //生成业务日期 + String generateBusinessDate = createGenerateBusinessDate(orderOutTobHeaderDto); + + SaleorderRequestDto saleorderRequestDto = new SaleorderRequestDto(); + SaleorderRequestParentDto saleorderRequestParentDto = new SaleorderRequestParentDto(); + saleorderRequestParentDto.setDbilldate(generateBusinessDate);//单据日期 + saleorderRequestParentDto.setBretinvflag("N");//退货标记 + saleorderRequestParentDto.setCbiztype(bdBusitypeEntity.getPkBusitype());//业务流程 + saleorderRequestParentDto.setCcalbodyid(bdCalbodyEntity.getPkCalbody());//库存组织 + saleorderRequestParentDto.setCcustomerid(bdCumandocEntity.getPkCumandoc());//客户=开票单位=收货单位=表体收货单位=收货单位 + saleorderRequestParentDto.setCdeptid(bdDeptdocEntity.getPkDeptdoc());//部门 + saleorderRequestParentDto.setCemployeeid(null);//业务员 + saleorderRequestParentDto.setCoperatorid("0001A110000000000U3D");//制单人 + 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.setVdef19(header.getCode()); + saleorderRequestParentDto.setVdef20(header.getId()); + + //平台 + saleorderRequestParentDto.setPk_defdoc2(platformArchives.getPkDefdoc()); + saleorderRequestParentDto.setVdef2(platformArchives.getDocname()); + + //TODO 2024年8月8日 17:17:58 店铺档案自定义项1,先不传,后续维护好之后再传! + + saleorderRequestDto.setParentvo(saleorderRequestParentDto); + + List saleorderRequestChildrenDtoList = new ArrayList<>(); + saleorderRequestDto.setChildrenvo(saleorderRequestChildrenDtoList); + + //把汇总好的出库单明细行合并成一行 + for (int j = 0; j < details.size(); j++) { + DetailsDto detailsDto = details.get(j); + //存货管理档案:取发货公司的存货管理档案 + BdInvmandocEntity bdInvmandocEntity = queryInventoryMan(detailsDto, bdCalbodyEntity.getPkCorp()); + //存货基础档案 + BdInvbasdocEntity bdInvbasdocEntity = queryStockBasicArchives(bdInvmandocEntity.getPkInvmandoc(), deliverGoodsCorp.getPkCorp()); + //根据存货基础档案编码,查询当前存货的税率 + BdTaxitemsEntity bdTaxitemsEntity1 = queryBdTaxitems(bdInvbasdocEntity.getInvcode()); + + String tax = "0." + new BigDecimal(bdTaxitemsEntity1.getTaxratio()).stripTrailingZeros().toPlainString(); + + // 如果是海外的店铺,则税率为零 + String exportVaue = ExportConstant.exportConstant.get(header.getStoreCode()); + if (exportVaue != null) { + tax = "0"; + } + + BigDecimal noriginalcurprice = null;//无税单价 + BigDecimal noriginalcurmny = null;//无税金额 + BigDecimal noriginalcurtaxprice = null;//含税单价 + BigDecimal noriginalcursummny = null;//价税合计 + BigDecimal noriginalcurtaxmny = null;//税额 + try { + noriginalcurtaxprice = new BigDecimal(detailsDto.getTotalPayAmount()).divide(new BigDecimal(detailsDto.getShipQty()), 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(new BigDecimal(detailsDto.getShipQty())).setScale(2, BigDecimal.ROUND_HALF_UP); + noriginalcursummny = noriginalcurtaxprice.multiply(new BigDecimal(detailsDto.getShipQty())).setScale(2, BigDecimal.ROUND_HALF_UP); + noriginalcurtaxmny = noriginalcursummny.subtract(noriginalcurmny).setScale(2, BigDecimal.ROUND_HALF_UP); + } catch (Exception e) { + logger.error("TOB金额计算错误", e); + Assert.state(false, "TOB金额计算错误,原因:{}", e.getMessage()); + } + + //判断是否为赠品 + String isblargessflag = "N"; + if (noriginalcursummny.longValue() == 0) { + isblargessflag = "Y"; + } + + SaleorderRequestChildrenDto saleorderRequestChildrenDto = new SaleorderRequestChildrenDto(); + saleorderRequestChildrenDto.setBlargessflag(isblargessflag);//是否赠品 + saleorderRequestChildrenDto.setCadvisecalbodyid(bdCalbodyEntity.getPkCalbody());//发货库存组织 + saleorderRequestChildrenDto.setCbodywarehouseid(bdStordocEntity.getPkStordoc());//发货仓库 + saleorderRequestChildrenDto.setCbodywarehousecode(bdStordocEntity.getStorcode());//发货仓库编码:这个字段不需要给openapi接口,而是提供给下游方法使用 + saleorderRequestChildrenDto.setCconsigncorpid(deliverGoodsCorp.getPkCorp());//发货公司 + saleorderRequestChildrenDto.setCcurrencytypeid("00010000000000000001");//币种 + saleorderRequestChildrenDto.setCinventoryid(bdInvmandocEntity.getPkInvmandoc());//存货id + saleorderRequestChildrenDto.setCinventorycode(bdInvbasdocEntity.getInvcode());//存货编码 + saleorderRequestChildrenDto.setCreceiptcorpid(bdCumandocEntity.getPkCumandoc());//收货单位 + saleorderRequestChildrenDto.setDconsigndate(generateBusinessDate);//计划发货日期 + saleorderRequestChildrenDto.setDdeliverdate(generateBusinessDate);//要求收货日期 + saleorderRequestChildrenDto.setNexchangeotobrate("1.00000000");//折本汇率 + saleorderRequestChildrenDto.setNitemdiscountrate("100.000000");//单品折扣 + saleorderRequestChildrenDto.setNnumber(detailsDto.getShipQty());//数量 + saleorderRequestChildrenDto.setNoriginalcurdiscountmny("0");//折扣额 +// saleorderRequestChildrenDto.setNoriginalcurmny(noriginalcurmny.stripTrailingZeros().toPlainString());//无税金额 +// saleorderRequestChildrenDto.setNoriginalcurnetprice(noriginalcurprice.stripTrailingZeros().toPlainString());//无税净价* +// saleorderRequestChildrenDto.setNoriginalcurprice(noriginalcurprice.stripTrailingZeros().toPlainString());//无税单价* +// saleorderRequestChildrenDto.setNoriginalcursummny(noriginalcursummny.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());//税率 + saleorderRequestChildrenDtoList.add(saleorderRequestChildrenDto); + } + //记录成功 + //销售订单单据推送到u8c + List saleorderRequestDtoList = new ArrayList<>(); + saleorderRequestDtoList.add(saleorderRequestDto); + + Map> stringStringMap = new HashMap<>(); + stringStringMap.put("saleorder", saleorderRequestDtoList); + SoSaleResultRootDto soSaleResultRootDto = sendU8CTOCOrder(JSON.toJSONString(stringStringMap)); + logger.info("TOB销售订单编号:{} 销售公司:{}", soSaleResultRootDto.getParentvo().getVreceiptcode(), soSaleResultRootDto.getParentvo().getPk_corp()); + } + } catch (Exception e) { + logger.error("TOB业务转换成U8C对象过程中、或者单据推送到U8C出现异常!", e); + //记录失败 + } + } catch (Exception e) { + logger.error("TOB外层转换逻辑抛出异常", e); + // 记录失败 + } + } + } + + /** + * 2024年7月31日 10:34:09 + * 生成业务日期,以发货时间作为业务日期 + * + * @author liuyang + */ + private String createGenerateBusinessDate(OrderOutTobHeaderDto orderOutTobHeaderDto) { + return "2024-08-13"; + //TODO 测试 +// if (orderOutTobHeaderDto != null && orderOutTobHeaderDto.getHeader() != null && orderOutTobHeaderDto.getHeader().getShipAt() != null) { +// HeaderDto header = orderOutTobHeaderDto.getHeader(); +// String shipAt = header.getShipAt(); +// String businessFormat = null; +// try { +// Date dbill = DateUtil.parse(shipAt); +// businessFormat = DateUtil.format(dbill, "yyyy-MM-dd"); +// } catch (Exception e) { +// logger.error("业务日期生成失败", e); +// } +// return businessFormat; +// } else { +// logger.error("生成出库日期失败,或者shipAt为空! json:{}", JSON.toJSON(orderOutTobHeaderDto)); +// Assert.state(false, "生成出库日期失败,或者shipAt为空! json:{}", JSON.toJSON(orderOutTobHeaderDto)); +// return null; +// } + } + + /** + * 档案转换 + * + * @author liuyang + */ + private List queryBasicArchives(List headerDetailsDtoList) { + List orderOutTobHeaderDtoArrayList = new ArrayList<>(); + + if (headerDetailsDtoList != null && headerDetailsDtoList.size() > 0) { + try { + for (int i = 0; i < headerDetailsDtoList.size(); i++) { + HeaderDetailsDto headerDetailsDto = headerDetailsDtoList.get(i); + HeaderDto header = headerDetailsDto.getHeader(); + List details = headerDetailsDto.getDetails(); + + // 销售公司、发货公司 + String companyCode = header.getCompanyCode(); + Assert.notNull(companyCode, "O表头公司不能为空"); + BdCorpEntity bdCorpEntity = new BdCorpEntity(); + bdCorpEntity.setDr(0); + bdCorpEntity.setDataSourceCode("lets_u8c"); + bdCorpEntity.setUnitcode(companyCode); + List bdCorpEntityList = iBdCorpDao.query(bdCorpEntity); + if (bdCorpEntityList.size() == 0) { + Assert.state(false, "根据O货主编码{},无法匹配到U8C销售公司", companyCode); + } else if (bdCorpEntityList.size() >= 2) { + Assert.state(false, "根据O货主编码{},匹配到U8C销售公司{}个", companyCode, bdCorpEntityList.size()); + } + + // 发货库存组织 + BdCalbodyEntity bdCalbodyEntity = new BdCalbodyEntity(); + bdCalbodyEntity.setDr(0); + bdCalbodyEntity.setDataSourceCode("lets_u8c"); + bdCalbodyEntity.setPkCorp(bdCorpEntityList.get(0).getPkCorp()); + List bdCalbodyEntities = iBdCalbodyDao.query(bdCalbodyEntity); + if (bdCalbodyEntities.size() == 0) { + Assert.state(false, "根据U8C发货公司{},无法匹配到U8C发货库存组织", bdCorpEntityList.get(0).getPkCorp()); + } else if (bdCalbodyEntities.size() >= 2) { + Assert.state(false, "根据U8C发货公司{},匹配到U8C发货库存组织{}个", bdCorpEntityList.get(0).getPkCorp(), bdCalbodyEntities.size()); + } + + // 仓库 + String facilityCode = header.getFacilityCode(); + Assert.notNull(facilityCode, "O售后入库单仓库facilityCode字段不能为空"); + BdStordocEntity bdStordocEntity = new BdStordocEntity(); + bdStordocEntity.setDr(0L); + bdStordocEntity.setDataSourceCode("lets_u8c"); + bdStordocEntity.setPkCalbody(bdCalbodyEntities.get(0).getPkCalbody()); + bdStordocEntity.setStorcode(facilityCode); + List bdStordocEntityList = iBdStordocDao.query(bdStordocEntity); + if (bdStordocEntityList.size() == 0) { + Assert.state(false, "根据O仓库编码+U8C发货库存组织主键,无法匹配到U8C仓库", facilityCode, bdCalbodyEntities.get(0).getPkCalbody()); + } else if (bdStordocEntityList.size() >= 2) { + Assert.state(false, "根据O仓库编码+U8C发货库存组织主键,匹配到U8C仓库多个", facilityCode, bdCalbodyEntities.get(0).getPkCalbody()); + } + + //销售组织 + //2024年8月13日 10:35:05 已经和佳妮在微信确认,U8C销售公司编码与U8C销售组织编码保持一致,因此通过销售公司编码匹配 + BdSalestruEntity bdSalestruEntity = new BdSalestruEntity(); + bdSalestruEntity.setDr(0); + bdSalestruEntity.setDataSourceCode("lets_u8c"); + bdSalestruEntity.setVsalestrucode(bdCorpEntityList.get(0).getUnitcode()); + List bdSalestruEntityList = iBdSalestruDao.query(bdSalestruEntity); + if (bdSalestruEntityList.size() == 0) { + Assert.state(false, "根据U8C销售公司编码:{},无法匹配到U8C销售组织", bdCorpEntityList.get(0).getUnitcode()); + } else if (bdSalestruEntityList.size() >= 2) { + Assert.state(false, "根据U8C销售公司编码:{},无法匹配到U8C销售组织", bdCorpEntityList.get(0).getUnitcode()); + } + + //业务部门 + String deptName = "其他部门"; + BdDeptdocEntity bdDeptdocEntity = new BdDeptdocEntity(); + bdDeptdocEntity.setDataSourceCode("lets_u8c"); + bdDeptdocEntity.setDr(0); + bdDeptdocEntity.setDeptname(deptName); + bdDeptdocEntity.setPkCorp(bdCorpEntityList.get(0).getPkCorp()); + List bdDeptdocEntityList = iBdDeptdocDao.query(bdDeptdocEntity); + if (bdDeptdocEntityList.size() == 0) { + Assert.state(false, "根据部门名称:{} 公司id:{},无法匹配到U8C销售组织", deptName, bdCorpEntityList.get(0).getPkCorp()); + } else if (bdDeptdocEntityList.size() >= 2) { + Assert.state(false, "根据部门名称:{} 公司id:{},匹配到U8C销售组织{}个", deptName, bdCorpEntityList.get(0).getPkCorp()); + } + + //客商基本档案 + String custName = "天猫intoyou旗舰店-自营"; + BdCubasdocEntity bdCubasdocEntity = new BdCubasdocEntity(); + bdCubasdocEntity.setDataSourceCode("lets_u8c"); + bdCubasdocEntity.setDr(0L); + bdCubasdocEntity.setCustname(custName); + List bdCubasdocEntityList = iBdCubasdocDao.query(bdCubasdocEntity); + + //客商管理档案 + BdCumandocEntity bdCumandocEntity1 = new BdCumandocEntity(); + bdCumandocEntity1.setDataSourceCode("lets_u8c"); + bdCumandocEntity1.setDr(0L); + bdCumandocEntity1.setPkCorp(bdCorpEntityList.get(0).getPkCorp()); + bdCumandocEntity1.setPkCubasdoc(bdCubasdocEntityList.get(0).getPkCubasdoc()); + List bdCumandocEntityList = iBdCumandocDao.query(bdCumandocEntity1); + + //查找平台 + String platformZdyId = "0001A210000000000JUD"; + String sourcePlatformCode = header.getSourcePlatformCode(); + BdDefdocEntity bdDefdocEntity = new BdDefdocEntity(); + bdDefdocEntity.setPkDefdoclist(platformZdyId); + bdDefdocEntity.setDr(0); + bdDefdocEntity.setDataSourceCode("lets_u8c"); + bdDefdocEntity.setDoccode(sourcePlatformCode); + List bdDefdocEntityList = iBdDefdocDao.query(bdDefdocEntity); + if (bdDefdocEntityList.size() == 0) { + Assert.state(false, "根据O平台编码{},无法匹配到U8C平台自定义档案 自定义档案主键:{}", sourcePlatformCode, platformZdyId); + } else if (bdDefdocEntityList.size() >= 2) { + Assert.state(false, "根据O平台编码{},无法匹配到U8C平台自定义档案 自定义档案主键:{}", sourcePlatformCode, platformZdyId); + } + + OrderOutTobHeaderDto orderOutTobHeaderDto = new OrderOutTobHeaderDto(); + orderOutTobHeaderDto.setBdCorpEntity(bdCorpEntityList.get(0)); + orderOutTobHeaderDto.setBdCalbodyEntity(bdCalbodyEntities.get(0)); + orderOutTobHeaderDto.setBdStordocEntity(bdStordocEntityList.get(0)); + orderOutTobHeaderDto.setBdSalestruEntity(bdSalestruEntityList.get(0)); + orderOutTobHeaderDto.setBdDeptdocEntity(bdDeptdocEntityList.get(0)); + orderOutTobHeaderDto.setBdCumandocEntity(bdCumandocEntityList.get(0)); + orderOutTobHeaderDto.setBdCubasdocEntity(bdCubasdocEntityList.get(0)); + orderOutTobHeaderDto.setDeliverGoodsCorp(bdCorpEntityList.get(0)); + orderOutTobHeaderDto.setPlatformArchives(bdDefdocEntityList.get(0)); + + orderOutTobHeaderDto.setHeader(header); + orderOutTobHeaderDto.setDetails(details); + + BeanUtil.copyPropertiesV2(header, orderOutTobHeaderDto); + orderOutTobHeaderDtoArrayList.add(orderOutTobHeaderDto); + } + //成功 + } catch (Exception e) { + logger.error("OFS销售出库单关联查询U8C档案失败", e); + //失败 + } + } else { + logger.info("queryBasicArchives方法对应的headerDetailsDtoList.size为0"); + } + return orderOutTobHeaderDtoArrayList; + } + + /** + * bean copy + * 2024年7月31日 10:34:09 + */ + private List copyHeaderDto(List headerDtoList) { + List tocofsSaleoutEntityList = new ArrayList<>(); + if (headerDtoList != null && headerDtoList.size() > 0) { + for (int i = 0; i < headerDtoList.size(); i++) { + HeaderDto headerDto = headerDtoList.get(i); + TocofsSaleoutEntity tocofsSaleoutEntity = new TocofsSaleoutEntity(); +// BeanUtils.copyProperties(headerDto, tocofsSaleoutEntity); + BeanUtil.copyPropertiesV2(headerDto, tocofsSaleoutEntity); + tocofsSaleoutEntityList.add(tocofsSaleoutEntity); + } + } + return tocofsSaleoutEntityList; + } + + /** + * bean copy + * 2024年8月2日 16:04:11 + */ + private List copyDetailsDto(List detailsDtos) { + List tocofsSaleoutDetailedEntityArrayList = new ArrayList<>(); + if (detailsDtos != null && detailsDtos.size() > 0) { + for (int i = 0; i < detailsDtos.size(); i++) { + DetailsDto detailsDto = detailsDtos.get(i); + TocofsSaleoutDetailedEntity tocofsSaleoutDetailedEntity = new TocofsSaleoutDetailedEntity(); + tocofsSaleoutDetailedEntity.setBusinessType("TOB_ORDER"); +// BeanUtils.copyProperties(detailsDto, tocofsSaleoutDetailedEntity); + BeanUtil.copyPropertiesV2(detailsDto, tocofsSaleoutDetailedEntity); + tocofsSaleoutDetailedEntityArrayList.add(tocofsSaleoutDetailedEntity); + } + } + return tocofsSaleoutDetailedEntityArrayList; + } + + /** + * 分组汇总:公司+店铺+仓库+SKU+出库类型,数量合并相加 + * + * @author liuyang + */ + private Map> groupSummary(List sonDetailsDtoList) { + if (sonDetailsDtoList != null && sonDetailsDtoList.size() > 0) { + for (int i = 0; i < sonDetailsDtoList.size(); i++) { + SonDetailsDto sonDetailsDto = sonDetailsDtoList.get(i); + //2024年8月6日 10:35:25表头对象用于带出表头相关的分组汇总信息 + HeaderDto header = sonDetailsDto.getHeader(); + + //公司 + BdCorpEntity bdCorpEntity = sonDetailsDto.getBdCorpEntity(); + //店铺(主要是店铺编码) + String storeCode = header.getStoreCode(); + //仓库 + String facilityCode = header.getFacilityCode(); + //SKU + String skuCode = sonDetailsDto.getSkuCode(); + //出库类型 + String refOrderType = header.getRefOrderType(); + + StringBuffer summaryDimensionStr = new StringBuffer(); + if (bdCorpEntity != null && bdCorpEntity.getPkCorp() != null) { + summaryDimensionStr.append(bdCorpEntity.getPkCorp()); + } else { + summaryDimensionStr.append(NOTHING); + } + summaryDimensionStr.append(ADD); + + if (storeCode != null && !"".equals(storeCode)) { + summaryDimensionStr.append(storeCode); + } else { + summaryDimensionStr.append(NOTHING); + } + summaryDimensionStr.append(ADD); + + if (facilityCode != null && !"".equals(facilityCode)) { + summaryDimensionStr.append(facilityCode); + } else { + summaryDimensionStr.append(NOTHING); + } + summaryDimensionStr.append(ADD); + + if (skuCode != null && !"".equals(skuCode)) { + summaryDimensionStr.append(skuCode); + } else { + summaryDimensionStr.append(NOTHING); + } + summaryDimensionStr.append(ADD); + + if (refOrderType != null && !"".equals(refOrderType)) { + summaryDimensionStr.append(refOrderType); + } else { + summaryDimensionStr.append(NOTHING); + } + + sonDetailsDto.setSummaryDimensionStr(summaryDimensionStr.toString()); + } + logger.info("TOB:{}个出库单对象需要汇总", sonDetailsDtoList.size()); + return sonDetailsDtoList.stream().collect(Collectors.groupingBy(SonDetailsDto::getSummaryDimensionStr)); + } + logger.info("TOB:0个对象需要汇总"); + return null; + } + + /** + * 2024年8月6日 10:59:03 查询U8C业务流程 + * + * @author liuyang + */ + private BdBusitypeEntity u8cOperationFlow() throws Exception { + //查询业务流程 + //2024年8月6日 11:33:07 具体的业务流程名称,还需要实施提供 + String processName = "TOB销售"; + BdBusitypeEntity bdBusitypeEntity = queryBdBusitypeUtil.queryBdBusitype(processName); + Assert.notNull(bdBusitypeEntity, "根据业务流程名称({})没有查询到业务流程", processName); + return bdBusitypeEntity; + } + + /** + * 检查参数是否为空 + * 2024年8月6日 11:40:19 保险的做法,最好还是验证一下 + * + * @author liuyang + */ + private void checkArchives(SonDetailsDto sonDetailsDto) { + Assert.notNull(sonDetailsDto, "sonDetailsDto不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getHeader(), "header对象不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getBdCorpEntity(), "表头公司不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getBdCalbodyEntity(), "发货库存组织不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getBdStordocEntity(), "发货仓库不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getBdCalbodyEntity1(), "收货库存组织不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getBdStordocEntity1(), "收货库存不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getBdSalestruEntity(), "销售组织不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getBdDeptdocEntity(), "业务部门不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getBdCumandocEntity(), "客商档案不能为空 对象json:{}", JSON.toJSONString(sonDetailsDto)); + } + + /** + * 查询存货管理档案 + * + * @param pkCorp 发货公司主键 + * @param detailsDto 出库单存货明细行 + * @author liuyang + */ + private BdInvmandocEntity queryInventoryMan(DetailsDto detailsDto, String pkCorp) throws Exception { + Assert.notNull(detailsDto, "sonDetailsDto不能为空"); + Assert.notNull(detailsDto.getSkuCode(), "O存货商家编码不能为空"); + Assert.notNull(pkCorp, "发货公司主键不能为空"); + + BdInvmandocEntity bdInvmandocEntity = new BdInvmandocEntity(); + bdInvmandocEntity.setInvcode(detailsDto.getSkuCode()); + bdInvmandocEntity.setPkCorp(pkCorp); + List bdInvmandocEntity2 = iBdInvmandocDao.queryBdInvmandocByInvcodeList(bdInvmandocEntity); + if (bdInvmandocEntity2.size() == 0) { + Assert.state(false, "根据O商家编码:{} U8C发货公司主键:{}没有查询到存货管理档案", detailsDto.getSkuCode(), pkCorp); + } else if (bdInvmandocEntity2.size() >= 2) { + Assert.state(false, "根据O商家编码:{} U8C发货公司主键:{}没有查询到存货管理档案", detailsDto.getSkuCode(), pkCorp); + } + return bdInvmandocEntity2.get(0); + } + + /** + * 合并明细行 + * 单价计算公式:sum(实付金额/实发数量) 最后除以条数 + * + * @author liuyang + */ + private SonDetailsDto groupMergeDetailedRows(List sonDetailsDtoList) throws Exception { + if (sonDetailsDtoList != null && sonDetailsDtoList.size() > 0) { + BigDecimal groupTotalPayAmount = new BigDecimal("0"); + BigDecimal groupShipQty = new BigDecimal("0"); + + for (int i = 0; i < sonDetailsDtoList.size(); i++) { + SonDetailsDto sonDetailsDto = sonDetailsDtoList.get(i); + + //实付金额/实发数量 + Assert.notNull(sonDetailsDto.getTotalPayAmount(), "实付金额不能为空 明细行对象:{}", JSON.toJSONString(sonDetailsDto)); + Assert.notNull(sonDetailsDto.getShipQty(), "实发数量不能为空 明细行对象:{}", JSON.toJSONString(sonDetailsDto)); + BigDecimal totalPayAmountBigDecimal = new BigDecimal(sonDetailsDto.getTotalPayAmount()); + BigDecimal shipQtyBigDecimal = new BigDecimal(sonDetailsDto.getShipQty()); + + groupTotalPayAmount = groupTotalPayAmount.add(totalPayAmountBigDecimal); + groupShipQty = groupShipQty.add(shipQtyBigDecimal); + } + SonDetailsDto sonDetailsDto = sonDetailsDtoList.get(0); + sonDetailsDto.setGroupShipQty(groupShipQty); + sonDetailsDto.setGroupTotalPayAmount(groupTotalPayAmount); + logger.info("{}个明细行发生了合并!", sonDetailsDtoList.size()); + return sonDetailsDto; + } else { + logger.info("sonDetailsDtoList集合是空的!"); + } + return null; + } + + /** + * 2024年8月7日 10:25:29 + * 查询基础档案,根据公司、管理档案主键查询 + * + * @author liuyang + */ + private BdInvbasdocEntity queryStockBasicArchives(String pkInvmandoc, String pkCorp) throws Exception { + Assert.notNull(pkInvmandoc, "存货管理档案不能为空"); + Assert.notNull(pkCorp, "公司档案不能为空"); + + BdInvbasdocEntity bdInvbasdocEntity = new BdInvbasdocEntity(); + bdInvbasdocEntity.setPk_invmandoc(pkInvmandoc); + bdInvbasdocEntity.setPk_corp(pkCorp); + List bdInvbasdocEntity2 = iBdInvbasdocDao.queryBdInvbasdocByPkInvmandocV2(bdInvbasdocEntity); + if (bdInvbasdocEntity2.size() == 0) { + Assert.state(false, "根据存货管理档案主键{}和公司档案主键{}没有查询到U8C基础档案", pkInvmandoc, pkCorp); + } else if (bdInvbasdocEntity2.size() >= 2) { + Assert.state(false, "根据存货管理档案主键{}和公司档案主键{}没有查询到U8C基础档案", pkInvmandoc, pkCorp); + } + return bdInvbasdocEntity; + } + + /** + * 2024年8月7日 14:58:34 + * 查询税目档案 + * + * @author liuyang + */ + private BdTaxitemsEntity queryBdTaxitems(String invcode) throws Exception { + Assert.notNull(invcode, "存货编码不能为空"); + + BdTaxitemsEntity bdTaxitemsEntity = new BdTaxitemsEntity(); + bdTaxitemsEntity.setInvcode(invcode); + List bdTaxitemsEntityList = iBdTaxitemsDao.queryBdInvbasdocByInvcodeV2(bdTaxitemsEntity); + if (bdTaxitemsEntityList.size() == 0) { + Assert.state(false, "根据存货编码{}没有查询到U8C税目档案", invcode); + } else if (bdTaxitemsEntityList.size() >= 2) { + Assert.state(false, "根据存货编码{}没有查询到U8C税目档案", invcode); + } + return bdTaxitemsEntityList.get(0); + } + + /** + * 2024年8月8日 10:54:48 + * 推送U8C销售订单方法 + * + * @author liuyang + */ + public SoSaleResultRootDto sendU8CTOCOrder(String param) { + long startLong = System.currentTimeMillis(); + logger.info("TOB推送开始,推送参数:" + param + ",U8C_URL:" + ProfilesActiveConstant.U8C_URL); + String result = HttpRequest.post(ProfilesActiveConstant.U8C_URL).header("appId", "800037")//头信息,多个头信息多次调用此方法即可 + .header("usercode", "admin").header("password", "21232f297a57a5a743894a0e4a801fc3").header("system", "lz").header("trantype", "PK").header("apiCode", "8000370006")//头信息,多个头信息多次调用此方法即可 + .header("publicKey", "ZJYAWb7lhAUTYqekPkU+uHJv1/ObJxb7dT7sD8HPRDGAgyhCe7eDIk+3zDUT+v578prj")//头信息,多个头信息多次调用此方法即可 + .header("secretKey", "fviZnLBsQUAGF8w8FSOdJi7XlIm/XAZclMxRagDLfTyJFlvnIBF3w66Hrpfzs8cYj3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=")//头信息,多个头信息多次调用此方法即可 + .body(param)//表单内容 + .timeout(20000)//超时,毫秒 + .execute().body(); + logger.info("TOB推送结束,返回参数:" + result); + long endLong = System.currentTimeMillis(); + logger.info("TOB接口请求耗时:" + (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, "TOB业务O出库单推送U8C销售订单失败 接口返回结果:{}", result); + } + return soSaleResultRootDto; + } + + /** + * 返回结果解析处理,在确认了success后调用 + * + * @author liuyang + */ + private SoSaleResultRootDto resultDataHandle(String resultData) { + try { + if (resultData != null && !"".equals(resultData)) { + if (resultData.contains("[")) { + resultData = resultData.substring(1, resultData.length() - 1); + } + return JSON.parseObject(resultData, SoSaleResultRootDto.class); + } + } catch (Exception e) { + e.printStackTrace(); + logger.error("解析返回参数失败的错误", e); + //如果解析失败,记录原因,但是不能影响结果的记录 + } + return null; + } + + +} \ No newline at end of file diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToC.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToC.java index ed486007..87a07455 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToC.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToC.java @@ -455,7 +455,7 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity { Date dbill = DateUtil.parse(shipAt); businessFormat = DateUtil.format(dbill, "yyyy-MM-dd"); } catch (Exception e) { - e.printStackTrace(); +// e.printStackTrace(); logger.error("业务日期转换失败", e); } return businessFormat; @@ -593,6 +593,7 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity { for (int i = 0; i < detailsDtos.size(); i++) { com.hzya.frame.ttxofs.dto.ofssaleorderoutsearch.DetailsDto detailsDto = detailsDtos.get(i); TocofsSaleoutDetailedEntity tocofsSaleoutDetailedEntity = new TocofsSaleoutDetailedEntity(); + tocofsSaleoutDetailedEntity.setBusinessType("TOC_ORDER"); // BeanUtils.copyProperties(detailsDto, tocofsSaleoutDetailedEntity); BeanUtil.copyPropertiesV2(detailsDto, tocofsSaleoutDetailedEntity); tocofsSaleoutDetailedEntityArrayList.add(tocofsSaleoutDetailedEntity); @@ -676,7 +677,7 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity { private BdBusitypeEntity u8cOperationFlow() throws Exception { //查询业务流程 //2024年8月6日 11:33:07 具体的业务流程名称,还需要实施提供 - String processName = "TOC销售业务流程"; + String processName = "TOC销售"; BdBusitypeEntity bdBusitypeEntity = queryBdBusitypeUtil.queryBdBusitype(processName); Assert.notNull(bdBusitypeEntity, "根据业务流程名称({})没有查询到业务流程", processName); return bdBusitypeEntity; @@ -837,6 +838,4 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity { } return null; } - - } 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 8ca6f626..d2656b6c 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 @@ -365,6 +365,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { BigDecimal noriginalcursummny = null;//价税合计 BigDecimal noriginalcurtaxmny = null;//税额=价税合计-无税金额 try { + //TODO 这个金额取错了,需要取售后订单的退款金额 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); @@ -586,6 +587,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { ReturnGoodSearchDetailsDto returnGoodSearchDetailsDto = headerDetailsDtoList2.get(i); TocofsReturngoodsDetailedEntity tocofsReturngoodsDetailedEntity = new TocofsReturngoodsDetailedEntity(); + tocofsReturngoodsDetailedEntity.setBusinessType("TOC_RETURN"); BeanUtil.copyPropertiesV2(returnGoodSearchDetailsDto, tocofsReturngoodsDetailedEntity); tocofsSaleoutDetailedEntityArrayList.add(tocofsReturngoodsDetailedEntity); } @@ -670,7 +672,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity { private BdBusitypeEntity u8cOperationFlow() throws Exception { //查询业务流程 //2024年8月6日 11:33:07 具体的业务流程名称,还需要实施提供 - String processName = "TOC销售业务流程"; + String processName = "TOC销售"; BdBusitypeEntity bdBusitypeEntity = queryBdBusitypeUtil.queryBdBusitype(processName); Assert.notNull(bdBusitypeEntity, "根据业务流程名称({})没有查询到业务流程", processName); return bdBusitypeEntity; diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/u8cdto/OrderOutTobHeaderDto.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/u8cdto/OrderOutTobHeaderDto.java new file mode 100644 index 00000000..4b239d73 --- /dev/null +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/u8cdto/OrderOutTobHeaderDto.java @@ -0,0 +1,74 @@ +package com.hzya.frame.plugin.lets.u8cdto; + +import com.hzya.frame.plugin.lets.entity.*; +import com.hzya.frame.ttxofs.dto.ofssaleorderoutsearch.HeaderDetailsDto; +import lombok.Data; + +/** + * @Author:liuyang + * @Package:com.hzya.frame.plugin.lets.u8cdto + * @Project:kangarooDataCenterV3 + * @name:OrderOutTobHeaderDto + * @Date:2024/8/12 18:07 + * @Filename:OrderOutTobHeaderDto + */ +@Data +public class OrderOutTobHeaderDto extends HeaderDetailsDto { + + /** + * 表头公司(销售公司)、视为发货公司 + */ + private BdCorpEntity bdCorpEntity; + + /** + * 发货库存组织 + */ + private BdCalbodyEntity bdCalbodyEntity; + + /** + * 入库仓库 + */ + private BdStordocEntity bdStordocEntity; + + /** + * 收货库存组织 + */ +// private BdCalbodyEntity bdCalbodyEntity1; + + /** + * 收货仓库 + */ +// private BdStordocEntity bdStordocEntity1; + + /** + * 销售组织 + */ + private BdSalestruEntity bdSalestruEntity; + + + /** + * 业务部门 + */ + private BdDeptdocEntity bdDeptdocEntity; + + /** + * 客商管理档案 + */ + private BdCumandocEntity bdCumandocEntity; + + /** + * 客商基本档案 + */ + private BdCubasdocEntity bdCubasdocEntity; + + /** + * 发货公司 + */ + private BdCorpEntity deliverGoodsCorp; + + /** + * U8C平台档案 + */ + private BdDefdocEntity platformArchives; + +} \ No newline at end of file diff --git a/buildpackage/src/main/resources/cfgHome/plugin/lets/spring/spring-sowow-plugin.xml b/buildpackage/src/main/resources/cfgHome/plugin/lets/spring/spring-sowow-plugin.xml index 4e47ed20..dc45bad9 100644 --- a/buildpackage/src/main/resources/cfgHome/plugin/lets/spring/spring-sowow-plugin.xml +++ b/buildpackage/src/main/resources/cfgHome/plugin/lets/spring/spring-sowow-plugin.xml @@ -21,4 +21,7 @@ - + + + + \ No newline at end of file diff --git a/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToBTest.java b/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToBTest.java new file mode 100644 index 00000000..49c0525e --- /dev/null +++ b/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/sales/SoSaleOutPluginInitializerToBTest.java @@ -0,0 +1,31 @@ +package com.hzya.frame.plugin.lets.plugin.sales; + +import com.hzya.frame.WebappApplication; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.Assert.*; + +/** + * @Author:liuyang + * @Package:com.hzya.frame.plugin.lets.plugin.sales + * @Project:kangarooDataCenterV3 + * @name:SoSaleOutPluginInitializerToBTest + * @Date:2024/8/13 15:59 + * @Filename:SoSaleOutPluginInitializerToBTest + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = WebappApplication.class) +public class SoSaleOutPluginInitializerToBTest { + + @Autowired + private SoSaleOutPluginInitializerToB soSaleOutPluginInitializerToB; + + @Test + public void startImplement() { + soSaleOutPluginInitializerToB.startImplement(null, null); + } +} \ No newline at end of file diff --git a/service/src/main/java/com/hzya/frame/ttxofs/service/OfsUnifiedService.java b/service/src/main/java/com/hzya/frame/ttxofs/service/OfsUnifiedService.java index 31cbda27..ef5d7f12 100644 --- a/service/src/main/java/com/hzya/frame/ttxofs/service/OfsUnifiedService.java +++ b/service/src/main/java/com/hzya/frame/ttxofs/service/OfsUnifiedService.java @@ -15,7 +15,7 @@ import com.hzya.frame.ttxofs.dto.InterfaceParamDto; */ public interface OfsUnifiedService { /** - * OFS出库单查询 + * OFS接口入库 * * @author liuyang */