feat: 工参每周一一份并提前缓存,登录后自动补缺;评估按周一取工参,指标等平台同步三天后再查
- 工参从 2024-01-01 起每周一一份,排队任务一次补一份,新的周先补;一个地市同时只取一份 - 大数据平台账号登录成功后排补取,排队进程每 10 分钟检查缺的周;排队进程重启时放开没取完的快照 - 拆除前工参用拆除日上一周的周一,拆除后用当周的周一;待拆小区不参与周边站和指标匹配 - 一周的指标等周日过后第 3 天才查,没到时间在结果说明里写明哪天之后有数据 - AI 工作区没就绪时开通接口返回 200,改为等待重试,最多 150 秒 - 排任务加锁,避免多个线程同时排时用到已关闭的连接池 - 运行面板显示各地市工参缓存进度
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { computed, onMounted, onUnmounted, ref } from "vue";
|
||||
import type { EChartsCoreOption } from "echarts/core";
|
||||
import Shell from "../../shell/Shell.vue";
|
||||
import { api } from "../../shared/http";
|
||||
@@ -44,9 +44,34 @@ function readPool(result: unknown): PoolDash | null {
|
||||
};
|
||||
}
|
||||
|
||||
interface GongcanCache {
|
||||
city: string;
|
||||
expected: number;
|
||||
ready: number;
|
||||
earliest: string | null;
|
||||
latest: string | null;
|
||||
loading: string | null;
|
||||
error: string;
|
||||
errorAt: string | null;
|
||||
}
|
||||
|
||||
function readGongcan(result: unknown): GongcanCache[] {
|
||||
const list = (result as { gongcan?: unknown } | null)?.gongcan;
|
||||
return Array.isArray(list) ? (list as GongcanCache[]) : [];
|
||||
}
|
||||
|
||||
function cacheState(item: GongcanCache) {
|
||||
if (item.loading) return `正在取 ${item.loading}`;
|
||||
if (item.ready >= item.expected) return "已是最新";
|
||||
if (item.error) return `上次没取成:${item.error}`;
|
||||
return `还缺 ${item.expected - item.ready} 周,有有效凭证时自动补`;
|
||||
}
|
||||
|
||||
const toast = useToast();
|
||||
const loaded = ref(false);
|
||||
const accountPool = ref<PoolDash>(emptyPool());
|
||||
const gongcan = ref<GongcanCache[]>([]);
|
||||
let timer = 0;
|
||||
const stats = computed(() => accountPool.value ?? emptyPool());
|
||||
|
||||
const cards = computed(() => [
|
||||
@@ -124,18 +149,27 @@ const statusOption = computed<EChartsCoreOption>(() => {
|
||||
};
|
||||
});
|
||||
|
||||
async function load() {
|
||||
async function load(quiet = false) {
|
||||
try {
|
||||
const next = readPool(await api<unknown>("/api/admin/dashboard"));
|
||||
const result = await api<unknown>("/api/admin/dashboard");
|
||||
const next = readPool(result);
|
||||
if (!next) throw new Error("运行面板没有获取到");
|
||||
accountPool.value = next;
|
||||
gongcan.value = readGongcan(result);
|
||||
loaded.value = true;
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : "运行面板没有获取到");
|
||||
if (!quiet) toast.error(error instanceof Error ? error.message : "运行面板没有获取到");
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
onMounted(() => {
|
||||
void load();
|
||||
// 工参补取一份要一两分钟,没补完时隔一会儿刷新进度。
|
||||
timer = window.setInterval(() => {
|
||||
if (gongcan.value.some((item) => item.ready < item.expected)) void load(true);
|
||||
}, 30000);
|
||||
});
|
||||
onUnmounted(() => window.clearInterval(timer));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -160,6 +194,24 @@ onMounted(load);
|
||||
<ChartPane :option="statusOption" />
|
||||
</section>
|
||||
</div>
|
||||
<section class="surface table-card dash-cache">
|
||||
<h3>工参缓存</h3>
|
||||
<p class="dash-note">每个地市每周一一份,从 2024-01-01 起。平台数据约三天同步好,周一的工参到周四才取。</p>
|
||||
<p v-if="!gongcan.length" class="admin-status">还没有缓存。有人用大数据平台账号登录后开始取。</p>
|
||||
<table v-else class="admin-table">
|
||||
<thead>
|
||||
<tr><th>地市</th><th>已缓存</th><th>范围</th><th>状态</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="item in gongcan" :key="item.city">
|
||||
<td>{{ item.city }}</td>
|
||||
<td class="num">{{ item.ready }} / {{ item.expected }} 周</td>
|
||||
<td class="num">{{ item.earliest ? `${item.earliest} 至 ${item.latest}` : "—" }}</td>
|
||||
<td :class="{ 'status-bad': !item.loading && item.ready < item.expected && item.error }">{{ cacheState(item) }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
</template>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -107,7 +107,7 @@ function taskClass(task: EvalTask) {
|
||||
function windowText(task: EvalTask) {
|
||||
if (!task.windows) return "";
|
||||
const before = `${task.windows.before[0]} 至 ${task.windows.before[1]}`;
|
||||
const after = task.windows.after ? `${task.windows.after[0]} 至 ${task.windows.after[1]}` : "拆除后再取";
|
||||
const after = task.windows.after ? `${task.windows.after[0]} 至 ${task.windows.after[1]}` : "数据还没出";
|
||||
return `停闭前 ${before};停闭后 ${after}`;
|
||||
}
|
||||
</script>
|
||||
@@ -169,10 +169,7 @@ function windowText(task: EvalTask) {
|
||||
<div><dt>拆除前工参</dt><dd>{{ task.beforeDate || "—" }}</dd></div>
|
||||
<div>
|
||||
<dt>拆除后工参</dt>
|
||||
<dd>
|
||||
{{ task.afterDate || (task.status === "done" ? "拆除日还没过" : "—") }}
|
||||
<n-tag v-if="task.afterPresent" size="tiny" :bordered="false" type="warning">小区仍在</n-tag>
|
||||
</dd>
|
||||
<dd>{{ task.afterDate || (task.status === "done" ? "暂无" : "—") }}</dd>
|
||||
</div>
|
||||
<div><dt>小区</dt><dd>{{ task.cells.length }} 个</dd></div>
|
||||
</dl>
|
||||
|
||||
@@ -190,6 +190,24 @@ button, input, select { font: inherit; }
|
||||
font-weight: 650;
|
||||
}
|
||||
.dash-chart { height: 260px; }
|
||||
.dash-cache { margin-top: 12px; }
|
||||
.dash-cache h3 {
|
||||
margin: 0;
|
||||
padding: 16px 16px 4px;
|
||||
font-size: 13px;
|
||||
font-weight: 650;
|
||||
}
|
||||
.dash-cache .dash-note,
|
||||
.dash-cache .admin-status {
|
||||
margin: 0;
|
||||
padding: 0 16px 14px;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
.dash-cache .num {
|
||||
font-variant-numeric: tabular-nums;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
.dash-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
||||
|
||||
Reference in New Issue
Block a user