feat(wms): 新增质检发起服务接口和实现

- 创建 IWmsInspectionInitiationService 接口定义质检发起相关方法
- 实现批量发起质检任务功能,支持过滤必检且未发起的批次
- 实现单个批次发起质检任务功能,调用 QMS Dubbo 接口创建质检任务
- 添加质检校验逻辑,验证批次是否可以发起质检及获取失败原因
- 实现质检状态更新,成功后将打印记录状态更新为质检中
- 支持动态指定检验类型,默认为原材料检
- 集成分布式事务处理,确保数据一致性
master
zangch@mesnac.com 5 days ago
parent c415b2538f
commit 0df438dfa9

@ -0,0 +1,64 @@
package org.dromara.wms.service;
import org.dromara.wms.domain.bo.WmsInstockPrintBo;
import java.util.List;
import java.util.Map;
/**
* WMS
* <p>
* WMS QMS
* 便
*
* @author zch
* @date 2026-01-15
*/
public interface IWmsInspectionInitiationService {
/**
*
* <p>
*
* 1. inspectionRequest='0' inspectionType='0'
* 2. QMS Dubbo
* 3. inspectionType='1'
* 4.
* <p>
* Controller @GlobalTransactional
*
* @param prints
* @return Map<, >
*/
Map<String, String> createInspection(List<WmsInstockPrintBo> prints);
/**
*
* <p>
* Controller @GlobalTransactional
*
* @param print
* @return
*/
String createInspectionForSingle(WmsInstockPrintBo print);
/**
*
* <p>
*
* 1. inspectionRequest '0'
* 2. inspectionType '0' null
*
* @param print
* @return true=false=
*/
boolean canInitiateInspection(WmsInstockPrintBo print);
/**
*
*
* @param print
* @return null
*/
String getCannotInitiateReason(WmsInstockPrintBo print);
}

@ -0,0 +1,202 @@
package org.dromara.wms.service.impl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.qms.api.RemoteQmsInspectionService;
import org.dromara.qms.api.dto.WmsInspectionTaskRequest;
import org.dromara.wms.domain.bo.WmsInstockPrintBo;
import org.dromara.wms.service.IWmsInspectionInitiationService;
import org.dromara.wms.service.IWmsInstockPrintService;
import org.springframework.stereotype.Service;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* WMS
* <p>
* WMS QMS
* <p>
* 便
*
* @author zch
* @date 2026-01-15
*/
@Slf4j
@RequiredArgsConstructor
@Service
public class WmsInspectionInitiationServiceImpl implements IWmsInspectionInitiationService {
/**
* QMS Dubbo
*/
@DubboReference(timeout = 300000)
private RemoteQmsInspectionService remoteQmsInspectionService;
/**
*
*/
private final IWmsInstockPrintService instockPrintService;
/**
*
* <p>
* Controller @GlobalTransactional
*/
@Override
public Map<String, String> createInspection(List<WmsInstockPrintBo> prints) {
Map<String, String> result = new LinkedHashMap<>();
for (WmsInstockPrintBo print : prints) {
String batchCode = print.getBatchCode();
try {
// 1. 校验是否可以发起质检
String reason = getCannotInitiateReason(print);
if (reason != null) {
result.put(batchCode, "跳过: " + reason);
log.warn("批次 {} 不能发起质检: {}", batchCode, reason);
continue;
}
// 2. 调用单批次发起方法
String inspectionNo = createInspectionForSingle(print);
result.put(batchCode, inspectionNo);
} catch (Exception e) {
log.error("批次 {} 创建质检任务失败: {}", batchCode, e.getMessage(), e);
result.put(batchCode, "失败: " + e.getMessage());
// 全局事务会自动回滚
throw new ServiceException("批次 " + batchCode + " 创建质检任务失败: " + e.getMessage());
}
}
return result;
}
/**
*
* <p>
* Controller @GlobalTransactional
*/
@Override
public String createInspectionForSingle(WmsInstockPrintBo print) {
String batchCode = print.getBatchCode();
String instockCode = print.getInstockCode();
// 1. 构建质检任务请求参数
WmsInspectionTaskRequest request = buildInspectionRequest(print);
// 2. 调用 QMS Dubbo 接口创建质检任务
String inspectionNo;
try {
inspectionNo = remoteQmsInspectionService.createInspectionTaskForWMS(request);
} catch (ServiceException e) {
// 直接抛出 ServiceException
throw e;
} catch (RuntimeException e) {
// Dubbo 跨服务调用时ServiceException 会被包装成 RuntimeException
// 解析原始异常信息并抛出 ServiceException
String message = e.getMessage();
if (message != null && message.contains("ServiceException")) {
// 提取 ServiceException 中的 message 部分
int msgStart = message.indexOf("message=");
if (msgStart != -1) {
int msgEnd = message.indexOf(",", msgStart);
if (msgEnd == -1) {
msgEnd = message.indexOf(")", msgStart);
}
if (msgEnd != -1) {
String extractedMsg = message.substring(msgStart + 8, msgEnd);
throw new ServiceException(extractedMsg);
}
}
}
throw new ServiceException("QMS 创建质检任务失败: " + message);
}
if (StringUtils.isBlank(inspectionNo)) {
throw new ServiceException("QMS 返回质检单号为空");
}
log.info("批次 {} 质检任务创建成功,质检单号: {}, 入库单号: {}", batchCode, inspectionNo, instockCode);
// 3. 更新本地打印记录状态(只有远程调用成功才更新)
WmsInstockPrintBo updateBo = new WmsInstockPrintBo();
updateBo.setInstockPrintId(print.getInstockPrintId());
updateBo.setInspectionType("1"); // 质检中
instockPrintService.updateByBo(updateBo);
log.info("批次 {} 质检状态已更新为'质检中'", batchCode);
return inspectionNo;
}
/**
*
*/
@Override
public boolean canInitiateInspection(WmsInstockPrintBo print) {
return getCannotInitiateReason(print) == null;
}
/**
*
*/
@Override
public String getCannotInitiateReason(WmsInstockPrintBo print) {
String inspectionRequest = print.getInspectionRequest();
String inspectionType = print.getInspectionType();
// 校验1是否必检
if (!"0".equals(inspectionRequest)) {
return "该批次为免检,不需要质检";
}
// 校验2是否已发起
if (StringUtils.isNotBlank(inspectionType) && !"0".equals(inspectionType)) {
switch (inspectionType) {
case "1":
return "该批次质检中,请勿重复发起";
case "2":
return "该批次已质检合格";
case "3":
return "该批次质检不合格";
default:
return "该批次质检状态异常";
}
}
return null; // 可以发起
}
/**
*
* <p>
* WmsInstockPrintBo WmsInspectionTaskRequest
* inspectionTypeParam
*/
private WmsInspectionTaskRequest buildInspectionRequest(WmsInstockPrintBo print) {
WmsInspectionTaskRequest request = new WmsInspectionTaskRequest();
request.setInstockCode(print.getInstockCode()); // 入库单号
request.setMaterialCode(print.getMaterialCode()); // 物料编码
request.setMaterialName(print.getMaterialName()); // 物料名称
request.setInspectionQty(print.getApportionQty()); // 质检数量(分包数量)
request.setBatchCode(print.getBatchCode()); // 批次号
// 检验类型:优先使用前端传入的参数,默认为"4"(原材料检)
//首检=0, 专检=1, 自检=2, 互检=3, 原材料检=4, 抽检=5, 成品检=6, 入库检=7出库检=8
String inspectionType = StringUtils.isNotBlank(print.getInspectionTypeParam())
? print.getInspectionTypeParam() : "4";
request.setInspectionType(inspectionType);
// 以下字段可预留扩展
request.setStationName(null); // 工位名称WMS入库无需工位
request.setProcessCode(null); // 工序编码WMS入库无需工序
request.setSupplierName(null); // 供应商名称(可从入库单获取)
request.setProductionOrder(null); // 生产订单号(可从入库单获取)
request.setWorkshop(null); // 车间(可从入库单获取)
return request;
}
}
Loading…
Cancel
Save