feat: control lingxing sku sync with nacos

This commit is contained in:
2026-09-22 11:32:37 +08:00
parent 0c7ff73e2d
commit 212262e300
7 changed files with 42 additions and 3 deletions
+3
View File
@@ -35,6 +35,9 @@ baiyue:
lease-seconds: ${LASTLEG_OUTBOX_RELAY_LEASE_SECONDS:60}
retry-seconds: ${LASTLEG_OUTBOX_RELAY_RETRY_SECONDS:30}
firstleg:
lingxing:
# 安全默认关闭;开启后自动任务才允许调用领星新品维护接口。
auto-sync-enabled: ${LINGXING_AUTO_SYNC_ENABLED:false}
inbound:
allow-rejected-measurement: false
default-pallet-capacity-cbm: ${DEFAULT_PALLET_CAPACITY_CBM:1.200000}
+2
View File
@@ -22,6 +22,8 @@ baiyue.carrier-schedule.scheduler.batch-size: ${CARRIER_SCHEDULE_BATCH_SIZE:20}
baiyue.carrier-schedule.scheduler.max-tasks-per-trigger: ${CARRIER_SCHEDULE_MAX_TASKS_PER_TRIGGER:2000}
baiyue.carrier-schedule.scheduler.lease-duration: ${CARRIER_SCHEDULE_LEASE_DURATION:PT5M}
firstleg:
lingxing:
auto-sync-enabled: ${LINGXING_AUTO_SYNC_ENABLED:false}
inbound:
allow-rejected-measurement: false
default-pallet-capacity-cbm: ${DEFAULT_PALLET_CAPACITY_CBM:1.200000}
@@ -0,0 +1,18 @@
package com.baiyue.firstleg.config;
import lombok.Getter;
import lombok.Setter;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/** 领星新品自动同步策略;默认关闭,开关由 Nacos 注入。 */
@Getter
@Setter
@Component
@RefreshScope
@ConfigurationProperties(prefix = "firstleg.lingxing")
public class LingxingSyncProperties {
/** 安全默认值:墨家数据只入库,必须人工点击推送。 */
private boolean autoSyncEnabled = false;
}
@@ -34,6 +34,14 @@ public class PlatformMojiaSkuSyncController {
FirstlegScopeGuard.platform(user);
return ApiResponse.success(service.page(new MojiaSkuSyncDtos.Query(skuCode, syncStatus, page, size)));
}
@GetMapping("/config")
@PreAuthorize("hasAuthority('platform:mojia-sku-sync:list')")
@Operation(summary = "查询领星新品自动同步配置")
public ApiResponse<MojiaSkuSyncDtos.Config> config(
@AuthenticationPrincipal AuthenticatedUser user) {
FirstlegScopeGuard.platform(user);
return ApiResponse.success(service.config());
}
@PutMapping("/{id}")
@PreAuthorize("hasAuthority('platform:mojia-sku-sync:edit')")
@@ -47,7 +55,7 @@ public class PlatformMojiaSkuSyncController {
@PostMapping("/{id}/retry")
@PreAuthorize("hasAuthority('platform:mojia-sku-sync:retry')")
@Operation(summary = "重新推送失败的墨家一件代发SKU")
@Operation(summary = "人工推送墨家一件代发SKU")
public ApiResponse<MojiaSkuSyncDtos.Record> retry(
@AuthenticationPrincipal AuthenticatedUser user, @PathVariable long id,
@Valid @RequestBody MojiaSkuSyncDtos.RetryRequest request) {
@@ -12,6 +12,8 @@ public final class MojiaSkuSyncDtos {
public record Query(String skuCode, String syncStatus, long page, long size) {}
public record Config(boolean autoSyncEnabled) {}
public record UpdateRequest(
@NotBlank @Size(max = 128) String skuCode,
@NotNull @DecimalMin("0.001") BigDecimal lengthCm,
@@ -53,7 +53,7 @@ public class MojiaSkuSyncRepository {
.eq(MojiaMeasurementReceiptEntity::getId, id)
.eq(MojiaMeasurementReceiptEntity::getMeasurementKind, "SKU")
.eq(MojiaMeasurementReceiptEntity::getRevision, revision)
.eq(MojiaMeasurementReceiptEntity::getSyncStatus, "FAILED")
.in(MojiaMeasurementReceiptEntity::getSyncStatus, "PENDING", "FAILED")
.set(MojiaMeasurementReceiptEntity::getSyncStatus, "PENDING")
.set(MojiaMeasurementReceiptEntity::getSyncFailureCode, null)
.set(MojiaMeasurementReceiptEntity::getSyncFailureReason, null)
@@ -3,6 +3,7 @@ package com.baiyue.firstleg.service;
import com.baiyue.common.core.api.PageResult;
import com.baiyue.common.core.api.ResultCode;
import com.baiyue.common.core.exception.BizException;
import com.baiyue.firstleg.config.LingxingSyncProperties;
import com.baiyue.firstleg.dto.MojiaSkuSyncDtos;
import com.baiyue.firstleg.entity.MojiaMeasurementReceiptEntity;
import com.baiyue.firstleg.repository.MojiaSkuSyncRepository;
@@ -13,6 +14,11 @@ import org.springframework.transaction.annotation.Transactional;
@Service
public class MojiaSkuSyncService {
@Resource private MojiaSkuSyncRepository repository;
@Resource private LingxingSyncProperties lingxingProperties;
public MojiaSkuSyncDtos.Config config() {
return new MojiaSkuSyncDtos.Config(lingxingProperties.isAutoSyncEnabled());
}
public PageResult<MojiaSkuSyncDtos.Record> page(MojiaSkuSyncDtos.Query query) {
PageResult<MojiaMeasurementReceiptEntity> source = repository.page(
@@ -34,7 +40,7 @@ public class MojiaSkuSyncService {
public MojiaSkuSyncDtos.Record retry(long id, MojiaSkuSyncDtos.RetryRequest request) {
required(id);
if (repository.retry(id, request.revision()) != 1) {
throw conflict("仅同步失败记录可重新推送,或记录已被其他人修改");
throw conflict("仅待同步或同步失败记录可推送,或记录已被其他人修改");
}
return view(required(id));
}