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);
|
||||
|
||||
Reference in New Issue
Block a user