From bcffc0fa5f2148f0711ef8ad5d73aff424cfe3d7 Mon Sep 17 00:00:00 2001 From: zhengyf Date: Tue, 10 Sep 2024 16:01:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BD=E7=9F=A5=EF=BC=9A=E6=96=B0=E5=A2=9Eof?= =?UTF-8?q?s=E8=B0=83=E6=95=B4=E5=85=A5=E5=BA=93=EF=BC=88=E7=BB=84?= =?UTF-8?q?=E8=A3=85=EF=BC=89=E6=8E=A8=E9=80=81u8c=E7=BB=84=E8=A3=85?= =?UTF-8?q?=E5=8D=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adjust/AdjustInZZPluginInitializer.java | 419 ++++++++++++++++++ .../plugin/lets/spring/spring-lets-dao.xml | 3 + .../plugin/lets/plugin/base/BaseTest.java | 14 +- 3 files changed, 433 insertions(+), 3 deletions(-) create mode 100644 buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/adjust/AdjustInZZPluginInitializer.java diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/adjust/AdjustInZZPluginInitializer.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/adjust/AdjustInZZPluginInitializer.java new file mode 100644 index 00000000..55b69126 --- /dev/null +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/adjust/AdjustInZZPluginInitializer.java @@ -0,0 +1,419 @@ +package com.hzya.frame.plugin.lets.plugin.adjust; + +import cn.hutool.core.date.DateField; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.lang.Assert; +import cn.hutool.json.JSONUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hzya.frame.base.PluginBaseEntity; +import com.hzya.frame.plugin.lets.constant.OverallConstant; +import com.hzya.frame.plugin.lets.constant.ProfilesActiveConstant; +import com.hzya.frame.plugin.lets.dao.IBdRdclDao; +import com.hzya.frame.plugin.lets.ofsvo.QueryOfsAdjustOrderRequestVO; +import com.hzya.frame.plugin.lets.ofsvo.QueryOfsStockinOrderRequestVO; +import com.hzya.frame.plugin.lets.u8cdto.GeneralBillVO_4ADto; +import com.hzya.frame.plugin.lets.u8cdto.ReusltStrDto; +import com.hzya.frame.plugin.lets.util.PushDataByU8cUtil; +import com.hzya.frame.plugin.lets.util.SaveOrUpdateBusinessLogUtil; +import com.hzya.frame.plugin.lets.util.pushData.Attribute; +import com.hzya.frame.plugin.lets.util.pushData.PushU8CByApiCode; +import com.hzya.frame.plugin.lets.util.pushData.ZTResult; +import com.hzya.frame.sysnew.integtationTaskLivingDetails.dao.IIntegrationTaskLivingDetailsDao; +import com.hzya.frame.sysnew.integtationTaskLivingDetails.entity.IntegrationTaskLivingDetailsEntity; +import com.hzya.frame.ttxofs.dto.InterfaceParamDto; +import com.hzya.frame.ttxofs.dto.ofsTransferOrderSearch.OFSAdjustOrderSearchResponse; +import com.hzya.frame.ttxofs.dto.stock.StockinOrderSearchResponse; +import com.hzya.frame.ttxofs.service.OfsUnifiedService; +import com.hzya.frame.web.entity.JsonResultEntity; +import org.apache.commons.lang3.StringUtils; +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 AdjustInZZPluginInitializer extends PluginBaseEntity { + Logger logger = LoggerFactory.getLogger(AdjustInZZPluginInitializer.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 "adjust.AdjustInZZPluginInitializer"; + } + + @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 PushU8CByApiCode pushU8CByApiCode; + @Autowired + private SaveOrUpdateBusinessLogUtil saveOrUpdateBusinessLogUtil; + + @Autowired + private OfsUnifiedService ofsUnifiedService; + + @Autowired + private IBdRdclDao iBdRdclDao; + + @Override + public JsonResultEntity executeBusiness(JSONObject requestJson) throws Exception { + try { + logger.info("调用:" + getPluginName() + "-插件"); + String prod = "prod"; + String param = String.valueOf(requestJson.get("param")); + if (requestJson != null && ProfilesActiveConstant.TYPE_DATE.equals(requestJson.get("type"))) { + //按日期 + if (param != null && !"".equals(param)) { + String[] split = param.split("/"); + if (!(split.length == 2)) { + Assert.state(false, "时间格式传递不正确"); + } + Assert.notNull(split[0], "开始时间不能为空"); + Assert.notNull(split[1], "结束时间不能为空"); + start(split[0], split[1]); + } + } else if (requestJson != null && ProfilesActiveConstant.TYPE_VBILLCODE.equals(requestJson.get("type"))) { + //按单号 + if (param != null && !"".equals(param)) { + start(param); + } + } else if (ProfilesActiveConstant.TYPE_DETAIL_ERROR.equals(requestJson.get("type"))) { + String integrationTaskLivingDetails = (String) requestJson.get("integration_task_living_details_id"); + IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = saveOrUpdateBusinessLogUtil.queryIntegrationTaskLivingDetailsEntity(integrationTaskLivingDetails); + start(integrationTaskLivingDetailsEntity.getRootAppPk()); + } else if (ProfilesActiveConstant.LETS_PROFILES_ACTIVE.equals(prod)) { + //默认 + start(); + } + } catch (Exception e) { + e.printStackTrace(); + logger.error("executeBusiness方法抛出异常", e); + } + 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(startTimeStr); + queryOfsStockinOrderRequestVO.setCreated_end(endTimeStr); + List stockinOrders = queryOfsStockinOrder(queryOfsStockinOrderRequestVO); + System.out.println(stockinOrders); + + if (stockinOrders.size() == 0) { + return; + } + //过滤日志 + List filterStockinOrders = filterData(stockinOrders); + if (filterStockinOrders.size() == 0) { + return; + } + + //推送 + implement(filterStockinOrders); + + + } catch (Exception e) { + logger.error("丽知:OFS调整入库(组装入库)--->U8C组装订单,start()方法报错:", e); + } + } + + /** + * 按单号 + */ + public void start(String stockinNo) { + try { + + QueryOfsStockinOrderRequestVO queryOfsStockinOrderRequestVO = new QueryOfsStockinOrderRequestVO(); + queryOfsStockinOrderRequestVO.setCode(stockinNo); + List stockinOrders = queryOfsStockinOrder(queryOfsStockinOrderRequestVO); + System.out.println(stockinOrders); + + if (stockinOrders.size() == 0) { + Assert.state(false, "丽知:OFS调整入库(组装入库)--->U8C组装订单根据单据号[入库完成]:{},未查询到调整出库单", stockinNo); + } + //过滤日志 + List filterStockinOrders = filterData(stockinOrders); + if (filterStockinOrders.size() == 0) { + Assert.state(false, "丽知:OFS调整入库(组装入库)--->U8C组装订单根据单据号[入库完成]:{},该调整出库单已被推送成功,请勿重新推送", stockinNo); + } + + //推送 + implement(filterStockinOrders); + + } 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"; + + QueryOfsStockinOrderRequestVO queryOfsStockinOrderRequestVO = new QueryOfsStockinOrderRequestVO(); + queryOfsStockinOrderRequestVO.setClosedAt_start(start); + queryOfsStockinOrderRequestVO.setClosedAt_end(end); + List stockinOrders = queryOfsStockinOrder(queryOfsStockinOrderRequestVO); + System.out.println(stockinOrders); + + if (stockinOrders.size() == 0) { + Assert.state(false, "丽知:OFS调整入库(组装入库)--->U8C组装订单根据日期期间[开始时间]-[结束时间]:{}-{},未查询到调整入库单[入库完成]", startTime, endTime); + } + //过滤日志 + List filterStockinOrders = filterData(stockinOrders); + if (filterStockinOrders.size() == 0) { + Assert.state(false, "丽知:OFS调整入库(组装入库)--->U8C组装订单根据日期期间[开始时间]-[结束时间]:{}-{},该调期间整入库单[入库完成]已被推送成功,请勿重新推送", startTime, endTime); + } + + //推送 + implement(filterStockinOrders); + + + } catch (Exception e) { + logger.error("丽知:OFS调整入库(组装入库)--->U8C组装订单,start(String startTime, String endTime)方法报错:", e); + } + } + + /** + * 过滤成功日志 + * + * @return + */ + public List filterData(List stockinOrders) throws Exception { + List filterStockinOrders = new ArrayList<>(); + for (StockinOrderSearchResponse.StockinOrder stockinOrder : stockinOrders) { + StockinOrderSearchResponse.StockinOrder.StockinH header = stockinOrder.getHeader(); + + //cdispatcherid--收发类别, + List ofsAdjustOrders = queryOfsAdjustOrders(header.getRefOrderCode()); + + + + String rootAppPk = header.getCode(); + boolean isExis = true; + IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = new IntegrationTaskLivingDetailsEntity(); + integrationTaskLivingDetailsEntity.setRootAppPk(rootAppPk); + integrationTaskLivingDetailsEntity.setNewState(ProfilesActiveConstant.LOG_STATUS_Y); + integrationTaskLivingDetailsEntity.setPluginId(getPluginId()); + List integrationTaskLivingDetailsEntities = iIntegrationTaskLivingDetailsDao.query(integrationTaskLivingDetailsEntity); + if (integrationTaskLivingDetailsEntities == null || integrationTaskLivingDetailsEntities.size() == 0) { + isExis = false; + } + if (!isExis) { + filterStockinOrders.add(stockinOrder); + } + } + return filterStockinOrders; + } + + /** + * 推送U8C其它入库单 + * + * @param filterStockinOrders + */ + public void implement(List filterStockinOrders) { + for (StockinOrderSearchResponse.StockinOrder stockinOrder : filterStockinOrders) { + String mapStr = ""; + String format = ""; + String response = ""; + String ofsCode = ""; + try { + //主表 + + + + + + + + +// String dataJson = JSONUtil.toJsonStr(generalBillVO_4A); +// mapStr = "{\"GeneralBillVO_4A\":[" + dataJson + "]}"; + + //推送 +// ZTResult ztResult = pushU8CByApiCode.pushByCode(OverallConstant.getOverAllValue("otherinqzCode"), mapStr); +// +// //两层判断,一层中台转发,一层u8c返回 +// if ("false".equals(ztResult.getFlag())) { +// //转发失败 +// response = JSONUtil.toJsonStr(ztResult.getAttribute()); +// Assert.state(false, "丽知:OFS调整入库(组装入库)--->U8C组装订单.中台转发失败,失败原因:{}", ztResult.getAttribute()); +// } +// Attribute attribute = ztResult.getAttribute(); +// System.out.println(attribute); +// +// boolean isSuccess = false; +// String vbillcode = ""; +// if ("success".equals(attribute.getStatus())) { +// isSuccess = true; +// String data = attribute.getData(); +// GeneralBillVO_4ADto resGeneralBillVO = resultDataHandle(data); +// System.out.println(resGeneralBillVO); +// vbillcode = resGeneralBillVO.getParentvo().getVbillcode(); +// } +// if (!isSuccess) { +// Assert.state(false, "推送U8C--> 丽知:OFS调整入库(组装入库)--->U8C组装订单 失败 接口返回结果:{} 接口入参:{}", response, mapStr); +// } + + //成功 +// IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = new IntegrationTaskLivingDetailsEntity(); +// integrationTaskLivingDetailsEntity.setNewState(ProfilesActiveConstant.LOG_STATUS_Y); +// integrationTaskLivingDetailsEntity.setRootAppNewData(mapStr); +// integrationTaskLivingDetailsEntity.setNewTransmitInfo(response); +// integrationTaskLivingDetailsEntity.setNewPushDate(new Date()); +// integrationTaskLivingDetailsEntity.setBusinessDate(format); +// integrationTaskLivingDetailsEntity.setRootAppPk(ofsCode); +// integrationTaskLivingDetailsEntity.setRootAppBill(ofsCode); +// integrationTaskLivingDetailsEntity.setRootAppBill(vbillcode); +// integrationTaskLivingDetailsEntity.setDef1(vbillcode); +// integrationTaskLivingDetailsEntity.setPluginId(getPluginId()); +// saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity); + + } catch (Exception e) { + e.printStackTrace(); +// logger.error("推送U8C,丽知:OFS调整入库(组装入库)--->U8C组装订单失败,失败原因:" + e); +// +// ReusltStrDto reusltStrDto = JSON.parseObject(response, ReusltStrDto.class); +// +// String ErrMessage = "推送U8C,丽知:OFS调整入库(组装入库)--->U8C组装订单失败,失败原因:" + reusltStrDto.getErrormsg(); +// //失败 +// IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = new IntegrationTaskLivingDetailsEntity(); +// integrationTaskLivingDetailsEntity.setNewState(ProfilesActiveConstant.LOG_STATUS_N); +// integrationTaskLivingDetailsEntity.setRootAppNewData(mapStr); +// integrationTaskLivingDetailsEntity.setNewTransmitInfo(ErrMessage); +// integrationTaskLivingDetailsEntity.setNewPushDate(new Date()); +// integrationTaskLivingDetailsEntity.setBusinessDate(format); +// integrationTaskLivingDetailsEntity.setRootAppPk(ofsCode); +// integrationTaskLivingDetailsEntity.setRootAppBill(ofsCode); +// integrationTaskLivingDetailsEntity.setPluginId(getPluginId()); +// saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity); + } + } + } + + + public List queryOfsStockinOrder(QueryOfsStockinOrderRequestVO queryOfsStockinOrderRequestVO) throws Exception { + Long pageNo = 1L; + List all = new ArrayList<>(); + + + 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"); + queryOfsStockinOrderRequestVO.setStatus("900");//状态 500待同步 510已同步 700收货中 900入库完成 911作废 100订单池 200暂挂 400待合单 410待出库单出库 + queryOfsStockinOrderRequestVO.setPageNo(pageNo); + queryOfsStockinOrderRequestVO.setPageSize(500L); + interfaceParamDto.setData(JSON.toJSONString(queryOfsStockinOrderRequestVO)); + StockinOrderSearchResponse stockinOrderSearchResponse = (StockinOrderSearchResponse) ofsUnifiedService.unified(interfaceParamDto); + if (stockinOrderSearchResponse.getData() == null || stockinOrderSearchResponse.getData().size() == 0) { + return null; + } + + all.addAll(stockinOrderSearchResponse.getData()); + int count = stockinOrderSearchResponse.getData().size(); + while (count >= 500) {//>=500,可能还有下一页。 + //还有下一页 + pageNo++; + queryOfsStockinOrderRequestVO.setPageNo(pageNo); + interfaceParamDto.setData(JSON.toJSONString(queryOfsStockinOrderRequestVO)); + StockinOrderSearchResponse stockinOrderSearchResponse1 = (StockinOrderSearchResponse) ofsUnifiedService.unified(interfaceParamDto); + + all.addAll(stockinOrderSearchResponse1.getData()); + + count = stockinOrderSearchResponse1.getData().size(); + } + return all; + } + + + private GeneralBillVO_4ADto resultDataHandle(String resultData) { + try { + if (resultData != null && !"".equals(resultData)) { + if (resultData.contains("[")) { + resultData = resultData.substring(1, resultData.length() - 1); + } + return JSON.parseObject(resultData, GeneralBillVO_4ADto.class); + } + } catch (Exception e) { + e.printStackTrace(); + logger.error("解析返回参数失败的错误", e); + //如果解析失败,记录原因,但是不能影响结果的记录 + } + return null; + } + + /** + * ofs调整单查询 + * ofs. adjustOrder.search + */ + public List queryOfsAdjustOrders(String ofsAdjustCode) throws Exception { + QueryOfsAdjustOrderRequestVO queryOfsAdjustOrderRequestVO = new QueryOfsAdjustOrderRequestVO(); + queryOfsAdjustOrderRequestVO.setClientCode("LETS"); + queryOfsAdjustOrderRequestVO.setCode(ofsAdjustCode); + queryOfsAdjustOrderRequestVO.setPageNo(1L); + queryOfsAdjustOrderRequestVO.setPageSize(500L); + + InterfaceParamDto interfaceParamDto = new InterfaceParamDto(); + interfaceParamDto.setApi("ofs.adjustOrder.search"); + interfaceParamDto.setData(JSON.toJSONString(queryOfsAdjustOrderRequestVO)); + OFSAdjustOrderSearchResponse ofsAdjustOrderSearchResponse = (OFSAdjustOrderSearchResponse) ofsUnifiedService.unified(interfaceParamDto); + System.out.println(ofsAdjustOrderSearchResponse); + List data = ofsAdjustOrderSearchResponse.getData(); + return data; + } +} diff --git a/buildpackage/src/main/resources/cfgHome/plugin/lets/spring/spring-lets-dao.xml b/buildpackage/src/main/resources/cfgHome/plugin/lets/spring/spring-lets-dao.xml index 79b1a627..35e8602a 100644 --- a/buildpackage/src/main/resources/cfgHome/plugin/lets/spring/spring-lets-dao.xml +++ b/buildpackage/src/main/resources/cfgHome/plugin/lets/spring/spring-lets-dao.xml @@ -55,4 +55,7 @@ + + + \ No newline at end of file diff --git a/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/base/BaseTest.java b/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/base/BaseTest.java index 7dcdf0eb..279e3cee 100644 --- a/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/base/BaseTest.java +++ b/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/base/BaseTest.java @@ -19,6 +19,8 @@ public class BaseTest { private SKUClassPluginInitializer skuClassPluginInitializer; @Autowired private GoodsAutoAllotPluginInitializer goodsAutoAllotPluginInitializer; + @Autowired + private KitPluginInitializer kitPluginInitializer; ////////////////////////////////////////////////////////////////////////////////////SKU @Test @@ -27,7 +29,7 @@ public class BaseTest { } @Test public void t01(){ - skuPluginInitializer.start("6971229882248"); + skuPluginInitializer.start("test0717001"); } @Test public void t02(){ @@ -42,11 +44,11 @@ public class BaseTest { ////////////////////////////////////////////////////////////////////////////////////SKU自动分配 @Test public void t10(){ - goodsAutoAllotPluginInitializer.start("6973391735469"); + goodsAutoAllotPluginInitializer.start("test0717001"); } @Test public void t11(){ - goodsAutoAllotPluginInitializer.start("2024-09-09","2024-09-09"); + goodsAutoAllotPluginInitializer.start("2024-09-10","2024-09-10"); } ////////////////////////////////////////////////////////////////////////////////////SKU分类 @Test @@ -62,5 +64,11 @@ public class BaseTest { skuClassPluginInitializer.start("2024-08-23","2024-08-29"); } + /////////////////////////////////////////////////////////////////////////////////////实物组套 + @Test + public void t30(){ + kitPluginInitializer.start("test0717001"); + } + }