diff --git a/src/main/java/com/gaotao/modules/labelSplitMerge/service/impl/LabelSplitMergeServiceImpl.java b/src/main/java/com/gaotao/modules/labelSplitMerge/service/impl/LabelSplitMergeServiceImpl.java index 153925a..db739e5 100644 --- a/src/main/java/com/gaotao/modules/labelSplitMerge/service/impl/LabelSplitMergeServiceImpl.java +++ b/src/main/java/com/gaotao/modules/labelSplitMerge/service/impl/LabelSplitMergeServiceImpl.java @@ -1,14 +1,13 @@ package com.gaotao.modules.labelSplitMerge.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gaotao.modules.base.data.BuData; import com.gaotao.modules.labelSplitMerge.dao.LabelSplitMergeMapper; import com.gaotao.modules.labelSplitMerge.entity.LabelSplitMergeEntity; import com.gaotao.modules.labelSplitMerge.service.LabelSplitMergeService; -import com.gaotao.modules.trans.entity.TransDetail; -import com.gaotao.modules.trans.entity.TransDetailDto; -import com.gaotao.modules.trans.entity.TransHeader; -import com.gaotao.modules.trans.entity.TransNoControl; +import com.gaotao.modules.trans.entity.*; import com.gaotao.modules.trans.service.TransDetailService; +import com.gaotao.modules.trans.service.TransDetailSubService; import com.gaotao.modules.trans.service.TransHeaderService; import com.gaotao.modules.trans.service.TransNoControlService; import org.slf4j.Logger; @@ -47,6 +46,9 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl getStockInfoByLabelCode(String labelCode, String site, String warehouseId) { logger.info("根据标签条码获取库存信息,标签条码: {}, 站点: {}, 仓库: {}", labelCode, site, warehouseId); @@ -114,7 +116,7 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl result = new HashMap<>(); result.put("newLabelCode", newLabelCode); @@ -176,6 +178,8 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl transDetailList = new ArrayList<>(); // 原标签明细记录(减少数量) @@ -315,7 +317,7 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl subDetailList = new ArrayList<>(); + + TransDetailSub originalSubDetail = new TransDetailSub(); + originalSubDetail.setSite(site); + originalSubDetail.setTransNo(transNo); + originalSubDetail.setItemNo(1.0); + originalSubDetail.setSubNo(originalLabelCode); + originalSubDetail.setSubQty(Double.valueOf(splitQuantity)); + originalSubDetail.setDirection("-"); + originalSubDetail.setOrderRef2(buNo); + originalSubDetail.setOrderRef3(batchNo); + originalSubDetail.setOrderRef4(warehouseId); + originalSubDetail.setOrderRef5(locationCode); + subDetailList.add(originalSubDetail); + + TransDetailSub newSubDetail = new TransDetailSub(); + newSubDetail.setSite(site); + newSubDetail.setTransNo(transNo); + newSubDetail.setItemNo(2.0); + newSubDetail.setSubNo(newLabelCode); + newSubDetail.setSubQty(Double.valueOf(splitQuantity)); + newSubDetail.setDirection("+"); + newSubDetail.setOrderRef2(buNo); + newSubDetail.setOrderRef3(batchNo); + newSubDetail.setOrderRef4(warehouseId); + newSubDetail.setOrderRef5(locationCode); + subDetailList.add(newSubDetail); + + boolean success = transDetailSubService.saveBatch(subDetailList); + if (!success) { + throw new RuntimeException("子明细记录保存失败"); + } + logger.info("子明细记录生成成功,共生成 {} 条子明细记录", subDetailList.size()); } /** * 生成标签合并事务明细记录 */ private void generateMergeTransactionDetails(String transNo, String sourceLabelCode, String targetLabelCode, - String partNo, String batchNo, Float sourceQuantity, Float targetQuantity, Float mergedQuantity, String site) { + String partNo, String batchNo, Float sourceQuantity, Float targetQuantity, Float mergedQuantity, String site, String buNo) { logger.info("开始生成标签合并事务明细记录,事务单号: {}", transNo); List transDetailList = new ArrayList<>(); @@ -364,7 +405,7 @@ public class LabelSplitMergeServiceImpl extends ServiceImpl subDetailList = new ArrayList<>(); + + TransDetailSub originalSubDetail = new TransDetailSub(); + originalSubDetail.setSite(site); + originalSubDetail.setTransNo(transNo); + originalSubDetail.setItemNo(1.0); + originalSubDetail.setSubNo(sourceLabelCode); + originalSubDetail.setSubQty(Double.valueOf(targetQuantity)); + originalSubDetail.setDirection("-"); + originalSubDetail.setOrderRef2(buNo); + originalSubDetail.setOrderRef3(batchNo); + originalSubDetail.setOrderRef4(warehouseId); + originalSubDetail.setOrderRef5(locationCode); + subDetailList.add(originalSubDetail); + + TransDetailSub newSubDetail = new TransDetailSub(); + newSubDetail.setSite(site); + newSubDetail.setTransNo(transNo); + newSubDetail.setItemNo(2.0); + newSubDetail.setSubNo(targetLabelCode); + newSubDetail.setSubQty(Double.valueOf(mergedQuantity)); + newSubDetail.setDirection("+"); + newSubDetail.setOrderRef2(buNo); + newSubDetail.setOrderRef3(batchNo); + newSubDetail.setOrderRef4(warehouseId); + newSubDetail.setOrderRef5(locationCode); + subDetailList.add(newSubDetail); + + boolean success = transDetailSubService.saveBatch(subDetailList); + if (!success) { + throw new RuntimeException("子明细记录保存失败"); } + logger.info("子明细记录生成成功,共生成 {} 条子明细记录", subDetailList.size()); } } diff --git a/src/main/java/com/gaotao/modules/propertyChange/controller/PropertyChangeController.java b/src/main/java/com/gaotao/modules/propertyChange/controller/PropertyChangeController.java index 6357a3c..64de135 100644 --- a/src/main/java/com/gaotao/modules/propertyChange/controller/PropertyChangeController.java +++ b/src/main/java/com/gaotao/modules/propertyChange/controller/PropertyChangeController.java @@ -2,6 +2,7 @@ package com.gaotao.modules.propertyChange.controller; import com.gaotao.common.utils.R; import com.gaotao.modules.propertyChange.service.PropertyChangeService; +import com.gaotao.modules.toolman.entity.Location; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -10,6 +11,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.List; import java.util.Map; /** @@ -44,11 +46,9 @@ public class PropertyChangeController { if (labelCode == null || labelCode.trim().isEmpty()) { return R.error("标签条码不能为空"); } - if (site == null || site.trim().isEmpty()) { return R.error("站点不能为空"); } - if (warehouseId == null || warehouseId.trim().isEmpty()) { return R.error("仓库ID不能为空"); } @@ -115,6 +115,14 @@ public class PropertyChangeController { if (!hasLocationChange && !hasProductionDateChange && !hasExpiryDateChange) { return R.error("没有检测到属性变动,请修改后再提交"); } + + if (hasLocationChange) { + // 如果变动了库位,检查新库位是否存在且可用 + List locationInfo = propertyChangeService.getLocationInfoByWarehouseId(site, buNo, warehouseId, newLocationId); + if (locationInfo.isEmpty()) { + return R.error("新库位不存在或不属于当前仓库,请检查库位号"); + } + } // 设置操作人(这里可以从session或token中获取) params.put("operator", "PDA用户"); // 实际项目中应该获取真实用户信息 diff --git a/src/main/java/com/gaotao/modules/propertyChange/dao/PropertyChangeMapper.java b/src/main/java/com/gaotao/modules/propertyChange/dao/PropertyChangeMapper.java index 69956e9..e1aa624 100644 --- a/src/main/java/com/gaotao/modules/propertyChange/dao/PropertyChangeMapper.java +++ b/src/main/java/com/gaotao/modules/propertyChange/dao/PropertyChangeMapper.java @@ -2,9 +2,11 @@ package com.gaotao.modules.propertyChange.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.gaotao.modules.propertyChange.entity.PropertyChangeEntity; +import com.gaotao.modules.toolman.entity.Location; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.List; import java.util.Map; /** @@ -33,4 +35,6 @@ public interface PropertyChangeMapper extends BaseMapper { * @return 更新行数 */ int updateStockProperties(@Param("params") Map params); + + List getLocationInfoByWarehouseId(@Param("site") String site, @Param("buNo") String buNo, @Param("warehouseId") String warehouseId, @Param("newLocationId") String newLocationId); } \ No newline at end of file diff --git a/src/main/java/com/gaotao/modules/propertyChange/service/PropertyChangeService.java b/src/main/java/com/gaotao/modules/propertyChange/service/PropertyChangeService.java index 0df0ecd..f8250fa 100644 --- a/src/main/java/com/gaotao/modules/propertyChange/service/PropertyChangeService.java +++ b/src/main/java/com/gaotao/modules/propertyChange/service/PropertyChangeService.java @@ -2,7 +2,9 @@ package com.gaotao.modules.propertyChange.service; import com.baomidou.mybatisplus.extension.service.IService; import com.gaotao.modules.propertyChange.entity.PropertyChangeEntity; +import com.gaotao.modules.toolman.entity.Location; +import java.util.List; import java.util.Map; /** @@ -28,4 +30,6 @@ public interface PropertyChangeService extends IService { * @return 操作结果 */ boolean savePropertyChange(Map params); + + List getLocationInfoByWarehouseId(String site, String buNo, String warehouseId, String newLocationId); } \ No newline at end of file diff --git a/src/main/java/com/gaotao/modules/propertyChange/service/impl/PropertyChangeServiceImpl.java b/src/main/java/com/gaotao/modules/propertyChange/service/impl/PropertyChangeServiceImpl.java index 711a422..4b66fdb 100644 --- a/src/main/java/com/gaotao/modules/propertyChange/service/impl/PropertyChangeServiceImpl.java +++ b/src/main/java/com/gaotao/modules/propertyChange/service/impl/PropertyChangeServiceImpl.java @@ -5,10 +5,13 @@ import com.gaotao.common.utils.DateUtils; import com.gaotao.modules.propertyChange.dao.PropertyChangeMapper; import com.gaotao.modules.propertyChange.entity.PropertyChangeEntity; import com.gaotao.modules.propertyChange.service.PropertyChangeService; +import com.gaotao.modules.toolman.entity.Location; import com.gaotao.modules.trans.entity.TransDetail; import com.gaotao.modules.trans.entity.TransDetailDto; +import com.gaotao.modules.trans.entity.TransDetailSub; import com.gaotao.modules.trans.entity.TransHeader; import com.gaotao.modules.trans.service.TransDetailService; +import com.gaotao.modules.trans.service.TransDetailSubService; import com.gaotao.modules.trans.service.TransHeaderService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,11 +22,7 @@ import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * 属性变动服务实现类 @@ -45,6 +44,9 @@ public class PropertyChangeServiceImpl extends ServiceImpl getLocationInfoByWarehouseId(String site, String buNo, String warehouseId, String newLocationId) { + List locationList = propertyChangeMapper.getLocationInfoByWarehouseId(site, buNo, warehouseId, newLocationId); + return locationList; + } + /** * 生成属性变动事务记录 */ @@ -150,25 +157,37 @@ public class PropertyChangeServiceImpl extends ServiceImpl> labels = new ArrayList<>(); + Map labelInfo = new HashMap<>(); + labelInfo.put("labelCode", labelCode); + labelInfo.put("partNo", partNo); + labelInfo.put("batchNo", batchNo); + labelInfo.put("quantity", quantity); + labelInfo.put("oldLocationId", oldLocationId); + labelInfo.put("newLocationId", newLocationId); + labelInfo.put("oldProductionDate", oldProductionDate); + labelInfo.put("newProductionDate", newProductionDate); + labelInfo.put("oldExpiryDate", oldExpiryDate); + labelInfo.put("newExpiryDate", newExpiryDate); + labels.add(labelInfo); + // 生成事务明细记录 - generatePropertyChangeTransactionDetails(transHeader.getTransno(), labelCode, partNo, batchNo, quantity, - oldLocationId, newLocationId, oldProductionDate, newProductionDate, oldExpiryDate, newExpiryDate, site); + List transDetailList = generatePropertyChangeTransactionDetails2(transHeader.getTransno(), labels, site, buNo); + logger.info("属性变动事务记录生成完成,事务单号: {}, 标签条码: {}", transHeader.getTransno(), labelCode); - logger.info("属性变动事务记录生成完成,事务单号: {}, 标签条码: {}", - transHeader.getTransno(), labelCode); + // 生成事务子明细记录 + addSubTransactionDetails(transHeader.getTransno(), labels, site, buNo, transDetailList, warehouseId); + logger.info("属性变动事务子记录生成完成,事务单号: {}", transHeader.getTransno()); } catch (Exception e) { logger.error("生成属性变动事务记录失败", e); @@ -179,11 +198,11 @@ public class PropertyChangeServiceImpl extends ServiceImpl transDetailList = new ArrayList<>(); + double itemNo = 1.0; // 行号从1开始 // 库位变动明细 @@ -246,4 +265,113 @@ public class PropertyChangeServiceImpl extends ServiceImpl generatePropertyChangeTransactionDetails2(String transNo, List> labels ,String site, String buNo) { + logger.info("开始生成属性变动事务明细记录,事务单号: {}", transNo); + List transDetailList = new ArrayList<>(); + + // 统计每个partNo的数量总和 + Map partNoQuantityMap = new HashMap<>(); + for (Map label : labels) { + String partNo = (String) label.get("partNo"); + Object quantityObj = label.get("quantity"); + BigDecimal quantity = BigDecimal.ZERO; + if (quantityObj != null) { + if (quantityObj instanceof BigDecimal) { + quantity = (BigDecimal) quantityObj; + } else if (quantityObj instanceof Number) { + quantity = new BigDecimal(quantityObj.toString()); + } else { + quantity = new BigDecimal(quantityObj.toString()); + } + } + partNoQuantityMap.put(partNo, partNoQuantityMap.getOrDefault(partNo, BigDecimal.ZERO).add(quantity)); + } + // 构建合并后的事务明细 + double itemNo = 1.0; + for (Map.Entry entry : partNoQuantityMap.entrySet()) { + String partNo = entry.getKey(); + BigDecimal quantity = entry.getValue(); + TransDetail transDetail = new TransDetail(); + transDetail.setSite(site); + transDetail.setTransno(transNo); + transDetail.setItemno(itemNo); + transDetail.setPartno(partNo); + transDetail.setTransqty(quantity); + transDetail.setDirection("M"); + transDetail.setOrderref2(buNo); + transDetail.setRemark("属性变动"); + transDetailList.add(transDetail); + itemNo += 1.0; + } + + // 批量保存事务明细记录 + if (!transDetailList.isEmpty()) { + boolean success = transDetailService.saveBatch(transDetailList); + if (!success) { + throw new RuntimeException("事务明细记录保存失败"); + } + logger.info("事务明细记录生成成功,共生成 {} 条明细记录", transDetailList.size()); + } + return transDetailList; + } + + /** + * 添加子明细数据 + * @param transNo 事务单号 + * @param labels 标签列表 + * @param site 站点 + * @param buNo 业务单元 + * @param transDetailList 明细记录列表,用于获取正确的 itemNo + */ + private void addSubTransactionDetails(String transNo, List> labels, String site, String buNo, List transDetailList, String warehouseId) { + logger.info("开始添加子明细数据,事务单号: {}, 标签数量: {}", transNo, labels.size()); + + // 创建 partNo 到 itemNo 的映射 + Map partNoToItemNoMap = new HashMap<>(); + for (TransDetail detail : transDetailList) { + partNoToItemNoMap.put(detail.getPartno(), detail.getItemno()); + } + + List subDetailList = new ArrayList<>(); + for (Map label : labels) { + String partNo = (String) label.get("partNo"); + String labelCode = (String) label.get("labelCode"); // subNo + String batchNo = (String) label.get("batchNo"); // orderRef3 + String locationCode = (label.get("newLocationId") != null && !((String)label.get("newLocationId")).isEmpty()) ? (String) label.get("newLocationId") : (String) label.get("oldLocationId"); // orderRef5 + Object quantityObj = label.get("quantity"); // 标签数量 + Double quantity = quantityObj == null ? 0.0 : Double.parseDouble(quantityObj.toString()); + // 获取对应的明细 itemNo + Double itemNo = partNoToItemNoMap.get(partNo); + if (itemNo == null) { + logger.warn("未找到物料 {} 对应的明细记录,跳过该标签 {}", partNo, labelCode); + continue; + } + + TransDetailSub transDetail = new TransDetailSub(); + transDetail.setSite(site); + transDetail.setTransNo(transNo); + transDetail.setItemNo(itemNo); // 使用明细的 itemNo + transDetail.setSubNo(labelCode); + transDetail.setSubQty(quantity); + transDetail.setDirection("M"); + transDetail.setOrderRef2(buNo); + transDetail.setOrderRef3(batchNo); + transDetail.setOrderRef4(warehouseId); + transDetail.setOrderRef5(locationCode); + subDetailList.add(transDetail); + } + + if (!subDetailList.isEmpty()) { + boolean success = transDetailSubService.saveBatch(subDetailList); + if (!success) { + throw new RuntimeException("子明细记录保存失败"); + } + logger.info("子明细记录生成成功,共生成 {} 条子明细记录", subDetailList.size()); + } + } + } diff --git a/src/main/resources/mapper/labelSplitMerge/LabelSplitMergeMapper.xml b/src/main/resources/mapper/labelSplitMerge/LabelSplitMergeMapper.xml index 3f8362f..76b0063 100644 --- a/src/main/resources/mapper/labelSplitMerge/LabelSplitMergeMapper.xml +++ b/src/main/resources/mapper/labelSplitMerge/LabelSplitMergeMapper.xml @@ -16,6 +16,7 @@ s.roll_no as labelCode, s.in_qty as labelQuantity, s.status, + s.status_tb as statusTb, s.manufacture_date as productionDate, s.expired_date as expiryDate, s.freeze_flag as freezeFlag, diff --git a/src/main/resources/mapper/propertyChange/PropertyChangeMapper.xml b/src/main/resources/mapper/propertyChange/PropertyChangeMapper.xml index cf4da69..ce13313 100644 --- a/src/main/resources/mapper/propertyChange/PropertyChangeMapper.xml +++ b/src/main/resources/mapper/propertyChange/PropertyChangeMapper.xml @@ -51,4 +51,14 @@ AND warehouse_id = #{params.warehouseId} +