数据目录 F1-A4:码值项加「已列全」标记(complete: true),只有人工明确勾选、或剖析整表统计(没有只看前若干行)得到的码值才有;码值不在码值表中的检查只认标了它的码值表,给模型的话改为提示核对取值,不再叫它照目录里的码值改。以前经对话只补了 status=9 表示作废,之后 status = 1 就被报提醒,模型还可能把对的 SQL 改错。提案补充码值时沿用原有的标记、自己不能标;目录页的码值编辑和填写含义弹窗加「已列出全部取值」勾选,表格里标「已列全」,检查脚本跟上

This commit is contained in:
ThearchyHelios
2026-10-04 01:13:13 +08:00
parent fd3ec43662
commit b078d08ffe
11 changed files with 275 additions and 58 deletions
+6 -1
View File
@@ -2465,6 +2465,11 @@ export const CODES_TEXT = {
saved: (n: number) => (n ? `已填写 ${formatNumber(n)} 个码值的含义` : '已保存'),
save: '保存',
cancel: '取消',
// 「已列出全部取值」:只有勾了的码值表,SQL 检查才提醒「码值不在码值表中」;只列了一部分(比如对话里只补了一个码)不勾
complete: '已列出全部取值',
completeHint: '勾选表示这一列只会出现这些取值,SQL 检查会据此提醒码值表中没有的取值;只列了一部分时不要勾选',
completeMark: '已列全',
completeMarkHint: '已列出全部取值:SQL 检查会提醒码值表中没有的取值',
}
// ===========================================================================
@@ -2492,7 +2497,7 @@ export const SQL_CHECK_RULE_HINT: Record<SqlCheckCode, string> = {
join_unconfirmed: '关联条件对不上数据目录中有确证的关系,可能连错了列',
ratio_aggregated: '对比率列直接求和或求平均,得不到正确的比率',
missing_valid_filter: '表定义了有效记录条件,查询没有按它筛选',
unknown_code: '按码值筛选时用了码值表中没有的值',
unknown_code: '码值表已列出全部取值,按码值筛选时却用了其中没有的值',
wrong_date_column: '表定义了业务日期,查询却按另一个时间列分组或筛选',
}
+15 -4
View File
@@ -3,28 +3,32 @@ import type { CatalogItem } from '../../types'
import { isComposing, Modal, Spinner } from '../../components/ui'
import { CODES_TEXT as KT } from '../../lib/terms'
import { StatusChip } from './parts'
import { codesComplete } from './model'
// ===========================================================================
// 填写码值的含义。数据剖析只知道列里出现过哪些取值(码值候选的含义是空串),含义要人填:逐个码值一个输入框,
// 比在编辑模式里改「码值=含义」的多行文字省事。保存走整份提交,这一项记为人工填写、已确认;
// 暂不清楚的含义可以留空,表格里照旧显示「含义待填写」。
// 底下的「已列出全部取值」写明当前是否已列全,可以勾选或取消:只有勾了的码值表,SQL 检查才会提醒「取值不在码值表中」。
// ===========================================================================
export function CodesDialog({ column, item, saving, onSave, onClose }: {
column: string
item: CatalogItem<Record<string, string>>
saving: boolean
/** 新的码值对照(码值不变,只改含义) */
onSave: (value: Record<string, string>) => void
/** 新的码值对照(码值不变,只改含义)和「已列出全部取值」 */
onSave: (value: Record<string, string>, complete: boolean) => void
onClose: () => void
}) {
const [initial] = useState(() => ({ ...item.value }))
const [value, setValue] = useState<Record<string, string>>(initial)
const [wasComplete] = useState(() => codesComplete(item))
const [complete, setComplete] = useState(wasComplete)
const codes = Object.keys(initial)
const dirty = codes.some((k) => (value[k] ?? '').trim() !== (initial[k] ?? '').trim())
const dirty = complete !== wasComplete || codes.some((k) => (value[k] ?? '').trim() !== (initial[k] ?? '').trim())
const save = () => {
if (!dirty || saving) return
onSave(Object.fromEntries(codes.map((k) => [k, (value[k] ?? '').trim()])))
onSave(Object.fromEntries(codes.map((k) => [k, (value[k] ?? '').trim()])), complete)
}
return (
<Modal open onClose={onClose} dirty={dirty} width={520} title={KT.title(column)}
@@ -72,6 +76,13 @@ export function CodesDialog({ column, item, saving, onSave, onClose }: {
</tbody>
</table>
</div>
<label className="flex items-start gap-2 rounded border bg-bg px-2 py-1.5 text-xs" data-codes-complete-field={complete ? 'true' : 'false'}>
<input type="checkbox" className="mt-[3px]" checked={complete} onChange={(e) => setComplete(e.target.checked)} data-codes-complete="" />
<span className="min-w-0">
<span className="font-medium">{KT.complete}</span>
<span className="block text-2xs leading-relaxed text-faint">{KT.completeHint}</span>
</span>
</label>
<p className="text-2xs leading-relaxed text-faint">{KT.hint}</p>
</div>
</Modal>
+35 -17
View File
@@ -11,8 +11,8 @@ import {
} from '../../lib/terms'
import { ItemMark } from './parts'
import type { ReviewTarget } from './parts'
import { COLUMN_FIELDS, columnPath } from './model'
import type { ColumnField } from './model'
import { COLUMN_FIELDS, codesComplete, columnPath, completeOf } from './model'
import type { ColumnDraft, ColumnField } from './model'
// ===========================================================================
// 单表详情的列表格:列名 / 类型、中文名、含义、单位、度量类型、码值。每格的值旁边是只有图标的状态标识,点开看来源、
@@ -30,9 +30,9 @@ export interface ColumnModel {
items: CatalogColumnNotes | undefined
}
type ColumnTexts = Partial<Record<ColumnField, string>>
type ColumnTexts = ColumnDraft
export function ColumnTable({ columns, form, initial, problems, busy, systemNotes, onReview, onConfirmColumn, onFillCodes, onChange }: {
export function ColumnTable({ columns, form, initial, problems, busy, systemNotes, onReview, onConfirmColumn, onFillCodes, onChange, onCodesComplete }: {
columns: ColumnModel[]
/** 编辑中:列名 → 字段 → 文字(form 是当前的,initial 是进入编辑时的);不在编辑时为 null */
form: Record<string, ColumnTexts> | null
@@ -47,6 +47,8 @@ export function ColumnTable({ columns, form, initial, problems, busy, systemNote
/** 码值里有含义空着的:打开逐个填写含义的弹窗 */
onFillCodes: (col: string) => void
onChange: (col: string, field: ColumnField, value: string) => void
/** 编辑中勾选或取消码值的「已列出全部取值」 */
onCodesComplete: (col: string, value: boolean) => void
}) {
return (
<div className="relative overflow-x-auto rounded-lg border" data-catalog-columns="">
@@ -68,7 +70,8 @@ export function ColumnTable({ columns, form, initial, problems, busy, systemNote
<tbody>
{columns.map((c) => (
<ColumnRow key={c.name} col={c} editing={!!form} draft={form?.[c.name]} initial={initial?.[c.name]} problems={problems} busy={busy}
systemNotes={systemNotes} onReview={onReview} onConfirmColumn={onConfirmColumn} onFillCodes={onFillCodes} onChange={onChange} />
systemNotes={systemNotes} onReview={onReview} onConfirmColumn={onConfirmColumn} onFillCodes={onFillCodes} onChange={onChange}
onCodesComplete={onCodesComplete} />
))}
</tbody>
</table>
@@ -76,7 +79,8 @@ export function ColumnTable({ columns, form, initial, problems, busy, systemNote
)
}
const ColumnRow = memo(function ColumnRow({ col, editing, draft, initial, problems, busy, systemNotes, onReview, onConfirmColumn, onFillCodes, onChange }: {
const ColumnRow = memo(function ColumnRow({ col, editing, draft, initial, problems, busy, systemNotes, onReview, onConfirmColumn, onFillCodes, onChange,
onCodesComplete }: {
col: ColumnModel
editing: boolean
/** 这一列的表单。只有改了这一列时引用才会变,别的行不重画 */
@@ -89,6 +93,7 @@ const ColumnRow = memo(function ColumnRow({ col, editing, draft, initial, proble
onConfirmColumn: (col: string) => void
onFillCodes: (col: string) => void
onChange: (col: string, field: ColumnField, value: string) => void
onCodesComplete: (col: string, value: boolean) => void
}) {
const { name, structure, items } = col
const pending = COLUMN_FIELDS.filter((f) => items?.[f]?.status === 'proposed').length
@@ -97,7 +102,7 @@ const ColumnRow = memo(function ColumnRow({ col, editing, draft, initial, proble
const it = items?.[f] as CatalogItem | undefined
const where = CT.whereColumn(name, CATALOG_COLUMN_FIELD_LABEL[f])
const problem = problems[`c:${name}:${f}`]
const changed = editing && (draft?.[f] ?? '') !== (initial?.[f] ?? '')
const changed = editing && ((draft?.[f] ?? '') !== (initial?.[f] ?? '') || (f === 'codes' && completeOf(draft) !== completeOf(initial)))
return (
<td className="px-2 py-1.5 align-top" data-cell={f} data-status={it?.status}>
<div className="flex items-start gap-1.5">
@@ -170,15 +175,23 @@ const ColumnRow = memo(function ColumnRow({ col, editing, draft, initial, proble
{cell(
'codes',
<Value item={codes} render={(v) => (
<Codes value={v as Record<string, string>} label={KT.fillLabel(name)}
<Codes value={v as Record<string, string>} label={KT.fillLabel(name)} complete={codesComplete(codes)}
onFill={codes?.status !== 'rejected' && !busy ? () => onFillCodes(name) : undefined} />
)} />,
<textarea className="field mono !min-h-0 !px-1.5 !py-1 !text-2xs" rows={Math.min(4, Math.max(1, (draft?.codes ?? '').split('\n').length))}
value={draft?.codes ?? ''}
placeholder={codes?.status === 'rejected' ? CT.rejectedPlaceholder(codesInline(codes.value)) : CT.codesPlaceholder}
aria-label={CT.whereColumn(name, CATALOG_COLUMN_FIELD_LABEL.codes)}
aria-invalid={problems[`c:${name}:codes`] ? true : undefined}
onChange={(e) => onChange(name, 'codes', e.target.value)} data-input="codes" />,
<>
<textarea className="field mono !min-h-0 !px-1.5 !py-1 !text-2xs" rows={Math.min(4, Math.max(1, (draft?.codes ?? '').split('\n').length))}
value={draft?.codes ?? ''}
placeholder={codes?.status === 'rejected' ? CT.rejectedPlaceholder(codesInline(codes.value)) : CT.codesPlaceholder}
aria-label={CT.whereColumn(name, CATALOG_COLUMN_FIELD_LABEL.codes)}
aria-invalid={problems[`c:${name}:codes`] ? true : undefined}
onChange={(e) => onChange(name, 'codes', e.target.value)} data-input="codes" />
{/* 只列了一部分取值时不勾:SQL 检查只拿勾了的码值表判断「取值不在码值表中」 */}
<label className="mt-1 flex items-start gap-1 text-2xs leading-snug text-dim" title={KT.completeHint}>
<input type="checkbox" className="mt-[2px]" checked={completeOf(draft)} disabled={!(draft?.codes ?? '').trim()}
onChange={(e) => onCodesComplete(name, e.target.checked)} data-input="codes-complete" />
{KT.complete}
</label>
</>,
)}
<td className="px-1 py-1.5 align-top">
{!editing && pending > 0 && (
@@ -190,7 +203,7 @@ const ColumnRow = memo(function ColumnRow({ col, editing, draft, initial, proble
)
}, (a, b) => a.col === b.col && a.editing === b.editing && a.draft === b.draft && a.initial === b.initial && a.busy === b.busy
&& a.systemNotes === b.systemNotes && a.onReview === b.onReview && a.onConfirmColumn === b.onConfirmColumn && a.onFillCodes === b.onFillCodes
&& a.onChange === b.onChange
&& a.onChange === b.onChange && a.onCodesComplete === b.onCodesComplete
// 格式问题每次都是新对象:只比这一列的几格
&& COLUMN_FIELDS.every((f) => a.problems[`c:${a.col.name}:${f}`] === b.problems[`c:${b.col.name}:${f}`]))
@@ -206,11 +219,11 @@ export function Value<T>({ item, render }: { item: CatalogItem<T> | undefined; r
export const pendingCodes = (v: Record<string, string> | undefined): number =>
Object.values(v ?? {}).filter((x) => !String(x ?? '').trim()).length
function Codes({ value, label, onFill }: { value: Record<string, string>; label: string; onFill?: () => void }) {
function Codes({ value, label, complete, onFill }: { value: Record<string, string>; label: string; complete: boolean; onFill?: () => void }) {
const entries = Object.entries(value)
const pending = pendingCodes(value)
return (
<span className="block">
<span className="block" data-codes-complete={complete ? 'true' : 'false'}>
<span className="flex flex-wrap gap-1" title={entries.map(([k, v]) => `${k}=${v.trim() || KT.pending}`).join('\n')}>
{entries.slice(0, CODES_SHOWN).map(([k, v]) => (
<span key={k} className="inline-flex max-w-full items-center gap-1 rounded border bg-bg px-1 text-2xs" data-code={k}>
@@ -222,6 +235,11 @@ function Codes({ value, label, onFill }: { value: Record<string, string>; label:
))}
{entries.length > CODES_SHOWN && <span className="text-2xs text-faint">+{entries.length - CODES_SHOWN}</span>}
</span>
{complete && (
<span className="mt-1 inline-flex items-center gap-0.5 text-2xs text-faint" title={KT.completeMarkHint} data-codes-complete-mark="">
<CheckCheck size={10} aria-hidden /> {KT.completeMark}
</span>
)}
{pending > 0 && onFill && (
// 各码值的「含义待填写」已经写在上面,这里只给入口;几个待填写写在悬停里
<button type="button" className="mt-1 inline-flex items-center gap-1 whitespace-nowrap rounded px-1 text-2xs text-dim underline decoration-dotted underline-offset-2 hover:text-fg"
+11 -6
View File
@@ -25,7 +25,7 @@ import {
COLUMN_FIELDS, DATE_KEYS, TABLE_FIELDS, buildNotes, changeCount, columnPath, confirmProposed, countsOf, formFromNotes,
relationDraft, relationPath, relationRemoval, tablePath, unknownKeys, validateForm,
} from './model'
import type { ColumnField, EditForm, RelationDraft, TableField, TableKey } from './model'
import type { CodesItem, ColumnField, EditForm, RelationDraft, TableField, TableKey } from './model'
// ===========================================================================
// 单表详情:表级各项、列表格、关联关系。每一项标出来源和状态,点状态标识做单项确认 / 驳回 / 恢复(审阅接口);
@@ -182,15 +182,16 @@ export function TableDetail({ sourceId, table, rows, drafted, fillCodes, prev, n
const fillCodesOf = useCallback((col: string) => setCodesFor(col), [])
/**
* 填好的码值含义整份提交:只换这一列码值的值,服务端记为人工填写、已确认。别人刚改过(409)时收起弹窗、挂冲突横幅;
* 填好的码值含义(和「已列出全部取值」)整份提交:只换这一列码值的值,服务端记为人工填写、已确认。别人刚改过(409)时收起弹窗、挂冲突横幅;
* 其余失败弹窗留着,填的字不丢
*/
const saveCodes = useCallback(async (col: string, value: Record<string, string>) => {
const saveCodes = useCallback(async (col: string, value: Record<string, string>, complete: boolean) => {
const d = detailRef.current
const item = d?.notes.columns?.[col]?.codes
if (!d || !item) return
const notes = structuredClone(d.notes)
notes.columns![col] = { ...notes.columns![col], codes: { ...item, value } }
// 「已列出全部取值」跟着交:取消勾选交 false(服务端不留这个键),只改勾选也算人工改动
notes.columns![col] = { ...notes.columns![col], codes: { ...item, value, complete } as CodesItem }
setBusy(`codes:${col}`)
setWriteError(null)
try {
@@ -217,6 +218,9 @@ export function TableDetail({ sourceId, table, rows, drafted, fillCodes, prev, n
const setColumn = useCallback((col: string, f: ColumnField, v: string) => {
setEdit((e) => e && ({ ...e, form: { ...e.form, columns: { ...e.form.columns, [col]: { ...e.form.columns[col], [f]: v } } } }))
}, [])
const setCodesComplete = useCallback((col: string, v: boolean) => {
setEdit((e) => e && ({ ...e, form: { ...e.form, columns: { ...e.form.columns, [col]: { ...e.form.columns[col], complete: v } } } }))
}, [])
const setTable = (k: TableKey, v: string) => setEdit((e) => e && ({ ...e, form: { ...e.form, table: { ...e.form.table, [k]: v } } }))
const setRelations = (fn: (rs: RelationDraft[]) => RelationDraft[]) =>
setEdit((e) => e && ({ ...e, form: { ...e.form, relations: fn(e.form.relations) } }))
@@ -419,7 +423,8 @@ export function TableDetail({ sourceId, table, rows, drafted, fillCodes, prev, n
? (
<ColumnTable columns={shownColumns} form={edit?.form.columns ?? null} initial={edit?.initial.columns ?? null}
problems={problems} busy={!!busy} systemNotes={detail.system_notes}
onReview={review} onConfirmColumn={confirmColumn} onFillCodes={fillCodesOf} onChange={setColumn} />
onReview={review} onConfirmColumn={confirmColumn} onFillCodes={fillCodesOf} onChange={setColumn}
onCodesComplete={setCodesComplete} />
)
: <p className="rounded-lg border px-3 py-6 text-center text-xs text-faint">{CT.noColumns}</p>}
</section>
@@ -447,7 +452,7 @@ export function TableDetail({ sourceId, table, rows, drafted, fillCodes, prev, n
{codesFor && notes.columns?.[codesFor]?.codes && (
<CodesDialog column={codesFor} item={notes.columns[codesFor]!.codes!} saving={busy === `codes:${codesFor}`}
onSave={(v) => void saveCodes(codesFor, v)} onClose={() => setCodesFor(null)} />
onSave={(v, complete) => void saveCodes(codesFor, v, complete)} onClose={() => setCodesFor(null)} />
)}
{edit && (
+31 -3
View File
@@ -203,13 +203,27 @@ export function relationRemoval(orig: CatalogRelation | null): 'delete' | 'rejec
return orig.status === 'rejected' ? null : 'reject'
}
/** 一列的表单:每个字段一段文字;complete 是码值的「已列出全部取值」勾选 */
export type ColumnDraft = Partial<Record<ColumnField, string>> & { complete?: boolean }
export interface EditForm {
table: Partial<Record<TableKey, string>>
/** 列名 → 字段 → 文字 */
columns: Record<string, Partial<Record<ColumnField, string>>>
columns: Record<string, ColumnDraft>
relations: RelationDraft[]
}
/** 码值项:可带「已列全」标记(服务端 catalog.codes_complete) */
export type CodesItem = CatalogItem<Record<string, string>> & { complete?: boolean }
/**
* 码值表是不是标了「已列出全部取值」。只有标了的,SQL 检查才会提醒「码值不在码值表中」;没标的只是已知的一部分取值
* (比如对话里只补了一个码的含义),不拿来判断。被驳回的不算
*/
export function codesComplete(item: CatalogItem<Record<string, string>> | undefined): boolean {
return !!item && item.status !== 'rejected' && (item as CodesItem).complete === true
}
const splitList = (s: string) => s.split(/[、,,;;\s]+/).map((x) => x.trim()).filter(Boolean)
const joinList = (v: string[]) => v.join('、')
@@ -264,7 +278,7 @@ export function formFromNotes(notes: CatalogNotes, structure: CatalogStructureCo
for (const col of names) {
if (columns[col]) continue
const items = notes.columns?.[col]
columns[col] = Object.fromEntries(COLUMN_FIELDS.map((f) => [f, columnText(items, f)]))
columns[col] = { ...Object.fromEntries(COLUMN_FIELDS.map((f) => [f, columnText(items, f)])), complete: codesComplete(items?.codes) }
}
const relations = (notes.relations ?? []).map((r) => relationDraft(r))
return { table, columns, relations }
@@ -284,12 +298,16 @@ export function relationDraft(r: CatalogRelation | null, key?: string): Relation
const sameRelation = (a: RelationDraft, b: RelationDraft) =>
a.columns === b.columns && a.to_table === b.to_table && a.to_columns === b.to_columns && a.cardinality === b.cardinality
/** 表单里改了几处:表级、列级各算一格,关系增删改各算一条 */
/** 表单里「已列出全部取值」算不算勾上:码值清空了就不算(没有码值,谈不上列全) */
export const completeOf = (d: ColumnDraft | undefined): boolean => !!d?.complete && !!(d.codes ?? '').trim()
/** 表单里改了几处:表级、列级各算一格(码值的「已列全」勾选另算一格),关系增删改各算一条 */
export function changeCount(initial: EditForm, form: EditForm): number {
let n = 0
for (const k of TABLE_KEYS) if ((initial.table[k] ?? '') !== (form.table[k] ?? '')) n++
for (const [col, fields] of Object.entries(form.columns)) {
for (const f of COLUMN_FIELDS) if ((initial.columns[col]?.[f] ?? '') !== (fields[f] ?? '')) n++
if (completeOf(initial.columns[col]) !== completeOf(fields)) n++
}
const before = new Map(initial.relations.map((r) => [r.key, r]))
const after = new Set(form.relations.map((r) => r.key))
@@ -400,6 +418,16 @@ export function buildNotes(orig: CatalogNotes, initial: EditForm, form: EditForm
const o = orig.columns?.[col]?.[f] as CatalogItem | undefined
const a = initial.columns[col]?.[f] ?? ''
const b = form.columns[col]?.[f] ?? a
if (f === 'codes') {
// 码值的文字没动、只改了「已列全」勾选:值原样、带上新的勾选交回(服务端也算改动,记为人工填写、已确认)
const was = completeOf(initial.columns[col])
const now = form.columns[col] ? completeOf(form.columns[col]) : was
if (a === b && was === now) { if (o) items[f] = o; continue }
if (!b.trim()) continue
const value = a === b && o ? o.value : parseColumn(f, b)
items[f] = { ...(o ?? {}), value, complete: now }
continue
}
const next = put(o, a, b, () => parseColumn(f, b))
if (next) items[f] = next
}