|
|
|
@ -1,6 +1,5 @@ |
|
|
|
package com.gaotao.modules.productionInbound.service.impl; |
|
|
|
|
|
|
|
import com.gaotao.common.exception.XJException; |
|
|
|
import com.gaotao.modules.inventoryStock.dao.InventoryStockMapper; |
|
|
|
import com.gaotao.modules.pms.entity.vo.PartLabelTemplateVo; |
|
|
|
import com.gaotao.modules.productionInbound.dao.ProductionInboundMapper; |
|
|
|
@ -25,7 +24,6 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class ProductionInboundServiceImpl implements ProductionInboundService { |
|
|
|
@ -67,101 +65,89 @@ public class ProductionInboundServiceImpl implements ProductionInboundService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Map<String, Object>> validateLabelWithInbound(String labelCode, String orderNo, String partNo, String site, String buNo, String relatedOrderNo) { |
|
|
|
logger.info("验证标签与入库单匹配,标签: {}, 入库单: {}, 关联单号: {}", labelCode, orderNo, relatedOrderNo); |
|
|
|
public Map<String, Object> validateLabelWithInbound(String site, String buNo, String relatedOrderNo, String inboundNo, String labelCode, String operationType, String userName) { |
|
|
|
logger.info("验证生产入库标签,site: {}, buNo: {}, 关联单号: {}, 入库单号: {}, 标签: {}, 操作类型: {}", |
|
|
|
site, buNo, relatedOrderNo, inboundNo, labelCode, operationType); |
|
|
|
|
|
|
|
// 从SFDC_ROLLS表验证标签信息,返回多条子标签记录 |
|
|
|
List<Map<String, Object>> resultList = productionInboundMapper.validateLabelWithInbound(labelCode, orderNo, partNo, site, buNo, relatedOrderNo); |
|
|
|
|
|
|
|
if (resultList == null || resultList.isEmpty()) { |
|
|
|
logger.warn("该标签与入库单不符,标签: {}, 入库单: {}", labelCode, orderNo); |
|
|
|
throw new RuntimeException("该标签与入库单不符,请检查"); |
|
|
|
} |
|
|
|
|
|
|
|
// 验证所有标签的状态 |
|
|
|
for (Map<String, Object> result : resultList) { |
|
|
|
String status = (String) result.get("status"); |
|
|
|
if (!"待入库".equals(status)) { |
|
|
|
String subLabelCode = (String) result.get("labelCode"); |
|
|
|
logger.warn("子标签状态不允许入库,子标签: {}, 状态: {}", subLabelCode, status); |
|
|
|
throw new RuntimeException("标签 " + subLabelCode + " 的状态不允许入库"); |
|
|
|
try { |
|
|
|
// 调用存储过程 GetScanLabelVerification |
|
|
|
List<Object> params = new ArrayList<>(); |
|
|
|
params.add(site); // 参数1: site |
|
|
|
params.add(buNo); // 参数2: buNo |
|
|
|
params.add(relatedOrderNo); // 参数3: 关联单号 |
|
|
|
params.add(inboundNo); // 参数4: 入库单号 |
|
|
|
params.add(""); // 参数5: 空字符串 |
|
|
|
params.add(""); // 参数6: 空字符串 |
|
|
|
params.add(""); // 参数7: 空字符串 |
|
|
|
params.add(labelCode); // 参数8: 扫描的标签条码 |
|
|
|
params.add(""); // 参数9: 空字符串 |
|
|
|
params.add("生产入库"); // 参数10: 生产入库 |
|
|
|
params.add(operationType); // 参数11: 操作类型 I或D |
|
|
|
params.add(userName); // 参数12: 当前登陆人 |
|
|
|
|
|
|
|
List<Map<String, Object>> resultList = procedureMapper.getProcedureData("GetScanLabelVerification", params); |
|
|
|
|
|
|
|
// 判断返回结果 |
|
|
|
if (resultList == null || resultList.isEmpty()) { |
|
|
|
throw new RuntimeException("存储过程调用失败"); |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, Object> result = resultList.get(0); |
|
|
|
String code = String.valueOf(result.get("code")); |
|
|
|
|
|
|
|
if (!"200".equals(code)) { |
|
|
|
String msg = String.valueOf(result.get("message")); |
|
|
|
throw new RuntimeException(msg); |
|
|
|
} |
|
|
|
|
|
|
|
logger.info("标签验证成功,标签: {}, 操作类型: {}", labelCode, operationType); |
|
|
|
return result; |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("标签验证失败,标签: {}, 错误: {}", labelCode, e.getMessage(), e); |
|
|
|
throw new RuntimeException(e.getMessage(), e); |
|
|
|
} |
|
|
|
|
|
|
|
logger.info("标签验证成功,父标签: {}, 共找到 {} 条子标签记录", labelCode, resultList.size()); |
|
|
|
return resultList; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public boolean confirmInboundStorage(String orderNo, String locationCode, List<Map<String, Object>> labels, String site, String buNo, String relatedOrderNo) { |
|
|
|
SysUserEntity sysUserEntity = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
String userName = sysUserEntity.getUsername(); |
|
|
|
|
|
|
|
logger.info("开始确认生产入库上架,入库单号: {}, 库位号: {}, 标签数量: {}", orderNo, locationCode, labels.size()); |
|
|
|
public boolean confirmInboundStorage(String site, String buNo, String relatedOrderNo, String inboundNo, String locationCode, String userName) { |
|
|
|
logger.info("开始确认生产入库上架,site: {}, buNo: {}, 关联单号: {}, 入库单号: {}, 库位号: {}", |
|
|
|
site, buNo, relatedOrderNo, inboundNo, locationCode); |
|
|
|
|
|
|
|
try { |
|
|
|
// 1. 验证库位是否存在且可用 |
|
|
|
Map<String, Object> locationInfo = productionInboundMapper.validateLocation(locationCode, site); |
|
|
|
if (locationInfo == null || locationInfo.isEmpty()) { |
|
|
|
throw new RuntimeException("该库位不存在,请检查"); |
|
|
|
} |
|
|
|
|
|
|
|
String locationStatus = (String) locationInfo.get("status"); |
|
|
|
if (!"Y".equals(locationStatus)) { |
|
|
|
throw new RuntimeException("该库位已停用,请检查"); |
|
|
|
// 调用存储过程 GetSaveLabelVerification |
|
|
|
List<Object> params = new ArrayList<>(); |
|
|
|
params.add(site); // 参数1: site |
|
|
|
params.add(buNo); // 参数2: buNo |
|
|
|
params.add(relatedOrderNo); // 参数3: 关联单号 |
|
|
|
params.add(inboundNo); // 参数4: 入库单号 |
|
|
|
params.add(""); // 参数5: 空字符串 |
|
|
|
params.add(""); // 参数6: 空字符串 |
|
|
|
params.add(""); // 参数7: 空字符串 |
|
|
|
params.add(locationCode); // 参数8: 库位 |
|
|
|
params.add("生产入库"); // 参数9: 生产入库 |
|
|
|
params.add(userName); // 参数10: 当前登陆人 |
|
|
|
|
|
|
|
List<Map<String, Object>> resultList = procedureMapper.getProcedureData("GetSaveLabelVerification", params); |
|
|
|
|
|
|
|
// 判断返回结果 |
|
|
|
if (resultList == null || resultList.isEmpty()) { |
|
|
|
throw new RuntimeException("存储过程调用失败"); |
|
|
|
} |
|
|
|
|
|
|
|
// 根据库位获取实际的仓库ID |
|
|
|
String warehouseId = (String) locationInfo.get("warehouseId"); |
|
|
|
if (warehouseId == null && warehouseId.trim().isEmpty()) { |
|
|
|
throw new RuntimeException("该库位未绑定仓库,请检查"); |
|
|
|
} |
|
|
|
|
|
|
|
// 2. 提取标签条码列表 |
|
|
|
List<String> labelCodes = labels.stream() |
|
|
|
.map(label -> (String) label.get("labelCode")) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
// 3. 更新SFDC_ROLLS表中标签状态为"已入库" |
|
|
|
int updatedLabels = productionInboundMapper.updateSfdcRollsStatus(labelCodes, "已入库", site, buNo); |
|
|
|
if (updatedLabels != labelCodes.size()) { |
|
|
|
throw new RuntimeException("部分标签状态更新失败"); |
|
|
|
|
|
|
|
Map<String, Object> result = resultList.get(0); |
|
|
|
String code = String.valueOf(result.get("code")); |
|
|
|
|
|
|
|
if (!"200".equals(code)) { |
|
|
|
String msg = String.valueOf(result.get("message")); |
|
|
|
throw new RuntimeException(msg); |
|
|
|
} |
|
|
|
|
|
|
|
// 5. 插入库存数据 |
|
|
|
insertInventoryStock(orderNo, warehouseId, locationCode, labels, site, buNo, relatedOrderNo); |
|
|
|
|
|
|
|
// 6. 生成入库事务记录 |
|
|
|
String transNo = generateInboundTransaction(orderNo, warehouseId, locationCode, labels, site, buNo); |
|
|
|
|
|
|
|
// 7. 计算所有标签的数量总和 |
|
|
|
BigDecimal inQty = BigDecimal.ZERO; |
|
|
|
for (Map<String, Object> label : labels) { |
|
|
|
Object quantityObj = label.get("quantity"); |
|
|
|
BigDecimal quantity = convertToDecimal(quantityObj); |
|
|
|
inQty = inQty.add(quantity); |
|
|
|
} |
|
|
|
logger.info("标签总数量: {}, 用于倒冲的数量: {}", inQty, inQty); |
|
|
|
|
|
|
|
// 8. 基于工单BOM,生成入库倒冲数据 |
|
|
|
// 调用存储过程,使用计算出的总数量 |
|
|
|
Map<String, Object> resultMap = this.UspBackflushMaterialByOrder(site, buNo, transNo, orderNo, inQty, userName); |
|
|
|
//判断是否检验成功 |
|
|
|
String resultCode = String.valueOf(resultMap.get("resultCode")); |
|
|
|
if ("400".equalsIgnoreCase(resultCode)) { |
|
|
|
String msg = String.valueOf(resultMap.get("resultMsg")); |
|
|
|
String objectId = String.valueOf(resultMap.get("objectId")); |
|
|
|
throw new XJException(msg,objectId); |
|
|
|
} |
|
|
|
|
|
|
|
// 7. 异步调用ERP接口(这里可以发送消息到队列) |
|
|
|
//asyncCallErpInterface(orderNo, partNo, labels); |
|
|
|
|
|
|
|
logger.info("生产入库上架确认完成,入库单号: {}", orderNo); |
|
|
|
|
|
|
|
logger.info("生产入库上架成功,入库单号: {}", inboundNo); |
|
|
|
return true; |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("生产入库确认失败,入库单号: {}, 错误信息: {}", orderNo, e.getMessage(), e); |
|
|
|
throw new RuntimeException("入库确认失败: " + e.getMessage(), e); |
|
|
|
logger.error("生产入库确认失败,入库单号: {}, 错误: {}", inboundNo, e.getMessage(), e); |
|
|
|
throw new RuntimeException(e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -391,6 +377,25 @@ public class ProductionInboundServiceImpl implements ProductionInboundService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Map<String, Object>> getScannedLabelList(String site, String buNo, String relatedOrderNo, String inboundNo) { |
|
|
|
logger.info("获取已扫描标签列表,site: {}, buNo: {}, 关联单号: {}, 入库单号: {}", site, buNo, relatedOrderNo, inboundNo); |
|
|
|
|
|
|
|
try { |
|
|
|
List<Map<String, Object>> labelList = productionInboundMapper.getScannedLabelList(site, buNo, relatedOrderNo, inboundNo); |
|
|
|
|
|
|
|
if (labelList == null) { |
|
|
|
labelList = new ArrayList<>(); |
|
|
|
} |
|
|
|
|
|
|
|
logger.info("获取已扫描标签列表成功,共 {} 条记录", labelList.size()); |
|
|
|
return labelList; |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("获取已扫描标签列表失败,错误: {}", e.getMessage(), e); |
|
|
|
throw new RuntimeException("获取已扫描标签列表失败: " + e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 生成事务明细记录 |
|
|
|
*/ |
|
|
|
|