|
|
|
@ -1,25 +1,32 @@ |
|
|
|
package com.gaotao.modules.handlingunit.controller; |
|
|
|
|
|
|
|
import com.gaotao.common.exception.XJException; |
|
|
|
import com.gaotao.common.utils.R; |
|
|
|
import com.gaotao.modules.handlingunit.entity.HandlingUnit; |
|
|
|
import com.gaotao.modules.handlingunit.service.HandlingUnitService; |
|
|
|
import com.gaotao.modules.handlingunit.service.HandlingUnitIdGeneratorService; |
|
|
|
import com.gaotao.modules.handlingunit.service.HandlingUnitIdLogService; |
|
|
|
import com.gaotao.modules.handlingunit.dao.HandlingUnitMapper; |
|
|
|
import com.gaotao.modules.sys.controller.AbstractController; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
|
* PDA标签查询控制器 |
|
|
|
* |
|
|
|
* |
|
|
|
* <p><b>主要功能:</b></p> |
|
|
|
* <ul> |
|
|
|
* <li>扫描标签查询HandlingUnit信息</li> |
|
|
|
* <li>显示物料编码、库位、仓库、批次号、wdr等信息</li> |
|
|
|
* </ul> |
|
|
|
* |
|
|
|
* |
|
|
|
* @author System |
|
|
|
* @since 2025-01-23 |
|
|
|
*/ |
|
|
|
@ -27,13 +34,19 @@ import java.util.Map; |
|
|
|
@RestController |
|
|
|
@RequestMapping("/pda/label") |
|
|
|
public class PdaLabelController extends AbstractController { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private HandlingUnitService handlingUnitService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private HandlingUnitMapper handlingUnitMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private HandlingUnitIdGeneratorService handlingUnitIdGeneratorService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private HandlingUnitIdLogService handlingUnitIdLogService; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author System |
|
|
|
* @Description 查询标签信息 |
|
|
|
@ -46,25 +59,25 @@ public class PdaLabelController extends AbstractController { |
|
|
|
try { |
|
|
|
String site = (String) params.get("site"); |
|
|
|
String labelCode = (String) params.get("labelCode"); |
|
|
|
|
|
|
|
|
|
|
|
log.info("=== 开始查询标签信息 ==="); |
|
|
|
log.info("工厂: {}, 标签编码: {}", site, labelCode); |
|
|
|
|
|
|
|
|
|
|
|
// 参数验证 |
|
|
|
if (site == null || site.trim().isEmpty()) { |
|
|
|
return R.error("工厂编码不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (labelCode == null || labelCode.trim().isEmpty()) { |
|
|
|
return R.error("标签编码不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 查询HandlingUnit信息 |
|
|
|
HandlingUnit handlingUnit = handlingUnitService.lambdaQuery() |
|
|
|
.eq(HandlingUnit::getSite, site) |
|
|
|
.eq(HandlingUnit::getUnitId, labelCode.trim()) |
|
|
|
.one(); |
|
|
|
|
|
|
|
|
|
|
|
if (handlingUnit == null) { |
|
|
|
log.warn("标签不存在: site={}, labelCode={}", site, labelCode); |
|
|
|
return R.error("标签不存在"); |
|
|
|
@ -72,25 +85,25 @@ public class PdaLabelController extends AbstractController { |
|
|
|
if(!"Y".equals(handlingUnit.getInStockFlag())){ |
|
|
|
return R.error("标签库存已经被消耗!"); |
|
|
|
} |
|
|
|
|
|
|
|
log.info("查询到标签信息: unitId={}, partNo={}, locationId={}, warehouseId={}, batchNo={}, wdr={}", |
|
|
|
|
|
|
|
log.info("查询到标签信息: unitId={}, partNo={}, locationId={}, warehouseId={}, batchNo={}, wdr={}", |
|
|
|
handlingUnit.getUnitId(), |
|
|
|
handlingUnit.getPartNo(), |
|
|
|
handlingUnit.getLocationId(), |
|
|
|
handlingUnit.getWarehouseId(), |
|
|
|
handlingUnit.getBatchNo(), |
|
|
|
handlingUnit.getWdr()); |
|
|
|
|
|
|
|
|
|
|
|
log.info("=== 标签信息查询完成 ==="); |
|
|
|
|
|
|
|
|
|
|
|
return R.ok().put("data", handlingUnit); |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
log.error("=== 查询标签信息失败 === 错误信息: {}", e.getMessage(), e); |
|
|
|
return R.error("查询失败: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @Author rqrq |
|
|
|
* @Description 取消WMS预留 - rqrq |
|
|
|
@ -102,42 +115,202 @@ public class PdaLabelController extends AbstractController { |
|
|
|
public R cancelReserve(@RequestBody Map<String, Object> params) throws Exception { |
|
|
|
String site = (String) params.get("site"); |
|
|
|
String unitId = (String) params.get("unitId"); |
|
|
|
|
|
|
|
|
|
|
|
log.info("=== 开始取消WMS预留 - rqrq ==="); |
|
|
|
log.info("工厂: {}, 标签编码: {}", site, unitId); |
|
|
|
|
|
|
|
|
|
|
|
// 参数验证 - rqrq |
|
|
|
if (site == null || site.trim().isEmpty()) { |
|
|
|
throw new RuntimeException("工厂编码不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (unitId == null || unitId.trim().isEmpty()) { |
|
|
|
throw new RuntimeException("标签编码不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 查询HandlingUnit是否存在 - rqrq |
|
|
|
HandlingUnit handlingUnit = handlingUnitService.lambdaQuery() |
|
|
|
.eq(HandlingUnit::getSite, site) |
|
|
|
.eq(HandlingUnit::getUnitId, unitId.trim()) |
|
|
|
.one(); |
|
|
|
|
|
|
|
|
|
|
|
if (handlingUnit == null) { |
|
|
|
log.warn("标签不存在 - rqrq: site={}, unitId={}", site, unitId); |
|
|
|
throw new RuntimeException("标签不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查是否被预留 - rqrq |
|
|
|
if (!"Y".equals(handlingUnit.getReserveFlag())) { |
|
|
|
log.warn("标签未被预留 - rqrq: site={}, unitId={}", site, unitId); |
|
|
|
throw new RuntimeException("该标签未被WMS预留"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 调用Mapper方法取消预留 - rqrq |
|
|
|
handlingUnitMapper.cancelReserve(site, unitId); |
|
|
|
|
|
|
|
|
|
|
|
log.info("取消WMS预留成功 - rqrq: unitId={}", unitId); |
|
|
|
log.info("=== 取消WMS预留完成 - rqrq ==="); |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author System |
|
|
|
* @Description 标签拆分 - 将原标签拆分出指定数量到新标签 |
|
|
|
* @Date 2025/01/18 |
|
|
|
* @Param [Map<String, Object>] |
|
|
|
* @return com.gaotao.common.utils.R |
|
|
|
**/ |
|
|
|
@PostMapping("split") |
|
|
|
@Transactional |
|
|
|
public R splitLabel(@RequestBody Map<String, Object> params) { |
|
|
|
try { |
|
|
|
String site = (String) params.get("site"); |
|
|
|
String unitId = (String) params.get("unitId"); |
|
|
|
String operatorName = (String) params.get("operatorName"); |
|
|
|
BigDecimal splitQty = new BigDecimal(params.get("splitQty").toString()); |
|
|
|
|
|
|
|
log.info("=== 开始标签拆分 ==="); |
|
|
|
log.info("工厂: {}, 原标签: {}, 拆分数量: {}, 操作人: {}", site, unitId, splitQty, operatorName); |
|
|
|
|
|
|
|
// 1. 参数验证 |
|
|
|
if (site == null || site.trim().isEmpty()) { |
|
|
|
throw new XJException("工厂编码不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
if (unitId == null || unitId.trim().isEmpty()) { |
|
|
|
throw new XJException("标签编码不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
if (splitQty.compareTo(BigDecimal.ZERO) <= 0) { |
|
|
|
throw new XJException("拆分数量必须大于0"); |
|
|
|
} |
|
|
|
|
|
|
|
// 2. 查询原标签 |
|
|
|
HandlingUnit originalUnit = handlingUnitService.lambdaQuery() |
|
|
|
.eq(HandlingUnit::getSite, site) |
|
|
|
.eq(HandlingUnit::getUnitId, unitId) |
|
|
|
.one(); |
|
|
|
|
|
|
|
if (originalUnit == null) { |
|
|
|
throw new XJException("原标签不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
// 3. 验证库存状态 |
|
|
|
if (!"Y".equals(originalUnit.getInStockFlag())) { |
|
|
|
throw new XJException("该标签库存已被消耗,不能拆分"); |
|
|
|
} |
|
|
|
|
|
|
|
// 4. 验证拆分数量 |
|
|
|
BigDecimal originalQty = originalUnit.getQty(); |
|
|
|
if (splitQty.compareTo(originalQty) >= 0) { |
|
|
|
throw new XJException("拆分数量必须小于原标签数量(" + originalQty + ")"); |
|
|
|
} |
|
|
|
|
|
|
|
// 5. 生成新标签编码 |
|
|
|
String newUnitId = handlingUnitIdGeneratorService.generateUnitId(site); |
|
|
|
log.info("生成新标签编码: {}", newUnitId); |
|
|
|
|
|
|
|
// 6. 创建新标签(复制原标签所有信息,只修改数量) |
|
|
|
HandlingUnit newUnit = new HandlingUnit(); |
|
|
|
newUnit.setUnitId(newUnitId); |
|
|
|
newUnit.setSite(site); |
|
|
|
newUnit.setParentUnitId(originalUnit.getParentUnitId()); |
|
|
|
newUnit.setUnitType(originalUnit.getUnitType()); |
|
|
|
newUnit.setUnitTypeDb(originalUnit.getUnitTypeDb()); |
|
|
|
newUnit.setPartNo(originalUnit.getPartNo()); |
|
|
|
newUnit.setPartDesc(originalUnit.getPartDesc()); |
|
|
|
newUnit.setQty(splitQty); // 新标签数量 |
|
|
|
newUnit.setBatchNo(originalUnit.getBatchNo()); |
|
|
|
newUnit.setLocationId(originalUnit.getLocationId()); |
|
|
|
newUnit.setWarehouseId(originalUnit.getWarehouseId()); |
|
|
|
newUnit.setWdr(originalUnit.getWdr()); |
|
|
|
newUnit.setAvailabilityControlId(originalUnit.getAvailabilityControlId()); |
|
|
|
newUnit.setStatus(originalUnit.getStatus()); |
|
|
|
newUnit.setStatusDb(originalUnit.getStatusDb()); |
|
|
|
newUnit.setFreezeFlag(originalUnit.getFreezeFlag()); |
|
|
|
newUnit.setMergedFlag(originalUnit.getMergedFlag()); |
|
|
|
newUnit.setInStockFlag("Y"); |
|
|
|
newUnit.setOrderRef1(originalUnit.getOrderRef1()); |
|
|
|
newUnit.setOrderRef2(originalUnit.getOrderRef2()); |
|
|
|
newUnit.setOrderRef3(originalUnit.getOrderRef3()); |
|
|
|
newUnit.setSupplierId(originalUnit.getSupplierId()); |
|
|
|
newUnit.setCustomerId(originalUnit.getCustomerId()); |
|
|
|
newUnit.setManufactureDate(originalUnit.getManufactureDate()); |
|
|
|
newUnit.setExpiredDate(originalUnit.getExpiredDate()); |
|
|
|
newUnit.setSourceType("SPLIT"); // 来源类型:拆分 |
|
|
|
newUnit.setSourceRef(unitId); // 原标签编码 |
|
|
|
newUnit.setGrossWeight(originalUnit.getGrossWeight()); |
|
|
|
newUnit.setNetWeight(originalUnit.getNetWeight()); |
|
|
|
newUnit.setWeightUnit(originalUnit.getWeightUnit()); |
|
|
|
newUnit.setVolume(originalUnit.getVolume()); |
|
|
|
newUnit.setVolumeUnit(originalUnit.getVolumeUnit()); |
|
|
|
newUnit.setBarCode(newUnitId); |
|
|
|
newUnit.setQrCode(newUnitId); |
|
|
|
newUnit.setOriginalQty(splitQty); |
|
|
|
newUnit.setReceiveDate(originalUnit.getReceiveDate()); |
|
|
|
newUnit.setEngChgLevel(originalUnit.getEngChgLevel()); |
|
|
|
newUnit.setReserveFlag("N"); |
|
|
|
newUnit.setCreatedDate(new Date()); |
|
|
|
newUnit.setCreatedBy(operatorName); |
|
|
|
newUnit.setModifiedDate(new Date()); |
|
|
|
newUnit.setModifiedBy(operatorName); |
|
|
|
newUnit.setRemark("从标签 " + unitId + " 拆分"); |
|
|
|
|
|
|
|
// 7. 保存新标签 |
|
|
|
boolean saveResult = handlingUnitService.save(newUnit); |
|
|
|
if (!saveResult) { |
|
|
|
log.error("严重错误:新标签保存返回失败!unitId={}", newUnitId); |
|
|
|
handlingUnitIdLogService.logUnitIdGeneration( |
|
|
|
newUnitId, site, "LABEL_SPLIT", unitId, |
|
|
|
"", originalUnit.getPartNo(), originalUnit.getBatchNo(), |
|
|
|
splitQty.doubleValue(), operatorName, |
|
|
|
"N", "保存失败-save返回false" |
|
|
|
); |
|
|
|
throw new XJException("新标签保存失败(save返回false): " + newUnitId); |
|
|
|
} |
|
|
|
|
|
|
|
// 8. 记录新标签生成日志 |
|
|
|
handlingUnitIdLogService.logUnitIdGeneration( |
|
|
|
newUnitId, site, "LABEL_SPLIT", unitId, |
|
|
|
"", originalUnit.getPartNo(), originalUnit.getBatchNo(), |
|
|
|
splitQty.doubleValue(), operatorName, |
|
|
|
"Y", "标签拆分成功" |
|
|
|
); |
|
|
|
|
|
|
|
// 9. 更新原标签数量 |
|
|
|
BigDecimal remainQty = originalQty.subtract(splitQty); |
|
|
|
originalUnit.setQty(remainQty); |
|
|
|
originalUnit.setModifiedDate(new Date()); |
|
|
|
originalUnit.setModifiedBy(operatorName); |
|
|
|
originalUnit.setRemark("拆分出标签 " + newUnitId + ",数量: " + splitQty); |
|
|
|
|
|
|
|
boolean updateResult = handlingUnitService.updateById(originalUnit); |
|
|
|
if (!updateResult) { |
|
|
|
log.error("严重错误:原标签更新失败!unitId={}", unitId); |
|
|
|
throw new XJException("原标签更新失败"); |
|
|
|
} |
|
|
|
|
|
|
|
log.info("=== 标签拆分成功 ==="); |
|
|
|
log.info("原标签: {} 剩余数量: {}", unitId, remainQty); |
|
|
|
log.info("新标签: {} 数量: {}", newUnitId, splitQty); |
|
|
|
|
|
|
|
// 10. 返回结果(包含原标签和新标签ID,用于打印) |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
result.put("originalUnitId", unitId); |
|
|
|
result.put("newUnitId", newUnitId); |
|
|
|
result.put("originalQty", originalQty); |
|
|
|
result.put("remainQty", remainQty); |
|
|
|
result.put("splitQty", splitQty); |
|
|
|
|
|
|
|
return R.ok().put("data", result); |
|
|
|
|
|
|
|
} catch (XJException e) { |
|
|
|
log.error("=== 标签拆分失败 === 错误信息: {}", e.getMessage()); |
|
|
|
return R.error(e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("=== 标签拆分失败 === 错误信息: {}", e.getMessage(), e); |
|
|
|
return R.error("拆分失败: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|