系统所有的表结构统一保存到User包下。
正确示例:
Class User.CBSample Extends (%Persistent, %XML.Adaptor, src.util.DynamicObject.Adapter) [ ClassType = persistent, Inheritance = right, Not ProcedureBlock, SqlRowIdName = ID, SqlTableName = CB_Sample ]
错误示例:
Class src.CBSample Extends %Persistent
Class User.Sample Extends %Persistent
表名必须使用标准前缀,用于标识表的类型:
| 前缀 | 用途 | 示例 |
|---|---|---|
| CB | 系统级字典表 | CBOrganization, CBSex |
| HB | 医院级字典表 | HBDrugDictionary, HBLoc |
| BS | 业务表 | BSOrderPresc, BSDecoctDispRecord |
Class User.CBSample Extends (%Persistent, %XML.Adaptor, src.util.DynamicObject.Adapter) [ ClassType = persistent, Inheritance = right, Not ProcedureBlock, SqlRowIdName = ID, SqlTableName = CB_Sample ]
{
/// 逻辑删除标记
/// 0: 正常
/// 1: 已删除
Property Deleted As %Integer [ Required, InitialExpression = 0 ];
/// 删除日期
Property DeleteDate As %Date;
/// 删除时间
Property DeleteTime As %Time;
}
ClassType = persistent - 标识为持久化类SqlTableName = 表名 - 指定SQL表名src.util.DynamicObject.Adapter所有CB前缀的基础表必须包含以下字段:
/// 代码(主键,字符串类型)
Property Code As %String(MAXLEN = 100) [ Required ];
/// 描述
Property Descripts As %String(MAXLEN = 255) [ Required ];
/// 英文描述
Property ENDescripts As %String(MAXLEN = 255);
/// 开始日期
Property StartDate As %Date [ InitialExpression = {$zdateh($horolog, 5)} ];
/// 结束日期
Property StopDate As %Date;
/// 创建日期
Property CreateDate As %Date [ InitialExpression = {$zdateh($horolog, 5)} ];
/// 创建用户(外键)
Property CreateUserDr As User.HBUser [ SqlColumnNumber = 9 ];
| 字段名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| Code | %String | 是 | 主键,建议MAXLEN = 100 |
| Descripts | %String | 是 | 中文描述,建议MAXLEN = 255 |
| ENDescripts | %String | 否 | 英文描述,建议MAXLEN = 255 |
| StartDate | %Date | 是 | 开始日期,默认当前日期 |
| StopDate | %Date | 否 | 结束日期 |
| CreateDate | %Date | 是 | 创建日期,默认当前日期 |
| CreateUserDr | User.HBUser | 是 | 创建用户,外键指向User.User表 |
所有外键字段必须使用Dr后缀。
{关联表}Dr
/// 机构外键
Property OrganizationDr as User.CBOrganization;
/// 用户外键
Property CreateUserDr as User.HBUser;
/// 部门外键
Property DepartmentDr as User.CBDpartment;
/// 订单外键
Property OrderDr as User.BSOrder;
Dr结尾| ObjectScript类型 | SQL类型 | 用途 |
|---|---|---|
| %String | VARCHAR | 字符串 |
| %Integer | INTEGER | 整数 |
| %Numeric | NUMERIC | 数字 |
| %Date | DATE | 日期 |
| %Time | TIMESTAMP | 时间 |
| %Boolean | BIT | 布尔值 |
%String类型%Numeric类型%Integer类型%Date类型%Time类型Index CodeIndex On Code As Exact [ PrimaryKey ];
Index OrganizationDrIndex On OrganizationDr As Exact;
Index StartDateIndex On StartDate As Exact;
Index DeletedIndex On Deleted As Exact;
Class User.CBOrganization Extends src.util.DynamicObject.Adapter
{
ClassType = persistent;
SqlTableName = CBOrganization;
/// 代码(主键)
Property Code As %String(MAXLEN = 50) [ Required ];
/// 描述
Property Descripts As %String(MAXLEN = 255) [ Required ];
/// 英文描述
Property ENDescripts As %String(MAXLEN = 255);
/// 开始日期
Property StartDate As %Date [ InitialExpression = {$zdateh($horolog, 5)} ];
/// 结束日期
Property StopDate As %Date;
/// 创建日期
Property CreateDate As %Date [ InitialExpression = {$zdateh($horolog, 5)} ];
/// 创建用户
Property CreateUserDr As User.HBUser [ SqlColumnNumber = 9 ];
/// 删除标记
Property Deleted As %Integer [ Required, InitialExpression = 0 ];
/// 删除日期
Property DeleteDate As %Date;
/// 删除时间
Property DeleteTime As %Time;
/// 上级机构外键
Property ParentDr As CBOrganization;
Index CodeIndex On Code [ PrimaryKey ] As Exact;
Index CreateUserDrIndex On CreateUserDr As Exact;
Index DeletedIndex On Deleted As Exact;
}
❌ 错误1:表未保存到User包
Class src.CBOrganization Extends src.util.DynamicObject.Adapter
✅ 正确:
Class User.CBOrganization Extends src.util.DynamicObject.Adapter
❌ 错误2:缺少必填字段
Class User.CBSample Extends src.util.DynamicObject.Adapter
{
Property Code As %String [ Required ];
Property Descripts As %String [ Required ];
}
✅ 正确:包含所有CB必填字段
❌ 错误3:外键未使用Dr后缀
Property Organization As User.CBOrganization;
✅ 正确:
Property OrganizationDr As User.CBOrganization;
❌ 错误4:日期事件字段未拆分
Property CreateTime As %TimeStamp;
✅ 正确:
Property CreateDate As %Date;
Property CreateTime As %Time;