修改代码生成器模板.

This commit is contained in:
lijiahang
2023-07-13 09:57:32 +08:00
parent d39ab1f32a
commit 75e588be4e
25 changed files with 750 additions and 340 deletions

View File

@@ -1,8 +1,10 @@
{
"local": {
"baseUrl": "http://127.0.0.1:9200/orion-api"
"baseUrl": "http://127.0.0.1:9200/orion-api",
"token": "Bearer 1"
},
"gateway": {
"baseUrl": "http://127.0.0.1:9200/orion-api"
"baseUrl": "http://127.0.0.1:9200/orion-api",
"token": "Bearer 1"
}
}

View File

@@ -22,11 +22,13 @@
<artifactId>orion-all</artifactId>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- aspectj -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
@@ -72,11 +74,16 @@
<scope>provided</scope>
</dependency>
<!-- security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- doc -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@@ -2,6 +2,8 @@ package com.orion.ops.framework.common.constant;
/**
* 自动装配排序常量
* <p>
* 实际遵循 DependsOn
*
* @author Jiahang Li
* @version 1.0.0

View File

@@ -2,6 +2,7 @@ package com.orion.ops.framework.common.constant;
import com.orion.lang.define.wrapper.CodeInfo;
import com.orion.lang.define.wrapper.HttpWrapper;
import com.orion.lang.utils.Exceptions;
/**
* 错误码
@@ -69,6 +70,10 @@ public enum ErrorCode implements CodeInfo {
DIABLED_ERROR(715, "数据已被禁用"),
DATA_PRESENT(716, "数据已存在"),
DATA_ABESENT(717, "数据不存在"),
;
ErrorCode(int code, String message) {
@@ -127,4 +132,11 @@ public enum ErrorCode implements CodeInfo {
return wrapper;
}
/**
* @return 获取异常
*/
public RuntimeException exception() {
return Exceptions.httpWrapper(this);
}
}

View File

@@ -11,4 +11,6 @@ public interface ErrorMessage {
String PARAM_MISSING = "{} 不能为空";
String ID_MISSING = "id 不能为空";
}

View File

@@ -0,0 +1,27 @@
package com.orion.ops.framework.common.entity;
import com.orion.lang.define.wrapper.IPageRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
/**
* 公共页码请求
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023/7/12 23:14
*/
@Data
public class PageRequest implements IPageRequest {
// TODO TEST
@Range(min = 1, max = 10000)
@Schema(description = "页码")
private int page;
@Range(min = 1, max = 100)
@Schema(description = "大小")
private int limit;
}

View File

@@ -17,6 +17,9 @@ import com.orion.ops.framework.mybatis.core.mapper.IMapper;
import org.apache.ibatis.annotations.Mapper;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* 代码生成器
@@ -90,7 +93,7 @@ public class CodeGenerator {
.injection(injectionConfig);
// 执行
ag.execute();
ag.execute(new VelocityTemplateEngine());
}
/**
@@ -254,11 +257,11 @@ public class CodeGenerator {
private static TemplateConfig getTemplateConfig() {
TemplateConfig tplConfig = new TemplateConfig.Builder()
.controller("/templates/orion-controller.java.vm")
.entity("/templates/orion-domain.java.vm")
.entity("/templates/orion-entity-do.java.vm")
.service("/templates/orion-service.java.vm")
.serviceImpl("/templates/orion-service-impl.java.vm")
.mapper("/templates/orion-dao.java.vm")
.xml("/templates/orion-mapper.xml")
.mapper("/templates/orion-mapper.java.vm")
.xml("/templates/orion-mapper.xml.vm")
.build();
return tplConfig;
}
@@ -269,48 +272,42 @@ public class CodeGenerator {
* @return 注入配置
*/
private static InjectionConfig getInjectionConfig() {
// vo 文件
CustomFile voFile = new CustomFile.Builder()
.enableFileOverride()
.templatePath("/templates/orion-vo.java.vm")
.fileName("VO.java")
.packageName("vo")
.build();
String[][] customFileDefineArr = new String[][]{
// vo 文件
new String[]{"/templates/orion-entity-vo.java.vm", "%sVO.java", "entity.vo"},
// dto 文件
new String[]{"/templates/orion-entity-dto.java.vm", "%sDTO.java", "entity.dto"},
// create request 文件
new String[]{"/templates/orion-entity-request-create.java.vm", "%sCreateRequest.java", "entity.request"},
// update request 文件
new String[]{"/templates/orion-entity-request-update.java.vm", "%sUpdateRequest.java", "entity.request"},
// query request 文件
new String[]{"/templates/orion-entity-request-query.java.vm", "%sQueryRequest.java", "entity.request"},
// convert 文件
new String[]{"/templates/orion-convert.java.vm", "%sConvert.java", "convert"},
// convert provider 文件
new String[]{"/templates/orion-convert-provider.java.vm", "%sProviderConvert.java", "convert"},
};
// dto 文件
CustomFile dtoFile = new CustomFile.Builder()
.enableFileOverride()
.templatePath("/templates/orion-dto.java.vm")
.fileName("DTO.java")
.packageName("dto")
.build();
// request 文件
CustomFile requestFile = new CustomFile.Builder()
.enableFileOverride()
.templatePath("/templates/orion-request.java.vm")
.fileName("Request.java")
.packageName("request")
.build();
// convert 文件
CustomFile convertFile = new CustomFile.Builder()
.enableFileOverride()
.templatePath("/templates/orion-convert.java.vm")
.fileName("Convert.java")
.packageName("convert")
.build();
// 构建文件
List<CustomFile> customerFiles = Arrays.stream(customFileDefineArr)
.map(s -> {
return new CustomFile.Builder()
// 覆盖文件
.enableFileOverride()
// 模板路径
.templatePath(s[0])
// 文件
.fileName(s[1])
// 包名
.packageName(s[2])
.build();
}).collect(Collectors.toList());
// 注入配置
InjectionConfig injection = new InjectionConfig.Builder()
// vo 文件
.customFile(voFile)
// dto 文件
.customFile(dtoFile)
// request 文件
.customFile(requestFile)
// convert 文件
.customFile(convertFile)
// 自定义 文件
.customFile(customerFiles)
// 构建
.build();
return injection;

View File

@@ -0,0 +1,143 @@
/*
* Copyright (c) 2011-2022, baomidou (jobob@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.orion.ops.framework.mybatis.core.generator;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.generator.config.ConstVal;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
import com.baomidou.mybatisplus.generator.config.builder.CustomFile;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine;
import com.orion.lang.define.Console;
import com.orion.lang.utils.Strings;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.app.VelocityEngine;
import org.jetbrains.annotations.NotNull;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;
/**
* 代码生成器 Velocity 引擎
*
* @author Jiahang Li
* @version 1.0.0
* @since 2022/4/20 10:33
*/
public class VelocityTemplateEngine extends AbstractTemplateEngine {
private VelocityEngine velocityEngine;
{
try {
Class.forName("org.apache.velocity.util.DuckType");
} catch (ClassNotFoundException e) {
LOGGER.warn("Velocity 1.x is outdated, please upgrade to 2.x or later.");
}
}
@Override
@NotNull
public VelocityTemplateEngine init(@NotNull ConfigBuilder configBuilder) {
if (null == velocityEngine) {
Properties p = new Properties();
p.setProperty(ConstVal.VM_LOAD_PATH_KEY, ConstVal.VM_LOAD_PATH_VALUE);
p.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, StringPool.EMPTY);
p.setProperty(Velocity.ENCODING_DEFAULT, ConstVal.UTF8);
p.setProperty(Velocity.INPUT_ENCODING, ConstVal.UTF8);
p.setProperty("file.resource.loader.unicode", StringPool.TRUE);
velocityEngine = new VelocityEngine(p);
}
return this;
}
@Override
public void writer(@NotNull Map<String, Object> objectMap, @NotNull String templatePath, @NotNull File outputFile) throws Exception {
Template template = velocityEngine.getTemplate(templatePath, ConstVal.UTF8);
try (FileOutputStream fos = new FileOutputStream(outputFile);
OutputStreamWriter ow = new OutputStreamWriter(fos, ConstVal.UTF8);
BufferedWriter writer = new BufferedWriter(ow)) {
template.merge(new VelocityContext(objectMap), writer);
}
LOGGER.debug("模板:" + templatePath + "; 文件:" + outputFile);
}
@Override
@NotNull
public String templateFilePath(@NotNull String filePath) {
final String dotVm = ".vm";
return filePath.endsWith(dotVm) ? filePath : filePath + dotVm;
}
/**
* 输出自定义模板文件
*
* @param customFiles 自定义模板文件列表
* @param tableInfo 表信息
* @param objectMap 渲染数据
* @since 3.5.3
*/
@Override
protected void outputCustomFile(@NotNull List<CustomFile> customFiles, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> objectMap) {
String domainName = tableInfo.getEntityName();
String mappingHyphen = objectMap.get("controllerMappingHyphen").toString();
// 实际实体名称
String entityName = domainName.substring(0, domainName.length() - 2);
objectMap.put("type", entityName);
objectMap.put("typeLower", Strings.firstLower(entityName));
objectMap.put("typeHyphen", mappingHyphen.substring(0, mappingHyphen.length() - 3));
// 自定义文件的包
List<String> customFilePackages = customFiles.stream()
.filter(s -> s.getTemplatePath().contains(".java.vm"))
.map(CustomFile::getPackageName)
.map(s -> getConfigBuilder().getPackageConfig().getParent() + "." + s)
.distinct()
.collect(Collectors.toList());
// 设置导入的包
objectMap.put("customFilePackages", customFilePackages);
// 生成文件
String parentPath = getPathInfo(OutputFile.parent);
customFiles.forEach(file -> {
// 获取 parent package
String currentPackage = getConfigBuilder().getPackageConfig().getParent() + "." + file.getPackageName();
// 设置当前包
objectMap.put("currentPackage", currentPackage);
objectMap.forEach(Console::trace);
// 文件路径
String filePath = StringUtils.isNotBlank(file.getFilePath()) ? file.getFilePath() : parentPath;
if (StringUtils.isNotBlank(file.getPackageName())) {
filePath = filePath + File.separator + file.getPackageName();
filePath = filePath.replaceAll("\\.", StringPool.BACK_SLASH + File.separator);
}
String fileName = filePath + File.separator + String.format(file.getFileName(), entityName);
outputFile(new File(fileName), objectMap, file.getTemplatePath(), file.isFileOverride());
});
}
}

View File

@@ -3,7 +3,7 @@ package com.orion.ops.framework.mybatis.core.query;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.lang.define.wrapper.PageRequest;
import com.orion.lang.define.wrapper.IPageRequest;
import com.orion.lang.define.wrapper.Pager;
import com.orion.lang.utils.Valid;
import com.orion.lang.utils.collect.Lists;
@@ -25,7 +25,7 @@ public class DataQuery<T> {
private final BaseMapper<T> dao;
private PageRequest page;
private IPageRequest page;
private LambdaQueryWrapper<T> wrapper;
@@ -38,7 +38,7 @@ public class DataQuery<T> {
return new DataQuery<>(dao);
}
public DataQuery<T> page(PageRequest page) {
public DataQuery<T> page(IPageRequest page) {
this.page = Valid.notNull(page, "page is null");
return this;
}

View File

@@ -1,19 +1,24 @@
package ${package.Controller};
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.ops.framework.common.annotation.RestWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
#if(${restControllerStyle})
import org.springframework.web.bind.annotation.RestController;
#else
import org.springframework.stereotype.Controller;
import ${package.Service}.*;
#foreach($pkg in ${customFilePackages})
import ${pkg}.*;
#end
#if(${superControllerClassPackage})
import ${superControllerClassPackage};
#end
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* $!{table.comment} api
@@ -26,21 +31,70 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
@Validated
@RestWrapper
#if(${restControllerStyle})
@RestController
#else
@Controller
#end
@RequestMapping("#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end")
#if(${kotlin})
class ${table.controllerName}#if(${superControllerClass}) : ${superControllerClass}()#end
@RestController
@RequestMapping("/${package.ModuleName}/${typeHyphen}")
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
#if(${superControllerClass})
public class ${table.controllerName} extends ${superControllerClass} {
#else
#if(${superControllerClass})
public class ${table.controllerName} extends ${superControllerClass} {
#else
public class ${table.controllerName} {
#end
public class ${table.controllerName} {
#end
@Resource
private ${type}Service ${typeLower}Service;
@PostMapping("/create")
@Operation(summary = "创建$!{table.comment}")
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:create')")
public Long create${type}(@Validated ${type}CreateRequest request){
return ${typeLower}Service.create${type}(request);
}
@PutMapping("/update")
@Operation(summary = "更新$!{table.comment}")
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:update')")
public Integer update${type}(@Validated ${type}UpdateRequest request){
return ${typeLower}Service.update${type}(request);
}
@GetMapping("/get")
@Operation(summary = "通过id查询$!{table.comment}")
@Parameter(name = "id", description = "id", required = true)
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
public ${type}VO get${type}(@RequestParam("id") Long id){
return ${typeLower}Service.get${type}(id);
}
@GetMapping("/list")
@Operation(summary = "通过id批量查询$!{table.comment}")
@Parameter(name = "idList", description = "idList", required = true)
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
public List<${type}VO> get${type}List(@RequestParam("idList") List<Long> idList){
return ${typeLower}Service.get${type}List(idList);
}
@PostMapping("/query")
@Operation(summary = "分页查询$!{table.comment}")
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
public DataGrid<${type}VO> get${type}Page(@Validated @RequestBody ${type}QueryRequest request){
return ${typeLower}Service.get${type}Page(request);
}
@PutMapping("/delete")
@Operation(summary = "删除$!{table.comment}")
@Parameter(name = "id", description = "id", required = true)
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:delete')")
public Integer delete${type}(@RequestParam("id") Long id){
return ${typeLower}Service.delete${type}(id);
}
@PutMapping("/delete-batch")
@Operation(summary = "批量删除$!{table.comment}")
@Parameter(name = "idList", description = "idList", required = true)
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:delete')")
public Integer batchDelete${type}(@RequestParam("idList") List<Long> idList){
return ${typeLower}Service.batchDelete${type}(idList);
}
}
#end

View File

@@ -0,0 +1,32 @@
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 1.0.0
* @since ${date}
*/
@Mapper
@SuppressWarnings("ALL")
public interface ${type}ProviderConvert {
${type}ProviderConvert MAPPER = Mappers.getMapper(${type}ProviderConvert.class);
${type}DO to(${type}DTO dto);
${type}DTO to(${type}DO dto);
List<${type}DO> toDO(List<${type}DTO> list);
List<${type}DTO> toDTO(List<${type}DO> list);
}

View File

@@ -1,12 +1,15 @@
package ${package.Entity};
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} 转换器
* $!{table.comment} 内部对象转换器
*
* @author ${author}
* @version 1.0.0
@@ -14,28 +17,18 @@ import java.util.List;
*/
@Mapper
@SuppressWarnings("ALL")
public interface ${entity}Convert {
public interface ${type}Convert {
${entity}Convert MAPPER = Mappers.getMapper(${entity}Convert.class);
${type}Convert MAPPER = Mappers.getMapper(${type}Convert.class);
${entity} toDomain(${entity}Request request);
${type}DO to(${type}CreateRequest request);
${entity}DTO toDto(${entity}Request request);
${type}DO to(${type}UpdateRequest request);
${entity}VO toVo(${entity} domain);
${type}DO to(${type}QueryRequest request);
${entity}DTO toDto(${entity} domain);
${type}VO to(${type}DO request);
List<${entity}VO> toVoListForDomain(List<${entity}> domain);
List<${entity}DTO> toDtoListForDomain(List<${entity}> domain);
${entity}VO toVo(${entity}DTO dto);
${entity} toDto(${entity}DTO dto);
List<${entity}VO> toVoListForDto(List<${entity}DTO> dto);
List<${entity}> toDoListForDto(List<${entity}DTO> dto);
List<${type}VO> to(List<${type}DO> list);
}

View File

@@ -1,164 +0,0 @@
package ${package.Entity};
#foreach($pkg in ${table.importPackages})
import ${pkg};
#end
#if(${springdoc})
import io.swagger.v3.oas.annotations.media.Schema;
#elseif(${swagger})
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
#end
#if(${entityLombokModel})
import lombok.Data;
import lombok.EqualsAndHashCode;
#if(${chainModel})
import lombok.experimental.Accessors;
#end
#end
/**
* $!{table.comment}
*
* @author ${author}
* @version 1.0.0
* @since ${date}
*/
#if(${entityLombokModel})
@Data
@EqualsAndHashCode(callSuper = true)
#if(${chainModel})
@Accessors(chain = true)
#end
#end
#if(${table.convert})
@TableName("${schemaName}${table.name}")
#end
#if(${springdoc})
@Schema(name = "${entity}", description = "$!{table.comment}")
#elseif(${swagger})
@ApiModel(value = "${entity}对象", description = "$!{table.comment}")
#end
#if(${superEntityClass})
public class ${entity} extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
#elseif(${activeRecord})
public class ${entity} extends Model<${entity}> {
#elseif(${entitySerialVersionUID})
public class ${entity} implements Serializable{
#else
public class ${entity} {
#end
#if(${entitySerialVersionUID})
private static final long serialVersionUID=1L;
#end
## ---------- BEGIN 字段循环遍历 ----------
#foreach($field in ${table.fields})
#if(${field.keyFlag})
#set($keyPropertyName=${field.propertyName})
#end
#if("$!field.comment" != "")
#if(${springdoc})
@Schema(description = "${field.comment}")
#elseif(${swagger})
@ApiModelProperty("${field.comment}")
#else
/**
* ${field.comment}
*/
#end
#end
#if(${field.keyFlag})
## 主键
#if(${field.keyIdentityFlag})
@TableId(value = "${field.annotationColumnName}", type = IdType.AUTO)
#elseif(!$null.isNull(${idType}) && "$!idType" != "")
@TableId(value = "${field.annotationColumnName}", type = IdType.${idType})
#elseif(${field.convert})
@TableId("${field.annotationColumnName}")
#end
## 普通字段
#elseif(${field.fill})
## ----- 存在字段填充设置 -----
#if(${field.convert})
@TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill})
#else
@TableField(fill = FieldFill.${field.fill})
#end
#elseif(${field.convert})
@TableField("${field.annotationColumnName}")
#end
## 乐观锁注解
#if(${field.versionField})
@Version
#end
## 逻辑删除注解
#if(${field.logicDeleteField})
@TableLogic
#end
private ${field.propertyType} ${field.propertyName};
#if(!$foreach.hasNext)
#end
#end
## ---------- END 字段循环遍历 ----------
#if(!${entityLombokModel})
#foreach($field in ${table.fields})
#if(${field.propertyType.equals("boolean")})
#set($getprefix="is")
#else
#set($getprefix="get")
#end
public ${field.propertyType} ${getprefix}${field.capitalName}(){
return ${field.propertyName};
}
#if(${chainModel})
public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}){
#else
public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
#end
this.${field.propertyName} = ${field.propertyName};
#if(${chainModel})
return this;
#end
}
#end
## --foreach end---
#end
## --end of #if(!${entityLombokModel})--
#if(${entityColumnConstant})
#foreach($field in ${table.fields})
public static final String ${field.name.toUpperCase()} ="${field.name}";
#end
#end
#if(${activeRecord})
@Override
public Serializable pkVal(){
#if(${keyPropertyName})
return this.${keyPropertyName};
#else
return null;
#end
}
#end
#if(!${entityLombokModel})
@Override
public String toString() {
return "${entity}{" +
#foreach($field in ${table.fields})
#if($!{foreach.index}==0)
"${field.propertyName} = " + ${field.propertyName} +
#else
", ${field.propertyName} = " + ${field.propertyName} +
#end
#end
"}";
}
#end
}

View File

@@ -0,0 +1,77 @@
package ${package.Entity};
import com.baomidou.mybatisplus.annotation.*;
import com.orion.ops.framework.mybatis.core.domain.BaseDO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
/**
* $!{table.comment} 数据库对象
*
* @author ${author}
* @version 1.0.0
* @since ${date}
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
#if(${table.convert})
@TableName("${schemaName}${table.name}")
#end
@Schema(name = "${entity}", description = "$!{table.comment} 数据库对象")
#if(${superEntityClass})
public class ${entity} extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
#elseif(${entitySerialVersionUID})
public class ${entity} implements Serializable{
#else
public class ${entity} {
#end
#if(${entitySerialVersionUID})
private static final long serialVersionUID=1L;
#end
## ---------- BEGIN 字段循环遍历 ----------
#foreach($field in ${table.fields})
#if(${field.keyFlag})
#set($keyPropertyName=${field.propertyName})
#end
#if("$!field.comment" != "")
@Schema(description = "${field.comment}")
#end
#if(${field.keyFlag})
## 主键
#if(${field.keyIdentityFlag})
@TableId(value = "${field.annotationColumnName}", type = IdType.AUTO)
#elseif(!$null.isNull(${idType}) && "$!idType" != "")
@TableId(value = "${field.annotationColumnName}", type = IdType.${idType})
#elseif(${field.convert})
@TableId("${field.annotationColumnName}")
#end
## 普通字段
#elseif(${field.fill})
## ----- 存在字段填充设置 -----
#if(${field.convert})
@TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill})
#else
@TableField(fill = FieldFill.${field.fill})
#end
#elseif(${field.convert})
@TableField("${field.annotationColumnName}")
#end
## 乐观锁注解
#if(${field.versionField})
@Version
#end
## 逻辑删除注解
#if(${field.logicDeleteField})
@TableLogic
#end
private ${field.propertyType} ${field.propertyName};
#end
}

View File

@@ -1,31 +1,30 @@
package ${package.Entity};
package ${currentPackage};
#foreach($pkg in ${table.importPackages})
import ${pkg};
#end
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.Date;
import java.io.Serializable;
import lombok.*;
import java.util.*;
/**
* $!{table.comment} VO
* $!{table.comment} 业务对象
*
* @author ${author}
* @version 1.0.0
* @since ${date}
*/
@Data
@Schema(name = "${entity}VO", description = "$!{table.comment}")
public class ${entity}VO implements Serializable {
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "${type}DTO", description = "$!{table.comment} 业务对象")
public class ${type}DTO implements Serializable {
private static final long serialVersionUID = 1L;
## ---------- BEGIN 字段循环遍历 ----------
#foreach($field in ${table.fields})
#if(${field.keyFlag})
#set($keyPropertyName=${field.propertyName})
#end
#if("$!field.comment" != "")
@Schema(description = "${field.comment}")
#end

View File

@@ -0,0 +1,35 @@
package ${currentPackage};
import io.swagger.v3.oas.annotations.media.Schema;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.*;
/**
* $!{table.comment} 创建请求对象
*
* @author ${author}
* @version 1.0.0
* @since ${date}
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "${type}CreateRequest", description = "$!{table.comment} 创建请求对象")
public class ${type}CreateRequest implements Serializable {
#foreach($field in ${table.fields})
#if("$!field.comment" != "")
@Schema(description = "${field.comment}")
#end
private ${field.propertyType} ${field.propertyName};
#end
}

View File

@@ -0,0 +1,31 @@
package ${currentPackage};
import com.orion.ops.framework.common.entity.PageRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
/**
* $!{table.comment} 查询请求对象
*
* @author ${author}
* @version 1.0.0
* @since ${date}
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Schema(name = "${type}QueryRequest", description = "$!{table.comment} 查询请求对象")
public class ${type}QueryRequest extends PageRequest {
#foreach($field in ${table.fields})
#if("$!field.comment" != "")
@Schema(description = "${field.comment}")
#end
private ${field.propertyType} ${field.propertyName};
#end
}

View File

@@ -0,0 +1,35 @@
package ${currentPackage};
import io.swagger.v3.oas.annotations.media.Schema;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.*;
/**
* $!{table.comment} 更新请求对象
*
* @author ${author}
* @version 1.0.0
* @since ${date}
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "${type}UpdateRequest", description = "$!{table.comment} 更新请求对象")
public class ${type}UpdateRequest implements Serializable {
#foreach($field in ${table.fields})
#if("$!field.comment" != "")
@Schema(description = "${field.comment}")
#end
private ${field.propertyType} ${field.propertyName};
#end
}

View File

@@ -1,31 +1,30 @@
package ${package.Entity};
package ${currentPackage};
#foreach($pkg in ${table.importPackages})
import ${pkg};
#end
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.Date;
import java.io.Serializable;
import lombok.*;
import java.util.*;
/**
* $!{table.comment}
* $!{table.comment} 视图响应对象
*
* @author ${author}
* @version 1.0.0
* @since ${date}
*/
@Data
@Schema(name = "${entity}DTO", description = "$!{table.comment}")
public class ${entity}DTO implements Serializable {
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "${type}VO", description = "$!{table.comment} 视图响应对象")
public class ${type}VO implements Serializable {
private static final long serialVersionUID = 1L;
## ---------- BEGIN 字段循环遍历 ----------
#foreach($field in ${table.fields})
#if(${field.keyFlag})
#set($keyPropertyName=${field.propertyName})
#end
#if("$!field.comment" != "")
@Schema(description = "${field.comment}")
#end

View File

@@ -10,15 +10,12 @@ import ${mapperAnnotationClass.name};
* $!{table.comment} Mapper 接口
*
* @author ${author}
* @version 1.0.0
* @since ${date}
*/
#if(${mapperAnnotationClass})
@${mapperAnnotationClass.simpleName}
#end
#if(${kotlin})
interface ${table.mapperName} : ${superMapperClass}<${entity}>
#else
public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {
}
#end

View File

@@ -1,33 +0,0 @@
package ${package.Entity};
#foreach($pkg in ${table.importPackages})
import ${pkg};
#end
import com.orion.lang.define.wrapper.PageRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* $!{table.comment}
*
* @author ${author}
* @version 1.0.0
* @since ${date}
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Schema(name = "${entity}Request", description = "$!{table.comment}")
public class ${entity}Request extends PageRequest {
#foreach($field in ${table.fields})
#if(${field.keyFlag})
#set($keyPropertyName=${field.propertyName})
#end
#if("$!field.comment" != "")
@Schema(description = "${field.comment}")
#end
private ${field.propertyType} ${field.propertyName};
#end
}

View File

@@ -1,28 +1,129 @@
package ${package.ServiceImpl};
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.lang.utils.Valid;
import com.orion.lang.utils.collect.Lists;
import com.orion.ops.framework.common.constant.ErrorCode;
import com.orion.ops.framework.common.constant.ErrorMessage;
import com.orion.ops.framework.mybatis.core.query.Conditions;
#foreach($pkg in ${customFilePackages})
import ${pkg}.*;
#end
import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
#if(${table.serviceInterface})
import ${package.Service}.${table.serviceName};
#end
import ${superServiceImplClassPackage};
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 1.0.0
* @since ${date}
*/
@Slf4j
@Service
#if(${kotlin})
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>()#if(${table.serviceInterface}), ${table.serviceName}#end {
public class ${table.serviceImplName} implements ${table.serviceName} {
// TODO 需要自行实现 page 和 check 方法
@Resource
private ${type}DAO ${typeLower}DAO;
@Override
public Long create${type}(${type}CreateRequest request){
// 转换
${type}DO record= ${type}Convert.MAPPER.to(request);
record.setId(null);
// 查询是否存在
if(this.check${type}Present(record)){
throw ErrorCode.DATA_PRESENT.exception();
}
// 插入
int effect= ${typeLower}DAO.insert(record);
log.info("${type}Service-add${type} effect: {}, domain: {}",effect,JSON.toJSONString(record));
return record.getId();
}
@Override
public Integer update${type}(${type}UpdateRequest request){
// 转换
${type}DO record= ${type}Convert.MAPPER.to(request);
Valid.notNull(request.getId(),ErrorMessage.ID_MISSING);
// 查询是否存在
if(this.check${type}Present(record)){
throw ErrorCode.DATA_PRESENT.exception();
}
// 更新
int effect= ${typeLower}DAO.updateById(record);
log.info("${type}Service-update${type} effect: {}, domain: {}",effect,JSON.toJSONString(record));
return effect;
}
@Override
public ${type}VO get${type}(Long id){
// 查询
${type}DO record= ${typeLower}DAO.selectById(id);
if(record==null){
throw ErrorCode.DATA_ABESENT.exception();
}
// 转换
return ${type}Convert.MAPPER.to(record);
}
@Override
public List<${type}VO> get${type}List(List<Long> idList){
// 查询
List<${type}DO> records= ${typeLower}DAO.selectBatchIds(idList);
if(records.isEmpty()){
return Lists.empty();
}
// 转换
return ${type}Convert.MAPPER.to(records);
}
@Override
public DataGrid<${type}VO> get${type}Page(${type}QueryRequest request){
// 构造条件
LambdaQueryWrapper<${type}DO> wrapper=Conditions.wrapper(${type}DO.class);
// 查询
return ${typeLower}DAO.of()
.wrapper(wrapper)
.page(request)
.dataGrid(${type}Convert.MAPPER::to);
}
@Override
public Integer delete${type}(Long id){
return ${typeLower}DAO.deleteById(id);
}
@Override
public Integer batchDelete${type}(List<Long> idList){
return ${typeLower}DAO.deleteBatchIds(idList);
}
/**
* 检测对象是否存在
*
* @param domain domain
* @return 是否存在
*/
private boolean check${type}Present(${type}DO domain){
// 构造条件
LambdaQueryWrapper<${type}DO> wrapper=Conditions.wrapper(${type}DO.class)
.eq(${type}DO::getId,domain.getId());
// .eq(XXXDO::getXXX, domain.getXXX());
// 检查是否存在
return ${typeLower}DAO.of()
.wrapper(wrapper)
.present();
}
}
#else
public class ${table.serviceImplName} implements ${table.serviceName} {
}
#end

View File

@@ -1,18 +1,75 @@
package ${package.Service};
import ${package.Entity}.${entity};
import ${superServiceClassPackage};
import com.orion.lang.define.wrapper.DataGrid;
#foreach($pkg in ${customFilePackages})
import ${pkg}.*;
#end
import java.util.List;
/**
* $!{table.comment} 服务类
*
* @author ${author}
* @version 1.0.0
* @since ${date}
*/
#if(${kotlin})
interface ${table.serviceName} : ${superServiceClass}<${entity}>
#else
public interface ${table.serviceName} {
/**
* 插入$!{table.comment}
*
* @param request request
* @return id
*/
Long create${type}(${type}CreateRequest request);
/**
* 通过 id 更新$!{table.comment}
*
* @param request request
* @return effect
*/
Integer update${type}(${type}UpdateRequest request);
/**
* 通过 id 查询$!{table.comment}
*
* @param id id
* @return row
*/
${type}VO get${type}(Long id);
/**
* 通过 id 批量查询$!{table.comment}
*
* @param idList idList
* @return rows
*/
List<${type}VO> get${type}List(List<Long> idList);
/**
* 分页查询$!{table.comment}
*
* @param request request
* @return rows
*/
DataGrid<${type}VO> get${type}Page(${type}QueryRequest request);
/**
* 通过 id 删除$!{table.comment}
*
* @param id id
* @return effect
*/
Integer delete${type}(Long id);
/**
* 通过 id 批量删除$!{table.comment}
*
* @param idList idList
* @return effect
*/
Integer batchDelete${type}(List<Long> idList);
}
#end

View File

@@ -0,0 +1,10 @@
### 心跳检测
GET {{baseUrl}}/server/bootstrap/health
Authorization: {{token}}
###
GET http://127.0.0.1:9200/infra/test-table/get
Authorization: {{token}}
###

View File

@@ -1,5 +0,0 @@
### 心跳检测
GET http://{{baseUrl}}/server/bootstrap/health
Accept: application/json
###