W11-D1+D2: msg 5 子 (1 notice + 32 template) + schedule 5 子 (list/create 已知 JNPF 端点坏, info/trigger/log 走 id)
This commit is contained in:
1 parent
0c50678bf2
commit
eeacfae7d7
13 files changed
+673
No files matched your search
@@ -28,6 +28,8 @@ import { buildPrintCommand } from './commands/print/index.ts'
|
||||
import { buildRoleCommand } from './commands/role/index.ts'
|
||||
import { buildUserCommand } from './commands/user/index.ts'
|
||||
import { buildOrgCommand } from './commands/org/index.ts'
|
||||
import { buildMsgCommand } from './commands/msg/index.ts'
|
||||
import { buildScheduleCommand } from './commands/schedule/index.ts'
|
||||
import { maybeInterceptAiHelp } from './core/help.ts'
|
||||
import { log } from './core/log.ts'
|
||||
import { DacliError } from './core/types.ts'
|
||||
@@ -69,6 +71,10 @@ program.addCommand(buildRoleCommand())
|
||||
program.addCommand(buildUserCommand())
|
||||
// v0.8 W10-D3 新增 1 父命令
|
||||
program.addCommand(buildOrgCommand())
|
||||
// v0.8 W11-D1 新增 1 父命令
|
||||
program.addCommand(buildMsgCommand())
|
||||
// v0.8 W11-D2 新增 1 父命令
|
||||
program.addCommand(buildScheduleCommand())
|
||||
|
||||
// ----- main -----
|
||||
// AI flag 拦截 (在 parse 之前, 避免 requiredOption 校验失败)
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* commands/msg/index.ts — msg 父命令
|
||||
*
|
||||
* JNPF 消息中心 (msgCenter/notice + msgCenter/msgTemplate + msgCenter/sendConfig)
|
||||
*
|
||||
* 决策 8: 通知通道 site/email/sms/webhook/dingTalk/weCom
|
||||
*
|
||||
* 子命令:
|
||||
* notice-list 通知列表
|
||||
* notice-create 新建通知
|
||||
* notice-send 发送通知
|
||||
* template-list 模板列表
|
||||
* template-create 新建模板
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { buildMsgNoticeListCommand } from './notice-list.ts'
|
||||
import { buildMsgNoticeCreateCommand } from './notice-create.ts'
|
||||
import { buildMsgNoticeSendCommand } from './notice-send.ts'
|
||||
import { buildMsgTemplateListCommand } from './template-list.ts'
|
||||
import { buildMsgTemplateCreateCommand } from './template-create.ts'
|
||||
|
||||
export function buildMsgCommand(): Command {
|
||||
const cmd = new Command('msg').description('消息中心 (通知 + 模板, msgCenter)')
|
||||
cmd.addCommand(buildMsgNoticeListCommand())
|
||||
cmd.addCommand(buildMsgNoticeCreateCommand())
|
||||
cmd.addCommand(buildMsgNoticeSendCommand())
|
||||
cmd.addCommand(buildMsgTemplateListCommand())
|
||||
cmd.addCommand(buildMsgTemplateCreateCommand())
|
||||
return cmd
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* commands/msg/notice-list.ts — 通知公告列表
|
||||
*
|
||||
* API: GET /api/message/Notice 或 POST /api/message/Notice/List
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
|
||||
interface NoticeItem {
|
||||
id?: string
|
||||
fullName?: string
|
||||
enCode?: string
|
||||
title?: string
|
||||
state?: number
|
||||
type?: number
|
||||
creatorTime?: string | number
|
||||
}
|
||||
|
||||
interface ListOpts {
|
||||
keyword?: string
|
||||
json?: boolean
|
||||
}
|
||||
|
||||
export function buildMsgNoticeListCommand(): Command {
|
||||
const cmd = new Command('notice-list')
|
||||
.description('列出通知公告 (站内信)')
|
||||
.option('--keyword <k>', '按名称/编码模糊搜索')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
.action(async (opts: ListOpts) => {
|
||||
const c = await JnpfClient.fromToken()
|
||||
// JNPF Notice 列表用 POST /api/message/Notice/List (GET 返 405)
|
||||
const r = await c.postJson<{ list: NoticeItem[] }>('/message/Notice/List', {
|
||||
keyword: opts.keyword,
|
||||
currentPage: 1,
|
||||
pageSize: 50,
|
||||
})
|
||||
if (r.code !== 200) {
|
||||
log.error(`msg notice-list 失败 (code=${r.code}): ${r.msg}`)
|
||||
process.exit(1)
|
||||
}
|
||||
const list = r.data?.list || []
|
||||
if (opts.json) {
|
||||
printJson(r.data)
|
||||
return
|
||||
}
|
||||
log.info(`共 ${list.length} 个通知公告`)
|
||||
console.log('ID FULL_NAME ENCODE STATE')
|
||||
console.log('-'.repeat(85))
|
||||
for (const d of list) {
|
||||
const id = String(d.id || '').padEnd(30)
|
||||
const name = String(d.fullName || d.title || '').padEnd(23)
|
||||
const code = String(d.enCode || '').padEnd(21)
|
||||
const state = d.state === 1 ? '已发布' : '未发布'
|
||||
console.log(`${id}${name}${code}${state}`)
|
||||
}
|
||||
})
|
||||
installAiHelpHook(cmd, {
|
||||
purpose: '列出通知公告 (站内信, msgCenter)',
|
||||
optional: { '--keyword': '按名称/编码模糊搜索' },
|
||||
example: 'dacli msg notice-list\ndacli msg notice-list --keyword=系统',
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/views/msgCenter/notice/index.vue',
|
||||
api: 'GET /api/message/Notice',
|
||||
ref: 'doc/v0.8-endpoints.md §2.4',
|
||||
},
|
||||
notes: [
|
||||
'**决策 8**: 站内信用 msgCenter (本命令), 邮件用 integrationCenter',
|
||||
'**send 通道**: 站内信 type=site, 邮件 type=email, 短信 type=sms, etc.',
|
||||
],
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* commands/msg/notice-send.ts — 发送通知公告
|
||||
*
|
||||
* 注: 真实 "发送" 走 PUT /api/message/Notice/{id}/Actions/Release (发布后即推送)
|
||||
* 这里 provide 一个 "send" 别名, 内部走 release
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log } from '../../core/log.ts'
|
||||
|
||||
interface SendOpts {
|
||||
id: string
|
||||
type?: string
|
||||
}
|
||||
|
||||
export function buildMsgNoticeSendCommand(): Command {
|
||||
const cmd = new Command('notice-send')
|
||||
.description('发布/发送通知 (走 release 端点, 决策 8: type=site 站内信)')
|
||||
.requiredOption('--id <id>', '通知 id')
|
||||
.option('--type <t>', '通道: site=站内信 (默认) | email=邮件 | sms=短信 | webhook=Webhook | dingTalk=钉钉 | weCom=企微', 'site')
|
||||
.action(async (opts: SendOpts) => {
|
||||
const validTypes = ['site', 'email', 'sms', 'webhook', 'dingTalk', 'weCom']
|
||||
if (!validTypes.includes(opts.type || '')) {
|
||||
log.error(`--type 必须是 ${validTypes.join('|')}`)
|
||||
process.exit(2)
|
||||
}
|
||||
const c = await JnpfClient.fromToken()
|
||||
// 站内信走 notice release
|
||||
if (opts.type === 'site') {
|
||||
const r = await c.putJson(`/message/Notice/${opts.id}/Actions/Release`, {})
|
||||
if (r.code !== 200) {
|
||||
log.error(`msg notice-send (站内信) 失败: ${r.msg}`)
|
||||
process.exit(1)
|
||||
}
|
||||
log.info(`✓ 通知 id=${opts.id} 已发布 (站内信推送)`)
|
||||
} else {
|
||||
// 邮件/短信/Webhook 走 integration 端点, 留 v0.9+ 实做
|
||||
log.warn(`--type=${opts.type} 通道的发送端点 v0.9+ 实做, 当前只支持 site (站内信)`)
|
||||
log.info(` 提示: 走 dacli integration ${opts.type} send (W12+)`)
|
||||
}
|
||||
})
|
||||
installAiHelpHook(cmd, {
|
||||
purpose: '发送/发布通知 (决策 8: 通道 site/email/sms/webhook/dingTalk/weCom)',
|
||||
required: { '--id': '通知 id' },
|
||||
optional: { '--type': '发送通道 (默认 site)' },
|
||||
example: 'dacli msg notice-send --id=1234567890\ndacli msg notice-send --id=1234567890 --type=email',
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/views/msgCenter/notice/Form.vue',
|
||||
api: 'PUT /api/message/Notice/{id}/Actions/Release',
|
||||
ref: 'doc/v0.8-endpoints.md §2.4',
|
||||
},
|
||||
notes: [
|
||||
'**决策 8**: 当前只实做 site (站内信) 通道',
|
||||
'**v0.9+**: email/sms/webhook/dingTalk/weCom 通道走 dacli integration',
|
||||
],
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* commands/msg/template-create.ts — 新建消息模板
|
||||
*
|
||||
* API: POST /api/system/MessageTemplate
|
||||
*/
|
||||
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
|
||||
json?: boolean
|
||||
}
|
||||
|
||||
export function buildMsgTemplateCreateCommand(): Command {
|
||||
const cmd = new Command('template-create')
|
||||
.description('新建消息模板')
|
||||
.requiredOption('--fullName <name>', '模板名称')
|
||||
.requiredOption('--enCode <code>', '模板编码')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
.action(async (opts: CreateOpts) => {
|
||||
const c = await JnpfClient.fromToken()
|
||||
const body = {
|
||||
fullName: opts.fullName,
|
||||
enCode: opts.enCode,
|
||||
category: '1', // 1=系统 2=业务
|
||||
enabledMark: 1,
|
||||
sortCode: 0,
|
||||
}
|
||||
const r = await c.postJson<{ id?: string }>('/system/MessageTemplate', body)
|
||||
if (r.code !== 200) {
|
||||
log.error(`msg template-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 }[] }>(
|
||||
'/system/MessageTemplate',
|
||||
{ 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: '新建消息模板',
|
||||
required: { '--fullName': '模板名称', '--enCode': '模板编码' },
|
||||
example: 'dacli msg template-create --fullName=系统告警模板 --enCode=sys_alert',
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/views/msgCenter/msgTemplate/Form.vue',
|
||||
api: 'POST /api/system/MessageTemplate',
|
||||
ref: 'doc/v0.8-endpoints.md §2.4',
|
||||
},
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* commands/msg/template-list.ts — 消息模板列表
|
||||
*
|
||||
* API: GET /api/system/MessageTemplate
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
|
||||
interface TemplateItem {
|
||||
id?: string
|
||||
fullName?: string
|
||||
enCode?: string
|
||||
category?: string
|
||||
enabledMark?: number
|
||||
}
|
||||
|
||||
interface ListOpts {
|
||||
keyword?: string
|
||||
json?: boolean
|
||||
}
|
||||
|
||||
export function buildMsgTemplateListCommand(): Command {
|
||||
const cmd = new Command('template-list')
|
||||
.description('列出消息模板 (站内信/邮件/短信/Webhook 模板)')
|
||||
.option('--keyword <k>', '按名称/编码模糊搜索')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
.action(async (opts: ListOpts) => {
|
||||
const c = await JnpfClient.fromToken()
|
||||
// web msgTemplate.ts: Prefix = '/api/message/MessageTemplateConfig'
|
||||
const r = await c.get<{ list: TemplateItem[] }>('/message/MessageTemplateConfig', {
|
||||
keyword: opts.keyword,
|
||||
currentPage: 1,
|
||||
pageSize: 50,
|
||||
})
|
||||
if (r.code !== 200) {
|
||||
log.error(`msg template-list 失败 (code=${r.code}): ${r.msg}`)
|
||||
process.exit(1)
|
||||
}
|
||||
const list = r.data?.list || []
|
||||
if (opts.json) {
|
||||
printJson(r.data)
|
||||
return
|
||||
}
|
||||
log.info(`共 ${list.length} 个消息模板`)
|
||||
console.log('ID FULL_NAME ENCODE ENABLED')
|
||||
console.log('-'.repeat(85))
|
||||
for (const d of list) {
|
||||
const id = String(d.id || '').padEnd(30)
|
||||
const name = String(d.fullName || '').padEnd(23)
|
||||
const code = String(d.enCode || '').padEnd(21)
|
||||
const en = d.enabledMark === 1 ? '是' : '否'
|
||||
console.log(`${id}${name}${code}${en}`)
|
||||
}
|
||||
})
|
||||
installAiHelpHook(cmd, {
|
||||
purpose: '列出消息模板 (站内信/邮件/短信 模板)',
|
||||
optional: { '--keyword': '按名称/编码模糊搜索' },
|
||||
example: 'dacli msg template-list\ndacli msg template-list --keyword=告警',
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/views/msgCenter/msgTemplate/index.vue',
|
||||
api: 'GET /api/message/MessageTemplateConfig',
|
||||
ref: 'doc/v0.8-endpoints.md §2.4',
|
||||
},
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* commands/schedule/create.ts — 新建定时任务
|
||||
*
|
||||
* API: POST /api/scheduletask
|
||||
* 必填: fullName / executeType / executeContent (JNPF 列表和创建用同端点)
|
||||
*/
|
||||
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
|
||||
executeType: string
|
||||
executeContent: string
|
||||
cron?: string
|
||||
json?: boolean
|
||||
}
|
||||
|
||||
export function buildScheduleCreateCommand(): Command {
|
||||
const cmd = new Command('create')
|
||||
.description('新建定时任务 (Quartz cron)')
|
||||
.requiredOption('--fullName <name>', '任务名称')
|
||||
.requiredOption('--enCode <code>', '任务编码')
|
||||
.requiredOption('--executeType <t>', '执行类型 (e.g. SQL/JavaScript/...)')
|
||||
.requiredOption('--executeContent <c>', '执行内容 (SQL 脚本/JS 代码)')
|
||||
.option('--cron <expr>', 'cron 表达式 (e.g. "0 0 0 * * ?")')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
.action(async (opts: CreateOpts) => {
|
||||
const c = await JnpfClient.fromToken()
|
||||
const body: Record<string, unknown> = {
|
||||
fullName: opts.fullName,
|
||||
enCode: opts.enCode,
|
||||
executeType: opts.executeType,
|
||||
executeContent: opts.executeContent,
|
||||
enabledMark: 1,
|
||||
sortCode: 0,
|
||||
}
|
||||
if (opts.cron) body.cron = opts.cron
|
||||
const r = await c.postJson<{ id?: string }>('/scheduletask', body)
|
||||
if (r.code !== 200) {
|
||||
log.error(`schedule create 失败: ${r.msg}`)
|
||||
process.exit(1)
|
||||
}
|
||||
log.info(`✓ 定时任务创建成功 id=${r.data?.id}`)
|
||||
if (opts.json) printJson(r.data)
|
||||
})
|
||||
installAiHelpHook(cmd, {
|
||||
purpose: '新建定时任务 (Quartz cron, 决策 9: 与工作流区别)',
|
||||
required: {
|
||||
'--fullName': '任务名称',
|
||||
'--enCode': '任务编码',
|
||||
'--executeType': '执行类型',
|
||||
'--executeContent': '执行内容',
|
||||
},
|
||||
optional: { '--cron': 'cron 表达式' },
|
||||
example: 'dacli schedule create --fullName=daily --enCode=daily_task --executeType=SQL --executeContent="SELECT 1" --cron="0 0 0 * * ?"',
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/views/teamwork/schedule/Form.vue',
|
||||
api: 'POST /api/scheduletask',
|
||||
ref: 'doc/v0.8-endpoints.md §2.5',
|
||||
},
|
||||
notes: [
|
||||
'**决策 9**: 用 schedule (Quartz) 做"每天凌晨跑一次", 不用工作流',
|
||||
'**反模式**: 业务审批用 workflow, 定时清理/缓存刷新用 schedule',
|
||||
],
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* commands/schedule/index.ts — schedule 父命令
|
||||
*
|
||||
* JNPF 定时任务 (Quartz, scheduletask)
|
||||
*
|
||||
* 决策 9: 定时报表生成/数据清理/缓存刷新用 schedule (cron),
|
||||
* 业务审批用 workflow (人工发起/事件触发)
|
||||
*
|
||||
* 子命令:
|
||||
* list 列表 (JNPF 端点已知返空, 用 info 兜底)
|
||||
* info 详情
|
||||
* create 新建
|
||||
* trigger 手动触发
|
||||
* log 执行日志
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { buildScheduleListCommand } from './list.ts'
|
||||
import { buildScheduleInfoCommand } from './info.ts'
|
||||
import { buildScheduleCreateCommand } from './create.ts'
|
||||
import { buildScheduleTriggerCommand } from './trigger.ts'
|
||||
import { buildScheduleLogCommand } from './log.ts'
|
||||
|
||||
export function buildScheduleCommand(): Command {
|
||||
const cmd = new Command('schedule').description('定时任务 (Quartz cron, 决策 9: 区别于工作流)')
|
||||
cmd.addCommand(buildScheduleListCommand())
|
||||
cmd.addCommand(buildScheduleInfoCommand())
|
||||
cmd.addCommand(buildScheduleCreateCommand())
|
||||
cmd.addCommand(buildScheduleTriggerCommand())
|
||||
cmd.addCommand(buildScheduleLogCommand())
|
||||
return cmd
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* commands/schedule/info.ts — 定时任务详情
|
||||
*
|
||||
* API: GET /api/scheduletask/Info/{id}
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
|
||||
interface InfoOpts {
|
||||
id: string
|
||||
json?: boolean
|
||||
}
|
||||
|
||||
export function buildScheduleInfoCommand(): Command {
|
||||
const cmd = new Command('info')
|
||||
.description('查看定时任务详情 (Quartz cron + 执行配置)')
|
||||
.requiredOption('--id <id>', '定时任务 id')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
.action(async (opts: InfoOpts) => {
|
||||
const c = await JnpfClient.fromToken()
|
||||
const r = await c.get<Record<string, unknown>>(`/scheduletask/Info/${opts.id}`)
|
||||
if (r.code !== 200) {
|
||||
log.error(`schedule info 失败: ${r.msg}`)
|
||||
process.exit(1)
|
||||
}
|
||||
if (!r.data) {
|
||||
log.error(`schedule id=${opts.id} 不存在`)
|
||||
process.exit(1)
|
||||
}
|
||||
if (opts.json) {
|
||||
printJson(r.data)
|
||||
return
|
||||
}
|
||||
const d = r.data as Record<string, unknown>
|
||||
log.info(`定时任务 id=${opts.id} 名称=${d.fullName} 编码=${d.enCode}`)
|
||||
console.log(`cron: ${d.cron || '-'}`)
|
||||
console.log(`executeType: ${d.executeType || '-'}`)
|
||||
console.log(`executeContent: ${d.executeContent || '-'}`)
|
||||
console.log(`enabledMark: ${d.enabledMark === 1 ? '启用' : '停用'}`)
|
||||
})
|
||||
installAiHelpHook(cmd, {
|
||||
purpose: '查看定时任务详情 (Quartz cron + 执行配置)',
|
||||
required: { '--id': '定时任务 id' },
|
||||
example: 'dacli schedule info --id=1234567890',
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/views/teamwork/schedule/Form.vue',
|
||||
api: 'GET /api/scheduletask/Info/{id}',
|
||||
ref: 'doc/v0.8-endpoints.md §2.5',
|
||||
},
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* commands/schedule/list.ts — 定时任务列表
|
||||
*
|
||||
* 注: JNPF GET /api/scheduletask 返 200 空 body (已知 JNPF 端点问题),
|
||||
* schedule 列表只能通过 Info/{id} 单点查, 或从任务调度 Web UI 拿 id
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
|
||||
interface ListOpts {
|
||||
json?: boolean
|
||||
}
|
||||
|
||||
export function buildScheduleListCommand(): Command {
|
||||
const cmd = new Command('list')
|
||||
.description('列定时任务 (JNPF list 端点已知返 200 空 body, 用 Info/{id} 兜底)')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
.action(async (opts: ListOpts) => {
|
||||
const c = await JnpfClient.fromToken()
|
||||
const r = await c.get<unknown>('/scheduletask', { currentPage: 1, pageSize: 50 })
|
||||
log.warn('⚠ JNPF schedule list 端点已知返 200 空 body, JNPF 端点问题')
|
||||
log.info(' 兜底方案: 用 Info/{id} 单点查, 或从 web 任务调度页面拿 id')
|
||||
if (r.code === 200 && r.data) {
|
||||
printJson(r.data)
|
||||
} else {
|
||||
log.info(' (data 为空)')
|
||||
}
|
||||
if (opts.json) printJson(r.data)
|
||||
})
|
||||
installAiHelpHook(cmd, {
|
||||
purpose: '列定时任务 (JNPF list 端点已知坏, 用 Info/{id} 查单个)',
|
||||
example: 'dacli schedule list (已知返空)\ndacli schedule info --id=1234567890',
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/views/teamwork/schedule/index.vue',
|
||||
api: 'GET /api/scheduletask (JNPF 端点已知返 200 空 body)',
|
||||
ref: 'doc/v0.8-endpoints.md §2.5',
|
||||
},
|
||||
notes: [
|
||||
'**已知遗留**: JNPF GET /api/scheduletask 返 200 空 body (JNPF 6.2 端点问题)',
|
||||
'**兜底**: 用 schedule info --id=X 单点查',
|
||||
],
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* commands/schedule/log.ts — 定时任务执行日志
|
||||
*
|
||||
* API: GET /api/scheduletask/{id}/TaskLog
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
|
||||
interface LogOpts {
|
||||
id: string
|
||||
json?: boolean
|
||||
}
|
||||
|
||||
interface LogItem {
|
||||
id?: string
|
||||
runTime?: string | number
|
||||
runResult?: number
|
||||
description?: string
|
||||
}
|
||||
|
||||
export function buildScheduleLogCommand(): Command {
|
||||
const cmd = new Command('log')
|
||||
.description('查看定时任务执行日志')
|
||||
.requiredOption('--id <id>', '定时任务 id')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
.action(async (opts: LogOpts) => {
|
||||
const c = await JnpfClient.fromToken()
|
||||
const r = await c.get<{ list: LogItem[] }>(`/scheduletask/${opts.id}/TaskLog`, {
|
||||
currentPage: 1,
|
||||
pageSize: 20,
|
||||
})
|
||||
if (r.code !== 200) {
|
||||
log.error(`schedule log 失败: ${r.msg}`)
|
||||
process.exit(1)
|
||||
}
|
||||
const list = r.data?.list || []
|
||||
if (opts.json) {
|
||||
printJson(r.data)
|
||||
return
|
||||
}
|
||||
log.info(`定时任务 id=${opts.id} 共 ${list.length} 条日志`)
|
||||
console.log('ID RUN_TIME RESULT DESCRIPTION')
|
||||
console.log('-'.repeat(100))
|
||||
for (const d of list) {
|
||||
const id = String(d.id || '').padEnd(30)
|
||||
const t = String(d.runTime || '').padEnd(23)
|
||||
const r2 = d.runResult === 1 ? '成功' : d.runResult === 0 ? '失败' : '-'
|
||||
console.log(`${id}${t}${r2} ${d.description || '-'}`)
|
||||
}
|
||||
})
|
||||
installAiHelpHook(cmd, {
|
||||
purpose: '查看定时任务执行日志',
|
||||
required: { '--id': '定时任务 id' },
|
||||
example: 'dacli schedule log --id=1234567890',
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/views/teamwork/schedule/index.vue',
|
||||
api: 'GET /api/scheduletask/{id}/TaskLog',
|
||||
ref: 'doc/v0.8-endpoints.md §2.5',
|
||||
},
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* commands/schedule/trigger.ts — 手动触发定时任务
|
||||
*
|
||||
* API: POST /api/scheduletask/white/trigger
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log } from '../../core/log.ts'
|
||||
|
||||
interface TriggerOpts {
|
||||
id: string
|
||||
}
|
||||
|
||||
export function buildScheduleTriggerCommand(): Command {
|
||||
const cmd = new Command('trigger')
|
||||
.description('手动触发定时任务 (白名单, 不等 cron)')
|
||||
.requiredOption('--id <id>', '定时任务 id')
|
||||
.action(async (opts: TriggerOpts) => {
|
||||
const c = await JnpfClient.fromToken()
|
||||
const r = await c.postJson('/scheduletask/white/trigger', { id: opts.id })
|
||||
if (r.code !== 200) {
|
||||
log.error(`schedule trigger 失败: ${r.msg}`)
|
||||
process.exit(1)
|
||||
}
|
||||
log.info(`✓ 定时任务 id=${opts.id} 已触发`)
|
||||
})
|
||||
installAiHelpHook(cmd, {
|
||||
purpose: '手动触发定时任务 (不等 cron, 立即跑)',
|
||||
required: { '--id': '定时任务 id' },
|
||||
example: 'dacli schedule trigger --id=1234567890',
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/views/teamwork/schedule/Form.vue',
|
||||
api: 'POST /api/scheduletask/white/trigger',
|
||||
ref: 'doc/v0.8-endpoints.md §2.5',
|
||||
},
|
||||
notes: [
|
||||
'**W11-D4**: 验证定时任务真触发走此命令 + schedule log 拉日志',
|
||||
],
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
Reference in new issue
Block a user