优化
This commit is contained in:
-19
@@ -52,25 +52,6 @@ public class InboundCartonLabelRepository {
|
||||
.eq(InboundCartonLabelEntity::getBoxCode, boxCode));
|
||||
}
|
||||
|
||||
public int nextVersion(long tenantId, long inboundId) {
|
||||
InboundCartonLabelEntity latest = labels.selectOne(new LambdaQueryWrapper<InboundCartonLabelEntity>()
|
||||
.select(InboundCartonLabelEntity::getLabelVersion)
|
||||
.eq(InboundCartonLabelEntity::getTenantId, tenantId)
|
||||
.eq(InboundCartonLabelEntity::getInboundId, inboundId)
|
||||
.orderByDesc(InboundCartonLabelEntity::getLabelVersion)
|
||||
.last("LIMIT 1"));
|
||||
return latest == null || latest.getLabelVersion() == null ? 1 : latest.getLabelVersion() + 1;
|
||||
}
|
||||
|
||||
public void voidActive(long tenantId, long inboundId, java.time.LocalDateTime at) {
|
||||
labels.update(null, new LambdaUpdateWrapper<InboundCartonLabelEntity>()
|
||||
.eq(InboundCartonLabelEntity::getTenantId, tenantId)
|
||||
.eq(InboundCartonLabelEntity::getInboundId, inboundId)
|
||||
.eq(InboundCartonLabelEntity::getBatchStatus, "ACTIVE")
|
||||
.set(InboundCartonLabelEntity::getBatchStatus, "VOID")
|
||||
.set(InboundCartonLabelEntity::getVoidedAt, at));
|
||||
}
|
||||
|
||||
public void initializeLegacyFingerprint(long tenantId, long inboundId, int version, String fingerprint) {
|
||||
labels.update(null, new LambdaUpdateWrapper<InboundCartonLabelEntity>()
|
||||
.eq(InboundCartonLabelEntity::getTenantId, tenantId)
|
||||
|
||||
@@ -59,8 +59,7 @@ public class InboundCartonLabelService implements CartonLabelBindingResolver {
|
||||
return batch(inbound, consistent);
|
||||
}
|
||||
if (existingFingerprint.equals(fingerprint)) return batch(inbound, consistent);
|
||||
repository.voidActive(tenantId, inboundId, LocalDateTime.now());
|
||||
existing.clear();
|
||||
return batch(inbound, consistent);
|
||||
}
|
||||
int total = cargoes.stream().mapToInt(this::requirePackageCount).sum();
|
||||
if (total < 1 || total > MAX_LABELS) {
|
||||
@@ -68,8 +67,7 @@ public class InboundCartonLabelService implements CartonLabelBindingResolver {
|
||||
}
|
||||
repository.updatePackageCount(tenantId, inboundId, total);
|
||||
inbound.setTotalPackageCount(total);
|
||||
int labelVersion = repository.nextVersion(tenantId, inboundId);
|
||||
requirePrintableInboundCode(inbound.getInboundCode(), total, labelVersion);
|
||||
requirePrintableInboundCode(inbound.getInboundCode(), total);
|
||||
|
||||
int cartonIndex = 0;
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
@@ -77,7 +75,7 @@ public class InboundCartonLabelService implements CartonLabelBindingResolver {
|
||||
int detailCount = requirePackageCount(cargo);
|
||||
for (int offset = 0; offset < detailCount; offset++) {
|
||||
cartonIndex++;
|
||||
InboundCartonLabelEntity label = label(inbound, cargo, total, cartonIndex, labelVersion, fingerprint, now);
|
||||
InboundCartonLabelEntity label = label(inbound, cargo, total, cartonIndex, fingerprint, now);
|
||||
repository.insert(label);
|
||||
existing.add(label);
|
||||
}
|
||||
@@ -148,7 +146,7 @@ public class InboundCartonLabelService implements CartonLabelBindingResolver {
|
||||
InboundCartonLabelEntity label = repository.findByBoxCode(tenantId, boxCode.trim());
|
||||
if (label == null) throw new BizException(ResultCode.NOT_FOUND, "箱号不存在");
|
||||
if ("VOID".equals(label.getBatchStatus())) {
|
||||
throw new BizException(ResultCode.CONFLICT, "箱唛版本已作废,请重新打印");
|
||||
throw new BizException(ResultCode.CONFLICT, "箱码已失效,请重新打印");
|
||||
}
|
||||
return label;
|
||||
}
|
||||
@@ -182,11 +180,11 @@ public class InboundCartonLabelService implements CartonLabelBindingResolver {
|
||||
return cargo.packageCount();
|
||||
}
|
||||
|
||||
private void requirePrintableInboundCode(String inboundCode, int total, int version) {
|
||||
private void requirePrintableInboundCode(String inboundCode, int total) {
|
||||
if (!StringUtils.hasText(inboundCode) || !inboundCode.matches("[A-Za-z0-9._:-]+")) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED, "入仓码不能生成可打印二维码");
|
||||
}
|
||||
String longest = inboundCode + "#V" + version + "#" + total + "-" + total;
|
||||
String longest = inboundCode + "#" + total + "-" + total;
|
||||
if (longest.codePointCount(0, longest.length()) > MAX_QR_CODE_POINTS) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED, "入仓码和箱号组合超过二维码长度限制");
|
||||
}
|
||||
@@ -194,7 +192,7 @@ public class InboundCartonLabelService implements CartonLabelBindingResolver {
|
||||
|
||||
private InboundCartonLabelEntity label(InboundOrderEntity inbound,
|
||||
OrderCargoClient.CargoLabelBinding cargo,
|
||||
int total, int index, int labelVersion, String fingerprint,
|
||||
int total, int index, String fingerprint,
|
||||
LocalDateTime now) {
|
||||
InboundCartonLabelEntity label = new InboundCartonLabelEntity();
|
||||
label.setId(IdWorker.getId());
|
||||
@@ -206,10 +204,10 @@ public class InboundCartonLabelService implements CartonLabelBindingResolver {
|
||||
label.setCargoName(cargo.cargoName());
|
||||
label.setDetailPackageCount(cargo.packageCount());
|
||||
label.setInboundCode(inbound.getInboundCode());
|
||||
label.setBoxCode(inbound.getInboundCode() + "#V" + labelVersion + "#" + total + "-" + index);
|
||||
label.setBoxCode(inbound.getInboundCode() + "#" + total + "-" + index);
|
||||
label.setTotalCartonCount(total);
|
||||
label.setCartonIndex(index);
|
||||
label.setLabelVersion(labelVersion);
|
||||
label.setLabelVersion(1);
|
||||
label.setBatchStatus("ACTIVE");
|
||||
label.setCargoFingerprint(fingerprint);
|
||||
label.setLengthCm(cargo.lengthCm());
|
||||
|
||||
Reference in New Issue
Block a user