refactor(sales): 优化销售出库插件初始化逻辑

- 重构`startImplementByCode`方法,引入`sceneType`参数支持不同业务场景。
- 直接在`SoSaleOutPluginInitializerToB`中使用新的`getSetStock`和`getSetStockTran`方法,根据`sceneType`区分库存和转运场景。- 移除未使用的`findMatchingOfsOrder`方法,清理代码。
- 测试代码中添加了对新方法的调用示例,但实际测试逻辑未展开。

计划将`sceneType`参数传递到相关方法中,以支持后续的业务逻辑区分。
This commit is contained in:
liuy 2024-09-12 13:49:24 +08:00
parent 668c85eb0b
commit d6c492979a
2 changed files with 67 additions and 44 deletions

View File

@ -112,8 +112,10 @@ public class SoSaleOutPluginInitializerToB extends PluginBaseEntity {
String sceneType = String.valueOf(requestJson.get("sceneType"));//sceneTypestocktran
if (ProfilesActiveConstant.TYPE_VBILLCODE.equals(requestJson.get("type"))) {
//按单号
Assert.notNull(sceneType, "sceneType参数不能为空");
Assert.notNull(!"".equals(sceneType), "sceneType参数不能为空");
if (param != null && !"".equals(param)) {
startImplementByCode(param);
startImplementByCode(param, sceneType);
}
} else if (ProfilesActiveConstant.TYPE_TIME_FRAME.equals(requestJson.get("type"))) {
//前台页面功能日期推送或者接口调用也行
@ -128,7 +130,7 @@ public class SoSaleOutPluginInitializerToB extends PluginBaseEntity {
//实时执行每1分钟调度一次
StartAndEndVo startAndEndVo = offsetTimeTime.offsetTime();
startImplementByStockTime(startAndEndVo.getStart_time(), startAndEndVo.getEnd_time());
// startImplementByTranTime(startAndEndVo.getStart_time(), startAndEndVo.getEnd_time());
startImplementByTranTime(startAndEndVo.getStart_time(), startAndEndVo.getEnd_time());
}
}
} catch (Exception e) {
@ -316,7 +318,7 @@ public class SoSaleOutPluginInitializerToB extends PluginBaseEntity {
*
* @author liuyang
*/
public void startImplementByCode(String code) {
public void startImplementByCode(String code, String sceneType) {
long startMillis = System.currentTimeMillis();
String threadNameStrStart = StrUtil.format("OFS销售出库(TOB)同步U8C销售订单开始 出库单单号:{}", code);
logger.info(threadNameStrStart);
@ -342,7 +344,11 @@ public class SoSaleOutPluginInitializerToB extends PluginBaseEntity {
ofsStandardUtil.queryOfsSaleOrder(queryOfsSoSaleOutVo, headerDetailsDtoList, 1L, "ofs.shipment.search");
logger.info("根据单据号查询:数据返回行数:{}", headerDetailsDtoList.size());
if (headerDetailsDtoList.size() > 0) {
getSetStock(headerDetailsDtoList);
if (sceneType.equals("stock")) {
getSetStock(headerDetailsDtoList);
} else if (sceneType.equals("tran")) {
getSetStockTran(headerDetailsDtoList);
}
} else {
logger.info("没有查询到任何数据!不需要同步");
}
@ -884,6 +890,8 @@ public class SoSaleOutPluginInitializerToB extends PluginBaseEntity {
* @author liuyang
*/
private String createSuccessFulTradeDate(OrderOutTobHeaderDto orderOutTobHeaderDto) throws Exception {
//测试
// orderOutTobHeaderDto.getHeader().setTradeSuccessAt("2024-09-12");
if (orderOutTobHeaderDto != null && orderOutTobHeaderDto.getHeader() != null && orderOutTobHeaderDto.getHeader().getTradeSuccessAt() != null) {
HeaderDto header = orderOutTobHeaderDto.getHeader();
String shipAt = header.getTradeSuccessAt();
@ -945,8 +953,8 @@ public class SoSaleOutPluginInitializerToB extends PluginBaseEntity {
}
com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDto header1 = saleOrderMessageDto.getData().get(0).getHeader();
String memberId = header1.getMemberId();
//TODO 测试
memberId = "hzz";
//测试
// memberId = "hzz";
Assert.notNull(memberId, "TOB销售订单(OFS)表头会员id不能为空否则无法匹配U8C客商档案");
Assert.state(!"".equals(memberId.trim()), "TOB销售订单(OFS)表头会员id不能为空否则无法匹配U8C客商档案");
@ -1396,17 +1404,6 @@ public class SoSaleOutPluginInitializerToB extends PluginBaseEntity {
List<DetailsDto> details = headerDetailsDto.getDetails();
try {
com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto headerDetailsDto1 = header.getHeaderDetailsDto();
com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDto header2 = headerDetailsDto1.getHeader();
//如果没有O单据名称则默认为销售
if (header2.getSubOrderType() == null || "".equals(header2.getSubOrderType().trim())) {
header2.setSubOrderType("SALES");
}
//查询对应的收发类别
BdRdclEntity bdRdclEntity = rdclUtil.queryRdClObject(header2.getSubOrderType());
Assert.notNull(bdRdclEntity, "根据收发类别编码:{} 无法匹配到U8C收发类别");
//根据OFS销售出库单查询得到OFS销售订单
SaleOrderMessageDto saleOrderMessageDto = null;
try {
@ -1421,9 +1418,22 @@ public class SoSaleOutPluginInitializerToB extends PluginBaseEntity {
com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDto header1 = saleOrderMessageDto.getData().get(0).getHeader();
String memberId = header1.getMemberId();
// 测试
// memberId = "hzz";
Assert.notNull(memberId, "TOB销售订单(OFS)表头会员id不能为空否则无法匹配U8C客商档案");
Assert.state(!"".equals(memberId.trim()), "TOB销售订单(OFS)表头会员id不能为空否则无法匹配U8C客商档案");
// com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto headerDetailsDto1 = header.getHeaderDetailsDto();
// com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDto header2 = headerDetailsDto1.getHeader();
//如果没有O单据名称则默认为销售
if (header1.getSubOrderType() == null || "".equals(header1.getSubOrderType().trim())) {
header1.setSubOrderType("SALES");
}
//查询对应的收发类别
BdRdclEntity bdRdclEntity = rdclUtil.queryRdClObject(header1.getSubOrderType());
Assert.notNull(bdRdclEntity, "根据收发类别编码:{} 无法匹配到U8C收发类别");
//2024年8月28日 11:01:07 查询对应的U8C销售订单
SoSaleEntity soSaleEntity = new SoSaleEntity();
soSaleEntity.setDr(0L);
@ -1446,8 +1456,6 @@ public class SoSaleOutPluginInitializerToB extends PluginBaseEntity {
List<SoSaleorderBEntity> soSaleorderBEntityList = iSoSaleorderBDao.query(soSaleorderBEntity);
if (soSaleorderBEntityList == null || soSaleorderBEntityList.size() == 0) {
Assert.state(false, "根据O销售订单主键{}无法匹配到U8C销售订单明细行(传到U8C可能失败了)", soSaleEntityList.get(soSaleEntityList.size() - 1).getCsaleid());
} else if (soSaleorderBEntityList.size() >= 2) {
Assert.state(false, "根据O销售订单主键{}无法匹配到U8C销售订单明细行(传到U8C可能失败了)", soSaleEntityList.get(soSaleEntityList.size() - 1).getCsaleid());
}
//查询U8C销售订单对应的销售出库单表头
@ -1631,6 +1639,7 @@ public class SoSaleOutPluginInitializerToB extends PluginBaseEntity {
orderOutTobHeaderDto.setIcGeneralBEntityList(icGeneralBEntityList);
orderOutTobHeaderDto.setSoSaleorderBEntityList(soSaleorderBEntityList);
orderOutTobHeaderDto.setExtIntegrationTaskLivingDetailsQueryVos(extIntegrationTaskLivingDetailsQueryVos);
orderOutTobHeaderDto.setBdRdclEntity(bdRdclEntity);
orderOutTobHeaderDto.setHeader(header);
orderOutTobHeaderDto.setDetails(details);
@ -1779,8 +1788,9 @@ public class SoSaleOutPluginInitializerToB extends PluginBaseEntity {
Assert.state(false, "含税单价金额计算失败 原因:{}", e.getMessage());
}
//判断是否为赠品
Boolean isblargessflag = false;
if (noriginalcurtaxprice == null) {
if (noriginalcurtaxprice.longValue() == 0) {
isblargessflag = true;
}
@ -2477,27 +2487,27 @@ public class SoSaleOutPluginInitializerToB extends PluginBaseEntity {
* @param ofsSaleOutOrder ofs销售出库单集合
* @author liuyang
*/
private void findMatchingOfsOrder(List<com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto> ofsSaleOrder, List<com.hzya.frame.ttxofs.dto.ofssaleorderoutsearch.HeaderDetailsDto> ofsSaleOutOrder) throws Exception {
if (ofsSaleOrder != null && ofsSaleOutOrder != null && ofsSaleOrder.size() > 0 && ofsSaleOutOrder.size() > 0) {
try {
for (int i = 0; i < ofsSaleOutOrder.size(); i++) {
HeaderDetailsDto headerDetailsDto = ofsSaleOutOrder.get(i);
HeaderDto header = headerDetailsDto.getHeader();
List<DetailsDto> details = headerDetailsDto.getDetails();
String targetRefOrderCode = header.getRefOrderCode();
for (int j = 0; j < ofsSaleOrder.size(); j++) {
com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto headerDetailsDto1 = ofsSaleOrder.get(j);
com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDto header1 = headerDetailsDto1.getHeader();
List<com.hzya.frame.ttxofs.dto.ofssalesordersearch.DetailsDto> details1 = headerDetailsDto1.getDetails();
if (header1.getCode().equals(targetRefOrderCode)) {
header.setHeaderDetailsDto(headerDetailsDto1);
}
}
}
} catch (Exception e) {
logger.error("findMatchingOfsOrder方法抛出异常", e);
}
}
}
// private void findMatchingOfsOrder(List<com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto> ofsSaleOrder, List<com.hzya.frame.ttxofs.dto.ofssaleorderoutsearch.HeaderDetailsDto> ofsSaleOutOrder) throws Exception {
// if (ofsSaleOrder != null && ofsSaleOutOrder != null && ofsSaleOrder.size() > 0 && ofsSaleOutOrder.size() > 0) {
// try {
// for (int i = 0; i < ofsSaleOutOrder.size(); i++) {
// HeaderDetailsDto headerDetailsDto = ofsSaleOutOrder.get(i);
// HeaderDto header = headerDetailsDto.getHeader();
// List<DetailsDto> details = headerDetailsDto.getDetails();
//
// String targetRefOrderCode = header.getRefOrderCode();
// for (int j = 0; j < ofsSaleOrder.size(); j++) {
// com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto headerDetailsDto1 = ofsSaleOrder.get(j);
// com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDto header1 = headerDetailsDto1.getHeader();
// List<com.hzya.frame.ttxofs.dto.ofssalesordersearch.DetailsDto> details1 = headerDetailsDto1.getDetails();
// if (header1.getCode().equals(targetRefOrderCode)) {
// header.setHeaderDetailsDto(headerDetailsDto1);
// }
// }
// }
// } catch (Exception e) {
// logger.error("findMatchingOfsOrder方法抛出异常", e);
// }
// }
// }
}

View File

@ -2,6 +2,8 @@ package com.hzya.frame.plugin.lets.plugin.sales;
import com.hzya.frame.WebappApplication;
import com.hzya.frame.plugin.lets.util.AfterSalesOrderUtil;
import com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto;
import com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDto;
import com.hzya.frame.ttxofs.dto.ofssalesordersearch.SaleOrderMessageDto;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -9,6 +11,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
import static org.junit.Assert.*;
/**
@ -45,6 +49,15 @@ public class SoSaleOutPluginInitializerToBTest {
// soSaleOutPluginInitializerToB.startImplementByTranTime("2024-08-28 15:28:06", "2024-08-28 15:28:08");
soSaleOutPluginInitializerToB.startImplementByCode("LETS-SH2024080100006222");
// soSaleOutPluginInitializerToB.startImplementByCode("LETS-SH2024080100006222");
// try {
// SaleOrderMessageDto saleOrderMessageDto = afterSalesOrderUtil.getOfsOrder("LETS-SO2022080500002332");
// List<HeaderDetailsDto> data = saleOrderMessageDto.getData();
// HeaderDto header = data.get(0).getHeader();
// System.out.println(header.getSubOrderType());
// } catch (Exception e) {
// e.printStackTrace();
// }
}
}