diff --git a/src/commands/report/create.ts b/src/commands/report/create.ts index 0e3d0d6..960fbac 100644 --- a/src/commands/report/create.ts +++ b/src/commands/report/create.ts @@ -1,23 +1,20 @@ /** - * commands/report/create.ts — 新建报表模板 + * commands/report/create.ts — 新建报表模板 (v0.13+ 镜像 web 端) * - * API: POST /api/Report body=ReportCrForm - * - { fullName, enCode, systemId, category, sortCode, description, cells, snapshot, ... } + * v3.0+ (2026-06-29 regression audit P0): 改用 webapi/report.createReport + * - 之前直接 c.postJson('/api/Report') — 经验复刻, 与 web 端 schema 漂移风险 + * - 现在 webapi 镜像: 复用 web 端 createReport (走 reportHttp, 端口 32000 报表服务) * - * 镜像源 (jnpf 6.x 6.2.0): - * - web/apps/jnpf-web-apps-main/src/api/onlineDev/report.ts:22 `createReport(data)` - * - web 端走 reportHttp (端口 32000, 报表独立微服务) - * - 后端 jnpf-java-datareport-univer/.../ReportController.java: POST @RequestMapping("/api/Report") - * - body 镜像 ReportCrForm (jnpf/.../ReportCrForm.java) - * - * v0.13+ (jxcj 2026-07-01 实战): dacli 之前 report 只镜像 ureport2 预定义模板路径 - * (/extend/ReportManage), 漏镜像 jnpf-datareport-univer 动态创建路径 - * (/api/Report). 本命令补齐. + * 镜像源: web/apps/jnpf-web-apps-main/src/api/onlineDev/report.ts:22 createReport + * web/.../views/onlineDev/report/Form.vue: handleSubmit: 'const query = { ...values, id }; createReport(query)' + * 后端: jnpf-java-datareport-univer/.../ReportController.java POST /api/Report + * 端口 32000 独立微服务 (nginx 代理 /api/Report/ → jnpf:32000) */ 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, createReport as webCreateReport } from '../../webapi/report.ts' interface CreateOpts { fullName: string @@ -32,25 +29,29 @@ interface CreateOpts { export function buildReportCreateCommand(): Command { const cmd = new Command('create') - .description('新建报表模板 (镜像 web report.ts createReport, 走 /api/Report 端口 32000)') - .requiredOption('--fullName ', '报表名称 (镜像 ReportCrForm.fullName)') - .requiredOption('--enCode ', '英文编码 (镜像 ReportCrForm.enCode, 同 BS-56 字符限制)') - .option('--category ', '分类 (镜像 ReportCrForm.category)', '报表示例') - .option('--description ', '说明 (镜像 ReportCrForm.description)') - .option('--sortCode ', '排序码 (镜像 ReportCrForm.sortCode, 0-999999)', '0') - .option('--cells ', '模板内容 cells (镜像 ReportCrForm.cells, JSON 字符串)', '{"cells":[]}') - .option('--snapshot ', '模板快照 (镜像 ReportCrForm.snapshot)', '') + .description('新建报表模板 (镜像 web report.ts:22 createReport, 走 /api/Report 端口 32000)') + .requiredOption('--fullName ', '报表名称 (镜像 web Form.vue field:fullName)') + .requiredOption('--enCode ', '英文编码 (镜像 web Form.vue field:enCode, BS-56 字符限制)') + .option('--category ', '分类 (镜像 web Form.vue field:category)', '报表示例') + .option('--description ', '说明 (镜像 web Form.vue field:description)') + .option('--sortCode ', '排序码 (镜像 web Form.vue field:sortCode, 0-999999)', '0') + .option('--cells ', '模板内容 cells (镜像 web Form.vue field:cells, JSON 字符串)', '{"cells":[]}') + .option('--snapshot ', '模板快照 (镜像 web Form.vue field:snapshot)') .option('--json', '原始 JSON 输出', false) .action(async (opts: CreateOpts) => { const c = await JnpfClient.fromToken() - // 镜像 web 端 report.ts:22 const query = { ...values, id: state.dataForm.id }; createReport(query) - // web 端 handleSubmit: query = { ...values, id: state.dataForm.id } - // values 来自 BasicForm validate, 包含 fullName/enCode/category/description/sortCode 等 - // 后端 ReportCrForm 字段: id, systemId, fullName, enCode, category, sortCode, description, cells, snapshot, ... - const systemId = c.appCode === 'jxcj' ? '841761908376733829' : '' // 从 token 取 - const reportCrForm: Record = { - systemId, + // v3.0+ (2026-06-29 regression audit P0): 走 webapi/report.initWebapi + // - 镜像 web 端 createReport (走 reportHttp, 端口 32000 报表服务) + // - 不直接 c.postJson('/api/Report') — 那是经验复刻, web 端 schema 变了会漂移 + await initReportWebapi(c) + + // 镜像 web 端 web/.../views/onlineDev/report/Form.vue handleSubmit: + // const query = { ...values, id: state.dataForm.id }; + // const formMethod = state.dataForm.id ? updateReport : createReport; + // formMethod(query); + const query = { + systemId: c.appCode === 'jxcj' ? '841761908376733829' : '', fullName: opts.fullName, enCode: opts.enCode, category: opts.category || '报表示例', @@ -61,18 +62,18 @@ export function buildReportCreateCommand(): Command { enabledMark: 1, } - // jnpf 后端端点: POST /api/Report (jnpf-java-datareport-univer 微服务, 端口 32000) - // 走主服务 30000 时端点 URL 不变 (nginx 代理 /api/Report 到 32000) - const r = await c.postJson<{ id?: string; code?: number; msg?: string }>( - '/api/Report', - reportCrForm, - ) + // 调用 web 端 createReport (走 reportHttp, 端口 32000) + const r = (await webCreateReport(query)) as { + id?: string + code?: number + msg?: string + } // BS-新12 v2 (jxcj 2026-07-01): jnpf 报表后端可能返纯字符串 id 或 { id, code, msg } - let id = r.id + let id = r?.id if (!id && typeof r === 'string' && /^\d+$/.test(r.trim())) id = r.trim() - if (r.code && r.code !== 200) { + if (r?.code && r.code !== 200) { log.error(`report create 失败 (code=${r.code}): ${r.msg}`) process.exit(1) } @@ -82,7 +83,7 @@ export function buildReportCreateCommand(): Command { ) process.exit(1) } - log.ok(`✓ 报表创建成功 id=${id} enCode=${opts.enCode} (镜像 web 端 report.ts createReport)`) + log.ok(`✓ 报表创建成功 id=${id} enCode=${opts.enCode} (镜像 web 端 report.ts:22 createReport)`) if (opts.json) printJson({ id, enCode: opts.enCode, ...(r as object) }) }) installAiHelpHook(cmd, { @@ -99,14 +100,14 @@ export function buildReportCreateCommand(): Command { 'dacli report create --fullName=Jxcj综合排名 --enCode=JxcjFinalRankingReport --category=大赛报表 --cells=\'{"cells":[]}\'', ], source: { - web: 'web/.../onlineDev/report.ts:22 createReport + report/Form.vue handleSubmit', - api: 'POST /api/Report | GET /api/Report | PUT /api/Report/{id} | DELETE /api/Report/{id}', + web: 'web/.../api/onlineDev/report.ts:22 createReport + report/Form.vue handleSubmit', + api: 'POST /api/Report (走 webapi/report Proxy, 端口 32000 报表服务)', ref: 'jnpf-java-datareport-univer/.../ReportController.java + ReportCrForm.java', }, notes: [ - 'v0.13+ 镜像 jnpf 6.x jnpf-datareport-univer 微服务 (端口 32000).', - 'jnpf 6.x 报表分两类: 预定义模板 (ureport2, /extend/ReportManage) + 动态创建 (/api/Report).', - '本命令镜像动态创建路径. 预定义模板只读, 走 `dacli report list` 元数据.', + 'v0.13+ 镜像 jnpf 6.x 报表动态创建路径 (jnpf-datareport-univer 微服务, 端口 32000).', + 'v3.0+ (2026-06-29 regression audit P0): 改用 webapi/report.createReport, 不直接 c.postJson.', + '启动 32000 报表服务: java -Dloader.path=boot/report/lib/ -jar boot/report/jnpf-datareport-univer-admin-*.jar (见 CLAUDE.md §常用命令).', ], }) return cmd diff --git a/src/webapi/_defhttp_shim.ts b/src/webapi/_defhttp_shim.ts index dccaf16..f950e9b 100644 --- a/src/webapi/_defhttp_shim.ts +++ b/src/webapi/_defhttp_shim.ts @@ -119,4 +119,34 @@ export const defHttp = { const r = await c.del(stripApiPrefix(config.url)) return unwrap(r) }, +} + +/** + * shim of web reportHttp (jxcj 2026-07-01 镜像 web 端 report.ts) + * + * 区别: web 端 reportHttp 走独立 reportApiURL (jnpf 报表服务端口 32000, jnpf-datareport-univer 微服务). + * dacli 没多 client 机制, 但 nginx 已经把 /api/Report/ 代理到 32000, 走主 30000 client 等价. + * 镜像目的: 跟 web 端 report.ts 同 schema (formData cells snapshot 等), 不与 web 端 schema 漂移. + */ +export const reportHttp = { + async get(config: { url: string; data?: Record }): Promise { + const c = getClient() + const r = await c.get(stripApiPrefix(config.url), cleanQuery(config.data)) + return unwrap(r) + }, + async post(config: { url: string; data?: unknown }): Promise { + const c = getClient() + const r = await c.postJson(stripApiPrefix(config.url), config.data ?? {}) + return unwrap(r) + }, + async put(config: { url: string; data?: unknown }): Promise { + const c = getClient() + const r = await c.putJson(stripApiPrefix(config.url), config.data ?? {}) + return unwrap(r) + }, + async delete(config: { url: string; data?: unknown }): Promise { + const c = getClient() + const r = await c.del(stripApiPrefix(config.url)) + return unwrap(r) + }, } \ No newline at end of file diff --git a/src/webapi/report.ts b/src/webapi/report.ts index e3984c4..8bd10af 100644 --- a/src/webapi/report.ts +++ b/src/webapi/report.ts @@ -46,3 +46,28 @@ export const loadReport: any = new Proxy({} as any, { return cached[prop] }, }) + +/** 获取报表列表 (镜像 web report.ts: getReportList) */ +export async function getReportList(params?: Record): Promise { + return loadReport.getReportList(params) +} + +/** 获取报表信息 (镜像 web report.ts: getReportInfo) */ +export async function getReportInfo(id: string): Promise { + return loadReport.getReportInfo(id) +} + +/** 创建报表 (镜像 web report.ts:22 createReport) */ +export async function createReport(params: Record): Promise { + return loadReport.createReport(params) +} + +/** 更新报表 (镜像 web report.ts:23 updateReport) */ +export async function updateReport(params: Record & { id: string }): Promise { + return loadReport.updateReport(params) +} + +/** 删除报表 (镜像 web report.ts: delReport) */ +export async function delReport(id: string): Promise { + return loadReport.delReport(id) +}