|
|
|
@ -6,6 +6,7 @@ import com.gaotao.modules.salesReturn.dao.SalesReturnMapper; |
|
|
|
import com.gaotao.modules.salesReturn.service.SalesReturnService; |
|
|
|
import com.gaotao.modules.inventoryStock.entity.InventoryStock; |
|
|
|
import com.gaotao.modules.inventoryStock.service.InventoryStockService; |
|
|
|
import com.gaotao.modules.schedule.mapper.ProcedureMapper; |
|
|
|
import com.gaotao.modules.sys.entity.SysUserEntity; |
|
|
|
import com.gaotao.modules.trans.entity.TransDetail; |
|
|
|
import com.gaotao.modules.trans.entity.TransDetailDto; |
|
|
|
@ -53,6 +54,9 @@ public class SalesReturnServiceImpl implements SalesReturnService { |
|
|
|
@Autowired |
|
|
|
private ProductionInboundMapper productionInboundMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ProcedureMapper procedureMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Map<String, Object>> getSalesReturnList(String site, String warehouseId, String searchCode, String status) { |
|
|
|
SysUserEntity sysUserEntity = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
@ -65,93 +69,89 @@ public class SalesReturnServiceImpl implements SalesReturnService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Map<String, Object>> validateLabelInInventory(String labelCode, String site, String buNo) { |
|
|
|
List<Map<String, Object>> resultList = salesReturnMapper.validateLabelInInventory(labelCode, site, buNo); |
|
|
|
if (resultList == null || resultList.isEmpty()) { |
|
|
|
throw new RuntimeException("该标签不存在于库存中,无法退货"); |
|
|
|
} |
|
|
|
public Map<String, Object> validateLabelWithSalesReturn(String site, String buNo, String returnNo, String labelCode, String operationType, String userName) { |
|
|
|
logger.info("验证销售退货标签,site: {}, buNo: {}, 退货单号: {}, 标签: {}, 操作类型: {}", |
|
|
|
site, buNo, returnNo, labelCode, operationType); |
|
|
|
|
|
|
|
// 对每个记录进行校验 |
|
|
|
for (Map<String, Object> result : resultList) { |
|
|
|
String statusTb = (String) result.get("statusTb"); |
|
|
|
String status = (String) result.get("status"); |
|
|
|
if (!"E".equals(statusTb)) { |
|
|
|
throw new RuntimeException("该标签状态不允许退货,当前状态: " + status); |
|
|
|
try { |
|
|
|
// 调用存储过程 GetScanLabelVerification |
|
|
|
List<Object> params = new ArrayList<>(); |
|
|
|
params.add(site); // 参数1: site |
|
|
|
params.add(buNo); // 参数2: buNo |
|
|
|
params.add(returnNo); // 参数3: 退货单号 |
|
|
|
params.add(""); // 参数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); |
|
|
|
} |
|
|
|
|
|
|
|
return resultList; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public boolean confirmSalesReturnStorage(String returnNo, String locationCode, List<Map<String, Object>> labels, String site, String buNo) { |
|
|
|
logger.info("开始确认销售退货入库,退货单号: {}, 库位号: {}, 标签数量: {}", returnNo, locationCode, labels.size()); |
|
|
|
public boolean confirmSalesReturnStorage(String site, String buNo, String returnNo, String locationCode, String userName) { |
|
|
|
logger.info("开始确认销售退货入库,site: {}, buNo: {}, 退货单号: {}, 库位号: {}", |
|
|
|
site, buNo, returnNo, locationCode); |
|
|
|
|
|
|
|
try { |
|
|
|
// 1. 验证库位是否存在且可用 |
|
|
|
Map<String, Object> locationInfo = productionInboundMapper.validateLocation(locationCode, site); |
|
|
|
if (locationInfo == null || locationInfo.isEmpty()) { |
|
|
|
throw new RuntimeException("该库位不存在,请检查"); |
|
|
|
// 调用存储过程 GetSaveLabelVerification |
|
|
|
List<Object> params = new ArrayList<>(); |
|
|
|
params.add(site); // 参数1: site |
|
|
|
params.add(buNo); // 参数2: buNo |
|
|
|
params.add(returnNo); // 参数3: 退货单号 |
|
|
|
params.add(""); // 参数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("存储过程调用失败"); |
|
|
|
} |
|
|
|
|
|
|
|
String locationStatus = (String) locationInfo.get("status"); |
|
|
|
if (!"Y".equals(locationStatus)) { |
|
|
|
throw new RuntimeException("该库位已停用,请检查"); |
|
|
|
} |
|
|
|
|
|
|
|
// 根据库位获取实际的仓库ID |
|
|
|
String warehouseId = (String) locationInfo.get("warehouseId"); |
|
|
|
if (warehouseId == null && warehouseId.trim().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); |
|
|
|
} |
|
|
|
|
|
|
|
// 1. 提取标签条码列表 |
|
|
|
List<String> labelCodes = labels.stream() |
|
|
|
.map(label -> (String) label.get("labelCode")) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
// 2. 验证所有标签都存在于库存中且状态为出库状态 |
|
|
|
for (Map<String, Object> label : labels) { |
|
|
|
String labelCode = (String) label.get("labelCode"); |
|
|
|
List<Map<String, Object>> inventoryInfoList = salesReturnMapper.validateLabelInInventory2(labelCode, site, buNo); |
|
|
|
if (inventoryInfoList == null || inventoryInfoList.isEmpty()) { |
|
|
|
throw new RuntimeException("标签 " + labelCode + " 不存在于库存中"); |
|
|
|
} |
|
|
|
|
|
|
|
// 检查是否有符合条件的记录 |
|
|
|
boolean hasValidRecord = false; |
|
|
|
for (Map<String, Object> inventoryInfo : inventoryInfoList) { |
|
|
|
if ("E".equals(inventoryInfo.get("statusTb"))) { |
|
|
|
hasValidRecord = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!hasValidRecord) { |
|
|
|
throw new RuntimeException("标签 " + labelCode + " 不符合退货条件"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// // 3. 更新入库单状态为"已入库" |
|
|
|
// int updatedHead = headMapper.updateInboundStatus(returnNo, "已入库", site, buNo); |
|
|
|
// if (updatedHead == 0) { |
|
|
|
// throw new RuntimeException("入库单状态更新失败"); |
|
|
|
// } |
|
|
|
|
|
|
|
// 4. 插入库存数据 |
|
|
|
insertInventoryStock(returnNo, warehouseId, locationCode, labels, site, buNo); |
|
|
|
|
|
|
|
// 4. 生成退货入库事务记录 |
|
|
|
generateReturnTransaction(returnNo, warehouseId, locationCode, labels, site, buNo); |
|
|
|
|
|
|
|
// 6. 异步调用ERP接口(这里可以发送消息到队列) |
|
|
|
//asyncCallErpInterface(returnNo, partNo, labels); |
|
|
|
|
|
|
|
logger.info("销售退货入库确认完成,退货单号: {}", returnNo); |
|
|
|
|
|
|
|
logger.info("销售退货入库成功,退货单号: {}", returnNo); |
|
|
|
return true; |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("销售退货入库确认失败,退货单号: {}, 错误信息: {}", returnNo, e.getMessage(), e); |
|
|
|
throw new RuntimeException("退货入库确认失败: " + e.getMessage(), e); |
|
|
|
logger.error("销售退货入库确认失败,退货单号: {}, 错误: {}", returnNo, e.getMessage(), e); |
|
|
|
throw new RuntimeException(e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -302,6 +302,25 @@ public class SalesReturnServiceImpl implements SalesReturnService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Map<String, Object>> getScannedLabelList(String site, String buNo, String returnNo) { |
|
|
|
logger.info("获取已扫描标签列表,site: {}, buNo: {}, 退货单号: {}", site, buNo, returnNo); |
|
|
|
|
|
|
|
try { |
|
|
|
List<Map<String, Object>> labelList = salesReturnMapper.getScannedLabelList(site, buNo, returnNo); |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 生成事务明细记录 |
|
|
|
*/ |
|
|
|
|