refactor: 代码生成临时提交
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
package com.youlai.system.config.property;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成配置属性
|
||||||
|
*
|
||||||
|
* @author Ray
|
||||||
|
* @since 2.11.0
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "generator")
|
||||||
|
@Data
|
||||||
|
public class GeneratorProperties {
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.youlai.system.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.youlai.system.common.result.PageResult;
|
||||||
|
import com.youlai.system.common.result.Result;
|
||||||
|
import com.youlai.system.model.query.TablePageQuery;
|
||||||
|
import com.youlai.system.model.vo.TableColumnVO;
|
||||||
|
import com.youlai.system.model.vo.TableGeneratePreviewVO;
|
||||||
|
import com.youlai.system.model.vo.TablePageVO;
|
||||||
|
import com.youlai.system.service.DatabaseService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Tag(name = "09.代码生成")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1/databases")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DatabaseController {
|
||||||
|
|
||||||
|
private final DatabaseService databaseService;
|
||||||
|
|
||||||
|
@Operation(summary = "获取数据表分页列表")
|
||||||
|
@GetMapping("/table/page")
|
||||||
|
public PageResult<TablePageVO> getTablePage(
|
||||||
|
TablePageQuery queryParams
|
||||||
|
) {
|
||||||
|
Page<TablePageVO> result = databaseService.getTablePage(queryParams);
|
||||||
|
return PageResult.success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "获取数据表字段列表")
|
||||||
|
@GetMapping("/table/{tableName}/columns")
|
||||||
|
public Result<List<TableColumnVO>> getTableColumns(
|
||||||
|
@Parameter(description = "表名", example = "sys_user") @PathVariable String tableName
|
||||||
|
) {
|
||||||
|
List<TableColumnVO> list = databaseService.getTableColumns(tableName);
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Operation(summary = "获取预览生成代码")
|
||||||
|
@GetMapping("/table/{tableName}/generate-preview")
|
||||||
|
public Result<List<TableGeneratePreviewVO>> getTablePreviewData(@PathVariable String tableName) {
|
||||||
|
List<TableGeneratePreviewVO> list = databaseService.getTablePreviewData(tableName);
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -36,6 +36,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,9 +139,9 @@ public class SysUserController {
|
|||||||
public void downloadTemplate(HttpServletResponse response) throws IOException {
|
public void downloadTemplate(HttpServletResponse response) throws IOException {
|
||||||
String fileName = "用户导入模板.xlsx";
|
String fileName = "用户导入模板.xlsx";
|
||||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8));
|
||||||
|
|
||||||
String fileClassPath = "excel-templates" + File.separator + fileName;
|
String fileClassPath = "templates" + File.separator + "excel" + File.separator + fileName;
|
||||||
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(fileClassPath);
|
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(fileClassPath);
|
||||||
|
|
||||||
ServletOutputStream outputStream = response.getOutputStream();
|
ServletOutputStream outputStream = response.getOutputStream();
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ import org.mapstruct.Mapper;
|
|||||||
@Mapper(componentModel = "spring")
|
@Mapper(componentModel = "spring")
|
||||||
public interface DeptConverter {
|
public interface DeptConverter {
|
||||||
|
|
||||||
DeptForm convertToForm(SysDept entity);
|
DeptForm toForm(SysDept entity);
|
||||||
|
|
||||||
DeptVO convertToVo(SysDept entity);
|
DeptVO convertToVo(SysDept entity);
|
||||||
|
|
||||||
SysDept convertToEntity(DeptForm deptForm);
|
SysDept toEntity(DeptForm deptForm);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ public interface DictConverter {
|
|||||||
|
|
||||||
Page<DictPageVO> convertToPageVo(Page<SysDict> page);
|
Page<DictPageVO> convertToPageVo(Page<SysDict> page);
|
||||||
|
|
||||||
DictForm convertToForm(SysDict entity);
|
DictForm toForm(SysDict entity);
|
||||||
|
|
||||||
SysDict convertToEntity(DictForm entity);
|
SysDict toEntity(DictForm entity);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ public interface DictItemConverter {
|
|||||||
|
|
||||||
Page<DictPageVO> convertToPageVo(Page<SysDictItem> page);
|
Page<DictPageVO> convertToPageVo(Page<SysDictItem> page);
|
||||||
|
|
||||||
DictForm convertToForm(SysDictItem entity);
|
DictForm toForm(SysDictItem entity);
|
||||||
|
|
||||||
SysDictItem convertToEntity(DictForm.DictItem dictFormDictItems);
|
SysDictItem toEntity(DictForm.DictItem dictFormDictItems);
|
||||||
List<SysDictItem> convertToEntity(List<DictForm.DictItem> dictFormDictItems);
|
List<SysDictItem> toEntity(List<DictForm.DictItem> dictFormDictItems);
|
||||||
|
|
||||||
DictForm.DictItem convertToDictFormDictItem(SysDictItem entity);
|
DictForm.DictItem convertToDictFormDictItem(SysDictItem entity);
|
||||||
List<DictForm.DictItem> convertToDictFormDictItem(List<SysDictItem> entities);
|
List<DictForm.DictItem> convertToDictFormDictItem(List<SysDictItem> entities);
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ public interface MenuConverter {
|
|||||||
MenuVO convertToVo(SysMenu entity);
|
MenuVO convertToVo(SysMenu entity);
|
||||||
|
|
||||||
@Mapping(target = "params", ignore = true)
|
@Mapping(target = "params", ignore = true)
|
||||||
MenuForm convertToForm(SysMenu entity);
|
MenuForm toForm(SysMenu entity);
|
||||||
|
|
||||||
@Mapping(target = "params", ignore = true)
|
@Mapping(target = "params", ignore = true)
|
||||||
SysMenu convertToEntity(MenuForm menuForm);
|
SysMenu toEntity(MenuForm menuForm);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ public interface RoleConverter {
|
|||||||
|
|
||||||
List<Option> entities2Options(List<SysRole> roles);
|
List<Option> entities2Options(List<SysRole> roles);
|
||||||
|
|
||||||
SysRole convertToEntity(RoleForm roleForm);
|
SysRole toEntity(RoleForm roleForm);
|
||||||
|
|
||||||
RoleForm convertToForm(SysRole entity);
|
RoleForm toForm(SysRole entity);
|
||||||
}
|
}
|
||||||
@@ -28,16 +28,16 @@ public interface UserConverter {
|
|||||||
|
|
||||||
Page<UserPageVO> toPageVo(Page<UserBO> bo);
|
Page<UserPageVO> toPageVo(Page<UserBO> bo);
|
||||||
|
|
||||||
UserForm convertToForm(SysUser entity);
|
UserForm toForm(SysUser entity);
|
||||||
|
|
||||||
@InheritInverseConfiguration(name = "convertToForm")
|
@InheritInverseConfiguration(name = "toForm")
|
||||||
SysUser convertToEntity(UserForm entity);
|
SysUser toEntity(UserForm entity);
|
||||||
|
|
||||||
@Mappings({
|
@Mappings({
|
||||||
@Mapping(target = "userId", source = "id")
|
@Mapping(target = "userId", source = "id")
|
||||||
})
|
})
|
||||||
UserInfoVO toUserInfoVo(SysUser entity);
|
UserInfoVO toUserInfoVo(SysUser entity);
|
||||||
|
|
||||||
SysUser convertToEntity(UserImportDTO vo);
|
SysUser toEntity(UserImportDTO vo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
23
src/main/java/com/youlai/system/mapper/DatabaseMapper.java
Normal file
23
src/main/java/com/youlai/system/mapper/DatabaseMapper.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package com.youlai.system.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.youlai.system.model.entity.SysDept;
|
||||||
|
import com.youlai.system.model.query.TablePageQuery;
|
||||||
|
import com.youlai.system.model.vo.TableColumnVO;
|
||||||
|
import com.youlai.system.model.vo.TablePageVO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface DatabaseMapper extends BaseMapper<SysDept> {
|
||||||
|
|
||||||
|
|
||||||
|
Page<TablePageVO> getTablePage(Page<TablePageVO> page, TablePageQuery queryParams);
|
||||||
|
|
||||||
|
List<TableColumnVO> getTableColumns(String tableName);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.youlai.system.model.form;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Schema(description = "代码生成配置")
|
||||||
|
@Data
|
||||||
|
public class GeneratorConfig {
|
||||||
|
|
||||||
|
@Schema(description = "表名")
|
||||||
|
private String tableName;
|
||||||
|
|
||||||
|
@Schema(description = "包名")
|
||||||
|
private String packageName;
|
||||||
|
|
||||||
|
@Schema(description = "模块名")
|
||||||
|
private String moduleName;
|
||||||
|
|
||||||
|
@Schema(description = "作者")
|
||||||
|
private String author;
|
||||||
|
|
||||||
|
@Schema(description = "表前缀")
|
||||||
|
private String tablePrefix;
|
||||||
|
|
||||||
|
@Schema(description = "是否覆盖")
|
||||||
|
private Boolean cover;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.youlai.system.model.query;
|
||||||
|
|
||||||
|
import com.youlai.system.common.base.BasePageQuery;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据表分页查询对象
|
||||||
|
*
|
||||||
|
* @author Ray
|
||||||
|
* @since 2.10.0
|
||||||
|
*/
|
||||||
|
@Schema(description = "数据表分页查询对象")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class TablePageQuery extends BasePageQuery {
|
||||||
|
|
||||||
|
@Schema(description="关键字(表名)")
|
||||||
|
private String keywords;
|
||||||
|
|
||||||
|
}
|
||||||
34
src/main/java/com/youlai/system/model/vo/TableColumnVO.java
Normal file
34
src/main/java/com/youlai/system/model/vo/TableColumnVO.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package com.youlai.system.model.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Schema(description = "数据表字段VO")
|
||||||
|
@Data
|
||||||
|
public class TableColumnVO {
|
||||||
|
|
||||||
|
@Schema(description = "字段名称", example = "id")
|
||||||
|
private String columnName;
|
||||||
|
|
||||||
|
@Schema(description = "字段类型", example = "bigint")
|
||||||
|
private String dataType;
|
||||||
|
|
||||||
|
@Schema(description = "字段描述", example = "主键")
|
||||||
|
private String columnComment;
|
||||||
|
|
||||||
|
@Schema(description = "字段长度", example = "20")
|
||||||
|
private Integer characterMaximumLength;
|
||||||
|
|
||||||
|
@Schema(description = "是否主键(1-是 0-否)", example = "1")
|
||||||
|
private Integer isPrimaryKey;
|
||||||
|
|
||||||
|
@Schema(description = "是否可为空(1-是 0-否)", example = "1")
|
||||||
|
private String isNullable;
|
||||||
|
|
||||||
|
@Schema(description = "字符集", example = "utf8mb4")
|
||||||
|
private String characterSetName;
|
||||||
|
|
||||||
|
@Schema(description = "字符集排序规则", example = "utf8mb4_general_ci")
|
||||||
|
private String collationName;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.youlai.system.model.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Schema(description = "表生成代码预览VO")
|
||||||
|
@Data
|
||||||
|
public class TableGeneratePreviewVO {
|
||||||
|
|
||||||
|
@Schema(description = "生成文件路径")
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
@Schema(description = "生成文件名称",example = "SysUser.java" )
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
@Schema(description = "生成文件内容")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
}
|
||||||
29
src/main/java/com/youlai/system/model/vo/TablePageVO.java
Normal file
29
src/main/java/com/youlai/system/model/vo/TablePageVO.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package com.youlai.system.model.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
|
@Schema(description = "数据表分页VO")
|
||||||
|
@Data
|
||||||
|
public class TablePageVO {
|
||||||
|
|
||||||
|
@Schema(description = "数据表名称", example = "sys_user")
|
||||||
|
private String tableName;
|
||||||
|
|
||||||
|
@Schema(description = "数据表注释",example = "用户表")
|
||||||
|
private String tableComment;
|
||||||
|
|
||||||
|
@Schema(description = "数据表排序规则",example = "用户表")
|
||||||
|
private String tableCollation;
|
||||||
|
|
||||||
|
@Schema(description = "存储引擎",example = "InnoDB")
|
||||||
|
private String engine;
|
||||||
|
|
||||||
|
@Schema(description = "字符集",example = "utf8mb4_general_ci")
|
||||||
|
private String charset;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间",example = "2023-08-08 08:08:08")
|
||||||
|
private String createTime;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -104,7 +104,7 @@ public class UserImportListener extends MyAnalysisEventListener<UserImportDTO> {
|
|||||||
|
|
||||||
if (validationMsg.isEmpty()) {
|
if (validationMsg.isEmpty()) {
|
||||||
// 校验通过,持久化至数据库
|
// 校验通过,持久化至数据库
|
||||||
SysUser entity = userConverter.convertToEntity(userImportDTO);
|
SysUser entity = userConverter.toEntity(userImportDTO);
|
||||||
entity.setPassword(passwordEncoder.encode(SystemConstants.DEFAULT_PASSWORD)); // 默认密码
|
entity.setPassword(passwordEncoder.encode(SystemConstants.DEFAULT_PASSWORD)); // 默认密码
|
||||||
// 性别翻译
|
// 性别翻译
|
||||||
String genderLabel = userImportDTO.getGenderLabel();
|
String genderLabel = userImportDTO.getGenderLabel();
|
||||||
|
|||||||
43
src/main/java/com/youlai/system/service/DatabaseService.java
Normal file
43
src/main/java/com/youlai/system/service/DatabaseService.java
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package com.youlai.system.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.youlai.system.model.query.TablePageQuery;
|
||||||
|
import com.youlai.system.model.vo.TableColumnVO;
|
||||||
|
import com.youlai.system.model.vo.TableGeneratePreviewVO;
|
||||||
|
import com.youlai.system.model.vo.TablePageVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库服务接口
|
||||||
|
*
|
||||||
|
* @author haoxr
|
||||||
|
* @since 2.11.0
|
||||||
|
*/
|
||||||
|
public interface DatabaseService {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据表分页列表
|
||||||
|
*
|
||||||
|
* @param queryParams 查询参数
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Page<TablePageVO> getTablePage(TablePageQuery queryParams);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据表字段列表
|
||||||
|
*
|
||||||
|
* @param tableName 表名
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<TableColumnVO> getTableColumns(String tableName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取预览生成代码
|
||||||
|
*
|
||||||
|
* @param tableName 表名
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<TableGeneratePreviewVO> getTablePreviewData(String tableName);
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package com.youlai.system.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.extra.template.Template;
|
||||||
|
import cn.hutool.extra.template.TemplateConfig;
|
||||||
|
import cn.hutool.extra.template.TemplateEngine;
|
||||||
|
import cn.hutool.extra.template.TemplateUtil;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.youlai.system.mapper.DatabaseMapper;
|
||||||
|
import com.youlai.system.model.query.TablePageQuery;
|
||||||
|
import com.youlai.system.model.vo.TableColumnVO;
|
||||||
|
import com.youlai.system.model.vo.TableGeneratePreviewVO;
|
||||||
|
import com.youlai.system.model.vo.TablePageVO;
|
||||||
|
import com.youlai.system.service.DatabaseService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import cn.hutool.extra.template.TemplateConfig.ResourceMode;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库服务实现类
|
||||||
|
*
|
||||||
|
* @author Ray
|
||||||
|
* @since 2.11.0
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DatabaseServiceImpl implements DatabaseService {
|
||||||
|
|
||||||
|
private final DatabaseMapper databaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据表分页列表
|
||||||
|
*
|
||||||
|
* @param queryParams 查询参数
|
||||||
|
* @return 分页结果
|
||||||
|
*/
|
||||||
|
public Page<TablePageVO> getTablePage(TablePageQuery queryParams) {
|
||||||
|
Page<TablePageVO> page = new Page<>(queryParams.getPageNum(), queryParams.getPageSize());
|
||||||
|
return databaseMapper.getTablePage(page, queryParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据表字段列表
|
||||||
|
*
|
||||||
|
* @param tableName 表名
|
||||||
|
* @return 字段列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<TableColumnVO> getTableColumns(String tableName) {
|
||||||
|
return databaseMapper.getTableColumns(tableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取预览生成代码
|
||||||
|
*
|
||||||
|
* @param tableName 表名
|
||||||
|
* @return 预览数据
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<TableGeneratePreviewVO> getTablePreviewData(String tableName) {
|
||||||
|
|
||||||
|
List<TableGeneratePreviewVO> list = new ArrayList<>();
|
||||||
|
|
||||||
|
TemplateConfig templateConfig = new TemplateConfig("templates" , ResourceMode.CLASSPATH);
|
||||||
|
TemplateEngine templateEngine = TemplateUtil.createEngine(templateConfig);
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, Object> bindingMap = new HashMap<>();
|
||||||
|
bindingMap.put("tableName", "sys_user");
|
||||||
|
bindingMap.put("author", "Ray");
|
||||||
|
bindingMap.put("entityName", "User" );
|
||||||
|
bindingMap.put("lowerFirstEntityName", "user");
|
||||||
|
bindingMap.put("tableComment", "用户");
|
||||||
|
|
||||||
|
// 包路径
|
||||||
|
bindingMap.put("package", "com.youlai.system");
|
||||||
|
|
||||||
|
Template template = templateEngine.getTemplate("generator" + File.separator + "controller.java.vm");
|
||||||
|
String content = template.render(bindingMap);
|
||||||
|
TableGeneratePreviewVO vo = new TableGeneratePreviewVO();
|
||||||
|
vo.setPath("controller");
|
||||||
|
vo.setContent(content);
|
||||||
|
vo.setFileName("UserController.java");
|
||||||
|
|
||||||
|
list.add(vo);
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -141,7 +141,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||||||
Assert.isTrue(count == 0, "部门编号已存在");
|
Assert.isTrue(count == 0, "部门编号已存在");
|
||||||
|
|
||||||
// form->entity
|
// form->entity
|
||||||
SysDept entity = deptConverter.convertToEntity(formData);
|
SysDept entity = deptConverter.toEntity(formData);
|
||||||
|
|
||||||
// 生成部门路径(tree_path),格式:父节点tree_path + , + 父节点ID,用于删除部门时级联删除子部门
|
// 生成部门路径(tree_path),格式:父节点tree_path + , + 父节点ID,用于删除部门时级联删除子部门
|
||||||
String treePath = generateDeptTreePath(formData.getParentId());
|
String treePath = generateDeptTreePath(formData.getParentId());
|
||||||
@@ -164,7 +164,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||||||
@Override
|
@Override
|
||||||
public DeptForm getDeptForm(Long deptId) {
|
public DeptForm getDeptForm(Long deptId) {
|
||||||
SysDept entity = this.getById(deptId);
|
SysDept entity = this.getById(deptId);
|
||||||
return deptConverter.convertToForm(entity);
|
return deptConverter.toForm(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||||||
|
|
||||||
|
|
||||||
// form->entity
|
// form->entity
|
||||||
SysDept entity = deptConverter.convertToEntity(formData);
|
SysDept entity = deptConverter.toEntity(formData);
|
||||||
entity.setId(deptId);
|
entity.setId(deptId);
|
||||||
|
|
||||||
// 生成部门路径(tree_path),格式:父节点tree_path + , + 父节点ID,用于删除部门时级联删除子部门
|
// 生成部门路径(tree_path),格式:父节点tree_path + , + 父节点ID,用于删除部门时级联删除子部门
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.youlai.system.service.impl;
|
package com.youlai.system.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.convert.Convert;
|
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
@@ -62,7 +61,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
|||||||
@Override
|
@Override
|
||||||
public boolean saveDict(DictForm dictForm) {
|
public boolean saveDict(DictForm dictForm) {
|
||||||
// 保存字典
|
// 保存字典
|
||||||
SysDict entity = dictConverter.convertToEntity(dictForm);
|
SysDict entity = dictConverter.toEntity(dictForm);
|
||||||
|
|
||||||
// 校验 code 是否唯一
|
// 校验 code 是否唯一
|
||||||
long count = this.count(new LambdaQueryWrapper<SysDict>()
|
long count = this.count(new LambdaQueryWrapper<SysDict>()
|
||||||
@@ -74,7 +73,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
|||||||
// 保存字典项
|
// 保存字典项
|
||||||
if (result) {
|
if (result) {
|
||||||
List<DictForm.DictItem> dictFormDictItems = dictForm.getDictItems();
|
List<DictForm.DictItem> dictFormDictItems = dictForm.getDictItems();
|
||||||
List<SysDictItem> dictItems = dictItemConverter.convertToEntity(dictFormDictItems);
|
List<SysDictItem> dictItems = dictItemConverter.toEntity(dictFormDictItems);
|
||||||
dictItems.forEach(dictItem -> dictItem.setDictId(entity.getId()));
|
dictItems.forEach(dictItem -> dictItem.setDictId(entity.getId()));
|
||||||
dictItemService.saveBatch(dictItems);
|
dictItemService.saveBatch(dictItems);
|
||||||
}
|
}
|
||||||
@@ -92,7 +91,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
|||||||
// 获取字典
|
// 获取字典
|
||||||
SysDict entity = this.getById(id);
|
SysDict entity = this.getById(id);
|
||||||
Assert.isTrue(entity != null, "字典不存在");
|
Assert.isTrue(entity != null, "字典不存在");
|
||||||
DictForm dictForm = dictConverter.convertToForm(entity);
|
DictForm dictForm = dictConverter.toForm(entity);
|
||||||
|
|
||||||
// 获取字典项集合
|
// 获取字典项集合
|
||||||
List<SysDictItem> dictItems = dictItemService.list(new LambdaQueryWrapper<SysDictItem>()
|
List<SysDictItem> dictItems = dictItemService.list(new LambdaQueryWrapper<SysDictItem>()
|
||||||
@@ -113,7 +112,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
|||||||
@Override
|
@Override
|
||||||
public boolean updateDict(Long id, DictForm dictForm) {
|
public boolean updateDict(Long id, DictForm dictForm) {
|
||||||
// 更新字典
|
// 更新字典
|
||||||
SysDict entity = dictConverter.convertToEntity(dictForm);
|
SysDict entity = dictConverter.toEntity(dictForm);
|
||||||
|
|
||||||
// 校验 code 是否唯一
|
// 校验 code 是否唯一
|
||||||
long count = this.count(new LambdaQueryWrapper<SysDict>()
|
long count = this.count(new LambdaQueryWrapper<SysDict>()
|
||||||
@@ -127,7 +126,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
|||||||
if (result) {
|
if (result) {
|
||||||
// 更新字典项
|
// 更新字典项
|
||||||
List<DictForm.DictItem> dictFormDictItems = dictForm.getDictItems();
|
List<DictForm.DictItem> dictFormDictItems = dictForm.getDictItems();
|
||||||
List<SysDictItem> dictItems = dictItemConverter.convertToEntity(dictFormDictItems);
|
List<SysDictItem> dictItems = dictItemConverter.toEntity(dictFormDictItems);
|
||||||
|
|
||||||
// 获取当前数据库中的字典项
|
// 获取当前数据库中的字典项
|
||||||
List<SysDictItem> currentDictItemEntities = dictItemService.list(new LambdaQueryWrapper<SysDictItem>()
|
List<SysDictItem> currentDictItemEntities = dictItemService.list(new LambdaQueryWrapper<SysDictItem>()
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||||||
menuForm.setComponent(null);
|
menuForm.setComponent(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
SysMenu entity = menuConverter.convertToEntity(menuForm);
|
SysMenu entity = menuConverter.toEntity(menuForm);
|
||||||
String treePath = generateMenuTreePath(menuForm.getParentId());
|
String treePath = generateMenuTreePath(menuForm.getParentId());
|
||||||
entity.setTreePath(treePath);
|
entity.setTreePath(treePath);
|
||||||
|
|
||||||
@@ -303,7 +303,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||||||
public MenuForm getMenuForm(Long id) {
|
public MenuForm getMenuForm(Long id) {
|
||||||
SysMenu entity = this.getById(id);
|
SysMenu entity = this.getById(id);
|
||||||
Assert.isTrue(entity != null, "菜单不存在");
|
Assert.isTrue(entity != null, "菜单不存在");
|
||||||
MenuForm formData = menuConverter.convertToForm(entity);
|
MenuForm formData = menuConverter.toForm(entity);
|
||||||
// 路由参数字符串 {"id":"1","name":"张三"} 转换为 [{key:"id", value:"1"}, {key:"name", value:"张三"}]
|
// 路由参数字符串 {"id":"1","name":"张三"} 转换为 [{key:"id", value:"1"}, {key:"name", value:"张三"}]
|
||||||
String params = entity.getParams();
|
String params = entity.getParams();
|
||||||
if (StrUtil.isNotBlank(params)) {
|
if (StrUtil.isNotBlank(params)) {
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||||||
Assert.isTrue(count == 0, "角色名称或角色编码已存在,请修改后重试!");
|
Assert.isTrue(count == 0, "角色名称或角色编码已存在,请修改后重试!");
|
||||||
|
|
||||||
// 实体转换
|
// 实体转换
|
||||||
SysRole role = roleConverter.convertToEntity(roleForm);
|
SysRole role = roleConverter.toEntity(roleForm);
|
||||||
|
|
||||||
boolean result = this.saveOrUpdate(role);
|
boolean result = this.saveOrUpdate(role);
|
||||||
if (result) {
|
if (result) {
|
||||||
@@ -143,7 +143,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||||||
@Override
|
@Override
|
||||||
public RoleForm getRoleForm(Long roleId) {
|
public RoleForm getRoleForm(Long roleId) {
|
||||||
SysRole entity = this.getById(roleId);
|
SysRole entity = this.getById(roleId);
|
||||||
return roleConverter.convertToForm(entity);
|
return roleConverter.toForm(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||||||
Assert.isTrue(count == 0, "用户名已存在");
|
Assert.isTrue(count == 0, "用户名已存在");
|
||||||
|
|
||||||
// 实体转换 form->entity
|
// 实体转换 form->entity
|
||||||
SysUser entity = userConverter.convertToEntity(userForm);
|
SysUser entity = userConverter.toEntity(userForm);
|
||||||
|
|
||||||
// 设置默认加密密码
|
// 设置默认加密密码
|
||||||
String defaultEncryptPwd = passwordEncoder.encode(SystemConstants.DEFAULT_PASSWORD);
|
String defaultEncryptPwd = passwordEncoder.encode(SystemConstants.DEFAULT_PASSWORD);
|
||||||
@@ -141,7 +141,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||||||
Assert.isTrue(count == 0, "用户名已存在");
|
Assert.isTrue(count == 0, "用户名已存在");
|
||||||
|
|
||||||
// form -> entity
|
// form -> entity
|
||||||
SysUser entity = userConverter.convertToEntity(userForm);
|
SysUser entity = userConverter.toEntity(userForm);
|
||||||
|
|
||||||
// 修改用户
|
// 修改用户
|
||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
|
|||||||
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
|
||||||
|
|
||||||
@@ -3,3 +3,5 @@ spring:
|
|||||||
name: youlai-boot
|
name: youlai-boot
|
||||||
profiles:
|
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
|
||||||
|
|
||||||
|
}
|
||||||
@@ -48,20 +48,20 @@ public class FastAutoGeneratorTest {
|
|||||||
// 注入配置(设置扩展类的模板路径和包路径)
|
// 注入配置(设置扩展类的模板路径和包路径)
|
||||||
.injectionConfig(consumer -> {
|
.injectionConfig(consumer -> {
|
||||||
List<CustomFile> customFiles = new ArrayList<>();
|
List<CustomFile> customFiles = new ArrayList<>();
|
||||||
customFiles.add(new CustomFile.Builder().fileName("DTO.java").templatePath("/templates/dto.java.vm").packageName("model.dto").build());
|
customFiles.add(new CustomFile.Builder().fileName("DTO.java").templatePath("/templates/generator/dto.java.vm").packageName("model.dto").build());
|
||||||
customFiles.add(new CustomFile.Builder().fileName("VO.java").templatePath("/templates/vo.java.vm").packageName("model.vo").build());
|
customFiles.add(new CustomFile.Builder().fileName("VO.java").templatePath("/templates/generator/vo.java.vm").packageName("model.vo").build());
|
||||||
customFiles.add(new CustomFile.Builder().fileName("BO.java").templatePath("/templates/bo.java.vm").packageName("model.bo").build());
|
customFiles.add(new CustomFile.Builder().fileName("BO.java").templatePath("/templates/generator/bo.java.vm").packageName("model.bo").build());
|
||||||
customFiles.add(new CustomFile.Builder().fileName("PageQuery.java").templatePath("/templates/pageQuery.java.vm").packageName("model.query").build());
|
customFiles.add(new CustomFile.Builder().fileName("PageQuery.java").templatePath("/templates/generator/query.java.vm").packageName("model.query").build());
|
||||||
customFiles.add(new CustomFile.Builder().fileName("PageVO.java").templatePath("/templates/pageVO.java.vm").packageName("model.vo").build());
|
customFiles.add(new CustomFile.Builder().fileName("PageVO.java").templatePath("/templates/pageVO.java.vm").packageName("model.vo").build());
|
||||||
customFiles.add(new CustomFile.Builder().fileName("Form.java").templatePath("/templates/form.java.vm").packageName("model.form").build());
|
customFiles.add(new CustomFile.Builder().fileName("Form.java").templatePath("/templates/generator/form.java.vm").packageName("model.form").build());
|
||||||
customFiles.add(new CustomFile.Builder().fileName("Converter.java").templatePath("/templates/converter.java.vm").packageName("converter").build());
|
customFiles.add(new CustomFile.Builder().fileName("Converter.java").templatePath("/templates/generator/converter.java.vm").packageName("converter").build());
|
||||||
consumer.customFile(customFiles);
|
consumer.customFile(customFiles);
|
||||||
consumer.beforeOutputFile((tableInfo, objectMap) -> {
|
consumer.beforeOutputFile((tableInfo, objectMap) -> {
|
||||||
// 为每个表生成首字母小写的实体名
|
// 为每个表生成首字母小写的实体名
|
||||||
String entityName = tableInfo.getEntityName();
|
String entityName = tableInfo.getEntityName();
|
||||||
String lowerCaseEntity = entityName.substring(0, 1).toLowerCase() + entityName.substring(1);
|
String lowerCaseEntity = entityName.substring(0, 1).toLowerCase() + entityName.substring(1);
|
||||||
// 注入自定义参数
|
// 注入自定义参数
|
||||||
objectMap.put("firstCharLowerCaseEntity", lowerCaseEntity);
|
objectMap.put("lowerFirstEntityName", lowerCaseEntity);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,141 +0,0 @@
|
|||||||
package ${package.Parent}.model.bo;
|
|
||||||
|
|
||||||
#foreach($pkg in ${table.importPackages})
|
|
||||||
import ${pkg};
|
|
||||||
#end
|
|
||||||
#if(${entityLombokModel})
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
#if(${chainModel})
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* $!{table.comment}
|
|
||||||
*
|
|
||||||
* @author ${author}
|
|
||||||
* @since ${date}
|
|
||||||
*/
|
|
||||||
#if(${entityLombokModel})
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
#if(${chainModel})
|
|
||||||
@Accessors(chain = true)
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
#if(${superEntityClass})
|
|
||||||
public class ${entity}BO extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
|
|
||||||
#elseif(${activeRecord})
|
|
||||||
public class ${entity}BO extends Model<${entity}> {
|
|
||||||
#elseif(${entitySerialVersionUID})
|
|
||||||
public class ${entity}BO implements Serializable {
|
|
||||||
#else
|
|
||||||
public class ${entity}BO {
|
|
||||||
#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" != "")
|
|
||||||
/**
|
|
||||||
* ${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
|
|
||||||
## ---------- 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
|
|
||||||
}
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
package ${package.Controller};
|
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import ${package.Parent}.model.form.${entity}Form;
|
|
||||||
import ${package.Parent}.model.query.${entity}PageQuery;
|
|
||||||
import ${package.Parent}.model.vo.${entity}PageVO;
|
|
||||||
import ${package.Parent}.service.${table.serviceName};
|
|
||||||
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;
|
|
||||||
|
|
||||||
#if(${superControllerClassPackage})
|
|
||||||
import ${superControllerClassPackage};
|
|
||||||
#end
|
|
||||||
|
|
||||||
/**
|
|
||||||
* $!{table.comment} 前端控制器
|
|
||||||
*
|
|
||||||
* @author ${author}
|
|
||||||
* @since ${date}
|
|
||||||
*/
|
|
||||||
@Tag(name = "${table.comment}接口")
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/v1/${firstCharLowerCaseEntity}s")
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
#if(${superControllerClass})
|
|
||||||
public class ${table.controllerName} extends ${superControllerClass} {
|
|
||||||
#else
|
|
||||||
public class ${table.controllerName} {
|
|
||||||
#end
|
|
||||||
|
|
||||||
private final ${table.serviceName} ${firstCharLowerCaseEntity}Service;
|
|
||||||
|
|
||||||
@Operation(summary = "$!{table.comment}分页列表")
|
|
||||||
@GetMapping("/page")
|
|
||||||
public PageResult<${entity}PageVO> listPaged${entity}s(${entity}PageQuery queryParams ) {
|
|
||||||
IPage<${entity}PageVO> result = ${firstCharLowerCaseEntity}Service.listPaged${entity}s(queryParams);
|
|
||||||
return PageResult.success(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "新增$!{table.comment}")
|
|
||||||
@PostMapping
|
|
||||||
public Result save${entity}(@RequestBody @Valid ${entity}Form formData ) {
|
|
||||||
boolean result = ${firstCharLowerCaseEntity}Service.save${entity}(formData);
|
|
||||||
return Result.judge(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "$!{table.comment}表单数据")
|
|
||||||
@GetMapping("/{id}/form")
|
|
||||||
public Result<${entity}Form> get${entity}Form(
|
|
||||||
@Parameter(description = "$!{table.comment}ID") @PathVariable Long id
|
|
||||||
) {
|
|
||||||
${entity}Form formData = ${firstCharLowerCaseEntity}Service.get${entity}FormData(id);
|
|
||||||
return Result.success(formData);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "修改$!{table.comment}")
|
|
||||||
@PutMapping(value = "/{id}")
|
|
||||||
public Result update${entity}(@Parameter(description = "$!{table.comment}ID") @PathVariable Long id,
|
|
||||||
@RequestBody @Validated ${entity}Form formData) {
|
|
||||||
boolean result = ${firstCharLowerCaseEntity}Service.update${entity}(id, formData);
|
|
||||||
return Result.judge(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "删除$!{table.comment}")
|
|
||||||
@DeleteMapping("/{ids}")
|
|
||||||
public Result delete${entity}s(
|
|
||||||
@Parameter(description = "$!{table.comment}ID,多个以英文逗号(,)分割") @PathVariable String ids
|
|
||||||
) {
|
|
||||||
boolean result = ${firstCharLowerCaseEntity}Service.delete${entity}s(ids);
|
|
||||||
return Result.judge(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package ${package.Parent}.converter;
|
|
||||||
|
|
||||||
import org.mapstruct.InheritInverseConfiguration;
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
|
|
||||||
import ${package.Parent}.model.dto.${entity}DTO;
|
|
||||||
import ${package.Parent}.model.entity.${entity};
|
|
||||||
import ${package.Parent}.model.vo.${entity}PageVO;
|
|
||||||
import ${package.Parent}.model.form.${entity}Form;
|
|
||||||
import ${package.Parent}.model.bo.${entity}BO;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* $!{table.comment}转换器
|
|
||||||
*
|
|
||||||
* @author ${author}
|
|
||||||
* @since ${date}
|
|
||||||
*/
|
|
||||||
@Mapper(componentModel = "spring")
|
|
||||||
public interface ${entity}Converter{
|
|
||||||
|
|
||||||
${entity}PageVO toPageVo(${entity}BO bo);
|
|
||||||
|
|
||||||
Page<${entity}PageVO> toPageVo(Page<${entity}BO> bo);
|
|
||||||
|
|
||||||
${entity}Form convertToForm(${entity} entity);
|
|
||||||
|
|
||||||
@InheritInverseConfiguration(name = "convertToForm")
|
|
||||||
${entity} convertToEntity(${entity}Form entity);
|
|
||||||
}
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
package ${package.Parent}.model.dto;
|
|
||||||
|
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
#if(${entityLombokModel})
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
#if(${chainModel})
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
/**
|
|
||||||
* $!{table.comment} DTO
|
|
||||||
*
|
|
||||||
* @author ${author}
|
|
||||||
* @since ${date}
|
|
||||||
*/
|
|
||||||
#if(${entityLombokModel})
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
#if(${chainModel})
|
|
||||||
@Accessors(chain = true)
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
@Schema( description = "$!{table.comment}传输层对象")
|
|
||||||
#if(${superEntityClass})
|
|
||||||
public class ${entity}DTO extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
|
|
||||||
#elseif(${activeRecord})
|
|
||||||
public class ${entity}DTO extends Model<${entity}> {
|
|
||||||
#elseif(${entitySerialVersionUID})
|
|
||||||
public class ${entity}DTO implements Serializable {
|
|
||||||
#else
|
|
||||||
public class ${entity}DTO {
|
|
||||||
#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
|
|
||||||
|
|
||||||
private ${field.propertyType} ${field.propertyName};
|
|
||||||
#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
|
|
||||||
}
|
|
||||||
@@ -1,143 +0,0 @@
|
|||||||
package ${package.Entity};
|
|
||||||
|
|
||||||
#foreach($pkg in ${table.importPackages})
|
|
||||||
import ${pkg};
|
|
||||||
#end
|
|
||||||
#if(${entityLombokModel})
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
#if(${chainModel})
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
|
|
||||||
/**
|
|
||||||
* $!{table.comment}实体
|
|
||||||
*
|
|
||||||
* @author ${author}
|
|
||||||
* @since ${date}
|
|
||||||
*/
|
|
||||||
#if(${entityLombokModel})
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
#if(${chainModel})
|
|
||||||
@Accessors(chain = true)
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
#if(${table.convert})
|
|
||||||
@TableName("${schemaName}${table.name}")
|
|
||||||
#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" != "")
|
|
||||||
/**
|
|
||||||
* ${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
|
|
||||||
## ---------- 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
|
|
||||||
}
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
package ${package.Parent}.model.form;
|
|
||||||
|
|
||||||
#foreach($pkg in ${table.importPackages})
|
|
||||||
import ${pkg};
|
|
||||||
#end
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
#if(${entityLombokModel})
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
#if(${chainModel})
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
|
|
||||||
/**
|
|
||||||
* $!{table.comment} 表单对象
|
|
||||||
*
|
|
||||||
* @author ${author}
|
|
||||||
* @since ${date}
|
|
||||||
*/
|
|
||||||
#if(${entityLombokModel})
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
#if(${chainModel})
|
|
||||||
@Accessors(chain = true)
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
@Schema(description = "$!{table.comment}表单对象")
|
|
||||||
#if(${superEntityClass})
|
|
||||||
public class ${entity}Form extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
|
|
||||||
#elseif(${activeRecord})
|
|
||||||
public class ${entity}Form extends Model<${entity}> {
|
|
||||||
#elseif(${entitySerialVersionUID})
|
|
||||||
public class ${entity}Form implements Serializable {
|
|
||||||
#else
|
|
||||||
public class ${entity}Form {
|
|
||||||
#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
|
|
||||||
|
|
||||||
private ${field.propertyType} ${field.propertyName};
|
|
||||||
#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
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package ${package.Mapper};
|
|
||||||
|
|
||||||
import ${package.Entity}.${entity};
|
|
||||||
import ${superMapperClassPackage};
|
|
||||||
#if(${mapperAnnotationClass})
|
|
||||||
import ${mapperAnnotationClass.name};
|
|
||||||
#end
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import ${package.Parent}.model.bo.${entity}BO;
|
|
||||||
import ${package.Parent}.model.query.${entity}PageQuery;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* $!{table.comment} Mapper 接口
|
|
||||||
*
|
|
||||||
* @author ${author}
|
|
||||||
* @since ${date}
|
|
||||||
*/
|
|
||||||
#if(${mapperAnnotationClass})
|
|
||||||
@${mapperAnnotationClass.simpleName}
|
|
||||||
#end
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取用户分页列表
|
|
||||||
*
|
|
||||||
* @param page
|
|
||||||
* @param queryParams 查询参数
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Page<${entity}BO> listPaged${entity}s(Page<${entity}BO> page, ${entity}PageQuery queryParams);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
<?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})
|
|
||||||
${field.columnName},
|
|
||||||
#end
|
|
||||||
${table.fieldNames}
|
|
||||||
</sql>
|
|
||||||
|
|
||||||
#end
|
|
||||||
|
|
||||||
<!-- ${table.comment}分页列表 -->
|
|
||||||
<select id="listPaged${entity}s" resultType="${package.Parent}.model.bo.${entity}BO">
|
|
||||||
SELECT
|
|
||||||
<include refid="Base_Column_List"/>
|
|
||||||
FROM
|
|
||||||
${table.name}
|
|
||||||
<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>
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package ${package.Parent}.model.query;
|
|
||||||
|
|
||||||
import com.youlai.common.base.BasePageQuery;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* $!{table.comment}分页查询对象
|
|
||||||
*
|
|
||||||
* @author ${author}
|
|
||||||
* @since ${date}
|
|
||||||
*/
|
|
||||||
@Schema(description ="$!{table.comment}分页查询对象")
|
|
||||||
@Data
|
|
||||||
public class ${entity}PageQuery extends BasePageQuery {
|
|
||||||
|
|
||||||
@Schema(description="关键字")
|
|
||||||
private String keywords;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
package ${package.Parent}.model.vo;
|
|
||||||
|
|
||||||
#foreach($pkg in ${table.importPackages})
|
|
||||||
import ${pkg};
|
|
||||||
#end
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
#if(${entityLombokModel})
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
#if(${chainModel})
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
|
|
||||||
/**
|
|
||||||
* $!{table.comment} 分页VO
|
|
||||||
*
|
|
||||||
* @author ${author}
|
|
||||||
* @since ${date}
|
|
||||||
*/
|
|
||||||
#if(${entityLombokModel})
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
#if(${chainModel})
|
|
||||||
@Accessors(chain = true)
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
@Schema( description = "$!{table.comment}分页视图对象")
|
|
||||||
#if(${superEntityClass})
|
|
||||||
public class ${entity}PageVO extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
|
|
||||||
#elseif(${activeRecord})
|
|
||||||
public class ${entity}PageVO extends Model<${entity}> {
|
|
||||||
#elseif(${entitySerialVersionUID})
|
|
||||||
public class ${entity}PageVO implements Serializable {
|
|
||||||
#else
|
|
||||||
public class ${entity}PageVO {
|
|
||||||
#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
|
|
||||||
|
|
||||||
private ${field.propertyType} ${field.propertyName};
|
|
||||||
#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
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
package ${package.Service};
|
|
||||||
|
|
||||||
import ${package.Entity}.${entity};
|
|
||||||
import ${superServiceClassPackage};
|
|
||||||
import ${package.Parent}.model.form.${entity}Form;
|
|
||||||
import ${package.Parent}.model.query.${entity}PageQuery;
|
|
||||||
import ${package.Parent}.model.vo.${entity}PageVO;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
/**
|
|
||||||
* $!{table.comment} 服务类
|
|
||||||
*
|
|
||||||
* @author ${author}
|
|
||||||
* @since ${date}
|
|
||||||
*/
|
|
||||||
public interface ${table.serviceName} extends ${superServiceClass}<${entity}> {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*$!{table.comment}分页列表
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
IPage<${entity}PageVO> listPaged${entity}s(${entity}PageQuery queryParams);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取$!{table.comment}表单数据
|
|
||||||
*
|
|
||||||
* @param id $!{table.comment}ID
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
${entity}Form get${entity}FormData(Long id);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增$!{table.comment}
|
|
||||||
*
|
|
||||||
* @param formData $!{table.comment}表单对象
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
boolean save${entity}(${entity}Form formData);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改$!{table.comment}
|
|
||||||
*
|
|
||||||
* @param id $!{table.comment}ID
|
|
||||||
* @param formData $!{table.comment}表单对象
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
boolean update${entity}(Long id, ${entity}Form formData);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除$!{table.comment}
|
|
||||||
*
|
|
||||||
* @param ids $!{table.comment}ID,多个以英文逗号(,)分割
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
boolean delete${entity}s(String ids);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
package ${package.ServiceImpl};
|
|
||||||
|
|
||||||
import ${package.Entity}.${entity};
|
|
||||||
import ${package.Mapper}.${table.mapperName};
|
|
||||||
import ${package.Service}.${table.serviceName};
|
|
||||||
import ${superServiceImplClassPackage};
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import com.youlai.common.util.DateUtils;
|
|
||||||
import ${package.Parent}.model.form.${entity}Form;
|
|
||||||
import ${package.Parent}.model.query.${entity}PageQuery;
|
|
||||||
import ${package.Parent}.model.bo.${entity}BO;
|
|
||||||
import ${package.Parent}.model.vo.${entity}PageVO;
|
|
||||||
import ${package.Parent}.converter.${entity}Converter;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* $!{table.comment}服务实现类
|
|
||||||
*
|
|
||||||
* @author ${author}
|
|
||||||
* @since ${date}
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {
|
|
||||||
|
|
||||||
private final ${entity}Converter ${firstCharLowerCaseEntity}Converter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取$!{table.comment}分页列表
|
|
||||||
*
|
|
||||||
* @param queryParams 查询参数
|
|
||||||
* @return {@link IPage<${entity}PageVO>} $!{table.comment}分页列表
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public IPage<${entity}PageVO> listPaged${entity}s(${entity}PageQuery queryParams) {
|
|
||||||
|
|
||||||
// 参数构建
|
|
||||||
int pageNum = queryParams.getPageNum();
|
|
||||||
int pageSize = queryParams.getPageSize();
|
|
||||||
Page<${entity}BO> page = new Page<>(pageNum, pageSize);
|
|
||||||
|
|
||||||
// 格式化为数据库日期格式,避免日期比较使用格式化函数导致索引失效
|
|
||||||
DateUtils.toDatabaseFormat(queryParams, "startTime", "endTime");
|
|
||||||
|
|
||||||
// 查询数据
|
|
||||||
Page<${entity}BO> boPage = this.baseMapper.listPaged${entity}s(page, queryParams);
|
|
||||||
|
|
||||||
// 实体转换
|
|
||||||
return ${firstCharLowerCaseEntity}Converter.toPageVo(boPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取$!{table.comment}表单数据
|
|
||||||
*
|
|
||||||
* @param id $!{table.comment}ID
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ${entity}Form get${entity}FormData(Long id) {
|
|
||||||
${entity} entity = this.getById(id);
|
|
||||||
return ${firstCharLowerCaseEntity}Converter.convertToForm(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增$!{table.comment}
|
|
||||||
*
|
|
||||||
* @param formData $!{table.comment}表单对象
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean save${entity}(${entity}Form formData) {
|
|
||||||
// 实体转换 form->entity
|
|
||||||
${entity} entity = ${firstCharLowerCaseEntity}Converter.convertToEntity(formData);
|
|
||||||
return this.save(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新$!{table.comment}
|
|
||||||
*
|
|
||||||
* @param id $!{table.comment}ID
|
|
||||||
* @param formData $!{table.comment}表单对象
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean update${entity}(Long id,${entity}Form formData) {
|
|
||||||
${entity} entity = ${firstCharLowerCaseEntity}Converter.convertToEntity(formData);
|
|
||||||
return this.updateById(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除$!{table.comment}
|
|
||||||
*
|
|
||||||
* @param ids $!{table.comment}ID,多个以英文逗号(,)分割
|
|
||||||
* @return true|false
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean delete${entity}s(String ids) {
|
|
||||||
Assert.isTrue(StrUtil.isNotBlank(ids), "删除的$!{table.comment}数据为空");
|
|
||||||
// 逻辑删除
|
|
||||||
List<Long> idList = Arrays.stream(ids.split(","))
|
|
||||||
.map(Long::parseLong)
|
|
||||||
.toList();
|
|
||||||
return this.removeByIds(idList);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
package ${package.Parent}.model.vo;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
#if(${entityLombokModel})
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
#if(${chainModel})
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
|
|
||||||
/**
|
|
||||||
* $!{table.comment} VO
|
|
||||||
*
|
|
||||||
* @author ${author}
|
|
||||||
* @since ${date}
|
|
||||||
*/
|
|
||||||
#if(${entityLombokModel})
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
#if(${chainModel})
|
|
||||||
@Accessors(chain = true)
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
@Schema( description = "$!{table.comment}视图对象")
|
|
||||||
#if(${superEntityClass})
|
|
||||||
public class ${entity}VO extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
|
|
||||||
#elseif(${activeRecord})
|
|
||||||
public class ${entity} extends Model<${entity}> {
|
|
||||||
#elseif(${entitySerialVersionUID})
|
|
||||||
public class ${entity}VO implements Serializable {
|
|
||||||
#else
|
|
||||||
public class ${entity}VO {
|
|
||||||
#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
|
|
||||||
|
|
||||||
private ${field.propertyType} ${field.propertyName};
|
|
||||||
#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
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user