# Dynamic Domain Model

This system is based on a self-developed ORM framework using JDBC, allowing dynamic creation and modification of domain model definitions through the interface.

# Target Audience

This document is intended for implementation and development personnel of this system.

The following describes development notes for domain model support-related functions, including:

  • Domain model field property settings
  • Domain model extended metadata configuration

For a quick guide on creating and using a domain model, refer to this video:

# Domain Model Field Properties

When creating a domain model, you need to provide the model's abbreviated name, field property list, and extended metadata.

TIP

The system automatically generates the full name, database table name for storage, and display name based on the user-entered abbreviated name. This information cannot be modified after creation.

# Domain Model Field Property Settings

# Field Property Settings

Field Name Description
Name The field's name, used for code reference. Must be unique within the same domain model.
DataType The field's data type. See detailed types below.
Reference Domain For DOMAIN_OBJECT or DOMAIN_OBJECT_LIST data types, this associates with domain model objects.
Nullable Indicates if the field can be null.
Editable Indicates if the field can be edited after creation.
Default Value The field's default value.
Options List of optional values for the field, in JSON array format, e.g., ["option1", "option2"].
Ext Info Additional configuration information. May vary for different data types.

# Detailed Data Type Description

# Field Data Types

Supported field data types include:

Data Type Description
STRING Represents a string
BOOLEAN Represents a boolean value (true or false)
BIG_DECIMAL Represents an immutable, high-precision decimal number
INTEGER Represents an integer value
LONG Represents a long integer value
DOUBLE Represents a double-precision floating-point number
LOCAL_DATE Represents a date without time and timezone information
ZONED_DATETIME Represents a date and time with timezone information
JSON_STRING Represents a JSON string
DOMAIN_OBJECT Represents a reference to a domain object
DOMAIN_OBJECT_LIST Represents a list of domain objects
FILE Attachment type
FILE_LIST Multiple attachments
ENUM Enum type

# Extended Information (Ext Info) Field

Different data types may have different extended information configurations. For BIG_DECIMAL fields, you can configure scale and precision information in JSON format:

{
  // 适用于 Decimal 类型的字段,设置小数位数为 2
  // Applicable to Decimal type fields, set the number of decimal places to 2
  "scale": 2,
  // 适用于 Decimal 类型的字段,设置精度为 10
  // Applicable to Decimal type fields, set the precision to 10
  "precision": 10
  // 指定 ENUM 类型的字段的 Java 枚举类型定义
  // Specify the Java enum type definition of the ENUM type field
  // 该枚举类的定义可以放在动态插件中
  // The enum class definition can be in a dynamic plugin
  "enumClass": "tech.muyan.mes.enums.WorkTaskStatusEnum"
}
1
2
3
4
5
6
7
8
9
10
11
12

Here, scale represents the number of decimal places, and precision represents the total number of significant digits (integer digits + decimal places).

# Domain Model Metadata

Configure domain model extended metadata in extInfo:

  1. Use the static labelField property in Domain to specify which object attribute should be displayed as an identifier on the frontend object control.

  2. Use the static inlineSearchColumns property in Domain to specify which attributes to search when quickly searching for objects in the frontend object input control.

  3. Use the static loadAfter property in Domain to specify which object types this object type should be imported after when importing seed data. For details, see Import Order and Dependencies.

Example:

{
  // 用户快捷搜索时,使用 name 和 label 两个字段进行搜索匹配
  // When users perform quick search, use the name and label fields for search matching
  "inlineSearchColumns": ['name', 'label'],
  // 界面上显示 Object 控件时,显示其 label 字段的值作为标识
  // When displaying Object controls on the interface, show the value of its label field as identifier
  "labelField": 'label',
  // 导入 CSV 数据时,当前 Domain 会在 DynamicLogic 和 DynamicFieldDefinition 之后加载
  // When importing CSV data, the current Domain will be loaded after DynamicLogic and DynamicFieldDefinition
  "loadAfter": ['DynamicLogic', 'DynamicFieldDefinition'],
}
1
2
3
4
5
6
7
8
9
10

# Domain Design Conventions

# extInfo Convention

Use the extInfo field to store structurally complex, heterogeneous, or Domain subtype-specific information that requires structured storage.

Sample definition:

// 如下是在平台中实际实现的 extInfo 字段的样例
// Example of the extInfo field actually implemented in the platform
class DynamicFormField implements MultiTenant<DynamicFormField>,
  Auditable, Stampable<DynamicFormField>, Serializable {
  // ....
  // Java 的字段类型为 String
  // The Java field type is String
  String extInfo
  // 设置为可以为 null, 但是不能为空字符
  // Set to be nullable, but not blank
  static constraints = {
    extInfo nullable: true, blank: false
  }
  static mapping = {
    // 使用 jsonb 类型的数据库字段,数据库会自动增加相关校验,并提供 JSON 查询相关功能
    // 在转换为 Java 对象时,会被转换为 String 类型
    // Use jsonb field, the database will automatically add relevant checks and provide JSON query related functions
    // When converted to a Java object, it will be converted to a String type
    extInfo type: 'tech.muyan.rdbms.postgres.JSONBType', sqlType: "jsonb", defaultValue: "'{ }'"
  }
  // ....
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# displaySequence Convention

Use the displaySequence field to specify the frontend display order of fields, field groups, tree nodes, DynamicActions, etc.

# name / label / description Convention

Domain fields often include an unupdatable name field and an updatable label field.

  1. Use the name field to specify foreign key associations with other objects in CSV files. See Associated Object Query for details on CSV foreign key associations. The name field is typically unupdatable.
  2. Use the label field to display object summaries in the frontend Object display control.
  3. Use the description field to store business descriptions or help information.
  4. Include both name and label fields in the Domain's inlineSearchColumns property.
  5. Set the label field as the Domain's labelField.

# enableLogic Convention

Use enableLogic with DynamicLogic for business judgments to determine execution or display of customizations, DynamicActions, DynamicTasks, etc. Currently supported for:

  1. DynamicTask
  2. DynamicAction
  3. DynamicIntegration
  4. DynamicFormGroup
  5. DynamicDashboardWidget

# objectType/objectId(s) Convention

For scenarios requiring recording of associated object types and IDs in certain Domains, use the objectType/objectId(s) field combination:

  • objectType: Records the object type. This is a foreign key reference to the tech.muyan.DomainClass type object.
  • objectId(s): Records one or more object IDs. For multiple IDs, use a comma-separated list.

System usage examples:

  • tech.muyan.message.Message: objectType and objectIds fields record the associated message object's type and ID.
  • tech.muyan.comment.DomainComment: objectType and objectId fields record the associated comment object's type and ID.
  • tech.muyan.dynamic.hook.DynamicObjectHook: objectType field records the associated custom hook object's type.

# isSystem Convention

Use a boolean isSystem field to identify data essential for system operation that users cannot delete or modify.

The system provides a beforeDelete DynamicLogic named beforeDeleteObjectWithIsSystem. It checks before deleting a Domain object: if isSystem is true, deletion is not allowed.

Last Updated: 9/29/2024, 2:33:14 AM