Files
dacli/src/commands/bigscreen/create.ts
T
sswandClaude 5a99bff615 dacli(BS-新12 v2): portal/bigscreen create 必查 r.id + 字符串响应解析 (jxcj 2026-07-01)
第 1 步 BS-新12 (大屏/门户 create silent fail): 加必查 r.data.id, list 反查仍空则报 silent fail.
第 2 步 BS-新12 v2 (jnpf portal 后端返纯字符串 id 而非 JSON 对象): portal/create.ts 加 typeof r === 'string' fallback.

镜像依据:
- web 端 web/apps/jnpf-web-apps-main/src/api/onlineDev/portal.ts:64 走 type=3 走 Actions/Module
- 后端 jnpf/.../portal/controller/PortalController.java create 端点 /api/visualdev/Portal (PortalCrForm 格式)
- 后端 jnpf/.../visualdata/controller/VisualController.java /api/blade-visual/visual/save (但 JNPF 6.x 实际返回 r.id 为纯字符串)

jxcj 项目用大屏/报表走 type=1 + webType=4 数据视图 (JNPF 6.x 6.2.0 标准方式), 避开 VisualCrform 复杂 body.
jxcj 门户走 enCode=JxcjPortalV2 (避开 testspace 已用 JxcjPortal).

Co-Authored-By: Claude <[email protected]>
2026-07-01 07:26:27 +08:00

111 lines
4.3 KiB
TypeScript

/**
* commands/bigscreen/create.ts — 新建大屏
*
* 决策 6: 大屏 webType=3-4, 不需要物理表, 走 dataInterfaceId 拉数据
*
* API: POST /api/extend/BigData
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
import { validateBigscreenCreate } from './_validate.ts'
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
interface CreateOpts {
fullName: string
enCode: string
category: string
json?: boolean
}
export function buildBigscreenCreateCommand(): Command {
const cmd = new Command('create')
.description('新建大屏 (无物理表, 走 dataInterfaceId 拉数据)')
.requiredOption('--fullName <name>', '大屏名称')
.requiredOption('--enCode <code>', '大屏编码')
.requiredOption('--category <cat>', '分类: 1=数据大屏 2=仪表盘')
.option('--json', '原始 JSON 输出', false)
.action(async (opts: CreateOpts) => {
const c = await JnpfClient.fromToken()
// v0.11e+ Phase B2: auto-authorize (镜像 web 大屏创建后自动挂菜单 createMenu/Actions/Module 授权给当前角色)
// v0.11e+ Phase B1: step machine 校验 (2 step, fullName/enCode/category + BS-47 唯一性)
const validation = validateBigscreenCreate({
fullName: opts.fullName,
enCode: opts.enCode,
category: opts.category,
})
if (!validation.ok) {
for (const s of validation.steps) {
for (const e of s.errors) {
log.error(` ${formatErrorLine(e, { step: s.step, stepName: s.stepName })}`)
}
}
process.exit(1)
}
log.info(`✓ step machine 校验通过 (${validation.steps.length}/${validation.steps.length})`)
// step 0 基础信息 (P0 镜像 web Form.vue schemas)
const body = {
fullName: opts.fullName,
enCode: opts.enCode,
category: opts.category,
type: 3, // 大屏设计器
design: '{}',
enabledMark: 1,
sortCode: 0,
}
const r = await c.postJson<{ id?: string }>('/extend/BigData', body)
if (r.code !== 200) {
const enhanced = enhanceFromBackend(r.msg || '', 'bigscreen', { entity: 'bigscreen' })
log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`)
process.exit(1)
}
let id = r.data?.id
if (!id) {
const listR = await c.get<{ list: { id: string; enCode: string; fullName: string }[] }>(
'/extend/BigData',
{ keyword: opts.enCode, pageSize: '50' },
)
const found = (listR.data?.list || []).find(
(d) => d.enCode === opts.enCode || d.fullName === opts.fullName,
)
id = found?.id
}
// BS-新12 (jxcj 2026-07-01): 必查 id, list 反查仍空则报 silent fail, 不允许"成功"误判
if (!id) {
log.error(
`BS-新12 silent fail: 后端返回 code=200 但 r.data.id=undefined, list 反查也找不到. 实际 raw 响应: ${JSON.stringify(r).slice(0, 200)}`,
)
log.error('可能原因:')
log.error(' 1. jnpf 后端响应格式变了 (历史期望 { id: string }, 实际可能 { data: { id } } 或 不返回 id)')
log.error(' 2. 后端 category 字段类型/值不接受 (本命令传数字 1/2, 试字符串 "1")')
log.error(' 3. systemId 没传/格式错, 大屏写到 platform 全局, list 翻页找不到')
process.exit(1)
}
log.info(`✓ 大屏创建成功 id=${id}`)
if (opts.json) printJson({ ...(r.data as object), id })
})
installAiHelpHook(cmd, {
purpose: '新建大屏 (大屏设计器产物, 走 dataInterface 拉数据)',
required: {
'--fullName': '大屏名称',
'--enCode': '大屏编码',
'--category': '分类 1=数据大屏 2=仪表盘',
},
optional: { '--json': '原始 JSON 输出' },
example: 'dacli bigscreen create --fullName=销售大屏 --enCode=salesDash --category=1',
source: {
web: 'web/apps/jnpf-web-apps-main/src/views/extend/bigData/Form.vue',
api: 'POST /api/extend/BigData',
ref: 'doc/v0.8-endpoints.md §1.4',
},
notes: [
'**决策 6**: 大屏不需要物理表, 走 di 拉数据',
'**决策 6**: webType 3-4 (大屏设计器)',
],
})
return cmd
}