修改代码生成器包.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
${httpComment} ${apiComment.create}
|
||||
POST {{baseUrl}}/${package.ModuleName}/${typeHyphen}/create
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
#foreach($field in ${table.fields})
|
||||
#if("$!field.propertyName" != "id")
|
||||
"${field.propertyName}": ""#if($foreach.hasNext),#end
|
||||
#end
|
||||
#end
|
||||
}
|
||||
|
||||
|
||||
${httpComment} ${apiComment.update}
|
||||
PUT {{baseUrl}}/${package.ModuleName}/${typeHyphen}/update
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
#foreach($field in ${table.fields})
|
||||
"${field.propertyName}": ""#if($foreach.hasNext),#end
|
||||
#end
|
||||
}
|
||||
|
||||
|
||||
${httpComment} ${apiComment.get}
|
||||
GET {{baseUrl}}/${package.ModuleName}/${typeHyphen}/get?id=1
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
${httpComment} ${apiComment.list}
|
||||
GET {{baseUrl}}/${package.ModuleName}/${typeHyphen}/list?idList=1,2,3
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
${httpComment} ${apiComment.query}
|
||||
POST {{baseUrl}}/${package.ModuleName}/${typeHyphen}/query
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
#foreach($field in ${table.fields})
|
||||
"${field.propertyName}": ""#if($foreach.hasNext),#end
|
||||
#end
|
||||
}
|
||||
|
||||
|
||||
${httpComment} ${apiComment.delete}
|
||||
DELETE {{baseUrl}}/${package.ModuleName}/${typeHyphen}/delete?id=1
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
${httpComment} ${apiComment.batchDelete}
|
||||
DELETE {{baseUrl}}/${package.ModuleName}/${typeHyphen}/delete-batch?idList=1,2,3
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
${httpComment}
|
||||
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package ${package.Controller};
|
||||
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.ops.framework.common.annotation.IgnoreLog;
|
||||
import com.orion.ops.framework.common.annotation.RestWrapper;
|
||||
import com.orion.ops.framework.common.constant.IgnoreLogMode;
|
||||
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
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Tag(name = "${package.ModuleName} - $!{table.comment}服务")
|
||||
@Slf4j
|
||||
@Validated
|
||||
@RestWrapper
|
||||
@RestController
|
||||
@RequestMapping("/${package.ModuleName}/${typeHyphen}")
|
||||
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
|
||||
#if(${superControllerClass})
|
||||
public class ${table.controllerName} extends ${superControllerClass} {
|
||||
#else
|
||||
public class ${table.controllerName} {
|
||||
#end
|
||||
|
||||
@Resource
|
||||
private ${type}Service ${typeLower}Service;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "${apiComment.create}")
|
||||
@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 = "${apiComment.update}")
|
||||
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:update')")
|
||||
public Integer update${type}(@Validated @RequestBody ${type}UpdateRequest request) {
|
||||
return ${typeLower}Service.update${type}(request);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "${apiComment.get}")
|
||||
@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);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "${apiComment.list}")
|
||||
@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);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@PostMapping("/query")
|
||||
@Operation(summary = "${apiComment.query}")
|
||||
@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);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "${apiComment.delete}")
|
||||
@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);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-batch")
|
||||
@Operation(summary = "${apiComment.batchDelete}")
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
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);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
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}Convert {
|
||||
|
||||
${type}Convert MAPPER = Mappers.getMapper(${type}Convert.class);
|
||||
|
||||
${type}DO to(${type}CreateRequest request);
|
||||
|
||||
${type}DO to(${type}UpdateRequest request);
|
||||
|
||||
${type}DO to(${type}QueryRequest request);
|
||||
|
||||
${type}VO to(${type}DO domain);
|
||||
|
||||
List<${type}VO> to(List<${type}DO> list);
|
||||
|
||||
}
|
||||
@@ -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 ${since}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
#if(${table.convert})
|
||||
@TableName(value = "${schemaName}${table.name}", autoResultMap = true)
|
||||
#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
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package ${currentPackage};
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.io.Serializable;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* $!{table.comment} 业务对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "${type}DTO", description = "$!{table.comment} 业务对象")
|
||||
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
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@Schema(description = "修改时间")
|
||||
private Date updateTime;
|
||||
|
||||
@Schema(description = "创建人")
|
||||
private String creator;
|
||||
|
||||
@Schema(description = "修改人")
|
||||
private String updater;
|
||||
|
||||
}
|
||||
@@ -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}CreateRequest", description = "$!{table.comment} 创建请求对象")
|
||||
public class ${type}CreateRequest 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,35 @@
|
||||
package ${currentPackage};
|
||||
|
||||
import com.orion.ops.framework.common.entity.PageRequest;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* $!{table.comment} 查询请求对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @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.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}UpdateRequest", description = "$!{table.comment} 更新请求对象")
|
||||
public class ${type}UpdateRequest 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,44 @@
|
||||
package ${currentPackage};
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.io.Serializable;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* $!{table.comment} 视图响应对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "${type}VO", description = "$!{table.comment} 视图响应对象")
|
||||
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
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@Schema(description = "修改时间")
|
||||
private Date updateTime;
|
||||
|
||||
@Schema(description = "创建人")
|
||||
private String creator;
|
||||
|
||||
@Schema(description = "修改人")
|
||||
private String updater;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package ${package.Mapper};
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import ${package.Entity}.${entity};
|
||||
import ${superMapperClassPackage};
|
||||
#if(${mapperAnnotationClass})
|
||||
import ${mapperAnnotationClass.name};
|
||||
#end
|
||||
|
||||
/**
|
||||
* $!{table.comment} Mapper 接口
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${mapperAnnotationClass})
|
||||
@${mapperAnnotationClass.simpleName}
|
||||
#end
|
||||
public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {
|
||||
|
||||
/**
|
||||
* 获取全部条件
|
||||
*
|
||||
* @param entity entity
|
||||
* @return 全部条件
|
||||
*/
|
||||
default LambdaQueryWrapper<${entity}> condition(${entity} entity) {
|
||||
return this.wrapper()
|
||||
#foreach($field in ${table.fields})
|
||||
.eq(${type}DO::get${field.capitalName}, entity.get${field.capitalName}())#if(!$foreach.hasNext);#end
|
||||
#end
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!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}"/>
|
||||
|
||||
#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})#if(${foreach.count} == 1) #end${field.columnName}, #end${table.fieldNames}
|
||||
</sql>
|
||||
|
||||
#end
|
||||
</mapper>
|
||||
@@ -0,0 +1,134 @@
|
||||
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.collect.Lists;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
#foreach($pkg in ${customFilePackages})
|
||||
import ${pkg}.*;
|
||||
#end
|
||||
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 ${table.serviceImplName} implements ${table.serviceName} {
|
||||
|
||||
@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);
|
||||
// 查询数据是否冲突
|
||||
this.check${type}Present(record);
|
||||
// 插入
|
||||
int effect = ${typeLower}DAO.insert(record);
|
||||
log.info("${type}Service-create${type} effect: {}, record: {}", effect, JSON.toJSONString(record));
|
||||
return record.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer update${type}(${type}UpdateRequest request) {
|
||||
// 查询
|
||||
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
|
||||
${type}DO record = ${typeLower}DAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 转换
|
||||
${type}DO updateRecord = ${type}Convert.MAPPER.to(request);
|
||||
// 查询数据是否冲突
|
||||
this.check${type}Present(updateRecord);
|
||||
// 更新
|
||||
int effect = ${typeLower}DAO.updateById(updateRecord);
|
||||
log.info("${type}Service-update${type} effect: {}, updateRecord: {}", effect, JSON.toJSONString(updateRecord));
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ${type}VO get${type}(Long id) {
|
||||
// 查询
|
||||
${type}DO record = ${typeLower}DAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 转换
|
||||
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 = ${typeLower}DAO.wrapper()
|
||||
#foreach($field in ${table.fields})
|
||||
.eq(${type}DO::get${field.capitalName}, request.get${field.capitalName}())
|
||||
#end
|
||||
.orderByDesc(${type}DO::getId);
|
||||
// 查询
|
||||
return ${typeLower}DAO.of()
|
||||
.wrapper(wrapper)
|
||||
.page(request)
|
||||
.dataGrid(${type}Convert.MAPPER::to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer delete${type}(Long id) {
|
||||
int effect = ${typeLower}DAO.deleteById(id);
|
||||
log.info("${type}Service-delete${type} id: {}, effect: {}", id, effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer batchDelete${type}(List<Long> idList) {
|
||||
int effect = ${typeLower}DAO.deleteBatchIds(idList);
|
||||
log.info("${type}Service-batchDelete${type} idList: {}, effect: {}", JSON.toJSONString(idList), effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测对象是否存在
|
||||
*
|
||||
* @param domain domain
|
||||
*/
|
||||
private void check${type}Present(${type}DO domain) {
|
||||
// 构造条件
|
||||
LambdaQueryWrapper<${type}DO> wrapper = ${typeLower}DAO.wrapper()
|
||||
// 更新时忽略当前记录
|
||||
.ne(${type}DO::getId, domain.getId())
|
||||
// 用其他字段做重复校验
|
||||
#foreach($field in ${table.fields})
|
||||
#if("$!field.propertyName" != "id")
|
||||
.eq(${type}DO::get${field.capitalName}, domain.get${field.capitalName}())#if(!$foreach.hasNext);#end
|
||||
#end
|
||||
#end
|
||||
// 检查是否存在
|
||||
boolean present = ${typeLower}DAO.of().wrapper(wrapper).present();
|
||||
Valid.isFalse(present, ErrorMessage.DATA_PRESENT);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package ${package.Service};
|
||||
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
#foreach($pkg in ${customFilePackages})
|
||||
import ${pkg}.*;
|
||||
#end
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* $!{table.comment} 服务类
|
||||
*
|
||||
* @author ${author}
|
||||
* @version ${since}
|
||||
* @since ${date}
|
||||
*/
|
||||
public interface ${table.serviceName} {
|
||||
|
||||
/**
|
||||
* ${apiComment.create}
|
||||
*
|
||||
* @param request request
|
||||
* @return id
|
||||
*/
|
||||
Long create${type}(${type}CreateRequest request);
|
||||
|
||||
/**
|
||||
* ${apiComment.update}
|
||||
*
|
||||
* @param request request
|
||||
* @return effect
|
||||
*/
|
||||
Integer update${type}(${type}UpdateRequest request);
|
||||
|
||||
/**
|
||||
* ${apiComment.get}
|
||||
*
|
||||
* @param id id
|
||||
* @return row
|
||||
*/
|
||||
${type}VO get${type}(Long id);
|
||||
|
||||
/**
|
||||
* ${apiComment.list}
|
||||
*
|
||||
* @param idList idList
|
||||
* @return rows
|
||||
*/
|
||||
List<${type}VO> get${type}List(List<Long> idList);
|
||||
|
||||
/**
|
||||
* ${apiComment.query}
|
||||
*
|
||||
* @param request request
|
||||
* @return rows
|
||||
*/
|
||||
DataGrid<${type}VO> get${type}Page(${type}QueryRequest request);
|
||||
|
||||
/**
|
||||
* ${apiComment.delete}
|
||||
*
|
||||
* @param id id
|
||||
* @return effect
|
||||
*/
|
||||
Integer delete${type}(Long id);
|
||||
|
||||
/**
|
||||
* ${apiComment.batchDelete}
|
||||
*
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer batchDelete${type}(List<Long> idList);
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
api
|
||||
@@ -0,0 +1 @@
|
||||
form
|
||||
@@ -0,0 +1 @@
|
||||
table
|
||||
@@ -0,0 +1 @@
|
||||
index
|
||||
@@ -0,0 +1 @@
|
||||
e.types.ts
|
||||
@@ -0,0 +1 @@
|
||||
orion-vue-views-types-form.rules.ts
|
||||
@@ -0,0 +1 @@
|
||||
orion-vue-views-types-table.columns.ts.vm
|
||||
Reference in New Issue
Block a user