# Plugin Development Development
Plugins are an extension method opened by the platform itself. Through plugins, new functionalities can be added to the platform, or existing functionalities can be modified.
# Plugin Usage
Plugins are files ending with .myp
, which can be uploaded and enabled through the platform's plugin management interface.
# Plugin Runtime Description
- The same set of plugins can have different versions in the platform, and only one version of a plugin can be enabled at the same time.
- Enabling and disabling plugins take effect in real-time, without the need to restart the platform.
- All enabled plugins in the platform share the same runtime environment, and plugins can directly call each other. At the same time, the platform also provides some APIs for plugins to call platform functions.
# Plugin Development
# Target Audience
This document is mainly intended for advanced developers who wish to understand how to develop plugins for the Muyan development platform.
# Prerequisites
Readers need to have some understanding of gradle. Here are some related reference materials:
# Creating a Plugin
- Create a project based on the platform (opens new window) template.
- The plugin directory is located in
server
. Modify thebuild.gradle
configuration file in the plugin directory to replace information such as the plugin's name, version, and dependencies on other plugins.version "0.0.1" group "tech.muyan.plugin"
1
2 - Add your third-party dependencies through
build.gradle
and start writing your business logic.
# Data Binding
In the plugin source code, you can define data models that can bind to the platform's built-in DomainClass. You only need to ensure that the POJO class of the data model has the same name as the DomainClass and implements the tech.muyan.api.DynamicDomainEntity
interface.
Below are some specific examples for reference.
First, we define the CSV files for DomainClass and DomainClassField:
# DomainClass
shortName(*),extInfo
SampleDynamicOrderDomain,
2
3
# DomainClassField
domainClass.shortName(*),name(*),dataType,referenceDomain.shortName,nullable,editable,defaultValue,options,extInfo
SampleDynamicOrderDomain,orderId,STRING,,Y,Y,,,
SampleDynamicOrderDomain,isActive,BOOLEAN,,N,N,,,
SampleDynamicOrderDomain,totalAmount,BIG_DECIMAL,,Y,N,,,
SampleDynamicOrderDomain,quantity,INTEGER,,N,Y,,,
SampleDynamicOrderDomain,productId,LONG,,Y,Y,,"[1,2,3]",
SampleDynamicOrderDomain,discountRate,DOUBLE,,Y,Y,,,
SampleDynamicOrderDomain,orderDate,LOCAL_DATE,,Y,Y,,,
SampleDynamicOrderDomain,deliveryDateTime,ZONED_DATETIME,,Y,Y,,,
SampleDynamicOrderDomain,additionalInfo,JSON_STRING,,Y,Y,,,
SampleDynamicOrderDomain,buyerTask,DOMAIN_OBJECT,SampleTask,Y,Y,,,
SampleDynamicOrderDomain,sellerTasks,DOMAIN_OBJECT_LIST,SampleTask,Y,Y,,,
2
3
4
5
6
7
8
9
10
11
12
13
Next, we can define our POJO class:
package tech.muyan.plugin
import tech.muyan.api.DynamicDomainEntity
import java.time.LocalDate
import java.time.ZonedDateTime
class SampleDynamicOrderDomain implements DynamicDomainEntity {
Long id
String orderId
Boolean isActive
BigDecimal totalAmount
Integer quantity
Long productId
Double discountRate
LocalDate orderDate
ZonedDateTime deliveryDateTime
String additionalInfo
// SimpleTask is another defined POJO class. This is just an example, and its definition is not provided here.
// If the SimpleTask class is not defined, you can use Object instead. The same applies to sellerTasks below.
SimpleTask buyerTask
List<SampleTask> sellerTasks
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Using Data Model Binding
Refer to the SimpleQuery
utility class in the Platform API to operate data through data model binding. For example:
SampleDynamicOrderDomain domain = SimpleQuery
.of(SampleDynamicOrderDomain.class)
.eq("orderId", "123456")
.get()
2
3
4
Or convert the queried data into a POJO object:
SampleDynamicOrderDomain domain = SimpleQuery
.of("SampleDynamicOrderDomain")
.eq("orderId", "123456")
.get() as SampleDynamicOrderDomain
2
3
4
# Plugin Packaging
After development is complete, execute the gradle buildMuyanPlugin
task to package the plugin.
All third-party dependency packages in this project will be included in the plugin. Note that
third-party dependencies marked as compileOnly
will not be included during packaging.