From 2ef716bf30fe7f06c3387c551f10dd33a970a1ec Mon Sep 17 00:00:00 2001 From: ssw Date: Thu, 2 Jul 2026 08:13:11 +0800 Subject: [PATCH] =?UTF-8?q?BS-=E6=96=B0115/116=20=E5=9B=BA=E5=8C=96:=20?= =?UTF-8?q?=E8=A1=A8=E5=90=8D=E5=86=B2=E7=AA=81=20precheck=20+=20report=20?= =?UTF-8?q?release=20=E5=AD=90=E5=91=BD=E4=BB=A4=20(jyzs=202026-07-02=20te?= =?UTF-8?q?stspace=20=E9=AA=8C=E8=AF=81=204=20PASS)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/_precheck.ts | 11 +++ src/commands/report/index.ts | 3 + src/commands/report/release.ts | 147 +++++++++++++++++++++++++++++++++ src/webapi/report.ts | 12 +++ 4 files changed, 173 insertions(+) create mode 100644 src/commands/report/release.ts diff --git a/src/commands/_precheck.ts b/src/commands/_precheck.ts index 537ea08..a489e59 100644 --- a/src/commands/_precheck.ts +++ b/src/commands/_precheck.ts @@ -90,6 +90,17 @@ export async function preCheckFormCreate( errors.push(' b) dacli form delete 后重建(破坏性)') } + // 检查 2.5: 表名不重复 (BS-新115, jyzs 2026-07-02) + // jyzs 实战: AI 自动建表 + release 又建表 → VS032 "database table name should remain unique" + // 修复: form create 前检测 existingTables, 已存在 → 警告+建议复用 (走 --autoTable 引用现有) + if (opts.table && ctx.existingTables.includes(opts.table)) { + errors.push(`表名 "${opts.table}" 已存在(当前业务库已有 ${ctx.existingTables.length} 张表)`) + errors.push(' 修复方案(BS-新115, jyzs 2026-07-02 实战):') + errors.push(' a) 换表名(推荐加业务前缀,如 jyzs_<原名>)') + errors.push(' b) 复用现有表: --autoTable=false + --tables=...[{"table":"' + opts.table + '",...}]') + errors.push(' c) dacli dm drop ' + opts.table + ' 后重建(破坏性)') + } + // 检查 3: type/webType 合法组合(用 form-type-rules.json,由 P1.3 提供) // 如果 form-type-rules.json 不存在,跳过此检查 try { diff --git a/src/commands/report/index.ts b/src/commands/report/index.ts index 8229ce1..b29ae73 100644 --- a/src/commands/report/index.ts +++ b/src/commands/report/index.ts @@ -19,6 +19,7 @@ * info 详情 * create 新建 * update 修改 (v0.14+ 新增) + * release 发布/保存设计 (v0.14+ BS-新116, jyzs 2026-07-02 补) * templates 选择器 (web 等价语义: 菜单/下拉/树形展示, 替代旧版样本数据端点) */ import { Command } from 'commander' @@ -27,6 +28,7 @@ import { buildReportInfoCommand } from './info.ts' import { buildReportTemplatesCommand } from './templates.ts' import { buildReportCreateCommand } from './create.ts' import { buildReportUpdateCommand } from './update.ts' +import { buildReportReleaseCommand } from './release.ts' export function buildReportCommand(): Command { const cmd = new Command('report').description('报表 (jnpf 6.x univer 报表微服务端口 32000, 全部走 webapi 镜像)') @@ -35,5 +37,6 @@ export function buildReportCommand(): Command { cmd.addCommand(buildReportTemplatesCommand()) cmd.addCommand(buildReportCreateCommand()) cmd.addCommand(buildReportUpdateCommand()) + cmd.addCommand(buildReportReleaseCommand()) return cmd } diff --git a/src/commands/report/release.ts b/src/commands/report/release.ts new file mode 100644 index 0000000..77a7f55 --- /dev/null +++ b/src/commands/report/release.ts @@ -0,0 +1,147 @@ +/** + * commands/report/release.ts — 发布/保存报表设计 (BS-新116, jyzs 2026-07-02) + * + * v0.14+ (2026-07-02): 新增 BS-新116 修复, jyzs 实战发现 + * - 之前 `dacli report --help` 只有 list/info/templates/create/update, 没 release + * - jnpf 后端报表发布走 `POST /api/Report/Save` (web 端叫 saveVersion), + * 需要 type=0 (保存设计) 或 type=1 (发布+部署), 加完整 columnList + dataSetList + * - 不是无参 release, 是设计 + 发布两步合一 + * + * 镜像源: web/apps/jnpf-web-apps-main/src/api/onlineDev/report.ts:49 saveVersion + * - web 端: reportHttp.post({ url: `${Api.Prefix}/Save`, data }) + * - 端点: POST /api/Report/Save (走 32000 报表微服务 jnpf-datareport-univer) + * - 后端: ReportController.java @PostMapping("/Save") + ReportUpForm (同 update) + * + * 用法: + * dacli report release --id= --type=1 --cells='' --dataSets='' + * dacli report release --id= --type=0 --cells='' # 仅保存设计不发布 + */ +import { Command } from 'commander' +import { JnpfClient } from '../../core/client.ts' +import { installAiHelpHook } from '../../core/help.ts' +import { log, printJson } from '../../core/log.ts' +import { initWebapi as initReportWebapi, loadReport } from '../../webapi/report.ts' + +interface ReleaseOpts { + id: string + type?: string + cells?: string + dataSets?: string + columnList?: string + queryList?: string + versionId?: string + json?: boolean +} + +interface ReportForm { + id?: string + fullName?: string + enCode?: string + category?: string + description?: string + versionId?: string | null + cells?: string | null + snapshot?: string | null + queryList?: string | null + columnList?: string | null + dataSetList?: string | null + enabledMark?: number +} + +export function buildReportReleaseCommand(): Command { + const cmd = new Command('release') + .description( + '发布/保存报表设计 (BS-新116 jyzs 2026-07-02, 镜像 web report.ts:49 saveVersion, 走 POST /api/Report/Save)', + ) + .requiredOption('--id ', '报表 id') + .option('--type <0|1>', '类型: 0=保存设计 1=发布+部署 (默认 1)', '1') + .option('--cells ', '设计 cells JSON 字符串 (type=1 必传)') + .option('--dataSets ', '数据集列表 JSON 数组字符串') + .option('--columnList ', '列定义 JSON 数组字符串') + .option('--queryList ', '查询参数 JSON 数组字符串') + .option('--versionId ', '版本 id (留空则创建新版本)') + .option('--json', '原始 JSON 输出', false) + .action(async (opts: ReleaseOpts) => { + const c = await JnpfClient.fromToken() + await initReportWebapi(c) + + // === step 1: 拉报表现状 === + const current = (await loadReport.getReportInfo(opts.id)) as ReportForm + if (!current || !current.id) { + log.error(`report id=${opts.id} 不存在, 无法 release`) + process.exit(1) + } + + // === step 2: 校验 type=1 必传 cells === + const releaseType = Number(opts.type || 1) + if (releaseType === 1 && !opts.cells) { + log.error('--type=1 (发布) 必传 --cells (设计内容不能为空)') + log.error('提示: --type=0 (仅保存设计) 不强制 cells, 但仍建议提供') + process.exit(1) + } + + // === step 3: 构造 saveVersion body (镜像 web 端 Form.vue handleSubmit) === + // 后端 ReportUpForm 要求几乎所有字段都在, 跟 update 一样先 getReportInfo 拿全字段, + // 然后 spread 覆盖用户传入字段. 这里与 update 区别是: release 同时支持 type=0/1. + const body: Record = { + ...current, + id: opts.id, + type: releaseType, + versionId: opts.versionId || current.versionId || null, + } + if (opts.cells !== undefined) body.cells = opts.cells + if (opts.dataSets !== undefined) body.dataSetList = opts.dataSets + if (opts.columnList !== undefined) body.columnList = opts.columnList + if (opts.queryList !== undefined) body.queryList = opts.queryList + + // === step 4: 调 webapi saveReport (Proxy 走 loadReport.saveVersion) === + // web 端 saveVersion 走 reportHttp.post({url: '/api/Report/Save', data}), + // 后端返 {code:200, msg:'保存成功', data:null} → shim unwrap 后 data=null. + const r = (await loadReport.saveVersion(body)) as unknown + let code: number | undefined + let msg: string | undefined + if (r && typeof r === 'object') { + const obj = r as { code?: number; msg?: string } + code = obj.code + msg = obj.msg + } + if (code !== undefined && code !== 200) { + log.error(`report release 失败 (code=${code}): ${msg}`) + process.exit(1) + } + log.ok( + `✓ 报表 ${releaseType === 1 ? '发布' : '保存'}成功 id=${opts.id} ` + + `(BS-新116, type=${releaseType}, msg="${msg || '保存成功'}")`, + ) + if (opts.json) printJson({ id: opts.id, type: releaseType, code, msg, raw: r }) + }) + installAiHelpHook(cmd, { + purpose: + '发布/保存报表设计 (BS-新116, jyzs 2026-07-02 实战补 release 子命令, 走 webapi/report.saveVersion 镜像 web 端 saveVersion)', + required: { '--id': '报表 id' }, + optional: { + '--type': '0=保存设计 1=发布+部署 (默认 1)', + '--cells': '设计 cells JSON (type=1 必传)', + '--dataSets': '数据集列表 JSON 数组 (type=1 强烈建议)', + '--columnList': '列定义 JSON 数组', + '--queryList': '查询参数 JSON 数组', + '--versionId': '版本 id (留空创建新版本)', + }, + example: [ + 'dacli report release --id=842032225770801349 --type=1 --cells="" --dataSets=""', + 'dacli report release --id=842032225770801349 --type=0 --cells="" # 仅保存', + ], + source: { + web: 'web/apps/jnpf-web-apps-main/src/api/onlineDev/report.ts:49 saveVersion', + api: 'POST /api/Report/Save (走 webapi/report.saveVersion 镜像, 端口 32000 报表服务)', + ref: 'jnpf-java-datareport-univer/.../ReportController.java @PostMapping("/Save") + ReportUpForm.java', + }, + notes: [ + '**BS-新116 修复** (jyzs 2026-07-02): 之前无 release 子命令, jyzs 3 张报表 enabledMark=0 卡模板态, 现补', + '**web 镜像**: 走 web 端 saveVersion (reportHttp.post → /api/Report/Save)', + '**type 区别**: type=0 仅保存设计 (不部署), type=1 发布+部署 (需完整 cells + dataSets)', + '**BACKEND-7 已知**: nginx /api/Report 重定向 /api/Report/ → 404, 当前 list/create 受影响, release 走 POST /Save 通常 200', + ], + }) + return cmd +} \ No newline at end of file diff --git a/src/webapi/report.ts b/src/webapi/report.ts index 8bd10af..69edde2 100644 --- a/src/webapi/report.ts +++ b/src/webapi/report.ts @@ -71,3 +71,15 @@ export async function updateReport(params: Record & { id: strin export async function delReport(id: string): Promise { return loadReport.delReport(id) } + +/** + * 保存报表设计 (镜像 web report.ts:49 saveVersion) + * 端点: POST /api/Report/Save + * body: { id, versionId, type, cells, snapshot, columnList, dataSetList ... } + * - type=0 = 保存设计 (不发布, versionId 留空或当前 version) + * - type=1 = 发布 (走 saveOrRelease, 真正上线, 需要完整 columnList + dataSetList) + * BS-新116 (jyzs 2026-07-02): 之前 dacli report 无 release 子命令, 现补 + */ +export async function saveReport(data: Record): Promise { + return loadReport.saveVersion(data) +}