|
|
@ -554,6 +554,167 @@ public class PhysicalInventoryServiceImpl extends ServiceImpl<PhysicalInventoryM |
|
|
return countLabels.size(); |
|
|
return countLabels.size(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
public int quickAddMaterialByPartNo(CountHeaderData query) { |
|
|
|
|
|
log.info("quickAddMaterialByPartNo 开始,site: {}, countNo: {}, partNo: {}", |
|
|
|
|
|
query.getSite(), query.getCountNo(), query.getSearchPartNo()); |
|
|
|
|
|
|
|
|
|
|
|
// 1. 参数校验 - rqrq |
|
|
|
|
|
if (!StringUtils.hasText(query.getSite())) { |
|
|
|
|
|
throw new RuntimeException("工厂编码不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
if (!StringUtils.hasText(query.getCountNo())) { |
|
|
|
|
|
throw new RuntimeException("盘点单号不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
if (!StringUtils.hasText(query.getSearchPartNo())) { |
|
|
|
|
|
throw new RuntimeException("物料号不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 2. 校验盘点单状态 - rqrq |
|
|
|
|
|
CountHeaderData header = getCountHeaderByNo(query.getSite(), query.getCountNo()); |
|
|
|
|
|
if (header == null) { |
|
|
|
|
|
throw new RuntimeException("盘点单不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
if (!CountHeader.STATUS_DRAFT.equals(header.getStatus())) { |
|
|
|
|
|
throw new RuntimeException("只有草稿状态的盘点单才能添加物料"); |
|
|
|
|
|
} |
|
|
|
|
|
if (!CountHeader.COUNT_TYPE_MANUAL.equals(header.getCountType())) { |
|
|
|
|
|
throw new RuntimeException("只有手工盘点单才能添加物料"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 3. 获取当前盘点单已有的标签(用于去重)- rqrq |
|
|
|
|
|
CountLabelData labelQuery = new CountLabelData(); |
|
|
|
|
|
labelQuery.setSite(query.getSite()); |
|
|
|
|
|
labelQuery.setCountNo(query.getCountNo()); |
|
|
|
|
|
List<CountLabelData> existingLabels = baseMapper.searchCountLabelList(labelQuery); |
|
|
|
|
|
Set<String> existingUnitIds = existingLabels.stream() |
|
|
|
|
|
.map(CountLabelData::getUnitId) |
|
|
|
|
|
.collect(Collectors.toSet()); |
|
|
|
|
|
|
|
|
|
|
|
// 4. 根据物料号精确查询所有标签(在立库中的)- rqrq |
|
|
|
|
|
CountMaterialSummary labelQueryParam = new CountMaterialSummary(); |
|
|
|
|
|
labelQueryParam.setSite(query.getSite()); |
|
|
|
|
|
labelQueryParam.setSearchPartNo(query.getSearchPartNo()); // 精确匹配 |
|
|
|
|
|
|
|
|
|
|
|
List<CountLabelInfo> allLabels = baseMapper.queryLabelsByMaterial(labelQueryParam); |
|
|
|
|
|
|
|
|
|
|
|
// 5. 过滤出未在盘点单中的标签 - rqrq |
|
|
|
|
|
List<CountLabelInfo> newLabels = allLabels.stream() |
|
|
|
|
|
.filter(label -> query.getSearchPartNo().equals(label.getPartNo())) // 精确匹配物料号 |
|
|
|
|
|
.filter(label -> !existingUnitIds.contains(label.getUnitId())) |
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
if (newLabels.isEmpty()) { |
|
|
|
|
|
throw new RuntimeException("没有找到新的可添加标签(物料号: " + query.getSearchPartNo() + ")"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 6. 收集涉及的栈板 - rqrq |
|
|
|
|
|
Set<String> newPallets = new LinkedHashSet<>(); |
|
|
|
|
|
for (CountLabelInfo label : newLabels) { |
|
|
|
|
|
if (label.getPalletId() != null) { |
|
|
|
|
|
newPallets.add(label.getPalletId()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.info("新增标签数: {},涉及托盘数: {}", newLabels.size(), newPallets.size()); |
|
|
|
|
|
|
|
|
|
|
|
// 7. 创建盘点标签子表 - rqrq |
|
|
|
|
|
List<CountLabel> countLabels = new ArrayList<>(); |
|
|
|
|
|
for (CountLabelInfo labelInfo : newLabels) { |
|
|
|
|
|
CountLabel countLabel = createCountLabel(query.getSite(), query.getCountNo(), labelInfo, |
|
|
|
|
|
CountLabel.LABEL_TYPE_ASSIGNED, query.getUsername()); |
|
|
|
|
|
countLabels.add(countLabel); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!countLabels.isEmpty()) { |
|
|
|
|
|
baseMapper.batchInsertCountLabel(countLabels); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 8. 创建/更新盘点栈板子表 - rqrq |
|
|
|
|
|
Integer maxSeqNo = baseMapper.getMaxSeqNo(query.getSite(), query.getCountNo()); |
|
|
|
|
|
int seqNo = (maxSeqNo == null ? 0 : maxSeqNo) + 1; |
|
|
|
|
|
|
|
|
|
|
|
List<CountPallet> countPallets = new ArrayList<>(); |
|
|
|
|
|
for (String palletId : newPallets) { |
|
|
|
|
|
int exists = baseMapper.checkCountPalletExists(query.getSite(), query.getCountNo(), palletId); |
|
|
|
|
|
if (exists == 0) { |
|
|
|
|
|
int labelCount = (int) countLabels.stream() |
|
|
|
|
|
.filter(l -> palletId.equals(l.getPalletId())) |
|
|
|
|
|
.count(); |
|
|
|
|
|
|
|
|
|
|
|
Integer locationZ = 1; |
|
|
|
|
|
CountLabelInfo firstLabel = newLabels.stream() |
|
|
|
|
|
.filter(l -> palletId.equals(l.getPalletId())) |
|
|
|
|
|
.findFirst() |
|
|
|
|
|
.orElse(null); |
|
|
|
|
|
if (firstLabel != null && firstLabel.getLocationZ() != null) { |
|
|
|
|
|
locationZ = firstLabel.getLocationZ().intValue(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CountPallet countPallet = new CountPallet(); |
|
|
|
|
|
countPallet.setSite(query.getSite()); |
|
|
|
|
|
countPallet.setCountNo(query.getCountNo()); |
|
|
|
|
|
countPallet.setSeqNo(seqNo++); |
|
|
|
|
|
countPallet.setPalletId(palletId); |
|
|
|
|
|
countPallet.setCountFlag(CountPallet.COUNT_FLAG_NO); |
|
|
|
|
|
countPallet.setLabelCount(labelCount); |
|
|
|
|
|
countPallet.setCheckedCount(0); |
|
|
|
|
|
countPallet.setLocationZ(locationZ); |
|
|
|
|
|
countPallet.setCreatedBy(query.getUsername()); |
|
|
|
|
|
countPallets.add(countPallet); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!countPallets.isEmpty()) { |
|
|
|
|
|
baseMapper.batchInsertCountPallet(countPallets); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.info("quickAddMaterialByPartNo 结束,新增标签数: {}", countLabels.size()); |
|
|
|
|
|
return countLabels.size(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
public int deleteMaterialByPartNo(CountHeaderData query) { |
|
|
|
|
|
log.info("deleteMaterialByPartNo 开始,site: {}, countNo: {}, partNo: {}", |
|
|
|
|
|
query.getSite(), query.getCountNo(), query.getSearchPartNo()); |
|
|
|
|
|
|
|
|
|
|
|
// 1. 参数校验 - rqrq |
|
|
|
|
|
if (!StringUtils.hasText(query.getSite())) { |
|
|
|
|
|
throw new RuntimeException("工厂编码不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
if (!StringUtils.hasText(query.getCountNo())) { |
|
|
|
|
|
throw new RuntimeException("盘点单号不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
if (!StringUtils.hasText(query.getSearchPartNo())) { |
|
|
|
|
|
throw new RuntimeException("物料号不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 2. 校验盘点单状态 - rqrq |
|
|
|
|
|
CountHeaderData header = getCountHeaderByNo(query.getSite(), query.getCountNo()); |
|
|
|
|
|
if (header == null) { |
|
|
|
|
|
throw new RuntimeException("盘点单不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
if (!CountHeader.STATUS_DRAFT.equals(header.getStatus())) { |
|
|
|
|
|
throw new RuntimeException("只有草稿状态的盘点单才能删除物料"); |
|
|
|
|
|
} |
|
|
|
|
|
if (!CountHeader.COUNT_TYPE_MANUAL.equals(header.getCountType())) { |
|
|
|
|
|
throw new RuntimeException("只有手工盘点单才能删除物料"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 3. 删除该物料的所有标签 - rqrq |
|
|
|
|
|
int deleteCount = baseMapper.deleteCountLabelByPartNo(query.getSite(), query.getCountNo(), query.getSearchPartNo()); |
|
|
|
|
|
log.info("已删除标签数: {}", deleteCount); |
|
|
|
|
|
|
|
|
|
|
|
// 4. 清理没有标签的栈板 - rqrq |
|
|
|
|
|
int cleanedPallets = baseMapper.deleteEmptyCountPallets(query.getSite(), query.getCountNo()); |
|
|
|
|
|
log.info("已清理空栈板数: {}", cleanedPallets); |
|
|
|
|
|
|
|
|
|
|
|
log.info("deleteMaterialByPartNo 结束,删除标签数: {}", deleteCount); |
|
|
|
|
|
return deleteCount; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public int releaseCount(CountHeaderData query) { |
|
|
public int releaseCount(CountHeaderData query) { |
|
|
|