修改代码生成器模板.
This commit is contained in:
@@ -15,7 +15,6 @@ import org.hibernate.validator.constraints.Range;
|
||||
@Data
|
||||
public class PageRequest implements IPageRequest {
|
||||
|
||||
// TODO TEST
|
||||
@Range(min = 1, max = 10000)
|
||||
@Schema(description = "页码")
|
||||
private int page;
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* mybatis 配置类
|
||||
* TODO 扫描的包
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
|
||||
@@ -21,6 +21,8 @@ public class FieldFillHandler implements MetaObjectHandler {
|
||||
@Resource
|
||||
private SecurityHolder securityHolder;
|
||||
|
||||
// TODO 删除fill baseConst
|
||||
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
if (Objects.nonNull(metaObject) && metaObject.getOriginalObject() instanceof BaseDO) {
|
||||
@@ -36,7 +38,6 @@ public class FieldFillHandler implements MetaObjectHandler {
|
||||
baseDO.setUpdateTime(now);
|
||||
}
|
||||
|
||||
// TODO TEST
|
||||
Long userId = securityHolder.getLoginUserId();
|
||||
// 创建人
|
||||
if (Objects.nonNull(userId) && Objects.isNull(baseDO.getCreator())) {
|
||||
@@ -60,7 +61,6 @@ public class FieldFillHandler implements MetaObjectHandler {
|
||||
|
||||
// 更新人
|
||||
Object updater = getFieldValByName("updater", metaObject);
|
||||
// TODO TEST
|
||||
Long userId = securityHolder.getLoginUserId();
|
||||
if (Objects.nonNull(userId) && Objects.isNull(updater)) {
|
||||
setFieldValByName("updater", userId.toString(), metaObject);
|
||||
|
||||
@@ -7,8 +7,6 @@ import com.orion.lang.utils.Strings;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* TODO TEST
|
||||
* <p>
|
||||
* 有效性验证 wrapper
|
||||
*
|
||||
* @author Jiahang Li
|
||||
@@ -38,22 +36,22 @@ public class ValidateLambdaWrapper<T> extends LambdaQueryWrapper<T> {
|
||||
for (Object object : objects) {
|
||||
// 非 null 检测
|
||||
if (object == null) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
// 字符串 非空校验
|
||||
if (object instanceof String) {
|
||||
if (Strings.isBlank((String) object)) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// 集合 非空校验
|
||||
if (object instanceof Collection<?>) {
|
||||
if (((Collection<?>) object).isEmpty()) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,12 +3,12 @@ package ${package.Controller};
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.ops.framework.common.annotation.RestWrapper;
|
||||
import ${package.Service}.*;
|
||||
#foreach($pkg in ${customFilePackages})
|
||||
import ${pkg}.*;
|
||||
#end
|
||||
#if(${superControllerClassPackage})
|
||||
import ${superControllerClassPackage};
|
||||
#end
|
||||
#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;
|
||||
@@ -40,61 +40,61 @@ public class ${table.controllerName} extends ${superControllerClass} {
|
||||
public class ${table.controllerName} {
|
||||
#end
|
||||
|
||||
@Resource
|
||||
private ${type}Service ${typeLower}Service;
|
||||
@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){
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建$!{table.comment}")
|
||||
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:create')")
|
||||
public Long create${type}(@Validated @RequestBody ${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){
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新$!{table.comment}")
|
||||
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:update')")
|
||||
public Integer update${type}(@Validated @RequestBody ${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){
|
||||
@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){
|
||||
@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){
|
||||
@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){
|
||||
@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){
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ package ${currentPackage};
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import ${package.Entity}.*;
|
||||
#foreach($pkg in ${customFilePackages})
|
||||
import ${pkg}.*;
|
||||
#end
|
||||
#foreach($pkg in ${customFilePackages})
|
||||
import ${pkg}.*;
|
||||
#end
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -19,11 +19,11 @@ import java.util.List;
|
||||
@SuppressWarnings("ALL")
|
||||
public interface ${type}ProviderConvert {
|
||||
|
||||
${type}ProviderConvert MAPPER = Mappers.getMapper(${type}ProviderConvert.class);
|
||||
${type}ProviderConvert MAPPER = Mappers.getMapper(${type}ProviderConvert.class);
|
||||
|
||||
${type}DO to(${type}DTO dto);
|
||||
${type}DO to(${type}DTO dto);
|
||||
|
||||
${type}DTO to(${type}DO dto);
|
||||
${type}DTO to(${type}DO dto);
|
||||
|
||||
List<${type}DO> toDO(List<${type}DTO> list);
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ package ${currentPackage};
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import ${package.Entity}.*;
|
||||
#foreach($pkg in ${customFilePackages})
|
||||
import ${pkg}.*;
|
||||
#end
|
||||
#foreach($pkg in ${customFilePackages})
|
||||
import ${pkg}.*;
|
||||
#end
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -18,16 +18,16 @@ import java.util.List;
|
||||
@Mapper
|
||||
@SuppressWarnings("ALL")
|
||||
public interface ${type}Convert {
|
||||
|
||||
${type}Convert MAPPER = Mappers.getMapper(${type}Convert.class);
|
||||
|
||||
${type}Convert MAPPER = Mappers.getMapper(${type}Convert.class);
|
||||
${type}DO to(${type}CreateRequest request);
|
||||
|
||||
${type}DO to(${type}CreateRequest request);
|
||||
${type}DO to(${type}UpdateRequest request);
|
||||
|
||||
${type}DO to(${type}UpdateRequest request);
|
||||
${type}DO to(${type}QueryRequest request);
|
||||
|
||||
${type}DO to(${type}QueryRequest request);
|
||||
|
||||
${type}VO to(${type}DO request);
|
||||
${type}VO to(${type}DO request);
|
||||
|
||||
List<${type}VO> to(List<${type}DO> list);
|
||||
|
||||
|
||||
@@ -26,52 +26,52 @@ import java.util.*;
|
||||
#if(${superEntityClass})
|
||||
public class ${entity} extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
|
||||
#elseif(${entitySerialVersionUID})
|
||||
public class ${entity} implements Serializable{
|
||||
public class ${entity} implements Serializable {
|
||||
#else
|
||||
public class ${entity} {
|
||||
#end
|
||||
#if(${entitySerialVersionUID})
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
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(${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})
|
||||
#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})
|
||||
#end
|
||||
## 乐观锁注解
|
||||
#if(${field.versionField})
|
||||
@Version
|
||||
#end
|
||||
## 逻辑删除注解
|
||||
#if(${field.logicDeleteField})
|
||||
#end
|
||||
## 逻辑删除注解
|
||||
#if(${field.logicDeleteField})
|
||||
@TableLogic
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package ${currentPackage};
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.*;
|
||||
@@ -25,9 +23,9 @@ public class ${type}DTO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
#foreach($field in ${table.fields})
|
||||
|
||||
#if("$!field.comment" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
#if("$!field.comment" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package ${currentPackage};
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@@ -26,9 +24,9 @@ import java.util.*;
|
||||
public class ${type}CreateRequest implements Serializable {
|
||||
#foreach($field in ${table.fields})
|
||||
|
||||
#if("$!field.comment" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
#if("$!field.comment" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ import java.util.*;
|
||||
public class ${type}QueryRequest extends PageRequest {
|
||||
#foreach($field in ${table.fields})
|
||||
|
||||
#if("$!field.comment" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
#if("$!field.comment" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package ${currentPackage};
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@@ -26,9 +24,9 @@ import java.util.*;
|
||||
public class ${type}UpdateRequest implements Serializable {
|
||||
#foreach($field in ${table.fields})
|
||||
|
||||
#if("$!field.comment" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
#if("$!field.comment" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package ${currentPackage};
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.*;
|
||||
@@ -25,9 +23,9 @@ public class ${type}VO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
#foreach($field in ${table.fields})
|
||||
|
||||
#if("$!field.comment" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
#if("$!field.comment" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
|
||||
|
||||
@@ -18,4 +18,4 @@ import ${mapperAnnotationClass.name};
|
||||
#end
|
||||
public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,38 +2,38 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="${package.Mapper}.${table.mapperName}">
|
||||
|
||||
#if(${enableCache})
|
||||
<!-- 开启二级缓存 -->
|
||||
<cache type="${cacheClassName}"/>
|
||||
#if(${enableCache})
|
||||
<!-- 开启二级缓存 -->
|
||||
<cache type="${cacheClassName}"/>
|
||||
|
||||
#end
|
||||
#if(${baseResultMap})
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="${package.Entity}.${entity}">
|
||||
#foreach($field in ${table.fields})
|
||||
#if(${field.keyFlag})##生成主键排在第一位
|
||||
<id column="${field.name}" property="${field.propertyName}"/>
|
||||
#end
|
||||
#end
|
||||
#foreach($field in ${table.commonFields})##生成公共字段
|
||||
<result column="${field.name}" property="${field.propertyName}"/>
|
||||
#end
|
||||
#foreach($field in ${table.fields})
|
||||
#if(!${field.keyFlag})##生成普通字段
|
||||
<result column="${field.name}" property="${field.propertyName}"/>
|
||||
#end
|
||||
#end
|
||||
</resultMap>
|
||||
#end
|
||||
#if(${baseResultMap})
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="${package.Entity}.${entity}">
|
||||
#foreach($field in ${table.fields})
|
||||
#if(${field.keyFlag})##生成主键排在第一位
|
||||
<id column="${field.name}" property="${field.propertyName}"/>
|
||||
#end
|
||||
#end
|
||||
#foreach($field in ${table.commonFields})##生成公共字段
|
||||
<result column="${field.name}" property="${field.propertyName}"/>
|
||||
#end
|
||||
#foreach($field in ${table.fields})
|
||||
#if(!${field.keyFlag})##生成普通字段
|
||||
<result column="${field.name}" property="${field.propertyName}"/>
|
||||
#end
|
||||
#end
|
||||
</resultMap>
|
||||
|
||||
#end
|
||||
#if(${baseColumnList})
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
#foreach($field in ${table.commonFields})
|
||||
${field.columnName},
|
||||
#end
|
||||
${table.fieldNames}
|
||||
</sql>
|
||||
#end
|
||||
#if(${baseColumnList})
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
#foreach($field in ${table.commonFields})
|
||||
${field.columnName},
|
||||
#end
|
||||
${table.fieldNames}
|
||||
</sql>
|
||||
|
||||
#end
|
||||
#end
|
||||
</mapper>
|
||||
|
||||
@@ -8,9 +8,9 @@ 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
|
||||
#foreach($pkg in ${customFilePackages})
|
||||
import ${pkg}.*;
|
||||
#end
|
||||
import ${package.Entity}.${entity};
|
||||
import ${package.Mapper}.${table.mapperName};
|
||||
import ${package.Service}.${table.serviceName};
|
||||
@@ -31,99 +31,97 @@ import java.util.List;
|
||||
@Service
|
||||
public class ${table.serviceImplName} implements ${table.serviceName} {
|
||||
|
||||
// TODO 需要自行实现 page 和 check 方法
|
||||
// TODO 需要自行实现 page 和 check 方法
|
||||
|
||||
@Resource
|
||||
private ${type}DAO ${typeLower}DAO;
|
||||
@Resource
|
||||
private ${type}DAO ${typeLower}DAO;
|
||||
|
||||
@Override
|
||||
public Long create${type}(${type}CreateRequest request){
|
||||
@Override
|
||||
public Long create${type}(${type}CreateRequest request) {
|
||||
// 转换
|
||||
${type}DO record= ${type}Convert.MAPPER.to(request);
|
||||
${type}DO record = ${type}Convert.MAPPER.to(request);
|
||||
record.setId(null);
|
||||
// 查询是否存在
|
||||
if(this.check${type}Present(record)){
|
||||
throw ErrorCode.DATA_PRESENT.exception();
|
||||
}
|
||||
this.checkTestTablePresent(record);
|
||||
// 插入
|
||||
int effect= ${typeLower}DAO.insert(record);
|
||||
log.info("${type}Service-add${type} effect: {}, domain: {}",effect,JSON.toJSONString(record));
|
||||
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){
|
||||
@Override
|
||||
public Integer update${type}(${type}UpdateRequest request) {
|
||||
// 转换
|
||||
${type}DO record= ${type}Convert.MAPPER.to(request);
|
||||
Valid.notNull(request.getId(),ErrorMessage.ID_MISSING);
|
||||
${type}DO record = ${type}Convert.MAPPER.to(request);
|
||||
Valid.notNull(record.getId(), ErrorMessage.ID_MISSING);
|
||||
// 查询是否存在
|
||||
if(this.check${type}Present(record)){
|
||||
throw ErrorCode.DATA_PRESENT.exception();
|
||||
}
|
||||
this.checkTestTablePresent(record);
|
||||
// 更新
|
||||
int effect= ${typeLower}DAO.updateById(record);
|
||||
log.info("${type}Service-update${type} effect: {}, domain: {}",effect,JSON.toJSONString(record));
|
||||
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){
|
||||
@Override
|
||||
public ${type}VO get${type}(Long id) {
|
||||
// 查询
|
||||
${type}DO record= ${typeLower}DAO.selectById(id);
|
||||
if(record==null){
|
||||
throw ErrorCode.DATA_ABESENT.exception();
|
||||
${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){
|
||||
@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();
|
||||
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){
|
||||
@Override
|
||||
public DataGrid<${type}VO> get${type}Page(${type}QueryRequest request) {
|
||||
// 构造条件
|
||||
LambdaQueryWrapper<${type}DO> wrapper=Conditions.wrapper(${type}DO.class);
|
||||
LambdaQueryWrapper<${type}DO> wrapper = Conditions.wrapper(${type}DO.class);
|
||||
// 查询
|
||||
return ${typeLower}DAO.of()
|
||||
.wrapper(wrapper)
|
||||
.page(request)
|
||||
.dataGrid(${type}Convert.MAPPER::to);
|
||||
}
|
||||
.wrapper(wrapper)
|
||||
.page(request)
|
||||
.dataGrid(${type}Convert.MAPPER::to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer delete${type}(Long id){
|
||||
@Override
|
||||
public Integer delete${type}(Long id) {
|
||||
return ${typeLower}DAO.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer batchDelete${type}(List<Long> idList){
|
||||
@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){
|
||||
/**
|
||||
* 检测对象是否存在
|
||||
*
|
||||
* @param domain domain
|
||||
*/
|
||||
private void check${type}Present(${type}DO domain) {
|
||||
// 构造条件
|
||||
LambdaQueryWrapper<${type}DO> wrapper=Conditions.wrapper(${type}DO.class)
|
||||
.eq(${type}DO::getId,domain.getId());
|
||||
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();
|
||||
boolean present = testTableDAO.of()
|
||||
.wrapper(wrapper)
|
||||
.present();
|
||||
if (present) {
|
||||
throw ErrorCode.DATA_PRESENT.exception();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package ${package.Service};
|
||||
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
#foreach($pkg in ${customFilePackages})
|
||||
import ${pkg}.*;
|
||||
#end
|
||||
#foreach($pkg in ${customFilePackages})
|
||||
import ${pkg}.*;
|
||||
#end
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -16,60 +16,60 @@ import java.util.List;
|
||||
*/
|
||||
public interface ${table.serviceName} {
|
||||
|
||||
/**
|
||||
* 插入$!{table.comment}
|
||||
*
|
||||
* @param request request
|
||||
* @return id
|
||||
*/
|
||||
Long create${type}(${type}CreateRequest request);
|
||||
/**
|
||||
* 插入$!{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 request request
|
||||
* @return effect
|
||||
*/
|
||||
Integer update${type}(${type}UpdateRequest request);
|
||||
|
||||
/**
|
||||
* 通过 id 查询$!{table.comment}
|
||||
*
|
||||
* @param id id
|
||||
* @return row
|
||||
*/
|
||||
/**
|
||||
* 通过 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);
|
||||
/**
|
||||
* 通过 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);
|
||||
/**
|
||||
* 分页查询$!{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 id id
|
||||
* @return effect
|
||||
*/
|
||||
Integer delete${type}(Long id);
|
||||
|
||||
/**
|
||||
* 通过 id 批量删除$!{table.comment}
|
||||
*
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer batchDelete${type}(List<Long> idList);
|
||||
/**
|
||||
* 通过 id 批量删除$!{table.comment}
|
||||
*
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer batchDelete${type}(List<Long> idList);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class OrionSwaggerAutoConfiguration {
|
||||
Map<String, SecurityScheme> securitySchemas = this.buildSecuritySchemes();
|
||||
OpenAPI api = new OpenAPI()
|
||||
// 接口信息
|
||||
.info(buildInfo(properties))
|
||||
.info(this.buildInfo(properties))
|
||||
// 接口安全配置
|
||||
.components(new Components().securitySchemes(securitySchemas));
|
||||
securitySchemas.keySet()
|
||||
@@ -109,13 +109,12 @@ public class OrionSwaggerAutoConfiguration {
|
||||
propertyResolverUtils, openApiBuilderCustomizers, serverBaseUrlCustomizers, javadocProvider);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return 所有模块的 api 分组
|
||||
*/
|
||||
@Bean
|
||||
public GroupedOpenApi allGroupedOpenApi() {
|
||||
return buildGroupedOpenApi("全部", "");
|
||||
return buildGroupedOpenApi("全部", "*");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -74,8 +74,8 @@ public class GlobalExceptionHandler {
|
||||
@ExceptionHandler(value = BindException.class)
|
||||
public HttpWrapper<?> paramBindExceptionHandler(BindException ex) {
|
||||
log.error("paramBindExceptionHandler", ex);
|
||||
FieldError error = ex.getFieldError();
|
||||
return ErrorCode.BAD_REQUEST.wrapper().msg(Objects.requireNonNull(error).getDefaultMessage());
|
||||
FieldError error = Objects.requireNonNull(ex.getFieldError());
|
||||
return ErrorCode.BAD_REQUEST.wrapper().msg(error.getField() + " " + error.getDefaultMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = ConstraintViolationException.class)
|
||||
|
||||
Reference in New Issue
Block a user