mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 20:49:00 +08:00
♻️ Refactoring code. Vo -> VO
This commit is contained in:
1 parent
61bfcc00de
commit
07d9f0c98c
8 files changed
+256
-263
No files matched your search
@@ -25,7 +25,7 @@ import com.pig4cloud.pigx.admin.api.entity.SysOauthClientDetails;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysTenant;
|
||||
import com.pig4cloud.pigx.admin.api.feign.RemoteClientDetailsService;
|
||||
import com.pig4cloud.pigx.admin.api.feign.RemoteTenantService;
|
||||
import com.pig4cloud.pigx.admin.api.vo.TokenVo;
|
||||
import com.pig4cloud.pigx.admin.api.vo.TokenVO;
|
||||
import com.pig4cloud.pigx.auth.support.handler.PigxAuthenticationFailureEventHandler;
|
||||
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
|
||||
@@ -202,18 +202,18 @@ public class PigxTokenEndpoint {
|
||||
*/
|
||||
@Inner
|
||||
@PostMapping("/page")
|
||||
public R<Page<TokenVo>> tokenList(@RequestBody Map<String, Object> params) {
|
||||
public R<Page<TokenVO>> tokenList(@RequestBody Map<String, Object> params) {
|
||||
// 根据分页参数获取对应数据
|
||||
String key = String.format("%s::%s::*", tenantKeyStrResolver.key(), CacheConstants.PROJECT_OAUTH_ACCESS);
|
||||
int current = MapUtil.getInt(params, CommonConstants.CURRENT);
|
||||
int size = MapUtil.getInt(params, CommonConstants.SIZE);
|
||||
Set<String> keys = redisTemplate.keys(key);
|
||||
List<String> pages = keys.stream().skip((current - 1) * size).limit(size).collect(Collectors.toList());
|
||||
Page<TokenVo> result = new Page(current, size);
|
||||
Page<TokenVO> result = new Page(current, size);
|
||||
|
||||
List<TokenVo> tokenVoList = redisTemplate.opsForValue().multiGet(pages).stream().map(obj -> {
|
||||
List<TokenVO> tokenVoList = redisTemplate.opsForValue().multiGet(pages).stream().map(obj -> {
|
||||
OAuth2Authorization authorization = (OAuth2Authorization) obj;
|
||||
TokenVo tokenVo = new TokenVo();
|
||||
TokenVO tokenVo = new TokenVO();
|
||||
tokenVo.setClientId(authorization.getRegisteredClientId());
|
||||
tokenVo.setId(authorization.getId());
|
||||
tokenVo.setUsername(authorization.getPrincipalName());
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import java.io.Serializable;
|
||||
* 部门导入导出
|
||||
*/
|
||||
@Data
|
||||
public class DeptExcelVo implements Serializable {
|
||||
public class DeptExcelVO implements Serializable {
|
||||
|
||||
/**
|
||||
* 导入时候回显行号
|
||||
+1
-1
@@ -9,7 +9,7 @@ import lombok.Data;
|
||||
* @date 2022/6/2
|
||||
*/
|
||||
@Data
|
||||
public class TokenVo {
|
||||
public class TokenVO {
|
||||
|
||||
private String id;
|
||||
|
||||
+3
-3
@@ -20,7 +20,7 @@
|
||||
package com.pig4cloud.pigx.admin.controller;
|
||||
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysDept;
|
||||
import com.pig4cloud.pigx.admin.api.vo.DeptExcelVo;
|
||||
import com.pig4cloud.pigx.admin.api.vo.DeptExcelVO;
|
||||
import com.pig4cloud.pigx.admin.service.SysDeptService;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.excel.annotation.RequestExcel;
|
||||
@@ -140,7 +140,7 @@ public class SysDeptController {
|
||||
*/
|
||||
@ResponseExcel
|
||||
@GetMapping("/export")
|
||||
public List<DeptExcelVo> export() {
|
||||
public List<DeptExcelVO> export() {
|
||||
return sysDeptService.listExcelVo();
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ public class SysDeptController {
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("import")
|
||||
public R importDept(@RequestExcel List<DeptExcelVo> excelVOList, BindingResult bindingResult) {
|
||||
public R importDept(@RequestExcel List<DeptExcelVO> excelVOList, BindingResult bindingResult) {
|
||||
return sysDeptService.importDept(excelVOList, bindingResult);
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@ package com.pig4cloud.pigx.admin.service;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysDept;
|
||||
import com.pig4cloud.pigx.admin.api.vo.DeptExcelVo;
|
||||
import com.pig4cloud.pigx.admin.api.vo.DeptExcelVO;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import org.springframework.validation.BindingResult;
|
||||
|
||||
@@ -52,9 +52,9 @@ public interface SysDeptService extends IService<SysDept> {
|
||||
*/
|
||||
Boolean removeDeptById(Long id);
|
||||
|
||||
List<DeptExcelVo> listExcelVo();
|
||||
List<DeptExcelVO> listExcelVo();
|
||||
|
||||
R importDept(List<DeptExcelVo> excelVOList, BindingResult bindingResult);
|
||||
R importDept(List<DeptExcelVO> excelVOList, BindingResult bindingResult);
|
||||
|
||||
/**
|
||||
* 获取部门的所有后代部门列表
|
||||
|
||||
+6
-6
@@ -30,7 +30,7 @@ import com.pig4cloud.pigx.admin.api.entity.SysDept;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysPost;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysUser;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysUserPost;
|
||||
import com.pig4cloud.pigx.admin.api.vo.DeptExcelVo;
|
||||
import com.pig4cloud.pigx.admin.api.vo.DeptExcelVO;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysDeptMapper;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysPostMapper;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysUserMapper;
|
||||
@@ -141,10 +141,10 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<DeptExcelVo> listExcelVo() {
|
||||
public List<DeptExcelVO> listExcelVo() {
|
||||
List<SysDept> list = this.list();
|
||||
List<DeptExcelVo> deptExcelVos = list.stream().map(item -> {
|
||||
DeptExcelVo deptExcelVo = new DeptExcelVo();
|
||||
List<DeptExcelVO> deptExcelVos = list.stream().map(item -> {
|
||||
DeptExcelVO deptExcelVo = new DeptExcelVO();
|
||||
deptExcelVo.setName(item.getName());
|
||||
Optional<String> first = this.list()
|
||||
.stream()
|
||||
@@ -159,11 +159,11 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public R importDept(List<DeptExcelVo> excelVOList, BindingResult bindingResult) {
|
||||
public R importDept(List<DeptExcelVO> excelVOList, BindingResult bindingResult) {
|
||||
List<ErrorMessage> errorMessageList = (List<ErrorMessage>) bindingResult.getTarget();
|
||||
|
||||
List<SysDept> deptList = this.list();
|
||||
for (DeptExcelVo item : excelVOList) {
|
||||
for (DeptExcelVO item : excelVOList) {
|
||||
Set<String> errorMsg = new HashSet<>();
|
||||
boolean exsitUsername = deptList.stream().anyMatch(sysDept -> item.getName().equals(sysDept.getName()));
|
||||
if (exsitUsername) {
|
||||
|
||||
+3
-2
@@ -99,7 +99,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
public Boolean saveUser(UserDTO userDto) {
|
||||
SysUser sysUser = new SysUser();
|
||||
BeanUtils.copyProperties(userDto, sysUser);
|
||||
sysUser.setDelFlag(StrUtil.isBlank(userDto.getLockFlag()) ? CommonConstants.STATUS_NORMAL : sysUser.getDelFlag());
|
||||
sysUser
|
||||
.setDelFlag(StrUtil.isBlank(userDto.getLockFlag()) ? CommonConstants.STATUS_NORMAL : sysUser.getDelFlag());
|
||||
sysUser.setCreateBy(userDto.getUsername());
|
||||
sysUser.setUpdateBy(userDto.getUsername());
|
||||
sysUser.setPassword(ENCODER.encode(userDto.getPassword()));
|
||||
@@ -394,7 +395,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
userDTO.setNickname(excel.getNickname());
|
||||
userDTO.setName(excel.getName());
|
||||
userDTO.setEmail(excel.getEmail());
|
||||
userDTO.setLockFlag(excel.getLockFlag());
|
||||
userDTO.setLockFlag(excel.getLockFlag());
|
||||
// 批量导入初始密码为手机号
|
||||
userDTO.setPassword(userDTO.getPhone());
|
||||
// 根据部门名称查询部门ID
|
||||
|
||||
+234
-242
@@ -55,293 +55,285 @@ import java.util.zip.ZipOutputStream;
|
||||
@RequiredArgsConstructor
|
||||
public class GeneratorServiceImpl implements GeneratorService {
|
||||
|
||||
private final GenTableColumnService columnService;
|
||||
private final GenTableColumnService columnService;
|
||||
|
||||
private final GenFormConfService formConfService;
|
||||
private final GenFormConfService formConfService;
|
||||
|
||||
private final GenFieldTypeService fieldTypeService;
|
||||
private final GenFieldTypeService fieldTypeService;
|
||||
|
||||
private final GenTableService tableService;
|
||||
private final GenTableService tableService;
|
||||
|
||||
private final GenGroupService genGroupService;
|
||||
private final GenGroupService genGroupService;
|
||||
|
||||
private final GenTemplateService genTemplateService;
|
||||
private final GenTemplateService genTemplateService;
|
||||
|
||||
/**
|
||||
* 生成代码zip写出
|
||||
*
|
||||
* @param tableId 表
|
||||
* @param zip 输出流
|
||||
*/
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void downloadCode(Long tableId, ZipOutputStream zip) {
|
||||
// 数据模型
|
||||
Map<String, Object> dataModel = getDataModel(tableId);
|
||||
/**
|
||||
* 生成代码zip写出
|
||||
* @param tableId 表
|
||||
* @param zip 输出流
|
||||
*/
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void downloadCode(Long tableId, ZipOutputStream zip) {
|
||||
// 数据模型
|
||||
Map<String, Object> dataModel = getDataModel(tableId);
|
||||
|
||||
Long style = (Long) dataModel.get("style");
|
||||
Long style = (Long) dataModel.get("style");
|
||||
|
||||
GroupVo groupVo = genGroupService.getGroupVoById(style);
|
||||
List<GenTemplateEntity> templateList = groupVo.getTemplateList();
|
||||
GroupVo groupVo = genGroupService.getGroupVoById(style);
|
||||
List<GenTemplateEntity> templateList = groupVo.getTemplateList();
|
||||
|
||||
Map<String, Object> generatorConfig = tableService.getGeneratorConfig();
|
||||
JSONObject project = (JSONObject) generatorConfig.get("project");
|
||||
String frontendPath = project.getStr("frontendPath");
|
||||
String backendPath = project.getStr("backendPath");
|
||||
Map<String, Object> generatorConfig = tableService.getGeneratorConfig();
|
||||
JSONObject project = (JSONObject) generatorConfig.get("project");
|
||||
String frontendPath = project.getStr("frontendPath");
|
||||
String backendPath = project.getStr("backendPath");
|
||||
|
||||
for (GenTemplateEntity template : templateList) {
|
||||
String templateCode = template.getTemplateCode();
|
||||
String generatorPath = template.getGeneratorPath();
|
||||
for (GenTemplateEntity template : templateList) {
|
||||
String templateCode = template.getTemplateCode();
|
||||
String generatorPath = template.getGeneratorPath();
|
||||
|
||||
dataModel.put("frontendPath", frontendPath);
|
||||
dataModel.put("backendPath", backendPath);
|
||||
String content = VelocityKit.renderStr(templateCode, dataModel);
|
||||
String path = VelocityKit.renderStr(generatorPath, dataModel);
|
||||
dataModel.put("frontendPath", frontendPath);
|
||||
dataModel.put("backendPath", backendPath);
|
||||
String content = VelocityKit.renderStr(templateCode, dataModel);
|
||||
String path = VelocityKit.renderStr(generatorPath, dataModel);
|
||||
|
||||
// 添加到zip
|
||||
zip.putNextEntry(new ZipEntry(path));
|
||||
IoUtil.writeUtf8(zip, false, content);
|
||||
zip.flush();
|
||||
zip.closeEntry();
|
||||
}
|
||||
// 添加到zip
|
||||
zip.putNextEntry(new ZipEntry(path));
|
||||
IoUtil.writeUtf8(zip, false, content);
|
||||
zip.flush();
|
||||
zip.closeEntry();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 表达式优化的预览代码方法
|
||||
*
|
||||
* @param tableId 表
|
||||
* @return [{模板名称:渲染结果}]
|
||||
*/
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public List<Map<String, String>> preview(Long tableId) {
|
||||
// 数据模型
|
||||
Map<String, Object> dataModel = getDataModel(tableId);
|
||||
/**
|
||||
* 表达式优化的预览代码方法
|
||||
* @param tableId 表
|
||||
* @return [{模板名称:渲染结果}]
|
||||
*/
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public List<Map<String, String>> preview(Long tableId) {
|
||||
// 数据模型
|
||||
Map<String, Object> dataModel = getDataModel(tableId);
|
||||
|
||||
Long style = (Long) dataModel.get("style");
|
||||
Long style = (Long) dataModel.get("style");
|
||||
|
||||
// 获取模板列表,Lambda 表达式简化代码
|
||||
List<GenTemplateEntity> templateList = genGroupService.getGroupVoById(style).getTemplateList();
|
||||
// 获取模板列表,Lambda 表达式简化代码
|
||||
List<GenTemplateEntity> templateList = genGroupService.getGroupVoById(style).getTemplateList();
|
||||
|
||||
Map<String, Object> generatorConfig = tableService.getGeneratorConfig();
|
||||
JSONObject project = (JSONObject) generatorConfig.get("project");
|
||||
String frontendPath = project.getStr("frontendPath");
|
||||
String backendPath = project.getStr("backendPath");
|
||||
Map<String, Object> generatorConfig = tableService.getGeneratorConfig();
|
||||
JSONObject project = (JSONObject) generatorConfig.get("project");
|
||||
String frontendPath = project.getStr("frontendPath");
|
||||
String backendPath = project.getStr("backendPath");
|
||||
|
||||
return templateList.stream().map(template -> {
|
||||
String templateCode = template.getTemplateCode();
|
||||
String generatorPath = template.getGeneratorPath();
|
||||
return templateList.stream().map(template -> {
|
||||
String templateCode = template.getTemplateCode();
|
||||
String generatorPath = template.getGeneratorPath();
|
||||
|
||||
// 预览模式下, 使用相对路径展示
|
||||
dataModel.put("frontendPath", frontendPath);
|
||||
dataModel.put("backendPath", backendPath);
|
||||
String content = VelocityKit.renderStr(templateCode, dataModel);
|
||||
String path = VelocityKit.renderStr(generatorPath, dataModel);
|
||||
// 预览模式下, 使用相对路径展示
|
||||
dataModel.put("frontendPath", frontendPath);
|
||||
dataModel.put("backendPath", backendPath);
|
||||
String content = VelocityKit.renderStr(templateCode, dataModel);
|
||||
String path = VelocityKit.renderStr(generatorPath, dataModel);
|
||||
|
||||
// 使用 map 简化代码
|
||||
return new HashMap<String, String>(4) {
|
||||
{
|
||||
put("code", content);
|
||||
put("codePath", path);
|
||||
}
|
||||
};
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
// 使用 map 简化代码
|
||||
return new HashMap<String, String>(4) {
|
||||
{
|
||||
put("code", content);
|
||||
put("codePath", path);
|
||||
}
|
||||
};
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 目标目录写入渲染结果方法
|
||||
*
|
||||
* @param tableId 表
|
||||
*/
|
||||
@Override
|
||||
public void generatorCode(Long tableId) {
|
||||
// 数据模型
|
||||
Map<String, Object> dataModel = getDataModel(tableId);
|
||||
Long style = (Long) dataModel.get("style");
|
||||
/**
|
||||
* 目标目录写入渲染结果方法
|
||||
* @param tableId 表
|
||||
*/
|
||||
@Override
|
||||
public void generatorCode(Long tableId) {
|
||||
// 数据模型
|
||||
Map<String, Object> dataModel = getDataModel(tableId);
|
||||
Long style = (Long) dataModel.get("style");
|
||||
|
||||
// 获取模板列表,Lambda 表达式简化代码
|
||||
List<GenTemplateEntity> templateList = genGroupService.getGroupVoById(style).getTemplateList();
|
||||
// 获取模板列表,Lambda 表达式简化代码
|
||||
List<GenTemplateEntity> templateList = genGroupService.getGroupVoById(style).getTemplateList();
|
||||
|
||||
templateList.forEach(template -> {
|
||||
String templateCode = template.getTemplateCode();
|
||||
String generatorPath = template.getGeneratorPath();
|
||||
String content = VelocityKit.renderStr(templateCode, dataModel);
|
||||
String path = VelocityKit.renderStr(generatorPath, dataModel);
|
||||
FileUtil.writeUtf8String(content, path);
|
||||
});
|
||||
}
|
||||
templateList.forEach(template -> {
|
||||
String templateCode = template.getTemplateCode();
|
||||
String generatorPath = template.getGeneratorPath();
|
||||
String content = VelocityKit.renderStr(templateCode, dataModel);
|
||||
String path = VelocityKit.renderStr(generatorPath, dataModel);
|
||||
FileUtil.writeUtf8String(content, path);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表单设计器需要的 JSON 方法
|
||||
*
|
||||
* @param dsName 数据源名称
|
||||
* @param tableName 表名称
|
||||
* @return JSON 字符串
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public String vform(String dsName, String tableName) {
|
||||
// 查询表的元数据
|
||||
GenTable genTable = tableService.queryOrBuildTable(dsName, tableName);
|
||||
/**
|
||||
* 获取表单设计器需要的 JSON 方法
|
||||
* @param dsName 数据源名称
|
||||
* @param tableName 表名称
|
||||
* @return JSON 字符串
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public String vform(String dsName, String tableName) {
|
||||
// 查询表的元数据
|
||||
GenTable genTable = tableService.queryOrBuildTable(dsName, tableName);
|
||||
|
||||
// 获取数据模型
|
||||
Map<String, Object> dataModel = getDataModel(genTable.getId());
|
||||
// 获取数据模型
|
||||
Map<String, Object> dataModel = getDataModel(genTable.getId());
|
||||
|
||||
// 获取模板信息,Lambda 表达式简化代码
|
||||
GenTemplateEntity genTemplateEntity = Optional
|
||||
.ofNullable(genTemplateService.getById(GeneratorStyleEnum.VFORM_JSON.getTemplateId()))
|
||||
.orElseThrow(() -> new Exception("模板不存在"));
|
||||
// 获取模板信息,Lambda 表达式简化代码
|
||||
GenTemplateEntity genTemplateEntity = Optional
|
||||
.ofNullable(genTemplateService.getById(GeneratorStyleEnum.VFORM_JSON.getTemplateId()))
|
||||
.orElseThrow(() -> new Exception("模板不存在"));
|
||||
|
||||
// 渲染模板并返回结果
|
||||
return VelocityKit.renderStr(genTemplateEntity.getTemplateCode(), dataModel);
|
||||
}
|
||||
// 渲染模板并返回结果
|
||||
return VelocityKit.renderStr(genTemplateEntity.getTemplateCode(), dataModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表单设计器需要的 JSON 方法
|
||||
*
|
||||
* @param id 表单配置 ID
|
||||
* @return JSON 字符串
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public String vformSfc(Long id) {
|
||||
// 获取表单配置信息
|
||||
GenFormConf formConf = formConfService.getById(id);
|
||||
/**
|
||||
* 获取表单设计器需要的 JSON 方法
|
||||
* @param id 表单配置 ID
|
||||
* @return JSON 字符串
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public String vformSfc(Long id) {
|
||||
// 获取表单配置信息
|
||||
GenFormConf formConf = formConfService.getById(id);
|
||||
|
||||
// 查询表的元数据
|
||||
GenTable genTable = tableService.queryOrBuildTable(formConf.getDsName(), formConf.getTableName());
|
||||
// 查询表的元数据
|
||||
GenTable genTable = tableService.queryOrBuildTable(formConf.getDsName(), formConf.getTableName());
|
||||
|
||||
// 获取数据模型
|
||||
Map<String, Object> dataModel = getDataModel(genTable.getId());
|
||||
// 获取数据模型
|
||||
Map<String, Object> dataModel = getDataModel(genTable.getId());
|
||||
|
||||
// 解析组件列表
|
||||
Map<String, List<JSONObject>> resultMap = formConfService.parse(formConf.getFormInfo());
|
||||
// 解析组件列表
|
||||
Map<String, List<JSONObject>> resultMap = formConfService.parse(formConf.getFormInfo());
|
||||
|
||||
// 遍历 widgetList
|
||||
dataModel.put("resultMap", resultMap);
|
||||
// 遍历 widgetList
|
||||
dataModel.put("resultMap", resultMap);
|
||||
|
||||
// 获取模板信息
|
||||
GenTemplateEntity genTemplateEntity = Optional
|
||||
.ofNullable(genTemplateService.getById(GeneratorStyleEnum.VFORM_FORM.getTemplateId()))
|
||||
.orElseThrow(() -> new Exception("模板不存在"));
|
||||
// 获取模板信息
|
||||
GenTemplateEntity genTemplateEntity = Optional
|
||||
.ofNullable(genTemplateService.getById(GeneratorStyleEnum.VFORM_FORM.getTemplateId()))
|
||||
.orElseThrow(() -> new Exception("模板不存在"));
|
||||
|
||||
// 渲染模板并返回结果
|
||||
return VelocityKit.renderStr(genTemplateEntity.getTemplateCode(), dataModel);
|
||||
}
|
||||
// 渲染模板并返回结果
|
||||
return VelocityKit.renderStr(genTemplateEntity.getTemplateCode(), dataModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 Lambda 表达式优化的获取数据模型方法
|
||||
*
|
||||
* @param tableId 表格 ID
|
||||
* @return 数据模型 Map 对象
|
||||
*/
|
||||
private Map<String, Object> getDataModel(Long tableId) {
|
||||
// 获取表格信息
|
||||
GenTable table = tableService.getById(tableId);
|
||||
// 获取字段列表
|
||||
List<GenTableColumnEntity> fieldList = columnService.lambdaQuery()
|
||||
.eq(GenTableColumnEntity::getDsName, table.getDsName())
|
||||
.eq(GenTableColumnEntity::getTableName, table.getTableName())
|
||||
.orderByAsc(GenTableColumnEntity::getSort)
|
||||
.list();
|
||||
/**
|
||||
* 通过 Lambda 表达式优化的获取数据模型方法
|
||||
* @param tableId 表格 ID
|
||||
* @return 数据模型 Map 对象
|
||||
*/
|
||||
private Map<String, Object> getDataModel(Long tableId) {
|
||||
// 获取表格信息
|
||||
GenTable table = tableService.getById(tableId);
|
||||
// 获取字段列表
|
||||
List<GenTableColumnEntity> fieldList = columnService.lambdaQuery()
|
||||
.eq(GenTableColumnEntity::getDsName, table.getDsName())
|
||||
.eq(GenTableColumnEntity::getTableName, table.getTableName())
|
||||
.orderByAsc(GenTableColumnEntity::getSort)
|
||||
.list();
|
||||
|
||||
table.setFieldList(fieldList);
|
||||
table.setFieldList(fieldList);
|
||||
|
||||
// 创建数据模型对象
|
||||
Map<String, Object> dataModel = new HashMap<>();
|
||||
// 创建数据模型对象
|
||||
Map<String, Object> dataModel = new HashMap<>();
|
||||
|
||||
// 填充数据模型
|
||||
dataModel.put("isSpringBoot3", isSpringBoot3());
|
||||
dataModel.put("dbType", table.getDbType());
|
||||
dataModel.put("package", table.getPackageName());
|
||||
dataModel.put("packagePath", table.getPackageName().replace(".", "/"));
|
||||
dataModel.put("version", table.getVersion());
|
||||
dataModel.put("moduleName", table.getModuleName());
|
||||
dataModel.put("ModuleName", StrUtil.upperFirst(table.getModuleName()));
|
||||
dataModel.put("functionName", table.getFunctionName());
|
||||
dataModel.put("FunctionName", StrUtil.upperFirst(table.getFunctionName()));
|
||||
dataModel.put("formLayout", table.getFormLayout());
|
||||
dataModel.put("style", table.getStyle());
|
||||
dataModel.put("author", table.getAuthor());
|
||||
dataModel.put("datetime", DateUtil.now());
|
||||
dataModel.put("date", DateUtil.today());
|
||||
setFieldTypeList(dataModel, table);
|
||||
// 填充数据模型
|
||||
dataModel.put("isSpringBoot3", isSpringBoot3());
|
||||
dataModel.put("dbType", table.getDbType());
|
||||
dataModel.put("package", table.getPackageName());
|
||||
dataModel.put("packagePath", table.getPackageName().replace(".", "/"));
|
||||
dataModel.put("version", table.getVersion());
|
||||
dataModel.put("moduleName", table.getModuleName());
|
||||
dataModel.put("ModuleName", StrUtil.upperFirst(table.getModuleName()));
|
||||
dataModel.put("functionName", table.getFunctionName());
|
||||
dataModel.put("FunctionName", StrUtil.upperFirst(table.getFunctionName()));
|
||||
dataModel.put("formLayout", table.getFormLayout());
|
||||
dataModel.put("style", table.getStyle());
|
||||
dataModel.put("author", table.getAuthor());
|
||||
dataModel.put("datetime", DateUtil.now());
|
||||
dataModel.put("date", DateUtil.today());
|
||||
setFieldTypeList(dataModel, table);
|
||||
|
||||
// 获取导入的包列表
|
||||
Set<String> importList = fieldTypeService.getPackageByTableId(table.getDsName(), table.getTableName());
|
||||
dataModel.put("importList", importList);
|
||||
dataModel.put("tableName", table.getTableName());
|
||||
dataModel.put("tableComment", table.getTableComment());
|
||||
dataModel.put("className", StrUtil.lowerFirst(table.getClassName()));
|
||||
dataModel.put("ClassName", table.getClassName());
|
||||
dataModel.put("fieldList", table.getFieldList());
|
||||
// 获取导入的包列表
|
||||
Set<String> importList = fieldTypeService.getPackageByTableId(table.getDsName(), table.getTableName());
|
||||
dataModel.put("importList", importList);
|
||||
dataModel.put("tableName", table.getTableName());
|
||||
dataModel.put("tableComment", table.getTableComment());
|
||||
dataModel.put("className", StrUtil.lowerFirst(table.getClassName()));
|
||||
dataModel.put("ClassName", table.getClassName());
|
||||
dataModel.put("fieldList", table.getFieldList());
|
||||
|
||||
dataModel.put("backendPath", table.getBackendPath());
|
||||
dataModel.put("frontendPath", table.getFrontendPath());
|
||||
dataModel.put("backendPath", table.getBackendPath());
|
||||
dataModel.put("frontendPath", table.getFrontendPath());
|
||||
|
||||
// 设置子表
|
||||
String childTableName = table.getChildTableName();
|
||||
if (StrUtil.isNotBlank(childTableName)) {
|
||||
List<GenTableColumnEntity> childFieldList = columnService.lambdaQuery()
|
||||
.eq(GenTableColumnEntity::getDsName, table.getDsName())
|
||||
.eq(GenTableColumnEntity::getTableName, table.getChildTableName())
|
||||
.list();
|
||||
dataModel.put("childFieldList", childFieldList);
|
||||
dataModel.put("childTableName", childTableName);
|
||||
dataModel.put("mainField", NamingCase.toCamelCase(table.getMainField()));
|
||||
dataModel.put("childField", NamingCase.toCamelCase(table.getChildField()));
|
||||
dataModel.put("ChildClassName", NamingCase.toPascalCase(childTableName));
|
||||
dataModel.put("childClassName", StrUtil.lowerFirst(NamingCase.toPascalCase(childTableName)));
|
||||
}
|
||||
// 设置子表
|
||||
String childTableName = table.getChildTableName();
|
||||
if (StrUtil.isNotBlank(childTableName)) {
|
||||
List<GenTableColumnEntity> childFieldList = columnService.lambdaQuery()
|
||||
.eq(GenTableColumnEntity::getDsName, table.getDsName())
|
||||
.eq(GenTableColumnEntity::getTableName, table.getChildTableName())
|
||||
.list();
|
||||
dataModel.put("childFieldList", childFieldList);
|
||||
dataModel.put("childTableName", childTableName);
|
||||
dataModel.put("mainField", NamingCase.toCamelCase(table.getMainField()));
|
||||
dataModel.put("childField", NamingCase.toCamelCase(table.getChildField()));
|
||||
dataModel.put("ChildClassName", NamingCase.toPascalCase(childTableName));
|
||||
dataModel.put("childClassName", StrUtil.lowerFirst(NamingCase.toPascalCase(childTableName)));
|
||||
}
|
||||
|
||||
return dataModel;
|
||||
}
|
||||
return dataModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断当前是否是 SpringBoot3 版本
|
||||
*
|
||||
* @return true/fasle
|
||||
*/
|
||||
private boolean isSpringBoot3() {
|
||||
return StrUtil.startWith(SpringBootVersion.getVersion(), "3");
|
||||
}
|
||||
/**
|
||||
* 判断当前是否是 SpringBoot3 版本
|
||||
* @return true/fasle
|
||||
*/
|
||||
private boolean isSpringBoot3() {
|
||||
return StrUtil.startWith(SpringBootVersion.getVersion(), "3");
|
||||
}
|
||||
|
||||
/**
|
||||
* 将表字段按照类型分组并存储到数据模型中
|
||||
*
|
||||
* @param dataModel 存储数据的 Map 对象
|
||||
* @param table 表信息对象
|
||||
*/
|
||||
private void setFieldTypeList(Map<String, Object> dataModel, GenTable table) {
|
||||
// 按字段类型分组,使用 Map 存储不同类型的字段列表
|
||||
Map<Boolean, List<GenTableColumnEntity>> typeMap = table.getFieldList()
|
||||
.stream()
|
||||
.collect(Collectors
|
||||
.partitioningBy(columnEntity -> BooleanUtil.toBoolean(columnEntity.getPrimaryPk().toString())));
|
||||
/**
|
||||
* 将表字段按照类型分组并存储到数据模型中
|
||||
* @param dataModel 存储数据的 Map 对象
|
||||
* @param table 表信息对象
|
||||
*/
|
||||
private void setFieldTypeList(Map<String, Object> dataModel, GenTable table) {
|
||||
// 按字段类型分组,使用 Map 存储不同类型的字段列表
|
||||
Map<Boolean, List<GenTableColumnEntity>> typeMap = table.getFieldList()
|
||||
.stream()
|
||||
.collect(Collectors
|
||||
.partitioningBy(columnEntity -> BooleanUtil.toBoolean(columnEntity.getPrimaryPk().toString())));
|
||||
|
||||
// 从分组后的 Map 中获取不同类型的字段列表
|
||||
List<GenTableColumnEntity> primaryList = typeMap.get(true);
|
||||
List<GenTableColumnEntity> formList = typeMap.get(false)
|
||||
.stream()
|
||||
.filter(columnEntity -> BooleanUtil.toBoolean(columnEntity.getFormItem()))
|
||||
.collect(Collectors.toList());
|
||||
List<GenTableColumnEntity> gridList = typeMap.get(false)
|
||||
.stream()
|
||||
.filter(columnEntity -> BooleanUtil.toBoolean(columnEntity.getGridItem()))
|
||||
.collect(Collectors.toList());
|
||||
List<GenTableColumnEntity> queryList = typeMap.get(false)
|
||||
.stream()
|
||||
.filter(columnEntity -> BooleanUtil.toBoolean(columnEntity.getQueryItem()))
|
||||
.collect(Collectors.toList());
|
||||
// 从分组后的 Map 中获取不同类型的字段列表
|
||||
List<GenTableColumnEntity> primaryList = typeMap.get(true);
|
||||
List<GenTableColumnEntity> formList = typeMap.get(false)
|
||||
.stream()
|
||||
.filter(columnEntity -> BooleanUtil.toBoolean(columnEntity.getFormItem()))
|
||||
.collect(Collectors.toList());
|
||||
List<GenTableColumnEntity> gridList = typeMap.get(false)
|
||||
.stream()
|
||||
.filter(columnEntity -> BooleanUtil.toBoolean(columnEntity.getGridItem()))
|
||||
.collect(Collectors.toList());
|
||||
List<GenTableColumnEntity> queryList = typeMap.get(false)
|
||||
.stream()
|
||||
.filter(columnEntity -> BooleanUtil.toBoolean(columnEntity.getQueryItem()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (CollUtil.isNotEmpty(primaryList)) {
|
||||
dataModel.put("pk", primaryList.get(0));
|
||||
}
|
||||
dataModel.put("primaryList", primaryList);
|
||||
dataModel.put("formList", formList);
|
||||
dataModel.put("gridList", gridList);
|
||||
dataModel.put("queryList", queryList);
|
||||
}
|
||||
if (CollUtil.isNotEmpty(primaryList)) {
|
||||
dataModel.put("pk", primaryList.get(0));
|
||||
}
|
||||
dataModel.put("primaryList", primaryList);
|
||||
dataModel.put("formList", formList);
|
||||
dataModel.put("gridList", gridList);
|
||||
dataModel.put("queryList", queryList);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user