|
|
@ -1,14 +1,21 @@ |
|
|
package com.gaotao.modules.handlingunit.controller; |
|
|
package com.gaotao.modules.handlingunit.controller; |
|
|
|
|
|
|
|
|
|
|
|
import com.gaotao.common.exception.XJException; |
|
|
import com.gaotao.common.utils.R; |
|
|
import com.gaotao.common.utils.R; |
|
|
import com.gaotao.modules.handlingunit.entity.HandlingUnit; |
|
|
import com.gaotao.modules.handlingunit.entity.HandlingUnit; |
|
|
import com.gaotao.modules.handlingunit.service.HandlingUnitService; |
|
|
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.handlingunit.dao.HandlingUnitMapper; |
|
|
import com.gaotao.modules.sys.controller.AbstractController; |
|
|
import com.gaotao.modules.sys.controller.AbstractController; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
|
import java.util.Date; |
|
|
|
|
|
import java.util.HashMap; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -34,6 +41,12 @@ public class PdaLabelController extends AbstractController { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private HandlingUnitMapper handlingUnitMapper; |
|
|
private HandlingUnitMapper handlingUnitMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private HandlingUnitIdGeneratorService handlingUnitIdGeneratorService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private HandlingUnitIdLogService handlingUnitIdLogService; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @Author System |
|
|
* @Author System |
|
|
* @Description 查询标签信息 |
|
|
* @Description 查询标签信息 |
|
|
@ -139,5 +152,165 @@ public class PdaLabelController extends AbstractController { |
|
|
log.info("=== 取消WMS预留完成 - rqrq ==="); |
|
|
log.info("=== 取消WMS预留完成 - rqrq ==="); |
|
|
return R.ok(); |
|
|
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()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|