推送逻辑修改;

This commit is contained in:
王奎兴
2026-06-12 16:46:51 +08:00
parent fa9682ae63
commit ece27b786f
5 changed files with 229 additions and 3 deletions
@@ -62,4 +62,8 @@ public interface OmsServiceFeign {
@ApiOperation("批量推送")
@PostMapping("/reservationStockOutOrderApi/batchPush")
public AjaxResult batchPush(@RequestBody List<Long> idList);
@ApiOperation("批量推送")
@PostMapping("/reservationStockOutOrderApi/batchPushByNumber")
public AjaxResult batchPushByNumber(@RequestBody List<String> numberList);
}
@@ -85,6 +85,11 @@ public class RemoteOmsFeignFallbackFactory implements FallbackFactory<OmsService
public AjaxResult batchPush(List<Long> idList) {
return null;
}
@Override
public AjaxResult batchPushByNumber(List<String> numberList) {
return null;
}
};
}
}
@@ -1080,6 +1080,213 @@ public class ReservationStockOutOrderApplicationService {
return stockOutOrderDomainService.queryOutStockNoticePrintDetail(stockOutOrderDO);
}
public AjaxResult batchPushByNumber(List<String> numberList) {
if (numberList == null || numberList.isEmpty() || numberList.size() < 1) {
return AjaxResult.error("没有数据需要推送");
}
String s = numberList.get(0);
ReservationStockOutOrder one = stockOutOrderService.getOne(new LambdaQueryWrapper<ReservationStockOutOrder>()
.eq(ReservationStockOutOrder::getOutOrderNumber, s)
.eq(ReservationStockOutOrder::getDelFlag, 1), false);
List<Long> idList = new ArrayList<>();
idList.add(one.getOutOrderId());
LoginUser loginUser = SecurityUtils.getLoginUser();
Long pushBy = loginUser != null ? loginUser.getUserid() : null;
String pushByName = loginUser != null ? loginUser.getUsername() : null;
Long organizationId = loginUser != null ? loginUser.getUserPo().getOrganizationId() : null;
Long topOrganizationId = loginUser != null ? loginUser.getUserPo().getTopOrganizationId() : null;
String organizationName = loginUser != null ? loginUser.getUserPo().getOrganizationName() : null;
int successCount = 0;
int failCount = 0;
StringBuilder failMsg = new StringBuilder();
for (Long id : idList) {
// 查询出库单
ReservationStockOutOrder reservationStockOutOrder = reservationStockOutOrderMapper.selectById(id);
if (reservationStockOutOrder == null) {
failCount++;
failMsg.append("id:").append(id).append("不存在;");
continue;
}
// 获取货主NC编码
Long shipperId = reservationStockOutOrder.getShipperId();
String userNcCode = reservationStockInOrderMapper.getUserNcCode(shipperId);
// 构建主单Map
Map<String, Object> order = new HashMap<>();
order.put("billNo", reservationStockOutOrder.getOutOrderNumber());
order.put("ieFlag", "E");
order.put("billDate", reservationStockOutOrder.getDocumentDate());
order.put("corpCode", userNcCode != null ? userNcCode : "");
// 查询出库物料明细
List<ReservationOutMaterialDetail> reservationOutMaterialDetails =
reservationOutMaterialDetailMapper.selectList(
new LambdaQueryWrapper<ReservationOutMaterialDetail>()
.eq(ReservationOutMaterialDetail::getOutOrderNumber, reservationStockOutOrder.getOutOrderNumber())
.eq(ReservationOutMaterialDetail::getDelFlag, 1)
);
if (reservationOutMaterialDetails == null || reservationOutMaterialDetails.isEmpty()) {
failCount++;
failMsg.append("id:").append(id).append("无物料明细;");
continue;
}
// 构建明细List<Map>
List<Map<String, Object>> orderList = new ArrayList<>();
for (ReservationOutMaterialDetail detail : reservationOutMaterialDetails) {
Map<String, Object> item = new HashMap<>();
item.put("billNo", reservationStockOutOrder.getOutOrderNumber());
String lotNo = detail.getLotNo();
if (lotNo != null) {
String[] split = lotNo.split("-");
if (split.length == 2) {
item.put("lineNum", split[1]);
} else {
item.put("lineNum", 1);
}
} else {
item.put("lineNum", 1);
}
item.put("qty", detail.getQuantity());
// 获取物料详情
if (detail.getMaterialBaseInfoId() != null) {
MaterialBaseInfoPO materialBaseInfoPO = reservationStockInOrderMapper.getinfo(detail.getMaterialBaseInfoId());
if (materialBaseInfoPO != null) {
item.put("erpCurr", materialBaseInfoPO.getCurrency() != null ? materialBaseInfoPO.getCurrency() : "");
item.put("erpPrice", materialBaseInfoPO.getUnitPrice());
item.put("itemNo", materialBaseInfoPO.getMaterialCode() != null ? materialBaseInfoPO.getMaterialCode() : "");
item.put("itemName", materialBaseInfoPO.getMaterialName() != null ? materialBaseInfoPO.getMaterialName() : "");
item.put("spec", materialBaseInfoPO.getSpecificationModel() != null ? materialBaseInfoPO.getSpecificationModel() : "");
item.put("unit", materialBaseInfoPO.getDeclarationUnit() != null ? materialBaseInfoPO.getDeclarationUnit() : "");
// 计算金额
BigDecimal unitPrice = materialBaseInfoPO.getUnitPrice();
BigDecimal quantity = detail.getQuantity();
if (unitPrice != null && quantity != null && unitPrice.compareTo(BigDecimal.ZERO) != 0 && quantity.compareTo(BigDecimal.ZERO) != 0) {
BigDecimal amount = unitPrice.multiply(quantity).setScale(2, BigDecimal.ROUND_HALF_UP);
item.put("amount", amount);
}
}
}
// 库存关联信息(实体默认值 + WMS覆盖)
Long kcId = reservationOutMaterialDetailMapper.getkcIdByUniqueId(detail.getUniqueId());
if (kcId != null) {
String inOrderNumber = reservationOutMaterialDetailMapper.getInOrderNumber(kcId);
String warehouseCode = reservationOutMaterialDetailMapper.getWarehouse(kcId);
String opWhLoc = reservationOutMaterialDetailMapper.getOpWhLoc(kcId);
String inLotNo = reservationOutMaterialDetailMapper.getLotByKcId(kcId);
if (inOrderNumber != null) {
item.put("orderINo", inOrderNumber);
}
if (warehouseCode != null) {
item.put("warehouse", warehouseCode);
}
if (opWhLoc != null) {
item.put("opWhLoc", opWhLoc);
}
// billI = 入库单号
if (inOrderNumber != null) {
item.put("billI", inOrderNumber);
}
if (inLotNo != null && inLotNo.contains("-")) {
String[] split = inLotNo.split("-");
if (split.length == 2) {
item.put("orderIRow", split[1]);
item.put("billIRow", split[1]);
} else {
item.put("orderIRow", 1);
item.put("billIRow", 1);
}
} else {
item.put("orderIRow", 1);
item.put("billIRow", 1);
}
}
orderList.add(item);
}
order.put("orderList", orderList);
// 构建推送body
List<Map<String, Object>> bodyList = new ArrayList<>();
bodyList.add(order);
GwLog gwLog = new GwLog();
gwLog.setType("保税仓-出口订单");
gwLog.setBusinessId(id);
gwLog.setRequestBody(com.alibaba.fastjson.JSONObject.toJSONString(bodyList));
gwLog.setResponseBody("");
gwLog.setStatus(1);
gwLog.setSendTime(new Date());
gwLog.setOrganizationId(organizationId);
gwLog.setTopOrganizationId(topOrganizationId);
gwLog.setOrganizationName(organizationName);
gwLog.setCreateBy(pushBy);
gwLog.setCreateTime(new Date());
gwLog.setDelFlag(1);
gwLogMapper.insert(gwLog);
updatePushStatus(id, 2, new Date(), pushBy,pushByName);
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(PUSH_API_URL);
StringEntity postingString = new StringEntity(com.alibaba.fastjson.JSONObject.toJSONString(bodyList), "UTF-8");
httpPost.setEntity(postingString);
httpPost.setHeader("Content-type", "application/json");
httpPost.setHeader("apiName", API_NAME);
httpPost.setHeader("verify", VERIFY);
try {
CloseableHttpResponse response = httpClient.execute(httpPost);
String responseString = EntityUtils.toString(response.getEntity());
gwLog.setResponseBody(responseString);
if (response.getStatusLine().getStatusCode() == 200) {
gwLog.setStatus(2);
updatePushStatus(id, 3, new Date(), pushBy,pushByName);
successCount++;
} else {
gwLog.setStatus(3);
gwLog.setErrorMsg(responseString);
updatePushStatus(id, 4, new Date(), pushBy,pushByName);
failCount++;
failMsg.append("id:").append(id).append("失败;");
}
gwLogMapper.updateById(gwLog);
response.close();
} catch (IOException e) {
gwLog.setStatus(3);
gwLog.setErrorMsg(e.getMessage());
gwLog.setResponseBody("请求异常:" + e.getMessage());
gwLogMapper.updateById(gwLog);
updatePushStatus(id, 4, new Date(), pushBy,pushByName);
failCount++;
failMsg.append("id:").append(id).append("异常:").append(e.getMessage()).append(";");
log.error("保税仓推送异常: id={}, error={}", id, e.getMessage());
} finally {
try {
httpClient.close();
} catch (Exception e) {
log.error("关闭httpClient异常: {}", e.getMessage());
}
}
}
String resultMsg = "推送完成: 成功" + successCount + "条, 失败" + failCount + "";
if (failCount > 0) {
resultMsg += "[" + failMsg.toString() + "]";
}
return AjaxResult.success(resultMsg);
}
public AjaxResult batchPush(List<Long> idList) {
if (idList == null || idList.isEmpty()) {
return AjaxResult.error("没有数据需要推送");
@@ -199,6 +199,16 @@ public class ReservationStockOutOrderApi extends BaseController {
}
@ApiOperation("批量推送")
@PostMapping("/batchPushByNumber")
public AjaxResult batchPushByNumber(@RequestBody List<String> numberList){
if(numberList == null || numberList.isEmpty()){
return AjaxResult.error("没有数据需要推送");
}
return stockOutOrderApplicationService.batchPushByNumber(numberList);
}
@ApiOperation("退货")
@GetMapping("/returnGoods")
@@ -1010,10 +1010,10 @@ public class StockOutOrderApplicationService {
ids.add(outOrderId);
batchPush(ids);
} else {
Long outOrderId = stockOutOrderDO.getOutOrderId();
List<Long> ids = new ArrayList<>();
String outOrderId = stockOutOrderDO.getOutOrderNumber();
List<String> ids = new ArrayList<>();
ids.add(outOrderId);
omsServiceFeign.batchPush(ids);
omsServiceFeign.batchPushByNumber(ids);
}
} catch (Exception e) {
throw new ServiceException("生成报关单失败");