init
This commit is contained in:
71
visual/code-gen/pom.xml
Normal file
71
visual/code-gen/pom.xml
Normal file
@@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>visual</artifactId>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>code-gen</artifactId>
|
||||
<description>代码生成模块</description>
|
||||
|
||||
<properties>
|
||||
<velocity.version>1.7</velocity.version>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!--velocity代码生成使用模板-->
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity</artifactId>
|
||||
<version>${velocity.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>common-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>common-swagger</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>common-log</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>common-mybatis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>common-excel</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>2.7.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.fateverse.code;
|
||||
|
||||
import cn.fateverse.common.security.annotation.EnableSecurity;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/10
|
||||
*/
|
||||
@EnableSecurity
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class CodeGenApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CodeGenApplication.class, args);
|
||||
System.out.println("代码生成模块启动成功");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package cn.fateverse.code.aspect;
|
||||
|
||||
import cn.fateverse.code.entity.CodeDataSource;
|
||||
import cn.fateverse.code.factory.DynamicDataSourceService;
|
||||
import cn.fateverse.code.mapper.DataSourceMapper;
|
||||
import cn.fateverse.code.mapper.dynamic.DynamicTableMapper;
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import lombok.SneakyThrows;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* 动态数据源反射控制
|
||||
*
|
||||
* @author Clay
|
||||
* @date 2022/11/17
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class DynamicTableAspect {
|
||||
|
||||
private final DataSourceMapper dataSourceMapper;
|
||||
|
||||
private final DynamicDataSourceService dynamicDataSourceService;
|
||||
|
||||
|
||||
public DynamicTableAspect(DataSourceMapper dataSourceMapper,
|
||||
DynamicDataSourceService dynamicDataSourceService) {
|
||||
this.dataSourceMapper = dataSourceMapper;
|
||||
this.dynamicDataSourceService = dynamicDataSourceService;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Around("execution(* cn.fateverse.code.service.DynamicTableMetadataService.*(..))")
|
||||
public Object around(ProceedingJoinPoint point) {
|
||||
Object[] args = point.getArgs();
|
||||
Long dataSourceId = (Long) args[args.length - 1];
|
||||
//获取到当前数据源id的数据源
|
||||
CodeDataSource codeDataSource = dataSourceMapper.selectById(dataSourceId);
|
||||
if (null == codeDataSource) {
|
||||
throw new CustomException("数据源错误!");
|
||||
}
|
||||
//获取动态数据源的sqlSession
|
||||
DynamicTableMapper dynamicTableMapper = dynamicDataSourceService.getMapper(codeDataSource);
|
||||
//获取到当前代理的对象
|
||||
Object target = point.getTarget();
|
||||
Class<?> targetClass = target.getClass();
|
||||
//将数据源对象通过反射设置到代理对象中
|
||||
Field dataSource = targetClass.getDeclaredField("dataSource");
|
||||
dataSource.setAccessible(true);
|
||||
dataSource.set(target, codeDataSource);
|
||||
//获取到获取到数据源mapper字段对象
|
||||
Field dataSourceMapperField = targetClass.getDeclaredField("dynamicTableMapper");
|
||||
dataSourceMapperField.setAccessible(true);
|
||||
//将动态表格的mapper通过反射的方式设置到代理对象中
|
||||
dataSourceMapperField.set(target, dynamicTableMapper);
|
||||
//运行代理的函数
|
||||
Object proceed;
|
||||
try {
|
||||
proceed = point.proceed();
|
||||
} catch (Exception e) {
|
||||
dynamicDataSourceService.remove(dataSourceId);
|
||||
throw e;
|
||||
}
|
||||
//将表格mapper对象置null
|
||||
dataSourceMapperField.set(target, null);
|
||||
//对数据源对象置null
|
||||
dataSource.set(target, null);
|
||||
//关闭sqlSession
|
||||
dynamicDataSourceService.closeSqlSession();
|
||||
//返回对象
|
||||
return proceed;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package cn.fateverse.code.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/17
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "gen")
|
||||
public class CodeGenConfig {
|
||||
/**
|
||||
* 作者
|
||||
*/
|
||||
private static String author;
|
||||
|
||||
/**
|
||||
* 包名
|
||||
*/
|
||||
private static String packageName;
|
||||
|
||||
/**
|
||||
* 是否去掉前缀
|
||||
*/
|
||||
private static boolean autoRemovePre;
|
||||
|
||||
/**
|
||||
* 需要去除的前缀列表
|
||||
*/
|
||||
private static List<String> tablePrefix;
|
||||
|
||||
|
||||
public static String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
CodeGenConfig.author = author;
|
||||
}
|
||||
|
||||
public static String getPackageName() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
CodeGenConfig.packageName = packageName;
|
||||
}
|
||||
|
||||
public static boolean isAutoRemovePre() {
|
||||
return autoRemovePre;
|
||||
}
|
||||
|
||||
public void setAutoRemovePre(boolean autoRemovePre) {
|
||||
CodeGenConfig.autoRemovePre = autoRemovePre;
|
||||
}
|
||||
|
||||
public static List<String> getTablePrefix() {
|
||||
return tablePrefix;
|
||||
}
|
||||
|
||||
public void setTablePrefix(List<String> tablePrefix) {
|
||||
CodeGenConfig.tablePrefix = tablePrefix;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package cn.fateverse.code.controller;
|
||||
|
||||
import cn.fateverse.common.excel.utils.ExcelUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.fateverse.code.entity.CodeDataSource;
|
||||
import cn.fateverse.code.entity.dto.DataSourceDto;
|
||||
import cn.fateverse.code.entity.query.DataSourceQuery;
|
||||
import cn.fateverse.code.entity.vo.DataSourceVo;
|
||||
import cn.fateverse.code.enums.DynamicSourceEnum;
|
||||
import cn.fateverse.code.service.DataSourceService;
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.LongUtils;
|
||||
import cn.fateverse.common.log.annotation.Log;
|
||||
import cn.fateverse.common.log.enums.BusinessType;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/16
|
||||
*/
|
||||
@Api(tags = "数据源管理")
|
||||
@RestController
|
||||
@RequestMapping("/data-source")
|
||||
public class DataSourceController {
|
||||
|
||||
private final DataSourceService dataSourceService;
|
||||
|
||||
|
||||
public DataSourceController(DataSourceService dataSourceService) {
|
||||
this.dataSourceService = dataSourceService;
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("获取数据源信息")
|
||||
@GetMapping
|
||||
@PreAuthorize("@ss.hasPermission('rapid:data-source:list')")
|
||||
public Result<TableDataInfo<DataSourceVo>> list(DataSourceQuery query) {
|
||||
TableDataInfo<DataSourceVo> dataInfo = dataSourceService.searchList(query);
|
||||
return Result.ok(dataInfo);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("导出")
|
||||
@PreAuthorize("@ss.hasPermission('rapid:table:export')")
|
||||
@GetMapping("/export")
|
||||
public void export(DataSourceQuery query) {
|
||||
List<DataSourceVo> list = dataSourceService.searchExport(query);
|
||||
ExcelUtil.exportExcel(list, DataSourceVo.class);
|
||||
}
|
||||
|
||||
@ApiOperation("获取数据源详情")
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("@ss.hasPermission('rapid:data-source:info')")
|
||||
public Result<CodeDataSource> info(
|
||||
@ApiParam(name = "id", value = "数据源id")
|
||||
@PathVariable Long id) {
|
||||
checkDataSourceId(id);
|
||||
CodeDataSource codeDataSource = dataSourceService.searchById(id);
|
||||
return Result.ok(codeDataSource);
|
||||
}
|
||||
|
||||
@ApiOperation("获取option选项接口")
|
||||
@GetMapping("/option")
|
||||
public Result<List<Option>> option() {
|
||||
List<Option> optionList = dataSourceService.searchOption();
|
||||
return Result.ok(optionList);
|
||||
}
|
||||
|
||||
@ApiOperation("获取数据库适配类型接口")
|
||||
@GetMapping("/option/type")
|
||||
public Result<List<Option>> optionType() {
|
||||
List<Option> optionList = Arrays.stream(DynamicSourceEnum.values()).map(type -> Option.builder()
|
||||
.value(type.name())
|
||||
.label(type.getType())
|
||||
.build()).collect(Collectors.toList());
|
||||
return Result.ok(optionList);
|
||||
}
|
||||
|
||||
@ApiOperation("新增数据源")
|
||||
@PostMapping
|
||||
@PreAuthorize("@ss.hasPermission('rapid:data-source:add')")
|
||||
@Log(title = "新增数据源", businessType = BusinessType.INSERT)
|
||||
public Result<Void> add(@RequestBody @Validated DataSourceDto dataSource) {
|
||||
checkDataSource(dataSource);
|
||||
if (StrUtil.isEmpty(dataSource.getPassword())) {
|
||||
return Result.error("数据库密码不能为空!");
|
||||
}
|
||||
dataSourceService.save(dataSource);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("修改数据源")
|
||||
@PutMapping
|
||||
@PreAuthorize("@ss.hasPermission('rapid:data-source:edit')")
|
||||
@Log(title = "修改数据源", businessType = BusinessType.UPDATE)
|
||||
public Result<Void> edit(@RequestBody @Validated DataSourceDto dataSource) {
|
||||
checkDataSourceId(dataSource.getDsId());
|
||||
checkDataSource(dataSource);
|
||||
dataSourceService.edit(dataSource);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("删除数据源")
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("@ss.hasPermission('rapid:data-source:del')")
|
||||
@Log(title = "删除数据源", businessType = BusinessType.DELETE)
|
||||
public Result<Void> delete(@PathVariable Long id) {
|
||||
checkDataSourceId(id);
|
||||
dataSourceService.removeById(id);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查数据源是否正确
|
||||
*
|
||||
* @param dataSource 数据源
|
||||
*/
|
||||
public void checkDataSource(DataSourceDto dataSource) {
|
||||
if (1 == dataSource.getConfType()) {
|
||||
if (StrUtil.isEmpty(dataSource.getHost())) {
|
||||
throw new CustomException("主机地址不能为空!");
|
||||
}
|
||||
if (null == dataSource.getPort()) {
|
||||
throw new CustomException("主机端口不能为空!");
|
||||
}
|
||||
if (StrUtil.isEmpty(dataSource.getDbName())) {
|
||||
throw new CustomException("数据库名称不能为空!");
|
||||
}
|
||||
} else {
|
||||
if (StrUtil.isEmpty(dataSource.getJdbcUrl())) {
|
||||
throw new CustomException("数据库连接地址不能为空!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检查部门id是都为空
|
||||
*/
|
||||
private void checkDataSourceId(Long id) {
|
||||
LongUtils.checkId(id, "数据源id不能为空!");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package cn.fateverse.code.controller;
|
||||
|
||||
import cn.fateverse.code.entity.query.DynamicTable;
|
||||
import cn.fateverse.code.service.DynamicTableMetadataService;
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.LongUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/17
|
||||
*/
|
||||
@Api(tags = "代码生成:数据表源信息")
|
||||
@RestController
|
||||
@RequestMapping("/dynamic-table")
|
||||
public class DynamicTableController {
|
||||
|
||||
private final DynamicTableMetadataService tableSourceService;
|
||||
|
||||
public DynamicTableController(DynamicTableMetadataService tableSourceService) {
|
||||
this.tableSourceService = tableSourceService;
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("获取数据源信息")
|
||||
@GetMapping
|
||||
@PreAuthorize("@ss.hasPermission('code:dynamic-table:list')")
|
||||
public Result<TableDataInfo<DynamicTable>> list(DynamicTable dynamicTable, Long dataSourceId) {
|
||||
if (LongUtils.isNull(dataSourceId)){
|
||||
return Result.error("数据源id不能为空!");
|
||||
}
|
||||
TableDataInfo<DynamicTable> dataInfo = tableSourceService.searchList(dynamicTable, dataSourceId);
|
||||
return Result.ok(dataInfo);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package cn.fateverse.code.controller;
|
||||
|
||||
import cn.fateverse.code.entity.dto.RegularDto;
|
||||
import cn.fateverse.code.entity.query.RegularQuery;
|
||||
import cn.fateverse.code.entity.vo.RegularVo;
|
||||
import cn.fateverse.code.service.RegularService;
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.excel.utils.ExcelUtil;
|
||||
import cn.fateverse.common.log.annotation.Log;
|
||||
import cn.fateverse.common.log.enums.BusinessType;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 校验规则表 Controller
|
||||
*
|
||||
* @author clay
|
||||
* @date 2023-05-27
|
||||
*/
|
||||
@Api(value = "校验规则表管理",tags = "校验规则表管理")
|
||||
@RestController
|
||||
@RequestMapping("/rapid/regular")
|
||||
public class RegularController {
|
||||
|
||||
private final RegularService regularService;
|
||||
|
||||
public RegularController(RegularService regularService) {
|
||||
this.regularService = regularService;
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("获取校验规则表列表")
|
||||
@GetMapping
|
||||
@PreAuthorize("@ss.hasPermission('rapid:regular:list')")
|
||||
public Result<TableDataInfo<RegularVo>> list(RegularQuery query) {
|
||||
TableDataInfo<RegularVo> dataInfo = regularService.searchList(query);
|
||||
return Result.ok(dataInfo);
|
||||
}
|
||||
|
||||
@ApiOperation("获取校验规则表列表")
|
||||
@GetMapping("/option")
|
||||
public Result<List<Option>> option(){
|
||||
List<Option> options = regularService.searchOptionList();
|
||||
return Result.ok(options);
|
||||
}
|
||||
|
||||
@ApiOperation("导出excel数据")
|
||||
@GetMapping("/export")
|
||||
@PreAuthorize("@ss.hasPermission('rapid:regular:export')")
|
||||
public void export(RegularQuery query){
|
||||
List<RegularVo> list = regularService.exportList(query);
|
||||
ExcelUtil.exportExcel(list, RegularVo.class);
|
||||
}
|
||||
|
||||
@ApiOperation("获取校验规则表详细信息")
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("@ss.hasPermission('rapid:regular:info')")
|
||||
public Result<RegularVo> info(@PathVariable Long id) {
|
||||
ObjectUtils.checkPk(id);
|
||||
RegularVo regular = regularService.searchById(id);
|
||||
return Result.ok(regular);
|
||||
}
|
||||
|
||||
@ApiOperation("新增校验规则表")
|
||||
@PostMapping
|
||||
@Log(title = "新增校验规则表",businessType = BusinessType.INSERT)
|
||||
@PreAuthorize("@ss.hasPermission('rapid:regular:add')")
|
||||
public Result<Void> add(@RequestBody @Validated RegularDto regular){
|
||||
if (!verifyRegular(regular)) {
|
||||
return Result.error("正则表达式校验不通过!");
|
||||
}
|
||||
regularService.save(regular);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("修改校验规则表")
|
||||
@PutMapping
|
||||
@Log(title = "修改校验规则表",businessType = BusinessType.UPDATE)
|
||||
@PreAuthorize("@ss.hasPermission('rapid:regular:edit')")
|
||||
public Result<Void> edit(@RequestBody @Validated RegularDto regular){
|
||||
ObjectUtils.checkPk(regular.getId());
|
||||
if (!verifyRegular(regular)) {
|
||||
return Result.error("正则表达式校验不通过!");
|
||||
}
|
||||
regularService.edit(regular);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("删除校验规则表")
|
||||
@DeleteMapping("/{idList}")
|
||||
@Log(title = "删除校验规则表",businessType = BusinessType.DELETE)
|
||||
@PreAuthorize("@ss.hasPermission('rapid:regular:del')")
|
||||
public Result<Void> batchDel(@PathVariable List<Long> idList){
|
||||
ObjectUtils.checkPkList(idList);
|
||||
regularService.removeBatch(idList);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
public boolean verifyRegular(RegularDto regular) {
|
||||
return Pattern.matches(regular.getRegular(), regular.getValidation());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
package cn.fateverse.code.controller;
|
||||
|
||||
import cn.fateverse.code.entity.OptionInfo;
|
||||
import cn.fateverse.code.entity.TableColumn;
|
||||
import cn.fateverse.code.entity.dto.ImportDto;
|
||||
import cn.fateverse.code.entity.dto.TableDto;
|
||||
import cn.fateverse.code.entity.query.TableQuery;
|
||||
import cn.fateverse.code.entity.vo.TableInfoVo;
|
||||
import cn.fateverse.code.entity.vo.TableVo;
|
||||
import cn.fateverse.code.service.TableService;
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.LongUtils;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.excel.utils.ExcelUtil;
|
||||
import cn.fateverse.common.log.annotation.Log;
|
||||
import cn.fateverse.common.log.enums.BusinessType;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/15
|
||||
*/
|
||||
@Api(tags = "数据表格管理")
|
||||
@RestController
|
||||
@RequestMapping("/table")
|
||||
public class TableController {
|
||||
|
||||
private final TableService tableService;
|
||||
|
||||
public TableController(TableService tableService) {
|
||||
this.tableService = tableService;
|
||||
}
|
||||
|
||||
@ApiOperation("获取list")
|
||||
@PreAuthorize("@ss.hasPermission('code:table:list')")
|
||||
@GetMapping
|
||||
public Result<TableDataInfo<TableVo>> list(TableQuery query) {
|
||||
TableDataInfo<TableVo> dataInfo = tableService.searchList(query);
|
||||
return Result.ok(dataInfo);
|
||||
}
|
||||
|
||||
@ApiOperation("导出")
|
||||
@PreAuthorize("@ss.hasPermission('code:table:export')")
|
||||
@GetMapping("/export")
|
||||
public void export(TableQuery query) {
|
||||
List<TableVo> list = tableService.searchExport(query);
|
||||
ExcelUtil.exportExcel(list,TableVo.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ApiOperation("获取详细信息")
|
||||
@PreAuthorize("@ss.hasPermission('code:table:info')")
|
||||
@GetMapping("/{tableId}")
|
||||
public Result<TableInfoVo> info(@PathVariable Long tableId) {
|
||||
LongUtils.checkId(tableId);
|
||||
TableDto tableDto = tableService.searchByTableId(tableId);
|
||||
if(null == tableDto){
|
||||
return Result.error("获取结果为空");
|
||||
}
|
||||
List<Option> optionList = tableService.searchOptionByDataSourceId(tableDto.getDataSourceId());
|
||||
List<TableColumn> columns = tableDto.getColumns();
|
||||
tableDto.setColumns(null);
|
||||
TableInfoVo tableInfoVo = TableInfoVo.builder()
|
||||
.info(tableDto)
|
||||
.optionInfo(JSONObject.parseObject(tableDto.getOptionApi(), OptionInfo.class))
|
||||
.columns(columns)
|
||||
.tableOption(optionList)
|
||||
.build();
|
||||
return Result.ok(tableInfoVo);
|
||||
}
|
||||
|
||||
@ApiOperation("预览代码")
|
||||
@GetMapping("/preview/{tableId}")
|
||||
@PreAuthorize("@ss.hasPermission('tool:gen:preview')")
|
||||
public Result<Map<String, String>> preview(@PathVariable Long tableId) {
|
||||
Map<String, String> dataMap = tableService.previewCode(tableId);
|
||||
return Result.ok(dataMap);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("导入数据源信息")
|
||||
@PreAuthorize("@ss.hasPermission('code:table:import')")
|
||||
@Log(title = "导入数据源信息", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/import-table")
|
||||
public Result<Void> importData(@RequestBody ImportDto dto) {
|
||||
if (dto.getTables().isEmpty() || LongUtils.isNull(dto.getDataSourceId())) {
|
||||
return Result.error("缺少必要参数!");
|
||||
}
|
||||
return tableService.importTable(dto);
|
||||
}
|
||||
|
||||
@ApiOperation("修改数据源信息")
|
||||
@PreAuthorize("@ss.hasPermission('code:table:edit')")
|
||||
@Log(title = "修改数据源信息", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public Result<Void> edit(@RequestBody @Validated TableDto table) {
|
||||
LongUtils.checkId(table.getTableId());
|
||||
tableService.edit(table);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("同步数据库")
|
||||
@PutMapping("/sync/{tableId}")
|
||||
@Log(title = "修改数据源信息", businessType = BusinessType.UPDATE)
|
||||
public Result<Void> syncTable(@PathVariable Long tableId){
|
||||
if (ObjectUtils.isEmpty(tableId)){
|
||||
return Result.error("缺少必要参数!");
|
||||
}
|
||||
tableService.syncTable(tableId);
|
||||
return Result.ok("同步成功");
|
||||
}
|
||||
|
||||
@ApiOperation("生成代码-下载")
|
||||
@PreAuthorize("@ss.hasPermission('code:table:code')")
|
||||
@Log(title = "生成代码-下载", businessType = BusinessType.GENCODE)
|
||||
@GetMapping("/download/{tableId}")
|
||||
public void download(@PathVariable Long tableId){
|
||||
tableService.downloadCode(tableId);
|
||||
}
|
||||
|
||||
@ApiOperation("生成代码-下载")
|
||||
@PreAuthorize("@ss.hasPermission('code:table:code')")
|
||||
@Log(title = "生成代码-下载", businessType = BusinessType.GENCODE)
|
||||
@GetMapping("/downloads/{tableIds}")
|
||||
public void downloads(@PathVariable List<Long> tableIds){
|
||||
if (ObjectUtils.isEmpty(tableIds)){
|
||||
throw new CustomException("关键参数不能weikong");
|
||||
}
|
||||
tableService.downloadCodeList(tableIds);
|
||||
}
|
||||
|
||||
@ApiOperation("删除数据源信息")
|
||||
@PreAuthorize("@ss.hasPermission('code:table:del')")
|
||||
@Log(title = "删除数据源信息", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{tableId}")
|
||||
public Result<Void> del(@PathVariable Long tableId) {
|
||||
LongUtils.checkId(tableId);
|
||||
tableService.remove(tableId);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("批量删除数据源信息")
|
||||
@PreAuthorize("@ss.hasPermission('code:table:del')")
|
||||
@Log(title = "删除数据源信息", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping
|
||||
public Result<Void> delBatch(@RequestParam List<Long> tables) {
|
||||
if (null == tables || tables.isEmpty()) {
|
||||
return Result.error("缺少必要参数");
|
||||
}
|
||||
tableService.removeBatch(tables);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package cn.fateverse.code.entity;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/15
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("接口类")
|
||||
public class ApiClass {
|
||||
|
||||
/**
|
||||
* 类id
|
||||
*/
|
||||
@ApiModelProperty("类id")
|
||||
private String classId;
|
||||
/**
|
||||
* 模块id
|
||||
*/
|
||||
@ApiModelProperty("模块id")
|
||||
private String moduleId;
|
||||
/**
|
||||
* 类名
|
||||
*/
|
||||
@ApiModelProperty("类名")
|
||||
private String className;
|
||||
/**
|
||||
* 类描述
|
||||
*/
|
||||
@ApiModelProperty("类描述")
|
||||
private String classDescribe;
|
||||
/**
|
||||
* 包名
|
||||
*/
|
||||
@ApiModelProperty("包名")
|
||||
private String packageName;
|
||||
/**
|
||||
* 作者
|
||||
*/
|
||||
@ApiModelProperty("作者")
|
||||
private String author;
|
||||
/**
|
||||
* 电子邮件
|
||||
*/
|
||||
@ApiModelProperty("电子邮件")
|
||||
private String email;
|
||||
/**
|
||||
* 前缀
|
||||
*/
|
||||
@ApiModelProperty("前缀")
|
||||
private String prefix;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package cn.fateverse.code.entity;
|
||||
|
||||
import cn.fateverse.code.enums.DynamicSourceEnum;
|
||||
import cn.fateverse.common.core.entity.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/16
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CodeDataSource extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 数据源id
|
||||
*/
|
||||
private Long dsId;
|
||||
/**
|
||||
* 数据源名称
|
||||
*/
|
||||
private String dsName;
|
||||
/**
|
||||
* 数据源用户名
|
||||
*/
|
||||
private String username;
|
||||
/**
|
||||
* 数据源密码
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* 数据源主机
|
||||
*/
|
||||
private String host;
|
||||
/**
|
||||
* 数据源主机端口
|
||||
*/
|
||||
private Integer port;
|
||||
/**
|
||||
* 数据源类型
|
||||
*/
|
||||
private DynamicSourceEnum type;
|
||||
/**
|
||||
* 数据库名称
|
||||
*/
|
||||
private String dbName;
|
||||
/**
|
||||
* 数据库连接地址
|
||||
*/
|
||||
private String jdbcUrl;
|
||||
/**
|
||||
* 数据源类型 (1:主机 2:jdbc连接url)
|
||||
*/
|
||||
private Integer confType;
|
||||
/**
|
||||
* 连接参数
|
||||
*/
|
||||
private String args;
|
||||
|
||||
/**
|
||||
* 查询参数
|
||||
*/
|
||||
private String params;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.fateverse.code.entity;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2023-07-29
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class DynamicPage {
|
||||
private Integer startNum;
|
||||
|
||||
private Integer endNum;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package cn.fateverse.code.entity;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/15
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("接口表")
|
||||
public class InterTable {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@ApiModelProperty("id")
|
||||
private String interId;
|
||||
/**
|
||||
* 模块id
|
||||
*/
|
||||
@ApiModelProperty("模块id")
|
||||
private String moduleId;
|
||||
/**
|
||||
* 类id
|
||||
*/
|
||||
@ApiModelProperty("类id")
|
||||
private String classId;
|
||||
/**
|
||||
* 接口名称
|
||||
*/
|
||||
@ApiModelProperty("接口名称")
|
||||
private String itName;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@ApiModelProperty("描述")
|
||||
private String itDescribe;
|
||||
/**
|
||||
* 是否设置许可
|
||||
*/
|
||||
@ApiModelProperty("是否设置许可")
|
||||
private String isPermission;
|
||||
/**
|
||||
* 请求路径
|
||||
*/
|
||||
@ApiModelProperty("请求路径")
|
||||
private String reqUrl;
|
||||
/**
|
||||
* 请求方式
|
||||
*/
|
||||
@ApiModelProperty("请求方式")
|
||||
private String method;
|
||||
/**
|
||||
* 是否生成
|
||||
*/
|
||||
@ApiModelProperty("是否生成")
|
||||
private String isGenerate;
|
||||
/**
|
||||
* 类型(1,工作台,2流程)
|
||||
*/
|
||||
@ApiModelProperty("类型(1,工作台,2流程)")
|
||||
private String type;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package cn.fateverse.code.entity;
|
||||
|
||||
import cn.fateverse.common.core.entity.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/15
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("模块实体")
|
||||
public class Module extends BaseEntity {
|
||||
|
||||
|
||||
/**
|
||||
* 模块id
|
||||
*/
|
||||
@ApiModelProperty("模块id")
|
||||
private Long modeId;
|
||||
/**
|
||||
* 模块名称
|
||||
*/
|
||||
@ApiModelProperty("模块名称")
|
||||
private String modeName;
|
||||
/**
|
||||
* 模块描述
|
||||
*/
|
||||
@ApiModelProperty("模块描述")
|
||||
private String modeDescribe;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.fateverse.code.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2023-05-29
|
||||
*/
|
||||
@Data
|
||||
public class OptionInfo {
|
||||
|
||||
private Boolean enabled;
|
||||
|
||||
private String valueField;
|
||||
|
||||
private String labelFiled;
|
||||
|
||||
|
||||
public static OptionInfo getDefaultInstance() {
|
||||
OptionInfo option = new OptionInfo();
|
||||
option.setEnabled(Boolean.FALSE);
|
||||
option.setValueField("");
|
||||
option.setLabelFiled("");
|
||||
return option;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package cn.fateverse.code.entity;
|
||||
|
||||
import cn.fateverse.common.core.annotaion.EnableAutoField;
|
||||
import cn.fateverse.common.core.entity.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
/**
|
||||
* 校验规则表对象 gen_regula
|
||||
*
|
||||
* @author clay
|
||||
* @date 2023-05-27
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@EnableAutoField
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Regular extends BaseEntity{
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 正则名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 正则内容
|
||||
*/
|
||||
private String regular;
|
||||
|
||||
/**
|
||||
* 验证内容
|
||||
*/
|
||||
private String validation;
|
||||
|
||||
/**
|
||||
* 是否启用 1:启动 2:关闭
|
||||
*/
|
||||
private String enable;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package cn.fateverse.code.entity;
|
||||
|
||||
import cn.fateverse.common.core.entity.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/15
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("关联表实体")
|
||||
public class RelTable extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 关联表id
|
||||
*/
|
||||
@ApiModelProperty("关联表id")
|
||||
private Long relTableId;
|
||||
/**
|
||||
* 主表id
|
||||
*/
|
||||
@ApiModelProperty("主表id")
|
||||
private Long tableId;
|
||||
/**
|
||||
* 关联子表表名
|
||||
*/
|
||||
@ApiModelProperty("关联子表表名")
|
||||
private String relName;
|
||||
/**
|
||||
* 子表简称
|
||||
*/
|
||||
@ApiModelProperty("子表简称")
|
||||
private String relAs;
|
||||
/**
|
||||
* 父表名称
|
||||
*/
|
||||
@ApiModelProperty("父表名称")
|
||||
private String tableName;
|
||||
/**
|
||||
* 父表名简称
|
||||
*/
|
||||
@ApiModelProperty("父表名简称")
|
||||
private String tableAs;
|
||||
/**
|
||||
* 表描述
|
||||
*/
|
||||
@ApiModelProperty("表描述")
|
||||
private String relComment;
|
||||
/**
|
||||
* 关联子表的字段
|
||||
*/
|
||||
@ApiModelProperty("关联子表的字段")
|
||||
private String relColumn;
|
||||
/**
|
||||
* 关联父表字段
|
||||
*/
|
||||
@ApiModelProperty("关联父表字段")
|
||||
private String tableColumn;
|
||||
/**
|
||||
* 实体类名称(子表)
|
||||
*/
|
||||
@ApiModelProperty("实体类名称(子表)")
|
||||
private String relClass;
|
||||
/**
|
||||
* 实体类名称(子表)小写
|
||||
*/
|
||||
@ApiModelProperty("实体类名称(子表)小写")
|
||||
private String relClassLower;
|
||||
/**
|
||||
* 关联类型
|
||||
*/
|
||||
@ApiModelProperty("关联类型")
|
||||
private String queryType;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@ApiModelProperty("排序")
|
||||
private String sort;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package cn.fateverse.code.entity;
|
||||
|
||||
import cn.fateverse.common.core.entity.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/15
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("关联表列名称")
|
||||
public class RelTableColumn extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 子表字段id
|
||||
*/
|
||||
@ApiModelProperty("子表字段id")
|
||||
private Long relColumnId;
|
||||
/**
|
||||
* 归属表编号
|
||||
*/
|
||||
@ApiModelProperty("归属表编号")
|
||||
private Long relTableId;
|
||||
/**
|
||||
* 列名称
|
||||
*/
|
||||
@ApiModelProperty("列名称")
|
||||
private String columnName;
|
||||
/**
|
||||
* 列描述
|
||||
*/
|
||||
@ApiModelProperty("列描述")
|
||||
private String columnComment;
|
||||
/**
|
||||
* 列类型
|
||||
*/
|
||||
@ApiModelProperty("列类型")
|
||||
private String columnType;
|
||||
/**
|
||||
* JAVA类型
|
||||
*/
|
||||
@ApiModelProperty("JAVA类型")
|
||||
private String javaType;
|
||||
/**
|
||||
* JAVA字段名
|
||||
*/
|
||||
@ApiModelProperty("JAVA字段名")
|
||||
private String javaField;
|
||||
/**
|
||||
* 是否列表字段(1是)
|
||||
*/
|
||||
@ApiModelProperty("是否列表字段(1是)")
|
||||
private String isList;
|
||||
/**
|
||||
* 是否查询字段(1是)
|
||||
*/
|
||||
@ApiModelProperty("是否查询字段(1是)")
|
||||
private String isQuery;
|
||||
/**
|
||||
* 查询方式(等于、不等于、大于、小于、范围)
|
||||
*/
|
||||
@ApiModelProperty("查询方式(等于、不等于、大于、小于、范围)")
|
||||
private String queryType;
|
||||
/**
|
||||
* 显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件)
|
||||
*/
|
||||
@ApiModelProperty("显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件)")
|
||||
private String htmlType;
|
||||
/**
|
||||
* 字典类型
|
||||
*/
|
||||
@ApiModelProperty("字典类型")
|
||||
private String dictType;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@ApiModelProperty("排序")
|
||||
private String sort;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package cn.fateverse.code.entity;
|
||||
|
||||
import cn.fateverse.code.entity.vo.TableVo;
|
||||
import cn.fateverse.code.enums.BackTemplateEnum;
|
||||
import cn.fateverse.code.enums.DynamicSourceEnum;
|
||||
import cn.fateverse.code.enums.FrontTemplateEnum;
|
||||
import cn.fateverse.common.core.entity.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/15
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ApiModel("代码生成表格")
|
||||
public class Table extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@ApiModelProperty("编号")
|
||||
private Long tableId;
|
||||
|
||||
private Long parentMenuId;
|
||||
/**
|
||||
* 数据源id
|
||||
*/
|
||||
@ApiModelProperty("数据源id")
|
||||
private Long dataSourceId;
|
||||
|
||||
@ApiModelProperty("数据源类型")
|
||||
private DynamicSourceEnum dataSourceType;
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
@ApiModelProperty("表名称")
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表描述
|
||||
*/
|
||||
@ApiModelProperty("表描述")
|
||||
private String tableComment;
|
||||
|
||||
/**
|
||||
* 关联子表的表名
|
||||
*/
|
||||
@ApiModelProperty("关联子表的表名")
|
||||
private String subTableName;
|
||||
|
||||
/**
|
||||
* 子表关联的外键名
|
||||
*/
|
||||
@ApiModelProperty("子表关联的外键名")
|
||||
private String subTableFkName;
|
||||
|
||||
/**
|
||||
* 实体类名称
|
||||
*/
|
||||
@ApiModelProperty("实体类名称")
|
||||
private String className;
|
||||
|
||||
/**
|
||||
* 使用的模板(crud单表操作 tree树表操作)
|
||||
*/
|
||||
@ApiModelProperty("使用的模板")
|
||||
private String tplCategory;
|
||||
|
||||
/**
|
||||
* 生成包路径
|
||||
*/
|
||||
@ApiModelProperty("生成包路径")
|
||||
private String packageName;
|
||||
|
||||
/**
|
||||
* 生成模块名
|
||||
*/
|
||||
@ApiModelProperty("生成模块名")
|
||||
private String moduleName;
|
||||
|
||||
/**
|
||||
* 生成服务名
|
||||
*/
|
||||
@ApiModelProperty("生成服务名")
|
||||
private String serviceName;
|
||||
|
||||
/**
|
||||
* 生成业务名
|
||||
*/
|
||||
@ApiModelProperty("生成业务名")
|
||||
private String businessName;
|
||||
|
||||
/**
|
||||
* 生成功能名
|
||||
*/
|
||||
@ApiModelProperty("生成功能名")
|
||||
private String functionName;
|
||||
|
||||
/**
|
||||
* 生成功能作者
|
||||
*/
|
||||
@ApiModelProperty("生成功能作者")
|
||||
private String functionAuthor;
|
||||
|
||||
@ApiModelProperty("后端模板 0: mybatis 1: mybatispuls ")
|
||||
private BackTemplateEnum backTemplate;
|
||||
|
||||
@ApiModelProperty("前端模板 0: vue 1: react")
|
||||
private FrontTemplateEnum frontTemplate;
|
||||
|
||||
/**
|
||||
* 其它生成选项
|
||||
*/
|
||||
@ApiModelProperty("其它生成选项")
|
||||
private String options;
|
||||
|
||||
|
||||
private String optionApi;
|
||||
|
||||
|
||||
public TableVo toTableVo(){
|
||||
return TableVo.builder()
|
||||
.tableId(tableId)
|
||||
.dataSourceId(dataSourceId)
|
||||
.tableName(tableName)
|
||||
.tableComment(tableComment)
|
||||
.className(className)
|
||||
.createTime(getCreateTime())
|
||||
.updateTime(getUpdateTime())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
package cn.fateverse.code.entity;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.fateverse.code.util.constant.CodeGenConstants;
|
||||
import cn.fateverse.common.core.annotaion.EnableAutoField;
|
||||
import cn.fateverse.common.core.entity.BaseEntity;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/15
|
||||
*/
|
||||
@Data
|
||||
@EnableAutoField
|
||||
@ApiModel("table表字段实体")
|
||||
public class TableColumn extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@ApiModelProperty("编号")
|
||||
private Long columnId;
|
||||
/**
|
||||
* 归属表编号
|
||||
*/
|
||||
@ApiModelProperty("归属表编号")
|
||||
private Long tableId;
|
||||
/**
|
||||
* 列名称
|
||||
*/
|
||||
@ApiModelProperty("列名称")
|
||||
private String columnName;
|
||||
/**
|
||||
* 列描述
|
||||
*/
|
||||
@ApiModelProperty("列描述")
|
||||
private String columnComment;
|
||||
/**
|
||||
* 列类型
|
||||
*/
|
||||
@ApiModelProperty("列类型")
|
||||
private String columnType;
|
||||
|
||||
@ApiModelProperty("列长度")
|
||||
private Integer columnLength;
|
||||
|
||||
@ApiModelProperty("列精度")
|
||||
private Integer columnScale;
|
||||
/**
|
||||
* JAVA类型
|
||||
*/
|
||||
@ApiModelProperty("JAVA类型")
|
||||
private String javaType;
|
||||
/**
|
||||
* JAVA字段名
|
||||
*/
|
||||
@ApiModelProperty("JAVA字段名")
|
||||
private String javaField;
|
||||
/**
|
||||
* 是否主键(1是)
|
||||
*/
|
||||
@ApiModelProperty("是否主键(1是)")
|
||||
private String isPk;
|
||||
/**
|
||||
* 是否自增(1是)
|
||||
*/
|
||||
@ApiModelProperty("是否自增(1是)")
|
||||
private String isIncrement;
|
||||
/**
|
||||
* 是否必填(1是)
|
||||
*/
|
||||
@ApiModelProperty("是否必填(1是)")
|
||||
private String isRequired;
|
||||
/**
|
||||
* 是否为插入字段(1是)
|
||||
*/
|
||||
@ApiModelProperty("是否为插入字段(1是)")
|
||||
private String isInsert;
|
||||
/**
|
||||
* 是否编辑字段(1是)
|
||||
*/
|
||||
@ApiModelProperty("是否编辑字段(1是)")
|
||||
private String isEdit;
|
||||
/**
|
||||
* 是否列表字段(1是)
|
||||
*/
|
||||
@ApiModelProperty("是否列表字段(1是)")
|
||||
private String isList;
|
||||
/**
|
||||
* 是否查询字段(1是)
|
||||
*/
|
||||
@ApiModelProperty("是否查询字段(1是)")
|
||||
private String isQuery;
|
||||
/**
|
||||
* 是否正则(1 否)
|
||||
*/
|
||||
@ApiModelProperty("是否正则(1 否)")
|
||||
private Long isRegular;
|
||||
/**
|
||||
* 正则表达式内容
|
||||
*/
|
||||
@ApiModelProperty("正则表达式内容")
|
||||
private String regular;
|
||||
/**
|
||||
* 查询方式(等于、不等于、大于、小于、范围)
|
||||
*/
|
||||
@ApiModelProperty("查询方式(等于、不等于、大于、小于、范围)")
|
||||
private String queryType;
|
||||
/**
|
||||
* 显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件)
|
||||
*/
|
||||
@ApiModelProperty("显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件)")
|
||||
private String htmlType;
|
||||
/**
|
||||
* 字典类型
|
||||
*/
|
||||
@ApiModelProperty("字典类型")
|
||||
private String dictType;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@ApiModelProperty("排序")
|
||||
private String sort;
|
||||
|
||||
/**
|
||||
* 是否为主键
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@JsonIgnore
|
||||
public Boolean isPk() {
|
||||
return isPk(this.isPk);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为主键
|
||||
*
|
||||
* @param isPk
|
||||
* @return
|
||||
*/
|
||||
@JsonIgnore
|
||||
public Boolean isPk(String isPk) {
|
||||
return "1".equals(isPk);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为基础的列
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@JsonIgnore
|
||||
public Boolean isSuperColumn() {
|
||||
return isSuperColumn(this.javaField);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Boolean query() {
|
||||
return "1".equals(this.getIsQuery());
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Boolean from() {
|
||||
return "1".equals(isEdit) || "1".equals(isInsert);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Boolean list() {
|
||||
return "1".equals(isList);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Boolean required() {
|
||||
return "1".equals(isRequired);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Boolean isRegular() {
|
||||
return !isRegular.equals(0L);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 是否为基础的列
|
||||
*
|
||||
* @param javaField
|
||||
* @return
|
||||
*/
|
||||
@JsonIgnore
|
||||
public static Boolean isSuperColumn(String javaField) {
|
||||
javaField = javaField.toLowerCase();
|
||||
return StringUtils.equalsAnyIgnoreCase(javaField,
|
||||
// BaseEntity
|
||||
"createBy", "createTime", "updateBy", "updateTime", "remark",
|
||||
// TreeEntity
|
||||
"parentName", "parentId", "orderNum", "ancestors");
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public static Boolean isUsableColumn(String javaField) {
|
||||
// isSuperColumn()中的名单用于避免生成多余Entity属性,若某些属性在生成页面时需要用到不能忽略,则放在此处白名单
|
||||
return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark");
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public boolean isDict() {
|
||||
return dictType != null && !ObjectUtils.isEmpty(dictType.trim());
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public boolean isInput() {
|
||||
return CodeGenConstants.HTML_INPUT.equals(htmlType);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public boolean isSelect() {
|
||||
return CodeGenConstants.HTML_SELECT.equals(htmlType);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public boolean isRadio() {
|
||||
return CodeGenConstants.HTML_RADIO.equals(htmlType);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Object getDefaultRadio() {
|
||||
if ("Integer".equals(javaType) || "Long".equals(javaField)) {
|
||||
return 0;
|
||||
} else {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public boolean isDatetime() {
|
||||
return CodeGenConstants.HTML_DATETIME.equals(htmlType);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public boolean isBetween() {
|
||||
return "BETWEEN".equals(htmlType);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public boolean isCheckbox() {
|
||||
return CodeGenConstants.HTML_CHECKBOX.equals(htmlType);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public String comment() {
|
||||
int en = columnComment.indexOf('(');
|
||||
int cn = columnComment.indexOf('(');
|
||||
int index = Math.max(en, cn);
|
||||
if (index != -1) {
|
||||
return columnComment.substring(0, index);
|
||||
}
|
||||
return columnComment;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public String getAttrName() {
|
||||
return javaField.substring(0, 1).toUpperCase() + javaField.substring(1);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Boolean fromValue() {
|
||||
return !isDatetime() && !isBetween() && !"createBy".equals(javaField) && !"updateBy".equals(javaField);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Boolean listAndDict() {
|
||||
return list() && isDict();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package cn.fateverse.code.entity.bo;
|
||||
|
||||
import cn.fateverse.code.entity.dto.TableDto;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.fateverse.code.entity.TableColumn;
|
||||
import cn.fateverse.code.util.constant.CodeGenConstants;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 代码生成时专用增强dto
|
||||
*
|
||||
* @author Clay
|
||||
* @date 2022/11/18
|
||||
*/
|
||||
@Data
|
||||
public class TableGenBo extends TableDto {
|
||||
private TableColumn pkColumn;
|
||||
|
||||
|
||||
/**
|
||||
* 是否启动正则
|
||||
*/
|
||||
public boolean isRegular() {
|
||||
return this.getColumns().stream().anyMatch(column -> column.getIsRegular() != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为空
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isRequired() {
|
||||
return this.getColumns().stream().anyMatch(column -> "1".equals(column.getIsRequired()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 首字母大写转换
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public String capitalize(String str) {
|
||||
return StringUtils.capitalize(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增是拥有字段
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Boolean hasCreateXMLColumns() {
|
||||
boolean createByFlag = Boolean.FALSE;
|
||||
boolean createTimeFlag = Boolean.FALSE;
|
||||
for (TableColumn column : this.getColumns()) {
|
||||
if (CodeGenConstants.CREATE_BY_FIELD.equals(column.getJavaField())) {
|
||||
createByFlag = Boolean.TRUE;
|
||||
}
|
||||
if (CodeGenConstants.CREATE_TIME_FIELD.equals(column.getJavaField())) {
|
||||
createTimeFlag = Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
return createByFlag && createTimeFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新是拥有字段
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Boolean hasUpdateXMLColumns() {
|
||||
boolean updateByFlag = Boolean.FALSE;
|
||||
boolean updateTimeFlag = Boolean.FALSE;
|
||||
for (TableColumn column : this.getColumns()) {
|
||||
if (CodeGenConstants.UPDATE_BY_FIELD.equals(column.getJavaField())) {
|
||||
updateByFlag = Boolean.TRUE;
|
||||
}
|
||||
if (CodeGenConstants.UPDATE_TIME_FIELD.equals(column.getJavaField())) {
|
||||
updateTimeFlag = Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
return updateByFlag && updateTimeFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 筛选Dto中的时间格式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Boolean hasDateDto() {
|
||||
return this.getColumns().stream().anyMatch(column ->
|
||||
(CodeGenConstants.REQUIRE.equals(column.getIsEdit()) || CodeGenConstants.REQUIRE.equals(column.getIsInsert())) && CodeGenConstants.TYPE_DATE.equals(column.getJavaType())
|
||||
);
|
||||
}
|
||||
|
||||
public Boolean isEntityTime(String field) {
|
||||
if (CodeGenConstants.UPDATE_TIME_FIELD.equals(field) || CodeGenConstants.CREATE_TIME_FIELD.equals(field)) {
|
||||
return Boolean.TRUE;
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 筛选Query中的时间格式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Boolean hasDateQuery() {
|
||||
return this.getColumns().stream().anyMatch(column ->
|
||||
CodeGenConstants.REQUIRE.equals(column.getIsQuery()) && CodeGenConstants.TYPE_DATE.equals(column.getJavaType())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 筛选Vo中的时间格式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Boolean hasDateVo() {
|
||||
return this.getColumns().stream().anyMatch(column ->
|
||||
CodeGenConstants.REQUIRE.equals(column.getIsList()) && CodeGenConstants.TYPE_DATE.equals(column.getJavaType())
|
||||
);
|
||||
}
|
||||
|
||||
public Boolean hasListAndDict(){
|
||||
return this.getColumns().stream().anyMatch(column->(CodeGenConstants.HTML_SELECT.equals(column.getHtmlType()) || CodeGenConstants.HTML_RADIO.equals(column.getHtmlType()))
|
||||
&& !StrUtil.isEmpty(column.getDictType()) && column.list());
|
||||
}
|
||||
|
||||
|
||||
public Boolean hasDictSelect() {
|
||||
return this.getColumns().stream().anyMatch(column ->
|
||||
(CodeGenConstants.HTML_SELECT.equals(column.getHtmlType()) || CodeGenConstants.HTML_RADIO.equals(column.getHtmlType()))
|
||||
&& !StrUtil.isEmpty(column.getDictType())
|
||||
);
|
||||
}
|
||||
|
||||
public String getDictType(){
|
||||
StringBuilder cacheType = new StringBuilder();
|
||||
this.getColumns().stream().filter(column ->
|
||||
(CodeGenConstants.HTML_SELECT.equals(column.getHtmlType()) || CodeGenConstants.HTML_RADIO.equals(column.getHtmlType()))
|
||||
&& !StrUtil.isEmpty(column.getDictType()))
|
||||
.forEach(column ->cacheType.append(" '").append(column.getDictType()).append("',"));
|
||||
return cacheType.substring(0, cacheType.length() - 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Boolean strNotEmpty(String str) {
|
||||
return !StrUtil.isEmpty(str);
|
||||
}
|
||||
|
||||
public String getFieldList() {
|
||||
StringBuilder columnNames = new StringBuilder();
|
||||
this.getColumns().stream().filter(column -> "1".equals(column.getIsList())).forEach(column -> {
|
||||
columnNames.append(" \"").append(column.getColumnName()).append("\",");
|
||||
});
|
||||
return columnNames.substring(0, columnNames.length() - 1);
|
||||
}
|
||||
|
||||
|
||||
public Boolean hasOptionApi() {
|
||||
return getOptionInfo().getEnabled();
|
||||
}
|
||||
|
||||
|
||||
public String getOptionValueFiled() {
|
||||
String valueField = getOptionInfo().getValueField();
|
||||
return StringUtils.capitalize(valueField);
|
||||
}
|
||||
|
||||
public String getOptionLabelFiled() {
|
||||
String labelFiled = getOptionInfo().getLabelFiled();
|
||||
return StringUtils.capitalize(labelFiled);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package cn.fateverse.code.entity.dto;
|
||||
|
||||
import cn.fateverse.code.entity.CodeDataSource;
|
||||
import cn.fateverse.code.enums.DynamicSourceEnum;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @Date: 2023/5/18
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ApiModel("数据源新增")
|
||||
public class DataSourceDto {
|
||||
|
||||
/**
|
||||
* 数据源id
|
||||
*/
|
||||
@ApiModelProperty("数据源id")
|
||||
private Long dsId;
|
||||
|
||||
/**
|
||||
* 数据源名称
|
||||
*/
|
||||
@ApiModelProperty("数据源名称")
|
||||
@NotBlank(message = "数据源名称不能为空")
|
||||
private String dsName;
|
||||
|
||||
/**
|
||||
* 数据源用户名
|
||||
*/
|
||||
@ApiModelProperty("数据源用户名")
|
||||
@NotBlank(message = "数据源用户名")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 数据源密码
|
||||
*/
|
||||
@ApiModelProperty("数据源密码")
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 数据源主机
|
||||
*/
|
||||
@ApiModelProperty("数据源主机")
|
||||
private String host;
|
||||
|
||||
/**
|
||||
* 数据源主机端口
|
||||
*/
|
||||
@ApiModelProperty("数据源主机端口")
|
||||
private Integer port;
|
||||
|
||||
/**
|
||||
* 数据源类型
|
||||
*/
|
||||
@ApiModelProperty("数据源类型")
|
||||
@NotNull(message = "数据源类型不能为空")
|
||||
private DynamicSourceEnum type;
|
||||
|
||||
/**
|
||||
* 数据库名称
|
||||
*/
|
||||
@ApiModelProperty("数据库名称")
|
||||
private String dbName;
|
||||
|
||||
/**
|
||||
* 数据库连接地址
|
||||
*/
|
||||
@ApiModelProperty("数据库连接地址")
|
||||
private String jdbcUrl;
|
||||
|
||||
/**
|
||||
* 数据源类型 (1:主机 2:jdbc连接url)
|
||||
*/
|
||||
@ApiModelProperty("数据源类型 (1:主机 2:jdbc连接url)")
|
||||
@Max(value = 2, message = "参数不合法")
|
||||
@Min(value = 1, message = "参数不合法")
|
||||
private Integer confType;
|
||||
|
||||
/**
|
||||
* 连接参数
|
||||
*/
|
||||
private String args;
|
||||
|
||||
/**
|
||||
* 查询参数
|
||||
*/
|
||||
private String params;
|
||||
|
||||
|
||||
public CodeDataSource toCodeDataSource() {
|
||||
if (confType.equals(1)) {
|
||||
return CodeDataSource.builder()
|
||||
.dsId(dsId)
|
||||
.dsName(dsName)
|
||||
.username(username)
|
||||
.password(password)
|
||||
.host(host)
|
||||
.port(port)
|
||||
.type(type)
|
||||
.args(args)
|
||||
.params(params)
|
||||
.dbName(dbName)
|
||||
.confType(confType)
|
||||
.build();
|
||||
} else {
|
||||
return CodeDataSource.builder()
|
||||
.dsId(dsId)
|
||||
.dsName(dsName)
|
||||
.username(username)
|
||||
.password(password)
|
||||
.jdbcUrl(jdbcUrl)
|
||||
.confType(confType)
|
||||
.params(params)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.fateverse.code.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2023-05-26
|
||||
*/
|
||||
@Data
|
||||
public class ImportDto {
|
||||
|
||||
@NotNull(message = "表格不能为空")
|
||||
private List<String> tables;
|
||||
|
||||
@NotNull(message = "数据源id不能为空")
|
||||
private Long dataSourceId;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package cn.fateverse.code.entity.dto;
|
||||
|
||||
import cn.fateverse.code.entity.Regular;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 校验规则表对象 gen_regula
|
||||
*
|
||||
* @author clay
|
||||
* @date 2023-05-27
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("校验规则表Dto")
|
||||
public class RegularDto {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@ApiModelProperty("id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 正则名称
|
||||
*/
|
||||
@ApiModelProperty("正则名称")
|
||||
@NotBlank(message = "正则名称不能为空!")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 正则内容
|
||||
*/
|
||||
@ApiModelProperty("正则内容")
|
||||
@NotBlank(message = "正则内容不能为空!")
|
||||
private String regular;
|
||||
|
||||
/**
|
||||
* 验证内容
|
||||
*/
|
||||
@ApiModelProperty("验证内容")
|
||||
@NotBlank(message = "验证内容不能为空!")
|
||||
private String validation;
|
||||
|
||||
/**
|
||||
* 是否启用 1:启动 2:关闭
|
||||
*/
|
||||
@ApiModelProperty("是否启用 1:启动 0:关闭")
|
||||
@NotNull(message = "是否启用不能为空!")
|
||||
private String enable;
|
||||
|
||||
public Regular toRegula() {
|
||||
return Regular.builder()
|
||||
.id(id)
|
||||
.name(name)
|
||||
.regular(regular)
|
||||
.validation(validation)
|
||||
.enable(enable)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.fateverse.code.entity.dto;
|
||||
|
||||
import cn.fateverse.code.entity.OptionInfo;
|
||||
import cn.fateverse.code.entity.Table;
|
||||
import cn.fateverse.code.entity.TableColumn;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/15
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TableDto extends Table {
|
||||
private List<TableColumn> columns;
|
||||
|
||||
|
||||
private OptionInfo optionInfo;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.fateverse.code.entity.query;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @Date: 2023/5/18
|
||||
*/
|
||||
@Data
|
||||
public class DataSourceQuery {
|
||||
/**
|
||||
* 数据源名称
|
||||
*/
|
||||
@ApiModelProperty("数据源名称")
|
||||
private String dsName;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.fateverse.code.entity.query;
|
||||
|
||||
import cn.fateverse.common.core.entity.QueryTime;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/17
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DynamicTable extends QueryTime {
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
@ApiModelProperty("表名称")
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表注释
|
||||
*/
|
||||
@ApiModelProperty("表注释")
|
||||
private String tableComment;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
private Date updateTime;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.fateverse.code.entity.query;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 校验规则表对象 gen_regula
|
||||
*
|
||||
* @author clay
|
||||
* @date 2023-05-27
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ApiModel("校验规则表Query")
|
||||
public class RegularQuery {
|
||||
|
||||
/**
|
||||
* 正则名称
|
||||
*/
|
||||
@ApiModelProperty("正则名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 正则内容
|
||||
*/
|
||||
@ApiModelProperty("正则内容")
|
||||
private String regular;
|
||||
|
||||
/**
|
||||
* 是否启用 1:启动 2:关闭
|
||||
*/
|
||||
@ApiModelProperty("是否启用 1:启动 0:关闭")
|
||||
private Integer enable;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package cn.fateverse.code.entity.query;
|
||||
|
||||
import cn.fateverse.common.core.entity.QueryTime;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/18
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ApiModel("代码生成查询实体")
|
||||
public class TableQuery extends QueryTime {
|
||||
|
||||
/**
|
||||
* 数据源id
|
||||
*/
|
||||
@ApiModelProperty("数据源id")
|
||||
private Long dataSourceId;
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
@ApiModelProperty("表名称")
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表描述
|
||||
*/
|
||||
@ApiModelProperty("表描述")
|
||||
private String tableComment;
|
||||
|
||||
@ApiModelProperty("数据类型")
|
||||
private String dataSourceType;
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package cn.fateverse.code.entity.vo;
|
||||
|
||||
import cn.fateverse.code.entity.CodeDataSource;
|
||||
import cn.fateverse.common.core.annotaion.Excel;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @Date: 2023/5/18
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ApiModel("数据源返回实体")
|
||||
public class DataSourceVo implements Serializable {
|
||||
|
||||
/**
|
||||
* 数据源id
|
||||
*/
|
||||
@ApiModelProperty("数据源id")
|
||||
private Long dsId;
|
||||
|
||||
/**
|
||||
* 数据源名称
|
||||
*/
|
||||
@ApiModelProperty("数据源名称")
|
||||
@Excel("数据源名称")
|
||||
private String dsName;
|
||||
|
||||
/**
|
||||
* 数据源用户名
|
||||
*/
|
||||
@ApiModelProperty("数据源用户名")
|
||||
@Excel("数据源用户名")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 数据源密码
|
||||
*/
|
||||
@ApiModelProperty("数据源密码")
|
||||
@Excel("数据源密码")
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 数据源主机
|
||||
*/
|
||||
@ApiModelProperty("数据源主机")
|
||||
@Excel("数据源主机")
|
||||
private String host;
|
||||
|
||||
/**
|
||||
* 数据源主机端口
|
||||
*/
|
||||
@ApiModelProperty("数据源主机端口")
|
||||
@Excel("数据源主机端口")
|
||||
private Integer port;
|
||||
|
||||
/**
|
||||
* 数据源类型
|
||||
*/
|
||||
@ApiModelProperty("数据源类型")
|
||||
@Excel("数据源类型")
|
||||
private String dsType;
|
||||
|
||||
/**
|
||||
* 数据库名称
|
||||
*/
|
||||
@ApiModelProperty("数据库名称")
|
||||
@Excel("数据库名称")
|
||||
private String dbName;
|
||||
|
||||
/**
|
||||
* 数据库连接地址
|
||||
*/
|
||||
@ApiModelProperty("数据库连接地址")
|
||||
@Excel("数据库连接地址")
|
||||
private String jdbcUrl;
|
||||
/**
|
||||
* 数据源类型 (1:主机 2:jdbc连接url)
|
||||
*/
|
||||
@ApiModelProperty("数据源类型 (1:主机 2:jdbc连接url)")
|
||||
@Max(value = 2, message = "参数不合法")
|
||||
@Min(value = 1, message = "参数不合法")
|
||||
@Excel("数据源类型")
|
||||
private Integer confType;
|
||||
|
||||
/**
|
||||
* 连接参数
|
||||
*/
|
||||
private String args;
|
||||
|
||||
/**
|
||||
* 查询参数
|
||||
*/
|
||||
private String params;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
public static DataSourceVo toDataSourceVo(CodeDataSource data) {
|
||||
return DataSourceVo.builder()
|
||||
.dsId(data.getDsId())
|
||||
.dsName(data.getDsName())
|
||||
.dbName(data.getDbName())
|
||||
.username(data.getUsername())
|
||||
.port(data.getPort())
|
||||
.jdbcUrl(data.getJdbcUrl())
|
||||
.confType(data.getConfType())
|
||||
.args(data.getArgs())
|
||||
.params(data.getParams())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package cn.fateverse.code.entity.vo;
|
||||
|
||||
import cn.fateverse.code.entity.Regular;
|
||||
import cn.fateverse.common.core.annotaion.Excel;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 校验规则表对象 gen_regula
|
||||
*
|
||||
* @author clay
|
||||
* @date 2023-05-27
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ApiModel("校验规则表Vo")
|
||||
public class RegularVo {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@ApiModelProperty("id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 正则名称
|
||||
*/
|
||||
@ApiModelProperty("正则名称")
|
||||
@Excel("正则名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 正则内容
|
||||
*/
|
||||
@ApiModelProperty("正则内容")
|
||||
@Excel("正则内容")
|
||||
private String regular;
|
||||
|
||||
/**
|
||||
* 验证内容
|
||||
*/
|
||||
@ApiModelProperty("验证内容")
|
||||
private String validation;
|
||||
|
||||
/**
|
||||
* 是否启用 1:启动 2:关闭
|
||||
*/
|
||||
@ApiModelProperty("是否启用 1:启动 2:关闭")
|
||||
@Excel(value = "是否启用",dictType = "regular_enable")
|
||||
private String enable;
|
||||
|
||||
@Excel("创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@Excel("是否启用")
|
||||
private Date updateTime;
|
||||
|
||||
public static RegularVo toRegulaVo(Regular regular) {
|
||||
return RegularVo.builder()
|
||||
.id(regular.getId())
|
||||
.name(regular.getName())
|
||||
.regular(regular.getRegular())
|
||||
.validation(regular.getValidation())
|
||||
.enable(regular.getEnable())
|
||||
.createTime(regular.getCreateTime())
|
||||
.updateTime(regular.getUpdateTime())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package cn.fateverse.code.entity.vo;
|
||||
|
||||
import cn.fateverse.code.entity.OptionInfo;
|
||||
import cn.fateverse.code.entity.Table;
|
||||
import cn.fateverse.code.entity.TableColumn;
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/18
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TableInfoVo {
|
||||
private List<Option> tableOption;
|
||||
private Table info;
|
||||
private OptionInfo optionInfo;
|
||||
private List<TableColumn> columns;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package cn.fateverse.code.entity.vo;
|
||||
|
||||
import cn.fateverse.common.core.annotaion.Excel;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/18
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ApiModel("代码生成table表格list 返回实体")
|
||||
public class TableVo {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@ApiModelProperty("编号")
|
||||
@Excel("编号")
|
||||
private Long tableId;
|
||||
|
||||
/**
|
||||
* 数据源id
|
||||
*/
|
||||
@ApiModelProperty("数据源id")
|
||||
@Excel("数据源id")
|
||||
private Long dataSourceId;
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
@ApiModelProperty("表名称")
|
||||
@Excel("表名称")
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表描述
|
||||
*/
|
||||
@ApiModelProperty("表描述")
|
||||
@Excel("表描述")
|
||||
private String tableComment;
|
||||
/**
|
||||
* 实体类名称
|
||||
*/
|
||||
@ApiModelProperty("实体类名称")
|
||||
@Excel("实体类名称")
|
||||
private String className;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Excel(value = "创建时间",dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Excel(value = "更新时间",dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date updateTime;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package cn.fateverse.code.enums;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2023-07-31
|
||||
*/
|
||||
public enum BackTemplateEnum {
|
||||
|
||||
MYBATIS,
|
||||
MYBATIS_PLUS;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package cn.fateverse.code.enums;
|
||||
|
||||
import cn.fateverse.code.factory.DynamicTableService;
|
||||
import cn.fateverse.code.factory.impl.MySQLDynamicTableService;
|
||||
import cn.fateverse.code.factory.impl.OracleDynamicTableService;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2023-07-29
|
||||
*/
|
||||
public enum DynamicSourceEnum {
|
||||
|
||||
/**
|
||||
* 数据库状态
|
||||
*/
|
||||
MYSQL("mysql", "com.mysql.cj.jdbc.Driver", MySQLDynamicTableService.class),
|
||||
MARIADB("mariadb", "org.mariadb.jdbc.Driver", MySQLDynamicTableService.class),
|
||||
ORACLE("oracle", "oracle.jdbc.driver.OracleDriver", OracleDynamicTableService.class),
|
||||
POSTGRES("postgres", "org.postgresql.Driver", DynamicTableService.class),
|
||||
;
|
||||
|
||||
|
||||
private final String type;
|
||||
|
||||
private final String drive;
|
||||
|
||||
private final Class<? extends DynamicTableService> clazz;
|
||||
|
||||
private volatile DynamicTableService dynamicTableService;
|
||||
|
||||
|
||||
DynamicSourceEnum(String type, String drive, Class<? extends DynamicTableService> clazz) {
|
||||
this.type = type;
|
||||
this.drive = drive;
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getDrive() {
|
||||
return drive;
|
||||
}
|
||||
|
||||
public DynamicTableService getDynamicDataSourceFactory() {
|
||||
if (null == dynamicTableService) {
|
||||
synchronized (this) {
|
||||
if (null == dynamicTableService) {
|
||||
try {
|
||||
dynamicTableService = clazz.newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("初始化实例失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dynamicTableService;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.fateverse.code.enums;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2023-07-31
|
||||
*/
|
||||
public enum FrontTemplateEnum {
|
||||
|
||||
VUE,
|
||||
REACT;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package cn.fateverse.code.factory;
|
||||
|
||||
import cn.fateverse.code.entity.CodeDataSource;
|
||||
import cn.fateverse.code.enums.DynamicSourceEnum;
|
||||
import cn.fateverse.code.mapper.dynamic.DynamicTableMapper;
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 动态数据源获取类
|
||||
*
|
||||
* @author Clay
|
||||
* @date 2023-07-16
|
||||
*/
|
||||
@Component
|
||||
public class DynamicDataSourceService {
|
||||
|
||||
private final Map<Long, SqlSessionFactory> factoryMap = new ConcurrentHashMap<>(8);
|
||||
|
||||
private static final ThreadLocal<SqlSession> session = new ThreadLocal<>();
|
||||
|
||||
|
||||
/**
|
||||
* 获取到数据源的
|
||||
*
|
||||
* @param dataSource 数据源
|
||||
* @return 返回sqlSession
|
||||
*/
|
||||
public DynamicTableMapper getMapper(CodeDataSource dataSource) {
|
||||
SqlSessionFactory sqlSessionFactory = factoryMap.get(dataSource.getDsId());
|
||||
DynamicSourceEnum type = dataSource.getType();
|
||||
if (sqlSessionFactory == null) {
|
||||
synchronized (this) {
|
||||
sqlSessionFactory = factoryMap.get(dataSource.getDsId());
|
||||
if (null == sqlSessionFactory) {
|
||||
sqlSessionFactory = type.getDynamicDataSourceFactory().getSqlSessionFactory(dataSource);
|
||||
factoryMap.put(dataSource.getDsId(), sqlSessionFactory);
|
||||
}
|
||||
}
|
||||
}
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession();
|
||||
session.set(sqlSession);
|
||||
return type.getDynamicDataSourceFactory().getTableMapper(sqlSession);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查当前数据源是否可连接
|
||||
*
|
||||
* @param dataSource 数据源
|
||||
* @return 状态
|
||||
*/
|
||||
public Boolean checkDataSource(CodeDataSource dataSource) {
|
||||
try {
|
||||
SqlSessionFactory sqlSessionFactory = dataSource.getType().getDynamicDataSourceFactory().getSqlSessionFactory(dataSource);
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession();
|
||||
DynamicTableMapper tableMapper = dataSource.getType().getDynamicDataSourceFactory().getTableMapper(sqlSession);
|
||||
tableMapper.checkSource();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (e instanceof CustomException) {
|
||||
throw e;
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除当前的缓存
|
||||
*
|
||||
* @param dataSourceId 数据源id
|
||||
*/
|
||||
public synchronized void remove(Long dataSourceId) {
|
||||
factoryMap.remove(dataSourceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭sqlSession
|
||||
*/
|
||||
public void closeSqlSession() {
|
||||
session.get().close();
|
||||
session.remove();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package cn.fateverse.code.factory;
|
||||
|
||||
import cn.fateverse.code.entity.CodeDataSource;
|
||||
import cn.fateverse.code.entity.DynamicPage;
|
||||
import cn.fateverse.code.entity.Table;
|
||||
import cn.fateverse.code.entity.TableColumn;
|
||||
import cn.fateverse.code.entity.dto.TableDto;
|
||||
import cn.fateverse.code.mapper.dynamic.DynamicTableMapper;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 动态表格服务接口
|
||||
*
|
||||
* @author Clay
|
||||
* @date 2023-07-16
|
||||
*/
|
||||
public interface DynamicTableService {
|
||||
|
||||
/**
|
||||
* 获取到数据库session 工厂
|
||||
*
|
||||
* @param dataSource 数据源管理信息
|
||||
* @return 数据工厂
|
||||
*/
|
||||
SqlSessionFactory getSqlSessionFactory(CodeDataSource dataSource);
|
||||
|
||||
/**
|
||||
* 获取到查询的mapper映射文件
|
||||
*
|
||||
* @param sqlSession sqlSession
|
||||
* @return 映射的mapper
|
||||
*/
|
||||
DynamicTableMapper getTableMapper(SqlSession sqlSession);
|
||||
|
||||
/**
|
||||
* 获取到动态的分页信息
|
||||
*
|
||||
* @return 分页信息
|
||||
*/
|
||||
DynamicPage getDynamicPage();
|
||||
|
||||
/**
|
||||
* 使用数据源拼接jdbcUrl
|
||||
*
|
||||
* @param dataSource 数据源管理信息
|
||||
* @return url返回参数
|
||||
*/
|
||||
String getDataBaseUrl(CodeDataSource dataSource);
|
||||
|
||||
/**
|
||||
* 获取到数据库对应的特殊参数
|
||||
*
|
||||
* @param dataSource 数据库特殊参数
|
||||
* @return 返回参数
|
||||
*/
|
||||
Map<String, Object> getParams(CodeDataSource dataSource);
|
||||
|
||||
/**
|
||||
* 初始化表格信息
|
||||
*
|
||||
* @param table 表格
|
||||
* @param tableColumns 表格列表
|
||||
*/
|
||||
TableDto initTable(Table table, List<TableColumn> tableColumns);
|
||||
|
||||
/**
|
||||
* 获取到mapper映射
|
||||
*
|
||||
* @return mapper映射文件
|
||||
*/
|
||||
String getMapperTemplate();
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
package cn.fateverse.code.factory.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.fateverse.code.config.CodeGenConfig;
|
||||
import cn.fateverse.code.entity.CodeDataSource;
|
||||
import cn.fateverse.code.entity.DynamicPage;
|
||||
import cn.fateverse.code.entity.Table;
|
||||
import cn.fateverse.code.entity.TableColumn;
|
||||
import cn.fateverse.code.entity.dto.TableDto;
|
||||
import cn.fateverse.code.enums.DynamicSourceEnum;
|
||||
import cn.fateverse.code.factory.DynamicTableService;
|
||||
import cn.fateverse.code.util.constant.CodeGenConstants;
|
||||
import cn.fateverse.common.core.entity.PageInfo;
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import cn.fateverse.common.core.utils.TableSupport;
|
||||
import cn.fateverse.common.mybatis.utils.PageUtils;
|
||||
import cn.fateverse.common.security.utils.SecurityUtils;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.datasource.unpooled.UnpooledDataSource;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 抽象动态表格
|
||||
*
|
||||
* @author Clay
|
||||
* @date 2023-07-24
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class AbstractDynamicTableService implements DynamicTableService {
|
||||
|
||||
public SqlSessionFactory getSqlSessionFactory(CodeDataSource dataSource, String mapperPath) {
|
||||
SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
|
||||
//获取需要的xml文件
|
||||
Resource[] resources = getResources(mapperPath);
|
||||
sessionFactoryBean.setMapperLocations(resources);
|
||||
DynamicSourceEnum dbType = dataSource.getType();
|
||||
String baseUrl;
|
||||
if (1 == dataSource.getConfType()) {
|
||||
baseUrl = getDataBaseUrl(dataSource);
|
||||
} else {
|
||||
baseUrl = dataSource.getJdbcUrl();
|
||||
}
|
||||
DataSource sqlDataSource = new UnpooledDataSource(dbType.getDrive(), baseUrl,
|
||||
dataSource.getUsername(), dataSource.getPassword());
|
||||
sessionFactoryBean.setDataSource(sqlDataSource);
|
||||
SqlSessionFactory sqlSessionFactory;
|
||||
try {
|
||||
sqlSessionFactory = sessionFactoryBean.getObject();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return sqlSessionFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DynamicPage getDynamicPage() {
|
||||
PageInfo pageInfo = TableSupport.buildPageRequest();
|
||||
Integer startNum = PageUtils.getStartSize(pageInfo);
|
||||
Integer endNum = startNum + pageInfo.getPageSize();
|
||||
return DynamicPage.builder()
|
||||
.startNum(startNum)
|
||||
.endNum(endNum)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getParams(CodeDataSource dataSource) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDto initTable(Table table, List<TableColumn> tableColumns) {//包名
|
||||
table.setPackageName(CodeGenConfig.getPackageName());
|
||||
//作者
|
||||
table.setFunctionAuthor(CodeGenConfig.getAuthor());
|
||||
//创建人
|
||||
table.setCreateBy(SecurityUtils.getUsername());
|
||||
//功能名
|
||||
table.setFunctionName(table.getTableComment());
|
||||
//模块名
|
||||
table.setModuleName(getModel(CodeGenConfig.getPackageName()));
|
||||
//Java Class 大驼峰名称
|
||||
table.setClassName(getClassName(table.getTableName()));
|
||||
//业务名称
|
||||
table.setBusinessName(getBusinessName(table.getTableName()));
|
||||
|
||||
TableDto tableDto = new TableDto();
|
||||
BeanUtils.copyProperties(table, tableDto);
|
||||
tableColumns.forEach(column -> {
|
||||
initBeforeColumn(column);
|
||||
initColumn(column);
|
||||
initAfterColumn(column);
|
||||
});
|
||||
tableDto.setColumns(tableColumns);
|
||||
return tableDto;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 预先初始化公共字段
|
||||
*
|
||||
* @param column 列
|
||||
*/
|
||||
abstract void initColumn(TableColumn column);
|
||||
|
||||
/**
|
||||
* 预先初始化公共字段
|
||||
*
|
||||
* @param column 列
|
||||
*/
|
||||
private void initBeforeColumn(TableColumn column) {
|
||||
column.setCreateBy(SecurityUtils.getUsername());
|
||||
column.setIsRequired(CodeGenConstants.NO_REQUIRE);
|
||||
column.setJavaField(StrUtil.toCamelCase(column.getColumnName().toLowerCase()));
|
||||
column.setJavaType(CodeGenConstants.TYPE_STRING);
|
||||
column.setIsRegular(0L);
|
||||
column.setDictType(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 后处理公共字段
|
||||
*
|
||||
* @param tableColumn 列
|
||||
*/
|
||||
private void initAfterColumn(TableColumn tableColumn) {
|
||||
String columnName = tableColumn.getColumnName().toLowerCase();
|
||||
// 编辑字段
|
||||
if (!arraysContains(CodeGenConstants.COLUMN_NAME_NOT_EDIT_INSERT, columnName) && !tableColumn.isPk()) {
|
||||
tableColumn.setIsEdit(CodeGenConstants.REQUIRE);
|
||||
}
|
||||
if (!arraysContains(CodeGenConstants.COLUMN_NAME_NOT_EDIT_INSERT, columnName) && !tableColumn.isPk()) {
|
||||
tableColumn.setIsInsert(CodeGenConstants.REQUIRE);
|
||||
}
|
||||
// 列表字段
|
||||
if (!arraysContains(CodeGenConstants.COLUMN_NAME_NOT_LIST, columnName) && !tableColumn.isPk()) {
|
||||
tableColumn.setIsList(CodeGenConstants.REQUIRE);
|
||||
}
|
||||
// 查询字段
|
||||
if (!arraysContains(CodeGenConstants.COLUMN_NAME_NOT_QUERY, columnName) && !tableColumn.isPk()) {
|
||||
tableColumn.setIsQuery(CodeGenConstants.REQUIRE);
|
||||
}
|
||||
// 查询字段类型
|
||||
if (StringUtils.endsWithIgnoreCase(columnName, CodeGenConstants.NAME_SUFFIX)) {
|
||||
tableColumn.setQueryType(CodeGenConstants.QUERY_LIKE);
|
||||
}
|
||||
// 状态字段设置单选框
|
||||
if (StringUtils.endsWithIgnoreCase(columnName, CodeGenConstants.STATE_SUFFIX)) {
|
||||
tableColumn.setHtmlType(CodeGenConstants.HTML_RADIO);
|
||||
}
|
||||
// 类型&性别字段设置下拉框
|
||||
else if (StringUtils.endsWithIgnoreCase(columnName, CodeGenConstants.TYPE_SUFFIX) || StringUtils.endsWithIgnoreCase(columnName, CodeGenConstants.SEX_SUFFIX)) {
|
||||
tableColumn.setHtmlType(CodeGenConstants.HTML_SELECT);
|
||||
}
|
||||
// 图片字段设置图片上传控件
|
||||
else if (StringUtils.endsWithIgnoreCase(columnName, CodeGenConstants.IMAGE_SUFFIX)) {
|
||||
tableColumn.setHtmlType(CodeGenConstants.HTML_IMAGE_UPLOAD);
|
||||
}
|
||||
// 文件字段设置文件上传控件
|
||||
else if (StringUtils.endsWithIgnoreCase(columnName, CodeGenConstants.FILE_SUFFIX)) {
|
||||
tableColumn.setHtmlType(CodeGenConstants.HTML_FILE_UPLOAD);
|
||||
}
|
||||
// 内容字段设置富文本控件
|
||||
else if (StringUtils.endsWithIgnoreCase(columnName, CodeGenConstants.CONTENT_SUFFIX)) {
|
||||
tableColumn.setHtmlType(CodeGenConstants.HTML_EDITOR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断数据中是否存在这个参数
|
||||
*
|
||||
* @param arr 数组
|
||||
* @param targetValue 目标值
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean arraysContains(String[] arr, String targetValue) {
|
||||
return Arrays.asList(arr).contains(targetValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查参数设置
|
||||
*
|
||||
* @param paramStr 参数str
|
||||
* @param msg 失败信息
|
||||
* @param keys 参数key
|
||||
* @return 参数对象
|
||||
*/
|
||||
public JSONObject checkParam(String paramStr, String msg, String... keys) {
|
||||
if (StrUtil.isBlank(paramStr)) {
|
||||
throw new CustomException(msg);
|
||||
}
|
||||
JSONObject params;
|
||||
try {
|
||||
params = JSON.parseObject(paramStr);
|
||||
for (String key : keys) {
|
||||
if (StrUtil.isBlank(params.getString(key))) {
|
||||
log.error(key + "is blank");
|
||||
throw new CustomException(msg);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
throw new CustomException(msg);
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取到mybatis xml资源
|
||||
*
|
||||
* @param location 资源路径
|
||||
* @return 资源组
|
||||
*/
|
||||
public Resource[] getResources(String location) {
|
||||
PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
|
||||
Resource resource = pathMatchingResourcePatternResolver.getResource(location);
|
||||
Resource baseResource = pathMatchingResourcePatternResolver.getResource("classpath:mapper/dynamic/DynamicTableMapper.xml");
|
||||
Resource[] resources = new Resource[2];
|
||||
resources[0] = resource;
|
||||
resources[1] = baseResource;
|
||||
return resources;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模块名称
|
||||
*
|
||||
* @param packageName 包名
|
||||
* @return 模块名
|
||||
*/
|
||||
public String getModel(String packageName) {
|
||||
int lastIndex = packageName.lastIndexOf(".") + 1;
|
||||
int nameLength = packageName.length();
|
||||
return packageName.substring(lastIndex, nameLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Class类名,去除前缀
|
||||
*
|
||||
* @param tableName 表名称
|
||||
* @return 处理完成的class名称
|
||||
*/
|
||||
public String getClassName(String tableName) {
|
||||
String finalTableName = tableName.toLowerCase();
|
||||
if (CodeGenConfig.isAutoRemovePre()) {
|
||||
List<String> tablePrefix = CodeGenConfig.getTablePrefix();
|
||||
Optional<String> first = tablePrefix.stream().filter(finalTableName::startsWith).findFirst();
|
||||
if (first.isPresent()) {
|
||||
String text = first.get();
|
||||
finalTableName = finalTableName.replaceFirst(text, "");
|
||||
}
|
||||
}
|
||||
return StringUtils.capitalize(StrUtil.toCamelCase(finalTableName));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取业务名称
|
||||
*
|
||||
* @param tableName 表名称
|
||||
* @return 业务名称
|
||||
*/
|
||||
public String getBusinessName(String tableName) {
|
||||
tableName = tableName.toLowerCase();
|
||||
String[] split = tableName.split("_");
|
||||
return split[split.length - 1].toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Mysql or MariaDB数据库类型
|
||||
*
|
||||
* @param columnType 列类型
|
||||
* @return 数据类型
|
||||
*/
|
||||
public String getDbType(String columnType) {
|
||||
if (StringUtils.indexOf(columnType, "(") > 0) {
|
||||
return StringUtils.substringBefore(columnType, "(");
|
||||
} else {
|
||||
return columnType;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* todo mysql获取到字段长度,需要将字段长度和类型分别存放到两个字段里面去
|
||||
*
|
||||
* @param columnType 列类型
|
||||
* @return 长度
|
||||
*/
|
||||
public Integer getColumnLength(String columnType) {
|
||||
//todo 需要对带有小数的数据类型进行特殊判断
|
||||
if (StringUtils.indexOf(columnType, "(") > 0) {
|
||||
String length = StringUtils.substringBetween(columnType, "(", ")");
|
||||
return Integer.valueOf(length);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package cn.fateverse.code.factory.impl;
|
||||
|
||||
import cn.fateverse.code.entity.CodeDataSource;
|
||||
import cn.fateverse.code.entity.TableColumn;
|
||||
import cn.fateverse.code.mapper.dynamic.DynamicTableMapper;
|
||||
import cn.fateverse.code.mapper.dynamic.MySqlDynamicTableMapper;
|
||||
import cn.fateverse.code.util.constant.CodeGenConstants;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2023-07-29
|
||||
*/
|
||||
public class MySQLDynamicTableService extends AbstractDynamicTableService {
|
||||
|
||||
|
||||
/**
|
||||
* mysql 数据库字符串类型
|
||||
*/
|
||||
public static final String[] MYSQL_COLUMN_TYPE_STR = {"char", "varchar", "nvarchar", "nvarchar2", "varchar2", "tinytext", "text",
|
||||
"mediumtext", "longtext"};
|
||||
|
||||
/**
|
||||
* mysql 数据库文本类型
|
||||
*/
|
||||
public static final String[] MYSQL_COLUMN_TYPE_TEXT = {"tinytext", "text", "mediumtext", "longtext"};
|
||||
|
||||
/**
|
||||
* mysql 数据库时间类型
|
||||
*/
|
||||
public static final String[] MYSQL_COLUMN_TYPE_TIME = {"datetime", "time", "date", "timestamp"};
|
||||
|
||||
/**
|
||||
* mysql 数据库数字类型
|
||||
*/
|
||||
public static final String[] MYSQL_COLUMN_TYPE_NUMBER = {"tinyint", "smallint", "mediumint", "int", "number", "integer",
|
||||
"bit", "bigint"};
|
||||
|
||||
/**
|
||||
* mysql 数据库浮点类型
|
||||
*/
|
||||
public static final String[] MYSQL_COLUMN_TYPE_FLOAT = {"float", "float", "double", "decimal"};
|
||||
|
||||
|
||||
@Override
|
||||
public SqlSessionFactory getSqlSessionFactory(CodeDataSource dataSource) {
|
||||
return super.getSqlSessionFactory(dataSource,"classpath:mapper/dynamic/MySqlDynamicTableMapper.xml");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DynamicTableMapper getTableMapper(SqlSession sqlSession) {
|
||||
return sqlSession.getMapper(MySqlDynamicTableMapper.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDataBaseUrl(CodeDataSource dataSource) {
|
||||
return "jdbc:mysql://" + dataSource.getHost() + ":" + dataSource.getPort() + "/" + dataSource.getDbName() + dataSource.getArgs();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
void initColumn(TableColumn column) {
|
||||
column.setColumnType(column.getColumnType().toLowerCase());
|
||||
String dataType = getDbType(column.getColumnType());
|
||||
column.setColumnLength(getColumnLength(column.getColumnType()));
|
||||
if (arraysContains(MYSQL_COLUMN_TYPE_STR, dataType) || arraysContains(MYSQL_COLUMN_TYPE_TEXT, dataType)) {
|
||||
// 字符串长度超过500设置为文本域
|
||||
Integer columnLength = column.getColumnLength();
|
||||
String htmlType = columnLength >= 500 || arraysContains(MYSQL_COLUMN_TYPE_TEXT, dataType) ? CodeGenConstants.HTML_TEXTAREA : CodeGenConstants.HTML_INPUT;
|
||||
column.setHtmlType(htmlType);
|
||||
} else if (arraysContains(MYSQL_COLUMN_TYPE_TIME, dataType)) {
|
||||
column.setJavaType(CodeGenConstants.TYPE_DATE);
|
||||
column.setHtmlType(CodeGenConstants.HTML_DATETIME);
|
||||
} else if (arraysContains(MYSQL_COLUMN_TYPE_NUMBER, dataType)) {
|
||||
column.setHtmlType(CodeGenConstants.HTML_INPUT);
|
||||
// 如果是浮点型 统一用BigDecimal
|
||||
String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
|
||||
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) {
|
||||
column.setJavaType(CodeGenConstants.TYPE_BIG_DECIMAL);
|
||||
} else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) {
|
||||
// 如果是整形
|
||||
column.setJavaType(CodeGenConstants.TYPE_INTEGER);
|
||||
} else {
|
||||
// 长整形
|
||||
column.setJavaType(CodeGenConstants.TYPE_LONG);
|
||||
}
|
||||
// 如果类型确定是浮点型,直接使用BigDecimal
|
||||
} else if (arraysContains(MYSQL_COLUMN_TYPE_FLOAT, dataType)) {
|
||||
column.setHtmlType(CodeGenConstants.HTML_INPUT);
|
||||
column.setJavaType(CodeGenConstants.TYPE_BIG_DECIMAL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMapperTemplate() {
|
||||
return "vm/xml/mapperMySql.xml.vm";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package cn.fateverse.code.factory.impl;
|
||||
|
||||
import cn.fateverse.code.entity.CodeDataSource;
|
||||
import cn.fateverse.code.entity.TableColumn;
|
||||
import cn.fateverse.code.mapper.dynamic.DynamicTableMapper;
|
||||
import cn.fateverse.code.mapper.dynamic.OracleDynamicTableMapper;
|
||||
import cn.fateverse.code.util.constant.CodeGenConstants;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2023-07-30
|
||||
*/
|
||||
public class OracleDynamicTableService extends AbstractDynamicTableService {
|
||||
|
||||
/**
|
||||
* oracle字符类型
|
||||
*/
|
||||
public static final String[] ORACLE_COLUMN_TYPE_STR = {"VARCHAR", "VARCHAR2", "NVARCHAR2", "CLOB"};
|
||||
|
||||
/**
|
||||
* oracle 数字类型
|
||||
*/
|
||||
public static final String[] ORACLE_COLUMN_TYPE_NUMBER = {"NUMBER"};
|
||||
|
||||
/**
|
||||
* oracle 时间类型
|
||||
*/
|
||||
public static final String[] ORACLE_COLUMN_TYPE_DATE = {"DATE"};
|
||||
|
||||
/**
|
||||
* oracle 大文本类型
|
||||
*/
|
||||
public static final String ORACLE_CLOB = "CLOB";
|
||||
|
||||
/**
|
||||
* oracle 大文本二进制类型
|
||||
*/
|
||||
public static final String ORACLE_BLOB = "BLOB";
|
||||
|
||||
@Override
|
||||
public SqlSessionFactory getSqlSessionFactory(CodeDataSource dataSource) {
|
||||
return super.getSqlSessionFactory(dataSource, "classpath:mapper/dynamic/OracleDynamicTableMapper.xml");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DynamicTableMapper getTableMapper(SqlSession sqlSession) {
|
||||
return sqlSession.getMapper(OracleDynamicTableMapper.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDataBaseUrl(CodeDataSource dataSource) {
|
||||
JSONObject params = super.checkParam(dataSource.getParams(), "服务名称不能为空", "serviceName");
|
||||
return "jdbc:oracle:thin:@" + dataSource.getHost() + ":" + dataSource.getPort() + ":" + params.getString("serviceName") + (ObjectUtils.isEmpty(dataSource.getArgs()) ? "" : dataSource.getArgs());
|
||||
}
|
||||
|
||||
@Override
|
||||
void initColumn(TableColumn column) {
|
||||
column.setIsIncrement(CodeGenConstants.NO_REQUIRE);
|
||||
if (arraysContains(ORACLE_COLUMN_TYPE_STR, column.getColumnType())) {
|
||||
Integer columnLength = column.getColumnLength();
|
||||
String htmlType = columnLength >= 500 || ORACLE_CLOB.equals(column.getColumnComment()) ? CodeGenConstants.HTML_TEXTAREA : CodeGenConstants.HTML_INPUT;
|
||||
column.setHtmlType(htmlType);
|
||||
} else if (arraysContains(ORACLE_COLUMN_TYPE_DATE, column.getColumnType())) {
|
||||
column.setJavaType(CodeGenConstants.TYPE_DATE);
|
||||
column.setHtmlType(CodeGenConstants.HTML_DATETIME);
|
||||
} else if (arraysContains(ORACLE_COLUMN_TYPE_NUMBER, column.getColumnType())) {
|
||||
column.setHtmlType(CodeGenConstants.HTML_INPUT);
|
||||
// 如果是浮点型 统一用BigDecimal
|
||||
if (null != column.getColumnScale() && column.getColumnScale() > 0) {
|
||||
column.setJavaType(CodeGenConstants.TYPE_BIG_DECIMAL);
|
||||
} else if (column.getColumnLength() <= 10) {
|
||||
// 如果是整形
|
||||
column.setJavaType(CodeGenConstants.TYPE_INTEGER);
|
||||
} else {
|
||||
// 长整形
|
||||
column.setJavaType(CodeGenConstants.TYPE_LONG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMapperTemplate() {
|
||||
return "vm/xml/mapperOracle.xml.vm";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package cn.fateverse.code.mapper;
|
||||
|
||||
import cn.fateverse.code.entity.CodeDataSource;
|
||||
import cn.fateverse.code.entity.query.DataSourceQuery;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/16
|
||||
*/
|
||||
public interface DataSourceMapper {
|
||||
|
||||
/**
|
||||
* 查询数据源列表
|
||||
*
|
||||
* @param query 查询对象
|
||||
* @return 返回结果
|
||||
*/
|
||||
List<CodeDataSource> selectList(DataSourceQuery query);
|
||||
|
||||
/**
|
||||
* 根据id查询数据源信息
|
||||
*
|
||||
* @param dsId
|
||||
* @return
|
||||
*/
|
||||
CodeDataSource selectById(Long dsId);
|
||||
|
||||
/**
|
||||
* 新增数据源
|
||||
*
|
||||
* @param codeDataSource
|
||||
* @return
|
||||
*/
|
||||
int insert(CodeDataSource codeDataSource);
|
||||
|
||||
/**
|
||||
* 更新数据源信息
|
||||
*
|
||||
* @param codeDataSource
|
||||
* @return
|
||||
*/
|
||||
int update(CodeDataSource codeDataSource);
|
||||
|
||||
|
||||
/**
|
||||
* 根据id删除数据源信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
int delete(Long id);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package cn.fateverse.code.mapper;
|
||||
|
||||
import cn.fateverse.code.entity.Regular;
|
||||
import cn.fateverse.code.entity.query.RegularQuery;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 校验规则表 Mapper
|
||||
*
|
||||
* @author clay
|
||||
* @date 2023-05-27
|
||||
*/
|
||||
public interface RegularMapper {
|
||||
|
||||
/**
|
||||
* 查询校验规则表
|
||||
*
|
||||
* @param id 校验规则表Id
|
||||
* @return 校验规则表
|
||||
*/
|
||||
Regular selectById(Long id);
|
||||
|
||||
/**
|
||||
* 查询校验规则表列表
|
||||
*
|
||||
* @param query 校验规则表查询
|
||||
* @return 校验规则表集合
|
||||
*/
|
||||
List<Regular> selectList(RegularQuery query);
|
||||
|
||||
/**
|
||||
* 新增校验规则表
|
||||
*
|
||||
* @param regular 校验规则表
|
||||
* @return 结果
|
||||
*/
|
||||
int insert(Regular regular);
|
||||
|
||||
/**
|
||||
* 修改校验规则表
|
||||
*
|
||||
* @param regular 校验规则表
|
||||
* @return 结果
|
||||
*/
|
||||
int update(Regular regular);
|
||||
|
||||
/**
|
||||
* 删除校验规则表
|
||||
*
|
||||
* @param id 需要删除的校验规则表Id
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除校验规则表
|
||||
*
|
||||
* @param idList 需要删除的校验规则表Id 集合
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteBatchByIdList(List<Long> idList);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package cn.fateverse.code.mapper;
|
||||
|
||||
import cn.fateverse.code.entity.TableColumn;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/18
|
||||
*/
|
||||
public interface TableColumnMapper {
|
||||
|
||||
|
||||
/**
|
||||
* 根据表格id查询列信息
|
||||
*
|
||||
* @param tableId 表格id
|
||||
* @return 查询结果
|
||||
*/
|
||||
List<TableColumn> selectListByTableId(Long tableId);
|
||||
|
||||
/**
|
||||
* 新增列信息
|
||||
*
|
||||
* @param tableColumn
|
||||
* @return
|
||||
*/
|
||||
int insert(TableColumn tableColumn);
|
||||
|
||||
|
||||
/**
|
||||
* 批量新增
|
||||
*
|
||||
* @param columns 列信息
|
||||
* @return 执行结果
|
||||
*/
|
||||
int batchInsert(List<TableColumn> columns);
|
||||
|
||||
/**
|
||||
* 修改列信息
|
||||
*
|
||||
* @param tableColumn
|
||||
* @return
|
||||
*/
|
||||
int update(TableColumn tableColumn);
|
||||
|
||||
/**
|
||||
* 批量修改列信息
|
||||
*
|
||||
* @param columns 列信息
|
||||
* @return 执行结果
|
||||
*/
|
||||
int batchUpdate(List<TableColumn> columns);
|
||||
|
||||
/**
|
||||
* 批量删除列信息
|
||||
*
|
||||
* @param tableIds
|
||||
* @return
|
||||
*/
|
||||
int deleteByTableIds(List<Long> tableIds);
|
||||
|
||||
/**
|
||||
* 删除列信息
|
||||
*
|
||||
* @param tableId
|
||||
* @return
|
||||
*/
|
||||
int deleteByTableId(Long tableId);
|
||||
|
||||
/**
|
||||
* 批量删除列信息
|
||||
*
|
||||
* @param ids 需要删除的id信息
|
||||
* @return 执行结果
|
||||
*/
|
||||
int batchRemove(@Param("ids") List<Long> ids);
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package cn.fateverse.code.mapper;
|
||||
|
||||
import cn.fateverse.code.entity.Table;
|
||||
import cn.fateverse.code.entity.dto.TableDto;
|
||||
import cn.fateverse.code.entity.query.TableQuery;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/15
|
||||
*/
|
||||
public interface TableMapper {
|
||||
/**
|
||||
* 根据数据源id查询表格名称
|
||||
*
|
||||
* @param dataSourceId
|
||||
* @return
|
||||
*/
|
||||
Set<String> selectTableNameByDataSourceId(Long dataSourceId);
|
||||
|
||||
/**
|
||||
* 查询表格list
|
||||
*
|
||||
* @param query
|
||||
* @return 业务集合
|
||||
*/
|
||||
List<Table> selectTableList(TableQuery query);
|
||||
|
||||
/**
|
||||
* 查询所有表信息
|
||||
*
|
||||
* @return 表信息集合
|
||||
*/
|
||||
List<Table> selectTableAll();
|
||||
|
||||
/**
|
||||
* 根据id查询表信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
TableDto selectTableDtoByTableId(Long id);
|
||||
|
||||
/**
|
||||
* 根据表名称查询表信息
|
||||
*
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
TableDto selectTableByName(String tableName);
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*
|
||||
* @param table
|
||||
* @return
|
||||
*/
|
||||
int insertTable(Table table);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*
|
||||
* @param table
|
||||
* @return
|
||||
*/
|
||||
int updateTable(Table table);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param tableId
|
||||
* @return
|
||||
*/
|
||||
int deleteTableById(Long tableId);
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
int deleteTableByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据数据源id检查是否存在表格信息
|
||||
* @param id 数据源id
|
||||
* @return 表格数据量
|
||||
*/
|
||||
Long selectCheckTableByDataSourceId(Long id);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package cn.fateverse.code.mapper.dynamic;
|
||||
|
||||
import cn.fateverse.code.entity.DynamicPage;
|
||||
import cn.fateverse.code.entity.TableColumn;
|
||||
import cn.fateverse.code.entity.query.DynamicTable;
|
||||
import cn.fateverse.code.entity.Table;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/17
|
||||
*/
|
||||
public interface DynamicTableMapper {
|
||||
|
||||
/**
|
||||
* 检查数据源是否可用
|
||||
* @return
|
||||
*/
|
||||
Integer checkSource();
|
||||
|
||||
|
||||
/**
|
||||
* 查询动态的表格源信息列表
|
||||
*
|
||||
* @param table
|
||||
* @param page
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
List<DynamicTable> selectList(@Param("table") DynamicTable table, @Param("page") DynamicPage page, @Param("list") List<String> tableName);
|
||||
|
||||
/**
|
||||
* 查询动态的表格源信息 总数
|
||||
* @param table
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
Long selectListCount(@Param("table") DynamicTable table, @Param("list") List<String> tableName);
|
||||
|
||||
/**
|
||||
* 通过表名称查询
|
||||
*
|
||||
* @param tables
|
||||
* @return
|
||||
*/
|
||||
List<Table> selectListByNameList(List<String> tables);
|
||||
|
||||
/**
|
||||
* 根据tablename list 获取到所有的
|
||||
*
|
||||
* @param tables
|
||||
* @return
|
||||
*/
|
||||
List<TableColumn> selectColumnsByNameList(List<String> tables);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.fateverse.code.mapper.dynamic;
|
||||
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/21
|
||||
*/
|
||||
public interface MySqlDynamicTableMapper extends DynamicTableMapper {
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.fateverse.code.mapper.dynamic;
|
||||
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/21
|
||||
*/
|
||||
public interface OracleDynamicTableMapper extends DynamicTableMapper {
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package cn.fateverse.code.service;
|
||||
|
||||
import cn.fateverse.code.entity.CodeDataSource;
|
||||
import cn.fateverse.code.entity.dto.DataSourceDto;
|
||||
import cn.fateverse.code.entity.query.DataSourceQuery;
|
||||
import cn.fateverse.code.entity.vo.DataSourceVo;
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/16
|
||||
*/
|
||||
public interface DataSourceService {
|
||||
|
||||
|
||||
/**
|
||||
* 查询数据源列表
|
||||
*
|
||||
* @param query 查询对象
|
||||
* @return 查询结果
|
||||
*/
|
||||
TableDataInfo<DataSourceVo> searchList(DataSourceQuery query);
|
||||
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param query 查询对象
|
||||
* @return 查询结果
|
||||
*/
|
||||
List<DataSourceVo> searchExport(DataSourceQuery query);
|
||||
|
||||
/**
|
||||
* 根据id获取数据源
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
CodeDataSource searchById(Long id);
|
||||
|
||||
/**
|
||||
* 获取到option类型的数据源信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<Option> searchOption();
|
||||
|
||||
/**
|
||||
* 新增数据源
|
||||
*
|
||||
*
|
||||
* @param dataSource 数据源信息
|
||||
*/
|
||||
void save(DataSourceDto dataSource);
|
||||
|
||||
/**
|
||||
* 更新数据源
|
||||
*
|
||||
* @param dataSource 数据源信息
|
||||
*/
|
||||
void edit(DataSourceDto dataSource);
|
||||
|
||||
/**
|
||||
* 根据id删除数据源
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
void removeById(Long id);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.fateverse.code.service;
|
||||
|
||||
import cn.fateverse.code.entity.query.DynamicTable;
|
||||
import cn.fateverse.code.entity.dto.TableDto;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 动态表格元数据服务接口
|
||||
*
|
||||
* @author Clay
|
||||
* @date 2022/11/17
|
||||
*/
|
||||
@Service
|
||||
public interface DynamicTableMetadataService {
|
||||
|
||||
/**
|
||||
* 查询动态的表格源信息列表
|
||||
*
|
||||
* @param table 动态表格
|
||||
* @param dataSourceId 数据源id
|
||||
* @return 表格数据
|
||||
*/
|
||||
TableDataInfo<DynamicTable> searchList(DynamicTable table, Long dataSourceId);
|
||||
|
||||
/**
|
||||
* 获取到完成的表元数据
|
||||
*
|
||||
* @param tables 表格名称数组
|
||||
* @param dataSourceId 数据源id
|
||||
* @return 表格信息
|
||||
*/
|
||||
List<TableDto> searchFullTableByTableNames(List<String> tables, Long dataSourceId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package cn.fateverse.code.service;
|
||||
|
||||
import cn.fateverse.code.entity.dto.RegularDto;
|
||||
import cn.fateverse.code.entity.vo.RegularVo;
|
||||
import cn.fateverse.code.entity.query.RegularQuery;
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 校验规则表 Service
|
||||
*
|
||||
* @author clay
|
||||
* @date 2023-05-27
|
||||
*/
|
||||
public interface RegularService {
|
||||
|
||||
/**
|
||||
* 查询校验规则表
|
||||
*
|
||||
* @param id 校验规则表Id
|
||||
* @return 校验规则表
|
||||
*/
|
||||
RegularVo searchById(Long id);
|
||||
|
||||
/**
|
||||
* 查询校验规则表列表
|
||||
*
|
||||
* @param query 校验规则表
|
||||
* @return 校验规则表集合
|
||||
*/
|
||||
TableDataInfo<RegularVo> searchList(RegularQuery query);
|
||||
|
||||
/**
|
||||
* 获取到选项列表
|
||||
*
|
||||
* @return 选项列表
|
||||
*/
|
||||
List<Option> searchOptionList();
|
||||
|
||||
/**
|
||||
* 导出校验规则表列表
|
||||
*
|
||||
* @param query query 校验规则表
|
||||
* @return 校验规则表集合
|
||||
*/
|
||||
List<RegularVo> exportList(RegularQuery query);
|
||||
|
||||
/**
|
||||
* 新增校验规则表
|
||||
*
|
||||
* @param regular 校验规则表
|
||||
* @return 结果
|
||||
*/
|
||||
int save(RegularDto regular);
|
||||
|
||||
/**
|
||||
* 修改校验规则表
|
||||
*
|
||||
* @param regular 校验规则表
|
||||
* @return 结果
|
||||
*/
|
||||
int edit(RegularDto regular);
|
||||
|
||||
/**
|
||||
* 删除校验规则表
|
||||
*
|
||||
* @param id 需要删除的校验规则表Id
|
||||
* @return 结果
|
||||
*/
|
||||
int removeById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除校验规则表
|
||||
*
|
||||
* @param idList 需要删除的校验规则表Id 集合
|
||||
* @return 结果
|
||||
*/
|
||||
int removeBatch(List<Long> idList);
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package cn.fateverse.code.service;
|
||||
|
||||
import cn.fateverse.code.entity.dto.ImportDto;
|
||||
import cn.fateverse.code.entity.dto.TableDto;
|
||||
import cn.fateverse.code.entity.query.TableQuery;
|
||||
import cn.fateverse.code.entity.vo.TableVo;
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/15
|
||||
*/
|
||||
public interface TableService {
|
||||
|
||||
|
||||
/**
|
||||
* 查询表信息
|
||||
*
|
||||
* @param query 表格查询
|
||||
* @return 表格数据信息
|
||||
*/
|
||||
TableDataInfo<TableVo> searchList(TableQuery query);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* @param query 表格查询
|
||||
* @return 导出数据
|
||||
*/
|
||||
List<TableVo> searchExport(TableQuery query);
|
||||
|
||||
/**
|
||||
* 根据id查询到表的所有信息
|
||||
*
|
||||
* @param tableId
|
||||
* @return
|
||||
*/
|
||||
TableDto searchByTableId(Long tableId);
|
||||
|
||||
/**
|
||||
* 根据数据源id获取到对应的表,并组合成为option
|
||||
*
|
||||
* @param dataSourceId
|
||||
* @return
|
||||
*/
|
||||
List<Option> searchOptionByDataSourceId(Long dataSourceId);
|
||||
|
||||
/**
|
||||
* 预览代码
|
||||
*
|
||||
* @param tableId 表编号
|
||||
* @return 预览数据列表
|
||||
*/
|
||||
Map<String, String> previewCode(Long tableId);
|
||||
|
||||
/**
|
||||
* 下载代码
|
||||
*
|
||||
* @param tableId 表编号
|
||||
*/
|
||||
void downloadCode(Long tableId);
|
||||
|
||||
/**
|
||||
* 批量下载代码
|
||||
*
|
||||
* @param tableIds 表编号列表
|
||||
*/
|
||||
void downloadCodeList(List<Long> tableIds);
|
||||
|
||||
/**
|
||||
* 导入数据库表的源信息
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
Result<Void> importTable(ImportDto dto);
|
||||
|
||||
/**
|
||||
* 更新数据源信息
|
||||
*
|
||||
* @param table
|
||||
* @return
|
||||
*/
|
||||
Result<Void> edit(TableDto table);
|
||||
|
||||
/**
|
||||
* 同步数据库
|
||||
* @param tableId 同步数据库表
|
||||
*/
|
||||
void syncTable(Long tableId);
|
||||
|
||||
/**
|
||||
* 删除元数据
|
||||
*
|
||||
* @param tableId
|
||||
*/
|
||||
void remove(Long tableId);
|
||||
|
||||
/**
|
||||
* 批量删除元数据
|
||||
*
|
||||
* @param tableIds
|
||||
*/
|
||||
void removeBatch(List<Long> tableIds);
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package cn.fateverse.code.service.impl;
|
||||
|
||||
import cn.fateverse.code.mapper.TableMapper;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.fateverse.code.entity.CodeDataSource;
|
||||
import cn.fateverse.code.entity.dto.DataSourceDto;
|
||||
import cn.fateverse.code.entity.query.DataSourceQuery;
|
||||
import cn.fateverse.code.entity.vo.DataSourceVo;
|
||||
import cn.fateverse.code.factory.DynamicDataSourceService;
|
||||
import cn.fateverse.code.mapper.DataSourceMapper;
|
||||
import cn.fateverse.code.service.DataSourceService;
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.mybatis.utils.PageUtils;
|
||||
import cn.fateverse.common.redis.annotation.RedisCache;
|
||||
import cn.fateverse.common.redis.enums.RedisCacheType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/16
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DataSourceServiceImpl implements DataSourceService {
|
||||
|
||||
private final TableMapper tableMapper;
|
||||
|
||||
private final DataSourceMapper dataSourceMapper;
|
||||
|
||||
private final DynamicDataSourceService dynamicDataSourceService;
|
||||
|
||||
public DataSourceServiceImpl(TableMapper tableMapper,
|
||||
DataSourceMapper dataSourceMapper,
|
||||
DynamicDataSourceService dynamicDataSourceService) {
|
||||
this.tableMapper = tableMapper;
|
||||
this.dataSourceMapper = dataSourceMapper;
|
||||
this.dynamicDataSourceService = dynamicDataSourceService;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@RedisCache(prefix = "data-source")
|
||||
public TableDataInfo<DataSourceVo> searchList(DataSourceQuery query) {
|
||||
PageUtils.startPage();
|
||||
List<CodeDataSource> list = dataSourceMapper.selectList(query);
|
||||
return PageUtils.convertDataTable(list, DataSourceVo::toDataSourceVo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataSourceVo> searchExport(DataSourceQuery query) {
|
||||
List<CodeDataSource> list = dataSourceMapper.selectList(query);
|
||||
return list.stream().map(DataSourceVo::toDataSourceVo).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@RedisCache(prefix = "data-source", type = RedisCacheType.GET_BY_PRIMARY_KEY, primaryKey = "#{#id}")
|
||||
public CodeDataSource searchById(Long id) {
|
||||
return dataSourceMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@RedisCache(prefix = "data-source")
|
||||
public List<Option> searchOption() {
|
||||
List<CodeDataSource> codeDataSources = dataSourceMapper.selectList(new DataSourceQuery());
|
||||
return codeDataSources.stream().map(dataSource ->
|
||||
Option.builder()
|
||||
.label(dataSource.getDsName())
|
||||
.value(dataSource.getDsId())
|
||||
.build()
|
||||
).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@RedisCache(prefix = "data-source", type = RedisCacheType.INSERT)
|
||||
public void save(DataSourceDto dataSource) {
|
||||
CodeDataSource save = dataSource.toCodeDataSource();
|
||||
checkConnect(save);
|
||||
dataSourceMapper.insert(save);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@RedisCache(prefix = "data-source", type = RedisCacheType.UPDATE, primaryKey = "#{#dataSource.dsId}")
|
||||
public void edit(DataSourceDto dataSource) {
|
||||
CodeDataSource edit = dataSource.toCodeDataSource();
|
||||
if (StrUtil.isBlank(dataSource.getPassword())) {
|
||||
CodeDataSource codeDataSource = dataSourceMapper.selectById(dataSource.getDsId());
|
||||
edit.setPassword(codeDataSource.getPassword());
|
||||
}
|
||||
checkConnect(edit);
|
||||
dataSourceMapper.update(edit);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@RedisCache(prefix = "data-source", type = RedisCacheType.DELETE, primaryKey = "#{#id}")
|
||||
public void removeById(Long id) {
|
||||
Long count = tableMapper.selectCheckTableByDataSourceId(id);
|
||||
if (count == null || count > 0) {
|
||||
throw new CustomException("当前数据源下存在表格信息,不允许删除!");
|
||||
}
|
||||
dataSourceMapper.delete(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查数据源的连接性
|
||||
*
|
||||
* @param dataSource 数据源
|
||||
*/
|
||||
private void checkConnect(CodeDataSource dataSource) {
|
||||
if (!dynamicDataSourceService.checkDataSource(dataSource)) {
|
||||
throw new CustomException("数据源无法连接,请检查配置信息!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package cn.fateverse.code.service.impl;
|
||||
|
||||
import cn.fateverse.code.entity.CodeDataSource;
|
||||
import cn.fateverse.code.entity.DynamicPage;
|
||||
import cn.fateverse.code.entity.Table;
|
||||
import cn.fateverse.code.entity.TableColumn;
|
||||
import cn.fateverse.code.entity.query.DynamicTable;
|
||||
import cn.fateverse.code.entity.dto.TableDto;
|
||||
import cn.fateverse.code.mapper.dynamic.DynamicTableMapper;
|
||||
import cn.fateverse.code.mapper.TableMapper;
|
||||
import cn.fateverse.code.service.DynamicTableMetadataService;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.mybatis.utils.PageUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 动态表格元数据服务实现类
|
||||
*
|
||||
* @author Clay
|
||||
* @date 2022/11/17
|
||||
*/
|
||||
@Service
|
||||
public class DynamicTableMetadataServiceImpl implements DynamicTableMetadataService {
|
||||
|
||||
private final TableMapper tableMapper;
|
||||
|
||||
private DynamicTableMapper dynamicTableMapper;
|
||||
|
||||
private CodeDataSource dataSource;
|
||||
|
||||
public DynamicTableMetadataServiceImpl(TableMapper tableMapper) {
|
||||
this.tableMapper = tableMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo<DynamicTable> searchList(DynamicTable table, Long dataSourceId) {
|
||||
DynamicPage page = dataSource.getType().getDynamicDataSourceFactory().getDynamicPage();
|
||||
List<String> tableNameList = new ArrayList<>(tableMapper.selectTableNameByDataSourceId(dataSourceId));
|
||||
List<DynamicTable> dynamicTables = dynamicTableMapper.selectList(table, page, tableNameList);
|
||||
Long count = dynamicTableMapper.selectListCount(table, tableNameList);
|
||||
return PageUtils.convertDataTable(dynamicTables, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TableDto> searchFullTableByTableNames(List<String> tables, Long dataSourceId) {
|
||||
List<Table> tableList = dynamicTableMapper.selectListByNameList(tables);
|
||||
Map<String, List<TableColumn>> tableColumnListMap = dynamicTableMapper.selectColumnsByNameList(tables).stream().collect(Collectors.groupingBy(TableColumn::getDictType));
|
||||
return tableList.stream().map(table -> {
|
||||
table.setDataSourceId(dataSourceId);
|
||||
List<TableColumn> tableColumns = tableColumnListMap.get(table.getTableName());
|
||||
return dataSource.getType().getDynamicDataSourceFactory().initTable(table, tableColumns);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package cn.fateverse.code.service.impl;
|
||||
|
||||
import cn.fateverse.code.entity.Regular;
|
||||
import cn.fateverse.code.entity.dto.RegularDto;
|
||||
import cn.fateverse.code.entity.vo.RegularVo;
|
||||
import cn.fateverse.code.entity.query.RegularQuery;
|
||||
import cn.fateverse.code.mapper.RegularMapper;
|
||||
import cn.fateverse.code.service.RegularService;
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.security.utils.SecurityUtils;
|
||||
import cn.fateverse.common.mybatis.utils.PageUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 校验规则表 Controller
|
||||
*
|
||||
* @author clay
|
||||
* @date 2023-05-27
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class RegularServiceImpl implements RegularService {
|
||||
|
||||
private final RegularMapper regularMapper;
|
||||
|
||||
public RegularServiceImpl(RegularMapper regularMapper) {
|
||||
this.regularMapper = regularMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegularVo searchById(Long id){
|
||||
Regular regular = regularMapper.selectById(id);
|
||||
return RegularVo.toRegulaVo(regular);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo<RegularVo> searchList(RegularQuery query){
|
||||
PageUtils.startPage();
|
||||
List<Regular> list = regularMapper.selectList(query);
|
||||
return PageUtils.convertDataTable(list, RegularVo::toRegulaVo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Option> searchOptionList() {
|
||||
RegularQuery query = new RegularQuery();
|
||||
query.setEnable(1);
|
||||
List<Regular> list = regularMapper.selectList(query);
|
||||
return list.stream().map(regular->Option.builder()
|
||||
.value(regular.getId())
|
||||
.label(regular.getName())
|
||||
.build()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RegularVo> exportList(RegularQuery query){
|
||||
List<Regular> list = regularMapper.selectList(query);
|
||||
return list.stream().map(RegularVo::toRegulaVo)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
|
||||
public int save(RegularDto regular){
|
||||
Regular info = regular.toRegula();
|
||||
info.setCreateBy(SecurityUtils.getUsername());
|
||||
return regularMapper.insert(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
|
||||
public int edit(RegularDto regular){
|
||||
Regular info = regular.toRegula();
|
||||
info.setUpdateBy(SecurityUtils.getUsername());
|
||||
return regularMapper.update(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
|
||||
public int removeById(Long id){
|
||||
return regularMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
|
||||
public int removeBatch(List<Long> idList){
|
||||
return regularMapper.deleteBatchByIdList(idList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,349 @@
|
||||
package cn.fateverse.code.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.fateverse.code.entity.OptionInfo;
|
||||
import cn.fateverse.code.entity.Table;
|
||||
import cn.fateverse.code.entity.TableColumn;
|
||||
import cn.fateverse.code.entity.bo.TableGenBo;
|
||||
import cn.fateverse.code.entity.dto.ImportDto;
|
||||
import cn.fateverse.code.entity.dto.TableDto;
|
||||
import cn.fateverse.code.entity.query.TableQuery;
|
||||
import cn.fateverse.code.entity.vo.TableVo;
|
||||
import cn.fateverse.code.mapper.TableColumnMapper;
|
||||
import cn.fateverse.code.mapper.TableMapper;
|
||||
import cn.fateverse.code.service.DynamicTableMetadataService;
|
||||
import cn.fateverse.code.service.TableService;
|
||||
import cn.fateverse.code.util.velocity.VelocityInitializer;
|
||||
import cn.fateverse.code.util.velocity.VelocityUtils;
|
||||
import cn.fateverse.common.core.constant.Constants;
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.HttpServletUtils;
|
||||
import cn.fateverse.common.mybatis.utils.PageUtils;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/17
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class TableServiceImpl implements TableService {
|
||||
|
||||
private final TableMapper tableMapper;
|
||||
|
||||
private final DynamicTableMetadataService dynamicTableMetadataService;
|
||||
|
||||
private final TableColumnMapper tableColumnMapper;
|
||||
|
||||
public TableServiceImpl(TableMapper tableMapper,
|
||||
TableColumnMapper tableColumnMapper,
|
||||
DynamicTableMetadataService dynamicTableMetadataService) {
|
||||
this.tableMapper = tableMapper;
|
||||
this.tableColumnMapper = tableColumnMapper;
|
||||
this.dynamicTableMetadataService = dynamicTableMetadataService;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TableDataInfo<TableVo> searchList(TableQuery query) {
|
||||
PageUtils.startPage();
|
||||
List<Table> tableList = tableMapper.selectTableList(query);
|
||||
return PageUtils.convertDataTable(tableList, Table::toTableVo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TableVo> searchExport(TableQuery query) {
|
||||
List<Table> tableList = tableMapper.selectTableList(query);
|
||||
return tableList.stream().map(Table::toTableVo).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDto searchByTableId(Long tableId) {
|
||||
return tableMapper.selectTableDtoByTableId(tableId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Option> searchOptionByDataSourceId(Long dataSourceId) {
|
||||
TableQuery query = new TableQuery();
|
||||
query.setDataSourceId(dataSourceId);
|
||||
List<Table> tableList = tableMapper.selectTableList(query);
|
||||
return tableList.stream().map(table ->
|
||||
Option.builder()
|
||||
.value(table.getTableId())
|
||||
.label(table.getTableName() + ":" + table.getTableComment())
|
||||
.build()
|
||||
).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> previewCode(Long tableId) {
|
||||
Map<String, String> dataMap = new LinkedHashMap<>();
|
||||
TableGenBo table = getTableGenBo(tableId, "代码预览失败!");
|
||||
VelocityInitializer.initVelocity();
|
||||
VelocityContext context = VelocityUtils.prepareContext(table);
|
||||
List<String> templateList = VelocityUtils.getTemplateList(table);
|
||||
for (String template : templateList) {
|
||||
StringWriter sw = new StringWriter();
|
||||
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
||||
tpl.merge(context, sw);
|
||||
dataMap.put(VelocityUtils.getPreviewName(template, table.getClassName()), sw.toString());
|
||||
}
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadCode(Long tableId) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||
generatorCode(tableId, zip);
|
||||
IOUtils.closeQuietly(zip);
|
||||
downloadZip(outputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadCodeList(List<Long> tableIds) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||
for (Long tableId : tableIds) {
|
||||
generatorCode(tableId, zip);
|
||||
}
|
||||
IOUtils.closeQuietly(zip);
|
||||
downloadZip(outputStream);
|
||||
}
|
||||
|
||||
private void generatorCode(Long tableId, ZipOutputStream zip) {
|
||||
TableGenBo table = getTableGenBo(tableId, "代码生成失败");
|
||||
VelocityInitializer.initVelocity();
|
||||
VelocityContext context = VelocityUtils.prepareContext(table);
|
||||
List<String> templateList = VelocityUtils.getTemplateList(table);
|
||||
for (String template : templateList) {
|
||||
StringWriter sw = new StringWriter();
|
||||
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
||||
tpl.merge(context, sw);
|
||||
try {
|
||||
zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table)));
|
||||
IOUtils.write(sw.toString(), zip, Constants.UTF8);
|
||||
sw.close();
|
||||
zip.flush();
|
||||
zip.closeEntry();
|
||||
} catch (IOException e) {
|
||||
log.error("渲染模板失败,表名:" + table.getTableName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取到代码生成需要的业务数据
|
||||
*
|
||||
* @param tableId 表格id
|
||||
* @param msg 错误信息
|
||||
* @return 业务数据
|
||||
*/
|
||||
private TableGenBo getTableGenBo(Long tableId, String msg) {
|
||||
TableDto tableDto = tableMapper.selectTableDtoByTableId(tableId);
|
||||
if (null == tableDto) {
|
||||
throw new CustomException(msg);
|
||||
}
|
||||
if (StrUtil.isEmpty(tableDto.getServiceName())) {
|
||||
tableDto.setServiceName("demo");
|
||||
}
|
||||
TableGenBo table = new TableGenBo();
|
||||
BeanUtils.copyProperties(tableDto, table);
|
||||
table.setOptionInfo(JSONObject.parseObject(table.getOptionApi(), OptionInfo.class));
|
||||
setPKColumn(table);
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置主键列信息
|
||||
*
|
||||
* @param table 业务表信息
|
||||
*/
|
||||
public void setPKColumn(TableGenBo table) {
|
||||
for (TableColumn column : table.getColumns()) {
|
||||
if (column.isPk()) {
|
||||
table.setPkColumn(column);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result<Void> importTable(ImportDto dto) {
|
||||
List<String> tables = dto.getTables();
|
||||
Long dataSourceId = dto.getDataSourceId();
|
||||
Set<String> tableNameSet = tableMapper.selectTableNameByDataSourceId(dataSourceId);
|
||||
List<String> tableList = new ArrayList<>();
|
||||
List<String> exist = new ArrayList<>();
|
||||
for (String table : tables) {
|
||||
if (!tableNameSet.contains(table)) {
|
||||
tableList.add(table);
|
||||
} else {
|
||||
exist.add(table);
|
||||
}
|
||||
}
|
||||
if (tableList.isEmpty()) {
|
||||
return Result.error("需要新增的表在数据库中已存在!");
|
||||
}
|
||||
List<TableDto> tableDtoList = dynamicTableMetadataService.searchFullTableByTableNames(tables, dataSourceId);
|
||||
if (tableDtoList.isEmpty()) {
|
||||
return Result.error("当前表信息在数据库中已经不存在!");
|
||||
}
|
||||
OptionInfo defaultOption = OptionInfo.getDefaultInstance();
|
||||
String optionApi = JSON.toJSONString(defaultOption);
|
||||
Date now = new Date();
|
||||
tableDtoList.forEach(table -> {
|
||||
table.setOptionApi(optionApi);
|
||||
table.setCreateTime(now);
|
||||
tableMapper.insertTable(table);
|
||||
List<TableColumn> columns = table.getColumns();
|
||||
columns.forEach(column -> {
|
||||
column.setTableId(table.getTableId());
|
||||
column.setCreateTime(now);
|
||||
// tableColumnMapper.insert(column);
|
||||
});
|
||||
tableColumnMapper.batchInsert(columns);
|
||||
});
|
||||
if (!exist.isEmpty()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
exist.forEach(str -> sb.append(str).append(","));
|
||||
return Result.ok(1001, "表:" + sb + "在数据库中已存在!", null);
|
||||
}
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result<Void> edit(TableDto table) {
|
||||
table.setOptionApi(JSON.toJSONString(table.getOptionInfo()));
|
||||
tableMapper.updateTable(table);
|
||||
List<TableColumn> columns = table.getColumns();
|
||||
tableColumnMapper.batchUpdate(columns);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void syncTable(Long tableId) {
|
||||
TableDto tableDto = tableMapper.selectTableDtoByTableId(tableId);
|
||||
if (null == tableDto) {
|
||||
throw new CustomException("操作失败!");
|
||||
}
|
||||
List<TableDto> tableDtos = dynamicTableMetadataService.searchFullTableByTableNames(Collections.singletonList(tableDto.getTableName()), tableDto.getDataSourceId());
|
||||
if (null == tableDtos || tableDtos.size() != 1) {
|
||||
throw new CustomException("同步数据失败,原表结构不存在");
|
||||
}
|
||||
List<TableColumn> dataBaseColumns = tableDto.getColumns();
|
||||
if (dataBaseColumns == null || dataBaseColumns.isEmpty()) {
|
||||
throw new CustomException("列信息查询为空!");
|
||||
}
|
||||
TableDto table = tableDtos.get(0);
|
||||
if (ObjectUtils.isEmpty(tableDto.getTableComment())) {
|
||||
tableDto.setTableComment(table.getTableComment());
|
||||
tableMapper.updateTable(tableDto);
|
||||
}
|
||||
List<TableColumn> sourceColumn = table.getColumns();
|
||||
if (sourceColumn == null || sourceColumn.isEmpty()) {
|
||||
tableColumnMapper.deleteByTableId(tableId);
|
||||
return;
|
||||
}
|
||||
Map<String, TableColumn> dataBaseColumnMap = dataBaseColumns.stream().collect(Collectors.toMap(TableColumn::getColumnName, Function.identity()));
|
||||
Map<String, TableColumn> sourceColumnMap = sourceColumn.stream().collect(Collectors.toMap(TableColumn::getColumnName, Function.identity()));
|
||||
Set<String> dataBaseSet = dataBaseColumnMap.keySet();
|
||||
List<TableColumn> updateList = new ArrayList<>();
|
||||
List<TableColumn> insertList = new ArrayList<>();
|
||||
List<Long> removeIds = new ArrayList<>();
|
||||
sourceColumnMap.forEach((key, sourceColumnColumn) -> {
|
||||
if (dataBaseColumnMap.containsKey(key)) {
|
||||
TableColumn dataBaseColumn = dataBaseColumnMap.get(key);
|
||||
boolean flag = false;
|
||||
if (!dataBaseColumn.getColumnType().equals(sourceColumnColumn.getColumnType())) {
|
||||
dataBaseColumn.setColumnType(sourceColumnColumn.getColumnType());
|
||||
flag = true;
|
||||
}
|
||||
if (ObjectUtils.isEmpty(dataBaseColumn.getColumnComment()) && !ObjectUtils.isEmpty(sourceColumnColumn.getColumnComment())) {
|
||||
dataBaseColumn.setColumnComment(sourceColumnColumn.getColumnComment());
|
||||
flag = true;
|
||||
}
|
||||
if (flag) {
|
||||
updateList.add(dataBaseColumn);
|
||||
}
|
||||
dataBaseSet.remove(key);
|
||||
} else {
|
||||
sourceColumnColumn.setTableId(tableId);
|
||||
insertList.add(sourceColumnColumn);
|
||||
}
|
||||
});
|
||||
if (!dataBaseSet.isEmpty()) {
|
||||
dataBaseSet.forEach(key -> removeIds.add(dataBaseColumnMap.get(key).getColumnId()));
|
||||
}
|
||||
if (!updateList.isEmpty()) {
|
||||
tableColumnMapper.batchUpdate(updateList);
|
||||
}
|
||||
if (!insertList.isEmpty()) {
|
||||
tableColumnMapper.batchInsert(insertList);
|
||||
}
|
||||
if (!removeIds.isEmpty()) {
|
||||
tableColumnMapper.batchRemove(removeIds);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void remove(Long tableId) {
|
||||
tableMapper.deleteTableById(tableId);
|
||||
tableColumnMapper.deleteByTableId(tableId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeBatch(List<Long> tableIds) {
|
||||
tableMapper.deleteTableByIds(tableIds);
|
||||
tableColumnMapper.deleteByTableIds(tableIds);
|
||||
}
|
||||
|
||||
|
||||
private void downloadZip(ByteArrayOutputStream outputStream) {
|
||||
HttpServletResponse response = HttpServletUtils.getResponse();
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment;fileName=ebts-code.zip");
|
||||
try {
|
||||
IOUtils.write(outputStream.toByteArray(), response.getOutputStream());
|
||||
} catch (IOException e) {
|
||||
log.error("代码生成失败", e);
|
||||
throw new CustomException("word导出失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
package cn.fateverse.code.util.constant;
|
||||
|
||||
/**
|
||||
* 代码生成通用常量
|
||||
*
|
||||
* @author binlin
|
||||
*/
|
||||
public class CodeGenConstants {
|
||||
|
||||
/**
|
||||
* 单表(增删改查)
|
||||
*/
|
||||
public static final String TPL_CRUD = "crud";
|
||||
|
||||
/**
|
||||
* 树表(增删改查)
|
||||
*/
|
||||
public static final String TPL_TREE = "tree";
|
||||
|
||||
/**
|
||||
* 主子表(增删改查)
|
||||
*/
|
||||
public static final String TPL_SUB = "sub";
|
||||
|
||||
/**
|
||||
* 关联查询(增删改查)
|
||||
*/
|
||||
public static final String TPL_ASS = "ass";
|
||||
|
||||
/**
|
||||
* 多表关联查询(增删改查)
|
||||
*/
|
||||
public static final String TPL_REL = "rel";
|
||||
|
||||
/**
|
||||
* 树编码字段
|
||||
*/
|
||||
public static final String TREE_CODE = "treeCode";
|
||||
|
||||
/**
|
||||
* 树父编码字段
|
||||
*/
|
||||
public static final String TREE_PARENT_CODE = "treeParentCode";
|
||||
|
||||
/**
|
||||
* 树名称字段
|
||||
*/
|
||||
public static final String TREE_NAME = "treeName";
|
||||
|
||||
/**
|
||||
* 上级菜单ID字段
|
||||
*/
|
||||
public static final String PARENT_MENU_ID = "parentMenuId";
|
||||
|
||||
/**
|
||||
* 上级菜单名称字段
|
||||
*/
|
||||
public static final String PARENT_MENU_NAME = "parentMenuName";
|
||||
|
||||
/**
|
||||
* 页面不需要编辑新增字段
|
||||
*/
|
||||
public static final String[] COLUMN_NAME_NOT_EDIT_INSERT = {"id", "create_by", "create_time", "del_flag", "update_by",
|
||||
"update_time"};
|
||||
|
||||
/**
|
||||
* 页面不需要显示的列表字段
|
||||
*/
|
||||
public static final String[] COLUMN_NAME_NOT_LIST = {"id", "create_by", "create_time", "del_flag", "update_by",
|
||||
"update_time"};
|
||||
|
||||
/**
|
||||
* 页面不需要查询字段
|
||||
*/
|
||||
public static final String[] COLUMN_NAME_NOT_QUERY = {"id", "create_by", "create_time", "del_flag", "update_by",
|
||||
"update_time", "remark"};
|
||||
|
||||
/**
|
||||
* Entity基类字段
|
||||
*/
|
||||
public static final String[] BASE_ENTITY = {"createBy", "createTime", "updateBy", "updateTime", "remark"};
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
public static final String CREATE_BY_FIELD = "createBy";
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
public static final String CREATE_TIME_FIELD = "createTime";
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
public static final String UPDATE_BY_FIELD = "updateBy";
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
public static final String UPDATE_TIME_FIELD = "updateTime";
|
||||
|
||||
/**
|
||||
* Tree基类字段
|
||||
*/
|
||||
public static final String[] TREE_ENTITY = {"parentName", "parentId", "orderNum", "ancestors", "children"};
|
||||
|
||||
/**
|
||||
* 文本框
|
||||
*/
|
||||
public static final String HTML_INPUT = "input";
|
||||
|
||||
/**
|
||||
* 文本域
|
||||
*/
|
||||
public static final String HTML_TEXTAREA = "textarea";
|
||||
|
||||
/**
|
||||
* 下拉框
|
||||
*/
|
||||
public static final String HTML_SELECT = "select";
|
||||
|
||||
/**
|
||||
* 单选框
|
||||
*/
|
||||
public static final String HTML_RADIO = "radio";
|
||||
|
||||
/**
|
||||
* 复选框
|
||||
*/
|
||||
public static final String HTML_CHECKBOX = "checkbox";
|
||||
|
||||
/**
|
||||
* 日期控件
|
||||
*/
|
||||
public static final String HTML_DATETIME = "datetime";
|
||||
|
||||
/**
|
||||
* 图片上传控件
|
||||
*/
|
||||
public static final String HTML_IMAGE_UPLOAD = "imageUpload";
|
||||
|
||||
/**
|
||||
* 文件上传控件
|
||||
*/
|
||||
public static final String HTML_FILE_UPLOAD = "fileUpload";
|
||||
|
||||
/**
|
||||
* 富文本控件
|
||||
*/
|
||||
public static final String HTML_EDITOR = "editor";
|
||||
|
||||
/**
|
||||
* 字符串类型
|
||||
*/
|
||||
public static final String TYPE_STRING = "String";
|
||||
|
||||
/**
|
||||
* 整型
|
||||
*/
|
||||
public static final String TYPE_INTEGER = "Integer";
|
||||
|
||||
/**
|
||||
* 长整型
|
||||
*/
|
||||
public static final String TYPE_LONG = "Long";
|
||||
|
||||
/**
|
||||
* 浮点型
|
||||
*/
|
||||
public static final String TYPE_DOUBLE = "Double";
|
||||
|
||||
/**
|
||||
* 高精度计算类型
|
||||
*/
|
||||
public static final String TYPE_BIG_DECIMAL = "BigDecimal";
|
||||
|
||||
/**
|
||||
* 时间类型
|
||||
*/
|
||||
public static final String TYPE_DATE = "Date";
|
||||
|
||||
/**
|
||||
* 模糊查询
|
||||
*/
|
||||
public static final String QUERY_LIKE = "LIKE";
|
||||
|
||||
/**
|
||||
* 精确查询
|
||||
*/
|
||||
public static final String QUERY_EQ = "EQ";
|
||||
|
||||
/**
|
||||
* 需要
|
||||
*/
|
||||
public static final String REQUIRE = "1";
|
||||
|
||||
/**
|
||||
* 不需要
|
||||
*/
|
||||
public static final String NO_REQUIRE = "0";
|
||||
|
||||
/**
|
||||
* 不需要 int类型
|
||||
*/
|
||||
public static final Integer NO_REQUIRE_INTEGER = 0;
|
||||
|
||||
/**
|
||||
* 自定义路径
|
||||
*/
|
||||
public static final String CUSTOM_PATHS = "1";
|
||||
|
||||
/**
|
||||
* zip压缩包
|
||||
*/
|
||||
public static final String ZIP_COMPRESSED_PACKAGE = "0";
|
||||
|
||||
/**
|
||||
* 前缀 name
|
||||
*/
|
||||
public static final String NAME_SUFFIX = "name";
|
||||
/**
|
||||
* 前缀 state
|
||||
*/
|
||||
public static final String STATE_SUFFIX = "state";
|
||||
/**
|
||||
* 前缀 type
|
||||
*/
|
||||
public static final String TYPE_SUFFIX = "type";
|
||||
/**
|
||||
* 前缀 sex
|
||||
*/
|
||||
public static final String SEX_SUFFIX = "sex";
|
||||
/**
|
||||
* 前缀 image
|
||||
*/
|
||||
public static final String IMAGE_SUFFIX = "image";
|
||||
/**
|
||||
* 前缀 file
|
||||
*/
|
||||
public static final String FILE_SUFFIX = "file";
|
||||
/**
|
||||
* 前缀 content
|
||||
*/
|
||||
public static final String CONTENT_SUFFIX = "content";
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.fateverse.code.util.velocity;
|
||||
|
||||
import cn.fateverse.common.core.constant.Constants;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
import org.apache.velocity.runtime.RuntimeConstants;
|
||||
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Velocity初始化
|
||||
*
|
||||
* @author Clay
|
||||
* @date 2022/11/18
|
||||
*/
|
||||
public class VelocityInitializer {
|
||||
/**
|
||||
* 初始化Velocity
|
||||
*/
|
||||
public static void initVelocity(){
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
|
||||
properties.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
|
||||
properties.setProperty(Velocity.ENCODING_DEFAULT, Constants.UTF8);
|
||||
properties.setProperty(Velocity.OUTPUT_ENCODING, Constants.UTF8);
|
||||
Velocity.init(properties);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
package cn.fateverse.code.util.velocity;
|
||||
|
||||
import cn.fateverse.code.entity.TableColumn;
|
||||
import cn.fateverse.code.entity.bo.TableGenBo;
|
||||
import cn.fateverse.code.enums.BackTemplateEnum;
|
||||
import cn.fateverse.code.enums.DynamicSourceEnum;
|
||||
import cn.fateverse.code.enums.FrontTemplateEnum;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.fateverse.common.core.constant.DateConstants;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 模板构建工具类
|
||||
*
|
||||
* @author Clay
|
||||
* @date 2022/11/18
|
||||
*/
|
||||
public class VelocityUtils {
|
||||
|
||||
/**
|
||||
* 项目空间路径
|
||||
*/
|
||||
private static final String PROJECT_PATH = "main/java";
|
||||
|
||||
/**
|
||||
* mybatis空间路径
|
||||
*/
|
||||
private static final String MYBATIS_PATH = "main/resources/mapper";
|
||||
|
||||
/**
|
||||
* 准备环境
|
||||
*
|
||||
* @param table
|
||||
* @return
|
||||
*/
|
||||
public static VelocityContext prepareContext(TableGenBo table) {
|
||||
if (DynamicSourceEnum.ORACLE.equals(table.getDataSourceType())) {
|
||||
initOracleVelocityContext(table);
|
||||
}
|
||||
|
||||
String tableName = table.getTableName();
|
||||
String moduleName = table.getModuleName();
|
||||
String businessName = table.getBusinessName();
|
||||
String packageName = table.getPackageName();
|
||||
String tplCategory = table.getTplCategory();
|
||||
String functionName = table.getFunctionName();
|
||||
String serviceName = table.getServiceName();
|
||||
|
||||
VelocityContext velocityContext = new VelocityContext();
|
||||
velocityContext.put("tableName", tableName);
|
||||
velocityContext.put("serviceName", serviceName);
|
||||
velocityContext.put("moduleName", moduleName);
|
||||
velocityContext.put("businessName", businessName);
|
||||
velocityContext.put("packageName", packageName);
|
||||
velocityContext.put("tplCategory", tplCategory);
|
||||
velocityContext.put("functionName", functionName);
|
||||
velocityContext.put("pkColumn", table.getPkColumn());
|
||||
velocityContext.put("dateTime", DateUtil.format(new Date(), DateConstants.YYYY_MM_DD));
|
||||
velocityContext.put("ClassName", table.getClassName());
|
||||
velocityContext.put("className", StringUtils.uncapitalize(table.getClassName()));
|
||||
velocityContext.put("author", table.getFunctionAuthor());
|
||||
velocityContext.put("permissionPrefix", StrFormatter.format("{}:{}", moduleName, businessName));
|
||||
velocityContext.put("table", table);
|
||||
velocityContext.put("columns", table.getColumns());
|
||||
return velocityContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化oracle相关的数据类型
|
||||
*
|
||||
* @param table
|
||||
*/
|
||||
private static void initOracleVelocityContext(TableGenBo table) {
|
||||
table.setTableName(table.getTableName().toLowerCase());
|
||||
List<TableColumn> columns = table.getColumns();
|
||||
columns = columns.stream().peek(column -> column.setColumnName(column.getColumnName().toLowerCase())).collect(Collectors.toList());
|
||||
table.setColumns(columns);
|
||||
}
|
||||
|
||||
|
||||
public static List<String> getTemplateList(TableGenBo table) {
|
||||
List<String> templateList = new ArrayList<>();
|
||||
templateList.add("vm/java/entity.java.vm");
|
||||
templateList.add("vm/java/entityDto.java.vm");
|
||||
templateList.add("vm/java/entityQuery.java.vm");
|
||||
templateList.add("vm/java/entityVo.java.vm");
|
||||
templateList.add("vm/java/controller.java.vm");
|
||||
templateList.add("vm/java/service.java.vm");
|
||||
if (BackTemplateEnum.MYBATIS.equals(table.getBackTemplate())) {
|
||||
templateList.add("vm/java/mybatis/serviceImpl.java.vm");
|
||||
templateList.add("vm/java/mybatis/mapper.java.vm");
|
||||
templateList.add(table.getDataSourceType().getDynamicDataSourceFactory().getMapperTemplate());
|
||||
} else {
|
||||
templateList.add("vm/java/mybatisplus/serviceImpl.java.vm");
|
||||
templateList.add("vm/java/mybatisplus/mapper.java.vm");
|
||||
}
|
||||
if (FrontTemplateEnum.VUE.equals(table.getFrontTemplate())) {
|
||||
templateList.add("vm/vue/index.vue.vm");
|
||||
templateList.add("vm/vue/api.js.vm");
|
||||
} else {
|
||||
templateList.add("vm/react/type.ts.vm");
|
||||
templateList.add("vm/react/api.ts.vm");
|
||||
templateList.add("vm/react/view.tsx.vm");
|
||||
}
|
||||
return templateList;
|
||||
}
|
||||
|
||||
|
||||
public static String getFileName(String template, TableGenBo table) {
|
||||
String className = table.getClassName();
|
||||
String packageName = table.getPackageName();
|
||||
String moduleName = table.getModuleName();
|
||||
String businessName = table.getBusinessName();
|
||||
String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/");
|
||||
String mybatisPath = MYBATIS_PATH + "/" + table.getModuleName();
|
||||
String frontPath = table.getFrontTemplate().equals("0") ? "vue" : "react";
|
||||
String fileName = "";
|
||||
|
||||
if (template.contains("entity.java.vm")) {
|
||||
fileName = StrFormatter.format("{}/entity/{}.java", javaPath, className);
|
||||
} else if (template.contains("entityDto.java.vm")) {
|
||||
fileName = StrFormatter.format("{}/entity/dto/{}Dto.java", javaPath, className);
|
||||
} else if (template.contains("entityQuery.java.vm")) {
|
||||
fileName = StrFormatter.format("{}/entity/query/{}Query.java", javaPath, className);
|
||||
} else if (template.contains("entityVo.java.vm")) {
|
||||
fileName = StrFormatter.format("{}/entity/vo/{}Vo.java", javaPath, className);
|
||||
} else if (template.contains("rel-entity.java.vm")) {
|
||||
fileName = StrFormatter.format("{}/entity/{}.java", javaPath, className);
|
||||
} else if (template.contains("mapper.java.vm")) {
|
||||
fileName = StrFormatter.format("{}/mapper/{}Mapper.java", javaPath, className);
|
||||
} else if (template.contains("service.java.vm")) {
|
||||
fileName = StrFormatter.format("{}/service/{}Service.java", javaPath, className);
|
||||
} else if (template.contains("serviceImpl.java.vm")) {
|
||||
fileName = StrFormatter.format("{}/service/impl/{}ServiceImpl.java", javaPath, className);
|
||||
} else if (template.contains("controller.java.vm")) {
|
||||
fileName = StrFormatter.format("{}/controller/{}Controller.java", javaPath, className);
|
||||
} else if (template.contains("mapperMySql.xml.vm") || template.contains("mapperOracle.xml.vm")) {
|
||||
fileName = StrFormatter.format("{}/{}Mapper.xml", mybatisPath, className);
|
||||
} else if (template.contains("table.sql.vm")) {
|
||||
fileName = className + "menu.sql";
|
||||
} else if (template.contains("api.js.vm")) {
|
||||
fileName = StrFormatter.format("{}/api/{}/{}.js", frontPath, moduleName, businessName);
|
||||
} else if (template.contains("index.vue.vm")) {
|
||||
fileName = StrFormatter.format("{}/views/{}/{}/index.vue", frontPath, moduleName, businessName);
|
||||
} else if (template.contains("index-tree.vue.vm")) {
|
||||
fileName = StrFormatter.format("{}/views/{}/{}/index.vue", frontPath, moduleName, businessName);
|
||||
} else if (template.contains("type.ts.vm")) {
|
||||
fileName = StrFormatter.format("{}/type/{}/{}/indexType.ts", frontPath, moduleName, businessName);
|
||||
} else if (template.contains("api.ts.vm")) {
|
||||
fileName = StrFormatter.format("{}/api/{}/{}.ts", frontPath, moduleName, businessName);
|
||||
} else if (template.contains("view.tsx.vm")) {
|
||||
fileName = StrFormatter.format("{}/views/{}/{}/index.tsx", frontPath, moduleName, businessName);
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public static String getPreviewName(String template, String className) {
|
||||
String fileName = "";
|
||||
if (template.contains("entity.java.vm")) {
|
||||
fileName = StrFormatter.format("{}.java", className);
|
||||
} else if (template.contains("entityDto.java.vm")) {
|
||||
fileName = StrFormatter.format("{}Dto.java", className);
|
||||
} else if (template.contains("entityQuery.java.vm")) {
|
||||
fileName = StrFormatter.format("{}Query.java", className);
|
||||
} else if (template.contains("entityVo.java.vm")) {
|
||||
fileName = StrFormatter.format("{}Vo.java", className);
|
||||
} else
|
||||
//if (template.contains("sub-entity.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, className)) {
|
||||
// fileName = StrFormatter.format("{}.java", className);
|
||||
//} else
|
||||
if (template.contains("rel-entity.java.vm")) {
|
||||
fileName = StrFormatter.format("{}.java", className);
|
||||
} else if (template.contains("mapper.java.vm")) {
|
||||
fileName = StrFormatter.format("{}Mapper.java", className);
|
||||
} else if (template.contains("service.java.vm")) {
|
||||
fileName = StrFormatter.format("{}Service.java", className);
|
||||
} else if (template.contains("serviceImpl.java.vm")) {
|
||||
fileName = StrFormatter.format("{}ServiceImpl.java", className);
|
||||
} else if (template.contains("controller.java.vm")) {
|
||||
fileName = StrFormatter.format("{}Controller.java", className);
|
||||
} else if (template.contains("mapperMySql.xml.vm") || template.contains("mapperOracle.xml.vm")) {
|
||||
fileName = StrFormatter.format("{}Mapper.xml", className);
|
||||
} else if (template.contains("table.sql.vm")) {
|
||||
fileName = className + "menu.sql";
|
||||
} else if (template.contains("api.js.vm")) {
|
||||
fileName = StrFormatter.format("{}.js", StrUtil.lowerFirst(className));
|
||||
} else if (template.contains("index.vue.vm")) {
|
||||
fileName = "index.vue";
|
||||
} else if (template.contains("index-tree.vue.vm")) {
|
||||
fileName = "index.vue";
|
||||
} else if (template.contains("type.ts.vm")) {
|
||||
fileName = "indexType.ts";
|
||||
} else if (template.contains("api.ts.vm")) {
|
||||
fileName = "indexApi.ts";
|
||||
} else if (template.contains("view.tsx.vm")) {
|
||||
fileName = "view.tsx";
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
}
|
||||
12
visual/code-gen/src/main/resources/bootstrap-dev.yml
Normal file
12
visual/code-gen/src/main/resources/bootstrap-dev.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
# Spring
|
||||
spring:
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 10.7.127.189:38848
|
||||
namespace: clay
|
||||
dubbo:
|
||||
registry:
|
||||
parameters:
|
||||
namespace: dubbo-clay
|
||||
7
visual/code-gen/src/main/resources/bootstrap-pro.yml
Normal file
7
visual/code-gen/src/main/resources/bootstrap-pro.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
# Spring
|
||||
spring:
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: nacos.fateverse.svc.cluster.local:8848
|
||||
42
visual/code-gen/src/main/resources/bootstrap.yml
Normal file
42
visual/code-gen/src/main/resources/bootstrap.yml
Normal file
@@ -0,0 +1,42 @@
|
||||
# Tomcat
|
||||
server:
|
||||
port: 15078
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
# 应用名称
|
||||
name: code-gen
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 192.168.101.108:8848
|
||||
username: nacos
|
||||
password: nacos
|
||||
namespace: ${spring.profiles.active}
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: ${spring.cloud.nacos.discovery.server-addr}
|
||||
file-extension: yaml
|
||||
namespace: ${spring.profiles.active}
|
||||
shared-configs:
|
||||
- data-id: application-${spring.profiles.active}.yaml
|
||||
refresh: true
|
||||
|
||||
|
||||
dubbo:
|
||||
application:
|
||||
name: dubbo-${spring.application.name}
|
||||
protocol:
|
||||
name: dubbo
|
||||
port: -1
|
||||
registry:
|
||||
address: nacos://${spring.cloud.nacos.discovery.server-addr}
|
||||
username: ${spring.cloud.nacos.discovery.username}
|
||||
password: ${spring.cloud.nacos.discovery.password}
|
||||
parameters:
|
||||
namespace: dubbo-${spring.profiles.active}
|
||||
103
visual/code-gen/src/main/resources/mapper/DataSourceMapper.xml
Normal file
103
visual/code-gen/src/main/resources/mapper/DataSourceMapper.xml
Normal file
@@ -0,0 +1,103 @@
|
||||
<?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="cn.fateverse.code.mapper.DataSourceMapper">
|
||||
|
||||
<sql id="DataSource">
|
||||
select ds_id,
|
||||
ds_name,
|
||||
username,
|
||||
password,
|
||||
host,
|
||||
port,
|
||||
type,
|
||||
args,
|
||||
params,
|
||||
db_name,
|
||||
jdbc_url,
|
||||
conf_type,
|
||||
remark,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
update_time
|
||||
from gen_data_source
|
||||
</sql>
|
||||
|
||||
<select id="selectList" resultType="cn.fateverse.code.entity.CodeDataSource">
|
||||
<include refid="DataSource"/>
|
||||
<where>
|
||||
<if test="dsName != null and dsName != ''">and ds_name like concat('%',#{dsName},'%')</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectById" resultType="cn.fateverse.code.entity.CodeDataSource">
|
||||
<include refid="DataSource"/>
|
||||
where ds_id = #{dsId}
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="insert">
|
||||
insert into gen_data_source
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="dsName != null and dsName != ''">ds_name,</if>
|
||||
<if test="username != null and username != ''">username,</if>
|
||||
<if test="password != null and password != ''">`password`,</if>
|
||||
<if test="host != null and host != ''">`host`,</if>
|
||||
<if test="port != null and port != ''">`port`,</if>
|
||||
<if test="type != null ">type,</if>
|
||||
<if test="args != null and args != ''">args,</if>
|
||||
<if test="params != null and params != ''">params,</if>
|
||||
<if test="dbName != null and dbName != ''">db_name,</if>
|
||||
<if test="jdbcUrl != null and jdbcUrl != ''">jdbc_url,</if>
|
||||
<if test="confType != null and confType != ''">conf_type,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="dsName != null and dsName != ''">#{dsName},</if>
|
||||
<if test="username != null and username != ''">#{username},</if>
|
||||
<if test="password != null and password != ''">#{password},</if>
|
||||
<if test="host != null and host != ''">#{host},</if>
|
||||
<if test="port != null and port != ''">#{port},</if>
|
||||
<if test="type != null ">#{type},</if>
|
||||
<if test="args != null and args != ''">#{args},</if>
|
||||
<if test="params != null and params != ''">#{params},</if>
|
||||
<if test="dbName != null and dbName != ''">#{dbName},</if>
|
||||
<if test="jdbcUrl != null and jdbcUrl != ''">#{jdbcUrl},</if>
|
||||
<if test="confType != null and confType != ''">#{confType},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update gen_data_source
|
||||
<set>
|
||||
<if test="dsName != null and dsName != ''">ds_name = #{dsName},</if>
|
||||
<if test="username != null and username != ''">username = #{username},</if>
|
||||
<if test="password != null and password != ''">`password` = #{password},</if>
|
||||
<if test="host != null and host != ''">`host` = #{host},</if>
|
||||
<if test="port != null and port != ''">`port`=#{port},</if>
|
||||
<if test="type != null ">type=#{type},</if>
|
||||
<if test="args != null and args != ''">args=#{args},</if>
|
||||
<if test="params != null and params != ''">params=#{params},</if>
|
||||
<if test="dbName != null and dbName != ''">db_name=#{dbName},</if>
|
||||
<if test="jdbcUrl != null and jdbcUrl != ''">jdbc_url = #{jdbcUrl},</if>
|
||||
<if test="confType != null and confType != ''">conf_type= #{confType},</if>
|
||||
<if test="updateBy != null and updateBy != ''">update_by=#{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
</set>
|
||||
where ds_id = #{dsId}
|
||||
</update>
|
||||
|
||||
<delete id="delete">
|
||||
delete
|
||||
from gen_data_source
|
||||
where ds_id = #{id}
|
||||
</delete>
|
||||
|
||||
|
||||
</mapper>
|
||||
83
visual/code-gen/src/main/resources/mapper/RegularMapper.xml
Normal file
83
visual/code-gen/src/main/resources/mapper/RegularMapper.xml
Normal file
@@ -0,0 +1,83 @@
|
||||
<?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="cn.fateverse.code.mapper.RegularMapper">
|
||||
|
||||
<resultMap id="RegulaResult" type="cn.fateverse.code.entity.Regular">
|
||||
<id column="id" property="id"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="regular" property="regular"/>
|
||||
<result column="validation" property="validation"/>
|
||||
<result column="enable" property="enable"/>
|
||||
<result column="create_by" property="createBy"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_by" property="updateBy"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectRegulaVo">
|
||||
select id, name, regular, validation, enable, create_by, create_time, update_by, update_time from gen_regular
|
||||
</sql>
|
||||
|
||||
<select id="selectList" resultMap="RegulaResult">
|
||||
<include refid="selectRegulaVo"/>
|
||||
<where>
|
||||
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
|
||||
<if test="regular != null and regular != ''"> and regular like concat('%', #{regular}, '%')</if>
|
||||
<if test="enable != null "> and enable = #{enable}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectById" resultMap="RegulaResult">
|
||||
<include refid="selectRegulaVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insert" >
|
||||
insert into gen_regular
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="name != null">name,</if>
|
||||
<if test="regular != null">regular,</if>
|
||||
<if test="validation != null">validation,</if>
|
||||
<if test="enable != null">enable,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
<if test="createTime != null ">create_time,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="name != null">#{name},</if>
|
||||
<if test="regular != null">#{regular},</if>
|
||||
<if test="validation != null">#{validation},</if>
|
||||
<if test="enable != null">#{enable},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
<if test="createTime != null ">#{createTime},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update gen_regular
|
||||
<set>
|
||||
<if test="name != null">name = #{name},</if>
|
||||
<if test="regular != null">regular = #{regular},</if>
|
||||
<if test="validation != null">validation = #{validation},</if>
|
||||
<if test="enable != null">enable = #{enable},</if>
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null ">update_time = #{updateTime},</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteById">
|
||||
delete from gen_regular
|
||||
where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteBatchByIdList" parameterType="Long">
|
||||
delete from gen_regular
|
||||
where id in
|
||||
<foreach collection="list" open="(" close=")" separator="," item="id">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
317
visual/code-gen/src/main/resources/mapper/TableColumnMapper.xml
Normal file
317
visual/code-gen/src/main/resources/mapper/TableColumnMapper.xml
Normal file
@@ -0,0 +1,317 @@
|
||||
<?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="cn.fateverse.code.mapper.TableColumnMapper">
|
||||
|
||||
<select id="selectListByTableId" resultType="cn.fateverse.code.entity.TableColumn">
|
||||
select column_id,
|
||||
table_id,
|
||||
column_name,
|
||||
column_comment,
|
||||
column_type,
|
||||
column_length,
|
||||
column_scale,
|
||||
java_type,
|
||||
java_field,
|
||||
is_pk,
|
||||
is_increment,
|
||||
is_required,
|
||||
is_insert,
|
||||
is_edit,
|
||||
is_list,
|
||||
is_query,
|
||||
is_regular,
|
||||
query_type,
|
||||
html_type,
|
||||
dict_type,
|
||||
sort,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
update_time from gen_table_column where table_id = #{tableId}
|
||||
</select>
|
||||
|
||||
<insert id="insert">
|
||||
insert into gen_table_column
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="tableId != null and tableId != ''">table_id,</if>
|
||||
<if test="columnName != null and columnName != ''">column_name,</if>
|
||||
<if test="columnComment != null and columnComment != ''">column_comment,</if>
|
||||
<if test="columnType != null and columnType != ''">column_type,</if>
|
||||
<if test="columnLength != null and columnLength != 0">column_length,</if>
|
||||
<if test="columnScale != null and columnScale != 0">column_scale,</if>
|
||||
<if test="javaType != null and javaType != ''">java_type,</if>
|
||||
<if test="javaField != null and javaField != ''">java_field,</if>
|
||||
<if test="isPk != null and isPk != ''">is_pk,</if>
|
||||
<if test="isIncrement != null and isIncrement != ''">is_increment,</if>
|
||||
<if test="isRequired != null and isRequired != ''">is_required,</if>
|
||||
<if test="isRegular != null and isRegular != ''">is_regular,</if>
|
||||
<if test="isInsert != null and isInsert != ''">is_insert,</if>
|
||||
<if test="isEdit != null and isEdit != ''">is_edit,</if>
|
||||
<if test="isList != null and isList != ''">is_list,</if>
|
||||
<if test="isQuery != null and isQuery != ''">is_query,</if>
|
||||
<if test="queryType != null and queryType != ''">query_type,</if>
|
||||
<if test="htmlType != null and htmlType != ''">html_type,</if>
|
||||
<if test="dictType != null">dict_type,</if>
|
||||
<if test="sort != null">sort,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="tableId != null and tableId != ''">#{tableId},</if>
|
||||
<if test="columnName != null and columnName != ''">#{columnName},</if>
|
||||
<if test="columnComment != null and columnComment != ''">#{columnComment},</if>
|
||||
<if test="columnType != null and columnType != ''">#{columnType},</if>
|
||||
<if test="columnLength != null and columnLength != 0">#{columnLength},</if>
|
||||
<if test="columnScale != null and columnScale != 0">#{columnScale},</if>
|
||||
<if test="javaType != null and javaType != ''">#{javaType},</if>
|
||||
<if test="javaField != null and javaField != ''">#{javaField},</if>
|
||||
<if test="isPk != null and isPk != ''">#{isPk},</if>
|
||||
<if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if>
|
||||
<if test="isRequired != null and isRequired != ''">#{isRequired},</if>
|
||||
<if test="isRegular != null and isRegular != ''">#{isRegular},</if>
|
||||
<if test="isInsert != null and isInsert != ''">#{isInsert},</if>
|
||||
<if test="isEdit != null and isEdit != ''">#{isEdit},</if>
|
||||
<if test="isList != null and isList != ''">#{isList},</if>
|
||||
<if test="isQuery != null and isQuery != ''">#{isQuery},</if>
|
||||
<if test="queryType != null and queryType != ''">#{queryType},</if>
|
||||
<if test="htmlType != null and htmlType != ''">#{htmlType},</if>
|
||||
<if test="dictType != null">#{dictType},</if>
|
||||
<if test="sort != null">#{sort},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<insert id="batchInsert">
|
||||
insert into gen_table_column (
|
||||
table_id,
|
||||
column_name,
|
||||
column_comment,
|
||||
column_type,
|
||||
column_length,
|
||||
column_scale,
|
||||
java_type,
|
||||
java_field,
|
||||
is_pk,
|
||||
is_increment,
|
||||
is_required,
|
||||
is_insert,
|
||||
is_edit,
|
||||
is_list,
|
||||
is_query,
|
||||
is_regular,
|
||||
query_type,
|
||||
html_type,
|
||||
dict_type,
|
||||
sort,
|
||||
create_by,
|
||||
create_time) values
|
||||
<foreach collection="list" separator="," item="column">
|
||||
(#{column.tableId},
|
||||
#{column.columnName},
|
||||
#{column.columnComment},
|
||||
#{column.columnType},
|
||||
#{column.columnLength},
|
||||
#{column.columnScale},
|
||||
#{column.javaType},
|
||||
#{column.javaField},
|
||||
#{column.isPk},
|
||||
#{column.isIncrement},
|
||||
#{column.isRequired},
|
||||
#{column.isInsert},
|
||||
#{column.isEdit},
|
||||
#{column.isList},
|
||||
#{column.isQuery},
|
||||
#{column.isRegular},
|
||||
#{column.queryType},
|
||||
#{column.htmlType},
|
||||
#{column.dictType},
|
||||
#{column.sort},
|
||||
#{column.createBy},
|
||||
#{column.createTime})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update gen_table_column
|
||||
<set>
|
||||
<if test="tableId != null and tableId != ''">table_id = #{tableId},</if>
|
||||
<if test="columnName != null and columnName != ''">`column_name` = #{columnName},</if>
|
||||
<if test="columnComment != null and columnComment != ''">column_comment=#{columnComment},</if>
|
||||
<if test="columnType != null and columnType != ''">column_type=#{columnType},</if>
|
||||
<if test="columnLength != null and columnLength != ''">column_length=#{columnLength},</if>
|
||||
<if test="columnScale != null and columnScale != ''">column_scale=#{columnScale},</if>
|
||||
<if test="javaType != null and javaType != ''">java_type=#{javaType},</if>
|
||||
<if test="javaField != null and javaField != ''">java_field=#{javaField},</if>
|
||||
<if test="isPk != null and isPk != ''">is_pk=#{isPk},</if>
|
||||
<if test="isIncrement != null and isIncrement != ''">is_increment=#{isIncrement},</if>
|
||||
<if test="isRequired != null and isRequired != ''">is_required=#{isRequired},</if>
|
||||
<if test="isRegular != null and isRegular != ''">is_regular=#{isRegular},</if>
|
||||
<if test="isInsert != null and isInsert != ''">is_insert=#{isInsert},</if>
|
||||
<if test="isEdit != null and isEdit != ''">is_edit=#{isEdit},</if>
|
||||
<if test="isList != null and isList != ''">is_list=#{isList},</if>
|
||||
<if test="isQuery != null and isQuery != ''">is_query=#{isQuery},</if>
|
||||
<if test="queryType != null and queryType != ''">query_type=#{queryType},</if>
|
||||
<if test="htmlType != null and htmlType != ''">html_type=#{htmlType},</if>
|
||||
<if test="dictType != null">dict_type=#{dictType},</if>
|
||||
<if test="sort != null">sort=#{sort},</if>
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
</set>
|
||||
where column_id = #{columnId}
|
||||
</update>
|
||||
|
||||
<update id="batchUpdate">
|
||||
update gen_table_column
|
||||
<set>
|
||||
<trim prefix="column_comment = case" suffix="end,">
|
||||
<foreach collection="list" separator=" " item="item">
|
||||
<if test="item.columnComment != null">
|
||||
when column_id = #{item.columnId} then #{item.columnComment}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="column_type = case" suffix="end,">
|
||||
<foreach collection="list" separator=" " item="item">
|
||||
<if test="item.columnType != null">
|
||||
when column_id = #{item.columnId} then #{item.columnType}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="java_type = case" suffix="end,">
|
||||
<foreach collection="list" separator=" " item="item">
|
||||
<if test="item.javaType != null">
|
||||
when column_id = #{item.columnId} then #{item.javaType}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="java_field = case" suffix="end,">
|
||||
<foreach collection="list" separator=" " item="item">
|
||||
<if test="item.javaField != null">
|
||||
when column_id = #{item.columnId} then #{item.javaField}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="is_pk = case" suffix="end,">
|
||||
<foreach collection="list" separator=" " item="item">
|
||||
<if test="item.isPk != null and item.isPk != ''">
|
||||
when column_id = #{item.columnId} then #{item.isPk}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="is_increment = case" suffix="end,">
|
||||
<foreach collection="list" separator=" " item="item">
|
||||
<if test="item.isIncrement != null and item.isIncrement != ''">
|
||||
when column_id = #{item.columnId} then #{item.isIncrement}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="is_required = case" suffix="end,">
|
||||
<foreach collection="list" separator=" " item="item">
|
||||
<if test="item.isRequired != null and item.isRequired != ''">
|
||||
when column_id = #{item.columnId} then #{item.isRequired}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="is_regular = case" suffix="end,">
|
||||
<foreach collection="list" separator=" " item="item">
|
||||
<if test="item.isRegular != null and item.isRegular != ''">
|
||||
when column_id = #{item.columnId} then #{item.isRegular}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="is_insert = case" suffix="end,">
|
||||
<foreach collection="list" separator=" " item="item">
|
||||
<if test="item.isInsert != null and item.isInsert != ''">
|
||||
when column_id = #{item.columnId} then #{item.isInsert}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="is_edit = case" suffix="end,">
|
||||
<foreach collection="list" separator=" " item="item">
|
||||
<if test="item.isEdit != null and item.isEdit != ''">
|
||||
when column_id = #{item.columnId} then #{item.isEdit}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="is_list = case" suffix="end,">
|
||||
<foreach collection="list" separator=" " item="item">
|
||||
<if test="item.isList != null and item.isList != ''">
|
||||
when column_id = #{item.columnId} then #{item.isList}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="is_query = case" suffix="end,">
|
||||
<foreach collection="list" separator=" " item="item">
|
||||
<if test="item.isQuery != null and item.isQuery != ''">
|
||||
when column_id = #{item.columnId} then #{item.isQuery}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="query_type = case" suffix="end,">
|
||||
<foreach collection="list" separator=" " item="item">
|
||||
<if test="item.queryType != null and item.queryType != ''">
|
||||
when column_id = #{item.columnId} then #{item.queryType}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="html_type = case" suffix="end,">
|
||||
<foreach collection="list" separator=" " item="item">
|
||||
<if test="item.htmlType != null and item.htmlType != ''">
|
||||
when column_id = #{item.columnId} then #{item.htmlType}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="dict_type = case" suffix="end,">
|
||||
<foreach collection="list" separator=" " item="item">
|
||||
<if test="item.dictType != null and item.dictType != ''">
|
||||
when column_id = #{item.columnId} then #{item.dictType}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="update_by = case" suffix="end,">
|
||||
<foreach collection="list" separator=" " item="item">
|
||||
<if test="item.updateBy != null and item.updateBy != ''">
|
||||
when column_id = #{item.columnId} then #{item.updateBy}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="update_time = case" suffix="end,">
|
||||
<foreach collection="list" separator=" " item="item">
|
||||
<if test="item.updateTime != null">
|
||||
when column_id = #{item.columnId} then #{item.updateTime}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
</set>
|
||||
where column_id in
|
||||
<foreach collection="list" item="item" index="index"
|
||||
separator="," open="(" close=")">
|
||||
#{item.columnId}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
|
||||
<delete id="deleteByTableIds" parameterType="Long">
|
||||
delete from gen_table_column where table_id in
|
||||
<foreach collection="list" item="tableId" open="(" separator="," close=")">
|
||||
#{tableId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByTableId" parameterType="Long">
|
||||
delete
|
||||
from gen_table_column
|
||||
where table_id = #{tableId}
|
||||
</delete>
|
||||
|
||||
<delete id="batchRemove">
|
||||
delete from gen_table_column where column_id in
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
356
visual/code-gen/src/main/resources/mapper/TableMapper.xml
Normal file
356
visual/code-gen/src/main/resources/mapper/TableMapper.xml
Normal file
@@ -0,0 +1,356 @@
|
||||
<?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="cn.fateverse.code.mapper.TableMapper">
|
||||
|
||||
<resultMap type="cn.fateverse.code.entity.Table" id="TableResult">
|
||||
<id property="tableId" column="table_id"/>
|
||||
<result property="dataSourceId" column="data_source_id"/>
|
||||
<result property="parentMenuId" column="parent_menu_id"/>
|
||||
<result property="dataSourceType" column="data_source_type"/>
|
||||
<result property="tableName" column="table_name"/>
|
||||
<result property="tableComment" column="table_comment"/>
|
||||
<result property="subTableName" column="sub_table_name"/>
|
||||
<result property="subTableFkName" column="sub_table_fk_name"/>
|
||||
<result property="className" column="class_name"/>
|
||||
<result property="tplCategory" column="tpl_category"/>
|
||||
<result property="packageName" column="package_name"/>
|
||||
<result property="serviceName" column="service_name"/>
|
||||
<result property="moduleName" column="module_name"/>
|
||||
<result property="businessName" column="business_name"/>
|
||||
<result property="functionName" column="function_name"/>
|
||||
<result property="functionAuthor" column="function_author"/>
|
||||
<result property="backTemplate" column="back_template"/>
|
||||
<result property="frontTemplate" column="front_template"/>
|
||||
<result property="options" column="options"/>
|
||||
<result property="optionApi" column="option_api"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="remark" column="remark"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="cn.fateverse.code.entity.TableColumn" id="TableColumnResult">
|
||||
<id property="columnId" column="column_id"/>
|
||||
<result property="tableId" column="table_id"/>
|
||||
<result property="columnName" column="column_name"/>
|
||||
<result property="columnComment" column="column_comment"/>
|
||||
<result property="columnType" column="column_type"/>
|
||||
<result property="javaType" column="java_type"/>
|
||||
<result property="javaField" column="java_field"/>
|
||||
<result property="isPk" column="is_pk"/>
|
||||
<result property="isIncrement" column="is_increment"/>
|
||||
<result property="isRequired" column="is_required"/>
|
||||
<result property="isInsert" column="is_insert"/>
|
||||
<result property="isEdit" column="is_edit"/>
|
||||
<result property="isList" column="is_list"/>
|
||||
<result property="isQuery" column="is_query"/>
|
||||
<result property="isRegular" column="is_regular"/>
|
||||
<result property="regular" column="regular"/>
|
||||
<result property="queryType" column="query_type"/>
|
||||
<result property="htmlType" column="html_type"/>
|
||||
<result property="dictType" column="dict_type"/>
|
||||
<result property="sort" column="sort"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="TableResultDto" type="cn.fateverse.code.entity.dto.TableDto" extends="TableResult">
|
||||
<collection property="columns" javaType="java.util.List" resultMap="TableColumnResult"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectGenTable">
|
||||
select table_id,
|
||||
data_source_id,
|
||||
data_source_type,
|
||||
table_name,
|
||||
table_comment,
|
||||
sub_table_name,
|
||||
sub_table_fk_name,
|
||||
class_name,
|
||||
tpl_category,
|
||||
package_name,
|
||||
service_name,
|
||||
module_name,
|
||||
business_name,
|
||||
function_name,
|
||||
function_author,
|
||||
back_template,
|
||||
front_template,
|
||||
options,
|
||||
option_api,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
update_time,
|
||||
remark
|
||||
from gen_table
|
||||
</sql>
|
||||
|
||||
<select id="selectTableList" resultMap="TableResult">
|
||||
<include refid="selectGenTable"/>
|
||||
<where>
|
||||
<if test="dataSourceId != null ">
|
||||
and data_source_id = #{dataSourceId}
|
||||
</if>
|
||||
<if test="tableName != null and tableName != ''">
|
||||
and lower(`table_name`) like lower(concat('%', #{tableName}, '%'))
|
||||
</if>
|
||||
<if test="tableComment != null and tableComment != ''">
|
||||
and lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
|
||||
</if>
|
||||
<if test="dataSourceType != null ">
|
||||
and data_source_type like concat('%', #{dataSourceType}, '%')
|
||||
</if>
|
||||
<if test="startTime != null and startTime != ''"><!-- 开始时间检索 -->
|
||||
and create_time,'%y%m%d') >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
|
||||
and create_time <= #{endTime}
|
||||
</if>
|
||||
</where>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<!--todo 获取表信息 预览代码使用-->
|
||||
<select id="selectTableDtoByTableId" parameterType="Long" resultMap="TableResultDto">
|
||||
SELECT gt.table_id,
|
||||
gt.data_source_id,
|
||||
gt.parent_menu_id,
|
||||
gt.data_source_type,
|
||||
gt.table_name,
|
||||
gt.table_comment,
|
||||
gt.sub_table_name,
|
||||
gt.sub_table_fk_name,
|
||||
gt.class_name,
|
||||
gt.tpl_category,
|
||||
gt.package_name,
|
||||
gt.service_name,
|
||||
gt.module_name,
|
||||
gt.business_name,
|
||||
gt.function_name,
|
||||
gt.function_author,
|
||||
gt.options,
|
||||
gt.option_api,
|
||||
gt.remark,
|
||||
gt.back_template,
|
||||
gt.front_template,
|
||||
gtc.column_id,
|
||||
gtc.column_name,
|
||||
gtc.column_comment,
|
||||
gtc.column_type,
|
||||
gtc.java_type,
|
||||
gtc.java_field,
|
||||
gtc.is_pk,
|
||||
gtc.is_increment,
|
||||
gtc.is_required,
|
||||
gtc.is_insert,
|
||||
gtc.is_edit,
|
||||
gtc.is_list,
|
||||
gtc.is_query,
|
||||
gtc.query_type,
|
||||
gtc.html_type,
|
||||
gtc.dict_type,
|
||||
gtc.sort,
|
||||
gtc.is_regular,
|
||||
gr.regular
|
||||
FROM gen_table gt
|
||||
LEFT JOIN gen_table_column gtc ON gt.table_id = gtc.table_id
|
||||
LEFT JOIN gen_regular gr ON gtc.is_regular = gr.id
|
||||
where gt.table_id = #{tableId}
|
||||
order by gtc.sort
|
||||
</select>
|
||||
<!--todo 获取表信息 生成代码使用-->
|
||||
<select id="selectTableByName" parameterType="String" resultMap="TableResultDto">
|
||||
SELECT gt.table_id,
|
||||
gt.data_source_id,
|
||||
gt.parent_menu_id,
|
||||
gt.data_source_type,
|
||||
gt.table_name,
|
||||
gt.table_comment,
|
||||
gt.sub_table_name,
|
||||
gt.sub_table_fk_name,
|
||||
gt.class_name,
|
||||
gt.tpl_category,
|
||||
gt.package_name,
|
||||
gt.service_name,
|
||||
gt.module_name,
|
||||
gt.business_name,
|
||||
gt.function_name,
|
||||
gt.function_author,
|
||||
gt.back_template,
|
||||
gt.front_template,
|
||||
gt.options,
|
||||
gt.option_api,
|
||||
gt.remark,
|
||||
gtc.column_id,
|
||||
gtc.column_name,
|
||||
gtc.column_comment,
|
||||
gtc.column_type,
|
||||
gtc.java_type,
|
||||
gtc.java_field,
|
||||
gtc.is_pk,
|
||||
gtc.is_increment,
|
||||
gtc.is_required,
|
||||
gtc.is_insert,
|
||||
gtc.is_edit,
|
||||
gtc.is_list,
|
||||
gtc.is_query,
|
||||
gtc.query_type,
|
||||
gtc.html_type,
|
||||
gtc.dict_type,
|
||||
gtc.sort,
|
||||
gtc.is_regular,
|
||||
gr.regular
|
||||
FROM gen_table gt
|
||||
LEFT JOIN gen_table_column gtc ON gt.table_id = gtc.table_id
|
||||
LEFT JOIN gen_regular gr ON gtc.is_regular = gr.id
|
||||
where gt.table_name = #{tableName}
|
||||
order by gtc.sort
|
||||
</select>
|
||||
|
||||
<!-- todo 查询数据库行配置信息-->
|
||||
<select id="selectTableAll" parameterType="String" resultMap="TableResultDto">
|
||||
SELECT gt.table_id,
|
||||
gt.data_source_id,
|
||||
gt.parent_menu_id,
|
||||
gt.data_source_type,
|
||||
gt.table_name,
|
||||
gt.table_comment,
|
||||
gt.sub_table_name,
|
||||
gt.sub_table_fk_name,
|
||||
gt.class_name,
|
||||
gt.tpl_category,
|
||||
gt.package_name,
|
||||
gt.service_name,
|
||||
gt.module_name,
|
||||
gt.business_name,
|
||||
gt.function_name,
|
||||
gt.function_author,
|
||||
gt.options,
|
||||
gt.option_api,
|
||||
gt.remark,
|
||||
gt.back_template,
|
||||
gt.front_template,
|
||||
gtc.column_id,
|
||||
gtc.column_name,
|
||||
gtc.column_comment,
|
||||
gtc.column_type,
|
||||
gtc.java_type,
|
||||
gtc.java_field,
|
||||
gtc.is_pk,
|
||||
gtc.is_increment,
|
||||
gtc.is_required,
|
||||
gtc.is_insert,
|
||||
gtc.is_edit,
|
||||
gtc.is_list,
|
||||
gtc.is_query,
|
||||
gtc.query_type,
|
||||
gtc.html_type,
|
||||
gtc.dict_type,
|
||||
gtc.sort
|
||||
FROM gen_table gt
|
||||
LEFT JOIN gen_table_column gtc ON gt.table_id = gtc.table_id
|
||||
order by gtc.sort
|
||||
</select>
|
||||
<select id="selectTableNameByDataSourceId" resultType="java.lang.String">
|
||||
select table_name
|
||||
from gen_table
|
||||
where data_source_id = #{dataSourceId}
|
||||
</select>
|
||||
|
||||
<select id="selectCheckTableByDataSourceId" resultType="java.lang.Long">
|
||||
select count(*) from gen_table where data_source_id = #{dataSourceId} limit 1
|
||||
</select>
|
||||
|
||||
<insert id="insertTable" useGeneratedKeys="true" keyProperty="tableId">
|
||||
insert into gen_table
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="tableName != null">table_name,</if>
|
||||
<if test="dataSourceId != null">data_source_id,</if>
|
||||
<if test="parentMenuId != null">parent_menu_id,</if>
|
||||
<if test="dataSourceType != null ">data_source_type,</if>
|
||||
<if test="tableComment != null and tableComment != ''">table_comment,</if>
|
||||
<if test="className != null and className != ''">class_name,</if>
|
||||
<if test="tplCategory != null and tplCategory != ''">tpl_category,</if>
|
||||
<if test="packageName != null and packageName != ''">package_name,</if>
|
||||
<if test="moduleName != null and moduleName != ''">module_name,</if>
|
||||
<if test="serviceName != null and serviceName != ''">service_name,</if>
|
||||
<if test="businessName != null and businessName != ''">business_name,</if>
|
||||
<if test="functionName != null and functionName != ''">function_name,</if>
|
||||
<if test="functionAuthor != null and functionAuthor != ''">function_author,</if>
|
||||
<if test="backTemplate != null">back_template,</if>
|
||||
<if test="frontTemplate != null">front_template,</if>
|
||||
<if test="optionApi != null and optionApi != ''">option_api,</if>
|
||||
<if test="remark != null and remark != ''">remark,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="tableName != null">#{tableName},</if>
|
||||
<if test="dataSourceId != null">#{dataSourceId},</if>
|
||||
<if test="parentMenuId != null">#{parentMenuId},</if>
|
||||
<if test="dataSourceType != null ">#{dataSourceType},</if>
|
||||
<if test="tableComment != null and tableComment != ''">#{tableComment},</if>
|
||||
<if test="className != null and className != ''">#{className},</if>
|
||||
<if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if>
|
||||
<if test="packageName != null and packageName != ''">#{packageName},</if>
|
||||
<if test="moduleName != null and moduleName != ''">#{moduleName},</if>
|
||||
<if test="serviceName != null and serviceName != ''">#{serviceName},</if>
|
||||
<if test="businessName != null and businessName != ''">#{businessName},</if>
|
||||
<if test="functionName != null and functionName != ''">#{functionName},</if>
|
||||
<if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if>
|
||||
<if test="backTemplate != null">#{backTemplate},</if>
|
||||
<if test="frontTemplate != null">#{frontTemplate},</if>
|
||||
<if test="optionApi != null and optionApi != ''">#{optionApi},</if>
|
||||
<if test="remark != null and remark != ''">#{remark},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
|
||||
<update id="updateTable">
|
||||
update gen_table
|
||||
<set>
|
||||
<if test="parentMenuId != null">parent_menu_id = #{parentMenuId},</if>
|
||||
<if test="tableName != null and tableName != ''">table_name = #{tableName},</if>
|
||||
<if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if>
|
||||
<if test="subTableName != null">sub_table_name = #{subTableName},</if>
|
||||
<if test="subTableFkName != null">sub_table_fk_name = #{subTableFkName},</if>
|
||||
<if test="className != null and className != ''">class_name = #{className},</if>
|
||||
<if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if>
|
||||
<if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if>
|
||||
<if test="packageName != null and packageName != ''">package_name = #{packageName},</if>
|
||||
<if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
|
||||
<if test="serviceName != null and serviceName != ''">service_name = #{serviceName},</if>
|
||||
<if test="businessName != null and businessName != ''">business_name = #{businessName},</if>
|
||||
<if test="functionName != null and functionName != ''">function_name = #{functionName},</if>
|
||||
<if test="optionApi != null and optionApi != ''">option_api = #{optionApi},</if>
|
||||
<if test="options != null and options != ''">`options` = #{options},</if>
|
||||
<if test="backTemplate != null">back_template = #{backTemplate},</if>
|
||||
<if test="frontTemplate != null">front_template = #{frontTemplate},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null and updateTime != ''">update_time = #{updateTime},</if>
|
||||
</set>
|
||||
where table_id = #{tableId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteTableByIds" parameterType="Long">
|
||||
delete from gen_table where table_id in
|
||||
<foreach collection="list" item="tableId" open="(" separator="," close=")">
|
||||
#{tableId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<delete id="deleteTableById">
|
||||
delete
|
||||
from gen_table
|
||||
where table_id = #{tableId}
|
||||
</delete>
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,49 @@
|
||||
<?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="cn.fateverse.code.mapper.dynamic.DynamicTableMapper">
|
||||
|
||||
<resultMap type="cn.fateverse.code.entity.Table" id="TableResult">
|
||||
<result property="tableName" column="table_name" />
|
||||
<result property="tableComment" column="table_comment" />
|
||||
<result property="dataSourceType" column="data_source_type" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="cn.fateverse.code.entity.query.DynamicTable" id="DynamicTableResult">
|
||||
<result property="tableName" column="table_name" />
|
||||
<result property="tableComment" column="table_comment" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="cn.fateverse.code.entity.TableColumn" id="TableColumnResult">
|
||||
<id property="columnId" column="column_id" />
|
||||
<result property="tableId" column="table_id" />
|
||||
<result property="columnName" column="column_name" />
|
||||
<result property="columnComment" column="column_comment" />
|
||||
<result property="columnType" column="column_type" />
|
||||
<result property="columnLength" column="column_length" />
|
||||
<result property="columnScale" column="column_scale" />
|
||||
<result property="javaType" column="java_type" />
|
||||
<result property="javaField" column="java_field" />
|
||||
<result property="isPk" column="is_pk" />
|
||||
<result property="isIncrement" column="is_increment" />
|
||||
<result property="isRequired" column="is_required" />
|
||||
<result property="isInsert" column="is_insert" />
|
||||
<result property="isEdit" column="is_edit" />
|
||||
<result property="isList" column="is_list" />
|
||||
<result property="isQuery" column="is_query" />
|
||||
<result property="queryType" column="query_type" />
|
||||
<result property="htmlType" column="html_type" />
|
||||
<result property="dictType" column="dict_type" />
|
||||
<result property="sort" column="sort" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,79 @@
|
||||
<?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="cn.fateverse.code.mapper.dynamic.MySqlDynamicTableMapper">
|
||||
|
||||
<select id="checkSource" resultType="java.lang.Integer">
|
||||
select 1 from dual
|
||||
</select>
|
||||
|
||||
<select id="selectList" resultMap="cn.fateverse.code.mapper.dynamic.DynamicTableMapper.DynamicTableResult">
|
||||
select table_name, table_comment, create_time, update_time
|
||||
from information_schema.tables
|
||||
where table_schema = (select database())
|
||||
and table_name NOT LIKE 'gen_%'
|
||||
<if test="table.tableName != null and table.tableName != ''">
|
||||
and table_name like concat('%', #{table.tableName}, '%')
|
||||
</if>
|
||||
<if test="table.tableComment != null and table.tableComment != ''">
|
||||
and table_comment like concat('%', #{table.tableComment}, '%')
|
||||
</if>
|
||||
<if test="table.startTime != null and table.endTime != null"><!-- 开始时间检索 -->
|
||||
and create_time between #{table.startTime} and #{table.endTime}
|
||||
</if>
|
||||
<if test="list !=null and list.size!=0">
|
||||
and table_name not in
|
||||
<foreach collection="list" item="name" separator="," open="(" close=")" >
|
||||
#{name}
|
||||
</foreach>
|
||||
</if>
|
||||
limit #{page.startNum},#{page.endNum}
|
||||
</select>
|
||||
|
||||
<select id="selectListCount" resultType="java.lang.Long">
|
||||
select count(1)
|
||||
from information_schema.tables
|
||||
where table_schema = (select database())
|
||||
and table_name NOT LIKE 'gen_%'
|
||||
<if test="table.tableName != null and table.tableName != ''">
|
||||
and table_name like concat('%', #{table.tableName}, '%')
|
||||
</if>
|
||||
<if test="table.tableComment != null and table.tableComment != ''">
|
||||
and table_comment like concat('%', #{table.tableComment}, '%')
|
||||
</if>
|
||||
<if test="table.startTime != null and table.endTime != null"><!-- 开始时间检索 -->
|
||||
and create_time between #{table.startTime} and #{table.endTime}
|
||||
</if>
|
||||
<if test="list !=null and list.size!=0">
|
||||
and table_name not in
|
||||
<foreach collection="list" item="name" separator="," open="(" close=")" >
|
||||
#{name}
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- and table_name NOT LIKE 'gen_%' -->
|
||||
<select id="selectListByNameList" resultMap="cn.fateverse.code.mapper.dynamic.DynamicTableMapper.TableResult">
|
||||
select table_name, table_comment, create_time, update_time, 'MYSQL' as data_source_type
|
||||
from information_schema.tables
|
||||
where table_name not like 'gen_%'
|
||||
and table_schema = (select database())
|
||||
and table_name in
|
||||
<foreach collection="list" item="name" open="(" separator="," close=")">
|
||||
#{name}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="selectColumnsByNameList" resultMap="cn.fateverse.code.mapper.dynamic.DynamicTableMapper.TableColumnResult">
|
||||
select table_name as dict_type,column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type
|
||||
from information_schema.columns
|
||||
where table_schema = (select database()) and table_name in
|
||||
<foreach collection="list" item="name" open="(" separator="," close=")">
|
||||
#{name}
|
||||
</foreach>
|
||||
order by ordinal_position
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,89 @@
|
||||
<?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="cn.fateverse.code.mapper.dynamic.OracleDynamicTableMapper">
|
||||
|
||||
<select id="checkSource" resultType="java.lang.Integer">
|
||||
select 1 from dual
|
||||
</select>
|
||||
|
||||
<select id="selectList" resultMap="cn.fateverse.code.mapper.dynamic.DynamicTableMapper.DynamicTableResult">
|
||||
select ut.table_name,utc.comments as table_comment,ut.last_analyzed as update_time
|
||||
from user_tables ut
|
||||
left join user_tab_comments utc on ut.table_name = utc.table_name
|
||||
where rownum between #{page.startNum} and #{page.endNum}
|
||||
<if test="table.tableName != null and table.tableName != ''">
|
||||
and ut.table_name like concat(concat('%', #{table.tableName}), '%')
|
||||
</if>
|
||||
<if test="table.tableComment != null and table.tableComment != ''">
|
||||
and utc.comments like concat(concat('%', #{table.tableComment}), '%')
|
||||
</if>
|
||||
<if test="table.startTime != null and table.endTime != null"><!-- 开始时间检索 -->
|
||||
and update_time between #{table.startTime} and #{table.endTime}
|
||||
</if>
|
||||
<if test="list !=null and list.size!=0">
|
||||
and ut.table_name not in
|
||||
<foreach collection="list" item="name" separator="," open="(" close=")" >
|
||||
#{name}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
</select>
|
||||
|
||||
<select id="selectListCount" resultType="java.lang.Long">
|
||||
select count(1)
|
||||
from user_tables ut
|
||||
left join user_tab_comments utc on ut.table_name = utc.table_name
|
||||
<where>
|
||||
<if test="table.tableName != null and table.tableName != ''">
|
||||
and ut.table_name like concat(concat('%', #{table.tableName}), '%')
|
||||
</if>
|
||||
<if test="table.tableComment != null and table.tableComment != ''">
|
||||
and utc.comments like concat(concat('%', #{table.tableComment}), '%')
|
||||
</if>
|
||||
<if test="table.startTime != null and table.endTime != null"><!-- 开始时间检索 -->
|
||||
and ut.last_analyzed between #{table.startTime} and #{table.endTime}
|
||||
</if>
|
||||
<if test="list !=null and list.size!=0">
|
||||
and ut.table_name not in
|
||||
<foreach collection="list" item="name" separator="," open="(" close=")" >
|
||||
#{name}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<!-- and table_name NOT LIKE 'gen_%' -->
|
||||
<select id="selectListByNameList" resultMap="cn.fateverse.code.mapper.dynamic.DynamicTableMapper.TableResult">
|
||||
select ut.table_name,utc.comments as table_comment,ut.last_analyzed as update_time,'ORACLE' as data_source_type
|
||||
from user_tables ut
|
||||
left join user_tab_comments utc on ut.table_name = utc.table_name
|
||||
where ut.table_name in
|
||||
<foreach collection="list" item="name" separator="," open="(" close=")" >
|
||||
#{name}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="selectColumnsByNameList" resultMap="cn.fateverse.code.mapper.dynamic.DynamicTableMapper.TableColumnResult">
|
||||
select distinct utc.column_name,
|
||||
utc.table_name as dict_type,
|
||||
utc.data_type as column_type,
|
||||
utc.data_length as column_length,
|
||||
utc.data_scale as column_scale,
|
||||
(case when utc.nullable = 'N' then '1' else '0' end) as is_required ,
|
||||
utc.column_id as sort,
|
||||
(case when uc.constraint_type = 'P' then '1' else '0' end) as is_pk ,
|
||||
ucc.comments as column_comment
|
||||
from user_tab_columns utc
|
||||
inner join user_col_comments ucc on ucc.column_name = utc.column_name and ucc.table_name = utc.table_name
|
||||
left join user_cons_columns uccs on uccs.column_name = utc.column_name
|
||||
left join user_constraints uc on uc.constraint_name = uccs.constraint_name
|
||||
where uc.search_condition is null
|
||||
and utc.table_name in
|
||||
<foreach collection="list" item="name" open="(" separator="," close=")">
|
||||
#{name}
|
||||
</foreach>
|
||||
order by utc.column_id
|
||||
</select>
|
||||
</mapper>
|
||||
106
visual/code-gen/src/main/resources/vm/java/controller.java.vm
Normal file
106
visual/code-gen/src/main/resources/vm/java/controller.java.vm
Normal file
@@ -0,0 +1,106 @@
|
||||
package ${packageName}.controller;
|
||||
|
||||
import ${packageName}.entity.dto.${ClassName}Dto;
|
||||
import ${packageName}.entity.query.${ClassName}Query;
|
||||
import ${packageName}.entity.vo.${ClassName}Vo;
|
||||
import ${packageName}.service.${ClassName}Service;
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
#if($table.hasOptionApi())
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
#end
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.log.annotation.Log;
|
||||
import cn.fateverse.common.log.enums.BusinessType;
|
||||
import cn.fateverse.common.excel.utils.ExcelUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ${functionName} Controller
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${dateTime}
|
||||
*/
|
||||
@Api(value = "${functionName}管理",tags = "${functionName}管理")
|
||||
@RestController
|
||||
@RequestMapping("/${moduleName}/${businessName}")
|
||||
public class ${ClassName}Controller {
|
||||
|
||||
private final ${ClassName}Service ${className}Service;
|
||||
|
||||
public ${ClassName}Controller(${ClassName}Service ${className}Service) {
|
||||
this.${className}Service = ${className}Service;
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("获取${functionName}列表")
|
||||
@GetMapping
|
||||
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:list')")
|
||||
public Result<TableDataInfo<${ClassName}Vo>> list(${ClassName}Query query) {
|
||||
TableDataInfo<${ClassName}Vo> dataInfo = ${className}Service.searchList(query);
|
||||
return Result.ok(dataInfo);
|
||||
}
|
||||
|
||||
#if($table.hasOptionApi())
|
||||
@ApiOperation("获取校验规则option")
|
||||
@GetMapping("/option")
|
||||
public Result<List<Option>> option(){
|
||||
List<Option> options = ${className}Service.searchOptionList();
|
||||
return Result.ok(options);
|
||||
}
|
||||
#end
|
||||
|
||||
@ApiOperation("导出excel数据")
|
||||
@GetMapping("/export")
|
||||
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:export')")
|
||||
public void export(${ClassName}Query query){
|
||||
List<${ClassName}Vo> list = ${className}Service.exportList(query);
|
||||
ExcelUtil.exportExcel(list,${ClassName}Vo.class);
|
||||
}
|
||||
|
||||
@ApiOperation("获取${functionName}详细信息")
|
||||
@GetMapping("/{${pkColumn.javaField}}")
|
||||
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:info')")
|
||||
public Result<${ClassName}Vo> info(@PathVariable ${pkColumn.javaType} ${pkColumn.javaField}) {
|
||||
ObjectUtils.checkPk(${pkColumn.javaField});
|
||||
${ClassName}Vo ${className} = ${className}Service.searchById(${pkColumn.javaField});
|
||||
return Result.ok(${className});
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("新增${functionName}")
|
||||
@PostMapping
|
||||
@Log(title = "新增${functionName}",businessType = BusinessType.INSERT)
|
||||
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:add')")
|
||||
public Result<Void> add(@RequestBody @Validated ${ClassName}Dto ${className}){
|
||||
${className}Service.save(${className});
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("修改${functionName}")
|
||||
@PutMapping
|
||||
@Log(title = "修改${functionName}",businessType = BusinessType.UPDATE)
|
||||
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:edit')")
|
||||
public Result<Void> edit(@RequestBody @Validated ${ClassName}Dto ${className}){
|
||||
ObjectUtils.checkPk(${className}.get${table.capitalize(${pkColumn.javaField})}());
|
||||
${className}Service.edit(${className});
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("删除${functionName}")
|
||||
@DeleteMapping("/{${pkColumn.javaField}List}")
|
||||
@Log(title = "删除${functionName}",businessType = BusinessType.DELETE)
|
||||
@PreAuthorize("@ss.hasPermission('${permissionPrefix}:del')")
|
||||
public Result<Void> batchDel(@PathVariable List<${pkColumn.javaType}> ${pkColumn.javaField}List){
|
||||
ObjectUtils.checkPkList(${pkColumn.javaField}List);
|
||||
${className}Service.removeBatch(${pkColumn.javaField}List);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
}
|
||||
37
visual/code-gen/src/main/resources/vm/java/entity.java.vm
Normal file
37
visual/code-gen/src/main/resources/vm/java/entity.java.vm
Normal file
@@ -0,0 +1,37 @@
|
||||
package ${packageName}.entity;
|
||||
|
||||
import cn.fateverse.common.core.annotaion.EnableAutoField;
|
||||
import cn.fateverse.common.core.entity.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
#if($table.hasDateDto())
|
||||
|
||||
import java.util.Date;
|
||||
#end
|
||||
|
||||
/**
|
||||
* ${functionName}对象 ${tableName}
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${dateTime}
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@EnableAutoField
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ${ClassName} extends BaseEntity{
|
||||
#foreach ($column in $columns)
|
||||
#if(!$column.isSuperColumn($column.javaField))
|
||||
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
private $column.javaType $column.javaField;
|
||||
#end
|
||||
#end
|
||||
|
||||
}
|
||||
77
visual/code-gen/src/main/resources/vm/java/entityDto.java.vm
Normal file
77
visual/code-gen/src/main/resources/vm/java/entityDto.java.vm
Normal file
@@ -0,0 +1,77 @@
|
||||
package ${packageName}.entity.dto;
|
||||
|
||||
import ${packageName}.entity.${ClassName};
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
#if($table.isRequired())
|
||||
import javax.validation.constraints.NotNull;
|
||||
#end
|
||||
#if($table.isRegular())
|
||||
import javax.validation.constraints.Pattern;
|
||||
#end
|
||||
#if($table.hasDateDto())
|
||||
|
||||
import java.util.Date;
|
||||
#end
|
||||
|
||||
/**
|
||||
* ${functionName}对象 ${tableName}
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${dateTime}
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("${functionName}Dto")
|
||||
public class ${ClassName}Dto {
|
||||
|
||||
/**
|
||||
* ${pkColumn.columnComment}
|
||||
*/
|
||||
@ApiModelProperty("${pkColumn.columnComment}")
|
||||
private $pkColumn.javaType $pkColumn.javaField;
|
||||
#foreach ($column in $columns)
|
||||
#if($column.from())
|
||||
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
#if($column.required())
|
||||
@NotNull(message = "${column.columnComment}不能为空!")
|
||||
#end
|
||||
#if($column.isRegular())
|
||||
@Pattern(regexp = "${column.regular}",message = "${column.columnComment}格式错误!")
|
||||
#end
|
||||
@ApiModelProperty("${column.columnComment}")
|
||||
private $column.javaType $column.javaField;
|
||||
#end
|
||||
#end
|
||||
|
||||
public ${ClassName} to${ClassName}() {
|
||||
#if($table.hasDateDto())
|
||||
${ClassName} build = ${ClassName}.builder()
|
||||
.${pkColumn.javaField}(${pkColumn.javaField})
|
||||
#foreach ($column in $columns)
|
||||
#if((1 == $column.isEdit || 1 == $column.isInsert) && !($table.isEntityTime(${column.javaField})))
|
||||
.${column.javaField}(${column.javaField})
|
||||
#end
|
||||
#end
|
||||
.build();
|
||||
#foreach ($column in $columns)
|
||||
#if((1 == $column.isEdit || 1 == $column.isInsert) && $table.isEntityTime(${column.javaField}))
|
||||
build.set${table.capitalize(${column.javaField})}(${column.javaField});
|
||||
#end
|
||||
#end
|
||||
return build;
|
||||
#else
|
||||
return ${ClassName}.builder()
|
||||
.${pkColumn.javaField}(${pkColumn.javaField})
|
||||
#foreach ($column in $columns)
|
||||
#if(1 == $column.isEdit || 1 == $column.isInsert)
|
||||
.${column.javaField}(${column.javaField})
|
||||
#end
|
||||
#end
|
||||
.build();
|
||||
#end
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package ${packageName}.entity.query;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
#if($table.hasDateQuery())
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
#end
|
||||
|
||||
/**
|
||||
* ${functionName}对象 ${tableName}
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${dateTime}
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ApiModel("${functionName}Query")
|
||||
public class ${ClassName}Query {
|
||||
#foreach ($column in $columns)
|
||||
#if($column.query())
|
||||
#if("BETWEEN" != $column.queryType)
|
||||
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
@ApiModelProperty("${column.columnComment}")
|
||||
#if($column.javaType.equals("Date"))
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
#end
|
||||
private $column.javaType $column.javaField;
|
||||
#else
|
||||
|
||||
/**
|
||||
* $column.columnComment 开始
|
||||
*/
|
||||
@ApiModelProperty("${column.columnComment}开始")
|
||||
#if($column.javaType.equals("Date"))
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
#end
|
||||
private $column.javaType begin${table.capitalize($column.javaField)};
|
||||
|
||||
/**
|
||||
* $column.columnComment 结束
|
||||
*/
|
||||
@ApiModelProperty("${column.columnComment}结束")
|
||||
#if($column.javaType.equals("Date"))
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
#end
|
||||
private $column.javaType end${table.capitalize($column.javaField)};
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
}
|
||||
56
visual/code-gen/src/main/resources/vm/java/entityVo.java.vm
Normal file
56
visual/code-gen/src/main/resources/vm/java/entityVo.java.vm
Normal file
@@ -0,0 +1,56 @@
|
||||
package ${packageName}.entity.vo;
|
||||
|
||||
import ${packageName}.entity.${ClassName};
|
||||
import cn.fateverse.common.core.annotaion.Excel;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
#if($table.hasDateDto())
|
||||
#end
|
||||
|
||||
|
||||
/**
|
||||
* ${functionName}对象 ${tableName}
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${dateTime}
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ApiModel("${functionName}Vo")
|
||||
public class ${ClassName}Vo {
|
||||
|
||||
/**
|
||||
* ${pkColumn.columnComment}
|
||||
*/
|
||||
@ApiModelProperty("${pkColumn.columnComment}")
|
||||
private $pkColumn.javaType $pkColumn.javaField;
|
||||
#foreach ($column in $columns)
|
||||
#if($column.list())
|
||||
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
@ApiModelProperty("${column.columnComment}")
|
||||
@Excel("${column.columnComment}")
|
||||
private $column.javaType $column.javaField;
|
||||
#end
|
||||
#end
|
||||
|
||||
public static ${ClassName}Vo to${ClassName}Vo(${ClassName} ${className}) {
|
||||
return ${ClassName}Vo.builder()
|
||||
.${pkColumn.javaField}(${className}.get${table.capitalize(${pkColumn.javaField})}())
|
||||
#foreach ($column in $columns)
|
||||
#if($column.list())
|
||||
.${column.javaField}(${className}.get${table.capitalize(${column.javaField})}())
|
||||
#end
|
||||
#end
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package ${packageName}.mapper;
|
||||
|
||||
import ${packageName}.entity.${ClassName};
|
||||
import ${packageName}.entity.query.${ClassName}Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ${functionName} Mapper
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${dateTime}
|
||||
*/
|
||||
public interface ${ClassName}Mapper {
|
||||
|
||||
/**
|
||||
* 查询${functionName}
|
||||
*
|
||||
* @param ${pkColumn.javaField} ${functionName}Id
|
||||
* @return ${functionName}
|
||||
*/
|
||||
${ClassName} selectById(${pkColumn.javaType} ${pkColumn.javaField});
|
||||
|
||||
/**
|
||||
* 查询${functionName}列表
|
||||
*
|
||||
* @param query ${functionName}查询
|
||||
* @return ${functionName}集合
|
||||
*/
|
||||
List<${ClassName}> selectList(${ClassName}Query query);
|
||||
|
||||
/**
|
||||
* 新增${functionName}
|
||||
*
|
||||
* @param ${className} ${functionName}
|
||||
* @return 结果
|
||||
*/
|
||||
int insert(${ClassName} ${className});
|
||||
|
||||
/**
|
||||
* 修改${functionName}
|
||||
*
|
||||
* @param ${className} ${functionName}
|
||||
* @return 结果
|
||||
*/
|
||||
int update(${ClassName} ${className});
|
||||
|
||||
/**
|
||||
* 删除${functionName}
|
||||
*
|
||||
* @param ${pkColumn.javaField} 需要删除的${functionName}Id
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteById(${pkColumn.javaType} ${pkColumn.javaField});
|
||||
|
||||
/**
|
||||
* 批量删除${functionName}
|
||||
*
|
||||
* @param ${pkColumn.javaField}List 需要删除的${functionName}Id 集合
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteBatchByIdList(List<${pkColumn.javaType}> ${pkColumn.javaField}List);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package ${packageName}.service.impl;
|
||||
|
||||
import ${packageName}.entity.${ClassName};
|
||||
import ${packageName}.entity.dto.${ClassName}Dto;
|
||||
import ${packageName}.entity.vo.${ClassName}Vo;
|
||||
import ${packageName}.entity.query.${ClassName}Query;
|
||||
import ${packageName}.mapper.${ClassName}Mapper;
|
||||
import ${packageName}.service.${ClassName}Service;
|
||||
#if($table.hasOptionApi())
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
#end
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.mybatis.utils.PageUtils;
|
||||
import cn.fateverse.common.security.utils.SecurityUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* ${functionName} Controller
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${dateTime}
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ${ClassName}ServiceImpl implements ${ClassName}Service {
|
||||
|
||||
private final ${ClassName}Mapper ${className}Mapper;
|
||||
|
||||
public ${ClassName}ServiceImpl(${ClassName}Mapper ${className}Mapper) {
|
||||
this.${className}Mapper = ${className}Mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ${ClassName}Vo searchById(${pkColumn.javaType} ${pkColumn.javaField}){
|
||||
${ClassName} ${className} = ${className}Mapper.selectById(${pkColumn.javaField});
|
||||
return ${ClassName}Vo.to${ClassName}Vo(${className});
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo<${ClassName}Vo> searchList(${ClassName}Query query){
|
||||
PageUtils.startPage();
|
||||
List<${ClassName}> list = ${className}Mapper.selectList(query);
|
||||
return PageUtils.convertDataTable(list, ${ClassName}Vo::to${ClassName}Vo);
|
||||
}
|
||||
|
||||
#if($table.hasOptionApi())
|
||||
@Override
|
||||
public List<Option> searchOptionList(){
|
||||
${ClassName}Query query = new ${ClassName}Query();
|
||||
List<${ClassName}> list = ${className}Mapper.selectList(query);
|
||||
return list.stream().map(item-> Option.builder()
|
||||
.value(item.get${table.getOptionValueFiled()}())
|
||||
.label(item.get${table.getOptionLabelFiled()}())
|
||||
.build()).collect(Collectors.toList());
|
||||
}
|
||||
#end
|
||||
|
||||
@Override
|
||||
public List<${ClassName}Vo> exportList(${ClassName}Query query){
|
||||
List<${ClassName}> list = ${className}Mapper.selectList(query);
|
||||
return list.stream().map(${ClassName}Vo::to${ClassName}Vo)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int save(${ClassName}Dto ${className}){
|
||||
${ClassName} info = ${className}.to${ClassName}();
|
||||
info.setCreateBy(SecurityUtils.getUsername());
|
||||
return ${className}Mapper.insert(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int edit(${ClassName}Dto ${className}){
|
||||
${ClassName} info = ${className}.to${ClassName}();
|
||||
info.setUpdateBy(SecurityUtils.getUsername());
|
||||
return ${className}Mapper.update(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int removeById(${pkColumn.javaType} ${pkColumn.javaField}){
|
||||
return ${className}Mapper.deleteById(${pkColumn.javaField});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int removeBatch(List<${pkColumn.javaType}> ${pkColumn.javaField}List){
|
||||
return ${className}Mapper.deleteBatchByIdList(${pkColumn.javaField}List);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package ${packageName}.mapper;
|
||||
|
||||
import ${packageName}.entity.${ClassName};
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ${functionName} Mapper
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${dateTime}
|
||||
*/
|
||||
public interface ${ClassName}Mapper extends BaseMapper<${ClassName}>{
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package ${packageName}.service.impl;
|
||||
|
||||
import ${packageName}.entity.${ClassName};
|
||||
import ${packageName}.entity.dto.${ClassName}Dto;
|
||||
import ${packageName}.entity.vo.${ClassName}Vo;
|
||||
import ${packageName}.entity.query.${ClassName}Query;
|
||||
import ${packageName}.mapper.${ClassName}Mapper;
|
||||
import ${packageName}.service.${ClassName}Service;
|
||||
#if($table.hasOptionApi())
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
#end
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.mybatisplus.utils.PageUtils;
|
||||
import cn.fateverse.common.security.utils.SecurityUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* ${functionName} Controller
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${dateTime}
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ${ClassName}ServiceImpl implements ${ClassName}Service {
|
||||
|
||||
private final ${ClassName}Mapper ${className}Mapper;
|
||||
|
||||
private final List<String> columnNames = Arrays.asList(${table.getFieldList()});
|
||||
|
||||
public ${ClassName}ServiceImpl(${ClassName}Mapper ${className}Mapper) {
|
||||
this.${className}Mapper = ${className}Mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ${ClassName}Vo searchById(${pkColumn.javaType} ${pkColumn.javaField}){
|
||||
${ClassName} ${className} = ${className}Mapper.selectById(${pkColumn.javaField});
|
||||
return ${ClassName}Vo.to${ClassName}Vo(${className});
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo<${ClassName}Vo> searchList(${ClassName}Query query){
|
||||
Page<${ClassName}> page = ${className}Mapper.selectPage(PageUtils.getPage(), buildQueryWrapper(query));
|
||||
return PageUtils.convertDataTable(page, ${ClassName}Vo::to${ClassName}Vo);
|
||||
}
|
||||
|
||||
#if($table.hasOptionApi())
|
||||
@Override
|
||||
public List<Option> searchOptionList(){
|
||||
LambdaQueryWrapper<Carousel> lqw = new LambdaQueryWrapper<>();
|
||||
List<${ClassName}> list = ${className}Mapper.selectList(lqw);
|
||||
return list.stream().map(item-> Option.builder()
|
||||
.value(item.get${table.getOptionValueFiled()})
|
||||
.label(item.get${table.getOptionLabelFiled()})
|
||||
.build()).collect(Collectors.toList())
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
@Override
|
||||
public List<${ClassName}Vo> exportList(${ClassName}Query query){
|
||||
List<${ClassName}> list = ${className}Mapper.selectList(buildQueryWrapper(query));
|
||||
return list.stream().map(${ClassName}Vo::to${ClassName}Vo)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public LambdaQueryWrapper<Carousel> buildQueryWrapper(${ClassName}Query query) {
|
||||
LambdaQueryWrapper<Carousel> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.select(Carousel.class,e->columnNames.contains(e.getColumn()))
|
||||
#foreach($column in $columns)
|
||||
#if($column.query())
|
||||
#set($mpMethod=$column.queryType.toLowerCase())
|
||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||
#if($queryType != 'BETWEEN')
|
||||
#if($column.javaType == 'String')
|
||||
#set($condition='!StrUtil.isBlank(query.get'+$AttrName+'())')
|
||||
#else
|
||||
#set($condition='query.get'+$AttrName+'() != null')
|
||||
#end
|
||||
.$mpMethod($condition, ${ClassName}::get$AttrName, query.get$AttrName())
|
||||
#else
|
||||
.between('query.getBegin$AttrName' != null && 'query.getEnd$AttrName' != null,
|
||||
${ClassName}::get$AttrName ,'query.getBegin$AttrName', 'query.getBegin$AttrName')
|
||||
#end#end#end;
|
||||
return lqw;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int save(${ClassName}Dto ${className}){
|
||||
${ClassName} info = ${className}.to${ClassName}();
|
||||
info.setCreateBy(SecurityUtils.getUsername());
|
||||
return ${className}Mapper.insert(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int edit(${ClassName}Dto ${className}){
|
||||
${ClassName} info = ${className}.to${ClassName}();
|
||||
info.setUpdateBy(SecurityUtils.getUsername());
|
||||
return ${className}Mapper.updateById(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int removeById(${pkColumn.javaType} ${pkColumn.javaField}){
|
||||
return ${className}Mapper.deleteById(${pkColumn.javaField});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int removeBatch(List<${pkColumn.javaType}> ${pkColumn.javaField}List){
|
||||
return ${className}Mapper.deleteBatchIds(${pkColumn.javaField}List);
|
||||
}
|
||||
|
||||
}
|
||||
86
visual/code-gen/src/main/resources/vm/java/service.java.vm
Normal file
86
visual/code-gen/src/main/resources/vm/java/service.java.vm
Normal file
@@ -0,0 +1,86 @@
|
||||
package ${packageName}.service;
|
||||
|
||||
import ${packageName}.entity.dto.${ClassName}Dto;
|
||||
import ${packageName}.entity.vo.${ClassName}Vo;
|
||||
import ${packageName}.entity.query.${ClassName}Query;
|
||||
#if($table.hasOptionApi())
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
#end
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ${functionName} Service
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${dateTime}
|
||||
*/
|
||||
public interface ${ClassName}Service {
|
||||
|
||||
/**
|
||||
* 查询${functionName}
|
||||
*
|
||||
* @param ${pkColumn.javaField} ${functionName}Id
|
||||
* @return ${functionName}
|
||||
*/
|
||||
${ClassName}Vo searchById(${pkColumn.javaType} ${pkColumn.javaField});
|
||||
|
||||
/**
|
||||
* 查询${functionName}列表
|
||||
*
|
||||
* @param query ${functionName}
|
||||
* @return ${functionName}集合
|
||||
*/
|
||||
TableDataInfo<${ClassName}Vo> searchList(${ClassName}Query query);
|
||||
|
||||
/**
|
||||
* 查询${functionName}option
|
||||
*
|
||||
* @return 选项集合
|
||||
*/
|
||||
#if($table.hasOptionApi())
|
||||
List<Option> searchOptionList();
|
||||
#end
|
||||
|
||||
/**
|
||||
* 导出${functionName}列表
|
||||
*
|
||||
* @param query query ${functionName}
|
||||
* @return ${functionName}集合
|
||||
*/
|
||||
List<${ClassName}Vo> exportList(${ClassName}Query query);
|
||||
|
||||
/**
|
||||
* 新增${functionName}
|
||||
*
|
||||
* @param ${className} ${functionName}
|
||||
* @return 结果
|
||||
*/
|
||||
int save(${ClassName}Dto ${className});
|
||||
|
||||
/**
|
||||
* 修改${functionName}
|
||||
*
|
||||
* @param ${className} ${functionName}
|
||||
* @return 结果
|
||||
*/
|
||||
int edit(${ClassName}Dto ${className});
|
||||
|
||||
/**
|
||||
* 删除${functionName}
|
||||
*
|
||||
* @param ${pkColumn.javaField} 需要删除的${functionName}Id
|
||||
* @return 结果
|
||||
*/
|
||||
int removeById(${pkColumn.javaType} ${pkColumn.javaField});
|
||||
|
||||
/**
|
||||
* 批量删除${functionName}
|
||||
*
|
||||
* @param ${pkColumn.javaField}List 需要删除的${functionName}Id 集合
|
||||
* @return 结果
|
||||
*/
|
||||
int removeBatch(List<${pkColumn.javaType}> ${pkColumn.javaField}List);
|
||||
|
||||
}
|
||||
54
visual/code-gen/src/main/resources/vm/react/api.ts.vm
Normal file
54
visual/code-gen/src/main/resources/vm/react/api.ts.vm
Normal file
@@ -0,0 +1,54 @@
|
||||
import request from "../../utils/http";
|
||||
|
||||
// 请求${functionName}list
|
||||
export const get${ClassName}List = (params:object|undefined) => {
|
||||
return request({
|
||||
url: '/${serviceName}/${moduleName}/${businessName}',
|
||||
method: 'get',
|
||||
params
|
||||
})
|
||||
}
|
||||
//获取到option列表
|
||||
#if($table.hasOptionApi())
|
||||
export const get${ClassName}Opt = () => {
|
||||
return request({
|
||||
url: '/${serviceName}/${moduleName}/${businessName}/option',
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
#end
|
||||
|
||||
// 获取${functionName}详情
|
||||
export const get${ClassName}Details = (${className}Id: number) => {
|
||||
return request({
|
||||
url: '/${serviceName}/${moduleName}/${businessName}/' + ${className}Id,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 新增${functionName}
|
||||
export const add${ClassName} = (data:object) => {
|
||||
return request({
|
||||
url: '/${serviceName}/${moduleName}/${businessName}',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// 修改${functionName}
|
||||
export const edit${ClassName} = (data: object) => {
|
||||
return request({
|
||||
url: '/${serviceName}/${moduleName}/${businessName}',
|
||||
method: 'put',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除${functionName}
|
||||
export const del${ClassName} =(${className}Id: number) => {
|
||||
return request({
|
||||
url: '/${serviceName}/${moduleName}/${businessName}/' + ${className}Id,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
10
visual/code-gen/src/main/resources/vm/react/type.ts.vm
Normal file
10
visual/code-gen/src/main/resources/vm/react/type.ts.vm
Normal file
@@ -0,0 +1,10 @@
|
||||
import { IBaseDataType } from "..";
|
||||
|
||||
// 表格${functionName}数据类型规范
|
||||
export interface ${ClassName}Type extends IBaseDataType {
|
||||
#foreach ($column in $columns)
|
||||
#if(!$column.isSuperColumn($column.javaField))
|
||||
${column.javaField}:#if("String" == $column.javaType) string#else number#end,
|
||||
#end
|
||||
#end
|
||||
}
|
||||
323
visual/code-gen/src/main/resources/vm/react/view.tsx.vm
Normal file
323
visual/code-gen/src/main/resources/vm/react/view.tsx.vm
Normal file
@@ -0,0 +1,323 @@
|
||||
import { Button, Col, Form, Input, message, Modal, Radio, Row, Space } from "antd";
|
||||
import { PlusCircleTwoTone, EditTwoTone, DeleteTwoTone, ExclamationCircleOutlined } from '@ant-design/icons'
|
||||
import Table, { ColumnsType } from "antd/lib/table";
|
||||
import { TableRowSelection } from "antd/lib/table/interface";
|
||||
import React, { Fragment, useEffect, useReducer, useState } from "react";
|
||||
import { get${ClassName}List, get${ClassName}Details, add${ClassName}, edit${ClassName}, del${ClassName} } from "../../api/${businessName}";
|
||||
#if($table.hasDictSelect())
|
||||
import { DTag } from "../../components/DTag";
|
||||
import { getCacheType } from "../../utils/cache";
|
||||
#end
|
||||
import SearchForm from "../../components/SearchForm";
|
||||
import { IModalConfig, IResponse } from "../../type";
|
||||
import { DataType } from "../../type/${businessName}";
|
||||
import confirm from "antd/lib/modal/confirm";
|
||||
import { parseDateTime, queryReducer, reducerPagination } from "../../utils/tool";
|
||||
|
||||
|
||||
// 初始化搜索条件
|
||||
const initQueryParams = {
|
||||
#foreach ($column in $columns)
|
||||
#if("1" == $column.isQuery)
|
||||
$column.javaField:#if("String" == $column.javaType) ''#else undefined#end,
|
||||
#end
|
||||
#end
|
||||
pageSize: 10,
|
||||
pageNum: 1
|
||||
}
|
||||
|
||||
const reducerSearch = (state: any, newState: any) =>{
|
||||
return {
|
||||
#foreach ($column in $columns)
|
||||
#if("1" == $column.isQuery)
|
||||
$column.javaField: state.$column.javaField = newState.$column.javaField,
|
||||
#end
|
||||
#end
|
||||
pageSize: state.pageSize = newState.pageSize,
|
||||
pageNum: state.pageNum = newState.pageNum,
|
||||
}
|
||||
}
|
||||
function ${ClassName}() {
|
||||
//搜索条件
|
||||
const [queryParams, setQueryParams] = useReducer( queryReducer ,initQueryParams)
|
||||
#foreach ($column in $columns)
|
||||
#if("select" == $column.htmlType && ${table.strNotEmpty($column.dictType)})
|
||||
//todo字典 下拉框options 动态判断
|
||||
const [${column.javaField}OptionList, set${table.capitalize($column.javaField)}OptionList] = useState<any>([])
|
||||
//单选options
|
||||
const [${column.javaField}RadioOption, set${table.capitalize($column.javaField)}RadioOption] = useState<any>()
|
||||
#end
|
||||
#end
|
||||
//数据总数
|
||||
const [total, setTotal] = useState<number>()
|
||||
//表格list
|
||||
const [list, setList] = useState<Array<DataType>>()
|
||||
//表格数据加载中
|
||||
const [loading, setLoading] = useState<boolean>(false)
|
||||
//表格多选是否勾选
|
||||
const [checkStrictly, setCheckStrictly] = useState(false);
|
||||
//弹窗config
|
||||
const [modalConfig, setModalConfig] = useState<IModalConfig>();
|
||||
//formHooks
|
||||
const [form] = Form.useForm()
|
||||
//所选数据id
|
||||
const [${pkColumn.javaField}, set${table.capitalize($pkColumn.javaField)}] = useState<number>()
|
||||
//所选数据ids
|
||||
const [${pkColumn.javaField}s, set${table.capitalize($pkColumn.javaField)}s] = useState<Array<any>>([])
|
||||
//筛选表单配置
|
||||
const searchConfig = {
|
||||
name: 'searchForm',
|
||||
formItem: [
|
||||
#foreach ($column in $columns)
|
||||
#if("1" == $column.isQuery)
|
||||
{
|
||||
name: '${column.columnComment}',
|
||||
type: '${column.htmlType}',
|
||||
key: '${column.javaField}',
|
||||
#if("select"==$column.htmlType)
|
||||
options: ${column.javaField}OptionList
|
||||
#end
|
||||
},
|
||||
#end
|
||||
#end
|
||||
]
|
||||
} as object
|
||||
// 表格列数据
|
||||
const colums: ColumnsType<DataType> = [
|
||||
#foreach ($column in $columns)
|
||||
#if("1" == $column.isList)
|
||||
{
|
||||
title: '${column.columnComment}',
|
||||
key: '${column.javaField}',
|
||||
dataIndex: '${column.javaField}',
|
||||
#if("select" == $column.htmlType && ${table.strNotEmpty($column.dictType)})
|
||||
render: ((_, { ${column.javaField} }) => {
|
||||
return (
|
||||
<DTag options={${column.javaField}OptionList} state={${column.javaField}} />
|
||||
)
|
||||
})
|
||||
#end
|
||||
},
|
||||
#end
|
||||
#end
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
align: 'center',
|
||||
render: ((_, record) => (
|
||||
<Space size="middle">
|
||||
<Button type="link" onClick={() => handleEdit(record)}>修改</Button>
|
||||
<Button type="text" onClick={() => handleDel(record)} danger>删除</Button>
|
||||
</Space>
|
||||
))
|
||||
}
|
||||
]
|
||||
//获取${functionName}list
|
||||
const getList = () => {
|
||||
setLoading(true)
|
||||
get${ClassName}List(queryParams).then((res: IResponse) => {
|
||||
setList(res.data.rows)
|
||||
setTotal(res.data.total)
|
||||
setLoading(false)
|
||||
})
|
||||
}
|
||||
// 点击添加
|
||||
const handleAdd = () => {
|
||||
#foreach ($column in $columns)
|
||||
#if("1" == $column.isInsert && "select" == $column.htmlType && ${table.strNotEmpty($column.dictType)})
|
||||
set${table.capitalize($column.javaField)}RadioOption(${column.javaField}OptionList)
|
||||
#end
|
||||
#end
|
||||
setModalConfig({ title: '添加', open: true, confirmLoading: false })
|
||||
}
|
||||
// 点击修改
|
||||
const handleEdit = (row:any) => {
|
||||
const ${pkColumn.javaField} = row.${pkColumn.javaField}|| ${pkColumn.javaField}s[0];
|
||||
set${table.capitalize($pkColumn.javaField)}(${pkColumn.javaField});
|
||||
#foreach ($column in $columns)
|
||||
#if("1" == $column.isInsert && "select" == $column.htmlType && ${table.strNotEmpty($column.dictType)})
|
||||
set${table.capitalize($column.javaField)}RadioOption(${column.javaField}OptionList)
|
||||
#end
|
||||
#end
|
||||
get${ClassName}Details(${pkColumn.javaField}).then((res: IResponse) => {
|
||||
form.setFieldsValue({...res.data})
|
||||
setModalConfig({ title: '修改', open: true, confirmLoading: false })
|
||||
})
|
||||
}
|
||||
// 点击删除
|
||||
const handleDel = (row:any) => {
|
||||
const ${pkColumn.javaField} = row.${pkColumn.javaField} || ${pkColumn.javaField}s[0];
|
||||
confirm({
|
||||
title: '确定删除这一项吗?',
|
||||
icon: <ExclamationCircleOutlined />,
|
||||
content: `详情主键为: `+ row.${pkColumn.javaField},
|
||||
onOk() {
|
||||
del${ClassName}(${pkColumn.javaField}).then((res: IResponse) => {
|
||||
if (res.code === 1000) {
|
||||
message.success(res.msg)
|
||||
getList()
|
||||
} else {
|
||||
message.error(res.msg)
|
||||
}
|
||||
})
|
||||
},
|
||||
onCancel() {
|
||||
},
|
||||
});
|
||||
}
|
||||
// 点击提交
|
||||
const handleSubmit = () => {
|
||||
const obj = form.getFieldsValue();
|
||||
if(modalConfig?.title === '添加') {
|
||||
add${ClassName}(obj).then((res: IResponse) => {
|
||||
setModalConfig({ title: '添加', open: true, confirmLoading: true })
|
||||
if(res.code === 1000) {
|
||||
message.success('添加成功');
|
||||
setModalConfig({ title: '添加', open: true, confirmLoading: false })
|
||||
handleCancel()
|
||||
getList()
|
||||
}else {
|
||||
message.error(res.msg);
|
||||
setModalConfig({ title: '添加', open: true, confirmLoading: false })
|
||||
}
|
||||
})
|
||||
}else {
|
||||
const objE = {${pkColumn.javaField}, ...obj}
|
||||
edit${ClassName}(objE).then((res: IResponse) => {
|
||||
setModalConfig({ title: '修改', open: true, confirmLoading: true })
|
||||
if (res.code === 1000) {
|
||||
message.success('修改成功')
|
||||
setModalConfig({ title: '修改', open: true, confirmLoading: false })
|
||||
handleCancel()
|
||||
getList()
|
||||
} else {
|
||||
message.error(res.msg)
|
||||
setModalConfig({ title: '修改', open: true, confirmLoading: false })
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
// 点击取消
|
||||
const handleCancel = () => {
|
||||
form.resetFields();
|
||||
setModalConfig({ title: '', open: false, confirmLoading: false })
|
||||
}
|
||||
// 分页
|
||||
const pagination = (pageNum: any,pageSize: any) => {
|
||||
new Promise((resolve,reject) => {
|
||||
setQueryParams({type: 'pagination', data: {pageNum,pageSize }})
|
||||
resolve(true)
|
||||
}).then((res: any) => {
|
||||
getList()
|
||||
})
|
||||
}
|
||||
// 行数据选择
|
||||
const rowSelection: TableRowSelection<DataType> = {
|
||||
onChange: (selectedRowKeys, selectedRows) => {
|
||||
console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
|
||||
set${table.capitalize($pkColumn.javaField)}s(Array.from(selectedRowKeys))
|
||||
},
|
||||
onSelect: (record, selected, selectedRows) => {
|
||||
console.log(record, selected, selectedRows);
|
||||
},
|
||||
onSelectAll: (selected, selectedRows, changeRows) => {
|
||||
console.log(selected, selectedRows, changeRows);
|
||||
},
|
||||
};
|
||||
|
||||
// 筛选表单提交事件
|
||||
const submit = (v: any) => {
|
||||
const {#foreach ($column in $columns)#if("1" == $column.isQuery)${column.javaField}, #end#end} = v
|
||||
const query = {
|
||||
#foreach ($column in $columns)
|
||||
#if("1" == $column.isQuery)
|
||||
${column.javaField},
|
||||
#end
|
||||
#end
|
||||
pageSize: 10,
|
||||
pageNum: 1
|
||||
}
|
||||
new Promise( (resolve, reject) => {
|
||||
setQueryParams({ type: 'search', data: query, void: reducerSearch})
|
||||
resolve(true)
|
||||
}).then((res)=>{
|
||||
getList()
|
||||
})
|
||||
}
|
||||
|
||||
#if($table.hasDictSelect())
|
||||
//获取筛选表单下拉框缓存数据
|
||||
const getSelectOptions = async () => {
|
||||
#foreach ($column in $columns)
|
||||
#if("1" == $column.isInsert && "select" == $column.htmlType && ${table.strNotEmpty($column.dictType)})
|
||||
const ${column.javaField}Options = await getCacheType('${column.dictType}').then((options: any) => {
|
||||
return options
|
||||
})
|
||||
set${table.capitalize($column.javaField)}OptionList(${column.javaField}Options)
|
||||
#end
|
||||
#end
|
||||
}
|
||||
#end
|
||||
useEffect(() => {
|
||||
getSelectOptions();
|
||||
getList()
|
||||
}, [])
|
||||
return (
|
||||
<Fragment>
|
||||
<SearchForm config={searchConfig} submit={submit}/>
|
||||
<div className="table-headbtn-box">
|
||||
<Button icon={<PlusCircleTwoTone />} type="primary" size="middle" className="table-headbtn" onClick={handleAdd}>添加</Button>
|
||||
<Button icon={<EditTwoTone />} type="primary" ghost className="table-headbtn" onClick={handleEdit} disabled={${pkColumn.javaField}s.length != 1} >修改</Button>
|
||||
<Button icon={<DeleteTwoTone />} type="primary" danger className="table-headbtn" disabled={${pkColumn.javaField}s.length != 1} >删除</Button>
|
||||
</div>
|
||||
<Table
|
||||
columns={colums}
|
||||
dataSource={list}
|
||||
loading={loading}
|
||||
rowSelection={{ ...rowSelection, checkStrictly }}
|
||||
pagination={{ total, onChange: pagination }}
|
||||
rowKey='${pkColumn.javaField}'
|
||||
/>
|
||||
<Modal
|
||||
open={modalConfig?.open}
|
||||
title={modalConfig?.title}
|
||||
onOk={handleSubmit}
|
||||
onCancel={handleCancel}
|
||||
confirmLoading={modalConfig?.confirmLoading}
|
||||
width={700}
|
||||
>
|
||||
<Form
|
||||
name="form"
|
||||
form={form}
|
||||
labelAlign='right'
|
||||
labelCol={{
|
||||
span: 6,
|
||||
offset: 0
|
||||
}}
|
||||
>
|
||||
<Row>
|
||||
#foreach ($column in $columns)
|
||||
#if("1" == $column.isInsert || "1" == $column.isEdit)
|
||||
<Col span={12}>
|
||||
<Form.Item
|
||||
label="${column.columnComment}"
|
||||
name="${column.javaField}"
|
||||
required
|
||||
>
|
||||
#if("select" == $column.htmlType && ${table.strNotEmpty($column.dictType)})
|
||||
<Radio.Group options={${column.javaField}RadioOption} />
|
||||
#else
|
||||
<Input placeholder="请输入${column.columnComment}" />
|
||||
#end
|
||||
</Form.Item>
|
||||
</Col>
|
||||
#end
|
||||
#end
|
||||
</Row>
|
||||
</Form>
|
||||
</Modal>
|
||||
</Fragment>
|
||||
)
|
||||
}
|
||||
|
||||
export default ${ClassName};
|
||||
55
visual/code-gen/src/main/resources/vm/vue/api.js.vm
Normal file
55
visual/code-gen/src/main/resources/vm/vue/api.js.vm
Normal file
@@ -0,0 +1,55 @@
|
||||
import request from '@/utils/request.js'
|
||||
|
||||
// 请求${functionName}list
|
||||
export const get${ClassName}List = (params) => {
|
||||
return request({
|
||||
url: '/${serviceName}/${moduleName}/${businessName}',
|
||||
method: 'get',
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
//获取到option列表
|
||||
#if($table.hasOptionApi())
|
||||
export const get${ClassName}Opt = () => {
|
||||
return request({
|
||||
url: '/${serviceName}/${moduleName}/${businessName}/option',
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
#end
|
||||
|
||||
// 获取${functionName}详情
|
||||
export const get${ClassName}Details = (${className}Id) => {
|
||||
return request({
|
||||
url: '/${serviceName}/${moduleName}/${businessName}/' + ${className}Id,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 新增${functionName}
|
||||
export const add${ClassName} = (data) => {
|
||||
return request({
|
||||
url: '/${serviceName}/${moduleName}/${businessName}',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// 修改${functionName}
|
||||
export const edit${ClassName} = (data) => {
|
||||
return request({
|
||||
url: '/${serviceName}/${moduleName}/${businessName}',
|
||||
method: 'put',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除${functionName}
|
||||
export const del${ClassName} =(${className}Id) => {
|
||||
return request({
|
||||
url: '/${serviceName}/${moduleName}/${businessName}/' + ${className}Id,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
353
visual/code-gen/src/main/resources/vm/vue/index.vue.vm
Normal file
353
visual/code-gen/src/main/resources/vm/vue/index.vue.vm
Normal file
@@ -0,0 +1,353 @@
|
||||
<template>
|
||||
<el-form :model="queryParams" inline class="query-form" ref="queryForm">
|
||||
#foreach($column in $columns)
|
||||
#if($column.query())
|
||||
#set($comment=$column.comment())
|
||||
#if($column.isInput())
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-input v-model="queryParams.${column.javaField}" placeholder="请输${comment}"></el-input>
|
||||
</el-form-item>
|
||||
#elseif(($column.isSelect() || $column.isRadio()) && $column.isDict())
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable >
|
||||
<el-option
|
||||
v-for="dict in cacheStore.getDict('${column.dictType}')"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
#elseif(($column.isSelect() || $column.isRadio()) && !$column.isDict())
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable >
|
||||
<el-option label="请选择字典生成" value="" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
#elseif($column.isDatetime() && !$column.isBetween())
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-date-picker clearable size="small"
|
||||
v-model="queryParams.${column.javaField}"
|
||||
type="date"
|
||||
value-format="yyyy-MM-dd"
|
||||
placeholder="选择${comment}">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
#elseif($column.isDatetime() && $column.isBetween())
|
||||
<el-form-item label="${comment}">
|
||||
<el-date-picker
|
||||
v-model="daterange${column.getAttrName()}"
|
||||
size="small"
|
||||
style="width: 240px"
|
||||
value-format="yyyy-MM-dd"
|
||||
type="daterange"
|
||||
range-separator="-"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
></el-date-picker>
|
||||
</el-form-item>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="handleSearch()" :icon="Search">搜索</el-button>
|
||||
<el-button @click="handleReset" :icon="Refresh">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div class="query-btn">
|
||||
<el-button type="primary" v-perm="['${permissionPrefix}:add']" @click="handleAdd" :icon="Plus" plain>新增</el-button>
|
||||
<el-button type="danger" v-perm="['${permissionPrefix}:del']" @click="handleDelete" :icon="Delete" plain :disabled="disabled">删除</el-button>
|
||||
<el-button type="warning" v-perm="['${permissionPrefix}:export']" @click="handleExport" :icon="Download" plain>导出</el-button>
|
||||
</div>
|
||||
<div class="table">
|
||||
<el-table
|
||||
:data="list"
|
||||
row-key="${pkColumn.javaField}"
|
||||
:lazy="true"
|
||||
ref="singleTable"
|
||||
v-loading="loading"
|
||||
@select="handleSelect"
|
||||
>
|
||||
<el-table-column type="selection" width="55"/>
|
||||
<el-table-column label="序号" type="index" class-name="allowDrag"/>
|
||||
#foreach($column in $columns)
|
||||
#if($column.list())
|
||||
#set($comment=$column.comment())
|
||||
#if($column.listAndDict())
|
||||
<el-table-column prop="${column.javaField}" label="${comment}" align="center">
|
||||
<template #default="scope">
|
||||
<tag dict-type="${column.dictType}" :value="scope.row.${column.javaField}"/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
#else
|
||||
<el-table-column prop="${column.javaField}" label="${comment}" align="center"/>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
<el-table-column label="操作">
|
||||
<template #default="scope">
|
||||
<el-button type="text" size="mini" v-perm="['${permissionPrefix}:edit']"
|
||||
@click="handleEdit(scope.row.${pkColumn.javaField})" :icon="Edit">编辑
|
||||
</el-button>
|
||||
<el-button type="text" size="mini" v-perm="['${permissionPrefix}:del']" @click="handleDelete(scope.row)"
|
||||
:icon="Delete">删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
<el-config-provider>
|
||||
<el-pagination
|
||||
v-model:current-page="pageInfo.pageNum"
|
||||
v-model:page-size="pageInfo.pageSize"
|
||||
:page-sizes="[10, 20, 30, 40,50]"
|
||||
:background="true"
|
||||
layout="->,total, sizes, prev, pager, next, jumper"
|
||||
:total="total"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
/>
|
||||
</el-config-provider>
|
||||
|
||||
<el-dialog v-model="isVisited" :title="title" width="900px">
|
||||
<el-form :model="form" ref="formInstance" :rules="formRules" label-width="100px" class="dialog-form">
|
||||
<el-row>
|
||||
#foreach($column in $columns)
|
||||
#if($column.from())
|
||||
#set($comment=$column.comment())
|
||||
#if($velocityCount % 2 == 1)
|
||||
<el-col :span="11" :offset="2">
|
||||
#else
|
||||
<el-col :span="11">
|
||||
#end
|
||||
#if($column.isInput())
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-input v-model="form.${column.javaField}" placeholder="请输入${comment}"></el-input>
|
||||
</el-form-item>
|
||||
#elseif($column.isSelect() && $column.isDict())
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-select v-model="form.${column.javaField}" placeholder="请选择${comment}" clearable >
|
||||
<el-option
|
||||
v-for="dict in cacheStore.getDict('${column.dictType}')"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
#elseif($column.isSelect() && !$column.isDict())
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-select v-model="form.${column.javaField}" placeholder="请选择${comment}">
|
||||
<el-option label="请选择字典生成" value="" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
#end
|
||||
</el-col>
|
||||
#end
|
||||
#end
|
||||
</el-row>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<span>
|
||||
<el-button @click="handleCancel">取消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit(formInstance)">确定</el-button>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { get${ClassName}List, get${ClassName}Details, add${ClassName}, edit${ClassName}, del${ClassName} } from "@/api/${moduleName}/${businessName}";
|
||||
import {Search, Refresh, Delete, Plus, Edit, Download} from '@element-plus/icons-vue'
|
||||
import {ElMessage, ElMessageBox} from "element-plus";
|
||||
#if($table.hasDictSelect())
|
||||
import { useCacheStore } from '@/stores/cache.js'
|
||||
const cacheStore = useCacheStore()
|
||||
cacheStore.setCacheKey([${table.getDictType()}])
|
||||
#end
|
||||
#if($table.hasListAndDict())
|
||||
import Tag from '@/components/Tag.vue'
|
||||
#end
|
||||
import {downLoadExcel} from "@/utils/downloadZip";
|
||||
//查询参数
|
||||
const queryParams = reactive({
|
||||
#foreach ($column in $columns)
|
||||
#if($column.query())
|
||||
$column.javaField:#if("String" == $column.javaType) ''#else undefined#end,
|
||||
#end
|
||||
#end
|
||||
})
|
||||
//页面信息
|
||||
const pageInfo = reactive({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
})
|
||||
const disabled = ref(true)
|
||||
const list = ref([])
|
||||
const queryForm = ref([])
|
||||
const loading = ref(true)
|
||||
const total = ref()
|
||||
const title = ref('')
|
||||
const isVisited = ref(false)
|
||||
const form = ref()
|
||||
const formInstance = ref()
|
||||
const formRules = ref({
|
||||
#foreach ($column in $columns)
|
||||
#if($column.required())
|
||||
#set($comment=$column.comment())
|
||||
$column.javaField: [
|
||||
{ required: true, message: "${comment}不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end },
|
||||
#if($column.isRegular != 1)
|
||||
{ pattern: /${column.regular}/, message: '${column.columnComment}格式有误', trigger:"blur"},
|
||||
#end
|
||||
]#if($velocityCount != $columns.size()),#end
|
||||
|
||||
#end
|
||||
#end
|
||||
})
|
||||
//搜索功能
|
||||
const handleSearch = () => {
|
||||
getList()
|
||||
}
|
||||
//重置搜索
|
||||
const handleReset = () => {
|
||||
queryForm.value.resetFields()
|
||||
getList()
|
||||
}
|
||||
//获取数据
|
||||
const getList = async () => {
|
||||
let params = {
|
||||
...queryParams,
|
||||
...pageInfo
|
||||
}
|
||||
get${ClassName}List(params).then(res => {
|
||||
if (res.code === 1000) {
|
||||
list.value = res.data.rows
|
||||
total.value = res.data.total
|
||||
loading.value = false
|
||||
} else {
|
||||
ElMessage.error(res.msg)
|
||||
}
|
||||
})
|
||||
}
|
||||
//重置from表单
|
||||
const restFrom = () => {
|
||||
form.value = {
|
||||
#foreach ($column in $columns)
|
||||
#if($column.from())
|
||||
#if($column.fromValue())
|
||||
#if($column.isRadio())
|
||||
$column.javaField: ${column.getDefaultRadio()}#if($velocityCount != $columns.size()),#end
|
||||
#elseif($column.isCheckbox())
|
||||
$column.javaField: []#if($velocityCount != $columns.size()),#end
|
||||
#else
|
||||
$column.javaField: null#if($velocityCount != $columns.size()),#end
|
||||
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
}
|
||||
}
|
||||
//取消
|
||||
const handleCancel = () => {
|
||||
restFrom()
|
||||
isVisited.value = false
|
||||
}
|
||||
//提交
|
||||
const handleSubmit = async (instance) => {
|
||||
if (!instance) return
|
||||
instance.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
if (title.value === '新增${functionName}') {
|
||||
add${ClassName}(form.value).then(res => {
|
||||
if (res.code === 1000) {
|
||||
ElMessage.success(res.msg)
|
||||
getList()
|
||||
isVisited.value = false
|
||||
} else {
|
||||
ElMessage.error(res.msg)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
edit${ClassName}(form.value).then(res => {
|
||||
if (res.code === 1000) {
|
||||
ElMessage.success(res.msg)
|
||||
getList()
|
||||
isVisited.value = false
|
||||
} else {
|
||||
ElMessage.error(res.msg)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
//添加
|
||||
const handleAdd = async () => {
|
||||
restFrom()
|
||||
title.value = "新增${functionName}"
|
||||
isVisited.value = true
|
||||
}
|
||||
//修改
|
||||
const handleEdit = async (${pkColumn.javaField}) => {
|
||||
restFrom()
|
||||
get${ClassName}Details(${pkColumn.javaField}).then(res => {
|
||||
if (res.code === 1000) {
|
||||
form.value = res.data
|
||||
title.value = "编辑${functionName}"
|
||||
isVisited.value = true
|
||||
} else {
|
||||
ElMessage.error(res.msg)
|
||||
}
|
||||
})
|
||||
}
|
||||
//导出excel
|
||||
const handleExport = () => {
|
||||
downLoadExcel('/${serviceName}/${moduleName}/${businessName}/export',{...queryParams})
|
||||
}
|
||||
|
||||
//勾选table数据行的 Checkbox
|
||||
const handleSelect = async (selection, row) => {
|
||||
if (selection.length !== 0) {
|
||||
disabled.value = false
|
||||
${pkColumn.javaField}.value = row.${pkColumn.javaField}
|
||||
if (selection.length > 1) {
|
||||
const del_row = selection.shift();
|
||||
singleTable.value.toggleRowSelection(del_row, false);
|
||||
}
|
||||
} else {
|
||||
disabled.value = true
|
||||
}
|
||||
}
|
||||
|
||||
//切换每页显示条数
|
||||
const handleSizeChange = async (val) => {
|
||||
pageInfo.value.pageSize = val
|
||||
await getList()
|
||||
}
|
||||
|
||||
//点击页码进行分页功能
|
||||
const handleCurrentChange = async (val) => {
|
||||
pageInfo.value.pageNum = val
|
||||
await getList()
|
||||
}
|
||||
//删除
|
||||
const handleDelete = async ({dsName, ${pkColumn.javaField}}) => {
|
||||
ElMessageBox.confirm(`确认删除名称为${dsName}的${functionName}吗?`, '系统提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
del${ClassName}(${pkColumn.javaField}).then(res => {
|
||||
if (res.code === 1000) {
|
||||
ElMessage.success(res.msg)
|
||||
getList()
|
||||
} else {
|
||||
ElMessage.error(res.msg)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
getList()
|
||||
</script>
|
||||
121
visual/code-gen/src/main/resources/vm/xml/mapperMySql.xml.vm
Normal file
121
visual/code-gen/src/main/resources/vm/xml/mapperMySql.xml.vm
Normal file
@@ -0,0 +1,121 @@
|
||||
<?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="${packageName}.mapper.${ClassName}Mapper">
|
||||
|
||||
<resultMap id="${className}Result" type="${packageName}.entity.${ClassName}">
|
||||
<id column="${pkColumn.columnName}" property="${pkColumn.javaField}"/>
|
||||
#foreach($column in $columns)
|
||||
#if("1" != $column.isPk)
|
||||
<result column="${column.columnName}" property="${column.javaField}"/>
|
||||
#end
|
||||
#end
|
||||
</resultMap>
|
||||
<sql id="selectVo">
|
||||
select #foreach($column in $columns)${column.columnName}#if($velocityCount != $columns.size()), #end
|
||||
#end
|
||||
from ${tableName}
|
||||
</sql>
|
||||
|
||||
|
||||
|
||||
<select id="selectList" resultMap="${className}Result">
|
||||
<include refid="selectVo"/>
|
||||
<where>
|
||||
#foreach($column in $columns)
|
||||
#set($queryType=$column.queryType)
|
||||
#set($javaField=$column.javaField)
|
||||
#set($javaType=$column.javaType)
|
||||
#set($columnName=$column.columnName)
|
||||
#if("1" == $column.isQuery)
|
||||
#if($column.queryType == "EQ")
|
||||
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName = #{$javaField}</if>
|
||||
#elseif($queryType == "NE")
|
||||
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName != #{$javaField}</if>
|
||||
#elseif($queryType == "GT")
|
||||
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName > #{$javaField}</if>
|
||||
#elseif($queryType == "GTE")
|
||||
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName >= #{$javaField}</if>
|
||||
#elseif($queryType == "LT")
|
||||
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName < #{$javaField}</if>
|
||||
#elseif($queryType == "LTE")
|
||||
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName <= #{$javaField}</if>
|
||||
#elseif($queryType == "LIKE")
|
||||
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName like concat('%', #{$javaField}, '%')</if>
|
||||
#elseif($queryType == "BETWEEN")
|
||||
#set($AttrName=${table.capitalize($javaField)})
|
||||
<if test="begin${AttrName} != null and end${AttrName} != null"> and $columnName between #{begin${AttrName}} and #{end${AttrName}}</if>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectById" resultMap="${className}Result">
|
||||
<include refid="selectVo"/>
|
||||
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
|
||||
</select>
|
||||
|
||||
<insert id="insert" #if($pkColumn.increment)useGeneratedKeys="true" keyProperty="$pkColumn.javaField"#end>
|
||||
insert into ${tableName}
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
#foreach($column in $columns)
|
||||
#if(!$column.isSuperColumn($column.javaField))
|
||||
#if(($column.columnName != $pkColumn.columnName || !$pkColumn.increment) && $column.isInsert == 1)
|
||||
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName,</if>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#if($table.hasCreateXMLColumns())
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
<if test="createTime != null ">create_time,</if>
|
||||
#end
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
#foreach($column in $columns)
|
||||
#if(!$column.isSuperColumn($column.javaField))
|
||||
#if(($column.columnName != $pkColumn.columnName || !$pkColumn.increment) && $column.isInsert == 1)
|
||||
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">#{$column.javaField},</if>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#if($table.hasCreateXMLColumns())
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
<if test="createTime != null ">#{createTime},</if>
|
||||
#end
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update ${tableName}
|
||||
<set>
|
||||
#foreach($column in $columns)
|
||||
#if(!$column.isSuperColumn($column.javaField))
|
||||
#if(($column.columnName != $pkColumn.columnName || !$pkColumn.increment) && $column.isInsert == 1)
|
||||
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName = #{$column.javaField},</if>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#if($table.hasUpdateXMLColumns())
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null ">update_time = #{updateTime},</if>
|
||||
#end
|
||||
</set>
|
||||
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
|
||||
</update>
|
||||
|
||||
<delete id="deleteById">
|
||||
delete from ${tableName}
|
||||
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteBatchByIdList" parameterType="${pkColumn.javaType}">
|
||||
delete from ${tableName}
|
||||
where ${pkColumn.columnName} in
|
||||
<foreach collection="list" open="(" close=")" separator="," item="${pkColumn.javaField}">
|
||||
#{${pkColumn.javaField}}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
121
visual/code-gen/src/main/resources/vm/xml/mapperOracle.xml.vm
Normal file
121
visual/code-gen/src/main/resources/vm/xml/mapperOracle.xml.vm
Normal file
@@ -0,0 +1,121 @@
|
||||
<?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="${packageName}.mapper.${ClassName}Mapper">
|
||||
|
||||
<resultMap id="${className}Result" type="${packageName}.entity.${ClassName}">
|
||||
<id column="${pkColumn.columnName}" property="${pkColumn.javaField}"/>
|
||||
#foreach($column in $columns)
|
||||
#if("1" != $column.isPk)
|
||||
<result column="${column.columnName}" property="${column.javaField}"/>
|
||||
#end
|
||||
#end
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectVo">
|
||||
select #foreach($column in $columns)${column.columnName}#if($velocityCount != $columns.size()), #end
|
||||
#end
|
||||
from ${tableName}
|
||||
</sql>
|
||||
|
||||
|
||||
|
||||
<select id="selectList" resultMap="${className}Result">
|
||||
<include refid="selectVo"/>
|
||||
<where>
|
||||
#foreach($column in $columns)
|
||||
#set($queryType=$column.queryType)
|
||||
#set($javaField=$column.javaField)
|
||||
#set($javaType=$column.javaType)
|
||||
#set($columnName=$column.columnName)
|
||||
#if("1" == $column.isQuery)
|
||||
#if($column.queryType == "EQ")
|
||||
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName = #{$javaField}</if>
|
||||
#elseif($queryType == "NE")
|
||||
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName != #{$javaField}</if>
|
||||
#elseif($queryType == "GT")
|
||||
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName > #{$javaField}</if>
|
||||
#elseif($queryType == "GTE")
|
||||
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName >= #{$javaField}</if>
|
||||
#elseif($queryType == "LT")
|
||||
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName < #{$javaField}</if>
|
||||
#elseif($queryType == "LTE")
|
||||
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName <= #{$javaField}</if>
|
||||
#elseif($queryType == "LIKE")
|
||||
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName like concat(concat('%', #{$javaField}),'%')</if>
|
||||
#elseif($queryType == "BETWEEN")
|
||||
#set($AttrName=${table.capitalize($javaField)})
|
||||
<if test="begin${AttrName} != null and end${AttrName} != null"> and $columnName between #{begin${AttrName}} and #{end${AttrName}}</if>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectById" resultMap="${className}Result">
|
||||
<include refid="selectVo"/>
|
||||
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
|
||||
</select>
|
||||
|
||||
<insert id="insert${ClassName}" #if($pkColumn.increment)useGeneratedKeys="true" keyProperty="$pkColumn.javaField"#end>
|
||||
insert into ${tableName}
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
#foreach($column in $columns)
|
||||
#if(!$column.isSuperColumn($column.javaField))
|
||||
#if(($column.columnName != $pkColumn.columnName || !$pkColumn.increment) && $column.isInsert == 1)
|
||||
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName,</if>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#if($table.hasCreateXMLColumns())
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
<if test="createTime != null ">create_time,</if>
|
||||
#end
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
#foreach($column in $columns)
|
||||
#if(!$column.isSuperColumn($column.javaField))
|
||||
#if(($column.columnName != $pkColumn.columnName || !$pkColumn.increment) && $column.isInsert == 1)
|
||||
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">#{$column.javaField},</if>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#if($table.hasCreateXMLColumns())
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
<if test="createTime != null ">#{createTime},</if>
|
||||
#end
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update ${tableName}
|
||||
<set>
|
||||
#foreach($column in $columns)
|
||||
#if(!$column.isSuperColumn($column.javaField))
|
||||
#if(($column.columnName != $pkColumn.columnName || !$pkColumn.increment) && $column.isInsert == 1)
|
||||
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName = #{$column.javaField},</if>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#if($table.hasUpdateXMLColumns())
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null ">update_time = #{updateTime},</if>
|
||||
#end
|
||||
</set>
|
||||
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
|
||||
</update>
|
||||
|
||||
<delete id="deleteById">
|
||||
delete from ${tableName}
|
||||
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteBatchByIdList" parameterType="${pkColumn.javaType}">
|
||||
delete from ${tableName}
|
||||
where ${pkColumn.columnName} in
|
||||
<foreach collection="list" open="(" close=")" separator="," item="${pkColumn.javaField}">
|
||||
#{${pkColumn.javaField}}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
92
visual/custom-query/pom.xml
Normal file
92
visual/custom-query/pom.xml
Normal file
@@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>visual</artifactId>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>custom-query</artifactId>
|
||||
<description>自定义查询模块</description>
|
||||
<properties>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>common-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>common-swagger</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>common-log</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>common-mybatis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>common-decrypt</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>admin-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>common-seata</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mariadb.jdbc</groupId>
|
||||
<artifactId>mariadb-java-client</artifactId>
|
||||
<version>2.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>common-code</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>common-excel</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>2.7.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.fateverse.query;
|
||||
|
||||
import cn.fateverse.common.security.annotation.EnableSecurity;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/10
|
||||
*/
|
||||
@EnableSecurity
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class CustomQueryApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CustomQueryApplication.class, args);
|
||||
System.out.println("自定义查询启动");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package cn.fateverse.query.aspect;
|
||||
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import cn.fateverse.query.entity.DataSourceManage;
|
||||
import cn.fateverse.query.factory.DynamicDataSourceService;
|
||||
import cn.fateverse.query.mapper.DataSourceManageMapper;
|
||||
import cn.fateverse.query.mapper.DynamicDataSourceMapper;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2023-07-16
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
public class DynamicDataSourceAspect {
|
||||
|
||||
private final DataSourceManageMapper dataSourceManageMapper;
|
||||
|
||||
private final DynamicDataSourceService dynamicDataSourceService;
|
||||
|
||||
public DynamicDataSourceAspect(DataSourceManageMapper dataSourceManageMapper,
|
||||
DynamicDataSourceService dynamicDataSourceService) {
|
||||
this.dataSourceManageMapper = dataSourceManageMapper;
|
||||
this.dynamicDataSourceService = dynamicDataSourceService;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Around("execution(* cn.fateverse.query.service.DynamicDataSourceTableService.*(..))")
|
||||
public Object around(ProceedingJoinPoint point) {
|
||||
try {
|
||||
Object[] args = point.getArgs();
|
||||
Long dataSourceId = (Long) args[args.length - 1];
|
||||
//获取到当前数据源id的数据源
|
||||
DataSourceManage dataSourceManage = dataSourceManageMapper.selectById(dataSourceId);
|
||||
if (null == dataSourceManage) {
|
||||
throw new CustomException("数据源错误!");
|
||||
}
|
||||
DynamicDataSourceMapper dataSourceServiceMapper = dynamicDataSourceService.getMapper(dataSourceManage);
|
||||
//获取到当前代理的对象
|
||||
Object target = point.getTarget();
|
||||
Class<?> targetClass = target.getClass();
|
||||
Field dataSourceManageField = targetClass.getDeclaredField("dataSourceManage");
|
||||
dataSourceManageField.setAccessible(true);
|
||||
dataSourceManageField.set(target, dataSourceManage);
|
||||
//根据数据源信息来获取到对应的具体mapper实现
|
||||
Field dynamicDataSourceMapperField = targetClass.getDeclaredField("dynamicDataSourceMapper");
|
||||
dynamicDataSourceMapperField.setAccessible(true);
|
||||
dynamicDataSourceMapperField.set(target, dataSourceServiceMapper);
|
||||
//运行代理的函数
|
||||
Object proceed;
|
||||
try {
|
||||
proceed = point.proceed();
|
||||
} catch (Exception e) {
|
||||
log.error("数据源{}连接失败", dataSourceManage.getDsName(), e);
|
||||
dynamicDataSourceService.remove(dataSourceId);
|
||||
throw e;
|
||||
}
|
||||
//将表格mapper对象置null
|
||||
dynamicDataSourceMapperField.set(target, null);
|
||||
//对数据源对象置null
|
||||
dataSourceManageField.set(target, null);
|
||||
//返回对象
|
||||
return proceed;
|
||||
} finally {
|
||||
//关闭session
|
||||
dynamicDataSourceService.closeSqlSession();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package cn.fateverse.query.constant;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2023-08-05
|
||||
*/
|
||||
public class QueryConstant {
|
||||
|
||||
|
||||
public static final String PERMISSIONS_KEY = "custom:query:online:";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package cn.fateverse.query.controller;
|
||||
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import cn.fateverse.common.excel.utils.ExcelUtil;
|
||||
import cn.fateverse.query.entity.dto.DataAdapterDto;
|
||||
import cn.fateverse.query.entity.query.DataAdapterQuery;
|
||||
import cn.fateverse.query.entity.vo.DataAdapterVo;
|
||||
import cn.fateverse.query.service.DataAdapterService;
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.log.annotation.Log;
|
||||
import cn.fateverse.common.log.enums.BusinessType;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据源适配器 Controller
|
||||
*
|
||||
* @author clay
|
||||
* @date 2023-10-29
|
||||
*/
|
||||
@Api(value = "数据源适配器管理", tags = "数据源适配器管理")
|
||||
@RestController
|
||||
@RequestMapping("/query/adapter")
|
||||
public class DataAdapterController {
|
||||
|
||||
private final DataAdapterService dataAdapterService;
|
||||
|
||||
public DataAdapterController(DataAdapterService dataAdapterService) {
|
||||
this.dataAdapterService = dataAdapterService;
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("获取数据源适配器列表")
|
||||
@GetMapping
|
||||
@PreAuthorize("@ss.hasPermission('query:adapter:list')")
|
||||
public Result<TableDataInfo<DataAdapterVo>> list(DataAdapterQuery query) {
|
||||
TableDataInfo<DataAdapterVo> dataInfo = dataAdapterService.searchList(query);
|
||||
return Result.ok(dataInfo);
|
||||
}
|
||||
|
||||
@ApiOperation("获取校验规则option")
|
||||
@GetMapping("/option")
|
||||
public Result<List<Option>> option() {
|
||||
List<Option> options = dataAdapterService.searchOptionList();
|
||||
return Result.ok(options);
|
||||
}
|
||||
|
||||
@ApiOperation("导出excel数据")
|
||||
@GetMapping("/export")
|
||||
@PreAuthorize("@ss.hasPermission('query:adapter:export')")
|
||||
public void export(DataAdapterQuery query) {
|
||||
List<DataAdapterVo> list = dataAdapterService.exportList(query);
|
||||
ExcelUtil.exportExcel(list, DataAdapterVo.class);
|
||||
}
|
||||
|
||||
@ApiOperation("获取数据源适配器详细信息")
|
||||
@GetMapping("/{adapterId}")
|
||||
@PreAuthorize("@ss.hasPermission('query:adapter:info')")
|
||||
public Result<DataAdapterVo> info(@PathVariable Long adapterId) {
|
||||
ObjectUtils.checkPk(adapterId);
|
||||
DataAdapterVo dataAdapter = dataAdapterService.searchById(adapterId);
|
||||
return Result.ok(dataAdapter);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("模拟执行适配器函数")
|
||||
@PostMapping("/mock/execute")
|
||||
@Log(title = "模拟执行适配器函数", businessType = BusinessType.EXECUTE_CODE)
|
||||
@PreAuthorize("@ss.hasPermission('query:adapter:execute')")
|
||||
public Result<Object> mockExecute(@RequestBody @Validated DataAdapterDto dataAdapter) {
|
||||
if (ObjectUtils.isEmpty(dataAdapter.getMockData())) {
|
||||
throw new CustomException("请先获取模拟数据");
|
||||
}
|
||||
Object result = dataAdapterService.mockExecute(dataAdapter);
|
||||
return Result.ok(result);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("新增数据源适配器")
|
||||
@PostMapping
|
||||
@Log(title = "新增数据源适配器", businessType = BusinessType.INSERT)
|
||||
@PreAuthorize("@ss.hasPermission('query:adapter:add')")
|
||||
public Result<Void> add(@RequestBody @Validated DataAdapterDto dataAdapter) {
|
||||
dataAdapterService.save(dataAdapter);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("修改数据源适配器")
|
||||
@PutMapping
|
||||
@Log(title = "修改数据源适配器", businessType = BusinessType.UPDATE)
|
||||
@PreAuthorize("@ss.hasPermission('query:adapter:edit')")
|
||||
public Result<Void> edit(@RequestBody @Validated DataAdapterDto dataAdapter) {
|
||||
ObjectUtils.checkPk(dataAdapter.getAdapterId());
|
||||
dataAdapterService.edit(dataAdapter);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("删除数据源适配器")
|
||||
@DeleteMapping("/{adapterIdList}")
|
||||
@Log(title = "删除数据源适配器", businessType = BusinessType.DELETE)
|
||||
@PreAuthorize("@ss.hasPermission('query:adapter:del')")
|
||||
public Result<Void> batchDel(@PathVariable List<Long> adapterIdList) {
|
||||
ObjectUtils.checkPkList(adapterIdList);
|
||||
dataAdapterService.removeBatch(adapterIdList);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package cn.fateverse.query.controller;
|
||||
|
||||
import cn.fateverse.common.excel.utils.ExcelUtil;
|
||||
import cn.fateverse.query.enums.DynamicSourceEnum;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import cn.fateverse.query.entity.dto.DataSourceManageDto;
|
||||
import cn.fateverse.query.entity.query.DataSourceManageQuery;
|
||||
import cn.fateverse.query.entity.vo.DataSourceManageVo;
|
||||
import cn.fateverse.query.service.DataSourceManageService;
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.log.annotation.Log;
|
||||
import cn.fateverse.common.log.enums.BusinessType;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据源管理 Controller
|
||||
*
|
||||
* @author clay
|
||||
* @date 2023-07-16
|
||||
*/
|
||||
@Api(value = "数据源管理管理",tags = "数据源管理管理")
|
||||
@RestController
|
||||
@RequestMapping("/datasource")
|
||||
public class DataSourceManageController {
|
||||
|
||||
private final DataSourceManageService dataSourceManageService;
|
||||
|
||||
public DataSourceManageController(DataSourceManageService dataSourceManageService) {
|
||||
this.dataSourceManageService = dataSourceManageService;
|
||||
}
|
||||
|
||||
@ApiOperation("获取数据源管理列表")
|
||||
@GetMapping
|
||||
@PreAuthorize("@ss.hasPermission('query:source:list')")
|
||||
public Result<TableDataInfo<DataSourceManageVo>> list(DataSourceManageQuery query) {
|
||||
TableDataInfo<DataSourceManageVo> dataInfo = dataSourceManageService.searchList(query);
|
||||
return Result.ok(dataInfo);
|
||||
}
|
||||
|
||||
@ApiOperation("获取数据源option")
|
||||
@GetMapping("/option")
|
||||
public Result<List<Option>> option(){
|
||||
List<Option> options = dataSourceManageService.searchOptionList();
|
||||
return Result.ok(options);
|
||||
}
|
||||
|
||||
@ApiOperation("获取数据源类型")
|
||||
@GetMapping("/option/type")
|
||||
public Result<List<Option>> datasourceType(){
|
||||
List<Option> optionList = Arrays.stream(DynamicSourceEnum.values()).map(dynamicSourceEnum -> Option.builder()
|
||||
.label(dynamicSourceEnum.getType())
|
||||
.value(dynamicSourceEnum)
|
||||
.build()).collect(Collectors.toList());
|
||||
return Result.ok(optionList);
|
||||
}
|
||||
|
||||
@ApiOperation("导出excel数据")
|
||||
@GetMapping("/export")
|
||||
@PreAuthorize("@ss.hasPermission('query:source:export')")
|
||||
public void export(DataSourceManageQuery query){
|
||||
List<DataSourceManageVo> list = dataSourceManageService.exportList(query);
|
||||
ExcelUtil.exportExcel(list, DataSourceManageVo.class);
|
||||
}
|
||||
|
||||
@ApiOperation("获取数据源管理详细信息")
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("@ss.hasPermission('query:source:info')")
|
||||
public Result<DataSourceManageVo> info(@PathVariable Long id) {
|
||||
ObjectUtils.checkPk(id);
|
||||
DataSourceManageVo dataSourceManageVo = dataSourceManageService.searchById(id);
|
||||
return Result.ok(dataSourceManageVo);
|
||||
}
|
||||
|
||||
@ApiOperation("新增数据源管理")
|
||||
@PostMapping
|
||||
@Log(title = "新增数据源管理",businessType = BusinessType.INSERT)
|
||||
@PreAuthorize("@ss.hasPermission('query:source:add')")
|
||||
public Result<Void> add(@RequestBody @Validated DataSourceManageDto manageDto){
|
||||
checkDataSource(manageDto);
|
||||
if (StrUtil.isBlank(manageDto.getPassword())){
|
||||
return Result.error("数据源密码不能为空!");
|
||||
}
|
||||
dataSourceManageService.save(manageDto);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("修改数据源管理")
|
||||
@PutMapping
|
||||
@Log(title = "修改数据源管理",businessType = BusinessType.UPDATE)
|
||||
@PreAuthorize("@ss.hasPermission('query:source:edit')")
|
||||
public Result<Void> edit(@RequestBody @Validated DataSourceManageDto manageDto){
|
||||
ObjectUtils.checkPk(manageDto.getId());
|
||||
checkDataSource(manageDto);
|
||||
dataSourceManageService.edit(manageDto);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("删除数据源管理")
|
||||
@DeleteMapping("/{idList}")
|
||||
@Log(title = "删除数据源管理",businessType = BusinessType.DELETE)
|
||||
@PreAuthorize("@ss.hasPermission('query:source:del')")
|
||||
public Result<Void> batchDel(@PathVariable List<Long> idList){
|
||||
ObjectUtils.checkPkList(idList);
|
||||
dataSourceManageService.removeBatch(idList);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查数据源字段的合规性
|
||||
* @param dataSource 数据源
|
||||
*/
|
||||
public void checkDataSource(DataSourceManageDto dataSource){
|
||||
if (1 == dataSource.getConfigType()){
|
||||
if (StrUtil.isEmpty(dataSource.getHost())) {
|
||||
throw new CustomException("主机地址不能为空!");
|
||||
}
|
||||
if (null == dataSource.getPort()) {
|
||||
throw new CustomException("主机端口不能为空!");
|
||||
}
|
||||
if (StrUtil.isEmpty(dataSource.getDbName())) {
|
||||
throw new CustomException("数据库名称不能为空!");
|
||||
}
|
||||
}else {
|
||||
if (StrUtil.isEmpty(dataSource.getUrl())) {
|
||||
throw new CustomException("数据源接地址不能为空!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package cn.fateverse.query.controller;
|
||||
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.LongUtils;
|
||||
import cn.fateverse.query.entity.DynamicTable;
|
||||
import cn.fateverse.query.entity.query.DynamicTableQuery;
|
||||
import cn.fateverse.query.service.DynamicDataSourceTableService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2023-07-16
|
||||
*/
|
||||
@Api(value = "动态数据源表格管理",tags = "动态数据源表格管理")
|
||||
@RestController
|
||||
@RequestMapping("/dynamic/table")
|
||||
public class DynamicDataSourceTableController {
|
||||
|
||||
private final DynamicDataSourceTableService dynamicDataSourceTableService;
|
||||
|
||||
public DynamicDataSourceTableController(DynamicDataSourceTableService dynamicDataSourceTableService) {
|
||||
this.dynamicDataSourceTableService = dynamicDataSourceTableService;
|
||||
}
|
||||
|
||||
@ApiOperation("获取数据源信息")
|
||||
@GetMapping
|
||||
@PreAuthorize("@ss.hasPermission('query:dynamic-table:list')")
|
||||
public Result<TableDataInfo<DynamicTable>> test(DynamicTableQuery query, Long dataSourceId) {
|
||||
if (LongUtils.isNull(dataSourceId)){
|
||||
return Result.error("数据源id不能为空!");
|
||||
}
|
||||
TableDataInfo<DynamicTable> dataInfo = dynamicDataSourceTableService.searchTableList(query, dataSourceId);
|
||||
return Result.ok(dataInfo);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package cn.fateverse.query.controller;
|
||||
|
||||
import cn.fateverse.query.entity.dto.DynamicEchartsDto;
|
||||
import cn.fateverse.query.entity.query.DynamicEchartsQuery;
|
||||
import cn.fateverse.query.entity.vo.DynamicEchartsVo;
|
||||
import cn.fateverse.query.service.DynamicEchartsService;
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.log.annotation.Log;
|
||||
import cn.fateverse.common.log.enums.BusinessType;
|
||||
import cn.fateverse.common.excel.utils.ExcelUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 动态echarts图表 Controller
|
||||
*
|
||||
* @author clay
|
||||
* @date 2023-11-16
|
||||
*/
|
||||
@Api(value = "动态echarts图表管理",tags = "动态echarts图表管理")
|
||||
@RestController
|
||||
@RequestMapping("/echarts")
|
||||
public class DynamicEchartsController {
|
||||
|
||||
private final DynamicEchartsService dynamicEchartsService;
|
||||
|
||||
public DynamicEchartsController(DynamicEchartsService dynamicEchartsService) {
|
||||
this.dynamicEchartsService = dynamicEchartsService;
|
||||
}
|
||||
|
||||
@ApiOperation("获取动态echarts图表列表")
|
||||
@GetMapping
|
||||
@PreAuthorize("@ss.hasPermission('query:echarts:list')")
|
||||
public Result<TableDataInfo<DynamicEchartsVo>> list(DynamicEchartsQuery query) {
|
||||
TableDataInfo<DynamicEchartsVo> dataInfo = dynamicEchartsService.searchList(query);
|
||||
return Result.ok(dataInfo);
|
||||
}
|
||||
|
||||
@ApiOperation("获取校验规则option")
|
||||
@GetMapping("/option")
|
||||
public Result<List<Option>> option(){
|
||||
List<Option> options = dynamicEchartsService.searchOptionList();
|
||||
return Result.ok(options);
|
||||
}
|
||||
|
||||
@ApiOperation("导出excel数据")
|
||||
@GetMapping("/export")
|
||||
@PreAuthorize("@ss.hasPermission('query:echarts:export')")
|
||||
public void export(DynamicEchartsQuery query){
|
||||
List<DynamicEchartsVo> list = dynamicEchartsService.exportList(query);
|
||||
ExcelUtil.exportExcel(list,DynamicEchartsVo.class);
|
||||
}
|
||||
|
||||
@ApiOperation("获取动态echarts图表详细信息")
|
||||
@GetMapping("/{echartsId}")
|
||||
@PreAuthorize("@ss.hasPermission('query:echarts:info')")
|
||||
public Result<DynamicEchartsVo> info(@PathVariable Long echartsId) {
|
||||
ObjectUtils.checkPk(echartsId);
|
||||
DynamicEchartsVo dynamicEcharts = dynamicEchartsService.searchById(echartsId);
|
||||
return Result.ok(dynamicEcharts);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("新增动态echarts图表")
|
||||
@PostMapping
|
||||
@Log(title = "新增动态echarts图表",businessType = BusinessType.INSERT)
|
||||
@PreAuthorize("@ss.hasPermission('query:echarts:add')")
|
||||
public Result<Void> add(@RequestBody @Validated DynamicEchartsDto dynamicEcharts){
|
||||
dynamicEchartsService.save(dynamicEcharts);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("修改动态echarts图表")
|
||||
@PutMapping
|
||||
@Log(title = "修改动态echarts图表",businessType = BusinessType.UPDATE)
|
||||
@PreAuthorize("@ss.hasPermission('query:echarts:edit')")
|
||||
public Result<Void> edit(@RequestBody @Validated DynamicEchartsDto dynamicEcharts){
|
||||
ObjectUtils.checkPk(dynamicEcharts.getEchartsId());
|
||||
dynamicEchartsService.edit(dynamicEcharts);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("删除动态echarts图表")
|
||||
@DeleteMapping("/{echartsIdList}")
|
||||
@Log(title = "删除动态echarts图表",businessType = BusinessType.DELETE)
|
||||
@PreAuthorize("@ss.hasPermission('query:echarts:del')")
|
||||
public Result<Void> batchDel(@PathVariable List<Long> echartsIdList){
|
||||
ObjectUtils.checkPkList(echartsIdList);
|
||||
dynamicEchartsService.removeBatch(echartsIdList);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package cn.fateverse.query.controller;
|
||||
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.decrypt.annotation.Encrypt;
|
||||
import cn.fateverse.common.decrypt.annotation.EncryptField;
|
||||
import cn.fateverse.query.entity.vo.CustomQueryResult;
|
||||
import cn.fateverse.query.entity.dto.SearchInfo;
|
||||
import cn.fateverse.query.service.PageService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2023-08-05
|
||||
*/
|
||||
@Api(value = "上线自定义查询页面",tags = "上线自定义查询页面")
|
||||
@RestController
|
||||
@RequestMapping("/page")
|
||||
public class PageController {
|
||||
|
||||
|
||||
private final PageService pageService;
|
||||
|
||||
|
||||
public PageController(PageService pageService) {
|
||||
this.pageService = pageService;
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("获取到自定义查询的信息")
|
||||
@GetMapping("/{queryId}")
|
||||
@Encrypt
|
||||
public Result<CustomQueryResult> info(@PathVariable @EncryptField String queryId){
|
||||
if (ObjectUtils.isEmpty(queryId)) {
|
||||
return Result.error("请求参数为空");
|
||||
}
|
||||
return pageService.searchQueryInfoAndData(Long.valueOf(queryId));
|
||||
}
|
||||
|
||||
@ApiOperation("查询数据")
|
||||
@PostMapping("/data")
|
||||
@Encrypt
|
||||
public Result<TableDataInfo<Map<String, Object>>> searchData(@RequestBody @Validated SearchInfo searchInfo){
|
||||
TableDataInfo<Map<String, Object>> tableDataInfo = pageService.searchQueryData(searchInfo);
|
||||
return Result.ok(tableDataInfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package cn.fateverse.query.controller;
|
||||
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.decrypt.annotation.Encrypt;
|
||||
import cn.fateverse.common.decrypt.annotation.EncryptField;
|
||||
import cn.fateverse.query.entity.vo.CustomQueryResult;
|
||||
import cn.fateverse.query.entity.dto.SearchInfo;
|
||||
import cn.fateverse.query.entity.dto.SqlDto;
|
||||
import cn.fateverse.query.entity.vo.SqlInfoVo;
|
||||
import cn.fateverse.query.service.SqlSearchService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2023-08-09
|
||||
*/
|
||||
@Api(value = "sql万能查询", tags = "sql万能查询")
|
||||
@RestController
|
||||
@RequestMapping("/sql/search")
|
||||
public class SqlSearchController {
|
||||
|
||||
private final SqlSearchService sqlSearchService;
|
||||
|
||||
|
||||
public SqlSearchController(SqlSearchService sqlSearchService) {
|
||||
this.sqlSearchService = sqlSearchService;
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("获取到sql自定义查询的基础信息")
|
||||
@GetMapping("/{queryId}")
|
||||
@Encrypt
|
||||
public Result<SqlInfoVo> topology(@PathVariable @EncryptField String queryId) {
|
||||
SqlInfoVo sqlInfoVo = sqlSearchService.search(Long.parseLong(queryId));
|
||||
return Result.ok(sqlInfoVo);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("保存sql自定义查询参数")
|
||||
@PostMapping
|
||||
@Encrypt
|
||||
public Result<Void> save(@RequestBody @Validated SqlDto sqlDto) {
|
||||
sqlSearchService.saveData(sqlDto);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("预览")
|
||||
@Encrypt
|
||||
@PutMapping("/preview")
|
||||
public Result<CustomQueryResult> preview(@RequestBody @Validated SqlDto sqlDto) {
|
||||
return sqlSearchService.preview(sqlDto);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("发布")
|
||||
@Encrypt
|
||||
@PostMapping("/publish")
|
||||
public Result<Void> publish(@RequestBody @Validated SqlDto sqlDto) {
|
||||
if (ObjectUtils.isEmpty(sqlDto.getMenuId())) {
|
||||
return Result.error("上级菜单不能为空!");
|
||||
}
|
||||
sqlSearchService.publish(sqlDto);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("撤销")
|
||||
@Encrypt
|
||||
@PutMapping("/cancel/{queryId}")
|
||||
public Result<Void> cancel(@PathVariable @EncryptField String queryId){
|
||||
sqlSearchService.cancel(Long.valueOf(queryId));
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("预览弹窗数据获取")
|
||||
@Encrypt
|
||||
@PostMapping("/preview/data")
|
||||
public Result<TableDataInfo<Map<String, Object>>> previewData(@RequestBody @Validated SearchInfo searchInfo) {
|
||||
TableDataInfo<Map<String, Object>> tableDataInfo = sqlSearchService.previewData(searchInfo.getList(), searchInfo.getQueryId());
|
||||
return Result.ok(tableDataInfo);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package cn.fateverse.query.controller;
|
||||
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.decrypt.annotation.Encrypt;
|
||||
import cn.fateverse.common.decrypt.annotation.EncryptField;
|
||||
import cn.fateverse.common.excel.utils.ExcelUtil;
|
||||
import cn.fateverse.common.log.annotation.Log;
|
||||
import cn.fateverse.common.log.enums.BusinessType;
|
||||
import cn.fateverse.query.entity.vo.UniQueryVo;
|
||||
import cn.fateverse.query.entity.dto.UniQueryDto;
|
||||
import cn.fateverse.query.entity.query.UniQueryQuery;
|
||||
import cn.fateverse.query.service.UniQueryService;
|
||||
import cn.fateverse.query.service.impl.SqlUniQueryServiceImpl;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2023-08-09
|
||||
*/
|
||||
@Api(value = "SQL万能查询管理", tags = "SQL万能查询管理")
|
||||
@RestController
|
||||
@RequestMapping("/sql/uni")
|
||||
public class SqlUniQueryController {
|
||||
|
||||
|
||||
private final UniQueryService uniQueryService;
|
||||
|
||||
|
||||
public SqlUniQueryController(SqlUniQueryServiceImpl uniQueryService) {
|
||||
this.uniQueryService = uniQueryService;
|
||||
}
|
||||
|
||||
@ApiOperation("获取万能查询列表")
|
||||
@GetMapping
|
||||
@Encrypt
|
||||
@PreAuthorize("@ss.hasPermission('sql:uni-query:list')")
|
||||
public Result<TableDataInfo<UniQueryVo>> list(UniQueryQuery query) {
|
||||
TableDataInfo<UniQueryVo> dataInfo = uniQueryService.searchList(query);
|
||||
return Result.ok(dataInfo);
|
||||
}
|
||||
|
||||
@ApiOperation("导出excel数据")
|
||||
@GetMapping("/export")
|
||||
@PreAuthorize("@ss.hasPermission('sql:uni-query:export')")
|
||||
public void export(UniQueryQuery query) {
|
||||
List<UniQueryVo> list = uniQueryService.exportList(query);
|
||||
ExcelUtil.exportExcel(list, UniQueryVo.class);
|
||||
}
|
||||
|
||||
@ApiOperation("获取万能查询详细信息")
|
||||
@GetMapping("/{id}")
|
||||
@Encrypt
|
||||
@PreAuthorize("@ss.hasPermission('sql:uni-query:info')")
|
||||
public Result<UniQueryVo> info(@PathVariable @EncryptField String id) {
|
||||
ObjectUtils.checkPk(id);
|
||||
UniQueryVo uniQuery = uniQueryService.searchById(Long.parseLong(id));
|
||||
return Result.ok(uniQuery);
|
||||
}
|
||||
|
||||
@ApiOperation("新增万能查询")
|
||||
@PostMapping
|
||||
@Log(title = "新增万能查询", businessType = BusinessType.INSERT)
|
||||
@PreAuthorize("@ss.hasPermission('sql:uni-query:add')")
|
||||
public Result<UniQueryVo> add(@RequestBody @Validated UniQueryDto dto) {
|
||||
return uniQueryService.save(dto);
|
||||
}
|
||||
|
||||
@ApiOperation("修改万能查询")
|
||||
@PutMapping
|
||||
@Encrypt
|
||||
@Log(title = "修改万能查询", businessType = BusinessType.UPDATE)
|
||||
@PreAuthorize("@ss.hasPermission('sql:uni-query:edit')")
|
||||
public Result<Void> edit(@RequestBody @Validated UniQueryDto dto) {
|
||||
ObjectUtils.checkPk(dto.getId());
|
||||
uniQueryService.edit(dto);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("删除万能查询")
|
||||
@DeleteMapping("/{idList}")
|
||||
@Encrypt
|
||||
@Log(title = "删除万能查询", businessType = BusinessType.DELETE)
|
||||
@PreAuthorize("@ss.hasPermission('sql:uni-query:del')")
|
||||
public Result<Void> batchDel(@PathVariable @EncryptField List<String> idList) {
|
||||
List<Long> collect = idList.stream().map(Long::valueOf).collect(Collectors.toList());
|
||||
ObjectUtils.checkPkList(idList);
|
||||
uniQueryService.removeBatch(collect);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package cn.fateverse.query.controller;
|
||||
|
||||
import cn.fateverse.common.core.entity.Option;
|
||||
import cn.fateverse.common.core.utils.LongUtils;
|
||||
import cn.fateverse.query.entity.TableInfo;
|
||||
import cn.fateverse.query.entity.dto.ImportDto;
|
||||
import cn.fateverse.query.entity.query.TableQuery;
|
||||
import cn.fateverse.query.entity.vo.TableVo;
|
||||
import cn.fateverse.query.service.TableService;
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.log.annotation.Log;
|
||||
import cn.fateverse.common.log.enums.BusinessType;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 自定义查询表格维护 Controller
|
||||
*
|
||||
* @author clay
|
||||
* @date 2023-07-16
|
||||
*/
|
||||
@Api(value = "自定义查询表格维护管理", tags = "自定义查询表格维护管理")
|
||||
@RestController
|
||||
@RequestMapping("/table")
|
||||
public class TableController {
|
||||
|
||||
private final TableService tableService;
|
||||
|
||||
public TableController(TableService tableService) {
|
||||
this.tableService = tableService;
|
||||
}
|
||||
|
||||
@ApiOperation("获取自定义查询表格维护列表")
|
||||
@GetMapping
|
||||
@PreAuthorize("@ss.hasPermission('query:table:list')")
|
||||
public Result<TableDataInfo<TableVo>> list(TableQuery query) {
|
||||
TableDataInfo<TableVo> dataInfo = tableService.searchList(query);
|
||||
return Result.ok(dataInfo);
|
||||
}
|
||||
|
||||
@ApiOperation("根据数据源获取到表格option信息")
|
||||
@GetMapping("/option/{datasourceId}")
|
||||
public Result<List<Option>> option(@PathVariable Long datasourceId){
|
||||
List<Option> optionList = tableService.searchOption(datasourceId);
|
||||
return Result.ok(optionList);
|
||||
}
|
||||
|
||||
@ApiOperation("根据表格id获取列的option信息")
|
||||
@GetMapping("/column/option/{tableId}")
|
||||
public Result<List<Option>> columnOption(@PathVariable Long tableId){
|
||||
List<Option> optionList = tableService.searchColumnOption(tableId);
|
||||
return Result.ok(optionList);
|
||||
}
|
||||
|
||||
@ApiOperation("获取详细信息")
|
||||
@GetMapping("/{tableId}")
|
||||
@PreAuthorize("@ss.hasPermission('query:table:info')")
|
||||
public Result<TableInfo> info(@PathVariable Long tableId) {
|
||||
TableInfo tableInfo = tableService.searchById(tableId);
|
||||
return Result.ok(tableInfo);
|
||||
}
|
||||
|
||||
@ApiOperation("导入表信息")
|
||||
@PostMapping("/import")
|
||||
@Log(title = "自定义查询导入表信息", businessType = BusinessType.INSERT)
|
||||
@PreAuthorize("@ss.hasPermission('query:table:import')")
|
||||
public Result<Long> importTable(@RequestBody @Validated ImportDto dto) {
|
||||
if (dto.getTables().isEmpty() || LongUtils.isNull(dto.getDataSourceId())) {
|
||||
return Result.error("缺少必要参数!");
|
||||
}
|
||||
return tableService.importTable(dto);
|
||||
}
|
||||
|
||||
@ApiOperation("同步数据库")
|
||||
@PutMapping("/sync/{tableId}")
|
||||
@Log(title = "同步数据库", businessType = BusinessType.UPDATE)
|
||||
@PreAuthorize("@ss.hasPermission('query:table:sync')")
|
||||
public Result<Void> syncTable(@PathVariable Long tableId) {
|
||||
if (ObjectUtils.isEmpty(tableId)){
|
||||
return Result.error("缺少必要参数!");
|
||||
}
|
||||
tableService.syncTable(tableId);
|
||||
return Result.ok("同步成功");
|
||||
}
|
||||
|
||||
@ApiOperation("修改自定义查询表格维护")
|
||||
@PutMapping
|
||||
@Log(title = "修改自定义查询表格维护", businessType = BusinessType.UPDATE)
|
||||
@PreAuthorize("@ss.hasPermission('query:table:edit')")
|
||||
public Result<Void> edit(@RequestBody @Validated TableInfo table) {
|
||||
ObjectUtils.checkPk(table.getTable().getTableId());
|
||||
if (null == table.getColumnList() || table.getColumnList().isEmpty()) {
|
||||
return Result.error("列信息不能为空!");
|
||||
}
|
||||
if (null == table.getRoleIds() || table.getRoleIds().isEmpty()) {
|
||||
return Result.error("角色信息不能为空!");
|
||||
}
|
||||
tableService.edit(table);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("删除自定义查询表格维护")
|
||||
@DeleteMapping("/{tableId}")
|
||||
@Log(title = "删除自定义查询表格维护", businessType = BusinessType.DELETE)
|
||||
@PreAuthorize("@ss.hasPermission('query:table:del')")
|
||||
public Result<Void> batchDel(@PathVariable Long tableId) {
|
||||
if (null == tableId || 0L == tableId) {
|
||||
return Result.error("缺少必要参数!");
|
||||
}
|
||||
tableService.removeById(tableId);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package cn.fateverse.query.controller;
|
||||
|
||||
import cn.fateverse.common.decrypt.annotation.Encrypt;
|
||||
import cn.fateverse.common.decrypt.annotation.EncryptField;
|
||||
import cn.fateverse.common.excel.utils.ExcelUtil;
|
||||
import cn.fateverse.common.log.annotation.Log;
|
||||
import cn.fateverse.common.log.enums.BusinessType;
|
||||
import cn.fateverse.query.entity.vo.UniQueryVo;
|
||||
import cn.fateverse.query.entity.dto.UniQueryDto;
|
||||
import cn.fateverse.query.entity.query.UniQueryQuery;
|
||||
import cn.fateverse.query.service.UniQueryService;
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.query.service.impl.TopoUniQueryServiceImpl;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 万能查询 Controller
|
||||
*
|
||||
* @author clay
|
||||
* @date 2023-03-01
|
||||
*/
|
||||
@Api(value = "TOPO万能查询管理", tags = "TOPO万能查询管理")
|
||||
@RestController
|
||||
@RequestMapping({"/topo/uni"})
|
||||
public class TopoUniQueryController {
|
||||
|
||||
private final UniQueryService uniQueryService;
|
||||
|
||||
public TopoUniQueryController(TopoUniQueryServiceImpl uniQueryService) {
|
||||
this.uniQueryService = uniQueryService;
|
||||
}
|
||||
|
||||
@ApiOperation("拓扑图获取万能查询列表")
|
||||
@GetMapping
|
||||
@Encrypt
|
||||
@PreAuthorize("@ss.hasPermission('topo:uni-query:list')")
|
||||
public Result<TableDataInfo<UniQueryVo>> list(UniQueryQuery query) {
|
||||
TableDataInfo<UniQueryVo> dataInfo = uniQueryService.searchList(query);
|
||||
return Result.ok(dataInfo);
|
||||
}
|
||||
|
||||
@ApiOperation("拓扑图导出excel数据")
|
||||
@GetMapping("/export")
|
||||
@PreAuthorize("@ss.hasPermission('topo:uni-query:export')")
|
||||
public void export(UniQueryQuery query) {
|
||||
List<UniQueryVo> list = uniQueryService.exportList(query);
|
||||
ExcelUtil.exportExcel(list, UniQueryVo.class);
|
||||
}
|
||||
|
||||
@ApiOperation("拓扑图数据查看接口")
|
||||
@GetMapping("/view/{id}")
|
||||
@PreAuthorize("@ss.hasPermission('topo:uni-query:view')")
|
||||
@Encrypt
|
||||
public Result<String> preview(@PathVariable @EncryptField String id) {
|
||||
String url = uniQueryService.view(Long.valueOf(id));
|
||||
return Result.ok(url);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("拓扑图获取万能查询详细信息")
|
||||
@GetMapping("/{id}")
|
||||
@Encrypt
|
||||
@PreAuthorize("@ss.hasPermission('topo:uni-query:info')")
|
||||
public Result<UniQueryVo> info(@PathVariable @EncryptField String id) {
|
||||
ObjectUtils.checkPk(id);
|
||||
UniQueryVo uniQuery = uniQueryService.searchById(Long.parseLong(id));
|
||||
return Result.ok(uniQuery);
|
||||
}
|
||||
|
||||
@ApiOperation("拓扑图新增万能查询")
|
||||
@PostMapping
|
||||
@Log(title = "拓扑图新增万能查询", businessType = BusinessType.INSERT)
|
||||
@PreAuthorize("@ss.hasPermission('topo:uni-query:add')")
|
||||
public Result<UniQueryVo> add(@RequestBody @Validated UniQueryDto dto) {
|
||||
return uniQueryService.save(dto);
|
||||
}
|
||||
|
||||
@ApiOperation("拓扑图修改万能查询")
|
||||
@PutMapping
|
||||
@Encrypt
|
||||
@Log(title = "拓扑图修改万能查询", businessType = BusinessType.UPDATE)
|
||||
@PreAuthorize("@ss.hasPermission('topo:uni-query:edit')")
|
||||
public Result<Void> edit(@RequestBody @Validated UniQueryDto dto) {
|
||||
ObjectUtils.checkPk(dto.getId());
|
||||
uniQueryService.edit(dto);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("拓扑图删除万能查询")
|
||||
@DeleteMapping("/{idList}")
|
||||
@Encrypt
|
||||
@Log(title = "拓扑图删除万能查询", businessType = BusinessType.DELETE)
|
||||
@PreAuthorize("@ss.hasPermission('topo:uni-query:del')")
|
||||
public Result<Void> batchDel(@PathVariable @EncryptField List<String> idList) {
|
||||
List<Long> collect = idList.stream().map(Long::valueOf).collect(Collectors.toList());
|
||||
ObjectUtils.checkPkList(idList);
|
||||
uniQueryService.removeBatch(collect);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package cn.fateverse.query.controller;
|
||||
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.decrypt.annotation.Encrypt;
|
||||
import cn.fateverse.common.decrypt.annotation.EncryptField;
|
||||
import cn.fateverse.query.entity.vo.CustomQueryResult;
|
||||
import cn.fateverse.query.entity.vo.TopoVo;
|
||||
import cn.fateverse.query.entity.dto.SearchInfo;
|
||||
import cn.fateverse.query.entity.dto.TopoDto;
|
||||
import cn.fateverse.query.service.TopologySearchService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2023-07-21
|
||||
*/
|
||||
@Api(value = "拓扑图万能查询", tags = "拓扑图万能查询")
|
||||
@RestController
|
||||
@RequestMapping("/topo/search")
|
||||
public class TopologySearchController {
|
||||
|
||||
private final TopologySearchService topologySearchService;
|
||||
|
||||
public TopologySearchController(TopologySearchService topologySearchService) {
|
||||
this.topologySearchService = topologySearchService;
|
||||
}
|
||||
|
||||
@ApiOperation("获取到表格的拖拽数据信息")
|
||||
@GetMapping("/{queryId}")
|
||||
@Encrypt
|
||||
public Result<TopoVo> topology(@PathVariable @EncryptField String queryId) {
|
||||
TopoVo topoVo = topologySearchService.search(Long.parseLong(queryId));
|
||||
return Result.ok(topoVo);
|
||||
}
|
||||
|
||||
@ApiOperation("保存topo参数")
|
||||
@PostMapping
|
||||
@Encrypt
|
||||
public Result<Void> save(@RequestBody @Validated TopoDto topo) {
|
||||
topologySearchService.saveData(topo);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("预览")
|
||||
@Encrypt
|
||||
@PostMapping("/preview")
|
||||
public Result<CustomQueryResult> preview(@RequestBody @Validated TopoDto topo) {
|
||||
return topologySearchService.preview(topo);
|
||||
}
|
||||
|
||||
@ApiOperation("撤销")
|
||||
@Encrypt
|
||||
@PutMapping("/cancel/{queryId}")
|
||||
public Result<Void> cancel(@PathVariable @EncryptField String queryId){
|
||||
topologySearchService.cancel(Long.valueOf(queryId));
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("发布")
|
||||
@Encrypt
|
||||
@PostMapping("/publish")
|
||||
public Result<Void> publish(@RequestBody @Validated TopoDto topo) {
|
||||
if (ObjectUtils.isEmpty(topo.getMenuId())) {
|
||||
return Result.error("上级菜单不能为空!");
|
||||
}
|
||||
topologySearchService.publish(topo);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("预览弹窗数据获取")
|
||||
@Encrypt
|
||||
@PostMapping("/preview/data")
|
||||
public Result<TableDataInfo<Map<String, Object>>> previewData(@RequestBody @Validated SearchInfo searchInfo) {
|
||||
TableDataInfo<Map<String, Object>> tableDataInfo = topologySearchService.previewData(searchInfo.getList(), searchInfo.getQueryId());
|
||||
return Result.ok(tableDataInfo);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package cn.fateverse.query.entity;
|
||||
|
||||
import cn.fateverse.common.core.annotaion.EnableAutoField;
|
||||
import cn.fateverse.common.core.entity.BaseEntity;
|
||||
import cn.fateverse.query.enums.DataAdapterSource;
|
||||
import cn.fateverse.query.enums.DataAdapterType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
/**
|
||||
* 数据源适配器对象 data_adapter
|
||||
*
|
||||
* @author clay
|
||||
* @date 2023-10-29
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@EnableAutoField
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DataAdapter extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 数据适配器id
|
||||
*/
|
||||
private Long adapterId;
|
||||
|
||||
/**
|
||||
* 数据源id,数据源可以是 topo自定义查询,sql自定义查询,api请求
|
||||
*/
|
||||
private Long dataSourceId;
|
||||
|
||||
/**
|
||||
* 适配器名称
|
||||
*/
|
||||
private String adapterName;
|
||||
|
||||
/**
|
||||
* 数据适配器代码类型 Java or Js
|
||||
*/
|
||||
private DataAdapterType type;
|
||||
|
||||
/**
|
||||
* 适配器代码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 可以执行的代码块
|
||||
*/
|
||||
private String executeCode;
|
||||
|
||||
/**
|
||||
* 适配器来源,数据源 自定义创建 自定义查询 sql 自定义查询 echart编辑器
|
||||
*/
|
||||
private DataAdapterSource source;
|
||||
|
||||
/**
|
||||
* 模拟数据 strng类型的json字符串
|
||||
*/
|
||||
private String mockData;
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user