12 KiB
12 KiB
stringtemplate4
设置 $
STGroup group = new STGroupString("db_template",template, '$', '$');
模版的定义
基础
classTemplate(item, module, operationList, className) ::= <<
>>
注意 <<内容>> 定义的方法
classTemplate 为 group.getInstanceOf("classTemplate"); 定义
例子:
classTemplate(item, module, operationList, className) ::= <<
package $module.packageName$;
/**
* @author xia
* @date 2026/1/10
* @version 0.0.1
*/
public class $className$ {
}
>>
映射字典
// 定义一个映射字典
requestAnnotations ::= [
"POST": "@PostMapping",
"GET": "@GetMapping",
"PUT": "@PutMapping",
"DELETE": "@DeleteMapping",
default: "@RequestMapping"
]
Controller
requestAnnotations ::= [
"POST": "@PostMapping",
"GET": "@GetMapping",
"PUT": "@PutMapping",
"DELETE": "@DeleteMapping",
default: "@RequestMapping"
]
classTemplate(module,item,operationList,basics) ::= <<
package $module.packageName$.controller;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* $item.itemName$ 控制器
* @author xia
*/
@Tag(name = "$item.itemName$")
@RequiredArgsConstructor
@RestController
@RequestMapping("/$item.itemCode$")
public class $basics.itemCodeUp$Controller {
private final $basics.itemCodeUp$Service $item.itemCode$Service;
$operationList:{op |
@OperLog
@SecureAudit(id = $op.id$,$if(op.isGreenLight)$isGreenLight = true,$endif$ $if(!item.isTenant)$isTenant = false,$endif$
funType = FunTypeEnum.$op.funType$, funName = "$op.funName$", funCode = "$module.moduleCode$:$item.itemCode$:$op.operationCode$")
@Operation(summary = "$op.funName$", description = "$op.describe$")
$requestAnnotations.(op.requestType)$("$op.url$$op.pathParamsUrl$")
public XResult<$if(op.isPage)$Page<$basics.itemCodeUp$$op.methodNamePascalCase$Res>$else$$if(op.isResParams)$$basics.itemCodeUp$$op.methodNamePascalCase$Res$else$Void$endif$$endif$> $op.methodName$($if(op.isReqParams)$@RequestBody @Valid $basics.itemCodeUp$$op.methodNamePascalCase$Req req$endif$$op.pathParamsLong$) {
return $item.itemCode$Service.$op.methodName$($if(op.isPathParams)$$op.pathParams$$endif$$if(op.isReqParams)$req$endif$);
\}
}$
}
>>
请求参数
classTemplate(module,item,operationList,basics) ::= <<
package $module.apiPackageName$.request.$item.itemCode$;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import java.io.Serial;
import java.io.Serializable;
/**
* $item.itemName$
* $basics.oper.funName$ 请求参数
* @author xia
*/
@Getter
@Setter
@Schema(description = "$basics.oper.funName$ 参数")
public class $basics.itemCodeUp$Req $if(basics.oper.isPage)$extends XhPage$endif$ implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
}
>>
响应参数
classTemplate(module,item,operationList,basics) ::= <<
package $module.apiPackageName$.response.$item.itemCode$;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import java.io.Serial;
import java.io.Serializable;
/**
* $item.itemName$
* $basics.oper.funName$ 响应
* @author xia
*/
@Getter
@Setter
@Schema(description = "$basics.oper.funName$ 响应")
public class $basics.itemCodeUp$Res implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
}
>>
服务接口
classTemplate(module,item,operationList,basics) ::= <<
package $module.packageName$.service;
/**
* $item.itemName$ 服务层接口
* @author xia
*/
public interface $basics.itemCodeUp$Service {
$operationList:{op |
/**
* $op.funName$
* $op.describe$
*/
XResult<$if(op.isPage)$Page<$basics.itemCodeUp$$op.methodNamePascalCase$Res>$else$$if(op.isResParams)$$basics.itemCodeUp$$op.methodNamePascalCase$Res$else$Void$endif$$endif$> $op.methodName$($if(op.isReqParams)$$basics.itemCodeUp$$op.methodNamePascalCase$Req req$endif$$if(op.isPathParams)$$op.pathParamsLongReq$$endif$);
}$
}
>>
服务接口实现
classTemplate(module,item,operationList,basics) ::= <<
package $module.packageName$.service.impl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import $module.packageName$.service.$basics.itemCodeUp$Service;
/**
* $item.itemName$ 服务层接口
* @author xia
*/
@Service
@RequiredArgsConstructor
public class $basics.itemCodeUp$ServiceImpl implements $basics.itemCodeUp$Service{
$operationList:{op |
/**
* $op.funName$
* $op.describe$
*/
@Override
public XResult<$if(op.isPage)$Page<$basics.itemCodeUp$$op.methodNamePascalCase$Res>$else$$if(op.isResParams)$$basics.itemCodeUp$$op.methodNamePascalCase$Res$else$Void$endif$$endif$> $op.methodName$($if(op.isReqParams)$$basics.itemCodeUp$$op.methodNamePascalCase$Req req$endif$$if(op.isPathParams)$$op.pathParamsLongReq$$endif$){
// TODO $op.funName$ 实现
return null;
\}
}$
}
>>
模块数据
group dbXml;
moduleTemplate(module) ::= <<
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd">
<changeSet id="insert-ms-fun-module-data" author="xinghe">
<comment>初始化模块数据</comment>
$module:{op |
<insert tableName="ms_fun_module">
<column name="id" value="$op.id$"/>
<column name="module_code" value="$op.moduleCode$"/>
<column name="module_name" value="$op.moduleName$"/>
<column name="remark" value="$op.describe$"/>
</insert>
}$
</changeSet>
</databaseChangeLog>
>>
itemTemplate(item) ::= <<
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd">
<changeSet id="insert-ms-fun-item-data" author="xinghe">
<comment>初始化功能数据</comment>
$item:{op |
<insert tableName="ms_fun_item">
<column name="id" value="$op.id$"/>
<column name="module_id" value="$op.moduleId$"/>
<column name="item_code" value="$op.itemCode$"/>
<column name="item_name" value="$op.itemName$"/>
<column name="is_tenant" value="$op.isTenant$"/>
<column name="remark" value="$op.describe$"/>
</insert>
}$
</changeSet>
</databaseChangeLog>
>>
funTypeAnnotations ::= [
"ADD": "0",
"DELETE": "1",
"EDIT": "2",
"QUERY": "3",
"UPLOAD": "4",
"DOWNLOAD": "5",
"IMPORT": "6",
"EXPORT": "7",
"PRINT": "8",
"REGISTER": "9",
"LOGIN": "10",
"LOGOUT": "11",
"SMS": "12",
"EMAIL": "13",
"WECHAT": "14",
"OTHER": "99"
default: "-1"
]
operationTemplate(operation) ::= <<
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd">
<changeSet id="insert-ms-fun-operation-data" author="xinghe">
<comment>初始化操作数据</comment>
$operation:{op |
<insert tableName="ms_fun_operation">
<column name="id" value="$op.id$"/>
<column name="module_id" value="$op.moduleId$"/>
<column name="item_id" value="$op.itemId$"/>
<column name="is_green_light" value="$op.isGreenLight$"/>
<column name="fun_code" value="$op.moduleCode$:$op.itemCode$:$op.operationCode$"/>
<column name="fun_name" value="$op.funName$"/>
<column name="fun_type" value="$funTypeAnnotations.(op.funType)$"/>
<column name="usable_config" value="$op.usableConfigJson$"/>
<column name="field_config" value="$op.fieldConfigJson$"/>
<column name="sort_order" value="$op.sortOrder$"/>
<column name="remark" value="$op.describe$"/>
</insert>
}$
</changeSet>
</databaseChangeLog>
>>
角色套餐
初始化数据
group dbXml;
roleBindFunTemplate(operations,clientTypeCode,clientTypeDesc) ::= <<
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd">
<changeSet id="insert-ms-user-role-fun-data" author="xinghe">
<comment>初始化平台角色权限数据($clientTypeDesc$)</comment>
$operations:{op |
<!-- $op.funName$ -->
<insert tableName="ms_user_role_fun">
<column name="id" value="$op.id$$clientTypeCode$100"/>
<column name="role_id" value="100"/>
<column name="fun_id" value="$op.id$"/>
<column name="client_type" value="$clientTypeCode$"/>
<column name="data_scope" value="0"/>
<column name="assign_data_scope" value="[]"/>
<column name="exclude_field" value="[]"/>
<column name="update_by_id" value="10086"/>
<column name="update_time" value="2025-01-01 00:00:00"/>
</insert>
}$
</changeSet>
</databaseChangeLog>
>>
mealBindFunTemplate(meals,clientTypeCode,clientTypeDesc) ::= <<
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd">
<changeSet id="insert-ms-tenant-meal-bind-fun-data" author="xinghe">
<comment>初始化模块数据($clientTypeDesc$)</comment>
$meals:{op |
<!-- $op.funName$ -->
<insert tableName="ms_tenant_meal_bind_fun">
<column name="id" value="$op.id$$clientTypeCode$200"/>
<column name="meal_id" value="200"/>
<column name="fun_id" value="$op.id$"/>
<column name="client_type" value="$clientTypeCode$"/>
</insert>
}$
</changeSet>
</databaseChangeLog>
>>
菜单数据
菜单数据生成
menuTypeAnnotations ::= [
"MENU_ID": "0",
"BUTTON_ID": "1"
]
clientTypeAnnotations ::= [
"PC": "0",
"MINI_PROGRAM": "1",
"H5": "2"
]
menuTemplate(menus) ::= <<
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.24.xsd">
<changeSet id="insert-ms-menu-data" author="xinghe">
<comment>初始化菜单数据</comment>
$menus:{op |
<insert tableName="ms_menu">
<column name="id" value="$op.id$"/>
<column name="parent_id" value="$op.parentId$"/>
<column name="fun_id" value="$if(op.funId)$$op.funId$$else$null$endif$"/>
<column name="menu_name" value="$op.menuName$"/>
<column name="menu_type" value="$menuTypeAnnotations.(op.menuType)$"/>
<column name="client_type" value="$clientTypeAnnotations.(op.clientType)$"/>
<column name="route_path" value="$op.path$"/>
<column name="page_path" value="$op.pagePath$"/>
<column name="icon" value="$op.icon$"/>
<column name="is_tenant" value="$op.isTenant$"/>
<column name="is_hide" value="$op.isHide$"/>
<column name="sort_order" value="$op.sortOrder$"/>
</insert>
}$
</changeSet>
</databaseChangeLog>
>>