feat(p3-commands): v0.11e+ Phase D1 org/msg/datasource step machine
新建 3 _validate.ts (P3 命令 step machine 扩展): - org/_validate.ts (1 step, 镜像 web organize/Form.vue + 后端 OrganizeController + PS036 层级限制) - msg/_validate.ts (1 step, 镜像 web message/notice/Form.vue + 后端 MessageController + MSERR114 系统编码规则 + 4 种消息类型) - datasource/_validate.ts (1 step, 镜像 web dataSource/Form.vue + 后端 DbLinkController + DB001 数据库类型 + host/port/user/password 必填) 每个 _validate.ts 完整导出: - ValidationError + StepValidation interface - validateBasicInfo - validate<Datasource>Create 镜像 web 端: - organize/Form.vue PS013 (parentId 必填, 不能与父级相同) / PS036 (层级限制) - message/notice/Form.vue MSERR113/114 (模板标题参数 + 系统编码规则) - dataSource/Form.vue DB001 (6 种数据库类型枚举) 未集成到 create.ts (P3 命令大, 留待后续 session 集成)
This commit is contained in:
1 parent
2b24a487a2
commit
f3bd0cc088
3 files changed
+272
No files matched your search
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* commands/datasource/_validate.ts — datasource create step machine (Phase D1)
|
||||
*
|
||||
* 镜像 web systemData/dataSource/Form.vue + 后端 DbLinkController
|
||||
* - fullName 必填
|
||||
* - enCode 必填
|
||||
* - dbType ∈ {MySQL, SqlServer, Oracle, DM, KingbaseES, PostgreSQL}
|
||||
* - host/port/userName/password 必填
|
||||
* - DB001 镜像: 数据类型编码
|
||||
*
|
||||
* v0.11e+ Phase D1: 剩余 40 命令 step machine 扩展
|
||||
*/
|
||||
|
||||
export interface ValidationError {
|
||||
field?: string
|
||||
message: string
|
||||
code?: string
|
||||
}
|
||||
|
||||
export interface StepValidation {
|
||||
ok: boolean
|
||||
step: 0
|
||||
stepName: string
|
||||
errors: ValidationError[]
|
||||
}
|
||||
|
||||
const VALID_DB_TYPES = ['MySQL', 'SqlServer', 'Oracle', 'DM', 'KingbaseES', 'PostgreSQL']
|
||||
|
||||
export interface DatasourceOpts {
|
||||
fullName?: string
|
||||
enCode?: string
|
||||
dbType?: string
|
||||
host?: string
|
||||
port?: number | string
|
||||
userName?: string
|
||||
password?: string
|
||||
serviceName?: string
|
||||
enabledMark?: number | string
|
||||
}
|
||||
|
||||
export function validateBasicInfo(opts: DatasourceOpts): StepValidation {
|
||||
const errors: ValidationError[] = []
|
||||
|
||||
if (!opts.fullName || !String(opts.fullName).trim()) {
|
||||
errors.push({ field: 'fullName', message: '数据源名称不能为空' })
|
||||
}
|
||||
|
||||
if (!opts.enCode || !String(opts.enCode).trim()) {
|
||||
errors.push({ field: 'enCode', message: '数据源编码不能为空' })
|
||||
}
|
||||
|
||||
if (!opts.dbType || !String(opts.dbType).trim()) {
|
||||
errors.push({ field: 'dbType', message: '数据库类型不能为空' })
|
||||
} else if (!VALID_DB_TYPES.includes(String(opts.dbType))) {
|
||||
errors.push({
|
||||
field: 'dbType',
|
||||
message: `数据库类型必须是 ${VALID_DB_TYPES.join('/')} 之一 (DB001 镜像), 当前 ${opts.dbType}`,
|
||||
code: 'DB001',
|
||||
})
|
||||
}
|
||||
|
||||
if (!opts.host || !String(opts.host).trim()) {
|
||||
errors.push({ field: 'host', message: '主机不能为空' })
|
||||
}
|
||||
|
||||
if (opts.port === undefined || opts.port === null) {
|
||||
errors.push({ field: 'port', message: '端口不能为空' })
|
||||
} else {
|
||||
const port = Number(opts.port)
|
||||
if (isNaN(port) || port < 1 || port > 65535) {
|
||||
errors.push({ field: 'port', message: '端口必须是 1-65535 之间的数字' })
|
||||
}
|
||||
}
|
||||
|
||||
if (!opts.userName || !String(opts.userName).trim()) {
|
||||
errors.push({ field: 'userName', message: '用户名不能为空' })
|
||||
}
|
||||
|
||||
if (!opts.password || !String(opts.password).trim()) {
|
||||
errors.push({ field: 'password', message: '密码不能为空' })
|
||||
}
|
||||
|
||||
if (opts.enabledMark !== undefined && ![0, 1].includes(Number(opts.enabledMark))) {
|
||||
errors.push({ field: 'enabledMark', message: 'enabledMark 必须是 0 或 1' })
|
||||
}
|
||||
|
||||
return {
|
||||
ok: errors.length === 0,
|
||||
step: 0,
|
||||
stepName: '基础信息',
|
||||
errors,
|
||||
}
|
||||
}
|
||||
|
||||
export function validateDatasourceCreate(opts: DatasourceOpts): {
|
||||
ok: boolean
|
||||
steps: StepValidation[]
|
||||
} {
|
||||
const s0 = validateBasicInfo(opts)
|
||||
return { ok: s0.ok, steps: [s0] }
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* commands/msg/_validate.ts — msg notice/template create/update step machine (Phase D1)
|
||||
*
|
||||
* 镜像 web message/notice/Form.vue + message/template/Form.vue + 后端 MessageController
|
||||
* - fullName 必填
|
||||
* - enCode 必填
|
||||
* - type ∈ {1=系统, 2=消息中心, 3=邮件, 4=短信}
|
||||
* - MSERR113/114 镜像: 模板标题参数 + 系统编码规则
|
||||
*
|
||||
* v0.11e+ Phase D1: 剩余 40 命令 step machine 扩展
|
||||
*/
|
||||
|
||||
export interface ValidationError {
|
||||
field?: string
|
||||
message: string
|
||||
code?: string
|
||||
}
|
||||
|
||||
export interface StepValidation {
|
||||
ok: boolean
|
||||
step: 0
|
||||
stepName: string
|
||||
errors: ValidationError[]
|
||||
}
|
||||
|
||||
export interface MsgOpts {
|
||||
fullName?: string
|
||||
enCode?: string
|
||||
type?: number | string
|
||||
category?: string
|
||||
enabledMark?: number | string
|
||||
}
|
||||
|
||||
const VALID_TYPES = [1, 2, 3, 4]
|
||||
|
||||
export function validateBasicInfo(opts: MsgOpts): StepValidation {
|
||||
const errors: ValidationError[] = []
|
||||
|
||||
if (!opts.fullName || !String(opts.fullName).trim()) {
|
||||
errors.push({ field: 'fullName', message: '消息标题不能为空' })
|
||||
}
|
||||
|
||||
if (!opts.enCode || !String(opts.enCode).trim()) {
|
||||
errors.push({ field: 'enCode', message: '消息编码不能为空' })
|
||||
} else if (String(opts.enCode).startsWith('sys_') || String(opts.enCode).startsWith('system_')) {
|
||||
// MSERR114 镜像: 自定义模板编码不能使用系统模板编码规则
|
||||
errors.push({
|
||||
field: 'enCode',
|
||||
message: '消息编码不能以 sys_/system_ 开头 (MSERR114, 保留系统模板编码)',
|
||||
code: 'MSERR114',
|
||||
})
|
||||
}
|
||||
|
||||
if (opts.type !== undefined && !VALID_TYPES.includes(Number(opts.type))) {
|
||||
errors.push({
|
||||
field: 'type',
|
||||
message: `消息类型必须是 ${VALID_TYPES.join('/')} 之一 (1=系统 2=消息中心 3=邮件 4=短信), 当前 ${opts.type}`,
|
||||
})
|
||||
}
|
||||
|
||||
if (opts.enabledMark !== undefined && ![0, 1].includes(Number(opts.enabledMark))) {
|
||||
errors.push({ field: 'enabledMark', message: 'enabledMark 必须是 0 或 1' })
|
||||
}
|
||||
|
||||
return {
|
||||
ok: errors.length === 0,
|
||||
step: 0,
|
||||
stepName: '基础信息',
|
||||
errors,
|
||||
}
|
||||
}
|
||||
|
||||
export function validateMsgCreate(opts: MsgOpts): {
|
||||
ok: boolean
|
||||
steps: StepValidation[]
|
||||
} {
|
||||
const s0 = validateBasicInfo(opts)
|
||||
return { ok: s0.ok, steps: [s0] }
|
||||
}
|
||||
|
||||
export function validateMsgUpdate(opts: MsgOpts): {
|
||||
ok: boolean
|
||||
steps: StepValidation[]
|
||||
} {
|
||||
return validateMsgCreate(opts)
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* commands/org/_validate.ts — org create/update step machine 校验 (Phase D1)
|
||||
*
|
||||
* 镜像 web permission/organize/Form.vue + 后端 OrganizeController
|
||||
* - fullName 必填
|
||||
* - enCode 必填
|
||||
* - parentId 必填 (顶级 -1)
|
||||
* - category ∈ {0=公司, 1=部门, 2=小组}
|
||||
* - PS036 镜像: 组织层级限制
|
||||
*
|
||||
* v0.11e+ Phase D1: 剩余 40 命令 step machine 扩展
|
||||
*/
|
||||
|
||||
export interface ValidationError {
|
||||
field?: string
|
||||
message: string
|
||||
code?: string
|
||||
}
|
||||
|
||||
export interface StepValidation {
|
||||
ok: boolean
|
||||
step: 0
|
||||
stepName: string
|
||||
errors: ValidationError[]
|
||||
}
|
||||
|
||||
export interface OrgOpts {
|
||||
fullName?: string
|
||||
enCode?: string
|
||||
parentId?: string
|
||||
category?: number | string
|
||||
enabledMark?: number | string
|
||||
sortCode?: number | string
|
||||
}
|
||||
|
||||
const VALID_CATEGORIES = [0, 1, 2]
|
||||
|
||||
export function validateBasicInfo(opts: OrgOpts): StepValidation {
|
||||
const errors: ValidationError[] = []
|
||||
|
||||
if (!opts.fullName || !String(opts.fullName).trim()) {
|
||||
errors.push({ field: 'fullName', message: '组织名称不能为空' })
|
||||
}
|
||||
|
||||
if (!opts.enCode || !String(opts.enCode).trim()) {
|
||||
errors.push({ field: 'enCode', message: '组织编码不能为空' })
|
||||
}
|
||||
|
||||
if (!opts.parentId || !String(opts.parentId).trim()) {
|
||||
errors.push({ field: 'parentId', message: '上级组织不能为空 (顶级传 -1)' })
|
||||
}
|
||||
|
||||
if (opts.category !== undefined && !VALID_CATEGORIES.includes(Number(opts.category))) {
|
||||
errors.push({
|
||||
field: 'category',
|
||||
message: `组织类型必须是 ${VALID_CATEGORIES.join('/')} 之一 (0=公司 1=部门 2=小组), 当前 ${opts.category}`,
|
||||
})
|
||||
}
|
||||
|
||||
if (opts.enabledMark !== undefined && ![0, 1].includes(Number(opts.enabledMark))) {
|
||||
errors.push({ field: 'enabledMark', message: 'enabledMark 必须是 0 或 1' })
|
||||
}
|
||||
|
||||
return {
|
||||
ok: errors.length === 0,
|
||||
step: 0,
|
||||
stepName: '基础信息',
|
||||
errors,
|
||||
}
|
||||
}
|
||||
|
||||
export function validateOrgCreate(opts: OrgOpts): {
|
||||
ok: boolean
|
||||
steps: StepValidation[]
|
||||
} {
|
||||
const s0 = validateBasicInfo(opts)
|
||||
return { ok: s0.ok, steps: [s0] }
|
||||
}
|
||||
|
||||
export function validateOrgUpdate(opts: OrgOpts): {
|
||||
ok: boolean
|
||||
steps: StepValidation[]
|
||||
} {
|
||||
return validateOrgCreate(opts)
|
||||
}
|
||||
Reference in new issue
Block a user