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.InputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -54,9 +55,9 @@ public class SysUserController {
|
||||
|
||||
@Operation(summary = "用户分页列表")
|
||||
@GetMapping("/page")
|
||||
@LogAnnotation( value = "用户分页列表",module = LogModuleEnum.USER)
|
||||
@LogAnnotation(value = "用户分页列表", module = LogModuleEnum.USER)
|
||||
public PageResult<UserPageVO> listPagedUsers(
|
||||
UserPageQuery queryParams
|
||||
UserPageQuery queryParams
|
||||
) {
|
||||
IPage<UserPageVO> result = userService.listPagedUsers(queryParams);
|
||||
return PageResult.success(result);
|
||||
@@ -138,9 +139,9 @@ public class SysUserController {
|
||||
public void downloadTemplate(HttpServletResponse response) throws IOException {
|
||||
String fileName = "用户导入模板.xlsx";
|
||||
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);
|
||||
|
||||
ServletOutputStream outputStream = response.getOutputStream();
|
||||
@@ -151,7 +152,7 @@ public class SysUserController {
|
||||
|
||||
@Operation(summary = "导入用户")
|
||||
@PostMapping("/import")
|
||||
public Result importUsers( MultipartFile file) throws IOException {
|
||||
public Result importUsers(MultipartFile file) throws IOException {
|
||||
UserImportListener listener = new UserImportListener();
|
||||
String msg = ExcelUtils.importExcel(file.getInputStream(), UserImportDTO.class, listener);
|
||||
return Result.success(msg);
|
||||
|
||||
@@ -14,10 +14,10 @@ import org.mapstruct.Mapper;
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface DeptConverter {
|
||||
|
||||
DeptForm convertToForm(SysDept entity);
|
||||
DeptForm toForm(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);
|
||||
|
||||
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);
|
||||
|
||||
DictForm convertToForm(SysDictItem entity);
|
||||
DictForm toForm(SysDictItem entity);
|
||||
|
||||
SysDictItem convertToEntity(DictForm.DictItem dictFormDictItems);
|
||||
List<SysDictItem> convertToEntity(List<DictForm.DictItem> dictFormDictItems);
|
||||
SysDictItem toEntity(DictForm.DictItem dictFormDictItems);
|
||||
List<SysDictItem> toEntity(List<DictForm.DictItem> dictFormDictItems);
|
||||
|
||||
DictForm.DictItem convertToDictFormDictItem(SysDictItem entity);
|
||||
List<DictForm.DictItem> convertToDictFormDictItem(List<SysDictItem> entities);
|
||||
|
||||
@@ -18,9 +18,9 @@ public interface MenuConverter {
|
||||
MenuVO convertToVo(SysMenu entity);
|
||||
|
||||
@Mapping(target = "params", ignore = true)
|
||||
MenuForm convertToForm(SysMenu entity);
|
||||
MenuForm toForm(SysMenu entity);
|
||||
|
||||
@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);
|
||||
|
||||
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);
|
||||
|
||||
UserForm convertToForm(SysUser entity);
|
||||
UserForm toForm(SysUser entity);
|
||||
|
||||
@InheritInverseConfiguration(name = "convertToForm")
|
||||
SysUser convertToEntity(UserForm entity);
|
||||
@InheritInverseConfiguration(name = "toForm")
|
||||
SysUser toEntity(UserForm entity);
|
||||
|
||||
@Mappings({
|
||||
@Mapping(target = "userId", source = "id")
|
||||
})
|
||||
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()) {
|
||||
// 校验通过,持久化至数据库
|
||||
SysUser entity = userConverter.convertToEntity(userImportDTO);
|
||||
SysUser entity = userConverter.toEntity(userImportDTO);
|
||||
entity.setPassword(passwordEncoder.encode(SystemConstants.DEFAULT_PASSWORD)); // 默认密码
|
||||
// 性别翻译
|
||||
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, "部门编号已存在");
|
||||
|
||||
// form->entity
|
||||
SysDept entity = deptConverter.convertToEntity(formData);
|
||||
SysDept entity = deptConverter.toEntity(formData);
|
||||
|
||||
// 生成部门路径(tree_path),格式:父节点tree_path + , + 父节点ID,用于删除部门时级联删除子部门
|
||||
String treePath = generateDeptTreePath(formData.getParentId());
|
||||
@@ -164,7 +164,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
@Override
|
||||
public DeptForm getDeptForm(Long 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
|
||||
SysDept entity = deptConverter.convertToEntity(formData);
|
||||
SysDept entity = deptConverter.toEntity(formData);
|
||||
entity.setId(deptId);
|
||||
|
||||
// 生成部门路径(tree_path),格式:父节点tree_path + , + 父节点ID,用于删除部门时级联删除子部门
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.youlai.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@@ -62,7 +61,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||
@Override
|
||||
public boolean saveDict(DictForm dictForm) {
|
||||
// 保存字典
|
||||
SysDict entity = dictConverter.convertToEntity(dictForm);
|
||||
SysDict entity = dictConverter.toEntity(dictForm);
|
||||
|
||||
// 校验 code 是否唯一
|
||||
long count = this.count(new LambdaQueryWrapper<SysDict>()
|
||||
@@ -74,7 +73,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||
// 保存字典项
|
||||
if (result) {
|
||||
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()));
|
||||
dictItemService.saveBatch(dictItems);
|
||||
}
|
||||
@@ -92,7 +91,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||
// 获取字典
|
||||
SysDict entity = this.getById(id);
|
||||
Assert.isTrue(entity != null, "字典不存在");
|
||||
DictForm dictForm = dictConverter.convertToForm(entity);
|
||||
DictForm dictForm = dictConverter.toForm(entity);
|
||||
|
||||
// 获取字典项集合
|
||||
List<SysDictItem> dictItems = dictItemService.list(new LambdaQueryWrapper<SysDictItem>()
|
||||
@@ -113,7 +112,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||
@Override
|
||||
public boolean updateDict(Long id, DictForm dictForm) {
|
||||
// 更新字典
|
||||
SysDict entity = dictConverter.convertToEntity(dictForm);
|
||||
SysDict entity = dictConverter.toEntity(dictForm);
|
||||
|
||||
// 校验 code 是否唯一
|
||||
long count = this.count(new LambdaQueryWrapper<SysDict>()
|
||||
@@ -127,7 +126,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||
if (result) {
|
||||
// 更新字典项
|
||||
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>()
|
||||
|
||||
@@ -238,7 +238,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
menuForm.setComponent(null);
|
||||
}
|
||||
|
||||
SysMenu entity = menuConverter.convertToEntity(menuForm);
|
||||
SysMenu entity = menuConverter.toEntity(menuForm);
|
||||
String treePath = generateMenuTreePath(menuForm.getParentId());
|
||||
entity.setTreePath(treePath);
|
||||
|
||||
@@ -303,7 +303,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
public MenuForm getMenuForm(Long id) {
|
||||
SysMenu entity = this.getById(id);
|
||||
Assert.isTrue(entity != null, "菜单不存在");
|
||||
MenuForm formData = menuConverter.convertToForm(entity);
|
||||
MenuForm formData = menuConverter.toForm(entity);
|
||||
// 路由参数字符串 {"id":"1","name":"张三"} 转换为 [{key:"id", value:"1"}, {key:"name", value:"张三"}]
|
||||
String params = entity.getParams();
|
||||
if (StrUtil.isNotBlank(params)) {
|
||||
|
||||
@@ -118,7 +118,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
Assert.isTrue(count == 0, "角色名称或角色编码已存在,请修改后重试!");
|
||||
|
||||
// 实体转换
|
||||
SysRole role = roleConverter.convertToEntity(roleForm);
|
||||
SysRole role = roleConverter.toEntity(roleForm);
|
||||
|
||||
boolean result = this.saveOrUpdate(role);
|
||||
if (result) {
|
||||
@@ -143,7 +143,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
@Override
|
||||
public RoleForm getRoleForm(Long 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, "用户名已存在");
|
||||
|
||||
// 实体转换 form->entity
|
||||
SysUser entity = userConverter.convertToEntity(userForm);
|
||||
SysUser entity = userConverter.toEntity(userForm);
|
||||
|
||||
// 设置默认加密密码
|
||||
String defaultEncryptPwd = passwordEncoder.encode(SystemConstants.DEFAULT_PASSWORD);
|
||||
@@ -141,7 +141,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
Assert.isTrue(count == 0, "用户名已存在");
|
||||
|
||||
// form -> entity
|
||||
SysUser entity = userConverter.convertToEntity(userForm);
|
||||
SysUser entity = userConverter.toEntity(userForm);
|
||||
|
||||
// 修改用户
|
||||
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
|
||||
|
||||
@@ -2,4 +2,6 @@ spring:
|
||||
application:
|
||||
name: youlai-boot
|
||||
profiles:
|
||||
active: dev
|
||||
active: dev
|
||||
include:
|
||||
- generator
|
||||
43
src/main/resources/mapper/DatabaseMapper.xml
Normal file
43
src/main/resources/mapper/DatabaseMapper.xml
Normal file
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.youlai.system.mapper.DatabaseMapper">
|
||||
|
||||
<!-- 查询数据库表分页 -->
|
||||
<select id="getTablePage" resultType="com.youlai.system.model.vo.TablePageVO">
|
||||
SELECT
|
||||
TABLE_NAME ,
|
||||
TABLE_COMMENT ,
|
||||
TABLE_COLLATION,
|
||||
ENGINE,
|
||||
CREATE_TIME
|
||||
FROM
|
||||
information_schema.tables
|
||||
WHERE
|
||||
TABLE_SCHEMA = (SELECT DATABASE())
|
||||
AND table_type = 'BASE TABLE'
|
||||
<if test="queryParams.keywords != null and queryParams.keywords.trim() neq ''">
|
||||
AND TABLE_NAME LIKE CONCAT('%',#{queryParams.keywords},'%')
|
||||
</if>
|
||||
ORDER BY
|
||||
CREATE_TIME DESC
|
||||
</select>
|
||||
|
||||
<select id="getTableColumns" resultType="com.youlai.system.model.vo.TableColumnVO">
|
||||
SELECT
|
||||
COLUMN_NAME,
|
||||
DATA_TYPE,
|
||||
COLUMN_COMMENT,
|
||||
CASE COLUMN_KEY WHEN 'PRI' THEN 1 ELSE 0 END AS isPrimaryKey,
|
||||
IS_NULLABLE,
|
||||
CHARACTER_MAXIMUM_LENGTH,
|
||||
CHARACTER_SET_NAME,
|
||||
COLLATION_NAME
|
||||
FROM
|
||||
information_schema.columns
|
||||
WHERE
|
||||
TABLE_SCHEMA = (SELECT DATABASE())
|
||||
AND TABLE_NAME = #{tableName}
|
||||
</select>
|
||||
</mapper>
|
||||
72
src/main/resources/templates/generator/controller.java.vm
Normal file
72
src/main/resources/templates/generator/controller.java.vm
Normal file
@@ -0,0 +1,72 @@
|
||||
package ${package}.controller;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ${package}.model.form.${entityName}Form;
|
||||
import ${package}.model.query.${entityName}PageQuery;
|
||||
import ${package}.model.vo.${entityName}PageVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.youlai.common.result.PageResult;
|
||||
import com.youlai.common.result.Result;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
/**
|
||||
* $!{tableComment} 前端控制器
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Tag(name = "${tableComment}接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/${lowerFirstEntityName}s")
|
||||
@RequiredArgsConstructor
|
||||
public class ${entityName}Controller {
|
||||
|
||||
private final ${entityName}Serivie ${lowerFirstEntityName}Service;
|
||||
|
||||
@Operation(summary = "$!{tableComment}分页列表")
|
||||
@GetMapping("/page")
|
||||
public PageResult<${entityName}PageVO> get${entityName}Page(${entityName}PageQuery queryParams ) {
|
||||
IPage<${entityName}PageVO> result = ${lowerFirstEntityName}Service.get${entityName}Page(queryParams);
|
||||
return PageResult.success(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "新增$!{tableComment}")
|
||||
@PostMapping
|
||||
public Result save${entityName}(@RequestBody @Valid ${entityName}Form formData ) {
|
||||
boolean result = ${lowerFirstEntityName}Service.save${entityName}(formData);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "$!{tableComment}表单数据")
|
||||
@GetMapping("/{id}/form")
|
||||
public Result<${entityName}Form> get${entityName}Form(
|
||||
@Parameter(description = "$!{tableComment}ID") @PathVariable Long id
|
||||
) {
|
||||
${entityName}Form formData = ${lowerFirstEntityName}Service.get${entityName}FormData(id);
|
||||
return Result.success(formData);
|
||||
}
|
||||
|
||||
@Operation(summary = "修改$!{tableComment}")
|
||||
@PutMapping(value = "/{id}")
|
||||
public Result update${entityName}(@Parameter(description = "$!{tableComment}ID") @PathVariable Long id,
|
||||
@RequestBody @Validated ${entityName}Form formData) {
|
||||
boolean result = ${lowerFirstEntityName}Service.update${entityName}(id, formData);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除$!{tableComment}")
|
||||
@DeleteMapping("/{ids}")
|
||||
public Result delete${entityName}s(
|
||||
@Parameter(description = "$!{tableComment}ID,多个以英文逗号(,)分割") @PathVariable String ids
|
||||
) {
|
||||
boolean result = ${lowerFirstEntityName}Service.delete${entityName}s(ids);
|
||||
return Result.judge(result);
|
||||
}
|
||||
}
|
||||
20
src/main/resources/templates/generator/converter.java.vm
Normal file
20
src/main/resources/templates/generator/converter.java.vm
Normal file
@@ -0,0 +1,20 @@
|
||||
package ${package}.converter;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import ${package}.model.entity.${entityName};
|
||||
import ${package}.model.form.${entityName}Form;
|
||||
|
||||
/**
|
||||
* $!{tableComment}转换器
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface ${entityName}Converter{
|
||||
|
||||
${entityName}Form toForm(${entityName} entity);
|
||||
|
||||
${entityName} toEntity(${entityName}Form entity);
|
||||
}
|
||||
35
src/main/resources/templates/generator/entity.java.vm
Normal file
35
src/main/resources/templates/generator/entity.java.vm
Normal file
@@ -0,0 +1,35 @@
|
||||
package ${package}.model.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
#if(${hasLocalDateTime})
|
||||
import java.time.LocalDateTime;
|
||||
#end
|
||||
#if(${hasBigDecimal})
|
||||
import java.math.BigDecimal;
|
||||
#end
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.youlai.system.common.base.BaseEntity;
|
||||
|
||||
/**
|
||||
* $!{tableComment}实体对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("${tableName}")
|
||||
public class ${entityName} extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
#foreach($field in ${table.fields})
|
||||
#if("$!field.comment" != "")
|
||||
/**
|
||||
* ${field.comment}
|
||||
*/
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
}
|
||||
37
src/main/resources/templates/generator/form.java.vm
Normal file
37
src/main/resources/templates/generator/form.java.vm
Normal file
@@ -0,0 +1,37 @@
|
||||
package ${package}.model.form;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
#if(${hasLocalDateTime})
|
||||
import java.time.LocalDateTime;
|
||||
#end
|
||||
#if(${hasBigDecimal})
|
||||
import java.math.BigDecimal;
|
||||
#end
|
||||
|
||||
|
||||
/**
|
||||
* $!{tableComment} 表单对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "$!{tableComment}表单对象")
|
||||
public class ${entityName}Form implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
## ---------- BEGIN 字段循环遍历 ----------
|
||||
#foreach($field in ${fields})
|
||||
#if("$!field.comment" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
}
|
||||
27
src/main/resources/templates/generator/mapper.java.vm
Normal file
27
src/main/resources/templates/generator/mapper.java.vm
Normal file
@@ -0,0 +1,27 @@
|
||||
package ${package}.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import ${package}.model.entity.${entityName};
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import ${package}.model.query.${entityName}Query;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* $!{tableComment} 数据库访问层
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Mapper
|
||||
public interface ${entityName}Mapper extends BaseMapper<${entityName}> {
|
||||
|
||||
/**
|
||||
* 获取$!{tableComment}分页数据
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param queryParams 查询参数
|
||||
* @return
|
||||
*/
|
||||
Page<${entityName}VO> get${entityName}Page(Page<${entityName}VO> page, ${entityName}Query queryParams);
|
||||
|
||||
}
|
||||
29
src/main/resources/templates/generator/mapper.xml.vm
Normal file
29
src/main/resources/templates/generator/mapper.xml.vm
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="${package}.mapper.${entityName}Mapper">
|
||||
|
||||
<!-- 获取${tableComment}分页列表 -->
|
||||
<select id="listPaged${entityName}s" resultType="${package}.model.entity.${entityName}">
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
${tableName}
|
||||
<where>
|
||||
is_deleted = 0
|
||||
<if test='queryParams.keywords!=null and queryParams.keywords.trim() neq ""'>
|
||||
AND (
|
||||
name LIKE CONCAT('%',#{queryParams.keywords},'%')
|
||||
)
|
||||
</if>
|
||||
<if test="queryParams.startTime != null">
|
||||
AND create_time >= #{queryParams.startTime}
|
||||
</if>
|
||||
<if test="queryParams.endTime != null">
|
||||
AND create_time <= #{queryParams.endTime}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY
|
||||
create_time DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
34
src/main/resources/templates/generator/query.java.vm
Normal file
34
src/main/resources/templates/generator/query.java.vm
Normal file
@@ -0,0 +1,34 @@
|
||||
package ${package}.model.query;
|
||||
|
||||
import com.youlai.common.base.BasePageQuery;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
#if(${hasLocalDateTime})
|
||||
import java.time.LocalDateTime;
|
||||
#end
|
||||
#if(${hasBigDecimal})
|
||||
import java.math.BigDecimal;
|
||||
#end
|
||||
|
||||
|
||||
/**
|
||||
* $!{tableComment}分页查询对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Schema(description ="$!{tableComment}分页查询对象")
|
||||
@Getter
|
||||
@Setter
|
||||
public class ${entityName}Query extends BasePageQuery {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
#foreach($field in ${fields})
|
||||
#if("$!field.comment" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
}
|
||||
61
src/main/resources/templates/generator/service.java.vm
Normal file
61
src/main/resources/templates/generator/service.java.vm
Normal file
@@ -0,0 +1,61 @@
|
||||
package ${package}.Service;
|
||||
|
||||
import ${package}.model.entity.${entityName};
|
||||
import ${package}.model.form.${entityName}Form;
|
||||
import ${package}.model.query.${entityName}PageQuery;
|
||||
import ${package}.model.vo.${entityName}PageVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
/**
|
||||
* $!{tableComment} 服务类
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
public interface ${entityName}Service extends IService<${entityName}> {
|
||||
|
||||
|
||||
/**
|
||||
*$!{tableComment}分页列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
IPage<${entityName}VO> get${entityName}Page(${entityName}Query queryParams);
|
||||
|
||||
|
||||
/**
|
||||
* 获取$!{tableComment}表单数据
|
||||
*
|
||||
* @param id $!{tableComment}ID
|
||||
* @return
|
||||
*/
|
||||
${entityName}Form get${entityName}FormData(Long id);
|
||||
|
||||
|
||||
/**
|
||||
* 新增$!{tableComment}
|
||||
*
|
||||
* @param formData $!{tableComment}表单对象
|
||||
* @return
|
||||
*/
|
||||
boolean save${entityName}(${entityName}Form formData);
|
||||
|
||||
/**
|
||||
* 修改$!{tableComment}
|
||||
*
|
||||
* @param id $!{tableComment}ID
|
||||
* @param formData $!{tableComment}表单对象
|
||||
* @return
|
||||
*/
|
||||
boolean update${entityName}(Long id, ${entityName}Form formData);
|
||||
|
||||
|
||||
/**
|
||||
* 删除$!{tableComment}
|
||||
*
|
||||
* @param ids $!{tableComment}ID,多个以英文逗号(,)分割
|
||||
* @return
|
||||
*/
|
||||
boolean delete${entityName}s(String ids);
|
||||
|
||||
}
|
||||
103
src/main/resources/templates/generator/serviceImpl.java.vm
Normal file
103
src/main/resources/templates/generator/serviceImpl.java.vm
Normal file
@@ -0,0 +1,103 @@
|
||||
package ${package}.service.impl;
|
||||
|
||||
import ${package}.model.entity.${entityName};
|
||||
import ${package}.mapper.${entityName}Mapper;
|
||||
import ${package}.service.${entityName}Service;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ${package}.model.form.${entityName}Form;
|
||||
import ${package}.model.query.${entityName}Query;
|
||||
import ${package}.model.vo.${entityName}PageVO;
|
||||
import ${package}.converter.${entityName}Converter;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* $!{tableComment}服务实现类
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ${table.serviceImplName} extends ServiceImpl<${entityName}Mapper, ${entityName}> implements ${entityName}Service {
|
||||
|
||||
private final ${entityName}Converter ${lowerFirstEntityName}Converter;
|
||||
|
||||
/**
|
||||
* 获取$!{tableComment}分页列表
|
||||
*
|
||||
* @param queryParams 查询参数
|
||||
* @return {@link IPage<${entityName}PageVO>} $!{tableComment}分页列表
|
||||
*/
|
||||
@Override
|
||||
public IPage<${entityName}VO> get${entityName}Page(${entityName}Query queryParams) {
|
||||
Page<${entityName}VO> pageVO = this.baseMapper.get${entityName}Page(
|
||||
new Page<>(queryParams.getPageNum(), queryParams.getPageSize()),
|
||||
queryParams
|
||||
);
|
||||
returnv pageVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取$!{tableComment}表单数据
|
||||
*
|
||||
* @param id $!{tableComment}ID
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ${entityName}Form get${entityName}FormData(Long id) {
|
||||
${entityName} entity = this.getById(id);
|
||||
return ${lowerFirstEntityName}Converter.toForm(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增$!{tableComment}
|
||||
*
|
||||
* @param formData $!{tableComment}表单对象
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean save${entityName}(${entityName}Form formData) {
|
||||
${entityName} entity = ${lowerFirstEntityName}Converter.toEntity(formData);
|
||||
return this.save(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新$!{tableComment}
|
||||
*
|
||||
* @param id $!{tableComment}ID
|
||||
* @param formData $!{tableComment}表单对象
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean update${entityName}(Long id,${entityName}Form formData) {
|
||||
${entityName} entity = ${lowerFirstEntityName}Converter.toEntity(formData);
|
||||
return this.updateById(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除$!{tableComment}
|
||||
*
|
||||
* @param ids $!{tableComment}ID,多个以英文逗号(,)分割
|
||||
* @return true|false
|
||||
*/
|
||||
@Override
|
||||
public boolean delete${entityName}s(String ids) {
|
||||
Assert.isTrue(StrUtil.isNotBlank(ids), "删除的$!{tableComment}数据为空");
|
||||
// 逻辑删除
|
||||
List<Long> idList = Arrays.stream(ids.split(","))
|
||||
.map(Long::parseLong)
|
||||
.toList();
|
||||
return this.removeByIds(idList);
|
||||
}
|
||||
|
||||
}
|
||||
37
src/main/resources/templates/generator/vo.java.vm
Normal file
37
src/main/resources/templates/generator/vo.java.vm
Normal file
@@ -0,0 +1,37 @@
|
||||
package ${package}.model.vo;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
#if(${hasLocalDateTime})
|
||||
import java.time.LocalDateTime;
|
||||
#end
|
||||
#if(${hasBigDecimal})
|
||||
import java.math.BigDecimal;
|
||||
#end
|
||||
|
||||
/**
|
||||
* $!{tableComment} 图对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema( description = "$!{tableComment}视图对象")
|
||||
public class ${entityName}VO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
#foreach($field in ${fields})
|
||||
#if("$!field.comment" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user