Browse Source

2025-11-03

pda调整扫描、查询、确认逻辑(采购退货)
master
fengyuan_yang 2 months ago
parent
commit
fd49d39290
  1. 82
      src/main/java/com/gaotao/modules/purchaseReturn/controller/PurchaseReturnController.java
  2. 15
      src/main/java/com/gaotao/modules/purchaseReturn/dao/PurchaseReturnMapper.java
  3. 43
      src/main/java/com/gaotao/modules/purchaseReturn/service/PurchaseReturnService.java
  4. 203
      src/main/java/com/gaotao/modules/purchaseReturn/service/impl/PurchaseReturnServiceImpl.java
  5. 17
      src/main/resources/mapper/purchaseReturn/PurchaseReturnMapper.xml

82
src/main/java/com/gaotao/modules/purchaseReturn/controller/PurchaseReturnController.java

@ -89,7 +89,7 @@ public class PurchaseReturnController extends AbstractController {
} }
/** /**
* 验证标签与采购退货单是否匹配并检查库存
* 验证标签通过存储过程
*/ */
@PostMapping("/validateLabelWithReturn") @PostMapping("/validateLabelWithReturn")
@ApiOperation("验证标签与退货单匹配") @ApiOperation("验证标签与退货单匹配")
@ -97,9 +97,11 @@ public class PurchaseReturnController extends AbstractController {
try { try {
String labelCode = (String) params.get("labelCode"); String labelCode = (String) params.get("labelCode");
String returnNo = (String) params.get("returnNo"); String returnNo = (String) params.get("returnNo");
String warehouseId = (String) params.get("warehouseId");
String relatedNo = (String) params.get("relatedNo");
String relatedLineNo = (String) params.get("relatedLineNo");
String site = (String) params.get("site"); String site = (String) params.get("site");
String buNo = (String) params.get("buNo"); String buNo = (String) params.get("buNo");
String operationType = (String) params.get("operationType");
if (labelCode == null || labelCode.trim().isEmpty()) { if (labelCode == null || labelCode.trim().isEmpty()) {
return R.error("标签条码不能为空"); return R.error("标签条码不能为空");
@ -109,8 +111,15 @@ public class PurchaseReturnController extends AbstractController {
return R.error("退货单号不能为空"); return R.error("退货单号不能为空");
} }
if (operationType == null || operationType.trim().isEmpty()) {
operationType = "I"; // 默认为添加
}
// 获取当前登录用户
String userName = getUser().getUsername();
Map<String, Object> result = purchaseReturnService.validateLabelWithReturn( Map<String, Object> result = purchaseReturnService.validateLabelWithReturn(
labelCode, returnNo, warehouseId, site, buNo);
site, buNo, returnNo, relatedNo, relatedLineNo, labelCode, operationType, userName);
return R.ok().put("data", result); return R.ok().put("data", result);
} catch (Exception e) { } catch (Exception e) {
@ -120,12 +129,7 @@ public class PurchaseReturnController extends AbstractController {
} }
/** /**
* 确认采购退货
* 系统逻辑
* 1. 更新库存表中的标签状态
* 2. 更改return_notification_head表中的单据状态为"已退货"
* 3. 生成WMS退货记录Transheader...
* 4. 异步调用ERP接口回传数据
* 确认采购退货通过存储过程
*/ */
@PostMapping("/confirmPurchaseReturn") @PostMapping("/confirmPurchaseReturn")
@ApiOperation("确认采购退货") @ApiOperation("确认采购退货")
@ -134,27 +138,22 @@ public class PurchaseReturnController extends AbstractController {
String site = (String) params.get("site"); String site = (String) params.get("site");
String buNo = (String) params.get("buNo"); String buNo = (String) params.get("buNo");
String returnNo = (String) params.get("returnNo"); String returnNo = (String) params.get("returnNo");
String warehouseId = (String) params.get("warehouseId");
List<Map<String, Object>> labels = (List<Map<String, Object>>) params.get("labels");
String relatedNo = (String) params.get("relatedNo");
String relatedLineNo = (String) params.get("relatedLineNo");
String locationCode = (String) params.get("locationCode");
if (returnNo == null || returnNo.trim().isEmpty()) { if (returnNo == null || returnNo.trim().isEmpty()) {
return R.error("退货单号不能为空"); return R.error("退货单号不能为空");
} }
if (warehouseId == null || warehouseId.trim().isEmpty()) {
return R.error("仓库ID不能为空");
}
if (labels == null || labels.isEmpty()) {
return R.error("标签列表不能为空");
if (locationCode == null || locationCode.trim().isEmpty()) {
return R.error("库位号不能为空");
} }
// 验证标签数据完整性
for (Map<String, Object> label : labels) {
String labelCode = (String) label.get("labelCode");
if (labelCode == null || labelCode.trim().isEmpty()) {
return R.error("标签条码不能为空");
}
}
boolean success = purchaseReturnService.confirmPurchaseReturn(site, buNo, returnNo, warehouseId, labels);
// 获取当前登录用户
String userName = getUser().getUsername();
boolean success = purchaseReturnService.confirmPurchaseReturn(
site, buNo, returnNo, relatedNo, relatedLineNo, locationCode, userName);
if (success) { if (success) {
return R.ok("退货成功"); return R.ok("退货成功");
} else { } else {
@ -239,4 +238,39 @@ public class PurchaseReturnController extends AbstractController {
return R.error("获取明细卡片列表失败: " + e.getMessage()); return R.error("获取明细卡片列表失败: " + e.getMessage());
} }
} }
/**
* 获取已扫描标签列表从缓存表
*/
@PostMapping("/getScannedLabelList")
@ApiOperation("获取已扫描标签列表")
public R getScannedLabelList(@RequestBody Map<String, Object> params) {
try {
String site = (String) params.get("site");
String buNo = (String) params.get("buNo");
String returnNo = (String) params.get("returnNo");
String relatedNo = (String) params.get("relatedNo");
String relatedLineNo = (String) params.get("relatedLineNo");
if (site == null || site.trim().isEmpty()) {
return R.error("站点不能为空");
}
if (buNo == null || buNo.trim().isEmpty()) {
return R.error("业务单元不能为空");
}
if (returnNo == null || returnNo.trim().isEmpty()) {
return R.error("退货单号不能为空");
}
List<Map<String, Object>> labelList = purchaseReturnService.getScannedLabelList(
site, buNo, returnNo, relatedNo, relatedLineNo);
return R.ok().put("data", labelList);
} catch (Exception e) {
logger.error("获取已扫描标签列表失败", e);
return R.error("获取已扫描标签列表失败: " + e.getMessage());
}
}
} }

15
src/main/java/com/gaotao/modules/purchaseReturn/dao/PurchaseReturnMapper.java

@ -116,4 +116,19 @@ public interface PurchaseReturnMapper extends BaseMapper {
@Param("warehouseId") String warehouseId, @Param("warehouseId") String warehouseId,
@Param("searchCode") String searchCode, @Param("searchCode") String searchCode,
@Param("userName") String userName); @Param("userName") String userName);
/**
* 获取已扫描标签列表从缓存表
* @param site 站点
* @param buNo 业务单元
* @param returnNo 退货单号
* @param relatedNo 关联单号
* @param relatedLineNo 关联单行号
* @return 已扫描标签列表
*/
List<Map<String, Object>> getScannedLabelList(@Param("site") String site,
@Param("buNo") String buNo,
@Param("returnNo") String returnNo,
@Param("relatedNo") String relatedNo,
@Param("relatedLineNo") String relatedLineNo);
} }

43
src/main/java/com/gaotao/modules/purchaseReturn/service/PurchaseReturnService.java

@ -32,32 +32,35 @@ public interface PurchaseReturnService {
Map<String, Object> getReturnDetails(String returnNo, String buNo, String warehouseId, String site); Map<String, Object> getReturnDetails(String returnNo, String buNo, String warehouseId, String site);
/** /**
* 验证标签与采购退货单是否匹配并检查库存
* 从库存表验证标签信息
* @param labelCode 标签条码
* @param returnNo 退货单号
* @param warehouseId 仓库ID
* 验证标签通过存储过程
* @param site 站点 * @param site 站点
* @param buNo 业务单元 * @param buNo 业务单元
* @param returnNo 退货单号
* @param relatedNo 关联单号
* @param relatedLineNo 关联单行号
* @param labelCode 标签条码
* @param operationType 操作类型 I-添加 D-移除
* @param userName 当前登录人
* @return 标签信息 * @return 标签信息
*/ */
Map<String, Object> validateLabelWithReturn(String labelCode, String returnNo,
String warehouseId, String site, String buNo);
Map<String, Object> validateLabelWithReturn(String site, String buNo, String returnNo,
String relatedNo, String relatedLineNo,
String labelCode, String operationType, String userName);
/** /**
* 确认采购退货
* 1. 更新库存表中的标签状态
* 2. 更新return_notification_head表状态
* 3. 生成退货事务记录
* 确认采购退货通过存储过程
* @param site 站点 * @param site 站点
* @param buNo 业务单元 * @param buNo 业务单元
* @param returnNo 退货单号 * @param returnNo 退货单号
* @param warehouseId 仓库ID
* @param labels 标签列表
* @param relatedNo 关联单号
* @param relatedLineNo 关联单行号
* @param locationCode 库位号
* @param userName 当前登录人
* @return 处理结果 * @return 处理结果
*/ */
boolean confirmPurchaseReturn(String site, String buNo, String returnNo, boolean confirmPurchaseReturn(String site, String buNo, String returnNo,
String warehouseId, List<Map<String, Object>> labels);
String relatedNo, String relatedLineNo,
String locationCode, String userName);
/** /**
* 获取采购退货单物料清单 * 获取采购退货单物料清单
@ -82,4 +85,16 @@ public interface PurchaseReturnService {
*/ */
List<Map<String, Object>> getReturnDetailCards(String site, String buNo, String returnNo, List<Map<String, Object>> getReturnDetailCards(String site, String buNo, String returnNo,
String warehouseId, String searchCode, String userName); String warehouseId, String searchCode, String userName);
/**
* 获取已扫描标签列表从缓存表
* @param site 站点
* @param buNo 业务单元
* @param returnNo 退货单号
* @param relatedNo 关联单号
* @param relatedLineNo 关联单行号
* @return 已扫描标签列表
*/
List<Map<String, Object>> getScannedLabelList(String site, String buNo, String returnNo,
String relatedNo, String relatedLineNo);
} }

203
src/main/java/com/gaotao/modules/purchaseReturn/service/impl/PurchaseReturnServiceImpl.java

@ -2,7 +2,7 @@ package com.gaotao.modules.purchaseReturn.service.impl;
import com.gaotao.modules.purchaseReturn.dao.PurchaseReturnMapper; import com.gaotao.modules.purchaseReturn.dao.PurchaseReturnMapper;
import com.gaotao.modules.purchaseReturn.service.PurchaseReturnService; import com.gaotao.modules.purchaseReturn.service.PurchaseReturnService;
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.sys.entity.SysUserEntity;
import com.gaotao.modules.trans.entity.TransDetail; import com.gaotao.modules.trans.entity.TransDetail;
import com.gaotao.modules.trans.entity.TransDetailDto; import com.gaotao.modules.trans.entity.TransDetailDto;
@ -29,9 +29,6 @@ public class PurchaseReturnServiceImpl implements PurchaseReturnService {
@Autowired @Autowired
private PurchaseReturnMapper purchaseReturnMapper; private PurchaseReturnMapper purchaseReturnMapper;
@Autowired
private InventoryStockService inventoryStockService;
@Autowired @Autowired
private TransHeaderService transHeaderService; private TransHeaderService transHeaderService;
@ -41,6 +38,9 @@ public class PurchaseReturnServiceImpl implements PurchaseReturnService {
@Autowired @Autowired
private TransDetailSubService transDetailSubService; private TransDetailSubService transDetailSubService;
@Autowired
private ProcedureMapper procedureMapper;
@Override @Override
public List<Map<String, Object>> getReturnList(String site, String warehouseId, String searchCode, String status) { public List<Map<String, Object>> getReturnList(String site, String warehouseId, String searchCode, String status) {
SysUserEntity sysUserEntity = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); SysUserEntity sysUserEntity = (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
@ -53,67 +53,144 @@ public class PurchaseReturnServiceImpl implements PurchaseReturnService {
} }
@Override @Override
public Map<String, Object> validateLabelWithReturn(String labelCode, String returnNo, String warehouseId, String site, String buNo) {
Map<String, Object> result = purchaseReturnMapper.validateLabelWithReturn(labelCode, returnNo, warehouseId, site, buNo);
if (result == null || result.isEmpty()) {
throw new RuntimeException("该标签与退货单不符,请检查");
}
String status = (String) result.get("status");
if (!"在库".equals(status)) {
throw new RuntimeException("该标签状态不允许退货");
public Map<String, Object> validateLabelWithReturn(String site, String buNo, String returnNo,
String relatedNo, String relatedLineNo,
String labelCode, String operationType, String userName) {
logger.info("验证采购退货标签,site: {}, buNo: {}, 退货单号: {}, 关联单号: {}, 关联行号: {}, 标签: {}, 操作类型: {}",
site, buNo, returnNo, relatedNo, relatedLineNo, labelCode, operationType);
try {
// 调用存储过程 GetScanLabelVerification
List<Object> params = new ArrayList<>();
params.add(site); // 参数1: site
params.add(buNo); // 参数2: buNo
params.add(returnNo); // 参数3: 退货单号
params.add(relatedNo); // 参数4: 关联单号
params.add(relatedLineNo); // 参数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 result;
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean confirmPurchaseReturn(String site, String buNo, String returnNo, String warehouseId, List<Map<String, Object>> labels) {
logger.info("开始确认采购退货,退货单号: {}, 仓库ID: {}, 标签数量: {}", returnNo, warehouseId, labels.size());
public boolean confirmPurchaseReturn(String site, String buNo, String returnNo,
String relatedNo, String relatedLineNo,
String locationCode, String userName) {
logger.info("开始确认采购退货,site: {}, buNo: {}, 退货单号: {}, 关联单号: {}, 关联行号: {}, 库位: {}",
site, buNo, returnNo, relatedNo, relatedLineNo, locationCode);
try { try {
// 1. 更新库存表中的标签状态为"已退货"
List<String> labelCodes = new ArrayList<>();
for (Map<String, Object> label : labels) {
labelCodes.add((String) label.get("labelCode"));
}
int updatedLabels = purchaseReturnMapper.updateInventoryStatus(labelCodes, "已退货", site, buNo);
if (updatedLabels != labelCodes.size()) {
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(relatedNo); // 参数4: 关联单号
params.add(relatedLineNo); // 参数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("存储过程调用失败");
} }
// 2. 检查是否所有标签都已退货决定是否更新退货单状态
Map<String, Object> labelStats = purchaseReturnMapper.checkAllLabelsReturned(returnNo, site, buNo);
if (labelStats != null) {
Integer totalLabels = (Integer) labelStats.get("totalLabels");
Integer returnedLabels = (Integer) labelStats.get("returnedLabels");
logger.info("退货单 {} 标签统计: 总标签数={}, 已退货标签数={}", returnNo, totalLabels, returnedLabels);
// 只有当所有标签都已退货时才更新退货单状态为"已完成"
if (totalLabels != null && returnedLabels != null && totalLabels.equals(returnedLabels) && totalLabels > 0) {
int updatedHead = purchaseReturnMapper.updateReturnStatus(returnNo, "已完成", site, buNo);
if (updatedHead > 0) {
logger.info("退货单 {} 所有标签已退货,状态更新为已完成", returnNo);
}
} else {
logger.info("退货单 {} 还有标签未退货,保持待退货状态", returnNo);
}
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);
} }
// 3. 生成退货事务记录
generateReturnTransaction(returnNo, warehouseId, labels, site, buNo);
// 4. 异步调用ERP接口这里可以发送消息到队列
//asyncCallErpInterface(returnNo, labels);
logger.info("采购退货确认完成,退货单号: {}", returnNo);
logger.info("采购退货确认成功,退货单号: {}", returnNo);
return true; return true;
} catch (Exception e) { } 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);
} }
} }
// 保留原有的实现方法作为注释以防需要
// private boolean confirmPurchaseReturnOld(String site, String buNo, String returnNo, String warehouseId, List<Map<String, Object>> labels) {
// logger.info("开始确认采购退货(旧方法),退货单号: {}, 仓库ID: {}, 标签数量: {}", returnNo, warehouseId, labels.size());
// try {
// // 1. 更新库存表中的标签状态为"已退货"
// List<String> labelCodes = new ArrayList<>();
// for (Map<String, Object> label : labels) {
// labelCodes.add((String) label.get("labelCode"));
// }
//
// int updatedLabels = purchaseReturnMapper.updateInventoryStatus(labelCodes, "已退货", site, buNo);
// if (updatedLabels != labelCodes.size()) {
// throw new RuntimeException("部分标签状态更新失败");
// }
//
// // 2. 检查是否所有标签都已退货决定是否更新退货单状态
// Map<String, Object> labelStats = purchaseReturnMapper.checkAllLabelsReturned(returnNo, site, buNo);
// if (labelStats != null) {
// Integer totalLabels = (Integer) labelStats.get("totalLabels");
// Integer returnedLabels = (Integer) labelStats.get("returnedLabels");
//
// logger.info("退货单 {} 标签统计: 总标签数={}, 已退货标签数={}", returnNo, totalLabels, returnedLabels);
//
// // 只有当所有标签都已退货时才更新退货单状态为"已完成"
// if (totalLabels != null && returnedLabels != null && totalLabels.equals(returnedLabels) && totalLabels > 0) {
// int updatedHead = purchaseReturnMapper.updateReturnStatus(returnNo, "已完成", site, buNo);
// if (updatedHead > 0) {
// logger.info("退货单 {} 所有标签已退货,状态更新为已完成", returnNo);
// }
// } else {
// logger.info("退货单 {} 还有标签未退货,保持待退货状态", returnNo);
// }
// }
//
// // 3. 生成退货事务记录
// generateReturnTransaction(returnNo, warehouseId, labels, site, buNo);
//
// // 4. 异步调用ERP接口这里可以发送消息到队列
// //asyncCallErpInterface(returnNo, labels);
//
// logger.info("采购退货确认完成,退货单号: {}", returnNo);
// return true;
// } catch (Exception e) {
// logger.error("采购退货确认失败,退货单号: {}, 错误信息: {}", returnNo, e.getMessage(), e);
// throw new RuntimeException("退货确认失败: " + e.getMessage(), e);
// }
// }
@Override @Override
public List<Map<String, Object>> getMaterialList(String site, String buNo, String returnNo) { public List<Map<String, Object>> getMaterialList(String site, String buNo, String returnNo) {
logger.info("获取采购退货物料清单,站点: {}, 业务单元: {}, 退货单号: {}", site, buNo, returnNo); logger.info("获取采购退货物料清单,站点: {}, 业务单元: {}, 退货单号: {}", site, buNo, returnNo);
@ -296,4 +373,26 @@ public class PurchaseReturnServiceImpl implements PurchaseReturnService {
} }
} }
@Override
public List<Map<String, Object>> getScannedLabelList(String site, String buNo, String returnNo,
String relatedNo, String relatedLineNo) {
logger.info("获取已扫描标签列表,site: {}, buNo: {}, 退货单号: {}, 关联单号: {}, 关联行号: {}",
site, buNo, returnNo, relatedNo, relatedLineNo);
try {
List<Map<String, Object>> labelList = purchaseReturnMapper.getScannedLabelList(
site, buNo, returnNo, relatedNo, relatedLineNo);
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);
}
}
} }

17
src/main/resources/mapper/purchaseReturn/PurchaseReturnMapper.xml

@ -183,4 +183,21 @@
ORDER BY h.required_outbound_date DESC ORDER BY h.required_outbound_date DESC
</select> </select>
<!-- 获取已扫描标签列表(从缓存表) -->
<select id="getScannedLabelList" resultType="java.util.Map">
SELECT
site,
bu_no as buNo,
part_no as partNo,
RollNo as labelCode,
RollQty as quantity
FROM ScannedRollTempTable
WHERE site = #{site}
AND bu_no = #{buNo}
AND NotifyNo = #{returnNo}
AND OrderNo = #{relatedNo}
AND seqNo = #{relatedLineNo}
ORDER BY RollNo DESC
</select>
</mapper> </mapper>
Loading…
Cancel
Save