mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
feat: 订单转换和计算侧增加手动创建全量任务功能
This commit is contained in:
+18
-1
@@ -1,14 +1,17 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.orderstat.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.dto.BiOrderStatFullCalcTaskCreateDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.po.BiOrderStatFullCalcTaskPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.po.BiOrderStatIncCalcPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.vo.BiOrderStatFullCalcTaskVO;
|
||||
@@ -22,7 +25,7 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* BI 订单统计计算控制面查询与人工恢复。
|
||||
* BI 订单统计计算控制面:查询、人工恢复、手动全量计算。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/bi/order-stat/calc")
|
||||
@@ -55,6 +58,20 @@ public class BiOrderStatCalcController {
|
||||
return ApiResponse.success("已恢复计算", toIncVo(shop.getId(), state));
|
||||
}
|
||||
|
||||
@PostMapping("/full-task")
|
||||
@RequirePermission(value = "biz:pdd:order:sync", description = "拼多多订单同步", allowSuper = true)
|
||||
public ApiResponse<BiOrderStatFullCalcTaskVO> createFullTask(
|
||||
@Valid @RequestBody BiOrderStatFullCalcTaskCreateDTO dto) {
|
||||
ShopPO shop = requireOwnedShop(dto.getShopId());
|
||||
BiOrderStatFullCalcTaskPO task = calcTaskService.createManualTask(
|
||||
shop.getCompanyId(),
|
||||
shop.getId(),
|
||||
shop.getPlatformCode(),
|
||||
dto.getDateFrom(),
|
||||
dto.getDateTo());
|
||||
return ApiResponse.success("任务已入队", toTaskVo(task));
|
||||
}
|
||||
|
||||
@GetMapping("/full-task/list")
|
||||
@RequirePermission(value = "biz:pdd:order:sync", description = "拼多多订单同步", allowSuper = true)
|
||||
public ApiResponse<List<BiOrderStatFullCalcTaskVO>> listFullTasks(
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 手动创建 BI 全量计算任务(upstream_convert_task_id 为空)。
|
||||
*/
|
||||
@Data
|
||||
public class BiOrderStatFullCalcTaskCreateDTO {
|
||||
|
||||
/** 内部店 id(ec_shop.id) */
|
||||
@NotNull
|
||||
private Long shopId;
|
||||
|
||||
@NotNull
|
||||
private LocalDate dateFrom;
|
||||
|
||||
@NotNull
|
||||
private LocalDate dateTo;
|
||||
}
|
||||
+92
@@ -8,6 +8,10 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.common.mq.OrderMqConstants;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.infra.config.BiStatProperties;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.messaging.BiFullCalcMessage;
|
||||
@@ -17,6 +21,7 @@ import top.xyquan.ecomdmbbackend.modules.bi.orderstat.mapper.BiOrderStatIncCalcM
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.po.BiOrderStatFullCalcTaskDayPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.po.BiOrderStatFullCalcTaskPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.po.BiOrderStatIncCalcPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.platform.model.enums.PlatformCode;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
@@ -37,6 +42,8 @@ public class BiOrderStatCalcTaskService {
|
||||
|
||||
private static final ZoneId ZONE = ZoneId.of("Asia/Shanghai");
|
||||
private static final String INC_FLUSH_KEY = "bi:stat:inc:flush:";
|
||||
/** 手动全量计算可选日历窗口(与同步/转换近 90 天对齐) */
|
||||
public static final int FULL_CALC_MAX_CALENDAR_DAYS = 90;
|
||||
|
||||
private final BiOrderStatFullCalcTaskMapper taskMapper;
|
||||
private final BiOrderStatFullCalcTaskDayMapper dayMapper;
|
||||
@@ -45,6 +52,91 @@ public class BiOrderStatCalcTaskService {
|
||||
private final StringRedisTemplate stringRedisTemplate;
|
||||
private final BiStatProperties biStatProperties;
|
||||
|
||||
/**
|
||||
* 手动按区间创建全量计算(upstream 空):预建 day,提交后按日投递 bi.stat.full。
|
||||
*
|
||||
* @param companyId 公司
|
||||
* @param internalShopId ec_shop.id
|
||||
* @param platform 平台编码,空则 pdd
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public BiOrderStatFullCalcTaskPO createManualTask(Long companyId, Long internalShopId,
|
||||
String platform, LocalDate dateFrom, LocalDate dateTo) {
|
||||
if (companyId == null || internalShopId == null || dateFrom == null || dateTo == null) {
|
||||
throw new BusinessException("参数不完整");
|
||||
}
|
||||
if (dateTo.isBefore(dateFrom)) {
|
||||
throw new BusinessException("结束日期不能早于开始日期");
|
||||
}
|
||||
LocalDate today = LocalDate.now(ZONE);
|
||||
if (dateTo.isAfter(today)) {
|
||||
throw new BusinessException("结束日期不能晚于今天");
|
||||
}
|
||||
int maxDays = FULL_CALC_MAX_CALENDAR_DAYS;
|
||||
LocalDate earliest = today.minusDays(maxDays - 1L);
|
||||
if (dateFrom.isBefore(earliest)) {
|
||||
throw new BusinessException("全量计算仅支持近 " + maxDays
|
||||
+ " 天(含今天):最早可选 " + earliest);
|
||||
}
|
||||
|
||||
BiOrderStatFullCalcTaskPO active = taskMapper.selectOne(new LambdaQueryWrapper<BiOrderStatFullCalcTaskPO>()
|
||||
.eq(BiOrderStatFullCalcTaskPO::getCompanyId, companyId)
|
||||
.eq(BiOrderStatFullCalcTaskPO::getShopId, internalShopId)
|
||||
.in(BiOrderStatFullCalcTaskPO::getStatus,
|
||||
BiOrderStatFullCalcTaskPO.STATUS_PENDING,
|
||||
BiOrderStatFullCalcTaskPO.STATUS_RUNNING)
|
||||
.orderByDesc(BiOrderStatFullCalcTaskPO::getId)
|
||||
.last("LIMIT 1"));
|
||||
if (active != null) {
|
||||
throw new BusinessException(String.format(
|
||||
"该店已有进行中的全量计算 #%d(%s~%s),请等待完成后再创建",
|
||||
active.getId(), active.getDateFrom(), active.getDateTo()));
|
||||
}
|
||||
|
||||
String platformCode = platform != null && !platform.isBlank()
|
||||
? platform : PlatformCode.PDD.getCode();
|
||||
int totalDays = (int) ChronoUnit.DAYS.between(dateFrom, dateTo) + 1;
|
||||
BiOrderStatFullCalcTaskPO task = new BiOrderStatFullCalcTaskPO();
|
||||
task.setCompanyId(companyId);
|
||||
task.setShopId(internalShopId);
|
||||
task.setPlatformCode(platformCode);
|
||||
task.setUpstreamConvertTaskId(null);
|
||||
task.setDateFrom(dateFrom);
|
||||
task.setDateTo(dateTo);
|
||||
task.setTotalDays(totalDays);
|
||||
task.setDoneDays(0);
|
||||
task.setFailedDays(0);
|
||||
task.setSkippedDays(0);
|
||||
task.setStatus(BiOrderStatFullCalcTaskPO.STATUS_PENDING);
|
||||
taskMapper.insert(task);
|
||||
insertDayRows(task);
|
||||
|
||||
Long taskId = task.getId();
|
||||
schedulePublishAfterCommit(taskId, companyId, internalShopId, platformCode, dateFrom, dateTo);
|
||||
return task;
|
||||
}
|
||||
|
||||
private void schedulePublishAfterCommit(Long taskId, Long companyId, Long shopId, String platform,
|
||||
LocalDate from, LocalDate to) {
|
||||
Runnable publish = () -> {
|
||||
for (LocalDate d = from; !d.isAfter(to); d = d.plusDays(1)) {
|
||||
publishFull(companyId, shopId, platform, d,
|
||||
"manual:" + shopId + ":" + d, taskId, null);
|
||||
}
|
||||
log.info("手动全量计算已投递全部日消息 calcTaskId={} {}~{}", taskId, from, to);
|
||||
};
|
||||
if (!TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
publish.run();
|
||||
return;
|
||||
}
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||
@Override
|
||||
public void afterCommit() {
|
||||
publish.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换成功某日后:按 upstream_convert_task_id 懒建 BI 任务并预建 days,再投递该日 full。
|
||||
*
|
||||
|
||||
+13
-1
@@ -1,12 +1,15 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.controller;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.model.dto.PddOrderFullConvertTaskCreateDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.model.po.PddOrderFullConvertTaskPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.model.po.PddOrderIncConvertPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.model.vo.PddOrderConvertIncStatusVO;
|
||||
@@ -19,7 +22,7 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 拼多多订单转换控制面查询与人工恢复。
|
||||
* 拼多多订单转换控制面:查询、人工恢复、手动全量转换。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/channel/pdd/order/convert")
|
||||
@@ -50,6 +53,15 @@ public class PddOrderConvertController {
|
||||
return ApiResponse.success("已恢复转换", toIncVo(ctx.getInternalShopId(), state));
|
||||
}
|
||||
|
||||
@PostMapping("/full-task")
|
||||
@RequirePermission(value = "biz:pdd:order:sync", description = "拼多多订单同步", allowSuper = true)
|
||||
public ApiResponse<PddOrderFullConvertTaskVO> createFullTask(
|
||||
@Valid @RequestBody PddOrderFullConvertTaskCreateDTO dto) {
|
||||
PddOrderSyncShopContext ctx = contextResolver.resolveForCurrentCompany(dto.getShopId());
|
||||
PddOrderFullConvertTaskPO task = convertTaskService.createManualTask(dto);
|
||||
return ApiResponse.success("任务已入队", toTaskVo(ctx.getInternalShopId(), task));
|
||||
}
|
||||
|
||||
@GetMapping("/full-task/list")
|
||||
@RequirePermission(value = "biz:pdd:order:sync", description = "拼多多订单同步", allowSuper = true)
|
||||
public ApiResponse<List<PddOrderFullConvertTaskVO>> listFullTasks(
|
||||
|
||||
+9
-3
@@ -26,6 +26,7 @@ public class PddOrderConvertPublisher {
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
|
||||
/**
|
||||
* @param orders 非 null(含空列表)= 只按 id 转换;null = 按成交日扫描渠道单(手动全量)
|
||||
* @param syncTaskId 全量同步任务 id,写入 message.taskId
|
||||
* @param convertTaskId 全量转换任务 id,可空(无控制面路径)
|
||||
*/
|
||||
@@ -38,8 +39,8 @@ public class PddOrderConvertPublisher {
|
||||
.platform(PlatformCode.PDD.getCode())
|
||||
.mode(OrderConvertMode.FULL_DAY)
|
||||
.statDate(statDate.toString())
|
||||
.orders(orders != null ? orders : List.of())
|
||||
.syncBatchId(syncTaskId != null ? syncTaskId + ":" + statDate : "day:" + shopId + ":" + statDate)
|
||||
.orders(orders)
|
||||
.syncBatchId(syncTaskId != null ? syncTaskId + ":" + statDate : "manual:" + shopId + ":" + statDate)
|
||||
.taskId(syncTaskId)
|
||||
.convertTaskId(convertTaskId)
|
||||
.occurredAt(OffsetDateTime.now(ZONE))
|
||||
@@ -48,7 +49,12 @@ public class PddOrderConvertPublisher {
|
||||
rabbitTemplate.convertAndSend(
|
||||
OrderMqConstants.EXCHANGE, OrderMqConstants.RK_ORDER_CONVERT_PDD_FULL, msg);
|
||||
log.info("已投递 FULL_DAY 转换消息 shopId={} statDate={} orders={} convertTaskId={}",
|
||||
shopId, statDate, orders != null ? orders.size() : 0, convertTaskId);
|
||||
shopId, statDate, orders == null ? "scan-by-day" : orders.size(), convertTaskId);
|
||||
}
|
||||
|
||||
/** 手动全量:按日扫描渠道镜像,不携带订单 id 列表。 */
|
||||
public void publishFullDayScan(Long companyId, Long shopId, LocalDate statDate, Long convertTaskId) {
|
||||
publishFullDay(companyId, shopId, statDate, null, null, convertTaskId);
|
||||
}
|
||||
|
||||
public void publishInc(Long companyId, Long shopId, List<ChannelOrderRef> orders) {
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 手动创建全量转换任务(sync_task_id 为空)。
|
||||
*/
|
||||
@Data
|
||||
public class PddOrderFullConvertTaskCreateDTO {
|
||||
|
||||
/** 内部店 id(ec_shop.id),与同步创建一致 */
|
||||
@NotNull
|
||||
private Long shopId;
|
||||
|
||||
@NotNull
|
||||
private LocalDate dateFrom;
|
||||
|
||||
@NotNull
|
||||
private LocalDate dateTo;
|
||||
}
|
||||
+91
@@ -6,19 +6,28 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.common.mq.ChannelOrderRef;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.mapper.PddOrderFullConvertTaskDayMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.mapper.PddOrderFullConvertTaskMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.mapper.PddOrderIncConvertMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.messaging.PddOrderConvertPublisher;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.model.dto.PddOrderFullConvertTaskCreateDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.model.po.PddOrderFullConvertTaskDayPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.model.po.PddOrderFullConvertTaskPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.model.po.PddOrderIncConvertPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.PddOrderSyncShopContext;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.model.po.PddOrderFullSyncTaskPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.service.PddOrderFullSyncTaskService;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.sync.service.PddOrderSyncContextResolver;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.platform.model.enums.PlatformCode;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
|
||||
@@ -30,10 +39,92 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
public class PddOrderFullConvertTaskService {
|
||||
|
||||
private static final ZoneId ZONE = ZoneId.of("Asia/Shanghai");
|
||||
|
||||
private final PddOrderFullConvertTaskMapper taskMapper;
|
||||
private final PddOrderFullConvertTaskDayMapper dayMapper;
|
||||
private final PddOrderIncConvertMapper incConvertMapper;
|
||||
private final PddOrderConvertPublisher convertPublisher;
|
||||
private final PddOrderSyncContextResolver contextResolver;
|
||||
|
||||
/**
|
||||
* 手动按区间创建全量转换(sync_task_id 空):预建 day,提交后按日投递扫库消息。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public PddOrderFullConvertTaskPO createManualTask(PddOrderFullConvertTaskCreateDTO dto) {
|
||||
if (dto.getDateTo().isBefore(dto.getDateFrom())) {
|
||||
throw new BusinessException("结束日期不能早于开始日期");
|
||||
}
|
||||
LocalDate today = LocalDate.now(ZONE);
|
||||
if (dto.getDateTo().isAfter(today)) {
|
||||
throw new BusinessException("结束日期不能晚于今天");
|
||||
}
|
||||
int maxDays = PddOrderFullSyncTaskService.FULL_SYNC_MAX_CALENDAR_DAYS;
|
||||
LocalDate earliest = today.minusDays(maxDays - 1L);
|
||||
if (dto.getDateFrom().isBefore(earliest)) {
|
||||
throw new BusinessException("全量转换仅支持近 " + maxDays
|
||||
+ " 天(含今天):最早可选 " + earliest);
|
||||
}
|
||||
PddOrderSyncShopContext ctx = contextResolver.resolveForCurrentCompany(dto.getShopId());
|
||||
|
||||
PddOrderFullConvertTaskPO active = taskMapper.selectOne(new LambdaQueryWrapper<PddOrderFullConvertTaskPO>()
|
||||
.eq(PddOrderFullConvertTaskPO::getShopId, ctx.getShopId())
|
||||
.eq(PddOrderFullConvertTaskPO::getCompanyId, ctx.getCompanyId())
|
||||
.in(PddOrderFullConvertTaskPO::getStatus,
|
||||
PddOrderFullConvertTaskPO.STATUS_PENDING,
|
||||
PddOrderFullConvertTaskPO.STATUS_RUNNING)
|
||||
.orderByDesc(PddOrderFullConvertTaskPO::getId)
|
||||
.last("LIMIT 1"));
|
||||
if (active != null) {
|
||||
throw new BusinessException(String.format(
|
||||
"该店已有进行中的全量转换 #%d(%s~%s),请等待完成后再创建",
|
||||
active.getId(), active.getDateFrom(), active.getDateTo()));
|
||||
}
|
||||
|
||||
int totalDays = (int) ChronoUnit.DAYS.between(dto.getDateFrom(), dto.getDateTo()) + 1;
|
||||
PddOrderFullConvertTaskPO task = new PddOrderFullConvertTaskPO();
|
||||
task.setCompanyId(ctx.getCompanyId());
|
||||
task.setShopId(ctx.getShopId());
|
||||
task.setSyncTaskId(null);
|
||||
task.setPlatformCode(PlatformCode.PDD.getCode());
|
||||
task.setDateFrom(dto.getDateFrom());
|
||||
task.setDateTo(dto.getDateTo());
|
||||
task.setTotalDays(totalDays);
|
||||
task.setDoneDays(0);
|
||||
task.setFailedDays(0);
|
||||
task.setSkippedDays(0);
|
||||
task.setStatus(PddOrderFullConvertTaskPO.STATUS_PENDING);
|
||||
taskMapper.insert(task);
|
||||
insertDayRows(task);
|
||||
|
||||
Long taskId = task.getId();
|
||||
Long companyId = task.getCompanyId();
|
||||
Long channelShopId = task.getShopId();
|
||||
LocalDate from = task.getDateFrom();
|
||||
LocalDate to = task.getDateTo();
|
||||
schedulePublishAfterCommit(taskId, companyId, channelShopId, from, to);
|
||||
return task;
|
||||
}
|
||||
|
||||
private void schedulePublishAfterCommit(Long taskId, Long companyId, Long channelShopId,
|
||||
LocalDate from, LocalDate to) {
|
||||
Runnable publish = () -> {
|
||||
for (LocalDate d = from; !d.isAfter(to); d = d.plusDays(1)) {
|
||||
convertPublisher.publishFullDayScan(companyId, channelShopId, d, taskId);
|
||||
}
|
||||
log.info("手动全量转换已投递全部日消息 convertTaskId={} {}~{}", taskId, from, to);
|
||||
};
|
||||
if (!TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
publish.run();
|
||||
return;
|
||||
}
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||
@Override
|
||||
public void afterCommit() {
|
||||
publish.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步成功某日后:按 sync_task_id 懒建转换任务并预建全部 day,再投递该日 FULL_DAY。
|
||||
|
||||
@@ -26,3 +26,15 @@ export async function listBiOrderStatFullCalcTasksApi(
|
||||
{ params: { shopId, limit } },
|
||||
);
|
||||
}
|
||||
|
||||
/** 手动创建 BI 全量计算任务 */
|
||||
export async function createBiOrderStatFullCalcTaskApi(data: {
|
||||
shopId: number;
|
||||
dateFrom: string;
|
||||
dateTo: string;
|
||||
}) {
|
||||
return requestClient.post<BiOrderStatCalcVO.FullTask>(
|
||||
'/bi/order-stat/calc/full-task',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -26,3 +26,15 @@ export async function listPddOrderConvertFullTasksApi(
|
||||
{ params: { shopId, limit } },
|
||||
);
|
||||
}
|
||||
|
||||
/** 手动创建全量转换任务(按渠道镜像扫日) */
|
||||
export async function createPddOrderConvertFullTaskApi(data: {
|
||||
shopId: number;
|
||||
dateFrom: string;
|
||||
dateTo: string;
|
||||
}) {
|
||||
return requestClient.post<PddOrderConvertVO.FullTask>(
|
||||
'/channel/pdd/order/convert/full-task',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
-254
@@ -1,254 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ShopVO } from '#/api/ec/shop/types';
|
||||
import type { BiOrderStatCalcVO } from '#/api/bi/order-stat-calc';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Card,
|
||||
Descriptions,
|
||||
Empty,
|
||||
List,
|
||||
Modal,
|
||||
Progress,
|
||||
Space,
|
||||
Tag,
|
||||
Typography,
|
||||
message,
|
||||
} from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import {
|
||||
getBiOrderStatIncCalcStatusApi,
|
||||
listBiOrderStatFullCalcTasksApi,
|
||||
resumeBiOrderStatIncCalcApi,
|
||||
} from '#/api/bi/order-stat-calc';
|
||||
|
||||
defineOptions({ name: 'BiOrderStatCalcModal' });
|
||||
|
||||
const emit = defineEmits<{ success: [] }>();
|
||||
|
||||
const openFlag = ref(false);
|
||||
const shop = ref<null | ShopVO.Info>(null);
|
||||
const loading = ref(false);
|
||||
const listLoading = ref(false);
|
||||
const resuming = ref(false);
|
||||
const incremental = ref<null | BiOrderStatCalcVO.IncStatus>(null);
|
||||
const fullTasks = ref<BiOrderStatCalcVO.FullTask[]>([]);
|
||||
|
||||
const title = computed(() =>
|
||||
shop.value ? `BI 计算 - ${shop.value.name}` : 'BI 计算',
|
||||
);
|
||||
|
||||
const statusLabel = computed(() => {
|
||||
const s = incremental.value?.status;
|
||||
if (s === 2) return '出错暂停';
|
||||
if (s === 1) return '正常';
|
||||
return '未开始';
|
||||
});
|
||||
|
||||
const statusColor = computed(() => {
|
||||
const s = incremental.value?.status;
|
||||
if (s === 2) return 'error';
|
||||
if (s === 1) return 'success';
|
||||
return 'default';
|
||||
});
|
||||
|
||||
function formatTime(time?: null | string) {
|
||||
if (!time) return '-';
|
||||
const d = dayjs(time);
|
||||
return d.isValid() ? d.format('YYYY-MM-DD HH:mm:ss') : '-';
|
||||
}
|
||||
|
||||
function statusTag(status: string) {
|
||||
const map: Record<string, { color: string; text: string }> = {
|
||||
PENDING: { color: 'default', text: '等待中' },
|
||||
RUNNING: { color: 'processing', text: '执行中' },
|
||||
SUCCESS: { color: 'success', text: '成功' },
|
||||
FAILED: { color: 'error', text: '失败' },
|
||||
CANCELLED: { color: 'warning', text: '已取消' },
|
||||
};
|
||||
return map[status] || { color: 'default', text: status };
|
||||
}
|
||||
|
||||
function taskProgressPercent(task: BiOrderStatCalcVO.FullTask) {
|
||||
if (!task.totalDays) return 0;
|
||||
return Math.min(100, Math.round((task.doneDays / task.totalDays) * 100));
|
||||
}
|
||||
|
||||
async function loadInc() {
|
||||
if (!shop.value) return;
|
||||
try {
|
||||
incremental.value = await getBiOrderStatIncCalcStatusApi(shop.value.id);
|
||||
} catch (error) {
|
||||
console.error('加载 BI 计算店态失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadFullTasks() {
|
||||
if (!shop.value) return;
|
||||
try {
|
||||
listLoading.value = true;
|
||||
fullTasks.value = await listBiOrderStatFullCalcTasksApi(shop.value.id, 30);
|
||||
} catch (error) {
|
||||
console.error('加载全量计算任务失败:', error);
|
||||
} finally {
|
||||
listLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleResume() {
|
||||
if (!shop.value) return;
|
||||
try {
|
||||
resuming.value = true;
|
||||
incremental.value = await resumeBiOrderStatIncCalcApi(shop.value.id);
|
||||
message.success('已恢复计算');
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('恢复计算失败:', error);
|
||||
message.error('恢复计算失败');
|
||||
} finally {
|
||||
resuming.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
openFlag.value = false;
|
||||
}
|
||||
|
||||
async function open(record: ShopVO.Info) {
|
||||
shop.value = record;
|
||||
incremental.value = null;
|
||||
fullTasks.value = [];
|
||||
openFlag.value = true;
|
||||
loading.value = true;
|
||||
try {
|
||||
await Promise.all([loadInc(), loadFullTasks()]);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ open, close: handleClose });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="openFlag"
|
||||
:title="title"
|
||||
:width="720"
|
||||
:footer="null"
|
||||
destroy-on-close
|
||||
@cancel="handleClose"
|
||||
>
|
||||
<Space direction="vertical" :size="16" class="w-full">
|
||||
<Card size="small">
|
||||
<template #title>
|
||||
<Space>
|
||||
<span>增量计算</span>
|
||||
<Tag :color="statusColor">{{ statusLabel }}</Tag>
|
||||
</Space>
|
||||
</template>
|
||||
<template #extra>
|
||||
<Button
|
||||
v-if="incremental?.status === 2"
|
||||
size="small"
|
||||
type="primary"
|
||||
:loading="resuming"
|
||||
@click="handleResume"
|
||||
>
|
||||
恢复运行
|
||||
</Button>
|
||||
</template>
|
||||
<Space direction="vertical" :size="12" class="w-full">
|
||||
<Typography.Text type="secondary">
|
||||
将转换侧 delta 累加到 BI 日汇聚;出错暂停后需人工恢复。
|
||||
</Typography.Text>
|
||||
<Descriptions bordered size="small" :column="1">
|
||||
<Descriptions.Item label="上次成功">
|
||||
{{ formatTime(incremental?.lastSuccessTime) }}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="最近统计日">
|
||||
{{ incremental?.lastStatDate || '-' }}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="最近订单">
|
||||
{{
|
||||
incremental?.lastAppliedOrderId
|
||||
? `#${incremental.lastAppliedOrderId}`
|
||||
: '-'
|
||||
}}
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
<Alert
|
||||
v-if="incremental?.lastSummary"
|
||||
:type="incremental?.status === 2 ? 'error' : 'info'"
|
||||
show-icon
|
||||
:message="incremental.lastSummary"
|
||||
/>
|
||||
</Space>
|
||||
</Card>
|
||||
|
||||
<Card size="small" title="全量计算任务">
|
||||
<template #extra>
|
||||
<Button size="small" :loading="listLoading" @click="loadFullTasks">
|
||||
刷新
|
||||
</Button>
|
||||
</template>
|
||||
<List
|
||||
v-if="fullTasks.length > 0"
|
||||
:data-source="fullTasks"
|
||||
:loading="listLoading"
|
||||
item-layout="vertical"
|
||||
size="small"
|
||||
class="max-h-[40vh] overflow-y-auto"
|
||||
>
|
||||
<template #renderItem="{ item: task }">
|
||||
<List.Item>
|
||||
<List.Item.Meta>
|
||||
<template #title>
|
||||
<Space wrap>
|
||||
<span>#{{ task.id }}</span>
|
||||
<Tag :color="statusTag(task.status).color">
|
||||
{{ statusTag(task.status).text }}
|
||||
</Tag>
|
||||
<Typography.Text type="secondary">
|
||||
{{ task.doneDays }}/{{ task.totalDays }} 天
|
||||
</Typography.Text>
|
||||
</Space>
|
||||
</template>
|
||||
<template #description>
|
||||
<div>区间 {{ task.dateFrom }} ~ {{ task.dateTo }}</div>
|
||||
<div>
|
||||
创建 {{ formatTime(task.createTime) }}
|
||||
<template v-if="task.finishTime">
|
||||
· 结束 {{ formatTime(task.finishTime) }}
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</List.Item.Meta>
|
||||
<Progress
|
||||
v-if="task.status === 'RUNNING' || task.status === 'SUCCESS'"
|
||||
:percent="taskProgressPercent(task)"
|
||||
size="small"
|
||||
/>
|
||||
<Alert
|
||||
v-if="task.lastError"
|
||||
class="mt-2"
|
||||
type="error"
|
||||
show-icon
|
||||
:message="task.lastError"
|
||||
/>
|
||||
</List.Item>
|
||||
</template>
|
||||
</List>
|
||||
<Empty
|
||||
v-else
|
||||
:image="Empty.PRESENTED_IMAGE_SIMPLE"
|
||||
description="暂无全量计算任务"
|
||||
/>
|
||||
</Card>
|
||||
</Space>
|
||||
</Modal>
|
||||
</template>
|
||||
-250
@@ -1,250 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ShopVO } from '#/api/ec/shop/types';
|
||||
import type { PddOrderConvertVO } from '#/api/channel/pdd/order-convert';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Card,
|
||||
Descriptions,
|
||||
Empty,
|
||||
List,
|
||||
Modal,
|
||||
Progress,
|
||||
Space,
|
||||
Tag,
|
||||
Typography,
|
||||
message,
|
||||
} from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import {
|
||||
getPddOrderConvertIncStatusApi,
|
||||
listPddOrderConvertFullTasksApi,
|
||||
resumePddOrderConvertIncApi,
|
||||
} from '#/api/channel/pdd/order-convert';
|
||||
|
||||
defineOptions({ name: 'PddOrderConvertModal' });
|
||||
|
||||
const emit = defineEmits<{ success: [] }>();
|
||||
|
||||
const openFlag = ref(false);
|
||||
const shop = ref<null | ShopVO.Info>(null);
|
||||
const loading = ref(false);
|
||||
const listLoading = ref(false);
|
||||
const resuming = ref(false);
|
||||
const incremental = ref<null | PddOrderConvertVO.IncStatus>(null);
|
||||
const fullTasks = ref<PddOrderConvertVO.FullTask[]>([]);
|
||||
|
||||
const title = computed(() =>
|
||||
shop.value ? `订单转换 - ${shop.value.name}` : '订单转换',
|
||||
);
|
||||
|
||||
const statusLabel = computed(() => {
|
||||
const s = incremental.value?.status;
|
||||
if (s === 2) return '出错暂停';
|
||||
if (s === 1) return '正常';
|
||||
return '未开始';
|
||||
});
|
||||
|
||||
const statusColor = computed(() => {
|
||||
const s = incremental.value?.status;
|
||||
if (s === 2) return 'error';
|
||||
if (s === 1) return 'success';
|
||||
return 'default';
|
||||
});
|
||||
|
||||
function formatTime(time?: null | string) {
|
||||
if (!time) return '-';
|
||||
const d = dayjs(time);
|
||||
return d.isValid() ? d.format('YYYY-MM-DD HH:mm:ss') : '-';
|
||||
}
|
||||
|
||||
function statusTag(status: string) {
|
||||
const map: Record<string, { color: string; text: string }> = {
|
||||
PENDING: { color: 'default', text: '等待中' },
|
||||
RUNNING: { color: 'processing', text: '执行中' },
|
||||
SUCCESS: { color: 'success', text: '成功' },
|
||||
FAILED: { color: 'error', text: '失败' },
|
||||
CANCELLED: { color: 'warning', text: '已取消' },
|
||||
};
|
||||
return map[status] || { color: 'default', text: status };
|
||||
}
|
||||
|
||||
function taskProgressPercent(task: PddOrderConvertVO.FullTask) {
|
||||
if (!task.totalDays) return 0;
|
||||
return Math.min(100, Math.round((task.doneDays / task.totalDays) * 100));
|
||||
}
|
||||
|
||||
async function loadInc() {
|
||||
if (!shop.value) return;
|
||||
try {
|
||||
incremental.value = await getPddOrderConvertIncStatusApi(shop.value.id);
|
||||
} catch (error) {
|
||||
console.error('加载转换店态失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadFullTasks() {
|
||||
if (!shop.value) return;
|
||||
try {
|
||||
listLoading.value = true;
|
||||
fullTasks.value = await listPddOrderConvertFullTasksApi(shop.value.id, 30);
|
||||
} catch (error) {
|
||||
console.error('加载全量转换任务失败:', error);
|
||||
} finally {
|
||||
listLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleResume() {
|
||||
if (!shop.value) return;
|
||||
try {
|
||||
resuming.value = true;
|
||||
incremental.value = await resumePddOrderConvertIncApi(shop.value.id);
|
||||
message.success('已恢复转换');
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('恢复转换失败:', error);
|
||||
message.error('恢复转换失败');
|
||||
} finally {
|
||||
resuming.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
openFlag.value = false;
|
||||
}
|
||||
|
||||
async function open(record: ShopVO.Info) {
|
||||
shop.value = record;
|
||||
incremental.value = null;
|
||||
fullTasks.value = [];
|
||||
openFlag.value = true;
|
||||
loading.value = true;
|
||||
try {
|
||||
await Promise.all([loadInc(), loadFullTasks()]);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ open, close: handleClose });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="openFlag"
|
||||
:title="title"
|
||||
:width="720"
|
||||
:footer="null"
|
||||
destroy-on-close
|
||||
@cancel="handleClose"
|
||||
>
|
||||
<Space direction="vertical" :size="16" class="w-full">
|
||||
<Card size="small">
|
||||
<template #title>
|
||||
<Space>
|
||||
<span>增量转换</span>
|
||||
<Tag :color="statusColor">{{ statusLabel }}</Tag>
|
||||
</Space>
|
||||
</template>
|
||||
<template #extra>
|
||||
<Button
|
||||
v-if="incremental?.status === 2"
|
||||
size="small"
|
||||
type="primary"
|
||||
:loading="resuming"
|
||||
@click="handleResume"
|
||||
>
|
||||
恢复运行
|
||||
</Button>
|
||||
</template>
|
||||
<Space direction="vertical" :size="12" class="w-full">
|
||||
<Typography.Text type="secondary">
|
||||
将渠道订单写入内部订单;出错暂停后需人工恢复才会继续消费。
|
||||
</Typography.Text>
|
||||
<Descriptions bordered size="small" :column="1">
|
||||
<Descriptions.Item label="上次成功">
|
||||
{{ formatTime(incremental?.lastSuccessTime) }}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="转换游标">
|
||||
{{ formatTime(incremental?.lastCursorAt) }}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="最近批次单数">
|
||||
{{ incremental?.lastConvertedCount ?? '-' }}
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
<Alert
|
||||
v-if="incremental?.lastSummary"
|
||||
:type="incremental?.status === 2 ? 'error' : 'info'"
|
||||
show-icon
|
||||
:message="incremental.lastSummary"
|
||||
/>
|
||||
</Space>
|
||||
</Card>
|
||||
|
||||
<Card size="small" title="全量转换任务">
|
||||
<template #extra>
|
||||
<Button size="small" :loading="listLoading" @click="loadFullTasks">
|
||||
刷新
|
||||
</Button>
|
||||
</template>
|
||||
<List
|
||||
v-if="fullTasks.length > 0"
|
||||
:data-source="fullTasks"
|
||||
:loading="listLoading"
|
||||
item-layout="vertical"
|
||||
size="small"
|
||||
class="max-h-[40vh] overflow-y-auto"
|
||||
>
|
||||
<template #renderItem="{ item: task }">
|
||||
<List.Item>
|
||||
<List.Item.Meta>
|
||||
<template #title>
|
||||
<Space wrap>
|
||||
<span>#{{ task.id }}</span>
|
||||
<Tag :color="statusTag(task.status).color">
|
||||
{{ statusTag(task.status).text }}
|
||||
</Tag>
|
||||
<Typography.Text type="secondary">
|
||||
{{ task.doneDays }}/{{ task.totalDays }} 天
|
||||
</Typography.Text>
|
||||
</Space>
|
||||
</template>
|
||||
<template #description>
|
||||
<div>区间 {{ task.dateFrom }} ~ {{ task.dateTo }}</div>
|
||||
<div>
|
||||
创建 {{ formatTime(task.createTime) }}
|
||||
<template v-if="task.finishTime">
|
||||
· 结束 {{ formatTime(task.finishTime) }}
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</List.Item.Meta>
|
||||
<Progress
|
||||
v-if="task.status === 'RUNNING' || task.status === 'SUCCESS'"
|
||||
:percent="taskProgressPercent(task)"
|
||||
size="small"
|
||||
/>
|
||||
<Alert
|
||||
v-if="task.lastError"
|
||||
class="mt-2"
|
||||
type="error"
|
||||
show-icon
|
||||
:message="task.lastError"
|
||||
/>
|
||||
</List.Item>
|
||||
</template>
|
||||
</List>
|
||||
<Empty
|
||||
v-else
|
||||
:image="Empty.PRESENTED_IMAGE_SIMPLE"
|
||||
description="暂无全量转换任务"
|
||||
/>
|
||||
</Card>
|
||||
</Space>
|
||||
</Modal>
|
||||
</template>
|
||||
-628
@@ -1,628 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ShopVO } from '#/api/ec/shop/types';
|
||||
import type { PddOrderSyncVO } from '#/api/channel/pdd/order-sync';
|
||||
import type { Dayjs } from 'dayjs';
|
||||
|
||||
import { computed, onBeforeUnmount, ref } from 'vue';
|
||||
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Card,
|
||||
DatePicker,
|
||||
Descriptions,
|
||||
Empty,
|
||||
Form,
|
||||
List,
|
||||
Modal,
|
||||
Progress,
|
||||
Radio,
|
||||
Space,
|
||||
Switch,
|
||||
Tag,
|
||||
Typography,
|
||||
message,
|
||||
} from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import {
|
||||
cancelPddFullSyncTaskApi,
|
||||
createPddFullSyncTaskApi,
|
||||
getPddFullSyncTaskApi,
|
||||
getPddIncrementalSyncStatusApi,
|
||||
listPddFullSyncTasksApi,
|
||||
resumePddFullSyncTaskApi,
|
||||
syncPddOrdersIncrementalApi,
|
||||
togglePddIncrementalSyncApi,
|
||||
} from '#/api/channel/pdd/order-sync';
|
||||
import { RealtimeSseEvent } from '#/api/notify/sse';
|
||||
import { useRealtimeStore } from '#/store';
|
||||
|
||||
defineOptions({ name: 'PddOrderSyncModal' });
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const FULL_SYNC_MAX_CALENDAR_DAYS = 90;
|
||||
|
||||
function fullSyncEarliest(): Dayjs {
|
||||
return dayjs().startOf('day').subtract(FULL_SYNC_MAX_CALENDAR_DAYS - 1, 'day');
|
||||
}
|
||||
|
||||
function fullSyncLatest(): Dayjs {
|
||||
return dayjs().startOf('day');
|
||||
}
|
||||
|
||||
function disabledFullSyncDate(current: Dayjs) {
|
||||
if (!current) return false;
|
||||
const d = current.startOf('day');
|
||||
return d.isBefore(fullSyncEarliest()) || d.isAfter(fullSyncLatest());
|
||||
}
|
||||
|
||||
const openFlag = ref(false);
|
||||
const shop = ref<null | ShopVO.Info>(null);
|
||||
const loading = ref(false);
|
||||
const listLoading = ref(false);
|
||||
const incSubmitting = ref(false);
|
||||
const createSubmitting = ref(false);
|
||||
const createModalOpen = ref(false);
|
||||
const createMode = ref<'day' | 'range'>('range');
|
||||
const confirmDate = ref<Dayjs>(dayjs().startOf('day'));
|
||||
const range = ref<[Dayjs, Dayjs]>([fullSyncEarliest(), fullSyncLatest()]);
|
||||
const incremental = ref<null | PddOrderSyncVO.IncrementalStatus>(null);
|
||||
const fullTasks = ref<PddOrderSyncVO.FullTask[]>([]);
|
||||
let pollTimer: null | ReturnType<typeof setInterval> = null;
|
||||
let unsubProgress: (() => void) | null = null;
|
||||
const terminalNotifiedTaskIds = new Set<number>();
|
||||
|
||||
const modalTitle = computed(() =>
|
||||
shop.value ? `同步拼多多订单 - ${shop.value.name}` : '同步拼多多订单',
|
||||
);
|
||||
|
||||
const hasActiveFullTask = computed(() =>
|
||||
fullTasks.value.some((t) => t.status === 'PENDING' || t.status === 'RUNNING'),
|
||||
);
|
||||
|
||||
const incHealthLabel = computed(() => {
|
||||
const health = incremental.value?.health;
|
||||
const map: Record<string, string> = {
|
||||
OFF: '已关闭',
|
||||
OK: '正常',
|
||||
LAGGING: '游标滞后',
|
||||
PAUSED: '出错暂停',
|
||||
};
|
||||
return health ? map[health] || health : '-';
|
||||
});
|
||||
|
||||
const incHealthColor = computed(() => {
|
||||
const health = incremental.value?.health;
|
||||
if (health === 'PAUSED') return 'error';
|
||||
if (health === 'LAGGING') return 'warning';
|
||||
if (health === 'OK') return 'success';
|
||||
return 'default';
|
||||
});
|
||||
|
||||
/** 只展示摘要(含失败提示);完整 lastError 不在抽屉展示 */
|
||||
const incStatusMessage = computed(() => incremental.value?.lastSummary || '');
|
||||
|
||||
const incStatusAlertType = computed(() => {
|
||||
const s = incremental.value?.lastSummary || '';
|
||||
if (s.includes('失败') || s.includes('限流')) return 'error';
|
||||
if (s) return 'info';
|
||||
return 'info';
|
||||
});
|
||||
|
||||
function formatTime(time?: null | string) {
|
||||
if (!time) return '-';
|
||||
const d = dayjs(time);
|
||||
return d.isValid() ? d.format('YYYY-MM-DD HH:mm:ss') : '-';
|
||||
}
|
||||
|
||||
function taskProgressPercent(task: PddOrderSyncVO.FullTask) {
|
||||
if (!task.totalDays) return 0;
|
||||
return Math.min(100, Math.round((task.doneDays / task.totalDays) * 100));
|
||||
}
|
||||
|
||||
function statusTag(status: string) {
|
||||
const map: Record<string, { color: string; text: string }> = {
|
||||
PENDING: { color: 'default', text: '等待中' },
|
||||
RUNNING: { color: 'processing', text: '执行中' },
|
||||
SUCCESS: { color: 'success', text: '成功' },
|
||||
FAILED: { color: 'error', text: '失败' },
|
||||
CANCELLED: { color: 'warning', text: '已取消' },
|
||||
};
|
||||
return map[status] || { color: 'default', text: status };
|
||||
}
|
||||
|
||||
function isTaskActive(task: PddOrderSyncVO.FullTask) {
|
||||
return task.status === 'PENDING' || task.status === 'RUNNING';
|
||||
}
|
||||
|
||||
function stopPoll() {
|
||||
if (pollTimer) {
|
||||
clearInterval(pollTimer);
|
||||
pollTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
function unsubscribeProgress() {
|
||||
unsubProgress?.();
|
||||
unsubProgress = null;
|
||||
}
|
||||
|
||||
function upsertTaskInList(task: PddOrderSyncVO.FullTask) {
|
||||
const idx = fullTasks.value.findIndex((t) => t.id === task.id);
|
||||
if (idx === -1) {
|
||||
fullTasks.value.unshift(task);
|
||||
} else {
|
||||
fullTasks.value[idx] = task;
|
||||
}
|
||||
}
|
||||
|
||||
function applyFullTaskUpdate(task: PddOrderSyncVO.FullTask) {
|
||||
if (!shop.value || task.shopId !== shop.value.id) {
|
||||
return;
|
||||
}
|
||||
upsertTaskInList(task);
|
||||
const terminal =
|
||||
task.status === 'SUCCESS' ||
|
||||
task.status === 'FAILED' ||
|
||||
task.status === 'CANCELLED';
|
||||
if (!terminal) {
|
||||
return;
|
||||
}
|
||||
if (!hasActiveFullTask.value) {
|
||||
stopPoll();
|
||||
}
|
||||
loading.value = false;
|
||||
if (terminalNotifiedTaskIds.has(task.id)) {
|
||||
return;
|
||||
}
|
||||
terminalNotifiedTaskIds.add(task.id);
|
||||
if (task.status === 'SUCCESS') {
|
||||
message.success(`全量任务 #${task.id} 完成:${task.doneDays}/${task.totalDays} 天`);
|
||||
emit('success');
|
||||
} else if (task.status === 'FAILED') {
|
||||
message.error(task.lastError || `全量任务 #${task.id} 失败`);
|
||||
emit('success');
|
||||
} else {
|
||||
message.info(`全量任务 #${task.id} 已取消`);
|
||||
emit('success');
|
||||
}
|
||||
}
|
||||
|
||||
function subscribeProgress() {
|
||||
unsubscribeProgress();
|
||||
const realtime = useRealtimeStore();
|
||||
unsubProgress = realtime.on(
|
||||
RealtimeSseEvent.PDD_ORDER_FULL_SYNC_PROGRESS,
|
||||
(event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.task) {
|
||||
applyFullTaskUpdate(data.task as PddOrderSyncVO.FullTask);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('解析全量同步进度失败:', error);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
async function loadIncrementalStatus() {
|
||||
if (!shop.value) return;
|
||||
try {
|
||||
incremental.value = await getPddIncrementalSyncStatusApi(shop.value.id);
|
||||
} catch (error) {
|
||||
console.error('加载增量状态失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadFullTasks() {
|
||||
if (!shop.value) return;
|
||||
try {
|
||||
listLoading.value = true;
|
||||
fullTasks.value = await listPddFullSyncTasksApi(shop.value.id, 30);
|
||||
const active = fullTasks.value.find((t) => isTaskActive(t));
|
||||
if (active) {
|
||||
watchActiveTasks();
|
||||
} else {
|
||||
stopPoll();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载全量任务列表失败:', error);
|
||||
} finally {
|
||||
listLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleToggleIncremental(checked: boolean | string | number) {
|
||||
if (!shop.value) return;
|
||||
const enabled = !!checked;
|
||||
const prev = incremental.value;
|
||||
try {
|
||||
incremental.value = await togglePddIncrementalSyncApi({
|
||||
shopId: shop.value.id,
|
||||
enabled,
|
||||
});
|
||||
message.success(enabled ? '已开启增量同步' : '已关闭增量同步');
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
incremental.value = prev;
|
||||
console.error('切换增量开关失败:', error);
|
||||
message.error('切换增量开关失败');
|
||||
}
|
||||
}
|
||||
|
||||
async function handleManualIncremental() {
|
||||
if (!shop.value) return;
|
||||
try {
|
||||
incSubmitting.value = true;
|
||||
await syncPddOrdersIncrementalApi(shop.value.id);
|
||||
message.success('已入队,后台增量同步中');
|
||||
emit('success');
|
||||
await loadIncrementalStatus();
|
||||
} catch (error) {
|
||||
console.error('手动增量失败:', error);
|
||||
} finally {
|
||||
incSubmitting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** SSE 为主,低频轮询活跃任务兜底 */
|
||||
function watchActiveTasks() {
|
||||
stopPoll();
|
||||
subscribeProgress();
|
||||
pollTimer = setInterval(async () => {
|
||||
const actives = fullTasks.value.filter((t) => isTaskActive(t));
|
||||
if (actives.length === 0) {
|
||||
stopPoll();
|
||||
return;
|
||||
}
|
||||
await Promise.all(
|
||||
actives.map(async (t) => {
|
||||
try {
|
||||
applyFullTaskUpdate(await getPddFullSyncTaskApi(t.id));
|
||||
} catch (error) {
|
||||
console.error('轮询全量任务失败:', error);
|
||||
}
|
||||
}),
|
||||
);
|
||||
}, 10_000);
|
||||
}
|
||||
|
||||
async function handleCancelFull(task: PddOrderSyncVO.FullTask) {
|
||||
try {
|
||||
loading.value = true;
|
||||
applyFullTaskUpdate(await cancelPddFullSyncTaskApi(task.id));
|
||||
message.success(`已取消全量任务 #${task.id}`);
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('取消全量任务失败:', error);
|
||||
message.error('取消全量任务失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleResumeFull(task: PddOrderSyncVO.FullTask) {
|
||||
try {
|
||||
loading.value = true;
|
||||
terminalNotifiedTaskIds.delete(task.id);
|
||||
const updated = await resumePddFullSyncTaskApi(task.id);
|
||||
upsertTaskInList(updated);
|
||||
message.success(`全量任务 #${task.id} 已续跑入队`);
|
||||
watchActiveTasks();
|
||||
} catch (error) {
|
||||
console.error('续跑全量任务失败:', error);
|
||||
message.error('续跑全量任务失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function openCreateModal() {
|
||||
createMode.value = 'range';
|
||||
confirmDate.value = fullSyncLatest();
|
||||
range.value = [fullSyncEarliest(), fullSyncLatest()];
|
||||
createModalOpen.value = true;
|
||||
}
|
||||
|
||||
async function handleCreateTask() {
|
||||
if (!shop.value) return;
|
||||
if (createMode.value === 'day' && !confirmDate.value) {
|
||||
message.warning('请选择成交日期');
|
||||
return;
|
||||
}
|
||||
if (createMode.value === 'range' && (!range.value?.[0] || !range.value?.[1])) {
|
||||
message.warning('请选择全量同步日期区间');
|
||||
return;
|
||||
}
|
||||
const dateFromDayjs =
|
||||
createMode.value === 'day' ? confirmDate.value : range.value[0];
|
||||
const dateToDayjs =
|
||||
createMode.value === 'day' ? confirmDate.value : range.value[1];
|
||||
if (
|
||||
disabledFullSyncDate(dateFromDayjs) ||
|
||||
disabledFullSyncDate(dateToDayjs) ||
|
||||
dateToDayjs.isBefore(dateFromDayjs, 'day')
|
||||
) {
|
||||
message.warning('日期须在近 90 天内(含今天),且结束不早于开始');
|
||||
return;
|
||||
}
|
||||
if (hasActiveFullTask.value) {
|
||||
message.warning('该店铺已有进行中的全量任务,请先等待或取消');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
createSubmitting.value = true;
|
||||
const dateFrom =
|
||||
createMode.value === 'day'
|
||||
? confirmDate.value.format('YYYY-MM-DD')
|
||||
: range.value[0].format('YYYY-MM-DD');
|
||||
const dateTo =
|
||||
createMode.value === 'day'
|
||||
? confirmDate.value.format('YYYY-MM-DD')
|
||||
: range.value[1].format('YYYY-MM-DD');
|
||||
const task = await createPddFullSyncTaskApi({
|
||||
shopId: shop.value.id,
|
||||
dateFrom,
|
||||
dateTo,
|
||||
});
|
||||
terminalNotifiedTaskIds.delete(task.id);
|
||||
upsertTaskInList(task);
|
||||
createModalOpen.value = false;
|
||||
message.success(
|
||||
createMode.value === 'day'
|
||||
? '单日全量任务已创建,正在后台执行'
|
||||
: '全量同步任务已创建,正在后台执行',
|
||||
);
|
||||
watchActiveTasks();
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('创建全量任务失败:', error);
|
||||
} finally {
|
||||
createSubmitting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
stopPoll();
|
||||
unsubscribeProgress();
|
||||
createModalOpen.value = false;
|
||||
openFlag.value = false;
|
||||
}
|
||||
|
||||
async function open(record: ShopVO.Info) {
|
||||
shop.value = record;
|
||||
fullTasks.value = [];
|
||||
incremental.value = null;
|
||||
loading.value = false;
|
||||
createSubmitting.value = false;
|
||||
incSubmitting.value = false;
|
||||
createModalOpen.value = false;
|
||||
terminalNotifiedTaskIds.clear();
|
||||
stopPoll();
|
||||
subscribeProgress();
|
||||
openFlag.value = true;
|
||||
await Promise.all([loadIncrementalStatus(), loadFullTasks()]);
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
stopPoll();
|
||||
unsubscribeProgress();
|
||||
});
|
||||
|
||||
defineExpose({ open, close: handleClose });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="openFlag"
|
||||
:title="modalTitle"
|
||||
:width="720"
|
||||
:footer="null"
|
||||
destroy-on-close
|
||||
:mask-closable="!hasActiveFullTask"
|
||||
@cancel="handleClose"
|
||||
>
|
||||
<Space direction="vertical" :size="16" class="w-full">
|
||||
<Card size="small">
|
||||
<template #title>
|
||||
<Space>
|
||||
<span>增量同步</span>
|
||||
<Tag :color="incHealthColor">{{ incHealthLabel }}</Tag>
|
||||
</Space>
|
||||
</template>
|
||||
<Space direction="vertical" :size="12" class="w-full">
|
||||
<Space wrap align="center">
|
||||
<Switch
|
||||
:checked="!!incremental?.enabled"
|
||||
checked-children="开"
|
||||
un-checked-children="关"
|
||||
@change="handleToggleIncremental"
|
||||
/>
|
||||
<Typography.Text type="secondary">
|
||||
开启后定时 Job 拉取增量并转换
|
||||
</Typography.Text>
|
||||
<Button
|
||||
size="small"
|
||||
type="primary"
|
||||
ghost
|
||||
:loading="incSubmitting"
|
||||
@click="handleManualIncremental"
|
||||
>
|
||||
手动增量一次
|
||||
</Button>
|
||||
</Space>
|
||||
|
||||
<Descriptions bordered size="small" :column="1">
|
||||
<Descriptions.Item label="游标">
|
||||
{{ formatTime(incremental?.lastCursorAt) }}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="上次成功">
|
||||
{{ formatTime(incremental?.lastSuccessTime) }}
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
|
||||
<Alert
|
||||
v-if="incStatusMessage"
|
||||
:type="incStatusAlertType"
|
||||
show-icon
|
||||
:message="incStatusMessage"
|
||||
/>
|
||||
</Space>
|
||||
</Card>
|
||||
|
||||
<Card size="small" title="全量同步任务">
|
||||
<template #extra>
|
||||
<Space size="small">
|
||||
<Button size="small" :loading="listLoading" @click="loadFullTasks">
|
||||
刷新
|
||||
</Button>
|
||||
<Button
|
||||
size="small"
|
||||
type="primary"
|
||||
:disabled="hasActiveFullTask"
|
||||
@click="openCreateModal"
|
||||
>
|
||||
创建全量任务
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<List
|
||||
v-if="fullTasks.length > 0"
|
||||
:data-source="fullTasks"
|
||||
:loading="listLoading"
|
||||
item-layout="vertical"
|
||||
size="small"
|
||||
class="max-h-[40vh] overflow-y-auto"
|
||||
>
|
||||
<template #renderItem="{ item: task }">
|
||||
<List.Item>
|
||||
<template #actions>
|
||||
<Button
|
||||
v-if="isTaskActive(task)"
|
||||
size="small"
|
||||
danger
|
||||
:loading="loading"
|
||||
@click="handleCancelFull(task)"
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
v-if="task.status === 'FAILED'"
|
||||
size="small"
|
||||
type="primary"
|
||||
:loading="loading"
|
||||
:disabled="hasActiveFullTask"
|
||||
@click="handleResumeFull(task)"
|
||||
>
|
||||
续跑
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<List.Item.Meta>
|
||||
<template #title>
|
||||
<Space wrap>
|
||||
<span>#{{ task.id }}</span>
|
||||
<Tag :color="statusTag(task.status).color">
|
||||
{{ statusTag(task.status).text }}
|
||||
</Tag>
|
||||
<Typography.Text type="secondary">
|
||||
{{ task.doneDays }}/{{ task.totalDays }} 天
|
||||
<template v-if="task.failedDays">
|
||||
· 失败日 {{ task.failedDays }}
|
||||
</template>
|
||||
</Typography.Text>
|
||||
</Space>
|
||||
</template>
|
||||
<template #description>
|
||||
<div>
|
||||
区间 {{ task.dateFrom }} ~ {{ task.dateTo }}
|
||||
<template v-if="task.currentDate">
|
||||
· 当前 {{ task.currentDate }}
|
||||
</template>
|
||||
</div>
|
||||
<div>
|
||||
创建 {{ formatTime(task.createTime) }}
|
||||
<template v-if="task.finishTime">
|
||||
· 结束 {{ formatTime(task.finishTime) }}
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</List.Item.Meta>
|
||||
|
||||
<Progress
|
||||
v-if="isTaskActive(task) || task.status === 'SUCCESS'"
|
||||
:percent="taskProgressPercent(task)"
|
||||
size="small"
|
||||
:status="task.status === 'FAILED' ? 'exception' : undefined"
|
||||
/>
|
||||
<Alert
|
||||
v-if="task.lastError"
|
||||
class="mt-2"
|
||||
type="error"
|
||||
show-icon
|
||||
:message="task.lastError"
|
||||
/>
|
||||
</List.Item>
|
||||
</template>
|
||||
</List>
|
||||
<Empty
|
||||
v-else
|
||||
:image="Empty.PRESENTED_IMAGE_SIMPLE"
|
||||
description="暂无全量任务"
|
||||
/>
|
||||
</Card>
|
||||
</Space>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
v-model:open="createModalOpen"
|
||||
title="创建全量同步任务"
|
||||
:confirm-loading="createSubmitting"
|
||||
ok-text="创建并开始"
|
||||
destroy-on-close
|
||||
@ok="handleCreateTask"
|
||||
>
|
||||
<Form layout="vertical" class="mt-2">
|
||||
<Form.Item label="任务类型">
|
||||
<Radio.Group v-model:value="createMode">
|
||||
<Radio value="range">按成交日区间</Radio>
|
||||
<Radio value="day">按成交日单日</Radio>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
v-if="createMode === 'range'"
|
||||
label="成交日期区间"
|
||||
extra="仅近 90 天(含今天);选到今天时,当日按当前时刻拉取。每天成功后进入转换与 BI"
|
||||
>
|
||||
<DatePicker.RangePicker
|
||||
v-model:value="range"
|
||||
class="w-full"
|
||||
:allow-clear="false"
|
||||
:disabled-date="disabledFullSyncDate"
|
||||
format="YYYY-MM-DD"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
v-else
|
||||
label="成交日期"
|
||||
extra="仅近 90 天(含今天);选今天时按当前时刻拉取。若进行中任务已涵盖该日则不会重复创建"
|
||||
>
|
||||
<DatePicker
|
||||
v-model:value="confirmDate"
|
||||
class="w-full"
|
||||
:allow-clear="false"
|
||||
:disabled-date="disabledFullSyncDate"
|
||||
format="YYYY-MM-DD"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
+1131
File diff suppressed because it is too large
Load Diff
@@ -23,10 +23,8 @@ import {
|
||||
getPlatformTagColor,
|
||||
} from '#/utils/platform-display';
|
||||
|
||||
import BiOrderStatCalcModal from './components/BiOrderStatCalcModal.vue';
|
||||
import PddOrderConvertModal from './components/PddOrderConvertModal.vue';
|
||||
import PddOrderSyncModal from './components/PddOrderSyncModal.vue';
|
||||
import ShopFormModal from './components/ShopFormModal.vue';
|
||||
import ShopOrderPipelineDrawer from './components/ShopOrderPipelineDrawer.vue';
|
||||
import PddShopDetailModal from '#/views/channel/pdd/shop/components/PddShopDetailModal.vue';
|
||||
|
||||
defineOptions({ name: 'ShopManagement' });
|
||||
@@ -39,9 +37,7 @@ const loading = ref(false);
|
||||
const authorizing = ref(false);
|
||||
const shopFormModalRef = ref();
|
||||
const pddShopDetailModalRef = ref();
|
||||
const pddOrderSyncModalRef = ref();
|
||||
const pddOrderConvertModalRef = ref();
|
||||
const biOrderStatCalcModalRef = ref();
|
||||
const pipelineDrawerRef = ref<InstanceType<typeof ShopOrderPipelineDrawer>>();
|
||||
|
||||
/** shopId -> 同步/转换/计算摘要 */
|
||||
const syncStatusMap = ref<Record<number, PddOrderSyncVO.ShopStatus>>({});
|
||||
@@ -455,15 +451,7 @@ function openPipelineStage(shop: ShopVO.Info, stage: PipelineStageKey) {
|
||||
message.warning('请先完成拼多多授权绑定');
|
||||
return;
|
||||
}
|
||||
if (stage === 'sync') {
|
||||
pddOrderSyncModalRef.value?.open(shop);
|
||||
return;
|
||||
}
|
||||
if (stage === 'convert') {
|
||||
pddOrderConvertModalRef.value?.open(shop);
|
||||
return;
|
||||
}
|
||||
biOrderStatCalcModalRef.value?.open(shop);
|
||||
pipelineDrawerRef.value?.open(shop, stage);
|
||||
}
|
||||
|
||||
function refreshTable() {
|
||||
@@ -707,16 +695,8 @@ onUnmounted(() => {
|
||||
|
||||
<ShopFormModal ref="shopFormModalRef" @success="handleModalSuccess" />
|
||||
<PddShopDetailModal ref="pddShopDetailModalRef" />
|
||||
<PddOrderSyncModal
|
||||
ref="pddOrderSyncModalRef"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
<PddOrderConvertModal
|
||||
ref="pddOrderConvertModalRef"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
<BiOrderStatCalcModal
|
||||
ref="biOrderStatCalcModalRef"
|
||||
<ShopOrderPipelineDrawer
|
||||
ref="pipelineDrawerRef"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
|
||||
Reference in New Issue
Block a user