mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:19:19 +08:00
feat: 单日全量也持久化任务并范围重叠不创建新任务
This commit is contained in:
+15
-24
@@ -28,6 +28,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 拼多多订单同步:执行类接口入队;补单仍同步执行。
|
||||
* 全量(含单日 / 区间回补)统一写任务表后入队。
|
||||
*/
|
||||
@Tag(name = "拼多多-订单同步", description = "按天回补 / 增量 / 补单 / 全量任务 / 增量开关")
|
||||
@RestController
|
||||
@@ -49,39 +50,29 @@ public class PddOrderSyncController {
|
||||
this.contextResolver = contextResolver;
|
||||
}
|
||||
|
||||
@Operation(summary = "按成交日同步一天(入队)")
|
||||
@Operation(summary = "按成交日同步一天", description = "创建单日全量任务并入队(持久化到任务表)")
|
||||
@PostMapping("/day")
|
||||
@RequirePermission(value = "biz:pdd:order:sync", description = "拼多多订单同步", allowSuper = true)
|
||||
public ApiResponse<PddOrderSyncResultVO> syncDay(@Valid @RequestBody PddOrderSyncDayDTO dto) {
|
||||
PddOrderSyncShopContext ctx = contextResolver.resolveForCurrentCompany(dto.getShopId());
|
||||
syncPublisher.publishFullRange(ctx.getCompanyId(), ctx.getShopId(), dto.getConfirmDate(), dto.getConfirmDate());
|
||||
return ApiResponse.success("已入队", PddOrderSyncResultVO.builder()
|
||||
.mode("day")
|
||||
.shopId(dto.getShopId())
|
||||
.fetchedCount(0)
|
||||
.upsertedCount(0)
|
||||
.skippedCount(0)
|
||||
.errors(List.of())
|
||||
.build());
|
||||
public ApiResponse<PddOrderFullSyncTaskVO> syncDay(@Valid @RequestBody PddOrderSyncDayDTO dto) {
|
||||
PddOrderFullSyncTaskCreateDTO create = new PddOrderFullSyncTaskCreateDTO();
|
||||
create.setShopId(dto.getShopId());
|
||||
create.setDateFrom(dto.getConfirmDate());
|
||||
create.setDateTo(dto.getConfirmDate());
|
||||
return ApiResponse.success("任务已入队", fullSyncTaskService.createTask(create));
|
||||
}
|
||||
|
||||
@Operation(summary = "按成交日范围回补(入队)")
|
||||
@Operation(summary = "按成交日范围回补", description = "创建区间全量任务并入队(持久化到任务表)")
|
||||
@PostMapping("/bootstrap")
|
||||
@RequirePermission(value = "biz:pdd:order:sync", description = "拼多多订单同步", allowSuper = true)
|
||||
public ApiResponse<PddOrderSyncResultVO> bootstrap(
|
||||
public ApiResponse<PddOrderFullSyncTaskVO> bootstrap(
|
||||
@Parameter(description = "内部店铺 ID") @RequestParam Long shopId,
|
||||
@Parameter(description = "开始日期") @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
|
||||
@Parameter(description = "结束日期") @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) {
|
||||
PddOrderSyncShopContext ctx = contextResolver.resolveForCurrentCompany(shopId);
|
||||
syncPublisher.publishFullRange(ctx.getCompanyId(), ctx.getShopId(), startDate, endDate);
|
||||
return ApiResponse.success("已入队", PddOrderSyncResultVO.builder()
|
||||
.mode("bootstrap")
|
||||
.shopId(shopId)
|
||||
.fetchedCount(0)
|
||||
.upsertedCount(0)
|
||||
.skippedCount(0)
|
||||
.errors(List.of())
|
||||
.build());
|
||||
PddOrderFullSyncTaskCreateDTO create = new PddOrderFullSyncTaskCreateDTO();
|
||||
create.setShopId(shopId);
|
||||
create.setDateFrom(startDate);
|
||||
create.setDateTo(endDate);
|
||||
return ApiResponse.success("任务已入队", fullSyncTaskService.createTask(create));
|
||||
}
|
||||
|
||||
@Operation(summary = "增量同步(入队)")
|
||||
|
||||
+35
-4
@@ -23,6 +23,7 @@ import top.xyquan.ecomdmbbackend.modules.ec.shop.mapper.ShopMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.po.ShopPO;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
@@ -61,12 +62,14 @@ public class PddOrderFullSyncTaskService {
|
||||
}
|
||||
PddOrderSyncShopContext ctx = contextResolver.resolveForCurrentCompany(dto.getShopId());
|
||||
|
||||
Long running = taskMapper.selectCount(new LambdaQueryWrapper<PddOrderFullSyncTaskPO>()
|
||||
PddOrderFullSyncTaskPO active = taskMapper.selectOne(new LambdaQueryWrapper<PddOrderFullSyncTaskPO>()
|
||||
.eq(PddOrderFullSyncTaskPO::getShopId, dto.getShopId())
|
||||
.in(PddOrderFullSyncTaskPO::getStatus,
|
||||
PddOrderFullSyncTaskPO.STATUS_PENDING, PddOrderFullSyncTaskPO.STATUS_RUNNING));
|
||||
if (running != null && running > 0) {
|
||||
throw new BusinessException("该店铺已有进行中的全量同步任务");
|
||||
PddOrderFullSyncTaskPO.STATUS_PENDING, PddOrderFullSyncTaskPO.STATUS_RUNNING)
|
||||
.orderByDesc(PddOrderFullSyncTaskPO::getId)
|
||||
.last("LIMIT 1"));
|
||||
if (active != null) {
|
||||
throw new BusinessException(buildActiveTaskConflictMessage(active, dto.getDateFrom(), dto.getDateTo()));
|
||||
}
|
||||
|
||||
int totalDays = (int) ChronoUnit.DAYS.between(dto.getDateFrom(), dto.getDateTo()) + 1;
|
||||
@@ -88,6 +91,34 @@ public class PddOrderFullSyncTaskService {
|
||||
return toVo(task);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同店仅允许一个进行中全量任务。
|
||||
* 若进行中任务区间已完全涵盖本次新建区间,提示无需重复创建;否则提示等待/取消后再建。
|
||||
*/
|
||||
private static String buildActiveTaskConflictMessage(PddOrderFullSyncTaskPO active,
|
||||
LocalDate newFrom, LocalDate newTo) {
|
||||
int done = active.getDoneDays() == null ? 0 : active.getDoneDays();
|
||||
int total = active.getTotalDays() == null ? 0 : active.getTotalDays();
|
||||
String progress = done + "/" + total;
|
||||
boolean covered = !active.getDateFrom().isAfter(newFrom) && !active.getDateTo().isBefore(newTo);
|
||||
if (covered) {
|
||||
return String.format(
|
||||
"该店全量任务 #%d(%s~%s,%s %s)已包含本次区间,无需重复创建",
|
||||
active.getId(),
|
||||
active.getDateFrom(),
|
||||
active.getDateTo(),
|
||||
active.getStatus(),
|
||||
progress);
|
||||
}
|
||||
return String.format(
|
||||
"该店已有进行中的全量任务 #%d(%s~%s,%s %s),请等待完成或取消后再创建",
|
||||
active.getId(),
|
||||
active.getDateFrom(),
|
||||
active.getDateTo(),
|
||||
active.getStatus(),
|
||||
progress);
|
||||
}
|
||||
|
||||
public PddOrderFullSyncTaskVO getTask(Long taskId) {
|
||||
PddOrderFullSyncTaskPO task = requireOwnedTask(taskId);
|
||||
return toVo(task);
|
||||
|
||||
Reference in New Issue
Block a user