丽知:新增ofs调整入库(组装)推送u8c组装单。

This commit is contained in:
zhengyf 2024-09-10 16:01:24 +08:00
parent 72db1447fe
commit bcffc0fa5f
3 changed files with 433 additions and 3 deletions

View File

@ -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<StockinOrderSearchResponse.StockinOrder> stockinOrders = queryOfsStockinOrder(queryOfsStockinOrderRequestVO);
System.out.println(stockinOrders);
if (stockinOrders.size() == 0) {
return;
}
//过滤日志
List<StockinOrderSearchResponse.StockinOrder> 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<StockinOrderSearchResponse.StockinOrder> stockinOrders = queryOfsStockinOrder(queryOfsStockinOrderRequestVO);
System.out.println(stockinOrders);
if (stockinOrders.size() == 0) {
Assert.state(false, "丽知OFS调整入库(组装入库)--->U8C组装订单根据单据号[入库完成]{},未查询到调整出库单", stockinNo);
}
//过滤日志
List<StockinOrderSearchResponse.StockinOrder> 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<StockinOrderSearchResponse.StockinOrder> stockinOrders = queryOfsStockinOrder(queryOfsStockinOrderRequestVO);
System.out.println(stockinOrders);
if (stockinOrders.size() == 0) {
Assert.state(false, "丽知OFS调整入库(组装入库)--->U8C组装订单根据日期期间[开始时间]-[结束时间]{}-{},未查询到调整入库单[入库完成]", startTime, endTime);
}
//过滤日志
List<StockinOrderSearchResponse.StockinOrder> 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<StockinOrderSearchResponse.StockinOrder> filterData(List<StockinOrderSearchResponse.StockinOrder> stockinOrders) throws Exception {
List<StockinOrderSearchResponse.StockinOrder> filterStockinOrders = new ArrayList<>();
for (StockinOrderSearchResponse.StockinOrder stockinOrder : stockinOrders) {
StockinOrderSearchResponse.StockinOrder.StockinH header = stockinOrder.getHeader();
//cdispatcherid--收发类别,
List<OFSAdjustOrderSearchResponse.OFSAdjustOrder> 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<IntegrationTaskLivingDetailsEntity> 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<StockinOrderSearchResponse.StockinOrder> 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<StockinOrderSearchResponse.StockinOrder> queryOfsStockinOrder(QueryOfsStockinOrderRequestVO queryOfsStockinOrderRequestVO) throws Exception {
Long pageNo = 1L;
List<StockinOrderSearchResponse.StockinOrder> 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<OFSAdjustOrderSearchResponse.OFSAdjustOrder> 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<OFSAdjustOrderSearchResponse.OFSAdjustOrder> data = ofsAdjustOrderSearchResponse.getData();
return data;
}
}

View File

@ -55,4 +55,7 @@
<bean name="bdBomDao" class="com.hzya.frame.plugin.lets.dao.impl.BdBomDaoImpl"/>
<!--ia_monthledger 存货总账月记录表-->
<bean name="iaMonthledgerDao" class="com.hzya.frame.plugin.lets.dao.impl.IaMonthledgerDaoImpl"/>
<bean name="scOrderBDao" class="com.hzya.frame.plugin.lets.dao.impl.ScOrderBDaoImpl"/>
<bean name="scOrderDao" class="com.hzya.frame.plugin.lets.dao.impl.ScOrderDaoImpl"/>
</beans>

View File

@ -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");
}
}