refactor: 代码生成临时提交
This commit is contained in:
175
src/main/resources/application-generator.yml
Normal file
175
src/main/resources/application-generator.yml
Normal file
@@ -0,0 +1,175 @@
|
||||
server:
|
||||
port: 8989
|
||||
|
||||
spring:
|
||||
jackson:
|
||||
## 默认序列化时间格式
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
## 默认序列化时区
|
||||
time-zone: GMT+8
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://www.youlai.tech:3306/youlai_boot?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&allowMultiQueries=true
|
||||
username: root
|
||||
password: YoulaiWuhui@2023
|
||||
data:
|
||||
redis:
|
||||
database: 0
|
||||
host: www.youlai.tech
|
||||
port: 6379
|
||||
# 如果Redis 服务未设置密码,需要将password删掉或注释,而不是设置为空字符串
|
||||
password: 123456
|
||||
|
||||
timeout: 10s
|
||||
lettuce:
|
||||
pool:
|
||||
# 连接池最大连接数 默认8 ,负数表示没有限制
|
||||
max-active: 8
|
||||
# 连接池最大阻塞等待时间(使用负值表示没有限制) 默认-1
|
||||
max-wait: -1
|
||||
# 连接池中的最大空闲连接 默认8
|
||||
max-idle: 8
|
||||
# 连接池中的最小空闲连接 默认0
|
||||
min-idle: 0
|
||||
cache:
|
||||
enabled: false
|
||||
# 缓存类型 redis、none(不使用缓存)
|
||||
type: redis
|
||||
# 缓存时间(单位:ms)
|
||||
redis:
|
||||
time-to-live: 3600000
|
||||
# 缓存null值,防止缓存穿透
|
||||
cache-null-values: true
|
||||
mybatis-plus:
|
||||
global-config:
|
||||
db-config:
|
||||
# 主键ID类型
|
||||
id-type: none
|
||||
# 逻辑删除字段名称
|
||||
logic-delete-field: deleted
|
||||
# 逻辑删除-删除值
|
||||
logic-delete-value: 1
|
||||
# 逻辑删除-未删除值
|
||||
logic-not-delete-value: 0
|
||||
configuration:
|
||||
# 驼峰下划线转换
|
||||
map-underscore-to-camel-case: true
|
||||
# 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
|
||||
# 安全配置
|
||||
security:
|
||||
jwt:
|
||||
# JWT 秘钥
|
||||
key: SecretKey012345678901234567890123456789012345678901234567890123456789
|
||||
# JWT 有效期(单位:秒)
|
||||
ttl: 7200
|
||||
ignore-urls:
|
||||
- /v3/api-docs/**
|
||||
- /doc.html
|
||||
- /swagger-resources/**
|
||||
- /webjars/**
|
||||
- /doc.html
|
||||
- /swagger-ui/**
|
||||
- /swagger-ui.html
|
||||
- /api/v1/auth/captcha
|
||||
- /ws/**
|
||||
- /ws-app/**
|
||||
|
||||
oss:
|
||||
# OSS 类型 (目前支持aliyun、minio)
|
||||
type: minio
|
||||
# MinIO 对象存储服务
|
||||
minio:
|
||||
# 服务Endpoint
|
||||
endpoint: http://localhost:9000
|
||||
# 访问凭据
|
||||
access-key: minioadmin
|
||||
# 凭据密钥
|
||||
secret-key: minioadmin
|
||||
# 存储桶名称
|
||||
bucket-name: default
|
||||
# (可选)自定义域名,如果配置了域名,生成的文件URL是域名格式,未配置则URL则是IP格式 (eg: https://oss.youlai.tech)
|
||||
custom-domain:
|
||||
# 阿里云OSS对象存储服务
|
||||
aliyun:
|
||||
# 服务Endpoint
|
||||
endpoint: oss-cn-hangzhou.aliyuncs.com
|
||||
# 访问凭据
|
||||
access-key-id: your-access-key-id
|
||||
# 凭据密钥
|
||||
access-key-secret: your-access-key-secret
|
||||
# 存储桶名称
|
||||
bucket-name: default
|
||||
|
||||
# springdoc配置: https://springdoc.org/properties.html
|
||||
springdoc:
|
||||
swagger-ui:
|
||||
path: /swagger-ui.html
|
||||
operationsSorter: alpha
|
||||
tags-sorter: alpha
|
||||
api-docs:
|
||||
path: /v3/api-docs
|
||||
group-configs:
|
||||
- group: 'default'
|
||||
paths-to-match: '/**'
|
||||
packages-to-scan: com.youlai.system.controller
|
||||
default-flat-param-object: true
|
||||
|
||||
# knife4j 接口文档配置
|
||||
knife4j:
|
||||
# 是否开启 Knife4j 增强功能
|
||||
enable: true # 设置为 true 表示开启增强功能
|
||||
# 生产环境配置
|
||||
production: false # 设置为 true 表示在生产环境中不显示文档,为 false 表示显示文档(通常在开发环境中使用)
|
||||
setting:
|
||||
language: zh_cn
|
||||
|
||||
# xxl-job 定时任务配置
|
||||
xxl:
|
||||
job:
|
||||
# 定时任务开关
|
||||
enabled: false
|
||||
admin:
|
||||
# 多个地址使用,分割
|
||||
addresses: http://127.0.0.1:8080/xxl-job-admin
|
||||
accessToken: default_token
|
||||
executor:
|
||||
appname: xxl-job-executor-${spring.application.name}
|
||||
address:
|
||||
ip:
|
||||
port: 9999
|
||||
logpath: /data/applogs/xxl-job/jobhandler
|
||||
logretentiondays: 30
|
||||
|
||||
# 验证码配置
|
||||
captcha:
|
||||
# 验证码类型 circle-圆圈干扰验证码|gif-Gif验证码|line-干扰线验证码|shear-扭曲干扰验证码
|
||||
type: circle
|
||||
# 验证码宽度
|
||||
width: 120
|
||||
# 验证码高度
|
||||
height: 40
|
||||
# 验证码干扰元素个数
|
||||
interfere-count: 2
|
||||
# 文本透明度(0.0-1.0)
|
||||
text-alpha: 0.8
|
||||
# 验证码字符配置
|
||||
code:
|
||||
# 验证码字符类型 math-算术|random-随机字符
|
||||
type: math
|
||||
# 验证码字符长度,type=算术时,表示运算位数(1:个位数运算 2:十位数运算);type=随机字符时,表示字符个数
|
||||
length: 1
|
||||
# 验证码字体
|
||||
font:
|
||||
# 字体名称 Dialog|DialogInput|Monospaced|Serif|SansSerif
|
||||
name: SansSerif
|
||||
# 字体样式 0-普通|1-粗体|2-斜体
|
||||
weight: 1
|
||||
# 字体大小
|
||||
size: 24
|
||||
# 验证码有效期(秒)
|
||||
expire-seconds: 120
|
||||
|
||||
@@ -2,4 +2,6 @@ spring:
|
||||
application:
|
||||
name: youlai-boot
|
||||
profiles:
|
||||
active: dev
|
||||
active: dev
|
||||
include:
|
||||
- generator
|
||||
43
src/main/resources/mapper/DatabaseMapper.xml
Normal file
43
src/main/resources/mapper/DatabaseMapper.xml
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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="com.youlai.system.mapper.DatabaseMapper">
|
||||
|
||||
<!-- 查询数据库表分页 -->
|
||||
<select id="getTablePage" resultType="com.youlai.system.model.vo.TablePageVO">
|
||||
SELECT
|
||||
TABLE_NAME ,
|
||||
TABLE_COMMENT ,
|
||||
TABLE_COLLATION,
|
||||
ENGINE,
|
||||
CREATE_TIME
|
||||
FROM
|
||||
information_schema.tables
|
||||
WHERE
|
||||
TABLE_SCHEMA = (SELECT DATABASE())
|
||||
AND table_type = 'BASE TABLE'
|
||||
<if test="queryParams.keywords != null and queryParams.keywords.trim() neq ''">
|
||||
AND TABLE_NAME LIKE CONCAT('%',#{queryParams.keywords},'%')
|
||||
</if>
|
||||
ORDER BY
|
||||
CREATE_TIME DESC
|
||||
</select>
|
||||
|
||||
<select id="getTableColumns" resultType="com.youlai.system.model.vo.TableColumnVO">
|
||||
SELECT
|
||||
COLUMN_NAME,
|
||||
DATA_TYPE,
|
||||
COLUMN_COMMENT,
|
||||
CASE COLUMN_KEY WHEN 'PRI' THEN 1 ELSE 0 END AS isPrimaryKey,
|
||||
IS_NULLABLE,
|
||||
CHARACTER_MAXIMUM_LENGTH,
|
||||
CHARACTER_SET_NAME,
|
||||
COLLATION_NAME
|
||||
FROM
|
||||
information_schema.columns
|
||||
WHERE
|
||||
TABLE_SCHEMA = (SELECT DATABASE())
|
||||
AND TABLE_NAME = #{tableName}
|
||||
</select>
|
||||
</mapper>
|
||||
72
src/main/resources/templates/generator/controller.java.vm
Normal file
72
src/main/resources/templates/generator/controller.java.vm
Normal file
@@ -0,0 +1,72 @@
|
||||
package ${package}.controller;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ${package}.model.form.${entityName}Form;
|
||||
import ${package}.model.query.${entityName}PageQuery;
|
||||
import ${package}.model.vo.${entityName}PageVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.youlai.common.result.PageResult;
|
||||
import com.youlai.common.result.Result;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
/**
|
||||
* $!{tableComment} 前端控制器
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Tag(name = "${tableComment}接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/${lowerFirstEntityName}s")
|
||||
@RequiredArgsConstructor
|
||||
public class ${entityName}Controller {
|
||||
|
||||
private final ${entityName}Serivie ${lowerFirstEntityName}Service;
|
||||
|
||||
@Operation(summary = "$!{tableComment}分页列表")
|
||||
@GetMapping("/page")
|
||||
public PageResult<${entityName}PageVO> get${entityName}Page(${entityName}PageQuery queryParams ) {
|
||||
IPage<${entityName}PageVO> result = ${lowerFirstEntityName}Service.get${entityName}Page(queryParams);
|
||||
return PageResult.success(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "新增$!{tableComment}")
|
||||
@PostMapping
|
||||
public Result save${entityName}(@RequestBody @Valid ${entityName}Form formData ) {
|
||||
boolean result = ${lowerFirstEntityName}Service.save${entityName}(formData);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "$!{tableComment}表单数据")
|
||||
@GetMapping("/{id}/form")
|
||||
public Result<${entityName}Form> get${entityName}Form(
|
||||
@Parameter(description = "$!{tableComment}ID") @PathVariable Long id
|
||||
) {
|
||||
${entityName}Form formData = ${lowerFirstEntityName}Service.get${entityName}FormData(id);
|
||||
return Result.success(formData);
|
||||
}
|
||||
|
||||
@Operation(summary = "修改$!{tableComment}")
|
||||
@PutMapping(value = "/{id}")
|
||||
public Result update${entityName}(@Parameter(description = "$!{tableComment}ID") @PathVariable Long id,
|
||||
@RequestBody @Validated ${entityName}Form formData) {
|
||||
boolean result = ${lowerFirstEntityName}Service.update${entityName}(id, formData);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除$!{tableComment}")
|
||||
@DeleteMapping("/{ids}")
|
||||
public Result delete${entityName}s(
|
||||
@Parameter(description = "$!{tableComment}ID,多个以英文逗号(,)分割") @PathVariable String ids
|
||||
) {
|
||||
boolean result = ${lowerFirstEntityName}Service.delete${entityName}s(ids);
|
||||
return Result.judge(result);
|
||||
}
|
||||
}
|
||||
20
src/main/resources/templates/generator/converter.java.vm
Normal file
20
src/main/resources/templates/generator/converter.java.vm
Normal file
@@ -0,0 +1,20 @@
|
||||
package ${package}.converter;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import ${package}.model.entity.${entityName};
|
||||
import ${package}.model.form.${entityName}Form;
|
||||
|
||||
/**
|
||||
* $!{tableComment}转换器
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface ${entityName}Converter{
|
||||
|
||||
${entityName}Form toForm(${entityName} entity);
|
||||
|
||||
${entityName} toEntity(${entityName}Form entity);
|
||||
}
|
||||
35
src/main/resources/templates/generator/entity.java.vm
Normal file
35
src/main/resources/templates/generator/entity.java.vm
Normal file
@@ -0,0 +1,35 @@
|
||||
package ${package}.model.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
#if(${hasLocalDateTime})
|
||||
import java.time.LocalDateTime;
|
||||
#end
|
||||
#if(${hasBigDecimal})
|
||||
import java.math.BigDecimal;
|
||||
#end
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.youlai.system.common.base.BaseEntity;
|
||||
|
||||
/**
|
||||
* $!{tableComment}实体对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("${tableName}")
|
||||
public class ${entityName} extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
#foreach($field in ${table.fields})
|
||||
#if("$!field.comment" != "")
|
||||
/**
|
||||
* ${field.comment}
|
||||
*/
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
}
|
||||
37
src/main/resources/templates/generator/form.java.vm
Normal file
37
src/main/resources/templates/generator/form.java.vm
Normal file
@@ -0,0 +1,37 @@
|
||||
package ${package}.model.form;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
#if(${hasLocalDateTime})
|
||||
import java.time.LocalDateTime;
|
||||
#end
|
||||
#if(${hasBigDecimal})
|
||||
import java.math.BigDecimal;
|
||||
#end
|
||||
|
||||
|
||||
/**
|
||||
* $!{tableComment} 表单对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "$!{tableComment}表单对象")
|
||||
public class ${entityName}Form implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
## ---------- BEGIN 字段循环遍历 ----------
|
||||
#foreach($field in ${fields})
|
||||
#if("$!field.comment" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
}
|
||||
27
src/main/resources/templates/generator/mapper.java.vm
Normal file
27
src/main/resources/templates/generator/mapper.java.vm
Normal file
@@ -0,0 +1,27 @@
|
||||
package ${package}.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import ${package}.model.entity.${entityName};
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import ${package}.model.query.${entityName}Query;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* $!{tableComment} 数据库访问层
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Mapper
|
||||
public interface ${entityName}Mapper extends BaseMapper<${entityName}> {
|
||||
|
||||
/**
|
||||
* 获取$!{tableComment}分页数据
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param queryParams 查询参数
|
||||
* @return
|
||||
*/
|
||||
Page<${entityName}VO> get${entityName}Page(Page<${entityName}VO> page, ${entityName}Query queryParams);
|
||||
|
||||
}
|
||||
29
src/main/resources/templates/generator/mapper.xml.vm
Normal file
29
src/main/resources/templates/generator/mapper.xml.vm
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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.${entityName}Mapper">
|
||||
|
||||
<!-- 获取${tableComment}分页列表 -->
|
||||
<select id="listPaged${entityName}s" resultType="${package}.model.entity.${entityName}">
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
${tableName}
|
||||
<where>
|
||||
is_deleted = 0
|
||||
<if test='queryParams.keywords!=null and queryParams.keywords.trim() neq ""'>
|
||||
AND (
|
||||
name LIKE CONCAT('%',#{queryParams.keywords},'%')
|
||||
)
|
||||
</if>
|
||||
<if test="queryParams.startTime != null">
|
||||
AND create_time >= #{queryParams.startTime}
|
||||
</if>
|
||||
<if test="queryParams.endTime != null">
|
||||
AND create_time <= #{queryParams.endTime}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY
|
||||
create_time DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
34
src/main/resources/templates/generator/query.java.vm
Normal file
34
src/main/resources/templates/generator/query.java.vm
Normal file
@@ -0,0 +1,34 @@
|
||||
package ${package}.model.query;
|
||||
|
||||
import com.youlai.common.base.BasePageQuery;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
#if(${hasLocalDateTime})
|
||||
import java.time.LocalDateTime;
|
||||
#end
|
||||
#if(${hasBigDecimal})
|
||||
import java.math.BigDecimal;
|
||||
#end
|
||||
|
||||
|
||||
/**
|
||||
* $!{tableComment}分页查询对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Schema(description ="$!{tableComment}分页查询对象")
|
||||
@Getter
|
||||
@Setter
|
||||
public class ${entityName}Query extends BasePageQuery {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
#foreach($field in ${fields})
|
||||
#if("$!field.comment" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
}
|
||||
61
src/main/resources/templates/generator/service.java.vm
Normal file
61
src/main/resources/templates/generator/service.java.vm
Normal file
@@ -0,0 +1,61 @@
|
||||
package ${package}.Service;
|
||||
|
||||
import ${package}.model.entity.${entityName};
|
||||
import ${package}.model.form.${entityName}Form;
|
||||
import ${package}.model.query.${entityName}PageQuery;
|
||||
import ${package}.model.vo.${entityName}PageVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
/**
|
||||
* $!{tableComment} 服务类
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
public interface ${entityName}Service extends IService<${entityName}> {
|
||||
|
||||
|
||||
/**
|
||||
*$!{tableComment}分页列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
IPage<${entityName}VO> get${entityName}Page(${entityName}Query queryParams);
|
||||
|
||||
|
||||
/**
|
||||
* 获取$!{tableComment}表单数据
|
||||
*
|
||||
* @param id $!{tableComment}ID
|
||||
* @return
|
||||
*/
|
||||
${entityName}Form get${entityName}FormData(Long id);
|
||||
|
||||
|
||||
/**
|
||||
* 新增$!{tableComment}
|
||||
*
|
||||
* @param formData $!{tableComment}表单对象
|
||||
* @return
|
||||
*/
|
||||
boolean save${entityName}(${entityName}Form formData);
|
||||
|
||||
/**
|
||||
* 修改$!{tableComment}
|
||||
*
|
||||
* @param id $!{tableComment}ID
|
||||
* @param formData $!{tableComment}表单对象
|
||||
* @return
|
||||
*/
|
||||
boolean update${entityName}(Long id, ${entityName}Form formData);
|
||||
|
||||
|
||||
/**
|
||||
* 删除$!{tableComment}
|
||||
*
|
||||
* @param ids $!{tableComment}ID,多个以英文逗号(,)分割
|
||||
* @return
|
||||
*/
|
||||
boolean delete${entityName}s(String ids);
|
||||
|
||||
}
|
||||
103
src/main/resources/templates/generator/serviceImpl.java.vm
Normal file
103
src/main/resources/templates/generator/serviceImpl.java.vm
Normal file
@@ -0,0 +1,103 @@
|
||||
package ${package}.service.impl;
|
||||
|
||||
import ${package}.model.entity.${entityName};
|
||||
import ${package}.mapper.${entityName}Mapper;
|
||||
import ${package}.service.${entityName}Service;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ${package}.model.form.${entityName}Form;
|
||||
import ${package}.model.query.${entityName}Query;
|
||||
import ${package}.model.vo.${entityName}PageVO;
|
||||
import ${package}.converter.${entityName}Converter;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* $!{tableComment}服务实现类
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ${table.serviceImplName} extends ServiceImpl<${entityName}Mapper, ${entityName}> implements ${entityName}Service {
|
||||
|
||||
private final ${entityName}Converter ${lowerFirstEntityName}Converter;
|
||||
|
||||
/**
|
||||
* 获取$!{tableComment}分页列表
|
||||
*
|
||||
* @param queryParams 查询参数
|
||||
* @return {@link IPage<${entityName}PageVO>} $!{tableComment}分页列表
|
||||
*/
|
||||
@Override
|
||||
public IPage<${entityName}VO> get${entityName}Page(${entityName}Query queryParams) {
|
||||
Page<${entityName}VO> pageVO = this.baseMapper.get${entityName}Page(
|
||||
new Page<>(queryParams.getPageNum(), queryParams.getPageSize()),
|
||||
queryParams
|
||||
);
|
||||
returnv pageVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取$!{tableComment}表单数据
|
||||
*
|
||||
* @param id $!{tableComment}ID
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ${entityName}Form get${entityName}FormData(Long id) {
|
||||
${entityName} entity = this.getById(id);
|
||||
return ${lowerFirstEntityName}Converter.toForm(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增$!{tableComment}
|
||||
*
|
||||
* @param formData $!{tableComment}表单对象
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean save${entityName}(${entityName}Form formData) {
|
||||
${entityName} entity = ${lowerFirstEntityName}Converter.toEntity(formData);
|
||||
return this.save(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新$!{tableComment}
|
||||
*
|
||||
* @param id $!{tableComment}ID
|
||||
* @param formData $!{tableComment}表单对象
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean update${entityName}(Long id,${entityName}Form formData) {
|
||||
${entityName} entity = ${lowerFirstEntityName}Converter.toEntity(formData);
|
||||
return this.updateById(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除$!{tableComment}
|
||||
*
|
||||
* @param ids $!{tableComment}ID,多个以英文逗号(,)分割
|
||||
* @return true|false
|
||||
*/
|
||||
@Override
|
||||
public boolean delete${entityName}s(String ids) {
|
||||
Assert.isTrue(StrUtil.isNotBlank(ids), "删除的$!{tableComment}数据为空");
|
||||
// 逻辑删除
|
||||
List<Long> idList = Arrays.stream(ids.split(","))
|
||||
.map(Long::parseLong)
|
||||
.toList();
|
||||
return this.removeByIds(idList);
|
||||
}
|
||||
|
||||
}
|
||||
37
src/main/resources/templates/generator/vo.java.vm
Normal file
37
src/main/resources/templates/generator/vo.java.vm
Normal file
@@ -0,0 +1,37 @@
|
||||
package ${package}.model.vo;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
#if(${hasLocalDateTime})
|
||||
import java.time.LocalDateTime;
|
||||
#end
|
||||
#if(${hasBigDecimal})
|
||||
import java.math.BigDecimal;
|
||||
#end
|
||||
|
||||
/**
|
||||
* $!{tableComment} 图对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema( description = "$!{tableComment}视图对象")
|
||||
public class ${entityName}VO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
#foreach($field in ${fields})
|
||||
#if("$!field.comment" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user