demand: 扫描漏组批次supplierCode线程安全问题修复

committer: heyu
This commit is contained in:
aike 2025-07-11 09:01:08 +08:00
parent 4341a91a90
commit cbf8f70fa9

View File

@ -4585,13 +4585,29 @@ public class EmisBaseService {
String key = batch.getStartSiteCode() + "_" + batch.getNextSiteCode(); String key = batch.getStartSiteCode() + "_" + batch.getNextSiteCode();
if (mergedBatches.containsKey(key)) { if (mergedBatches.containsKey(key)) {
EmisTmsSiteBatch existingBatch = mergedBatches.get(key); EmisTmsSiteBatch existingBatch = mergedBatches.get(key);
String existingSupplier = existingBatch.getSupplierCode(); // 合并supplierCode,去重、排序
String newSupplier = batch.getSupplierCode(); Set<String> supplierSet = new TreeSet<>();
if (!existingSupplier.equals(newSupplier)) { if (StringUtils.isNotBlank(existingBatch.getSupplierCode())) {
existingBatch.setSupplierCode(existingSupplier + "," + newSupplier); supplierSet.addAll(Arrays.asList(existingBatch.getSupplierCode().split(",")));
} }
if (StringUtils.isNotBlank(batch.getSupplierCode())) {
supplierSet.addAll(Arrays.asList(batch.getSupplierCode().split(",")));
}
// 新建一个新的Batch对象,复制属性,保证线程安全
EmisTmsSiteBatch newBatch = new EmisTmsSiteBatch();
BeanUtils.copyProperties(existingBatch, newBatch);
newBatch.setSupplierCode(String.join(",", supplierSet));
mergedBatches.put(key, newBatch);
} else { } else {
mergedBatches.put(key, batch); // 新建对象,避免外部引用被修改
EmisTmsSiteBatch newBatch = new EmisTmsSiteBatch();
BeanUtils.copyProperties(batch, newBatch);
Set<String> supplierSet = new TreeSet<>();
if (StringUtils.isNotBlank(batch.getSupplierCode())) {
supplierSet.addAll(Arrays.asList(batch.getSupplierCode().split(",")));
}
newBatch.setSupplierCode(String.join(",", supplierSet));
mergedBatches.put(key, newBatch);
} }
} }
waybillBatches = new ArrayList<>(mergedBatches.values()); waybillBatches = new ArrayList<>(mergedBatches.values());