auto(14b5ea1b9bd9): session end @ 2026-07-23T18:49:07 (+1f)
This commit is contained in:
1 parent
cba74702f2
commit
2357cb97be
1 file changed
+124
-14
+124
-14
@@ -76,6 +76,19 @@ interface ClearOpts {
|
||||
workspace?: string
|
||||
verbose?: boolean
|
||||
json?: boolean
|
||||
scope?: string // --scope=<preset> 原始值 (在 action 中转 scopePreset)
|
||||
// P1-2e (2026-07-23): 按范围控制清理 (v2 增强)
|
||||
includeWorkflow?: boolean // workflow_template 等 23 张 (默认 true)
|
||||
includeDi?: boolean // base_data_interface 等 5 张 (默认 true)
|
||||
includePortal?: boolean // base_portal 等 3 张 (默认 true)
|
||||
includePrint?: boolean // base_print_template 等 3 张 (默认 true)
|
||||
includeReport?: boolean // report_template (默认 true)
|
||||
includeSchedule?: boolean // base_schedule 等 3 张 (默认 true)
|
||||
includeDict?: boolean // base_dictionary_type + data (默认 true)
|
||||
includeBiz?: boolean // 业务库 RENAME (默认 true)
|
||||
// 短手: --only=workflow,di / --scope=conservative
|
||||
only?: string // 只清理这些范围 (空=全)
|
||||
scopePreset?: string // 'conservative' (只 form+dict) | 'all' (默认)
|
||||
}
|
||||
|
||||
interface Paths {
|
||||
@@ -117,6 +130,14 @@ interface DbClearPreview {
|
||||
mainHits: TableHit[]
|
||||
bizTables: BizTable[]
|
||||
error: string | null
|
||||
// P1-2e (2026-07-23): 按范围拆分 (后端透传)
|
||||
workflowHits?: TableHit[]
|
||||
diHits?: TableHit[]
|
||||
portalHits?: TableHit[]
|
||||
printHits?: TableHit[]
|
||||
reportHits?: TableHit[]
|
||||
scheduleHits?: TableHit[]
|
||||
dictHits?: TableHit[]
|
||||
}
|
||||
|
||||
interface DbClearResult {
|
||||
@@ -140,10 +161,23 @@ export function buildAppClearCommand(): Command {
|
||||
.option('--workspace <dir>', '工程根目录 (默认 $ccWorkDir 或 cwd)')
|
||||
.option('--verbose', '完整输出 (含 dry-run 详细预览)', false)
|
||||
.option('--json', '原始 JSON 输出 (--dry-run + --json 给 AI 解析清单; 真实执行时仍走人类 TTY)', false)
|
||||
// P1-2e (2026-07-23): 按范围控制清理 (扩展 --clean-docs 思路)
|
||||
.option('--only <list>', '只清这些范围 (逗号分隔: workflow,di,portal,print,report,schedule,dict,biz,form; 例: --only=workflow,di 跨 app 清残留)')
|
||||
.option('--scope <preset>', '预设范围: all (默认, 全清) | conservative (只 form+dict+biz, 不动 workflow/di/portal 全局资源)')
|
||||
.option('--include-workflow', '包含 workflow_template 等 23 张 (默认 true)', true)
|
||||
.option('--include-di', '包含 base_data_interface 等 5 张 (默认 true)', true)
|
||||
.option('--include-portal', '包含 base_portal 等 3 张 (默认 true)', true)
|
||||
.option('--include-print', '包含 base_print_template 等 3 张 (默认 true)', true)
|
||||
.option('--include-report', '包含 report_template (默认 true)', true)
|
||||
.option('--include-schedule', '包含 base_schedule 等 3 张 (默认 true)', true)
|
||||
.option('--include-dict', '包含 base_dictionary_type + data (默认 true)', true)
|
||||
.option('--include-biz', '包含业务库 RENAME (默认 true)', true)
|
||||
.action(async (opts: ClearOpts) => {
|
||||
// v2.1+ L1: stdout 三模式 (default=quiet, --verbose=完整 dry-run, --json=仅 dry-run 输出 JSON)
|
||||
setupOutputFilter(opts)
|
||||
const startTime = Date.now()
|
||||
// P1-2e: --scope=conservative / all 归一化到 scopePreset
|
||||
if (opts.scope) opts.scopePreset = opts.scope
|
||||
const c = await JnpfClient.fromToken().catch(() => ({ appCode: '' } as { appCode: string }))
|
||||
|
||||
// v2.1+ L2 silent+suggest: 跨命令 auto-fix pipeline
|
||||
@@ -200,16 +234,30 @@ export function buildAppClearCommand(): Command {
|
||||
'--skip-db': '跳过 DB 清理 (只清本地文件 + 构建配置)',
|
||||
'--no-restart': '清理后不询问 create 重建',
|
||||
'--workspace': '工程根目录 (默认 $ccWorkDir)',
|
||||
// P1-2e (2026-07-23)
|
||||
'--only <list>': '只清这些范围 (例: --only=workflow,di,dict 跨 app 清理残留)',
|
||||
'--scope <preset>': '预设: all (默认) | conservative (只 form+dict+biz, 不动 workflow/di 全局资源)',
|
||||
'--include-workflow / --no-include-workflow': '是否清 workflow_template 等 23 张 (默认 true)',
|
||||
'--include-di / --no-include-di': '是否清 base_data_interface 等 5 张 (默认 true)',
|
||||
'--include-portal / --no-include-portal': '是否清 base_portal 等 3 张 (默认 true)',
|
||||
'--include-print / --no-include-print': '是否清 base_print_template 等 3 张 (默认 true)',
|
||||
'--include-report / --no-include-report': '是否清 report_template (默认 true)',
|
||||
'--include-schedule / --no-include-schedule': '是否清 base_schedule 等 3 张 (默认 true)',
|
||||
'--include-dict / --no-include-dict': '是否清 base_dictionary_type + data (默认 true)',
|
||||
'--include-biz / --no-include-biz': '是否清业务库 RENAME (默认 true)',
|
||||
},
|
||||
example: [
|
||||
'dacli app clear --appCode=tds2 --dry-run # AI 也可跑, 看清单',
|
||||
'dacli app clear --appCode=tds2 # 人工 TTY + 双确认 (键入 tds2 + DELETE)',
|
||||
'dacli app clear --appCode=tds2 --skip-db # 只清文件 + 构建配置',
|
||||
'dacli app clear --appCode=tds2 --workspace=/work/cc',
|
||||
'dacli app clear --appCode=tds2 --dry-run # AI 也可跑, 看清单',
|
||||
'dacli app clear --appCode=tds2 # 人工 TTY + 双确认 (键入 tds2 + DELETE)',
|
||||
'dacli app clear --appCode=jxcj --dry-run --verbose # 7 大类分组预览',
|
||||
'dacli app clear --appCode=jxcj --only=workflow,di # 只清 workflow + DI 残留',
|
||||
'dacli app clear --appCode=jxcj --scope=conservative # 保守: 不动全局资源',
|
||||
'dacli app clear --appCode=jxcj --no-include-workflow --include-di # 显式关 workflow, 其他全清',
|
||||
'dacli app clear --appCode=tds2 --skip-db # 只清文件 + 构建配置',
|
||||
].join('\n'),
|
||||
source: {
|
||||
web: 'JNPF 平台无对应 UI (仅 CLI 后台工具)',
|
||||
api: 'ssw-common POST /api/ssw/db/clear (mode=preview/execute) — DB 方言自动按 yml 适配',
|
||||
api: 'ssw-common POST /api/ssw/db/clear (mode=preview/execute, scope=workflow,di,...) — DB 方言自动按 yml 适配',
|
||||
ref: 'ssw-common/ssw-common-biz/.../DbClearServiceImpl.java (Java 实现)',
|
||||
},
|
||||
notes: [
|
||||
@@ -217,7 +265,9 @@ export function buildAppClearCommand(): Command {
|
||||
'**DB 类型自动适配**: ssw-common 端点读 yml 的 spring.datasource.db-type 自动选 PG/MySQL 驱动, dacli 不需要装 mysql2/pg.',
|
||||
'**绝不 DROP TABLE / DROP DATABASE**: 业务库用 RENAME TABLE, 主库用 Phase 1/2/3 拆事务.',
|
||||
'**v10.6.1 DDL bug 复刻**: Phase 1 (CREATE+INSERT) + Phase 2 (单事务 DELETE) + Phase 3 (drop 空表) 必须分开, 否则 DDL 隐式 commit 打断事务, rollback 失效.',
|
||||
'**v10.6.2+ 同步清字典 (默认开启)**: ssw-common 端点内部用 `f_en_code LIKE \'{appCode}.%\'` 过滤本应用字典类型.',
|
||||
'**P1-2e (2026-07-23) 同步清平台全局资源 (默认开启)**: ssw-common 端点内部按 scope 过滤 7 大类, dict/workflow/di/portal/print/report/schedule 各有子表.',
|
||||
'**P1-2e dict LIKE 修复**: 之前 LIKE \'{appCode}.%\' 要求带点, 实际 jxcjxxx 不带点; 改为 LIKE \'{appCode}%\' 同时匹配两种命名.',
|
||||
'**范围控制 (--only / --scope=conservative / --include-xxx)**: 跨 app 清残留时, 避免一次清太狠. 例: `--only=workflow,di` 只清工作流和数据接口.',
|
||||
'**文件备份**: renameSync 原子到 docs/{app}/history-bak/{ts}/files/, MANIFEST.txt 写明还原 SQL/rsync.',
|
||||
'**回滚**: 按 docs/{app}/history-bak/{ts}/MANIFEST.txt 中的反向 SQL + rsync 手动还原.',
|
||||
'**--restart**: 清理成功后询问 Y/N, Y → 自动调 `dacli app create --appCode=X --appName=Y --force-rebuild` 重建.',
|
||||
@@ -263,11 +313,12 @@ async function runClear(opts: ClearOpts): Promise<void> {
|
||||
const fileTargets = collectFileTargets(layout, opts.appCode, !!opts.cleanDocs)
|
||||
const pomCount = countPomDependency(layout, opts.appCode)
|
||||
const ymlHasDs = ymlDatasourceExists(layout, opts.appCode)
|
||||
const scopeStr = buildScopeString(opts)
|
||||
let dbPreview: DbClearPreview | null = null
|
||||
|
||||
if (!opts.skipDb) {
|
||||
try {
|
||||
dbPreview = await fetchDbPreview(opts.appCode)
|
||||
dbPreview = await fetchDbPreview(opts.appCode, scopeStr)
|
||||
} catch (e) {
|
||||
log.warn(`(DB 预览失败, 视为 DB 不可用: ${(e as Error).message})`)
|
||||
dbPreview = {
|
||||
@@ -338,7 +389,7 @@ async function runClear(opts: ClearOpts): Promise<void> {
|
||||
let dbResult: DbClearResult | null = null
|
||||
try {
|
||||
if (dbPreview && dbPreview.dbConn) {
|
||||
dbResult = await executeDbClear(opts.appCode, dbTs)
|
||||
dbResult = await executeDbClear(opts.appCode, dbTs, scopeStr)
|
||||
}
|
||||
|
||||
// ---- (8) 文件备份 (跨 fs 安全 move: renameSync + EXDEV 回退 cp+rm) ----
|
||||
@@ -421,11 +472,12 @@ async function runClear(opts: ClearOpts): Promise<void> {
|
||||
// ssw-common 端点调用
|
||||
// =====================================================================
|
||||
|
||||
async function fetchDbPreview(appCode: string): Promise<DbClearPreview> {
|
||||
async function fetchDbPreview(appCode: string, scopeStr: string): Promise<DbClearPreview> {
|
||||
const c = await JnpfClient.fromToken()
|
||||
const res = await c.postJson<DbClearPreview>('/ssw/db/clear', {
|
||||
appCode,
|
||||
mode: 'preview',
|
||||
scope: scopeStr,
|
||||
})
|
||||
if (res.code !== 200 || !res.data) {
|
||||
throw new DacliError(`ssw-common /api/ssw/db/clear preview 失败: code=${res.code} ${res.msg}`)
|
||||
@@ -477,12 +529,13 @@ async function fetchBizTablesViaDmList(
|
||||
return list.map((t) => ({ name: t.table, rowCount: 0 }))
|
||||
}
|
||||
|
||||
async function executeDbClear(appCode: string, dbTs: string): Promise<DbClearResult> {
|
||||
async function executeDbClear(appCode: string, dbTs: string, scopeStr: string): Promise<DbClearResult> {
|
||||
const c = await JnpfClient.fromToken()
|
||||
const res = await c.postJson<DbClearResult>('/ssw/db/clear', {
|
||||
appCode,
|
||||
mode: 'execute',
|
||||
dbTs,
|
||||
scope: scopeStr,
|
||||
})
|
||||
if (res.code !== 200 || !res.data) {
|
||||
throw new DacliError(`ssw-common /api/ssw/db/clear execute 失败: code=${res.code} ${res.msg}`)
|
||||
@@ -490,6 +543,38 @@ async function executeDbClear(appCode: string, dbTs: string): Promise<DbClearRes
|
||||
return res.data
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// P1-2e (2026-07-23): scope 字符串构造
|
||||
// - opts.only="workflow,di" → 只清这两个, 其余关
|
||||
// - opts.includeXxx=false → 显式关 (从默认全开中扣掉)
|
||||
// - opts.scopePreset="conservative" → 仅 form+dict+biz
|
||||
// - 默认 → "all"
|
||||
// =====================================================================
|
||||
function buildScopeString(opts: ClearOpts): string {
|
||||
if (opts.scopePreset === 'conservative') {
|
||||
return 'form,dict,biz'
|
||||
}
|
||||
// opts.only 优先
|
||||
if (opts.only && opts.only.length > 0) {
|
||||
return opts.only
|
||||
}
|
||||
// 显式 includeXxx=false → 从全开中扣掉 (反推 include 列表)
|
||||
const hasExplicit = ['Workflow', 'Di', 'Portal', 'Print', 'Report', 'Schedule', 'Dict', 'Biz']
|
||||
.some(k => (opts as any)[`include${k}`] === false)
|
||||
if (!hasExplicit) return 'all'
|
||||
// form 始终开
|
||||
const includes = ['form']
|
||||
if (opts.includeWorkflow !== false) includes.push('workflow')
|
||||
if (opts.includeDi !== false) includes.push('di')
|
||||
if (opts.includePortal !== false) includes.push('portal')
|
||||
if (opts.includePrint !== false) includes.push('print')
|
||||
if (opts.includeReport !== false) includes.push('report')
|
||||
if (opts.includeSchedule !== false) includes.push('schedule')
|
||||
if (opts.includeDict !== false) includes.push('dict')
|
||||
if (opts.includeBiz !== false) includes.push('biz')
|
||||
return includes.join(',')
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// 工具函数
|
||||
// =====================================================================
|
||||
@@ -757,7 +842,7 @@ function renderPreview(ctx: {
|
||||
} else if (dbPreview.dbConn === null) {
|
||||
log.info(` [ERR ] 无法连接 ssw-common 端点: ${dbPreview.error || '未知错误'}`)
|
||||
} else {
|
||||
const { dbConn, systemId, mainHits, bizTables } = dbPreview
|
||||
const { dbConn, systemId, mainHits, bizTables, workflowHits, diHits, portalHits, printHits, reportHits, scheduleHits, dictHits } = dbPreview
|
||||
log.info(` ${dbConn.dbType} ${dbConn.host}:${dbConn.port} (mainDb=${dbConn.mainDb}, schema=${dbConn.schema || 'public'})`)
|
||||
|
||||
if (systemId === null) {
|
||||
@@ -765,9 +850,34 @@ function renderPreview(ctx: {
|
||||
} else if (mainHits.length === 0) {
|
||||
log.info(` 主库平台表 (systemId=${systemId}): (无受影响行)`)
|
||||
} else {
|
||||
log.info(` 主库平台表 (systemId=${systemId}):`)
|
||||
for (const h of mainHits) {
|
||||
log.info(` [BAK+DEL] ${h.table}: ${h.count} 行 → \`${HISTORY_BAK_DB}\`.\`D${previewTs}-${h.table}\` (INSERT SELECT + DELETE)`)
|
||||
// P1-2e: 按范围分组渲染 (后端透传 7 类 hits, 若未透传则退化为合并 mainHits)
|
||||
const groups: Array<[string, TableHit[] | undefined, string]> = [
|
||||
['字典 (jxcjxxx 等)', dictHits, 'base_dictionary'],
|
||||
['工作流 (workflow_template + 子表)', workflowHits, 'workflow_'],
|
||||
['数据接口 (DI)', diHits, 'base_data_interface'],
|
||||
['门户 (Portal)', portalHits, 'base_portal'],
|
||||
['打印模板 (Print)', printHits, 'base_print'],
|
||||
['报表 (Report)', reportHits, 'report_template'],
|
||||
['定时任务 (Schedule)', scheduleHits, 'base_schedule'],
|
||||
['其他 (form/menu/db_link/system)', undefined, ''],
|
||||
]
|
||||
const classifiedTables = new Set<string>()
|
||||
for (const [name, hits, prefix] of groups) {
|
||||
let bucket: TableHit[]
|
||||
if (hits && hits.length > 0) {
|
||||
bucket = hits
|
||||
} else if (prefix) {
|
||||
bucket = mainHits.filter(h => h.table.startsWith(prefix))
|
||||
} else {
|
||||
// 兜底: 不在前面 7 类的 mainHits
|
||||
bucket = mainHits.filter(h => !classifiedTables.has(h.table))
|
||||
}
|
||||
if (bucket.length === 0) continue
|
||||
for (const h of bucket) classifiedTables.add(h.table)
|
||||
log.info(` [${name}] (${bucket.length} 张):`)
|
||||
for (const h of bucket) {
|
||||
log.info(` [BAK+DEL] ${h.table}: ${h.count} 行 → \`${HISTORY_BAK_DB}\`.\`D${previewTs}-${h.table}\``)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user