|
|
@@ -8,16 +8,7 @@ const { makeChatCfg } = require('../context.js');
|
|
|
const naposService = require('../../napos-service.js');
|
|
|
const nlQuery = require('../../nl-query.js');
|
|
|
const reportHtml = require('../../report-html.js');
|
|
|
-
|
|
|
-/** 三表推送结果的一行摘要(日志用):合计 + 分表明细 */
|
|
|
-function aitablePushSummary(r) {
|
|
|
- const base = `新增 ${r.created} 行、更新 ${r.updated} 行`;
|
|
|
- const parts = Object.entries(r.perSheet || {})
|
|
|
- .filter(([, s]) => s.rows > 0)
|
|
|
- .map(([scope, s]) => `${s.sheet} 新增${s.created}/更新${s.updated}`)
|
|
|
- .join(',');
|
|
|
- return parts ? `${base}(${parts})` : base;
|
|
|
-}
|
|
|
+const { pushSummary } = require('../services/aitable.js');
|
|
|
|
|
|
function register(app, ctx) {
|
|
|
// 不限方法(保持拆分前行为:该路由未做方法检查)
|
|
|
@@ -129,18 +120,24 @@ function register(app, ctx) {
|
|
|
chainId: body.chainId || '',
|
|
|
shopIds: Array.isArray(body.shopIds) ? body.shopIds : undefined,
|
|
|
}).catch((e) => {
|
|
|
- // 同步失败也要让自动推送保持静默,但保留日志
|
|
|
- ctx.logs.pushSystemLog(`同步结束(失败):${e.message || e}`, 'warn');
|
|
|
+ ctx.logs.pushSystemLog(`同步失败:${e.message || e}`, 'error');
|
|
|
return null;
|
|
|
});
|
|
|
- // 同步完成后:若启用钉钉 AI 表格,自动把增量推上云端(失败不影响本地同步结果)
|
|
|
+ // 同步完成后:若启用钉钉 AI 表格,自动把增量推送云端(失败不影响本地同步结果)
|
|
|
entityPromise.then(async (snap) => {
|
|
|
- if (!snap || !snap.entity || !(ctx.config.aitable && ctx.config.aitable.enabled)) return;
|
|
|
+ if (!snap) return; // 失败已在 catch 记日志
|
|
|
+ if (snap.entity) {
|
|
|
+ ctx.logs.pushSystemLog(
|
|
|
+ `同步完成:${snap.entity.name},新增 ${snap.added} 行、更新 ${snap.updated} 行、失败 ${snap.failed} 项`,
|
|
|
+ snap.failed > 0 ? 'warn' : 'success'
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (!snap.entity || !(ctx.config.aitable && ctx.config.aitable.enabled)) return;
|
|
|
try {
|
|
|
const r = await ctx.aitable.pushLake(snap.entity.key);
|
|
|
- ctx.logs.pushSystemLog(`AI 表格推送完成:${aitablePushSummary(r)}`, 'success');
|
|
|
+ ctx.logs.pushSystemLog(`推送云端完成:${r.account ? r.account + ',' : ''}${pushSummary(r)}`, 'success');
|
|
|
} catch (e) {
|
|
|
- ctx.logs.pushSystemLog(`AI 表格推送失败:${e.message || e}`, 'error');
|
|
|
+ ctx.logs.pushSystemLog(`推送云端失败:${e.message || e}`, 'error');
|
|
|
}
|
|
|
});
|
|
|
return sendJson(res, 200, { ok: true, ...naposService.syncSnapshot() });
|
|
|
@@ -158,7 +155,7 @@ function register(app, ctx) {
|
|
|
const entity = body.entity || (naposService.store.listEntities()[0] || {}).key;
|
|
|
if (!entity) { const e = new Error('暂无数据主体,请先完成一次同步'); e.code = 'AITABLE_NO_ENTITY'; e.status = 400; throw e; }
|
|
|
const r = await ctx.aitable.pushLake(entity, { force: !!body.force });
|
|
|
- ctx.logs.pushSystemLog(`AI 表格推送完成:${aitablePushSummary(r)}`, 'success');
|
|
|
+ ctx.logs.pushSystemLog(`推送云端完成:${r.account ? r.account + ',' : ''}${pushSummary(r)}`, 'success');
|
|
|
sendJson(res, 200, r);
|
|
|
});
|
|
|
|
|
|
@@ -166,7 +163,7 @@ function register(app, ctx) {
|
|
|
const body = await readBody(req);
|
|
|
const r = await ctx.aitable.pullLake(body.entity);
|
|
|
const accounts = (r.accounts || []).map((a) => `${a.account}(新增${a.added}/更新${a.updated})`).join('、');
|
|
|
- ctx.logs.pushSystemLog(`AI 表格拉取完成:${r.pulled} 行 ${accounts}`, 'success');
|
|
|
+ ctx.logs.pushSystemLog(`云端拉取完成:${r.pulled} 行${accounts ? `(${accounts})` : ''}`, 'success');
|
|
|
sendJson(res, 200, r);
|
|
|
});
|
|
|
|
|
|
@@ -249,7 +246,7 @@ function register(app, ctx) {
|
|
|
app.del('/api/reports/data', async ({ res, query }) => {
|
|
|
if (!query.entity) return sendJson(res, 400, { error: '缺少 entity 参数' });
|
|
|
naposService.store.deleteEntityData(query.entity);
|
|
|
- ctx.logs.pushSystemLog(`数据报表:已清除主体 ${query.entity} 的本地数据`, 'warn');
|
|
|
+ ctx.logs.pushSystemLog(`本地数据已清除:主体 ${query.entity}`, 'warn');
|
|
|
sendJson(res, 200, { ok: true });
|
|
|
});
|
|
|
}
|