添加 api 代码生成模板.
This commit is contained in:
@@ -12,8 +12,6 @@ import com.orion.lang.constant.Const;
|
|||||||
import com.orion.lang.utils.ext.yml.YmlExt;
|
import com.orion.lang.utils.ext.yml.YmlExt;
|
||||||
import com.orion.ops.framework.mybatis.core.domain.BaseDO;
|
import com.orion.ops.framework.mybatis.core.domain.BaseDO;
|
||||||
import com.orion.ops.framework.mybatis.core.mapper.IMapper;
|
import com.orion.ops.framework.mybatis.core.mapper.IMapper;
|
||||||
import com.orion.ops.module.infra.enums.RoleStatusEnum;
|
|
||||||
import com.orion.ops.module.infra.enums.UserStatusEnum;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -40,13 +38,10 @@ public class CodeGenerator {
|
|||||||
String module = "infra";
|
String module = "infra";
|
||||||
// 生成的表
|
// 生成的表
|
||||||
GenTable[] tables = {
|
GenTable[] tables = {
|
||||||
new GenTable("system_user", "用户", "user")
|
// new GenTable("system_user", "用户", "user")
|
||||||
.vue("user", "user")
|
// .vue("user", "user")
|
||||||
.enums(UserStatusEnum.class),
|
// .enums(UserStatusEnum.class),
|
||||||
new GenTable("system_role", "角色", "role")
|
new GenTable("favorite", "收藏", "favorite", true),
|
||||||
.vue("user", "role")
|
|
||||||
.enums(RoleStatusEnum.class),
|
|
||||||
// new GenTable("system_menu", "菜单", "menu"),
|
|
||||||
};
|
};
|
||||||
// jdbc 配置 - 使用配置文件
|
// jdbc 配置 - 使用配置文件
|
||||||
File yamlFile = new File("orion-ops-launch/src/main/resources/application-dev.yaml");
|
File yamlFile = new File("orion-ops-launch/src/main/resources/application-dev.yaml");
|
||||||
@@ -127,8 +122,7 @@ public class CodeGenerator {
|
|||||||
* @return config
|
* @return config
|
||||||
*/
|
*/
|
||||||
private static GlobalConfig getGlobalConfig(String outputDir, String author) {
|
private static GlobalConfig getGlobalConfig(String outputDir, String author) {
|
||||||
// 全局配置
|
return new GlobalConfig.Builder()
|
||||||
GlobalConfig gbConfig = new GlobalConfig.Builder()
|
|
||||||
// 设置作者
|
// 设置作者
|
||||||
.author(author)
|
.author(author)
|
||||||
// 生成路径
|
// 生成路径
|
||||||
@@ -141,7 +135,6 @@ public class CodeGenerator {
|
|||||||
.commentDate("yyyy-M-d HH:mm")
|
.commentDate("yyyy-M-d HH:mm")
|
||||||
// 构建
|
// 构建
|
||||||
.build();
|
.build();
|
||||||
return gbConfig;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -153,7 +146,7 @@ public class CodeGenerator {
|
|||||||
* @return 数据源配置
|
* @return 数据源配置
|
||||||
*/
|
*/
|
||||||
private static DataSourceConfig getDataSourceConfig(String url, String username, String password) {
|
private static DataSourceConfig getDataSourceConfig(String url, String username, String password) {
|
||||||
DataSourceConfig dsConfig = new DataSourceConfig.Builder(url, username, password)
|
return new DataSourceConfig.Builder(url, username, password)
|
||||||
// 转换器
|
// 转换器
|
||||||
.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
|
.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
|
||||||
switch (metaInfo.getJdbcType().TYPE_CODE) {
|
switch (metaInfo.getJdbcType().TYPE_CODE) {
|
||||||
@@ -168,7 +161,6 @@ public class CodeGenerator {
|
|||||||
.dbQuery(new MySqlQuery())
|
.dbQuery(new MySqlQuery())
|
||||||
// 构建
|
// 构建
|
||||||
.build();
|
.build();
|
||||||
return dsConfig;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -181,7 +173,8 @@ public class CodeGenerator {
|
|||||||
String[] tableNames = Arrays.stream(tables)
|
String[] tableNames = Arrays.stream(tables)
|
||||||
.map(GenTable::getTableName)
|
.map(GenTable::getTableName)
|
||||||
.toArray(String[]::new);
|
.toArray(String[]::new);
|
||||||
StrategyConfig stConfig = new StrategyConfig.Builder()
|
// 策略配置
|
||||||
|
return new StrategyConfig.Builder()
|
||||||
// 生成的表
|
// 生成的表
|
||||||
.addInclude(tableNames)
|
.addInclude(tableNames)
|
||||||
// 全局大写命名
|
// 全局大写命名
|
||||||
@@ -240,7 +233,6 @@ public class CodeGenerator {
|
|||||||
.formatServiceImplFileName("%sServiceImpl")
|
.formatServiceImplFileName("%sServiceImpl")
|
||||||
// 构建
|
// 构建
|
||||||
.build();
|
.build();
|
||||||
return stConfig;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -250,7 +242,7 @@ public class CodeGenerator {
|
|||||||
* @return 包名配置
|
* @return 包名配置
|
||||||
*/
|
*/
|
||||||
private static PackageConfig getPackageConfig(String module) {
|
private static PackageConfig getPackageConfig(String module) {
|
||||||
PackageConfig pkConfig = new PackageConfig.Builder()
|
return new PackageConfig.Builder()
|
||||||
// 声明父包
|
// 声明父包
|
||||||
.parent("com.orion.ops.module")
|
.parent("com.orion.ops.module")
|
||||||
// 模块名称
|
// 模块名称
|
||||||
@@ -269,7 +261,6 @@ public class CodeGenerator {
|
|||||||
.controller("controller")
|
.controller("controller")
|
||||||
// 构建
|
// 构建
|
||||||
.build();
|
.build();
|
||||||
return pkConfig;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -278,7 +269,7 @@ public class CodeGenerator {
|
|||||||
* @return 模板配置
|
* @return 模板配置
|
||||||
*/
|
*/
|
||||||
private static TemplateConfig getTemplateConfig() {
|
private static TemplateConfig getTemplateConfig() {
|
||||||
TemplateConfig tplConfig = new TemplateConfig.Builder()
|
return new TemplateConfig.Builder()
|
||||||
.controller("/templates/orion-server-controller.java.vm")
|
.controller("/templates/orion-server-controller.java.vm")
|
||||||
.entity("/templates/orion-server-entity-do.java.vm")
|
.entity("/templates/orion-server-entity-do.java.vm")
|
||||||
.service("/templates/orion-server-service.java.vm")
|
.service("/templates/orion-server-service.java.vm")
|
||||||
@@ -286,7 +277,6 @@ public class CodeGenerator {
|
|||||||
.mapper("/templates/orion-server-mapper.java.vm")
|
.mapper("/templates/orion-server-mapper.java.vm")
|
||||||
.xml("/templates/orion-server-mapper.xml.vm")
|
.xml("/templates/orion-server-mapper.xml.vm")
|
||||||
.build();
|
.build();
|
||||||
return tplConfig;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -296,12 +286,11 @@ public class CodeGenerator {
|
|||||||
*/
|
*/
|
||||||
private static InjectionConfig getInjectionConfig() {
|
private static InjectionConfig getInjectionConfig() {
|
||||||
String[][] customFileDefineArr = new String[][]{
|
String[][] customFileDefineArr = new String[][]{
|
||||||
|
// -------------------- 后端 - service --------------------
|
||||||
// http 文件
|
// http 文件
|
||||||
new String[]{"/templates/orion-server-controller.http.vm", "%sController.http", "controller"},
|
new String[]{"/templates/orion-server-controller.http.vm", "%sController.http", "controller"},
|
||||||
// vo 文件
|
// vo 文件
|
||||||
new String[]{"/templates/orion-server-entity-vo.java.vm", "%sVO.java", "entity.vo"},
|
new String[]{"/templates/orion-server-entity-vo.java.vm", "%sVO.java", "entity.vo"},
|
||||||
// dto 文件
|
|
||||||
new String[]{"/templates/orion-server-entity-dto.java.vm", "%sDTO.java", "entity.dto"},
|
|
||||||
// create request 文件
|
// create request 文件
|
||||||
new String[]{"/templates/orion-server-entity-request-create.java.vm", "%sCreateRequest.java", "entity.request.%s"},
|
new String[]{"/templates/orion-server-entity-request-create.java.vm", "%sCreateRequest.java", "entity.request.%s"},
|
||||||
// update request 文件
|
// update request 文件
|
||||||
@@ -310,8 +299,22 @@ public class CodeGenerator {
|
|||||||
new String[]{"/templates/orion-server-entity-request-query.java.vm", "%sQueryRequest.java", "entity.request.%s"},
|
new String[]{"/templates/orion-server-entity-request-query.java.vm", "%sQueryRequest.java", "entity.request.%s"},
|
||||||
// convert 文件
|
// convert 文件
|
||||||
new String[]{"/templates/orion-server-convert.java.vm", "%sConvert.java", "convert"},
|
new String[]{"/templates/orion-server-convert.java.vm", "%sConvert.java", "convert"},
|
||||||
|
// -------------------- 后端 - api --------------------
|
||||||
|
// api 文件
|
||||||
|
new String[]{"/templates/orion-server-api-interface.java.vm", "%sApi.java", "api"},
|
||||||
|
// api impl 文件
|
||||||
|
new String[]{"/templates/orion-server-api-impl.java.vm", "%sApiImpl.java", "api.impl"},
|
||||||
|
// dto 文件
|
||||||
|
new String[]{"/templates/orion-server-api-entity-dto.java.vm", "%sDTO.java", "entity.dto.%s"},
|
||||||
|
// create dto 文件
|
||||||
|
new String[]{"/templates/orion-server-api-entity-dto-create.java.vm", "%sCreateDTO.java", "entity.dto.%s"},
|
||||||
|
// update dto 文件
|
||||||
|
new String[]{"/templates/orion-server-api-entity-dto-update.java.vm", "%sUpdateDTO.java", "entity.dto.%s"},
|
||||||
|
// query dto 文件
|
||||||
|
new String[]{"/templates/orion-server-api-entity-dto-query.java.vm", "%sQueryDTO.java", "entity.dto.%s"},
|
||||||
// convert provider 文件
|
// convert provider 文件
|
||||||
new String[]{"/templates/orion-server-convert-provider.java.vm", "%sProviderConvert.java", "convert"},
|
new String[]{"/templates/orion-server-api-convert.java.vm", "%sApiConvert.java", "convert"},
|
||||||
|
// -------------------- 前端 --------------------
|
||||||
// vue api 文件
|
// vue api 文件
|
||||||
new String[]{"/templates/orion-vue-api.ts.vm", "${feature}.ts", "vue/api/${module}"},
|
new String[]{"/templates/orion-vue-api.ts.vm", "${feature}.ts", "vue/api/${module}"},
|
||||||
// vue router 文件
|
// vue router 文件
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import java.io.OutputStreamWriter;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,7 +54,7 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
public class VelocityTemplateEngine extends AbstractTemplateEngine {
|
public class VelocityTemplateEngine extends AbstractTemplateEngine {
|
||||||
|
|
||||||
private static final String REQUEST_PACKAGE_REPLACER = "request.%s";
|
private static final String[] PACKAGE_REPLACER = new String[]{"request.%s", "dto.%s"};
|
||||||
|
|
||||||
private final Map<String, GenTable> tables;
|
private final Map<String, GenTable> tables;
|
||||||
|
|
||||||
@@ -82,7 +83,7 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
|
|||||||
p.setProperty(Velocity.ENCODING_DEFAULT, ConstVal.UTF8);
|
p.setProperty(Velocity.ENCODING_DEFAULT, ConstVal.UTF8);
|
||||||
p.setProperty(Velocity.INPUT_ENCODING, ConstVal.UTF8);
|
p.setProperty(Velocity.INPUT_ENCODING, ConstVal.UTF8);
|
||||||
p.setProperty("file.resource.loader.unicode", StringPool.TRUE);
|
p.setProperty("file.resource.loader.unicode", StringPool.TRUE);
|
||||||
velocityEngine = new VelocityEngine(p);
|
this.velocityEngine = new VelocityEngine(p);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -95,7 +96,7 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
|
|||||||
BufferedWriter writer = new BufferedWriter(ow)) {
|
BufferedWriter writer = new BufferedWriter(ow)) {
|
||||||
template.merge(new VelocityContext(objectMap), writer);
|
template.merge(new VelocityContext(objectMap), writer);
|
||||||
}
|
}
|
||||||
LOGGER.debug("模板:" + templatePath + "; 文件:" + outputFile);
|
LOGGER.debug("模板: " + templatePath + "; 文件: " + outputFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -109,20 +110,32 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
|
|||||||
* 创建自定义文件副本对象
|
* 创建自定义文件副本对象
|
||||||
*
|
*
|
||||||
* @param originCustomerFile originCustomerFile
|
* @param originCustomerFile originCustomerFile
|
||||||
|
* @param tableInfo tableInfo
|
||||||
* @return backup
|
* @return backup
|
||||||
*/
|
*/
|
||||||
private List<CustomFile> createCustomFilesBackup(@NotNull List<CustomFile> originCustomerFile) {
|
private List<CustomFile> createCustomFilesBackup(@NotNull List<CustomFile> originCustomerFile,
|
||||||
|
@NotNull TableInfo tableInfo) {
|
||||||
// 生成文件副本
|
// 生成文件副本
|
||||||
List<CustomFile> customFiles = originCustomerFile.stream().map(s -> {
|
List<CustomFile> files = originCustomerFile.stream().map(s ->
|
||||||
return new CustomFile.Builder()
|
new CustomFile.Builder()
|
||||||
.enableFileOverride()
|
.enableFileOverride()
|
||||||
.templatePath(s.getTemplatePath())
|
.templatePath(s.getTemplatePath())
|
||||||
.filePath(s.getFilePath())
|
.filePath(s.getFilePath())
|
||||||
.fileName(s.getFileName())
|
.fileName(s.getFileName())
|
||||||
.packageName(s.getPackageName())
|
.packageName(s.getPackageName())
|
||||||
.build();
|
.build())
|
||||||
}).collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
return customFiles;
|
// 获取 table
|
||||||
|
GenTable table = tables.get(tableInfo.getName());
|
||||||
|
// 不生成 api 文件
|
||||||
|
if (!table.isGenApi()) {
|
||||||
|
files.removeIf(file -> this.isServerApiFile(file.getTemplatePath()));
|
||||||
|
}
|
||||||
|
// 不生成 vue 文件
|
||||||
|
if (!table.isGenVue()) {
|
||||||
|
files.removeIf(file -> this.isVueFile(file.getTemplatePath()));
|
||||||
|
}
|
||||||
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,22 +151,37 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
|
|||||||
// 反射调用 setter 方法
|
// 反射调用 setter 方法
|
||||||
BiConsumer<String, Object> callSetter = (field, value) -> Fields.setFieldValue(s, field, value);
|
BiConsumer<String, Object> callSetter = (field, value) -> Fields.setFieldValue(s, field, value);
|
||||||
String packageName = s.getPackageName();
|
String packageName = s.getPackageName();
|
||||||
// 替换 Request.java 文件包名
|
// 替换文件业务包名
|
||||||
if (packageName.contains(REQUEST_PACKAGE_REPLACER)) {
|
boolean replace = Arrays.stream(PACKAGE_REPLACER).anyMatch(packageName::contains);
|
||||||
String replacePackage = String.format(packageName, tables.get(tableInfo.getName()).getRequestPackage());
|
if (replace) {
|
||||||
|
String replacePackage = String.format(packageName, tables.get(tableInfo.getName()).getBizPackage());
|
||||||
callSetter.accept("packageName", replacePackage);
|
callSetter.accept("packageName", replacePackage);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 包转换器
|
||||||
|
Function<Predicate<String>, List<String>> packageConverter = conv ->
|
||||||
|
customFiles.stream()
|
||||||
|
.filter(s -> conv.test(s.getTemplatePath()))
|
||||||
|
.map(CustomFile::getPackageName)
|
||||||
|
.map(s -> getConfigBuilder().getPackageConfig().getParent() + "." + s)
|
||||||
|
.distinct()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// 自定义文件的包 (导入用)
|
// 自定义文件的包 (导入用)
|
||||||
List<String> customFilePackages = customFiles.stream()
|
List<String> customFilePackages = packageConverter.apply(s -> s.contains(".java.vm") && !s.contains("orion-server-api"));
|
||||||
.filter(s -> s.getTemplatePath().contains(".java.vm"))
|
|
||||||
.map(CustomFile::getPackageName)
|
|
||||||
.map(s -> getConfigBuilder().getPackageConfig().getParent() + "." + s)
|
|
||||||
.distinct()
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
objectMap.put("customFilePackages", customFilePackages);
|
objectMap.put("customFilePackages", customFilePackages);
|
||||||
|
|
||||||
|
// 自定义 api entity 文件的包 (导入用)
|
||||||
|
List<String> customApiEntityFilePackages = packageConverter.apply(s -> s.contains(".java.vm") && s.contains("orion-server-api-entity"));
|
||||||
|
objectMap.put("customApiEntityFilePackages", customApiEntityFilePackages);
|
||||||
|
|
||||||
|
// 自定义 api interface 文件的包 (导入用)
|
||||||
|
List<String> customApiInterfaceFilePackages = packageConverter.apply(s -> s.contains("orion-server-api-interface.java.vm"));
|
||||||
|
objectMap.put("customApiInterfaceFilePackage", customApiInterfaceFilePackages.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插入表元数据
|
* 插入表元数据
|
||||||
*
|
*
|
||||||
@@ -187,18 +215,19 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
|
|||||||
objectMap.put("apiComment", map);
|
objectMap.put("apiComment", map);
|
||||||
String comment = tableInfo.getComment();
|
String comment = tableInfo.getComment();
|
||||||
map.put("create", "创建" + comment);
|
map.put("create", "创建" + comment);
|
||||||
map.put("update", "通过 id 更新" + comment);
|
map.put("updateById", "通过 id 更新" + comment);
|
||||||
map.put("get", "通过 id 查询" + comment);
|
map.put("getById", "通过 id 查询" + comment);
|
||||||
map.put("list", "通过 id 批量查询" + comment);
|
map.put("listById", "通过 id 批量查询" + comment);
|
||||||
map.put("query", "分页查询" + comment);
|
map.put("listAll", "查询全部" + comment);
|
||||||
map.put("delete", "通过 id 删除" + comment);
|
map.put("queryPage", "分页查询" + comment);
|
||||||
map.put("batchDelete", "通过 id 批量删除" + comment);
|
map.put("deleteById", "通过 id 删除" + comment);
|
||||||
|
map.put("batchDeleteById", "通过 id 批量删除" + comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void outputCustomFile(@NotNull List<CustomFile> customFiles, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> objectMap) {
|
protected void outputCustomFile(@NotNull List<CustomFile> customFiles, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> objectMap) {
|
||||||
// 创建自定义文件副本文件
|
// 创建自定义文件副本文件
|
||||||
customFiles = this.createCustomFilesBackup(customFiles);
|
customFiles = this.createCustomFilesBackup(customFiles, tableInfo);
|
||||||
// 替换自定义包名
|
// 替换自定义包名
|
||||||
this.replacePackageName(customFiles, tableInfo, objectMap);
|
this.replacePackageName(customFiles, tableInfo, objectMap);
|
||||||
// 添加表元数据
|
// 添加表元数据
|
||||||
@@ -265,7 +294,6 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
|
|||||||
beanMap.put("enums", this.getEnumMap(table));
|
beanMap.put("enums", this.getEnumMap(table));
|
||||||
objectMap.put("vue", beanMap);
|
objectMap.put("vue", beanMap);
|
||||||
|
|
||||||
|
|
||||||
// 生成文件
|
// 生成文件
|
||||||
customFiles.forEach(file -> {
|
customFiles.forEach(file -> {
|
||||||
// 文件路径
|
// 文件路径
|
||||||
@@ -284,7 +312,17 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
|
|||||||
* @return 是否为后端文件
|
* @return 是否为后端文件
|
||||||
*/
|
*/
|
||||||
private boolean isServerFile(String templatePath) {
|
private boolean isServerFile(String templatePath) {
|
||||||
return templatePath.startsWith("orion-server");
|
return templatePath.contains("orion-server");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为后端 api 文件
|
||||||
|
*
|
||||||
|
* @param templatePath templatePath
|
||||||
|
* @return 是否为 sql 文件
|
||||||
|
*/
|
||||||
|
private boolean isServerApiFile(String templatePath) {
|
||||||
|
return templatePath.contains("orion-server-api");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -298,16 +336,6 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
|
|||||||
templatePath.contains("orion-sql-menu.sql");
|
templatePath.contains("orion-sql-menu.sql");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否为 sql 文件
|
|
||||||
*
|
|
||||||
* @param templatePath templatePath
|
|
||||||
* @return 是否为 sql 文件
|
|
||||||
*/
|
|
||||||
private boolean isSqlFile(String templatePath) {
|
|
||||||
return templatePath.contains("orion-sql-");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取枚举 map
|
* 获取枚举 map
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package ${currentPackage};
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
import ${package.Entity}.*;
|
||||||
|
#foreach($pkg in ${customFilePackages})
|
||||||
|
import ${pkg}.*;
|
||||||
|
#end
|
||||||
|
#foreach($pkg in ${customApiEntityFilePackages})
|
||||||
|
import ${pkg}.*;
|
||||||
|
#end
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $!{table.comment} 对外服务对象转换器
|
||||||
|
*
|
||||||
|
* @author ${author}
|
||||||
|
* @version ${since}
|
||||||
|
* @since ${date}
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ${type}ApiConvert {
|
||||||
|
|
||||||
|
${type}ApiConvert MAPPER = Mappers.getMapper(${type}ApiConvert.class);
|
||||||
|
|
||||||
|
${type}DO to(${type}DTO dto);
|
||||||
|
|
||||||
|
${type}DTO to(${type}DO domain);
|
||||||
|
|
||||||
|
${type}DO to(${type}QueryDTO domain);
|
||||||
|
|
||||||
|
${type}CreateRequest to(${type}CreateDTO domain);
|
||||||
|
|
||||||
|
${type}UpdateRequest to(${type}UpdateDTO domain);
|
||||||
|
|
||||||
|
List<${type}DTO> toDTO(List<${type}DO> list);
|
||||||
|
|
||||||
|
List<${type}DO> toDomain(List<${type}DTO> list);
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package ${currentPackage};
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $!{table.comment} 创建请求业务对象
|
||||||
|
*
|
||||||
|
* @author ${author}
|
||||||
|
* @version ${since}
|
||||||
|
* @since ${date}
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Schema(name = "${type}CreateDTO", description = "$!{table.comment} 创建请求业务对象")
|
||||||
|
public class ${type}CreateDTO implements Serializable {
|
||||||
|
|
||||||
|
#foreach($field in ${table.fields})
|
||||||
|
#if("$!field.propertyName" != "id")
|
||||||
|
#if("$field.propertyType" == "String")
|
||||||
|
@NotBlank
|
||||||
|
@Size(max = $field.metaInfo.length)
|
||||||
|
#else
|
||||||
|
@NotNull
|
||||||
|
#end
|
||||||
|
#if("$!field.comment" != "")
|
||||||
|
@Schema(description = "${field.comment}")
|
||||||
|
#end
|
||||||
|
private ${field.propertyType} ${field.propertyName};
|
||||||
|
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package ${currentPackage};
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $!{table.comment} 查询请求业务对象
|
||||||
|
*
|
||||||
|
* @author ${author}
|
||||||
|
* @version ${since}
|
||||||
|
* @since ${date}
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Schema(name = "${type}QueryDTO", description = "$!{table.comment} 查询请求业务对象")
|
||||||
|
public class ${type}QueryDTO implements Serializable {
|
||||||
|
#foreach($field in ${table.fields})
|
||||||
|
|
||||||
|
#if("$field.propertyType" == "String")
|
||||||
|
@Size(max = $field.metaInfo.length)
|
||||||
|
#end
|
||||||
|
#if("$!field.comment" != "")
|
||||||
|
@Schema(description = "${field.comment}")
|
||||||
|
#end
|
||||||
|
private ${field.propertyType} ${field.propertyName};
|
||||||
|
#end
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package ${currentPackage};
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $!{table.comment} 更新请求业务对象
|
||||||
|
*
|
||||||
|
* @author ${author}
|
||||||
|
* @version ${since}
|
||||||
|
* @since ${date}
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Schema(name = "${type}UpdateDTO", description = "$!{table.comment} 更新请求业务对象")
|
||||||
|
public class ${type}UpdateDTO implements Serializable {
|
||||||
|
#foreach($field in ${table.fields})
|
||||||
|
|
||||||
|
#if("$field.propertyType" == "String")
|
||||||
|
@NotBlank
|
||||||
|
@Size(max = $field.metaInfo.length)
|
||||||
|
#else
|
||||||
|
@NotNull
|
||||||
|
#end
|
||||||
|
#if("$!field.comment" != "")
|
||||||
|
@Schema(description = "${field.comment}")
|
||||||
|
#end
|
||||||
|
private ${field.propertyType} ${field.propertyName};
|
||||||
|
#end
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
package ${package.ServiceImpl};
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.orion.lang.utils.collect.Collections;
|
||||||
|
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||||
|
import com.orion.ops.framework.common.utils.Valid;
|
||||||
|
#foreach($pkg in ${customFilePackages})
|
||||||
|
import ${pkg}.*;
|
||||||
|
#end
|
||||||
|
import ${customApiInterfaceFilePackage}.${type}Api;
|
||||||
|
import ${package.Entity}.${entity};
|
||||||
|
import ${package.Mapper}.${table.mapperName};
|
||||||
|
import ${package.Service}.${table.serviceName};
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $!{table.comment} 对外服务实现类
|
||||||
|
*
|
||||||
|
* @author ${author}
|
||||||
|
* @version ${since}
|
||||||
|
* @since ${date}
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class ${type}ApiImpl implements ${type}Api {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ${type}Service ${type}Service;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ${type}DAO ${typeLower}DAO;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long create${type}(${type}CreateDTO dto) {
|
||||||
|
log.info("${type}Api.create${type} request: {}", JSON.toJSONString(dto));
|
||||||
|
Valid.valid(dto);
|
||||||
|
// 转换
|
||||||
|
${type}CreateRequest request = ${type}ApiConvert.MAPPER.to(dto);
|
||||||
|
// 创建
|
||||||
|
return ${type}Service.create${type}(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer update${type}ById(${type}UpdateDTO dto) {
|
||||||
|
log.info("${type}Api.update${type} request: {}", JSON.toJSONString(dto));
|
||||||
|
Valid.valid(dto);
|
||||||
|
// 转换
|
||||||
|
${type}UpdateRequest request = ${type}ApiConvert.MAPPER.to(dto);
|
||||||
|
// 修改
|
||||||
|
return ${type}Service.update${type}(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ${type}DTO get${type}ById(Long id) {
|
||||||
|
log.info("${type}Api.get${type}ById id: {}", id);
|
||||||
|
Valid.notNull(id, ErrorMessage.ID_MISSING);
|
||||||
|
// 修改
|
||||||
|
${type}DO record = ${type}DAO.selectById(id);
|
||||||
|
if (record == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// 转换
|
||||||
|
return ${type}ApiConvert.MAPPER.to(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<${type}DTO> get${type}ListById(Collection<Long> idList) {
|
||||||
|
log.info("${type}Api.get${type}ListById idList: {}", idList);
|
||||||
|
if (Collections.isEmpty(idList)) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
// 查询
|
||||||
|
List<${type}DO> rows = ${type}DAO.selectBatchIds(idList);
|
||||||
|
// 转换
|
||||||
|
return ${type}ApiConvert.MAPPER.toDTO(rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<${type}DTO> get${type}List(${type}QueryDTO dto) {
|
||||||
|
log.info("${type}Api.get${type}List dto: {}", JSON.toJSONString(dto));
|
||||||
|
Valid.valid(dto);
|
||||||
|
// 转换条件
|
||||||
|
${type}DO domain = ${type}ApiConvert.MAPPER.to(dto);
|
||||||
|
// 查询
|
||||||
|
LambdaQueryWrapper<${type}DO> wrapper = ${type}DAO.queryCondition(domain);
|
||||||
|
List<${type}DO> rows = ${type}DAO.selectList(wrapper);
|
||||||
|
// 转换结果
|
||||||
|
return ${type}ApiConvert.MAPPER.toDTO(rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer delete${type}ById(Long id) {
|
||||||
|
log.info("${type}Api.delete${type}ById id: {}", id);
|
||||||
|
Valid.notNull(id, ErrorMessage.ID_MISSING);
|
||||||
|
// 删除
|
||||||
|
return ${type}DAO.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer batchDelete${type}ById(Collection<Long> idList) {
|
||||||
|
log.info("${type}Api.batchDelete${type}ById idList: {}", idList);
|
||||||
|
Valid.notEmpty(idList, ErrorMessage.ID_MISSING);
|
||||||
|
// 删除
|
||||||
|
return ${type}DAO.deleteBatchIds(idList);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package ${currentPackage};
|
||||||
|
|
||||||
|
#foreach($pkg in ${customApiEntityFilePackages})
|
||||||
|
import ${pkg}.*;
|
||||||
|
#end
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $!{table.comment} 对外服务类
|
||||||
|
*
|
||||||
|
* @author ${author}
|
||||||
|
* @version ${since}
|
||||||
|
* @since ${date}
|
||||||
|
*/
|
||||||
|
public interface ${type}Api {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${apiComment.create}
|
||||||
|
*
|
||||||
|
* @param dto dto
|
||||||
|
* @return id
|
||||||
|
*/
|
||||||
|
Long create${type}(${type}CreateDTO dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${apiComment.updateById}
|
||||||
|
*
|
||||||
|
* @param dto dto
|
||||||
|
* @return effect
|
||||||
|
*/
|
||||||
|
Integer update${type}ById(${type}UpdateDTO dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${apiComment.getById}
|
||||||
|
*
|
||||||
|
* @param id id
|
||||||
|
* @return row
|
||||||
|
*/
|
||||||
|
${type}DTO get${type}ById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${apiComment.listById}
|
||||||
|
*
|
||||||
|
* @param idList idList
|
||||||
|
* @return rows
|
||||||
|
*/
|
||||||
|
List<${type}DTO> get${type}ByIdList(Collection<Long> idList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${apiComment.listAll}
|
||||||
|
*
|
||||||
|
* @param dto dto
|
||||||
|
* @return rows
|
||||||
|
*/
|
||||||
|
List<${type}DTO> get${type}List(${type}QueryDTO dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${apiComment.deleteById}
|
||||||
|
*
|
||||||
|
* @param id id
|
||||||
|
* @return effect
|
||||||
|
*/
|
||||||
|
Integer delete${type}ById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${apiComment.batchDeleteById}
|
||||||
|
*
|
||||||
|
* @param idList idList
|
||||||
|
* @return effect
|
||||||
|
*/
|
||||||
|
Integer batchDelete${type}ByIdList(Collection<Long> idList);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@ Authorization: {{token}}
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
${httpComment} ${apiComment.update}
|
${httpComment} ${apiComment.updateById}
|
||||||
PUT {{baseUrl}}/${package.ModuleName}/${typeHyphen}/update
|
PUT {{baseUrl}}/${package.ModuleName}/${typeHyphen}/update
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
Authorization: {{token}}
|
Authorization: {{token}}
|
||||||
@@ -24,17 +24,29 @@ Authorization: {{token}}
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
${httpComment} ${apiComment.get}
|
${httpComment} ${apiComment.getById}
|
||||||
GET {{baseUrl}}/${package.ModuleName}/${typeHyphen}/get?id=1
|
GET {{baseUrl}}/${package.ModuleName}/${typeHyphen}/get?id=1
|
||||||
Authorization: {{token}}
|
Authorization: {{token}}
|
||||||
|
|
||||||
|
|
||||||
${httpComment} ${apiComment.list}
|
${httpComment} ${apiComment.listById}
|
||||||
GET {{baseUrl}}/${package.ModuleName}/${typeHyphen}/list?idList=1,2,3
|
GET {{baseUrl}}/${package.ModuleName}/${typeHyphen}/list?idList=1,2,3
|
||||||
Authorization: {{token}}
|
Authorization: {{token}}
|
||||||
|
|
||||||
|
|
||||||
${httpComment} ${apiComment.query}
|
${httpComment} ${apiComment.listAll}
|
||||||
|
POST {{baseUrl}}/${package.ModuleName}/${typeHyphen}/list-all
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: {{token}}
|
||||||
|
|
||||||
|
{
|
||||||
|
#foreach($field in ${table.fields})
|
||||||
|
"${field.propertyName}": ""#if($foreach.hasNext),#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
${httpComment} ${apiComment.queryPage}
|
||||||
POST {{baseUrl}}/${package.ModuleName}/${typeHyphen}/query
|
POST {{baseUrl}}/${package.ModuleName}/${typeHyphen}/query
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
Authorization: {{token}}
|
Authorization: {{token}}
|
||||||
@@ -46,12 +58,12 @@ Authorization: {{token}}
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
${httpComment} ${apiComment.delete}
|
${httpComment} ${apiComment.deleteById}
|
||||||
DELETE {{baseUrl}}/${package.ModuleName}/${typeHyphen}/delete?id=1
|
DELETE {{baseUrl}}/${package.ModuleName}/${typeHyphen}/delete?id=1
|
||||||
Authorization: {{token}}
|
Authorization: {{token}}
|
||||||
|
|
||||||
|
|
||||||
${httpComment} ${apiComment.batchDelete}
|
${httpComment} ${apiComment.batchDeleteById}
|
||||||
DELETE {{baseUrl}}/${package.ModuleName}/${typeHyphen}/delete-batch?idList=1,2,3
|
DELETE {{baseUrl}}/${package.ModuleName}/${typeHyphen}/delete-batch?idList=1,2,3
|
||||||
Authorization: {{token}}
|
Authorization: {{token}}
|
||||||
|
|
||||||
|
|||||||
@@ -53,52 +53,60 @@ public class ${table.controllerName} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
@Operation(summary = "${apiComment.update}")
|
@Operation(summary = "${apiComment.updateById}")
|
||||||
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:update')")
|
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:update')")
|
||||||
public Integer update${type}(@Validated @RequestBody ${type}UpdateRequest request) {
|
public Integer update${type}(@Validated @RequestBody ${type}UpdateRequest request) {
|
||||||
return ${typeLower}Service.update${type}(request);
|
return ${typeLower}Service.update${type}ById(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@IgnoreLog(IgnoreLogMode.RET)
|
@IgnoreLog(IgnoreLogMode.RET)
|
||||||
@GetMapping("/get")
|
@GetMapping("/get")
|
||||||
@Operation(summary = "${apiComment.get}")
|
@Operation(summary = "${apiComment.getById}")
|
||||||
@Parameter(name = "id", description = "id", required = true)
|
@Parameter(name = "id", description = "id", required = true)
|
||||||
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
|
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
|
||||||
public ${type}VO get${type}(@RequestParam("id") Long id) {
|
public ${type}VO get${type}(@RequestParam("id") Long id) {
|
||||||
return ${typeLower}Service.get${type}(id);
|
return ${typeLower}Service.get${type}ById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@IgnoreLog(IgnoreLogMode.RET)
|
@IgnoreLog(IgnoreLogMode.RET)
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@Operation(summary = "${apiComment.list}")
|
@Operation(summary = "${apiComment.listById}")
|
||||||
@Parameter(name = "idList", description = "idList", required = true)
|
@Parameter(name = "idList", description = "idList", required = true)
|
||||||
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
|
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
|
||||||
public List<${type}VO> get${type}List(@RequestParam("idList") List<Long> idList) {
|
public List<${type}VO> get${type}List(@RequestParam("idList") List<Long> idList) {
|
||||||
return ${typeLower}Service.get${type}List(idList);
|
return ${typeLower}Service.get${type}ByIdList(idList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@IgnoreLog(IgnoreLogMode.RET)
|
||||||
|
@PostMapping("/list-all")
|
||||||
|
@Operation(summary = "${apiComment.listAll}")
|
||||||
|
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
|
||||||
|
public List<${type}VO> get${type}ListAll(@Validated @RequestBody ${type}QueryRequest request) {
|
||||||
|
return ${typeLower}Service.get${type}List(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@IgnoreLog(IgnoreLogMode.RET)
|
@IgnoreLog(IgnoreLogMode.RET)
|
||||||
@PostMapping("/query")
|
@PostMapping("/query")
|
||||||
@Operation(summary = "${apiComment.query}")
|
@Operation(summary = "${apiComment.queryPage}")
|
||||||
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
|
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
|
||||||
public DataGrid<${type}VO> get${type}Page(@Validated @RequestBody ${type}QueryRequest request) {
|
public DataGrid<${type}VO> get${type}Page(@Validated @RequestBody ${type}QueryRequest request) {
|
||||||
return ${typeLower}Service.get${type}Page(request);
|
return ${typeLower}Service.get${type}Page(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/delete")
|
@DeleteMapping("/delete")
|
||||||
@Operation(summary = "${apiComment.delete}")
|
@Operation(summary = "${apiComment.deleteById}")
|
||||||
@Parameter(name = "id", description = "id", required = true)
|
@Parameter(name = "id", description = "id", required = true)
|
||||||
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:delete')")
|
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:delete')")
|
||||||
public Integer delete${type}(@RequestParam("id") Long id) {
|
public Integer delete${type}(@RequestParam("id") Long id) {
|
||||||
return ${typeLower}Service.delete${type}(id);
|
return ${typeLower}Service.delete${type}ById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/delete-batch")
|
@DeleteMapping("/delete-batch")
|
||||||
@Operation(summary = "${apiComment.batchDelete}")
|
@Operation(summary = "${apiComment.batchDeleteById}")
|
||||||
@Parameter(name = "idList", description = "idList", required = true)
|
@Parameter(name = "idList", description = "idList", required = true)
|
||||||
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:delete')")
|
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:delete')")
|
||||||
public Integer batchDelete${type}(@RequestParam("idList") List<Long> idList) {
|
public Integer batchDelete${type}(@RequestParam("idList") List<Long> idList) {
|
||||||
return ${typeLower}Service.batchDelete${type}(idList);
|
return ${typeLower}Service.batchDelete${type}ByIdList(idList);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
package ${currentPackage};
|
|
||||||
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.factory.Mappers;
|
|
||||||
import ${package.Entity}.*;
|
|
||||||
#foreach($pkg in ${customFilePackages})
|
|
||||||
import ${pkg}.*;
|
|
||||||
#end
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* $!{table.comment} 暴露服务转换器
|
|
||||||
*
|
|
||||||
* @author ${author}
|
|
||||||
* @version ${since}
|
|
||||||
* @since ${date}
|
|
||||||
*/
|
|
||||||
@Mapper
|
|
||||||
public interface ${type}ProviderConvert {
|
|
||||||
|
|
||||||
${type}ProviderConvert MAPPER = Mappers.getMapper(${type}ProviderConvert.class);
|
|
||||||
|
|
||||||
${type}DO to(${type}DTO dto);
|
|
||||||
|
|
||||||
${type}DTO to(${type}DO domain);
|
|
||||||
|
|
||||||
List<${type}DO> toDO(List<${type}DTO> list);
|
|
||||||
|
|
||||||
List<${type}DTO> toDTO(List<${type}DO> list);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -20,12 +20,12 @@ import ${mapperAnnotationClass.name};
|
|||||||
public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {
|
public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取全部条件
|
* 获取查询条件
|
||||||
*
|
*
|
||||||
* @param entity entity
|
* @param entity entity
|
||||||
* @return 全部条件
|
* @return 查询条件
|
||||||
*/
|
*/
|
||||||
default LambdaQueryWrapper<${entity}> condition(${entity} entity) {
|
default LambdaQueryWrapper<${entity}> queryCondition(${entity} entity) {
|
||||||
return this.wrapper()
|
return this.wrapper()
|
||||||
#foreach($field in ${table.fields})
|
#foreach($field in ${table.fields})
|
||||||
.eq(${type}DO::get${field.capitalName}, entity.get${field.capitalName}())#if(!$foreach.hasNext);#end
|
.eq(${type}DO::get${field.capitalName}, entity.get${field.capitalName}())#if(!$foreach.hasNext);#end
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer update${type}(${type}UpdateRequest request) {
|
public Integer update${type}ById(${type}UpdateRequest request) {
|
||||||
// 查询
|
// 查询
|
||||||
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
|
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
|
||||||
${type}DO record = ${typeLower}DAO.selectById(id);
|
${type}DO record = ${typeLower}DAO.selectById(id);
|
||||||
@@ -62,7 +62,7 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ${type}VO get${type}(Long id) {
|
public ${type}VO get${type}ById(Long id) {
|
||||||
// 查询
|
// 查询
|
||||||
${type}DO record = ${typeLower}DAO.selectById(id);
|
${type}DO record = ${typeLower}DAO.selectById(id);
|
||||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||||
@@ -71,7 +71,7 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<${type}VO> get${type}List(List<Long> idList) {
|
public List<${type}VO> get${type}ByIdList(List<Long> idList) {
|
||||||
// 查询
|
// 查询
|
||||||
List<${type}DO> records = ${typeLower}DAO.selectBatchIds(idList);
|
List<${type}DO> records = ${typeLower}DAO.selectBatchIds(idList);
|
||||||
if (records.isEmpty()) {
|
if (records.isEmpty()) {
|
||||||
@@ -82,13 +82,23 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataGrid<${type}VO> get${type}Page(${type}QueryRequest request) {
|
public List<${type}VO> get${type}List(${type}QueryRequest request) {
|
||||||
|
// 转换
|
||||||
|
${type}DO record = ${type}Convert.MAPPER.to(request);
|
||||||
// 构造条件
|
// 构造条件
|
||||||
LambdaQueryWrapper<${type}DO> wrapper = ${typeLower}DAO.wrapper()
|
LambdaQueryWrapper<${type}DO> wrapper = ${typeLower}DAO.queryCondition(record);
|
||||||
#foreach($field in ${table.fields})
|
// 查询
|
||||||
.eq(${type}DO::get${field.capitalName}, request.get${field.capitalName}())
|
return ${typeLower}DAO.of()
|
||||||
#end
|
.wrapper(wrapper)
|
||||||
.orderByDesc(${type}DO::getId);
|
.list(${type}Convert.MAPPER::to);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataGrid<${type}VO> get${type}Page(${type}QueryRequest request) {
|
||||||
|
// 转换
|
||||||
|
${type}DO record = ${type}Convert.MAPPER.to(request);
|
||||||
|
// 构造条件
|
||||||
|
LambdaQueryWrapper<${type}DO> wrapper = ${typeLower}DAO.queryCondition(record);
|
||||||
// 查询
|
// 查询
|
||||||
return ${typeLower}DAO.of()
|
return ${typeLower}DAO.of()
|
||||||
.wrapper(wrapper)
|
.wrapper(wrapper)
|
||||||
@@ -97,16 +107,16 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer delete${type}(Long id) {
|
public Integer delete${type}ById(Long id) {
|
||||||
int effect = ${typeLower}DAO.deleteById(id);
|
int effect = ${typeLower}DAO.deleteById(id);
|
||||||
log.info("${type}Service-delete${type} id: {}, effect: {}", id, effect);
|
log.info("${type}Service-delete${type} id: {}, effect: {}", id, effect);
|
||||||
return effect;
|
return effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer batchDelete${type}(List<Long> idList) {
|
public Integer batchDelete${type}ByIdList(List<Long> idList) {
|
||||||
int effect = ${typeLower}DAO.deleteBatchIds(idList);
|
int effect = ${typeLower}DAO.deleteBatchIds(idList);
|
||||||
log.info("${type}Service-batchDelete${type} idList: {}, effect: {}", JSON.toJSONString(idList), effect);
|
log.info("${type}Service-batchDelete${type} idList: {}, effect: {}", idList, effect);
|
||||||
return effect;
|
return effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,31 +25,39 @@ public interface ${table.serviceName} {
|
|||||||
Long create${type}(${type}CreateRequest request);
|
Long create${type}(${type}CreateRequest request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${apiComment.update}
|
* ${apiComment.updateById}
|
||||||
*
|
*
|
||||||
* @param request request
|
* @param request request
|
||||||
* @return effect
|
* @return effect
|
||||||
*/
|
*/
|
||||||
Integer update${type}(${type}UpdateRequest request);
|
Integer update${type}ById(${type}UpdateRequest request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${apiComment.get}
|
* ${apiComment.getById}
|
||||||
*
|
*
|
||||||
* @param id id
|
* @param id id
|
||||||
* @return row
|
* @return row
|
||||||
*/
|
*/
|
||||||
${type}VO get${type}(Long id);
|
${type}VO get${type}ById(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${apiComment.list}
|
* ${apiComment.listById}
|
||||||
*
|
*
|
||||||
* @param idList idList
|
* @param idList idList
|
||||||
* @return rows
|
* @return rows
|
||||||
*/
|
*/
|
||||||
List<${type}VO> get${type}List(List<Long> idList);
|
List<${type}VO> get${type}ByIdList(List<Long> idList);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${apiComment.query}
|
* ${apiComment.listAll}
|
||||||
|
*
|
||||||
|
* @param request request
|
||||||
|
* @return rows
|
||||||
|
*/
|
||||||
|
List<${type}VO> get${type}List(${type}QueryRequest request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${apiComment.queryPage}
|
||||||
*
|
*
|
||||||
* @param request request
|
* @param request request
|
||||||
* @return rows
|
* @return rows
|
||||||
@@ -57,19 +65,19 @@ public interface ${table.serviceName} {
|
|||||||
DataGrid<${type}VO> get${type}Page(${type}QueryRequest request);
|
DataGrid<${type}VO> get${type}Page(${type}QueryRequest request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${apiComment.delete}
|
* ${apiComment.deleteById}
|
||||||
*
|
*
|
||||||
* @param id id
|
* @param id id
|
||||||
* @return effect
|
* @return effect
|
||||||
*/
|
*/
|
||||||
Integer delete${type}(Long id);
|
Integer delete${type}ById(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${apiComment.batchDelete}
|
* ${apiComment.batchDeleteById}
|
||||||
*
|
*
|
||||||
* @param idList idList
|
* @param idList idList
|
||||||
* @return effect
|
* @return effect
|
||||||
*/
|
*/
|
||||||
Integer batchDelete${type}(List<Long> idList);
|
Integer batchDelete${type}ByIdList(List<Long> idList);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,21 +74,21 @@ export function create${vue.featureFirstUpper}(request: ${vue.featureFirstUpper}
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $apiComment.update
|
* $apiComment.updateById
|
||||||
*/
|
*/
|
||||||
export function update${vue.featureFirstUpper}(request: ${vue.featureFirstUpper}UpdateRequest) {
|
export function update${vue.featureFirstUpper}(request: ${vue.featureFirstUpper}UpdateRequest) {
|
||||||
return axios.put('/${package.ModuleName}/${typeHyphen}/update', request);
|
return axios.put('/${package.ModuleName}/${typeHyphen}/update', request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $apiComment.get
|
* $apiComment.getById
|
||||||
*/
|
*/
|
||||||
export function get${vue.featureFirstUpper}(id: number) {
|
export function get${vue.featureFirstUpper}(id: number) {
|
||||||
return axios.get<${vue.featureFirstUpper}QueryResponse>('/${package.ModuleName}/${typeHyphen}/get', { params: { id } });
|
return axios.get<${vue.featureFirstUpper}QueryResponse>('/${package.ModuleName}/${typeHyphen}/get', { params: { id } });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $apiComment.list
|
* $apiComment.listById
|
||||||
*/
|
*/
|
||||||
export function get${vue.featureFirstUpper}List(idList: Array<number>) {
|
export function get${vue.featureFirstUpper}List(idList: Array<number>) {
|
||||||
return axios.get<${vue.featureFirstUpper}QueryResponse[]>('/${package.ModuleName}/${typeHyphen}/list', {
|
return axios.get<${vue.featureFirstUpper}QueryResponse[]>('/${package.ModuleName}/${typeHyphen}/list', {
|
||||||
@@ -100,21 +100,28 @@ export function get${vue.featureFirstUpper}List(idList: Array<number>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $apiComment.query
|
* $apiComment.listAll
|
||||||
|
*/
|
||||||
|
export function get${vue.featureFirstUpper}ListAll(request: ${vue.featureFirstUpper}QueryRequest) {
|
||||||
|
return axios.post<Array<${vue.featureFirstUpper}QueryResponse>>('/${package.ModuleName}/${typeHyphen}/list-all', request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $apiComment.queryPage
|
||||||
*/
|
*/
|
||||||
export function get${vue.featureFirstUpper}Page(request: ${vue.featureFirstUpper}QueryRequest) {
|
export function get${vue.featureFirstUpper}Page(request: ${vue.featureFirstUpper}QueryRequest) {
|
||||||
return axios.post<DataGrid<${vue.featureFirstUpper}QueryResponse>>('/${package.ModuleName}/${typeHyphen}/query', request);
|
return axios.post<DataGrid<${vue.featureFirstUpper}QueryResponse>>('/${package.ModuleName}/${typeHyphen}/query', request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $apiComment.delete
|
* $apiComment.deleteById
|
||||||
*/
|
*/
|
||||||
export function delete${vue.featureFirstUpper}(id: number) {
|
export function delete${vue.featureFirstUpper}(id: number) {
|
||||||
return axios.delete('/${package.ModuleName}/${typeHyphen}/delete', { params: { id } });
|
return axios.delete('/${package.ModuleName}/${typeHyphen}/delete', { params: { id } });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $apiComment.batchDelete
|
* $apiComment.batchDeleteById
|
||||||
*/
|
*/
|
||||||
export function batchDelete${vue.featureFirstUpper}(idList: Array<number>) {
|
export function batchDelete${vue.featureFirstUpper}(idList: Array<number>) {
|
||||||
return axios.delete('/${package.ModuleName}/${typeHyphen}/delete-batch', {
|
return axios.delete('/${package.ModuleName}/${typeHyphen}/delete-batch', {
|
||||||
|
|||||||
Reference in New Issue
Block a user