mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 23:49:19 +08:00
feat: 工作台接入 BI 增量计算健康度(滞后/暂停/空闲)与按店明细恢复
This commit is contained in:
+6
@@ -26,4 +26,10 @@ public class BiStatProperties {
|
|||||||
|
|
||||||
/** 增量店态成功/跳过写库节流秒数 */
|
/** 增量店态成功/跳过写库节流秒数 */
|
||||||
private long incStatusFlushSeconds = 30;
|
private long incStatusFlushSeconds = 30;
|
||||||
|
|
||||||
|
/** 增量健康度:滞后阈值(分钟) */
|
||||||
|
private int incLagThresholdMinutes = 10;
|
||||||
|
|
||||||
|
/** 增量健康度:活跃判定窗口(小时);窗内无订单且无成功增量视为空闲 */
|
||||||
|
private int incActivityWindowHours = 24;
|
||||||
}
|
}
|
||||||
|
|||||||
+92
@@ -0,0 +1,92 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.bi.orderstat.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
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.po.BiOrderStatIncCalcPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.vo.BiOrderStatIncCalcStatusVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.vo.BiOrderStatIncHealthVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.service.BiOrderStatCalcTaskService;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.service.BiOrderStatIncHealthService;
|
||||||
|
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 com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** BI 增量计算健康度:公司汇总、按店明细、恢复暂停。 */
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/bi/order-stat/inc")
|
||||||
|
public class BiOrderStatIncHealthController {
|
||||||
|
|
||||||
|
private final BiOrderStatIncHealthService incHealthService;
|
||||||
|
private final BiOrderStatCalcTaskService calcTaskService;
|
||||||
|
private final ShopMapper shopMapper;
|
||||||
|
private final CurrentUserContext currentUserContext;
|
||||||
|
|
||||||
|
public BiOrderStatIncHealthController(BiOrderStatIncHealthService incHealthService,
|
||||||
|
BiOrderStatCalcTaskService calcTaskService,
|
||||||
|
ShopMapper shopMapper,
|
||||||
|
CurrentUserContext currentUserContext) {
|
||||||
|
this.incHealthService = incHealthService;
|
||||||
|
this.calcTaskService = calcTaskService;
|
||||||
|
this.shopMapper = shopMapper;
|
||||||
|
this.currentUserContext = currentUserContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/health")
|
||||||
|
@RequirePermission(value = "bi:order-stat:calc:read", description = "BI增量计算健康度", allowSuper = true)
|
||||||
|
public ApiResponse<BiOrderStatIncHealthVO.HealthSummary> health() {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
return ApiResponse.success(incHealthService.healthSummary(companyId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/shops")
|
||||||
|
@RequirePermission(value = "bi:order-stat:calc:read", description = "BI增量计算店列表", allowSuper = true)
|
||||||
|
public ApiResponse<List<BiOrderStatIncHealthVO.ShopRow>> listShops() {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
return ApiResponse.success(incHealthService.listShopRows(companyId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/resume-paused")
|
||||||
|
@RequirePermission(value = "bi:order-stat:calc:update", description = "批量恢复BI增量暂停店", allowSuper = true)
|
||||||
|
public ApiResponse<BiOrderStatIncHealthVO.ResumePausedResult> resumePaused() {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
return ApiResponse.success("已恢复暂停店", incHealthService.resumeAllPaused(companyId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/resume")
|
||||||
|
@RequirePermission(value = "bi:order-stat:calc:update", description = "恢复单店BI增量计算", allowSuper = true)
|
||||||
|
public ApiResponse<BiOrderStatIncCalcStatusVO> resumeOne(@RequestParam Long shopId) {
|
||||||
|
ShopPO shop = requireOwnedShop(shopId);
|
||||||
|
BiOrderStatIncCalcPO state = calcTaskService.resumeInc(shop.getCompanyId(), shop.getId());
|
||||||
|
return ApiResponse.success("已恢复计算", BiOrderStatIncCalcStatusVO.builder()
|
||||||
|
.shopId(shop.getId())
|
||||||
|
.status(state.getStatus())
|
||||||
|
.lastSummary(state.getLastSummary())
|
||||||
|
.lastError(state.getLastError())
|
||||||
|
.lastSuccessTime(state.getLastSuccessTime())
|
||||||
|
.lastStatDate(state.getLastStatDate())
|
||||||
|
.lastAppliedOrderId(state.getLastAppliedOrderId())
|
||||||
|
.lastSkipped(state.getLastSkipped())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ShopPO requireOwnedShop(Long shopId) {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
ShopPO shop = shopMapper.selectOne(new LambdaQueryWrapper<ShopPO>()
|
||||||
|
.eq(ShopPO::getId, shopId)
|
||||||
|
.eq(ShopPO::getCompanyId, companyId)
|
||||||
|
.last("LIMIT 1"));
|
||||||
|
if (shop == null) {
|
||||||
|
throw new BusinessException("店铺不存在或无权访问");
|
||||||
|
}
|
||||||
|
return shop;
|
||||||
|
}
|
||||||
|
}
|
||||||
+68
@@ -0,0 +1,68 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.vo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** BI 增量计算健康度(公司汇总 + 店行)。 */
|
||||||
|
public class BiOrderStatIncHealthVO {
|
||||||
|
|
||||||
|
/** 店健康档:OK / IDLE / LAGGED / PAUSED */
|
||||||
|
public static final String KIND_OK = "OK";
|
||||||
|
public static final String KIND_IDLE = "IDLE";
|
||||||
|
public static final String KIND_LAGGED = "LAGGED";
|
||||||
|
public static final String KIND_PAUSED = "PAUSED";
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class HealthSummary {
|
||||||
|
private int shopCount;
|
||||||
|
private int okCount;
|
||||||
|
private int idleCount;
|
||||||
|
private int laggedCount;
|
||||||
|
private int pausedCount;
|
||||||
|
/** 最差滞后分钟数;无滞后则为 null */
|
||||||
|
private Long worstLagMinutes;
|
||||||
|
private int lagThresholdMinutes;
|
||||||
|
private int activityWindowHours;
|
||||||
|
/** 无暂停且无滞后 */
|
||||||
|
private boolean healthy;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class ShopRow {
|
||||||
|
private Long shopId;
|
||||||
|
private String shopName;
|
||||||
|
private String platformCode;
|
||||||
|
/** 店态:1 正常 2 暂停;无记录则为 null */
|
||||||
|
private Integer status;
|
||||||
|
/** OK / IDLE / LAGGED / PAUSED */
|
||||||
|
private String healthKind;
|
||||||
|
private Long lagMinutes;
|
||||||
|
private LocalDateTime lastSuccessTime;
|
||||||
|
private LocalDate lastStatDate;
|
||||||
|
private String lastSummary;
|
||||||
|
private String lastError;
|
||||||
|
private boolean recentOrderActivity;
|
||||||
|
private boolean recentIncSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class ResumePausedResult {
|
||||||
|
private int resumedCount;
|
||||||
|
private List<Long> shopIds;
|
||||||
|
}
|
||||||
|
}
|
||||||
+198
@@ -0,0 +1,198 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.bi.orderstat.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.infra.config.BiStatProperties;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.mapper.BiOrderStatIncCalcMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.po.BiOrderStatIncCalcPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.vo.BiOrderStatIncHealthVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.order.mapper.OrderMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.shop.mapper.ShopMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.po.ShopPO;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BI 增量计算健康度:公司汇总 / 按店明细 / 批量恢复暂停。
|
||||||
|
* 滞后仅评估「近活动窗有订单或有成功增量」的店,安静店标 IDLE。
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class BiOrderStatIncHealthService {
|
||||||
|
|
||||||
|
private static final ZoneId ZONE = ZoneId.of("Asia/Shanghai");
|
||||||
|
|
||||||
|
private final ShopMapper shopMapper;
|
||||||
|
private final OrderMapper orderMapper;
|
||||||
|
private final BiOrderStatIncCalcMapper incCalcMapper;
|
||||||
|
private final BiOrderStatCalcTaskService calcTaskService;
|
||||||
|
private final BiStatProperties biStatProperties;
|
||||||
|
|
||||||
|
public BiOrderStatIncHealthVO.HealthSummary healthSummary(Long companyId) {
|
||||||
|
List<BiOrderStatIncHealthVO.ShopRow> rows = listShopRows(companyId);
|
||||||
|
int ok = 0;
|
||||||
|
int idle = 0;
|
||||||
|
int lagged = 0;
|
||||||
|
int paused = 0;
|
||||||
|
Long worst = null;
|
||||||
|
for (BiOrderStatIncHealthVO.ShopRow row : rows) {
|
||||||
|
switch (row.getHealthKind()) {
|
||||||
|
case BiOrderStatIncHealthVO.KIND_PAUSED -> paused++;
|
||||||
|
case BiOrderStatIncHealthVO.KIND_LAGGED -> {
|
||||||
|
lagged++;
|
||||||
|
if (row.getLagMinutes() != null
|
||||||
|
&& (worst == null || row.getLagMinutes() > worst)) {
|
||||||
|
worst = row.getLagMinutes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case BiOrderStatIncHealthVO.KIND_IDLE -> idle++;
|
||||||
|
default -> ok++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return BiOrderStatIncHealthVO.HealthSummary.builder()
|
||||||
|
.shopCount(rows.size())
|
||||||
|
.okCount(ok)
|
||||||
|
.idleCount(idle)
|
||||||
|
.laggedCount(lagged)
|
||||||
|
.pausedCount(paused)
|
||||||
|
.worstLagMinutes(worst)
|
||||||
|
.lagThresholdMinutes(lagThresholdMinutes())
|
||||||
|
.activityWindowHours(activityWindowHours())
|
||||||
|
.healthy(paused == 0 && lagged == 0)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BiOrderStatIncHealthVO.ShopRow> listShopRows(Long companyId) {
|
||||||
|
if (companyId == null) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
List<ShopPO> shops = shopMapper.selectList(new LambdaQueryWrapper<ShopPO>()
|
||||||
|
.eq(ShopPO::getCompanyId, companyId)
|
||||||
|
.orderByAsc(ShopPO::getId));
|
||||||
|
if (shops.isEmpty()) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalDateTime now = LocalDateTime.now(ZONE);
|
||||||
|
LocalDateTime activitySince = now.minusHours(activityWindowHours());
|
||||||
|
long lagThreshold = lagThresholdMinutes();
|
||||||
|
|
||||||
|
Set<Long> activeShopIds = new HashSet<>(
|
||||||
|
orderMapper.selectShopIdsWithRecentActivity(companyId, activitySince));
|
||||||
|
|
||||||
|
Map<Long, BiOrderStatIncCalcPO> stateByShop = incCalcMapper.selectList(
|
||||||
|
new LambdaQueryWrapper<BiOrderStatIncCalcPO>()
|
||||||
|
.eq(BiOrderStatIncCalcPO::getCompanyId, companyId))
|
||||||
|
.stream()
|
||||||
|
.filter(s -> s.getShopId() != null)
|
||||||
|
.collect(Collectors.toMap(BiOrderStatIncCalcPO::getShopId, s -> s, (a, b) -> a));
|
||||||
|
|
||||||
|
List<BiOrderStatIncHealthVO.ShopRow> rows = new ArrayList<>();
|
||||||
|
for (ShopPO shop : shops) {
|
||||||
|
BiOrderStatIncCalcPO state = stateByShop.get(shop.getId());
|
||||||
|
boolean recentOrder = activeShopIds.contains(shop.getId());
|
||||||
|
boolean recentInc = state != null
|
||||||
|
&& state.getLastSuccessTime() != null
|
||||||
|
&& !state.getLastSuccessTime().isBefore(activitySince);
|
||||||
|
boolean eligible = recentOrder || recentInc;
|
||||||
|
|
||||||
|
Integer status = state != null ? state.getStatus() : null;
|
||||||
|
boolean paused = status != null && status == BiOrderStatIncCalcPO.STATUS_PAUSED;
|
||||||
|
|
||||||
|
Long lagMinutes = null;
|
||||||
|
if (state != null && state.getLastSuccessTime() != null) {
|
||||||
|
lagMinutes = Math.max(0L,
|
||||||
|
Duration.between(state.getLastSuccessTime(), now).toMinutes());
|
||||||
|
}
|
||||||
|
|
||||||
|
String kind;
|
||||||
|
if (paused) {
|
||||||
|
kind = BiOrderStatIncHealthVO.KIND_PAUSED;
|
||||||
|
} else if (!eligible) {
|
||||||
|
kind = BiOrderStatIncHealthVO.KIND_IDLE;
|
||||||
|
lagMinutes = null;
|
||||||
|
} else if (state == null || state.getLastSuccessTime() == null
|
||||||
|
|| lagMinutes == null || lagMinutes > lagThreshold) {
|
||||||
|
kind = BiOrderStatIncHealthVO.KIND_LAGGED;
|
||||||
|
if (state == null || state.getLastSuccessTime() == null) {
|
||||||
|
lagMinutes = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
kind = BiOrderStatIncHealthVO.KIND_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
rows.add(BiOrderStatIncHealthVO.ShopRow.builder()
|
||||||
|
.shopId(shop.getId())
|
||||||
|
.shopName(shop.getName())
|
||||||
|
.platformCode(shop.getPlatformCode())
|
||||||
|
.status(status)
|
||||||
|
.healthKind(kind)
|
||||||
|
.lagMinutes(lagMinutes)
|
||||||
|
.lastSuccessTime(state != null ? state.getLastSuccessTime() : null)
|
||||||
|
.lastStatDate(state != null ? state.getLastStatDate() : null)
|
||||||
|
.lastSummary(state != null ? state.getLastSummary() : null)
|
||||||
|
.lastError(state != null ? state.getLastError() : null)
|
||||||
|
.recentOrderActivity(recentOrder)
|
||||||
|
.recentIncSuccess(recentInc)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
rows.sort(Comparator
|
||||||
|
.comparingInt((BiOrderStatIncHealthVO.ShopRow r) -> kindRank(r.getHealthKind()))
|
||||||
|
.thenComparing(r -> r.getLagMinutes() == null ? -1L : r.getLagMinutes(),
|
||||||
|
Comparator.reverseOrder())
|
||||||
|
.thenComparing(r -> r.getShopId() == null ? 0L : r.getShopId()));
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 恢复公司下全部暂停店。 */
|
||||||
|
public BiOrderStatIncHealthVO.ResumePausedResult resumeAllPaused(Long companyId) {
|
||||||
|
List<BiOrderStatIncCalcPO> paused = incCalcMapper.selectList(
|
||||||
|
new LambdaQueryWrapper<BiOrderStatIncCalcPO>()
|
||||||
|
.eq(BiOrderStatIncCalcPO::getCompanyId, companyId)
|
||||||
|
.eq(BiOrderStatIncCalcPO::getStatus, BiOrderStatIncCalcPO.STATUS_PAUSED));
|
||||||
|
List<Long> shopIds = new ArrayList<>();
|
||||||
|
for (BiOrderStatIncCalcPO row : paused) {
|
||||||
|
if (row.getShopId() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
calcTaskService.resumeInc(companyId, row.getShopId());
|
||||||
|
shopIds.add(row.getShopId());
|
||||||
|
}
|
||||||
|
return BiOrderStatIncHealthVO.ResumePausedResult.builder()
|
||||||
|
.resumedCount(shopIds.size())
|
||||||
|
.shopIds(shopIds)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int lagThresholdMinutes() {
|
||||||
|
return Math.max(1, biStatProperties.getIncLagThresholdMinutes());
|
||||||
|
}
|
||||||
|
|
||||||
|
private int activityWindowHours() {
|
||||||
|
return Math.max(1, biStatProperties.getIncActivityWindowHours());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int kindRank(String kind) {
|
||||||
|
if (BiOrderStatIncHealthVO.KIND_PAUSED.equals(kind)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (BiOrderStatIncHealthVO.KIND_LAGGED.equals(kind)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (BiOrderStatIncHealthVO.KIND_IDLE.equals(kind)) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
@@ -27,6 +27,10 @@ public interface OrderMapper extends BaseMapper<OrderPO> {
|
|||||||
@Param("startTime") LocalDateTime startTime,
|
@Param("startTime") LocalDateTime startTime,
|
||||||
@Param("endTime") LocalDateTime endTime);
|
@Param("endTime") LocalDateTime endTime);
|
||||||
|
|
||||||
|
/** 近窗内有订单活动的店铺(按 update_time,覆盖改单/转换) */
|
||||||
|
List<Long> selectShopIdsWithRecentActivity(@Param("companyId") Long companyId,
|
||||||
|
@Param("since") LocalDateTime since);
|
||||||
|
|
||||||
/** 新建 SKU 后挂 orphan 明细(仅补 product_sku_id;商品归属经 sku) */
|
/** 新建 SKU 后挂 orphan 明细(仅补 product_sku_id;商品归属经 sku) */
|
||||||
@Update("""
|
@Update("""
|
||||||
UPDATE ec_order_item i
|
UPDATE ec_order_item i
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ ecom:
|
|||||||
inc-max-retry: 20
|
inc-max-retry: 20
|
||||||
full-listener-concurrency: "2-4"
|
full-listener-concurrency: "2-4"
|
||||||
inc-listener-concurrency: "2-4"
|
inc-listener-concurrency: "2-4"
|
||||||
|
inc-lag-threshold-minutes: 10
|
||||||
|
inc-activity-window-hours: 24
|
||||||
license:
|
license:
|
||||||
license-file: config/license.key
|
license-file: config/license.key
|
||||||
revocation-file: config/revoked.jti
|
revocation-file: config/revoked.jti
|
||||||
|
|||||||
@@ -95,4 +95,11 @@
|
|||||||
AND o.order_time < #{endTime}
|
AND o.order_time < #{endTime}
|
||||||
ORDER BY o.shop_id, statDate
|
ORDER BY o.shop_id, statDate
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectShopIdsWithRecentActivity" resultType="long">
|
||||||
|
SELECT DISTINCT o.shop_id
|
||||||
|
FROM ec_order o
|
||||||
|
WHERE o.company_id = #{companyId}
|
||||||
|
AND o.update_time >= #{since}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import type { BiOrderStatIncHealthVO } from './types';
|
||||||
|
|
||||||
|
import { requestClient } from '#/api/request';
|
||||||
|
|
||||||
|
/** BI 增量计算健康度摘要 */
|
||||||
|
export async function getBiOrderStatIncHealthApi() {
|
||||||
|
return requestClient.get<BiOrderStatIncHealthVO.HealthSummary>(
|
||||||
|
'/bi/order-stat/inc/health',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** BI 增量计算按店明细 */
|
||||||
|
export async function listBiOrderStatIncShopsApi() {
|
||||||
|
return requestClient.get<BiOrderStatIncHealthVO.ShopRow[]>(
|
||||||
|
'/bi/order-stat/inc/shops',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量恢复暂停店 */
|
||||||
|
export async function resumeBiOrderStatIncPausedApi() {
|
||||||
|
return requestClient.post<BiOrderStatIncHealthVO.ResumePausedResult>(
|
||||||
|
'/bi/order-stat/inc/resume-paused',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 恢复单店增量计算 */
|
||||||
|
export async function resumeBiOrderStatIncShopApi(shopId: number) {
|
||||||
|
return requestClient.post(
|
||||||
|
'/bi/order-stat/inc/resume',
|
||||||
|
undefined,
|
||||||
|
{ params: { shopId } },
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './apis';
|
||||||
|
export type * from './types';
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export type * from './types.vo';
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
export namespace BiOrderStatIncHealthVO {
|
||||||
|
export interface HealthSummary {
|
||||||
|
shopCount: number;
|
||||||
|
okCount: number;
|
||||||
|
idleCount: number;
|
||||||
|
laggedCount: number;
|
||||||
|
pausedCount: number;
|
||||||
|
worstLagMinutes?: number;
|
||||||
|
lagThresholdMinutes: number;
|
||||||
|
activityWindowHours: number;
|
||||||
|
healthy: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ShopRow {
|
||||||
|
shopId: number;
|
||||||
|
shopName?: string;
|
||||||
|
platformCode?: string;
|
||||||
|
status?: number;
|
||||||
|
/** OK / IDLE / LAGGED / PAUSED */
|
||||||
|
healthKind: string;
|
||||||
|
lagMinutes?: number;
|
||||||
|
lastSuccessTime?: string;
|
||||||
|
lastStatDate?: string;
|
||||||
|
lastSummary?: string;
|
||||||
|
lastError?: string;
|
||||||
|
recentOrderActivity?: boolean;
|
||||||
|
recentIncSuccess?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ResumePausedResult {
|
||||||
|
resumedCount: number;
|
||||||
|
shopIds: number[];
|
||||||
|
}
|
||||||
|
}
|
||||||
+154
-30
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { BiOrderStatDirtyVO } from '#/api/bi/order-stat/dirty';
|
import type { BiOrderStatDirtyVO } from '#/api/bi/order-stat/dirty';
|
||||||
|
import type { BiOrderStatIncHealthVO } from '#/api/bi/order-stat/inc';
|
||||||
|
|
||||||
import { computed, ref, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
|
|
||||||
@@ -12,9 +13,14 @@ import {
|
|||||||
getBiOrderStatDirtyHealthApi,
|
getBiOrderStatDirtyHealthApi,
|
||||||
listBiOrderStatDirtyPendingApi,
|
listBiOrderStatDirtyPendingApi,
|
||||||
} from '#/api/bi/order-stat/dirty';
|
} from '#/api/bi/order-stat/dirty';
|
||||||
|
import {
|
||||||
|
getBiOrderStatIncHealthApi,
|
||||||
|
resumeBiOrderStatIncPausedApi,
|
||||||
|
} from '#/api/bi/order-stat/inc';
|
||||||
|
|
||||||
import BiHealthDimensionCard from './BiHealthDimensionCard.vue';
|
|
||||||
import BiDirtyDayModal from './BiDirtyDayModal.vue';
|
import BiDirtyDayModal from './BiDirtyDayModal.vue';
|
||||||
|
import BiHealthDimensionCard from './BiHealthDimensionCard.vue';
|
||||||
|
import BiIncHealthModal from './BiIncHealthModal.vue';
|
||||||
|
|
||||||
defineOptions({ name: 'BiDataHealthToolbarButton' });
|
defineOptions({ name: 'BiDataHealthToolbarButton' });
|
||||||
|
|
||||||
@@ -34,11 +40,14 @@ const HeartPulseIcon = createIconifyIcon('lucide:heart-pulse');
|
|||||||
const RefreshCwIcon = createIconifyIcon('lucide:refresh-cw');
|
const RefreshCwIcon = createIconifyIcon('lucide:refresh-cw');
|
||||||
|
|
||||||
const health = ref<BiOrderStatDirtyVO.HealthSummary | null>(null);
|
const health = ref<BiOrderStatDirtyVO.HealthSummary | null>(null);
|
||||||
|
const incHealth = ref<BiOrderStatIncHealthVO.HealthSummary | null>(null);
|
||||||
const previewRows = ref<BiOrderStatDirtyVO.PendingRow[]>([]);
|
const previewRows = ref<BiOrderStatDirtyVO.PendingRow[]>([]);
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const previewLoading = ref(false);
|
const previewLoading = ref(false);
|
||||||
const applying = ref(false);
|
const applying = ref(false);
|
||||||
|
const resumingInc = ref(false);
|
||||||
const dirtyModalRef = ref<InstanceType<typeof BiDirtyDayModal> | null>(null);
|
const dirtyModalRef = ref<InstanceType<typeof BiDirtyDayModal> | null>(null);
|
||||||
|
const incModalRef = ref<InstanceType<typeof BiIncHealthModal> | null>(null);
|
||||||
|
|
||||||
const showLoading = computed(() => loading.value || !!props.syncRefreshing);
|
const showLoading = computed(() => loading.value || !!props.syncRefreshing);
|
||||||
|
|
||||||
@@ -50,31 +59,55 @@ const dirtyStatus = computed<'ok' | 'pending' | 'running' | 'loading'>(() => {
|
|||||||
return 'pending';
|
return 'pending';
|
||||||
});
|
});
|
||||||
|
|
||||||
const overallAttention = computed(() => dirtyStatus.value !== 'ok');
|
const incStatus = computed<'ok' | 'pending' | 'error' | 'loading'>(() => {
|
||||||
|
if (showLoading.value && !incHealth.value) return 'loading';
|
||||||
|
const h = incHealth.value;
|
||||||
|
if (!h) return 'ok';
|
||||||
|
if (h.pausedCount > 0) return 'error';
|
||||||
|
if (h.laggedCount > 0) return 'pending';
|
||||||
|
return 'ok';
|
||||||
|
});
|
||||||
|
|
||||||
|
const incStatusLabel = computed(() => {
|
||||||
|
const h = incHealth.value;
|
||||||
|
if (!h) return undefined;
|
||||||
|
if (h.pausedCount > 0) return `${h.pausedCount} 店暂停`;
|
||||||
|
if (h.laggedCount > 0) return `${h.laggedCount} 店滞后`;
|
||||||
|
if (h.idleCount > 0 && h.okCount === 0) return '空闲';
|
||||||
|
return '正常';
|
||||||
|
});
|
||||||
|
|
||||||
|
const overallAttention = computed(
|
||||||
|
() => dirtyStatus.value !== 'ok' || incStatus.value !== 'ok',
|
||||||
|
);
|
||||||
|
|
||||||
const triggerDotClass = computed(() => {
|
const triggerDotClass = computed(() => {
|
||||||
switch (dirtyStatus.value) {
|
if (incStatus.value === 'error' || dirtyStatus.value === 'pending') {
|
||||||
case 'pending': {
|
return incStatus.value === 'error' ? 'bg-red-500' : 'bg-amber-500';
|
||||||
return 'bg-amber-500';
|
|
||||||
}
|
|
||||||
case 'running': {
|
|
||||||
return 'bg-blue-500 animate-pulse';
|
|
||||||
}
|
|
||||||
case 'ok': {
|
|
||||||
return 'bg-emerald-500';
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
return 'bg-slate-300';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (dirtyStatus.value === 'running' || incStatus.value === 'pending') {
|
||||||
|
return dirtyStatus.value === 'running'
|
||||||
|
? 'bg-blue-500 animate-pulse'
|
||||||
|
: 'bg-amber-500';
|
||||||
|
}
|
||||||
|
if (dirtyStatus.value === 'ok' && incStatus.value === 'ok') {
|
||||||
|
return 'bg-emerald-500';
|
||||||
|
}
|
||||||
|
return 'bg-slate-300';
|
||||||
});
|
});
|
||||||
|
|
||||||
const triggerLabel = computed(() => {
|
const triggerLabel = computed(() => {
|
||||||
const h = health.value;
|
if (showLoading.value && !health.value && !incHealth.value) return 'BI健康';
|
||||||
if (showLoading.value && !h) return 'BI健康';
|
const dirty = health.value;
|
||||||
if (!h || h.pendingDayCount <= 0) return 'BI健康';
|
const inc = incHealth.value;
|
||||||
if (h.hasRunning) return `重算中·${h.pendingDayCount}`;
|
if (inc && inc.pausedCount > 0) return `增量暂停·${inc.pausedCount}`;
|
||||||
return `待重算·${h.pendingDayCount}`;
|
if (dirty && dirty.pendingDayCount > 0) {
|
||||||
|
return dirty.hasRunning
|
||||||
|
? `重算中·${dirty.pendingDayCount}`
|
||||||
|
: `待重算·${dirty.pendingDayCount}`;
|
||||||
|
}
|
||||||
|
if (inc && inc.laggedCount > 0) return `增量滞后·${inc.laggedCount}`;
|
||||||
|
return 'BI健康';
|
||||||
});
|
});
|
||||||
|
|
||||||
const dirtyMetrics = computed(() => {
|
const dirtyMetrics = computed(() => {
|
||||||
@@ -92,6 +125,41 @@ const dirtyMetrics = computed(() => {
|
|||||||
return rows;
|
return rows;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const incMetrics = computed(() => {
|
||||||
|
const h = incHealth.value;
|
||||||
|
if (!h) {
|
||||||
|
return [{ label: '状态', value: '加载中…' }];
|
||||||
|
}
|
||||||
|
if (h.healthy) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
label: '店铺',
|
||||||
|
value: `${h.shopCount} 家(空闲 ${h.idleCount})`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '阈值阈值',
|
||||||
|
value: `${h.lagThresholdMinutes} 分钟`,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
const rows: { label: string; value: string }[] = [
|
||||||
|
{ label: '店铺', value: `${h.shopCount} 家` },
|
||||||
|
];
|
||||||
|
if (h.pausedCount > 0) {
|
||||||
|
rows.push({ label: '暂停', value: `${h.pausedCount} 家` });
|
||||||
|
}
|
||||||
|
if (h.laggedCount > 0) {
|
||||||
|
rows.push({
|
||||||
|
label: '滞后',
|
||||||
|
value:
|
||||||
|
h.worstLagMinutes != null
|
||||||
|
? `${h.laggedCount} 家(最差 ${h.worstLagMinutes} 分)`
|
||||||
|
: `${h.laggedCount} 家`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
|
});
|
||||||
|
|
||||||
const previewPending = computed(
|
const previewPending = computed(
|
||||||
() => previewRows.value.filter((r) => r.status === 'PENDING').length,
|
() => previewRows.value.filter((r) => r.status === 'PENDING').length,
|
||||||
);
|
);
|
||||||
@@ -106,17 +174,38 @@ const primaryDisabled = computed(
|
|||||||
() => !health.value || health.value.pendingDayCount <= 0,
|
() => !health.value || health.value.pendingDayCount <= 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const incPrimaryLabel = computed(() =>
|
||||||
|
(incHealth.value?.pausedCount ?? 0) > 0 ? '恢复暂停店' : undefined,
|
||||||
|
);
|
||||||
|
const incPrimaryDisabled = computed(
|
||||||
|
() => (incHealth.value?.pausedCount ?? 0) <= 0,
|
||||||
|
);
|
||||||
|
|
||||||
const reasonLabels: Record<string, string> = {
|
const reasonLabels: Record<string, string> = {
|
||||||
COST: '成本',
|
COST: '成本',
|
||||||
PRODUCT_DIM: '迁品',
|
PRODUCT_DIM: '迁品',
|
||||||
};
|
};
|
||||||
|
|
||||||
async function refreshHealth() {
|
async function refreshDirtyHealth() {
|
||||||
loading.value = true;
|
|
||||||
try {
|
try {
|
||||||
health.value = (await getBiOrderStatDirtyHealthApi()) ?? null;
|
health.value = (await getBiOrderStatDirtyHealthApi()) ?? null;
|
||||||
} catch {
|
} catch {
|
||||||
health.value = null;
|
health.value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshIncHealth() {
|
||||||
|
try {
|
||||||
|
incHealth.value = (await getBiOrderStatIncHealthApi()) ?? null;
|
||||||
|
} catch {
|
||||||
|
incHealth.value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshHealth() {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
await Promise.all([refreshDirtyHealth(), refreshIncHealth()]);
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
@@ -149,11 +238,16 @@ function handlePopoverOpen(open: boolean) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function openDetailModal() {
|
function openDirtyDetailModal() {
|
||||||
emit('update:open', false);
|
emit('update:open', false);
|
||||||
void dirtyModalRef.value?.open();
|
void dirtyModalRef.value?.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openIncDetailModal() {
|
||||||
|
emit('update:open', false);
|
||||||
|
void incModalRef.value?.open();
|
||||||
|
}
|
||||||
|
|
||||||
async function handleQuickApply() {
|
async function handleQuickApply() {
|
||||||
if (primaryDisabled.value) {
|
if (primaryDisabled.value) {
|
||||||
message.info('当前没有待处理的脏日');
|
message.info('当前没有待处理的脏日');
|
||||||
@@ -177,10 +271,31 @@ async function handleQuickApply() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleResumeIncPaused() {
|
||||||
|
if (incPrimaryDisabled.value) {
|
||||||
|
message.info('没有暂停中的店铺');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resumingInc.value = true;
|
||||||
|
try {
|
||||||
|
const result = await resumeBiOrderStatIncPausedApi();
|
||||||
|
message.success(`已恢复 ${result?.resumedCount ?? 0} 家暂停店`);
|
||||||
|
await refreshAll();
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
} finally {
|
||||||
|
resumingInc.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function onModalApplied() {
|
function onModalApplied() {
|
||||||
void refreshAll();
|
void refreshAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onIncRefreshed() {
|
||||||
|
void refreshHealth();
|
||||||
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.open,
|
() => props.open,
|
||||||
(open) => {
|
(open) => {
|
||||||
@@ -207,7 +322,7 @@ defineExpose({ refresh: refreshSummary, refreshAll });
|
|||||||
BI 数据健康度
|
BI 数据健康度
|
||||||
</div>
|
</div>
|
||||||
<div class="text-xs text-slate-500 dark:text-slate-400">
|
<div class="text-xs text-slate-500 dark:text-slate-400">
|
||||||
多维度监测;当前已接入统计重算
|
脏日重算与增量计算
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
@@ -235,7 +350,7 @@ defineExpose({ refresh: refreshSummary, refreshAll });
|
|||||||
:primary-loading="applying"
|
:primary-loading="applying"
|
||||||
:primary-disabled="primaryDisabled"
|
:primary-disabled="primaryDisabled"
|
||||||
@primary="handleQuickApply"
|
@primary="handleQuickApply"
|
||||||
@secondary="openDetailModal"
|
@secondary="openDirtyDetailModal"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
v-if="health && health.pendingDayCount > 0"
|
v-if="health && health.pendingDayCount > 0"
|
||||||
@@ -273,7 +388,8 @@ defineExpose({ refresh: refreshSummary, refreshAll });
|
|||||||
{{
|
{{
|
||||||
(row.reasons ?? [])
|
(row.reasons ?? [])
|
||||||
.map((r) => reasonLabels[r] ?? r)
|
.map((r) => reasonLabels[r] ?? r)
|
||||||
.join('/') || (row.status === 'RUNNING' ? '重算' : '待算')
|
.join('/') ||
|
||||||
|
(row.status === 'RUNNING' ? '重算' : '待算')
|
||||||
}}
|
}}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
@@ -289,11 +405,18 @@ defineExpose({ refresh: refreshSummary, refreshAll });
|
|||||||
</BiHealthDimensionCard>
|
</BiHealthDimensionCard>
|
||||||
|
|
||||||
<BiHealthDimensionCard
|
<BiHealthDimensionCard
|
||||||
title="增量同步"
|
title="BI 增量计算"
|
||||||
icon="lucide:radio"
|
icon="lucide:radio"
|
||||||
status="soon"
|
:status="incStatus"
|
||||||
coming-soon
|
:status-label="incStatusLabel"
|
||||||
description="监测订单增量、广告费转换等管线是否滞后或暂停。"
|
description="日常订单增量是否及时灌入统计;暂停优先于滞后,安静店不计不健康。"
|
||||||
|
:metrics="incMetrics"
|
||||||
|
:primary-action-label="incPrimaryLabel"
|
||||||
|
secondary-action-label="查看明细"
|
||||||
|
:primary-loading="resumingInc"
|
||||||
|
:primary-disabled="incPrimaryDisabled"
|
||||||
|
@primary="handleResumeIncPaused"
|
||||||
|
@secondary="openIncDetailModal"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<BiHealthDimensionCard
|
<BiHealthDimensionCard
|
||||||
@@ -343,6 +466,7 @@ defineExpose({ refresh: refreshSummary, refreshAll });
|
|||||||
</Popover>
|
</Popover>
|
||||||
|
|
||||||
<BiDirtyDayModal ref="dirtyModalRef" @applied="onModalApplied" />
|
<BiDirtyDayModal ref="dirtyModalRef" @applied="onModalApplied" />
|
||||||
|
<BiIncHealthModal ref="incModalRef" @refreshed="onIncRefreshed" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
+3
-1
@@ -14,7 +14,7 @@ export interface HealthMetric {
|
|||||||
export interface HealthDimensionCardProps {
|
export interface HealthDimensionCardProps {
|
||||||
title: string;
|
title: string;
|
||||||
icon: string;
|
icon: string;
|
||||||
status?: 'ok' | 'pending' | 'running' | 'loading' | 'soon';
|
status?: 'ok' | 'pending' | 'running' | 'loading' | 'soon' | 'error';
|
||||||
statusLabel?: string;
|
statusLabel?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
metrics?: HealthMetric[];
|
metrics?: HealthMetric[];
|
||||||
@@ -48,6 +48,7 @@ const statusColor = {
|
|||||||
running: 'processing',
|
running: 'processing',
|
||||||
loading: 'default',
|
loading: 'default',
|
||||||
soon: 'default',
|
soon: 'default',
|
||||||
|
error: 'error',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
const statusText = {
|
const statusText = {
|
||||||
@@ -56,6 +57,7 @@ const statusText = {
|
|||||||
running: '重算中',
|
running: '重算中',
|
||||||
loading: '加载中',
|
loading: '加载中',
|
||||||
soon: '即将推出',
|
soon: '即将推出',
|
||||||
|
error: '异常',
|
||||||
} as const;
|
} as const;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
+217
@@ -0,0 +1,217 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import type { BiOrderStatIncHealthVO } from '#/api/bi/order-stat/inc';
|
||||||
|
|
||||||
|
import { h, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { Alert, Button, Table, Tag, message } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import {
|
||||||
|
listBiOrderStatIncShopsApi,
|
||||||
|
resumeBiOrderStatIncPausedApi,
|
||||||
|
resumeBiOrderStatIncShopApi,
|
||||||
|
} from '#/api/bi/order-stat/inc';
|
||||||
|
|
||||||
|
defineOptions({ name: 'BiIncHealthModal' });
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
refreshed: [];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const [IncModal, incModalApi] = useVbenModal({
|
||||||
|
title: 'BI 增量计算 · 店铺明细',
|
||||||
|
class: 'w-[920px] max-w-[calc(100vw-2rem)]',
|
||||||
|
draggable: true,
|
||||||
|
contentClass: 'px-5 py-4 min-h-[360px]',
|
||||||
|
showCancelButton: true,
|
||||||
|
cancelText: '关闭',
|
||||||
|
showConfirmButton: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const loading = ref(false);
|
||||||
|
const resumingAll = ref(false);
|
||||||
|
const resumingShopId = ref<number | null>(null);
|
||||||
|
const rows = ref<BiOrderStatIncHealthVO.ShopRow[]>([]);
|
||||||
|
|
||||||
|
const pausedCount = () =>
|
||||||
|
rows.value.filter((r) => r.healthKind === 'PAUSED').length;
|
||||||
|
|
||||||
|
const kindMeta: Record<
|
||||||
|
string,
|
||||||
|
{ color: string; label: string }
|
||||||
|
> = {
|
||||||
|
PAUSED: { color: 'error', label: '暂停' },
|
||||||
|
LAGGED: { color: 'warning', label: '滞后' },
|
||||||
|
IDLE: { color: 'default', label: '空闲' },
|
||||||
|
OK: { color: 'success', label: '正常' },
|
||||||
|
};
|
||||||
|
|
||||||
|
function formatLag(minutes?: number | null) {
|
||||||
|
if (minutes == null) return '—';
|
||||||
|
if (minutes < 60) return `${minutes} 分`;
|
||||||
|
const h = Math.floor(minutes / 60);
|
||||||
|
const m = minutes % 60;
|
||||||
|
return m > 0 ? `${h} 时 ${m} 分` : `${h} 时`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
title: '店铺',
|
||||||
|
key: 'shop',
|
||||||
|
width: 160,
|
||||||
|
customRender: ({ record }: { record: BiOrderStatIncHealthVO.ShopRow }) =>
|
||||||
|
record.shopName || `#${record.shopId}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
key: 'healthKind',
|
||||||
|
width: 90,
|
||||||
|
customRender: ({ record }: { record: BiOrderStatIncHealthVO.ShopRow }) => {
|
||||||
|
const meta = kindMeta[record.healthKind] ?? {
|
||||||
|
color: 'default',
|
||||||
|
label: record.healthKind,
|
||||||
|
};
|
||||||
|
return h(Tag, { color: meta.color }, () => meta.label);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '滞后',
|
||||||
|
key: 'lag',
|
||||||
|
width: 100,
|
||||||
|
customRender: ({ record }: { record: BiOrderStatIncHealthVO.ShopRow }) =>
|
||||||
|
formatLag(record.lagMinutes),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '最近成功',
|
||||||
|
dataIndex: 'lastSuccessTime',
|
||||||
|
key: 'lastSuccessTime',
|
||||||
|
width: 170,
|
||||||
|
customRender: ({ text }: { text?: string }) => text || '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '统计日',
|
||||||
|
dataIndex: 'lastStatDate',
|
||||||
|
key: 'lastStatDate',
|
||||||
|
width: 110,
|
||||||
|
customRender: ({ text }: { text?: string }) => text || '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '摘要',
|
||||||
|
key: 'summary',
|
||||||
|
ellipsis: true,
|
||||||
|
customRender: ({ record }: { record: BiOrderStatIncHealthVO.ShopRow }) =>
|
||||||
|
record.lastError || record.lastSummary || '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
key: 'action',
|
||||||
|
width: 90,
|
||||||
|
customRender: ({ record }: { record: BiOrderStatIncHealthVO.ShopRow }) => {
|
||||||
|
if (record.healthKind !== 'PAUSED') {
|
||||||
|
return '—';
|
||||||
|
}
|
||||||
|
return h(
|
||||||
|
Button,
|
||||||
|
{
|
||||||
|
type: 'link',
|
||||||
|
size: 'small',
|
||||||
|
loading: resumingShopId.value === record.shopId,
|
||||||
|
onClick: () => void handleResumeOne(record.shopId),
|
||||||
|
},
|
||||||
|
() => '恢复',
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
async function reload() {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
rows.value = (await listBiOrderStatIncShopsApi()) ?? [];
|
||||||
|
} catch {
|
||||||
|
rows.value = [];
|
||||||
|
message.error('加载增量店态失败');
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function open() {
|
||||||
|
incModalApi.open();
|
||||||
|
await reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleResumeOne(shopId: number) {
|
||||||
|
resumingShopId.value = shopId;
|
||||||
|
try {
|
||||||
|
await resumeBiOrderStatIncShopApi(shopId);
|
||||||
|
message.success('已恢复该店增量计算');
|
||||||
|
await reload();
|
||||||
|
emit('refreshed');
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
} finally {
|
||||||
|
resumingShopId.value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleResumeAll() {
|
||||||
|
if (pausedCount() === 0) {
|
||||||
|
message.info('没有暂停中的店铺');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resumingAll.value = true;
|
||||||
|
try {
|
||||||
|
const result = await resumeBiOrderStatIncPausedApi();
|
||||||
|
message.success(`已恢复 ${result?.resumedCount ?? 0} 家暂停店`);
|
||||||
|
await reload();
|
||||||
|
emit('refreshed');
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
} finally {
|
||||||
|
resumingAll.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ open, reload });
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<IncModal>
|
||||||
|
<Alert
|
||||||
|
type="info"
|
||||||
|
show-icon
|
||||||
|
class="mb-4"
|
||||||
|
message="暂停优先于滞后。近 24 小时无订单且无成功增量的店标为空闲,不计入不健康。"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="mb-3 flex items-center justify-between gap-2">
|
||||||
|
<span class="text-sm text-slate-600 dark:text-slate-300">
|
||||||
|
共 {{ rows.length }} 家店铺
|
||||||
|
<template v-if="pausedCount() > 0">
|
||||||
|
· 暂停 {{ pausedCount() }}
|
||||||
|
</template>
|
||||||
|
</span>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
danger
|
||||||
|
:loading="resumingAll"
|
||||||
|
:disabled="pausedCount() === 0"
|
||||||
|
@click="handleResumeAll"
|
||||||
|
>
|
||||||
|
恢复全部暂停
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
:loading="loading"
|
||||||
|
:columns="columns"
|
||||||
|
:data-source="rows"
|
||||||
|
:pagination="{ pageSize: 10, showSizeChanger: false }"
|
||||||
|
row-key="shopId"
|
||||||
|
:scroll="{ y: 360 }"
|
||||||
|
/>
|
||||||
|
</IncModal>
|
||||||
|
</template>
|
||||||
Reference in New Issue
Block a user