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/dao/IShopDao.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/dao/IShopDao.java new file mode 100644 index 00000000..f2ea0bb3 --- /dev/null +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/dao/IShopDao.java @@ -0,0 +1,14 @@ +package com.hzya.frame.plugin.lets.ofs.dao; + +import com.hzya.frame.basedao.dao.IBaseDao; +import com.hzya.frame.plugin.lets.ofs.entity.ShopEntity; + +/** + * @Author + * @Date 2024/8/6 15:42 + * @PackageName:com.hzya.frame.plugin.lets.ofs.dao + * @ClassName: ShopDao + * @Description: TODO + */ +public interface IShopDao extends IBaseDao { +} diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/dao/impl/ShopDapImpl.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/dao/impl/ShopDapImpl.java new file mode 100644 index 00000000..ab9f915c --- /dev/null +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/dao/impl/ShopDapImpl.java @@ -0,0 +1,18 @@ +package com.hzya.frame.plugin.lets.ofs.dao.impl; + +import com.hzya.frame.basedao.dao.MybatisGenericDao; +import com.hzya.frame.plugin.lets.ofs.dao.IShopDao; +import com.hzya.frame.plugin.lets.ofs.entity.ShopEntity; +import com.hzya.frame.plugin.lets.ofs.entity.TocofsSaleoutEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * @Author + * @Date 2024/8/6 15:43 + * @PackageName:com.hzya.frame.plugin.lets.ofs.dao.impl + * @ClassName: ShopDapImpl + * @Description: TODO + */ +@Mapper +public class ShopDapImpl extends MybatisGenericDao implements IShopDao { +} diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsSaleoutDetailedEntity.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsSaleoutDetailedEntity.java index 4011c752..c32b28f1 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsSaleoutDetailedEntity.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/entity/TocofsSaleoutDetailedEntity.java @@ -144,8 +144,37 @@ public class TocofsSaleoutDetailedEntity extends BaseEntity { private String newSystemPrimary; + /** + * 主表主键 + */ private String primaryKey; + /** + * 业务类型 + */ + private String businessType; + + /** + * 业务日期 + */ + private String businessDate; + + public String getBusinessDate() { + return businessDate; + } + + public void setBusinessDate(String businessDate) { + this.businessDate = businessDate; + } + + public String getBusinessType() { + return businessType; + } + + public void setBusinessType(String businessType) { + this.businessType = businessType; + } + public String getNewTransmitInfo() { return newTransmitInfo; } diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/service/IShopService.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/service/IShopService.java new file mode 100644 index 00000000..70177bca --- /dev/null +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/service/IShopService.java @@ -0,0 +1,15 @@ +package com.hzya.frame.plugin.lets.ofs.service; + +import com.hzya.frame.basedao.service.IBaseService; +import com.hzya.frame.plugin.lets.ofs.entity.ShopEntity; +import com.hzya.frame.plugin.lets.ofs.entity.TocofsSaleoutDetailedEntity; + +/** + * @Author + * @Date 2024/8/6 15:46 + * @PackageName:com.hzya.frame.plugin.lets.ofs.service + * @ClassName: IShopService + * @Description: TODO + */ +public interface IShopService extends IBaseService { +} diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/service/impl/ShopSerivceImpl.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/service/impl/ShopSerivceImpl.java new file mode 100644 index 00000000..7ddba7b9 --- /dev/null +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofs/service/impl/ShopSerivceImpl.java @@ -0,0 +1,17 @@ +package com.hzya.frame.plugin.lets.ofs.service.impl; + +import com.hzya.frame.basedao.service.impl.BaseService; +import com.hzya.frame.plugin.lets.ofs.entity.ShopEntity; +import com.hzya.frame.plugin.lets.ofs.entity.TocofsSaleoutDetailedEntity; +import com.hzya.frame.plugin.lets.ofs.service.IShopService; + +/** + * @Author + * @Date 2024/8/6 15:46 + * @PackageName:com.hzya.frame.plugin.lets.ofs.service.impl + * @ClassName: ShopSerivceImpl + * @Description: TODO + */ +public class ShopSerivceImpl extends BaseService implements IShopService { + +} diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofsvo/QueryOfsGoodsRequestVO.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofsvo/QueryOfsGoodsRequestVO.java new file mode 100644 index 00000000..857c6930 --- /dev/null +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/ofsvo/QueryOfsGoodsRequestVO.java @@ -0,0 +1,16 @@ +package com.hzya.frame.plugin.lets.ofsvo; + +import lombok.Data; + +/** + * OFS SKU查询请求类 + */ +@Data +public class QueryOfsGoodsRequestVO { + /** 开始时间 */ + private String created_start; + /** 结束时间 */ + private String created_end; + /** 组织 */ + private String clientCode; +} diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/adjust/AdjustOutPluginInitializer.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/adjust/AdjustOutPluginInitializer.java new file mode 100644 index 00000000..666426ae --- /dev/null +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/adjust/AdjustOutPluginInitializer.java @@ -0,0 +1,155 @@ +package com.hzya.frame.plugin.lets.plugin.adjust; + +import cn.hutool.core.date.DateField; +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hzya.frame.base.PluginBaseEntity; +import com.hzya.frame.plugin.lets.ofsvo.QueryOfsStockinOrderRequestVO; +import com.hzya.frame.plugin.lets.util.PushDataByU8cUtil; +import com.hzya.frame.plugin.lets.util.SaveOrUpdateBusinessLogUtil; +import com.hzya.frame.sysnew.integtationTaskLivingDetails.dao.IIntegrationTaskLivingDetailsDao; +import com.hzya.frame.ttxofs.dto.InterfaceParamDto; +import com.hzya.frame.ttxofs.dto.stock.StockinOrderSearchResponse; +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.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.concurrent.locks.ReentrantLock; + +public class AdjustOutPluginInitializer extends PluginBaseEntity { + Logger logger = LoggerFactory.getLogger(AdjustOutPluginInitializer.class); + + private static final ReentrantLock LOCK = new ReentrantLock(true); + + @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.adjust.AdjustOutPluginInitializer"; + } + + @Override + public String getPluginName() { + return "丽知:OFS调整出库--->U8C其它入库"; + } + + @Override + public String getPluginLabel() { + return "丽知:OFS调整出库--->U8C其它入库"; + } + + @Override + public String getPluginType() { + return "1"; + } + + @Autowired + private IIntegrationTaskLivingDetailsDao iIntegrationTaskLivingDetailsDao; + @Autowired + private PushDataByU8cUtil pushDataByU8cUtil; + @Autowired + private SaveOrUpdateBusinessLogUtil saveOrUpdateBusinessLogUtil; + + @Autowired + private OfsUnifiedService ofsUnifiedService; + + @Override + public JsonResultEntity executeBusiness(JSONObject requestJson) throws Exception { + return null; + } + + + /** + * 默认推送 + */ + public void start() { + try { + //获取当前时间 + Date currentDate = new Date(); + Date startTime = DateUtil.offset(currentDate, DateField.MINUTE, -10); + Date endTime = DateUtil.offset(currentDate, DateField.MINUTE, -2); + String startTimeStr = DateUtil.format(startTime, "yyyy-MM-dd HH:mm:ss"); + String endTimeStr = DateUtil.format(endTime, "yyyy-MM-dd HH:mm:ss"); + + QueryOfsStockinOrderRequestVO queryOfsStockinOrderRequestVO = new QueryOfsStockinOrderRequestVO(); + queryOfsStockinOrderRequestVO.setCreated_start("2024-08-05 00:00:00"); + queryOfsStockinOrderRequestVO.setCreated_end("2024-08-09 23:59:59"); + queryOfsStockinOrderRequestVO.setCompanyCode("SHXM"); +// queryOfsTransferOrderRequestVO.setStatus("900");//状态 500待同步 510已同步 700收货中 900入库完成 911作废 100订单池 200暂挂 400待合单 410待出库单出库 + queryOfsStockinOrderRequestVO.setPageNo(1L); + queryOfsStockinOrderRequestVO.setPageSize(500L); + List data = queryOfsStockinOrder(queryOfsStockinOrderRequestVO); + System.out.println(data); + + //过滤日志 + + //推送 + + + } catch (Exception e) { + logger.error("丽知:OFS调整入库--->U8C其它入库,start()方法报错:", e); + } + } + + /** + * 按单号 + */ + public void start(String stockinNo) { + try { + } catch (Exception e) { + logger.error("丽知:OFS调整入库--->U8C其它入库,start(String goodsName)方法报错:", e); + } + + } + + /** + * 按时间区间 + */ + public void start(String startTime, String endTime) { + try { + Date business_start = DateUtil.parse(startTime); + Date business_end = DateUtil.parse(endTime); + String start = DateUtil.format(business_start, "yyyy-MM-dd") + " 00:00:00"; + String end = DateUtil.format(business_end, "yyyy-MM-dd") + " 23:59:59"; + } catch (Exception e) { + logger.error("丽知:OFS调整入库--->U8C其它入库,start(String startTime, String endTime)方法报错:", e); + } + } + + + public List queryOfsStockinOrder(QueryOfsStockinOrderRequestVO queryOfsStockinOrderRequestVO) throws Exception { + InterfaceParamDto interfaceParamDto = new InterfaceParamDto(); + interfaceParamDto.setApi("ofs.receipt.search"); +// queryOfsStockinOrderRequestVO.setInternalInstructionType("ADJUST");//入库单类型 SALES销售 EXCHANGE换货 REISSUE补发RETURN销退 PURCHASE采购 PURCHASE_RETURN采退 TRANSFER调拨 WORK_ORDER加工 OTHER其他 ADJUST调整 EXCHANGE换货 + queryOfsStockinOrderRequestVO.setClientCode("LETS"); + interfaceParamDto.setData(JSON.toJSONString(queryOfsStockinOrderRequestVO)); + StockinOrderSearchResponse stockinOrderSearchResponse = (StockinOrderSearchResponse) ofsUnifiedService.unified(interfaceParamDto); + System.out.println(stockinOrderSearchResponse); + if(stockinOrderSearchResponse.getData()==null||stockinOrderSearchResponse.getData().size()==0){ + return null; + } + //过滤ADJUST调整 + List adjustList=new ArrayList<>(); + for (StockinOrderSearchResponse.StockinOrder datum : stockinOrderSearchResponse.getData()) { + StockinOrderSearchResponse.StockinOrder.StockinH header = datum.getHeader(); + if("ADJUST".equals(header.getInternalInstructionType())){ + adjustList.add(datum); + } + } + return adjustList; + } +} 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..3a9ff38d --- /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; + } + + +} diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/transfer/TransferOutPluginInitializer.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/transfer/TransferOutPluginInitializer.java new file mode 100644 index 00000000..f996f624 --- /dev/null +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/transfer/TransferOutPluginInitializer.java @@ -0,0 +1,158 @@ +package com.hzya.frame.plugin.lets.plugin.transfer; + +import cn.hutool.core.date.DateField; +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hzya.frame.base.PluginBaseEntity; +import com.hzya.frame.plugin.lets.ofsvo.QueryOfsStockinOrderRequestVO; +import com.hzya.frame.plugin.lets.util.PushDataByU8cUtil; +import com.hzya.frame.plugin.lets.util.SaveOrUpdateBusinessLogUtil; +import com.hzya.frame.sysnew.integtationTaskLivingDetails.dao.IIntegrationTaskLivingDetailsDao; +import com.hzya.frame.ttxofs.dto.InterfaceParamDto; +import com.hzya.frame.ttxofs.dto.stock.StockinOrderSearchResponse; +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.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.concurrent.locks.ReentrantLock; + +/** + * 丽知:OFS调拨出库订单--->U8C调拨出库单(保存签字) + */ +public class TransferOutPluginInitializer extends PluginBaseEntity { + Logger logger = LoggerFactory.getLogger(TransferOutPluginInitializer.class); + + private static final ReentrantLock LOCK = new ReentrantLock(true); + + @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.transfer.TransferOutPluginInitializer"; + } + + @Override + public String getPluginName() { + return "丽知:OFS调拨出库订单--->U8C调拨出库单(保存签字)"; + } + + @Override + public String getPluginLabel() { + return "丽知:OFS调拨出库订单--->U8C调拨出库单(保存签字)"; + } + + @Override + public String getPluginType() { + return "1"; + } + + @Autowired + private IIntegrationTaskLivingDetailsDao iIntegrationTaskLivingDetailsDao; + @Autowired + private PushDataByU8cUtil pushDataByU8cUtil; + @Autowired + private SaveOrUpdateBusinessLogUtil saveOrUpdateBusinessLogUtil; + + @Autowired + private OfsUnifiedService ofsUnifiedService; + + @Override + public JsonResultEntity executeBusiness(JSONObject requestJson) throws Exception { + return null; + } + + + /** + * 默认推送 + */ + public void start() { + try { + //获取当前时间 + Date currentDate = new Date(); + Date startTime = DateUtil.offset(currentDate, DateField.MINUTE, -10); + Date endTime = DateUtil.offset(currentDate, DateField.MINUTE, -2); + String startTimeStr = DateUtil.format(startTime, "yyyy-MM-dd HH:mm:ss"); + String endTimeStr = DateUtil.format(endTime, "yyyy-MM-dd HH:mm:ss"); + + QueryOfsStockinOrderRequestVO queryOfsStockinOrderRequestVO = new QueryOfsStockinOrderRequestVO(); + queryOfsStockinOrderRequestVO.setCreated_start("2024-08-05 00:00:00"); + queryOfsStockinOrderRequestVO.setCreated_end("2024-08-09 23:59:59"); + queryOfsStockinOrderRequestVO.setCompanyCode("SHXM"); +// queryOfsTransferOrderRequestVO.setStatus("900");//状态 500待同步 510已同步 700收货中 900入库完成 911作废 100订单池 200暂挂 400待合单 410待出库单出库 + queryOfsStockinOrderRequestVO.setPageNo(1L); + queryOfsStockinOrderRequestVO.setPageSize(500L); + List data = queryOfsStockinOrder(queryOfsStockinOrderRequestVO); + System.out.println(data); + + //过滤日志 + + //推送 + + + } catch (Exception e) { + logger.error("丽知:OFS调拨出库订单--->U8C调拨出库单(保存签字),start()方法报错:", e); + } + } + + /** + * 按单号 + */ + public void start(String stockinNo) { + try { + } catch (Exception e) { + logger.error("丽知:OFS调拨出库订单--->U8C调拨出库单(保存签字),start(String goodsName)方法报错:", e); + } + + } + + /** + * 按时间区间 + */ + public void start(String startTime, String endTime) { + try { + Date business_start = DateUtil.parse(startTime); + Date business_end = DateUtil.parse(endTime); + String start = DateUtil.format(business_start, "yyyy-MM-dd") + " 00:00:00"; + String end = DateUtil.format(business_end, "yyyy-MM-dd") + " 23:59:59"; + } catch (Exception e) { + logger.error("丽知:OFS调拨出库订单--->U8C调拨出库单(保存签字),start(String startTime, String endTime)方法报错:", e); + } + } + + + public List queryOfsStockinOrder(QueryOfsStockinOrderRequestVO queryOfsStockinOrderRequestVO) throws Exception { + InterfaceParamDto interfaceParamDto = new InterfaceParamDto(); + interfaceParamDto.setApi("ofs.shipment.search"); + queryOfsStockinOrderRequestVO.setInternalInstructionType("TRANSFER");//入库单类型 SALES销售 EXCHANGE换货 REISSUE补发RETURN销退 PURCHASE采购 PURCHASE_RETURN采退 TRANSFER调拨 WORK_ORDER加工 OTHER其他 ADJUST调整 EXCHANGE换货 + queryOfsStockinOrderRequestVO.setClientCode("LETS"); + interfaceParamDto.setData(JSON.toJSONString(queryOfsStockinOrderRequestVO)); + StockinOrderSearchResponse stockinOrderSearchResponse = (StockinOrderSearchResponse) ofsUnifiedService.unified(interfaceParamDto); + System.out.println(stockinOrderSearchResponse); + if(stockinOrderSearchResponse.getData()==null||stockinOrderSearchResponse.getData().size()==0){ + return null; + } + //过滤ADJUST调整 + List adjustList=new ArrayList<>(); + for (StockinOrderSearchResponse.StockinOrder datum : stockinOrderSearchResponse.getData()) { + StockinOrderSearchResponse.StockinOrder.StockinH header = datum.getHeader(); + if("ADJUST".equals(header.getInternalInstructionType())){ + adjustList.add(datum); + } + } + return adjustList; + } +} 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/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/dto/ofsBaseSearch/OFSGoodsSearchResponse.java b/service/src/main/java/com/hzya/frame/ttxofs/dto/ofsBaseSearch/OFSGoodsSearchResponse.java new file mode 100644 index 00000000..91f871a2 --- /dev/null +++ b/service/src/main/java/com/hzya/frame/ttxofs/dto/ofsBaseSearch/OFSGoodsSearchResponse.java @@ -0,0 +1,10 @@ +package com.hzya.frame.ttxofs.dto.ofsBaseSearch; + +import lombok.Data; + +/** + * OFS SKU查询返回 + */ +@Data +public class OFSGoodsSearchResponse { +}