68 lines
2.3 KiB
TypeScript
68 lines
2.3 KiB
TypeScript
/**
|
|
* commands/msg/notice-create.ts — 新建通知公告
|
|
*
|
|
* API: POST /api/message/Notice
|
|
*/
|
|
import { Command } from 'commander'
|
|
import { JnpfClient } from '../../core/client.ts'
|
|
import { installAiHelpHook } from '../../core/help.ts'
|
|
import { log, printJson } from '../../core/log.ts'
|
|
|
|
interface CreateOpts {
|
|
fullName: string
|
|
enCode: string
|
|
body?: string
|
|
json?: boolean
|
|
}
|
|
|
|
export function buildMsgNoticeCreateCommand(): Command {
|
|
const cmd = new Command('notice-create')
|
|
.description('新建通知公告 (草稿, 未发布)')
|
|
.requiredOption('--fullName <name>', '通知标题')
|
|
.requiredOption('--enCode <code>', '通知编码')
|
|
.option('--body <text>', '通知正文 (可选)')
|
|
.option('--json', '原始 JSON 输出', false)
|
|
.action(async (opts: CreateOpts) => {
|
|
const c = await JnpfClient.fromToken()
|
|
const body = {
|
|
fullName: opts.fullName,
|
|
enCode: opts.enCode,
|
|
title: opts.fullName,
|
|
body: opts.body || '通知内容',
|
|
type: 1, // 1=系统公告 2=待办
|
|
enabledMark: 1,
|
|
sortCode: 0,
|
|
}
|
|
const r = await c.postJson<{ id?: string }>('/message/Notice', body)
|
|
if (r.code !== 200) {
|
|
log.error(`msg notice-create 失败 (code=${r.code}): ${r.msg}`)
|
|
process.exit(1)
|
|
}
|
|
let id = r.data?.id
|
|
if (!id) {
|
|
const listR = await c.get<{ list: { id: string; enCode: string; fullName: string }[] }>(
|
|
'/message/Notice',
|
|
{ keyword: opts.enCode, pageSize: '50' },
|
|
)
|
|
const found = (listR.data?.list || []).find(
|
|
(d) => d.enCode === opts.enCode || d.fullName === opts.fullName,
|
|
)
|
|
id = found?.id
|
|
}
|
|
log.info(`✓ 通知公告创建成功 id=${id}`)
|
|
if (opts.json) printJson({ ...(r.data as object), id })
|
|
})
|
|
installAiHelpHook(cmd, {
|
|
purpose: '新建通知公告 (草稿, 用 notice-release 发布)',
|
|
required: { '--fullName': '通知标题', '--enCode': '通知编码' },
|
|
optional: { '--body': '通知正文' },
|
|
example: 'dacli msg notice-create --fullName=系统升级 --enCode=sys_upgrade_2026 --body=今晚 10 点维护',
|
|
source: {
|
|
web: 'web/apps/jnpf-web-apps-main/src/views/msgCenter/notice/Form.vue',
|
|
api: 'POST /api/message/Notice',
|
|
ref: 'doc/v0.8-endpoints.md §2.4',
|
|
},
|
|
})
|
|
return cmd
|
|
}
|