优化
This commit is contained in:
@@ -3316,6 +3316,7 @@ CREATE TABLE fl_mojia_measurement_receipt (
|
||||
tenant_id bigint unsigned NOT NULL COMMENT '客户ID和数据隔离键',
|
||||
subject_id bigint unsigned NOT NULL COMMENT '设备应用操作主体ID',
|
||||
box_code varchar(128) NOT NULL COMMENT '设备扫描的原始箱码或不带#的SKU',
|
||||
inbound_code varchar(64) DEFAULT NULL COMMENT '箱码命中后的权威入仓码;SKU记录为空',
|
||||
measurement_kind varchar(16) NOT NULL DEFAULT 'BOX_LABEL' COMMENT '测量分流:BOX_LABEL箱唛;SKU一件代发SKU',
|
||||
scanned_shipment_id varchar(64) DEFAULT NULL COMMENT '设备从Amazon FBA箱标实扫的Shipment ID',
|
||||
length_cm decimal(12,3) NOT NULL COMMENT '设备实测长度cm',
|
||||
|
||||
+4
-3
@@ -35,15 +35,16 @@ public class PlatformMojiaSkuSyncController {
|
||||
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAuthority('platform:mojia-sku-sync:list')")
|
||||
@Operation(summary = "查询墨家一件代发SKU测量记录")
|
||||
@Operation(summary = "查询墨家机器全部上传记录")
|
||||
public ApiResponse<PageResult<MojiaSkuSyncDtos.Record>> page(
|
||||
@AuthenticationPrincipal AuthenticatedUser user,
|
||||
@RequestParam(required = false) String skuCode,
|
||||
@RequestParam(required = false) String code,
|
||||
@RequestParam(required = false) String measurementKind,
|
||||
@RequestParam(required = false) String syncStatus,
|
||||
@RequestParam(defaultValue = "1") @Min(1) long page,
|
||||
@RequestParam(defaultValue = "20") @Min(1) @Max(200) long size) {
|
||||
FirstlegScopeGuard.platform(user);
|
||||
return ApiResponse.success(service.page(new MojiaSkuSyncDtos.Query(skuCode, syncStatus, page, size)));
|
||||
return ApiResponse.success(service.page(new MojiaSkuSyncDtos.Query(code, measurementKind, syncStatus, page, size)));
|
||||
}
|
||||
@GetMapping("/config")
|
||||
@PreAuthorize("hasAuthority('platform:mojia-sku-sync:list')")
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.time.LocalDateTime;
|
||||
public final class MojiaSkuSyncDtos {
|
||||
private MojiaSkuSyncDtos() {}
|
||||
|
||||
public record Query(String skuCode, String syncStatus, long page, long size) {}
|
||||
public record Query(String code, String measurementKind, String syncStatus, long page, long size) {}
|
||||
|
||||
public record Config(boolean autoSyncEnabled) {}
|
||||
|
||||
@@ -25,7 +25,8 @@ public final class MojiaSkuSyncDtos {
|
||||
public record RetryRequest(@NotNull Integer revision) {}
|
||||
|
||||
public record Record(
|
||||
Long id, String skuCode, BigDecimal lengthCm, BigDecimal widthCm, BigDecimal heightCm,
|
||||
Long id, String measurementKind, String boxCode, String inboundCode, String skuCode,
|
||||
BigDecimal lengthCm, BigDecimal widthCm, BigDecimal heightCm,
|
||||
BigDecimal weightKg, Long imageFileId, LocalDateTime measuredAt, LocalDateTime receivedAt,
|
||||
String syncStatus, String syncFailureCode, String syncFailureReason, String lingxingSkuId,
|
||||
Integer revision, LocalDateTime updatedAt) {}
|
||||
|
||||
@@ -19,6 +19,7 @@ public class MojiaMeasurementReceiptEntity {
|
||||
private Long tenantId;
|
||||
private Long subjectId;
|
||||
private String boxCode;
|
||||
private String inboundCode;
|
||||
/** BOX_LABEL 表示现有箱唛链路;SKU 表示一件代发新品测量同步收件。 */
|
||||
private String measurementKind;
|
||||
private String scannedShipmentId;
|
||||
|
||||
@@ -14,14 +14,22 @@ import org.springframework.util.StringUtils;
|
||||
public class MojiaSkuSyncRepository {
|
||||
@Resource private MojiaMeasurementReceiptMapper mapper;
|
||||
|
||||
public PageResult<MojiaMeasurementReceiptEntity> page(String skuCode, String syncStatus,
|
||||
/** 保留仓储层旧测试/内部调用的四参数入口,统一查询改为全部上传记录。 */
|
||||
public PageResult<MojiaMeasurementReceiptEntity> page(String code, String syncStatus,
|
||||
long page, long size) {
|
||||
String normalizedSkuCode = StringUtils.hasText(skuCode) ? skuCode.trim() : null;
|
||||
return page(code, null, syncStatus, page, size);
|
||||
}
|
||||
|
||||
public PageResult<MojiaMeasurementReceiptEntity> page(String code, String measurementKind, String syncStatus,
|
||||
long page, long size) {
|
||||
String normalizedCode = StringUtils.hasText(code) ? code.trim() : null;
|
||||
return PageResult.from(mapper.selectPage(new Page<>(page, size),
|
||||
new LambdaQueryWrapper<MojiaMeasurementReceiptEntity>()
|
||||
.eq(MojiaMeasurementReceiptEntity::getMeasurementKind, "SKU")
|
||||
.eq(StringUtils.hasText(measurementKind), MojiaMeasurementReceiptEntity::getMeasurementKind, measurementKind)
|
||||
.eq(StringUtils.hasText(syncStatus), MojiaMeasurementReceiptEntity::getSyncStatus, syncStatus)
|
||||
.like(normalizedSkuCode != null, MojiaMeasurementReceiptEntity::getBoxCode, normalizedSkuCode)
|
||||
.and(normalizedCode != null, wrapper -> wrapper
|
||||
.like(MojiaMeasurementReceiptEntity::getBoxCode, normalizedCode)
|
||||
.or().like(MojiaMeasurementReceiptEntity::getInboundCode, normalizedCode))
|
||||
.orderByDesc(MojiaMeasurementReceiptEntity::getMeasuredAt)
|
||||
.orderByDesc(MojiaMeasurementReceiptEntity::getId)));
|
||||
}
|
||||
|
||||
+31
-1
@@ -111,7 +111,8 @@ public class MojiaMeasurementOpenApiService {
|
||||
throw exception;
|
||||
}
|
||||
if (platformBinding.warehouseId() != machineWarehouseId) {
|
||||
throw new BizException(ResultCode.FORBIDDEN, "箱号不属于当前设备绑定仓库");
|
||||
return saveUnmatched(app, request, image,
|
||||
new BizException(ResultCode.FORBIDDEN, "箱号不属于当前设备绑定仓库"));
|
||||
}
|
||||
CartonMeasurementResult result;
|
||||
try {
|
||||
@@ -132,6 +133,7 @@ public class MojiaMeasurementOpenApiService {
|
||||
correlation("requestId"), correlation("traceId"), safe(request.boxCode()),
|
||||
safe(request.machineNo()), request.length(), request.width(), request.height(),
|
||||
image.getSize(), result.measurementId(), result.itemId(), result.created());
|
||||
saveMatchedReceipt(app, request, result, platformBinding.binding().inboundCode());
|
||||
return new UploadResponse(true, true, null, result.measurementId(), result.itemId(),
|
||||
result.boxCode(), result.imageFileId(), result.created());
|
||||
} catch (RuntimeException exception) {
|
||||
@@ -146,6 +148,33 @@ public class MojiaMeasurementOpenApiService {
|
||||
}
|
||||
}
|
||||
|
||||
/** 每次箱码上传都保留一条设备收件流水,正式测量成功后补上权威入仓码。 */
|
||||
private void saveMatchedReceipt(AuthenticatedMeasurementApp app, UploadRequest request,
|
||||
CartonMeasurementResult result, String inboundCode) {
|
||||
MojiaMeasurementReceiptEntity receipt = new MojiaMeasurementReceiptEntity();
|
||||
receipt.setId(IdWorker.getId());
|
||||
receipt.setTenantId(app.tenantId());
|
||||
receipt.setSubjectId(app.subjectId());
|
||||
receipt.setBoxCode(request.boxCode().trim());
|
||||
receipt.setInboundCode(inboundCode);
|
||||
receipt.setMeasurementKind("BOX_LABEL");
|
||||
receipt.setScannedShipmentId(optionalTrim(request.shipmentId()));
|
||||
receipt.setLengthCm(request.length());
|
||||
receipt.setWidthCm(request.width());
|
||||
receipt.setHeightCm(request.height());
|
||||
receipt.setWeightKg(request.weightKg());
|
||||
receipt.setMachineNo(request.machineNo().trim());
|
||||
receipt.setMeasuredAt(request.measuredAt() == null ? LocalDateTime.now() : request.measuredAt());
|
||||
receipt.setImageFileId(result.imageFileId());
|
||||
receipt.setStatus("MATCHED");
|
||||
receipt.setRevision(1);
|
||||
receipt.setRequestId(correlation("requestId"));
|
||||
receipt.setTraceId(correlation("traceId"));
|
||||
receipt.setCreatedAt(LocalDateTime.now());
|
||||
receipt.setUpdatedAt(LocalDateTime.now());
|
||||
receipts.insert(receipt);
|
||||
}
|
||||
|
||||
private UploadResponse saveSkuPending(AuthenticatedMeasurementApp app, UploadRequest request,
|
||||
MultipartFile image) {
|
||||
long receiptId = IdWorker.getId();
|
||||
@@ -203,6 +232,7 @@ public class MojiaMeasurementOpenApiService {
|
||||
receipt.setTenantId(app.tenantId());
|
||||
receipt.setSubjectId(app.subjectId());
|
||||
receipt.setBoxCode(request.boxCode().trim());
|
||||
receipt.setMeasurementKind("BOX_LABEL");
|
||||
receipt.setScannedShipmentId(optionalTrim(request.shipmentId()));
|
||||
receipt.setLengthCm(request.length());
|
||||
receipt.setWidthCm(request.width());
|
||||
|
||||
@@ -42,7 +42,7 @@ public class MojiaSkuSyncService {
|
||||
|
||||
public PageResult<MojiaSkuSyncDtos.Record> page(MojiaSkuSyncDtos.Query query) {
|
||||
PageResult<MojiaMeasurementReceiptEntity> source = repository.page(
|
||||
query.skuCode(), query.syncStatus(), query.page(), query.size());
|
||||
query.code(), query.measurementKind(), query.syncStatus(), query.page(), query.size());
|
||||
return new PageResult<>(source.records().stream().map(MojiaSkuSyncService::view).toList(),
|
||||
source.page(), source.size(), source.total(), source.pages());
|
||||
}
|
||||
@@ -104,7 +104,9 @@ public class MojiaSkuSyncService {
|
||||
}
|
||||
|
||||
private static MojiaSkuSyncDtos.Record view(MojiaMeasurementReceiptEntity value) {
|
||||
return new MojiaSkuSyncDtos.Record(value.getId(), value.getBoxCode(), value.getLengthCm(),
|
||||
return new MojiaSkuSyncDtos.Record(value.getId(), value.getMeasurementKind(), value.getBoxCode(),
|
||||
value.getInboundCode(), "SKU".equals(value.getMeasurementKind()) ? value.getBoxCode() : null,
|
||||
value.getLengthCm(),
|
||||
value.getWidthCm(), value.getHeightCm(), value.getWeightKg(), value.getImageFileId(),
|
||||
value.getMeasuredAt(), value.getCreatedAt(), value.getSyncStatus(), value.getSyncFailureCode(),
|
||||
value.getSyncFailureReason(), value.getLingxingSkuId(), value.getRevision(), value.getUpdatedAt());
|
||||
|
||||
@@ -329,6 +329,7 @@ CREATE TABLE IF NOT EXISTS fl_mojia_measurement_receipt (
|
||||
tenant_id BIGINT UNSIGNED NOT NULL COMMENT '客户ID和数据隔离键',
|
||||
subject_id BIGINT UNSIGNED NOT NULL COMMENT '设备应用操作主体ID',
|
||||
box_code VARCHAR(128) NOT NULL COMMENT '设备扫描的原始箱码',
|
||||
inbound_code VARCHAR(64) NULL COMMENT '箱码命中后的权威入仓码;SKU记录为空',
|
||||
measurement_kind VARCHAR(16) NOT NULL DEFAULT 'BOX_LABEL' COMMENT '测量分流:BOX_LABEL箱唛;SKU一件代发SKU',
|
||||
scanned_shipment_id VARCHAR(64) NULL COMMENT '设备从Amazon FBA箱标实扫的Shipment ID',
|
||||
length_cm DECIMAL(12,3) NOT NULL COMMENT '设备实测长度cm',
|
||||
|
||||
@@ -108,6 +108,19 @@ DEALLOCATE PREPARE recent_schema_stmt;
|
||||
-- Firstleg:墨家测量收件箱扩展为箱唛/SKU 双分流
|
||||
-- ============================================================================
|
||||
|
||||
SET @ddl = IF(
|
||||
NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = DATABASE() AND table_name = 'fl_mojia_measurement_receipt'
|
||||
AND column_name = 'inbound_code'
|
||||
),
|
||||
'ALTER TABLE fl_mojia_measurement_receipt ADD COLUMN inbound_code VARCHAR(64) NULL COMMENT ''箱码命中后的权威入仓码;SKU记录为空'' AFTER box_code',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE recent_schema_stmt FROM @ddl;
|
||||
EXECUTE recent_schema_stmt;
|
||||
DEALLOCATE PREPARE recent_schema_stmt;
|
||||
|
||||
SET @ddl = IF(
|
||||
NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
|
||||
Reference in New Issue
Block a user