add
This commit is contained in:
46
qiaoba-module/qiaoba-module-generator/pom.xml
Normal file
46
qiaoba-module/qiaoba-module-generator/pom.xml
Normal file
@ -0,0 +1,46 @@
|
||||
<?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>qiaoba-modules</artifactId>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>qiaoba-module-generator</artifactId>
|
||||
|
||||
<description>代码生成</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<artifactId>qiaoba-common-base</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<artifactId>qiaoba-common-datasource</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<artifactId>qiaoba-common-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<artifactId>qiaoba-api-auth</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<artifactId>qiaoba-common-doc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<artifactId>qiaoba-api-log</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,30 @@
|
||||
package com.qiaoba.module.generator.config;
|
||||
|
||||
/**
|
||||
* 代码生成 默认配置
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class GeneratorConfig {
|
||||
|
||||
/**
|
||||
* 作者
|
||||
*/
|
||||
public static String AUTHOR = "Ailanyin";
|
||||
|
||||
/**
|
||||
* 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool
|
||||
*/
|
||||
public static String PACKAGE_NAME = "com.qiaoba.module.generator";
|
||||
|
||||
/**
|
||||
* 自动去除表前缀,默认是false
|
||||
*/
|
||||
public static boolean AUTO_REMOVE_PREFIX;
|
||||
|
||||
/**
|
||||
* 表前缀 生成类名不会包含表前缀, 多个用逗号分隔
|
||||
*/
|
||||
public static String TABLE_PREFIX;
|
||||
|
||||
}
|
@ -0,0 +1,190 @@
|
||||
package com.qiaoba.module.generator.constant;
|
||||
|
||||
/**
|
||||
* 代码生成通用常量
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class GenConstants {
|
||||
|
||||
/*====================================[数据库]=========================================*/
|
||||
|
||||
/**
|
||||
* 数据库字符串类型
|
||||
*/
|
||||
public static final String[] COLUMN_TYPE_STR = {"char", "varchar", "nvarchar", "varchar2"};
|
||||
|
||||
/**
|
||||
* 数据库文本类型
|
||||
*/
|
||||
public static final String[] COLUMN_TYPE_TEXT = {"tinytext", "text", "mediumtext", "longtext"};
|
||||
|
||||
/**
|
||||
* 数据库时间类型
|
||||
*/
|
||||
public static final String[] COLUMN_TYPE_TIME = {"datetime", "time", "date", "timestamp"};
|
||||
|
||||
/**
|
||||
* 数据库数字类型
|
||||
*/
|
||||
public static final String[] COLUMN_TYPE_NUMBER = {"tinyint", "smallint", "mediumint", "int", "number", "integer",
|
||||
"bit", "bigint", "float", "double", "decimal"};
|
||||
|
||||
/**
|
||||
* 页面不需要处理的字段
|
||||
*/
|
||||
public static final String[] COLUMN_NAME_NOT_HANDLE = {"id", "create_user", "create_time", "del_flag", "update_user",
|
||||
"update_time", "tenant_id"};
|
||||
|
||||
|
||||
/**
|
||||
* Entity基类字段
|
||||
*/
|
||||
public static final String[] BASE_ENTITY = {"createUser", "createTime", "updateUser", "updateTime", "remark", "tenantId"};
|
||||
|
||||
/*====================================[前端控件]=========================================*/
|
||||
/**
|
||||
* 文本框
|
||||
*/
|
||||
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_BIGDECIMAL = "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[] HTML_LIKE_COLUMN = {"name", "code", "phone"};
|
||||
|
||||
/**
|
||||
* 需要处理成 单选框 的字段
|
||||
*/
|
||||
public static final String[] HTML_RADIO_COLUMN = {"status"};
|
||||
|
||||
/**
|
||||
* 需要处理成 下拉框 的字段
|
||||
*/
|
||||
public static final String[] HTML_SELECT_COLUMN = {"type", "sex", "gender"};
|
||||
|
||||
/**
|
||||
* 需要处理成 图片上传控件 的字段
|
||||
*/
|
||||
public static final String[] HTML_IMAGE_COLUMN = {"image", "pic"};
|
||||
|
||||
/**
|
||||
* 需要处理成 文件上传控件 的字段
|
||||
*/
|
||||
public static final String[] HTML_FILE_COLUMN = {"file"};
|
||||
|
||||
/**
|
||||
* 需要处理成 富文本 的字段
|
||||
*/
|
||||
public static final String[] HTML_EDITOR_COLUMN = {"content", "description"};
|
||||
|
||||
/*====================================[下载类型]=========================================*/
|
||||
|
||||
/**
|
||||
* 下载-全部
|
||||
*/
|
||||
public static final String TEMPLATE_TYPE_ALL = "all";
|
||||
|
||||
/**
|
||||
* 下载-后端
|
||||
*/
|
||||
public static final String TEMPLATE_TYPE_JAVA = "java";
|
||||
|
||||
/**
|
||||
* 下载-前端
|
||||
*/
|
||||
public static final String TEMPLATE_TYPE_VUE = "vue";
|
||||
|
||||
/**
|
||||
* 下载-SQL
|
||||
*/
|
||||
public static final String TEMPLATE_TYPE_SQL = "sql";
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
package com.qiaoba.module.generator.controller;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.qiaoba.api.job.annotation.Log;
|
||||
import com.qiaoba.api.job.enums.BusinessType;
|
||||
import com.qiaoba.common.base.result.AjaxResult;
|
||||
import com.qiaoba.common.database.entity.PageQuery;
|
||||
import com.qiaoba.common.database.entity.TableDataInfo;
|
||||
import com.qiaoba.module.generator.constant.GenConstants;
|
||||
import com.qiaoba.module.generator.entity.GeneratorTable;
|
||||
import com.qiaoba.module.generator.entity.GeneratorTableColumn;
|
||||
import com.qiaoba.module.generator.entity.dto.GeneratorTableDto;
|
||||
import com.qiaoba.module.generator.entity.dto.TableDto;
|
||||
import com.qiaoba.module.generator.service.GeneratorTableColumnService;
|
||||
import com.qiaoba.module.generator.service.GeneratorTableService;
|
||||
import com.qiaoba.module.generator.util.GeneratorUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 代码生成 Web层
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 9:09
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/tool/gen")
|
||||
public class GeneratorController {
|
||||
|
||||
private final GeneratorTableService generatorTableService;
|
||||
private final GeneratorTableColumnService generatorTableColumnService;
|
||||
|
||||
/**
|
||||
* 代码生成列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(TableDto dto, PageQuery pageQuery) {
|
||||
return generatorTableService.selectPageList(dto, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 代码生成详细
|
||||
*/
|
||||
@GetMapping(value = "/{tableId}")
|
||||
public AjaxResult getInfo(@PathVariable String tableId) {
|
||||
GeneratorTable table = generatorTableService.selectById(tableId);
|
||||
List<GeneratorTableColumn> list = generatorTableColumnService.selectListByTableId(tableId, false);
|
||||
Map<String, Object> map = new HashMap<String, Object>(2);
|
||||
map.put("info", table);
|
||||
map.put("rows", list);
|
||||
return AjaxResult.success(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改代码生成
|
||||
*/
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody GeneratorTableDto dto) {
|
||||
GeneratorTable generatorTable = BeanUtil.copyProperties(dto, GeneratorTable.class);
|
||||
int result = generatorTableService.updateById(generatorTable);
|
||||
generatorTableColumnService.updateBatchById(dto.getColumns());
|
||||
return AjaxResult.toAjax(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除代码生成
|
||||
*/
|
||||
@DeleteMapping("/{tableIds}")
|
||||
@Log(title = "代码生成", businessType = BusinessType.DELETE)
|
||||
public AjaxResult remove(@PathVariable List<String> tableIds) {
|
||||
return AjaxResult.toAjax(generatorTableService.deleteByIds(tableIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库表列表(排除已导入表)
|
||||
*/
|
||||
@GetMapping("/db/list")
|
||||
public TableDataInfo dbTableList(TableDto dto, PageQuery pageQuery) {
|
||||
return generatorTableService.selectPageDbTableList(dto, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入表结构
|
||||
*/
|
||||
@PostMapping("/importTable")
|
||||
public AjaxResult importTable(@RequestBody TableDto dto) {
|
||||
return AjaxResult.toAjax(generatorTableService.importTable(dto));
|
||||
}
|
||||
|
||||
/**
|
||||
* 预览代码
|
||||
*/
|
||||
@GetMapping("/preview/{tableId}")
|
||||
public AjaxResult preview(@PathVariable("tableId") String tableId) {
|
||||
Map<String, String> dataMap = generatorTableService.previewCode(tableId, GenConstants.TEMPLATE_TYPE_ALL);
|
||||
return AjaxResult.success(dataMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*/
|
||||
@GetMapping("/download/{tableId}/{templateType}")
|
||||
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
||||
public void download(HttpServletResponse response, @PathVariable String tableId, @PathVariable String templateType) throws IOException {
|
||||
byte[] data = generatorTableService.downloadCode(tableId, templateType);
|
||||
GeneratorUtil.download(response, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步表结构
|
||||
*/
|
||||
@GetMapping("/syncTable/{tableId}")
|
||||
public AjaxResult syncTable(@PathVariable String tableId) {
|
||||
generatorTableService.syncTable(tableId);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.qiaoba.module.generator.entity;
|
||||
|
||||
import com.qiaoba.common.base.enums.BaseEnum;
|
||||
import com.qiaoba.common.base.util.ArrayUtil;
|
||||
import com.qiaoba.module.generator.constant.GenConstants;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/7/3 9:40
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class Generator implements Serializable {
|
||||
|
||||
private GeneratorTable table;
|
||||
|
||||
private List<GeneratorTableColumn> columns;
|
||||
|
||||
private List<GeneratorTableColumn> queryColumns;
|
||||
|
||||
private GeneratorTableColumn pkColumn;
|
||||
|
||||
public boolean isBaseColumn(String column) {
|
||||
return ArrayUtil.contains(GenConstants.BASE_ENTITY, column);
|
||||
}
|
||||
|
||||
public boolean isQueryColumn(String isQuery) {
|
||||
return BaseEnum.YES.getCode().equals(isQuery);
|
||||
}
|
||||
|
||||
public boolean isPk(String isPk) {
|
||||
return BaseEnum.YES.getCode().equals(isPk);
|
||||
}
|
||||
|
||||
public Generator(GeneratorTable table, List<GeneratorTableColumn> columns) {
|
||||
this.table = table;
|
||||
this.columns = columns;
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package com.qiaoba.module.generator.entity;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* 业务表 gen_table
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Data
|
||||
@TableName("generator_table")
|
||||
public class GeneratorTable implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId
|
||||
private String tableId;
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表描述
|
||||
*/
|
||||
private String tableComment;
|
||||
|
||||
/**
|
||||
* 实体类名称(首字母大写)
|
||||
*/
|
||||
private String className;
|
||||
|
||||
/**
|
||||
* 生成包路径
|
||||
*/
|
||||
private String packageName;
|
||||
|
||||
/**
|
||||
* 生成模块名
|
||||
*/
|
||||
private String moduleName;
|
||||
|
||||
/**
|
||||
* 生成业务名
|
||||
*/
|
||||
private String businessName;
|
||||
|
||||
/**
|
||||
* 生成功能名
|
||||
*/
|
||||
private String functionName;
|
||||
|
||||
/**
|
||||
* 生成作者
|
||||
*/
|
||||
private String author;
|
||||
|
||||
/**
|
||||
* 父级菜单ID
|
||||
*/
|
||||
private String parentMenuId;
|
||||
|
||||
/**
|
||||
* 文档开关
|
||||
*/
|
||||
private String docFlag;
|
||||
|
||||
/**
|
||||
* Excel导出开关
|
||||
*/
|
||||
private String excelFlag;
|
||||
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
package com.qiaoba.module.generator.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 表字段
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 10:12
|
||||
*/
|
||||
@Data
|
||||
@TableName("generator_table_column")
|
||||
public class GeneratorTableColumn implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId
|
||||
private String columnId;
|
||||
|
||||
/**
|
||||
* 归属表编号
|
||||
*/
|
||||
private String tableId;
|
||||
|
||||
/**
|
||||
* 列名称
|
||||
*/
|
||||
private String columnName;
|
||||
|
||||
/**
|
||||
* 列描述
|
||||
*/
|
||||
private String columnComment;
|
||||
|
||||
/**
|
||||
* 列类型
|
||||
*/
|
||||
private String columnType;
|
||||
|
||||
/**
|
||||
* JAVA类型
|
||||
*/
|
||||
private String javaType;
|
||||
|
||||
/**
|
||||
* JAVA字段名
|
||||
*/
|
||||
private String javaField;
|
||||
|
||||
/**
|
||||
* 是否主键(1是)
|
||||
*/
|
||||
private String isPk;
|
||||
|
||||
/**
|
||||
* 是否必填(1是)
|
||||
*/
|
||||
private String isRequired;
|
||||
|
||||
/**
|
||||
* 是否为插入字段(1是)
|
||||
*/
|
||||
private String isInsert;
|
||||
|
||||
/**
|
||||
* 是否编辑字段(1是)
|
||||
*/
|
||||
private String isEdit;
|
||||
|
||||
/**
|
||||
* 是否列表字段(1是)
|
||||
*/
|
||||
private String isList;
|
||||
|
||||
/**
|
||||
* 是否查询字段(1是)
|
||||
*/
|
||||
private String isQuery;
|
||||
|
||||
/**
|
||||
* 查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围)
|
||||
*/
|
||||
private String queryType;
|
||||
|
||||
/**
|
||||
* 显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、image图片上传控件、upload文件上传控件、editor富文本控件)
|
||||
*/
|
||||
private String htmlType;
|
||||
|
||||
/**
|
||||
* 字典类型
|
||||
*/
|
||||
private String dictType;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package com.qiaoba.module.generator.entity.dto;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.qiaoba.module.generator.entity.GeneratorTableColumn;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 表字段信息
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 10:12
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class GeneratorTableDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId
|
||||
private String tableId;
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表描述
|
||||
*/
|
||||
private String tableComment;
|
||||
|
||||
/**
|
||||
* 实体类名称(首字母大写)
|
||||
*/
|
||||
private String className;
|
||||
|
||||
/**
|
||||
* 生成包路径
|
||||
*/
|
||||
private String packageName;
|
||||
|
||||
/**
|
||||
* 生成模块名
|
||||
*/
|
||||
private String moduleName;
|
||||
|
||||
/**
|
||||
* 生成业务名
|
||||
*/
|
||||
private String businessName;
|
||||
|
||||
/**
|
||||
* 生成功能名
|
||||
*/
|
||||
private String functionName;
|
||||
|
||||
/**
|
||||
* 生成作者
|
||||
*/
|
||||
private String author;
|
||||
|
||||
/**
|
||||
* 生成路径(不填默认项目路径)
|
||||
*/
|
||||
private String genPath;
|
||||
|
||||
/**
|
||||
* 父级菜单ID
|
||||
*/
|
||||
private String parentMenuId;
|
||||
|
||||
/**
|
||||
* 字段信息
|
||||
*/
|
||||
private List<GeneratorTableColumn> columns;
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.qiaoba.module.generator.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 数据库表信息
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 9:21
|
||||
*/
|
||||
@Data
|
||||
public class TableDto implements Serializable {
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表描述
|
||||
*/
|
||||
private String tableComment;
|
||||
|
||||
/**
|
||||
* 数据库类型 Mysql/Oracle/PgSql/Sql Server
|
||||
*/
|
||||
private String dbType;
|
||||
|
||||
/**
|
||||
* 模式
|
||||
*/
|
||||
private String schema;
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.qiaoba.module.generator.entity.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 数据库表信息
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 9:21
|
||||
*/
|
||||
@Data
|
||||
public class DbTableVo implements Serializable {
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表描述
|
||||
*/
|
||||
private String tableComment;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.qiaoba.module.generator.entity.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 表字段信息
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 10:12
|
||||
*/
|
||||
@Data
|
||||
public class TableColumnVo implements Serializable {
|
||||
|
||||
/**
|
||||
* 列名称
|
||||
*/
|
||||
private String columnName;
|
||||
|
||||
/**
|
||||
* 列描述
|
||||
*/
|
||||
private String columnComment;
|
||||
|
||||
/**
|
||||
* 是否必填(1是)
|
||||
*/
|
||||
private String isRequired;
|
||||
|
||||
/**
|
||||
* 是否主键(1是)
|
||||
*/
|
||||
private String isPk;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 列类型
|
||||
*/
|
||||
private String columnType;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.qiaoba.module.generator.factory;
|
||||
|
||||
import com.qiaoba.common.base.constant.BaseConstant;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* VelocityEngine工厂
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class VelocityFactory {
|
||||
/**
|
||||
* 初始化vm方法
|
||||
*/
|
||||
public static void init() {
|
||||
Properties p = new Properties();
|
||||
try {
|
||||
// 加载classpath目录下的vm文件
|
||||
p.setProperty("resource.loader.file.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
|
||||
// 定义字符集
|
||||
p.setProperty(Velocity.INPUT_ENCODING, BaseConstant.UTF8);
|
||||
// 初始化Velocity引擎,指定配置Properties
|
||||
Velocity.init(p);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.qiaoba.module.generator.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qiaoba.module.generator.entity.GeneratorTableColumn;
|
||||
import com.qiaoba.module.generator.entity.vo.TableColumnVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 表字段 数据层
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 10:12
|
||||
*/
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
public interface GeneratorTableColumnMapper extends BaseMapper<GeneratorTableColumn> {
|
||||
|
||||
/**
|
||||
* 查询表的字段信息
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @return list
|
||||
*/
|
||||
List<TableColumnVo> selectDbColumnList(String tableName);
|
||||
|
||||
/**
|
||||
* 通过 tableIds 批量删除
|
||||
*
|
||||
* @param tableIds tableIds
|
||||
*/
|
||||
void deleteByTableIds(List<String> tableIds);
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.qiaoba.module.generator.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.qiaoba.module.generator.entity.GeneratorTable;
|
||||
import com.qiaoba.module.generator.entity.dto.TableDto;
|
||||
import com.qiaoba.module.generator.entity.vo.DbTableVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 数据库表 数据层
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 9:24
|
||||
*/
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
public interface GeneratorTableMapper extends BaseMapper<GeneratorTable> {
|
||||
|
||||
/**
|
||||
* 查询数据库表
|
||||
*
|
||||
* @param page 分页
|
||||
* @param dto 查询参数
|
||||
* @return list
|
||||
*/
|
||||
Page<DbTableVo> selectPageDbTableList(Page page, @Param("dto") TableDto dto);
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package com.qiaoba.module.generator.service;
|
||||
|
||||
import com.qiaoba.module.generator.entity.GeneratorTableColumn;
|
||||
import com.qiaoba.module.generator.entity.vo.TableColumnVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 表字段 服务层
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 10:12
|
||||
*/
|
||||
public interface GeneratorTableColumnService {
|
||||
|
||||
/**
|
||||
* 查询表的字段信息
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param allowNull 允许空
|
||||
* @return list
|
||||
*/
|
||||
List<TableColumnVo> selectDbColumnList(String tableName, boolean allowNull);
|
||||
|
||||
/**
|
||||
* 查询表的字段信息
|
||||
*
|
||||
* @param tableId 表ID
|
||||
* @param allowNull 允许空
|
||||
* @return list
|
||||
*/
|
||||
List<GeneratorTableColumn> selectListByTableId(String tableId, boolean allowNull);
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*
|
||||
* @param generatorTableColumn column
|
||||
* @return 结果
|
||||
*/
|
||||
Integer insert(GeneratorTableColumn generatorTableColumn);
|
||||
|
||||
/**
|
||||
* 根据ID更新
|
||||
*
|
||||
* @param generatorTableColumn generatorTableColumn
|
||||
*/
|
||||
void updateById(GeneratorTableColumn generatorTableColumn);
|
||||
|
||||
/**
|
||||
* 批量根据ID更新
|
||||
*
|
||||
* @param columns columns
|
||||
*/
|
||||
void updateBatchById(List<GeneratorTableColumn> columns);
|
||||
|
||||
/**
|
||||
* 通过 tableIds 批量删除
|
||||
*
|
||||
* @param tableIds tableIds
|
||||
*/
|
||||
void deleteByTableIds(List<String> tableIds);
|
||||
|
||||
/**
|
||||
* 通过主键批量删除
|
||||
*
|
||||
* @param ids 主键Ids
|
||||
*/
|
||||
void deleteByIds(List<String> ids);
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
package com.qiaoba.module.generator.service;
|
||||
|
||||
import com.qiaoba.common.database.entity.PageQuery;
|
||||
import com.qiaoba.common.database.entity.TableDataInfo;
|
||||
import com.qiaoba.module.generator.entity.GeneratorTable;
|
||||
import com.qiaoba.module.generator.entity.dto.TableDto;
|
||||
import com.qiaoba.module.generator.entity.vo.DbTableVo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 数据库表 服务层
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 9:24
|
||||
*/
|
||||
public interface GeneratorTableService {
|
||||
|
||||
/**
|
||||
* 查询代码生成列表
|
||||
*
|
||||
* @param dto 查询条件
|
||||
* @param pageQuery 分页
|
||||
* @return list
|
||||
*/
|
||||
TableDataInfo<GeneratorTable> selectPageList(TableDto dto, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询代码生成详细
|
||||
*
|
||||
* @param tableId tableId
|
||||
* @return info
|
||||
*/
|
||||
GeneratorTable selectById(String tableId);
|
||||
|
||||
/**
|
||||
* 更新代码生成
|
||||
*
|
||||
* @param generatorTable generatorTable
|
||||
* @return 结果
|
||||
*/
|
||||
int updateById(GeneratorTable generatorTable);
|
||||
|
||||
/**
|
||||
* 分页查询数据库表
|
||||
*
|
||||
* @param dto 查询条件
|
||||
* @param pageQuery 分页信息
|
||||
* @return list
|
||||
*/
|
||||
TableDataInfo<DbTableVo> selectPageDbTableList(TableDto dto, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 通过表名查询代码生成
|
||||
*
|
||||
* @param tableId 表ID
|
||||
* @param allowNull 允许空
|
||||
* @return GeneratorTable
|
||||
*/
|
||||
GeneratorTable selectByTableId(String tableId, boolean allowNull);
|
||||
|
||||
/**
|
||||
* 导入表结构
|
||||
*
|
||||
* @param dto dto
|
||||
* @return 结果
|
||||
*/
|
||||
int importTable(TableDto dto);
|
||||
|
||||
/**
|
||||
* 下载
|
||||
*
|
||||
* @param tableId 表ID
|
||||
* @param templateType 模板类型(前端/后端/sql/全部)
|
||||
* @return 文件字节
|
||||
*/
|
||||
byte[] downloadCode(String tableId, String templateType);
|
||||
|
||||
/**
|
||||
* 预览代码
|
||||
*
|
||||
* @param tableId tableId
|
||||
* @param templateType 模板类型(前端/后端/sql/全部)
|
||||
* @return 结果
|
||||
*/
|
||||
Map<String, String> previewCode(String tableId, String templateType);
|
||||
|
||||
/**
|
||||
* 批量删除代码生成
|
||||
*
|
||||
* @param tableIds tableIds
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteByIds(List<String> tableIds);
|
||||
|
||||
/**
|
||||
* 同步表结构
|
||||
*
|
||||
* @param tableId 表ID
|
||||
*/
|
||||
void syncTable(String tableId);
|
||||
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package com.qiaoba.module.generator.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.Db;
|
||||
import com.qiaoba.common.base.exception.ServiceException;
|
||||
import com.qiaoba.module.generator.entity.GeneratorTableColumn;
|
||||
import com.qiaoba.module.generator.entity.vo.TableColumnVo;
|
||||
import com.qiaoba.module.generator.mapper.GeneratorTableColumnMapper;
|
||||
import com.qiaoba.module.generator.service.GeneratorTableColumnService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 表字段 服务层实现
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 10:12
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class GeneratorTableColumnServiceImpl implements GeneratorTableColumnService {
|
||||
|
||||
private final GeneratorTableColumnMapper generatorTableColumnMapper;
|
||||
|
||||
@Override
|
||||
public List<TableColumnVo> selectDbColumnList(String tableName, boolean allowNull) {
|
||||
List<TableColumnVo> list = generatorTableColumnMapper.selectDbColumnList(tableName);
|
||||
if (CollUtil.isEmpty(list) && !allowNull) {
|
||||
throw new ServiceException(StrUtil.format("未查询到表字段信息, 表名: {}", tableName));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GeneratorTableColumn> selectListByTableId(String tableId, boolean allowNull) {
|
||||
QueryWrapper<GeneratorTableColumn> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda().eq(GeneratorTableColumn::getTableId, tableId);
|
||||
List<GeneratorTableColumn> list = generatorTableColumnMapper.selectList(wrapper);
|
||||
if (CollUtil.isEmpty(list) && !allowNull) {
|
||||
throw new ServiceException(StrUtil.format("未查询到表字段信息, tableId: {}", tableId));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Integer insert(GeneratorTableColumn generatorTableColumn) {
|
||||
return generatorTableColumnMapper.insert(generatorTableColumn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateById(GeneratorTableColumn generatorTableColumn) {
|
||||
generatorTableColumnMapper.updateById(generatorTableColumn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBatchById(List<GeneratorTableColumn> columns) {
|
||||
Db.updateBatchById(columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByTableIds(List<String> tableIds) {
|
||||
generatorTableColumnMapper.deleteByTableIds(tableIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByIds(List<String> ids) {
|
||||
generatorTableColumnMapper.deleteBatchIds(ids);
|
||||
}
|
||||
}
|
@ -0,0 +1,245 @@
|
||||
package com.qiaoba.module.generator.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.qiaoba.common.base.constant.BaseConstant;
|
||||
import com.qiaoba.common.base.enums.BaseEnum;
|
||||
import com.qiaoba.common.base.exception.ServiceException;
|
||||
import com.qiaoba.common.database.context.TenantDbTypeContext;
|
||||
import com.qiaoba.common.database.entity.PageQuery;
|
||||
import com.qiaoba.common.database.entity.TableDataInfo;
|
||||
import com.qiaoba.module.generator.entity.Generator;
|
||||
import com.qiaoba.module.generator.entity.GeneratorTable;
|
||||
import com.qiaoba.module.generator.entity.GeneratorTableColumn;
|
||||
import com.qiaoba.module.generator.entity.dto.TableDto;
|
||||
import com.qiaoba.module.generator.entity.vo.DbTableVo;
|
||||
import com.qiaoba.module.generator.entity.vo.TableColumnVo;
|
||||
import com.qiaoba.module.generator.factory.VelocityFactory;
|
||||
import com.qiaoba.module.generator.mapper.GeneratorTableMapper;
|
||||
import com.qiaoba.module.generator.service.GeneratorTableColumnService;
|
||||
import com.qiaoba.module.generator.service.GeneratorTableService;
|
||||
import com.qiaoba.module.generator.util.GeneratorUtil;
|
||||
import com.qiaoba.module.generator.util.VelocityUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
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 ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 10:12
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class GeneratorTableServiceImpl implements GeneratorTableService {
|
||||
|
||||
private final GeneratorTableMapper generatorTableMapper;
|
||||
private final GeneratorTableColumnService generatorTableColumnService;
|
||||
|
||||
@Override
|
||||
public TableDataInfo<GeneratorTable> selectPageList(TableDto dto, PageQuery pageQuery) {
|
||||
QueryWrapper<GeneratorTable> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda()
|
||||
.like(StrUtil.isNotBlank(dto.getTableName()), GeneratorTable::getTableName, dto.getTableName())
|
||||
.like(StrUtil.isNotBlank(dto.getTableComment()), GeneratorTable::getTableComment, dto.getTableComment());
|
||||
return TableDataInfo.build(generatorTableMapper.selectPage(pageQuery.build(), wrapper));
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneratorTable selectById(String tableId) {
|
||||
return generatorTableMapper.selectById(tableId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateById(GeneratorTable generatorTable) {
|
||||
return generatorTableMapper.updateById(generatorTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo<DbTableVo> selectPageDbTableList(TableDto dto, PageQuery pageQuery) {
|
||||
dto.setDbType(TenantDbTypeContext.getDefault());
|
||||
dto.setSchema(selectSchema());
|
||||
return TableDataInfo.build(generatorTableMapper.selectPageDbTableList(pageQuery.build(), dto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneratorTable selectByTableId(String tableId, boolean allowNull) {
|
||||
GeneratorTable generatorTable = generatorTableMapper.selectById(tableId);
|
||||
if (Objects.isNull(generatorTable) && !allowNull) {
|
||||
throw new ServiceException(StrUtil.format("未查到表信息, 表ID: {}", tableId));
|
||||
}
|
||||
return generatorTable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int importTable(TableDto dto) {
|
||||
GeneratorTable generatorTable = GeneratorUtil.dtoToGeneratorTable(dto);
|
||||
int result = generatorTableMapper.insert(generatorTable);
|
||||
if (result > BaseConstant.HANDLE_ERROR) {
|
||||
List<TableColumnVo> columnVos = generatorTableColumnService.selectDbColumnList(dto.getTableName(), false);
|
||||
for (TableColumnVo columnVo : columnVos) {
|
||||
GeneratorTableColumn generatorTableColumn = GeneratorUtil.initColumn(columnVo, generatorTable.getTableId());
|
||||
generatorTableColumnService.insert(generatorTableColumn);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] downloadCode(String tableId, String templateType) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||
generatorCode(tableId, templateType, zip);
|
||||
IoUtil.close(zip);
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> previewCode(String tableId, String templateType) {
|
||||
Map<String, String> dataMap = new LinkedHashMap<>();
|
||||
// 查询表信息
|
||||
GeneratorTable table = selectByTableId(tableId, false);
|
||||
// 查询字段信息
|
||||
List<GeneratorTableColumn> columns = generatorTableColumnService.selectListByTableId(table.getTableId(), false);
|
||||
Generator generator = new Generator(table, columns);
|
||||
// 设置主键列信息
|
||||
setPkColumn(generator);
|
||||
// 设置查询字段信息
|
||||
setQueryColumns(generator);
|
||||
// 初始化 Velocity
|
||||
VelocityFactory.init();
|
||||
// 设置参数
|
||||
VelocityContext context = VelocityUtil.setVariables(generator);
|
||||
// 获取模板列表
|
||||
List<String> templates = VelocityUtil.getTemplateList(templateType);
|
||||
for (String template : templates) {
|
||||
// 渲染模板
|
||||
StringWriter sw = new StringWriter();
|
||||
Template tpl = Velocity.getTemplate(template, BaseConstant.UTF8);
|
||||
tpl.merge(context, sw);
|
||||
dataMap.put(template, sw.toString());
|
||||
}
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int deleteByIds(List<String> tableIds) {
|
||||
int result = generatorTableMapper.deleteBatchIds(tableIds);
|
||||
if (result > BaseConstant.HANDLE_ERROR) {
|
||||
generatorTableColumnService.deleteByTableIds(tableIds);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void syncTable(String tableId) {
|
||||
// 查询表信息
|
||||
GeneratorTable table = selectByTableId(tableId, false);
|
||||
// 查询最新表结构
|
||||
List<TableColumnVo> dbColumns = generatorTableColumnService.selectDbColumnList(table.getTableName(), false);
|
||||
// 查询保存的表结构
|
||||
List<GeneratorTableColumn> generatorTableColumns = generatorTableColumnService.selectListByTableId(tableId, false);
|
||||
// 构造比较map
|
||||
Map<String, GeneratorTableColumn> generatorTableColumnMap = generatorTableColumns.stream().collect(Collectors.toMap(GeneratorTableColumn::getColumnName, Function.identity()));
|
||||
List<String> dbTableColumnNames = dbColumns.stream().map(TableColumnVo::getColumnName).collect(Collectors.toList());
|
||||
// 开始比较
|
||||
dbColumns.forEach(column -> {
|
||||
GeneratorTableColumn generatorTableColumn = GeneratorUtil.initColumn(column, tableId);
|
||||
// 字段名不变
|
||||
if (generatorTableColumnMap.containsKey(column.getColumnName())) {
|
||||
GeneratorTableColumn prevColumn = generatorTableColumnMap.get(column.getColumnName());
|
||||
generatorTableColumn.setColumnId(prevColumn.getColumnId());
|
||||
if (BaseEnum.YES.getCode().equals(generatorTableColumn.getIsList())) {
|
||||
// 如果是列表,继续保留查询方式/字典类型选项
|
||||
generatorTableColumn.setDictType(prevColumn.getDictType());
|
||||
generatorTableColumn.setQueryType(prevColumn.getQueryType());
|
||||
}
|
||||
generatorTableColumnService.updateById(generatorTableColumn);
|
||||
} else {
|
||||
generatorTableColumnService.insert(generatorTableColumn);
|
||||
}
|
||||
});
|
||||
|
||||
List<String> deleteIds = new ArrayList<>();
|
||||
for (GeneratorTableColumn generatorTableColumn : generatorTableColumns) {
|
||||
if (!dbTableColumnNames.contains(generatorTableColumn.getColumnName())) {
|
||||
deleteIds.add(generatorTableColumn.getColumnId());
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(deleteIds)) {
|
||||
generatorTableColumnService.deleteByIds(deleteIds);
|
||||
}
|
||||
}
|
||||
|
||||
private void generatorCode(String tableId, String templateType, ZipOutputStream zip) {
|
||||
// 查询表信息
|
||||
GeneratorTable table = selectByTableId(tableId, false);
|
||||
Map<String, String> dataMap = previewCode(tableId, templateType);
|
||||
for (String key : dataMap.keySet()) {
|
||||
String code = dataMap.get(key);
|
||||
try {
|
||||
// 添加到zip
|
||||
zip.putNextEntry(new ZipEntry(VelocityUtil.getFileName(key, table)));
|
||||
IoUtil.write(zip, false, code.getBytes());
|
||||
zip.flush();
|
||||
zip.closeEntry();
|
||||
} catch (IOException e) {
|
||||
log.error("渲染模板失败,表名:" + table.getTableName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String selectSchema() {
|
||||
// PgSQL 需要设置 schema
|
||||
//DataBaseEnum.POSTGRE_SQL.getType().equals(dbType)
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置主键列信息
|
||||
*
|
||||
* @param generator generator
|
||||
*/
|
||||
private void setPkColumn(Generator generator) {
|
||||
for (GeneratorTableColumn column : generator.getColumns()) {
|
||||
if (BaseEnum.YES.getCode().equals(column.getIsPk())) {
|
||||
generator.setPkColumn(column);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isNull(generator.getPkColumn())) {
|
||||
generator.setPkColumn(generator.getColumns().get(0));
|
||||
}
|
||||
}
|
||||
|
||||
private void setQueryColumns(Generator generator) {
|
||||
List<GeneratorTableColumn> queryColumns = new ArrayList<>();
|
||||
for (GeneratorTableColumn column : generator.getColumns()) {
|
||||
if (generator.isQueryColumn(column.getIsQuery())) {
|
||||
queryColumns.add(column);
|
||||
}
|
||||
}
|
||||
generator.setQueryColumns(queryColumns);
|
||||
}
|
||||
}
|
@ -0,0 +1,193 @@
|
||||
package com.qiaoba.module.generator.util;
|
||||
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.qiaoba.common.base.constant.BaseConstant;
|
||||
import com.qiaoba.common.base.util.ArrayUtil;
|
||||
import com.qiaoba.module.generator.config.GeneratorConfig;
|
||||
import com.qiaoba.module.generator.constant.GenConstants;
|
||||
import com.qiaoba.module.generator.entity.GeneratorTable;
|
||||
import com.qiaoba.module.generator.entity.GeneratorTableColumn;
|
||||
import com.qiaoba.module.generator.entity.dto.TableDto;
|
||||
import com.qiaoba.module.generator.entity.vo.TableColumnVo;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* GeneratorUtil
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/26 9:24
|
||||
*/
|
||||
public class GeneratorUtil {
|
||||
|
||||
public static GeneratorTableColumn initColumn(TableColumnVo vo, String tableId) {
|
||||
GeneratorTableColumn column = new GeneratorTableColumn();
|
||||
column.setTableId(tableId);
|
||||
column.setSort(vo.getSort());
|
||||
column.setColumnName(vo.getColumnName());
|
||||
column.setColumnComment(vo.getColumnComment());
|
||||
// 设置java字段名
|
||||
column.setJavaField(StrUtil.toCamelCase(column.getColumnName()));
|
||||
// 设置默认类型
|
||||
column.setJavaType(GenConstants.TYPE_STRING);
|
||||
column.setQueryType(GenConstants.QUERY_EQ);
|
||||
column.setColumnType(vo.getColumnType());
|
||||
setType(column, vo.getColumnType());
|
||||
|
||||
column.setIsPk(vo.getIsPk());
|
||||
column.setIsRequired(vo.getIsRequired());
|
||||
// (排除基类字段)
|
||||
if (!ArrayUtil.contains(GenConstants.COLUMN_NAME_NOT_HANDLE, column.getColumnName()) && !BaseConstant.YES.equals(column.getIsPk())) {
|
||||
column.setIsInsert(GenConstants.REQUIRE);
|
||||
column.setIsEdit(GenConstants.REQUIRE);
|
||||
column.setIsList(GenConstants.REQUIRE);
|
||||
|
||||
}
|
||||
|
||||
// 查询字段
|
||||
if (ArrayUtil.containsValueIgnoreCase(GenConstants.HTML_LIKE_COLUMN, column.getColumnName())) {
|
||||
column.setIsQuery(GenConstants.REQUIRE);
|
||||
column.setQueryType(GenConstants.QUERY_LIKE);
|
||||
}
|
||||
return column;
|
||||
}
|
||||
|
||||
public static GeneratorTable dtoToGeneratorTable(TableDto dto) {
|
||||
GeneratorTable generatorTable = new GeneratorTable();
|
||||
generatorTable.setTableName(dto.getTableName());
|
||||
generatorTable.setTableComment(dto.getTableComment());
|
||||
generatorTable.setClassName(tableNameToClassName(dto.getTableName()));
|
||||
generatorTable.setPackageName(GeneratorConfig.PACKAGE_NAME);
|
||||
generatorTable.setModuleName(packageNameToModuleName(GeneratorConfig.PACKAGE_NAME));
|
||||
generatorTable.setBusinessName(tableNameToBusinessName(dto.getTableName()));
|
||||
generatorTable.setFunctionName(commentToBusinessName(dto.getTableComment()));
|
||||
generatorTable.setAuthor(GeneratorConfig.AUTHOR);
|
||||
return generatorTable;
|
||||
}
|
||||
|
||||
private static String tableNameToClassName(String tableName) {
|
||||
// 去除前缀
|
||||
// eg: 表名: bz_sys_user 前缀: bz_ 去除后 sys_user
|
||||
if (GeneratorConfig.AUTO_REMOVE_PREFIX && StrUtil.isNotBlank(GeneratorConfig.TABLE_PREFIX)) {
|
||||
List<String> prefixList = StrUtil.split(GeneratorConfig.TABLE_PREFIX, BaseConstant.DEFAULT_SPLIT_STR);
|
||||
for (String prefix : prefixList) {
|
||||
if (tableName.startsWith(prefix)) {
|
||||
tableName = StrUtil.removePrefix(tableName, prefix);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 下划线转驼峰 sys_user -> sysUser
|
||||
tableName = StrUtil.toCamelCase(tableName);
|
||||
// 首字符大写 sysUser -> SysUser
|
||||
return StrUtil.upperFirst(tableName);
|
||||
}
|
||||
|
||||
private static String packageNameToModuleName(String packageName) {
|
||||
int lastIndex = packageName.lastIndexOf(".");
|
||||
int nameLength = packageName.length();
|
||||
return StrUtil.sub(packageName, lastIndex + 1, nameLength);
|
||||
}
|
||||
|
||||
private static String tableNameToBusinessName(String tableName) {
|
||||
int lastIndex = tableName.lastIndexOf("_");
|
||||
int nameLength = tableName.length();
|
||||
return StrUtil.sub(tableName, lastIndex + 1, nameLength);
|
||||
}
|
||||
|
||||
private static String commentToBusinessName(String comment) {
|
||||
// 用户表 -> 用户
|
||||
return StrUtil.isNotBlank(comment) ? StrUtil.replaceLast(comment, "表", "") : comment;
|
||||
}
|
||||
|
||||
private static void setType(GeneratorTableColumn column, String columnType) {
|
||||
// varchar(50) -> varchar
|
||||
columnType = StrUtil.subBefore(columnType, "(", false);
|
||||
// 字符串 or 长文本
|
||||
if (ArrayUtil.contains(GenConstants.COLUMN_TYPE_STR, columnType) || ArrayUtil.contains(GenConstants.COLUMN_TYPE_TEXT, columnType)) {
|
||||
// 字符串长度超过500设置为文本域
|
||||
Integer columnLength = getColumnLength(column.getColumnType());
|
||||
String htmlType = columnLength >= 500 || ArrayUtil.contains(GenConstants.COLUMN_TYPE_TEXT, columnType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT;
|
||||
column.setHtmlType(htmlType);
|
||||
}
|
||||
|
||||
// 时间类型
|
||||
if (ArrayUtil.contains(GenConstants.COLUMN_TYPE_TIME, columnType)) {
|
||||
column.setJavaType(GenConstants.TYPE_DATE);
|
||||
column.setHtmlType(GenConstants.HTML_DATETIME);
|
||||
}
|
||||
|
||||
// 数字类型
|
||||
if (ArrayUtil.contains(GenConstants.COLUMN_TYPE_NUMBER, columnType)) {
|
||||
column.setHtmlType(GenConstants.HTML_INPUT);
|
||||
// 如果是浮点型 统一用BigDecimal
|
||||
List<String> strList = StrUtil.split(StrUtil.subBetween(column.getColumnType(), "(", ")"), ",");
|
||||
|
||||
if (strList != null && strList.size() == 2 && Integer.parseInt(strList.get(1)) > 0) {
|
||||
column.setJavaType(GenConstants.TYPE_BIGDECIMAL);
|
||||
}
|
||||
// 如果是整形
|
||||
else if (strList != null && strList.size() == 1 && Integer.parseInt(strList.get(0)) <= 10) {
|
||||
column.setJavaType(GenConstants.TYPE_INTEGER);
|
||||
}
|
||||
// 长整形
|
||||
else {
|
||||
column.setJavaType(GenConstants.TYPE_LONG);
|
||||
}
|
||||
}
|
||||
|
||||
// 单选框
|
||||
if (ArrayUtil.containsValueIgnoreCase(GenConstants.HTML_RADIO_COLUMN, column.getColumnName())) {
|
||||
column.setHtmlType(GenConstants.HTML_RADIO);
|
||||
}
|
||||
// 下拉框
|
||||
if (ArrayUtil.containsValueIgnoreCase(GenConstants.HTML_SELECT_COLUMN, column.getColumnName())) {
|
||||
column.setHtmlType(GenConstants.HTML_SELECT);
|
||||
}
|
||||
// 图片上传控件
|
||||
if (ArrayUtil.containsValueIgnoreCase(GenConstants.HTML_IMAGE_COLUMN, column.getColumnName())) {
|
||||
column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD);
|
||||
}
|
||||
// 文件上传控件
|
||||
if (ArrayUtil.containsValueIgnoreCase(GenConstants.HTML_FILE_COLUMN, column.getColumnName())) {
|
||||
column.setHtmlType(GenConstants.HTML_FILE_UPLOAD);
|
||||
}
|
||||
// 富文本控件
|
||||
if (ArrayUtil.containsValueIgnoreCase(GenConstants.HTML_EDITOR_COLUMN, column.getColumnName())) {
|
||||
column.setHtmlType(GenConstants.HTML_EDITOR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字段长度
|
||||
*
|
||||
* @param columnType 列类型
|
||||
* @return 截取后的列类型
|
||||
*/
|
||||
private static Integer getColumnLength(String columnType) {
|
||||
// bigint(20)
|
||||
try {
|
||||
String length = StrUtil.subBetween(columnType, "(", ")");
|
||||
return Integer.valueOf(length);
|
||||
} catch (NumberFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成zip文件
|
||||
*/
|
||||
public static void download(HttpServletResponse response, byte[] data) throws IOException {
|
||||
response.reset();
|
||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
response.addHeader("Content-Length", String.valueOf(data.length));
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
IoUtil.write(response.getOutputStream(), true, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,241 @@
|
||||
package com.qiaoba.module.generator.util;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.Snowflake;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.qiaoba.common.base.constant.BaseConstant;
|
||||
import com.qiaoba.common.base.context.BaseContext;
|
||||
import com.qiaoba.common.base.enums.BaseEnum;
|
||||
import com.qiaoba.module.generator.constant.GenConstants;
|
||||
import com.qiaoba.module.generator.entity.Generator;
|
||||
import com.qiaoba.module.generator.entity.GeneratorTable;
|
||||
import com.qiaoba.module.generator.entity.GeneratorTableColumn;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 模板生成 工具类
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/7/3 9:22
|
||||
*/
|
||||
public class VelocityUtil {
|
||||
|
||||
private static final List<String> TEMPLATE_JAVA = new ArrayList<>();
|
||||
private static final List<String> TEMPLATE_VUE = new ArrayList<>();
|
||||
private static final List<String> TEMPLATE_SQL = new ArrayList<>();
|
||||
|
||||
private static final String VM_CONTROLLER = "controller.java.qb";
|
||||
private static final String VM_DOMAIN = "entity.java.qb";
|
||||
private static final String VM_DTO = "dto.java.qb";
|
||||
private static final String VM_PARAM = "param.java.qb";
|
||||
private static final String VM_EXCEL_EXPORT = "export.java.qb";
|
||||
private static final String VM_MAPPER = "mapper.java.qb";
|
||||
private static final String VM_SERVICE = "service.java.qb";
|
||||
private static final String VM_SERVICE_IMPL = "serviceImpl.java.qb";
|
||||
private static final String VM_SQL = "sql.qb";
|
||||
private static final String VM_API_JS = "api.js.qb";
|
||||
private static final String VM_INDEX_VUE = "index.qb";
|
||||
|
||||
/**
|
||||
* 项目空间路径
|
||||
*/
|
||||
private static final String PROJECT_PATH = "main/java";
|
||||
|
||||
|
||||
static {
|
||||
// 后端
|
||||
TEMPLATE_JAVA.add("vm/java/entity.java.qb");
|
||||
TEMPLATE_JAVA.add("vm/java/dto.java.qb");
|
||||
TEMPLATE_JAVA.add("vm/java/param.java.qb");
|
||||
TEMPLATE_JAVA.add("vm/java/export.java.qb");
|
||||
TEMPLATE_JAVA.add("vm/java/controller.java.qb");
|
||||
TEMPLATE_JAVA.add("vm/java/service.java.qb");
|
||||
TEMPLATE_JAVA.add("vm/java/serviceImpl.java.qb");
|
||||
TEMPLATE_JAVA.add("vm/java/mapper.java.qb");
|
||||
// 前端
|
||||
TEMPLATE_VUE.add("vm/js/api.js.qb");
|
||||
TEMPLATE_VUE.add("vm/vue/index.qb");
|
||||
// SQL
|
||||
TEMPLATE_SQL.add("vm/sql/sql.qb");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载模板
|
||||
*
|
||||
* @return 模板集合
|
||||
*/
|
||||
public static List<String> getTemplateList(String templateType) {
|
||||
List<String> templates = new ArrayList<>();
|
||||
// 全部
|
||||
if (GenConstants.TEMPLATE_TYPE_ALL.equals(templateType)) {
|
||||
// 后端
|
||||
templates.addAll(TEMPLATE_JAVA);
|
||||
// 前端
|
||||
templates.addAll(TEMPLATE_VUE);
|
||||
// SQL
|
||||
templates.addAll(TEMPLATE_SQL);
|
||||
|
||||
}
|
||||
// 后端
|
||||
else if (GenConstants.TEMPLATE_TYPE_JAVA.equals(templateType)) {
|
||||
// 后端
|
||||
templates.addAll(TEMPLATE_JAVA);
|
||||
}
|
||||
// 前端
|
||||
else if (GenConstants.TEMPLATE_TYPE_VUE.equals(templateType)) {
|
||||
// 前端
|
||||
templates.addAll(TEMPLATE_VUE);
|
||||
} else {
|
||||
// SQL
|
||||
templates.addAll(TEMPLATE_SQL);
|
||||
}
|
||||
return templates;
|
||||
}
|
||||
|
||||
public static VelocityContext setVariables(Generator generator) {
|
||||
|
||||
String moduleName = generator.getTable().getModuleName();
|
||||
String businessName = generator.getTable().getBusinessName();
|
||||
String packageName = generator.getTable().getPackageName();
|
||||
String functionName = generator.getTable().getFunctionName();
|
||||
|
||||
VelocityContext velocityContext = new VelocityContext();
|
||||
velocityContext.put("tableName" , generator.getTable().getTableName());
|
||||
velocityContext.put("functionName" , StrUtil.isNotBlank(functionName) ? functionName : "【请填写功能名称】");
|
||||
velocityContext.put("ClassName" , generator.getTable().getClassName());
|
||||
velocityContext.put("className" , StringUtils.uncapitalize(generator.getTable().getClassName()));
|
||||
velocityContext.put("moduleName" , generator.getTable().getModuleName());
|
||||
velocityContext.put("BusinessName" , StringUtils.capitalize(generator.getTable().getBusinessName()));
|
||||
velocityContext.put("businessName" , generator.getTable().getBusinessName());
|
||||
velocityContext.put("basePackage" , getPackagePrefix(packageName));
|
||||
velocityContext.put("packageName" , packageName);
|
||||
velocityContext.put("author" , generator.getTable().getAuthor());
|
||||
velocityContext.put("docFlag" , BaseEnum.YES.getCode().equals(generator.getTable().getDocFlag()));
|
||||
velocityContext.put("excelFlag" , BaseEnum.YES.getCode().equals(generator.getTable().getExcelFlag()));
|
||||
velocityContext.put("datetime" , DateUtil.now());
|
||||
velocityContext.put("pkColumn" , generator.getPkColumn());
|
||||
|
||||
velocityContext.put("permissionPrefix" , getPermissionPrefix(moduleName, businessName));
|
||||
velocityContext.put("columns" , generator.getColumns());
|
||||
velocityContext.put("queryColumns" , generator.getQueryColumns());
|
||||
velocityContext.put("table" , generator.getTable());
|
||||
velocityContext.put("generator" , generator);
|
||||
|
||||
velocityContext.put("dicts" , getDict(generator.getColumns()));
|
||||
|
||||
String parentId = new Snowflake().nextIdStr();
|
||||
velocityContext.put("parentId" , parentId);
|
||||
velocityContext.put("insertMenuId" , new Snowflake().nextIdStr());
|
||||
velocityContext.put("updateMenuId" , new Snowflake().nextIdStr());
|
||||
velocityContext.put("deleteMenuId" , new Snowflake().nextIdStr());
|
||||
velocityContext.put("selectMenuId" , new Snowflake().nextIdStr());
|
||||
velocityContext.put("exportMenuId" , new Snowflake().nextIdStr());
|
||||
|
||||
velocityContext.put("tenantId" , BaseContext.getTenantId());
|
||||
|
||||
String parentMenuId = generator.getTable().getParentMenuId();
|
||||
velocityContext.put("parentMenuId" , StrUtil.isNotBlank(parentMenuId) ? parentMenuId : BaseConstant.DEFAULT_PARENT_ID_VALUE);
|
||||
|
||||
return velocityContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取包前缀
|
||||
*
|
||||
* @param packageName 包名称
|
||||
* @return 包前缀名称
|
||||
*/
|
||||
private static String getPackagePrefix(String packageName) {
|
||||
int lastIndex = packageName.lastIndexOf(".");
|
||||
return StringUtils.substring(packageName, 0, lastIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权限前缀
|
||||
*
|
||||
* @param moduleName 模块名称
|
||||
* @param businessName 业务名称
|
||||
* @return 返回权限前缀
|
||||
*/
|
||||
private static String getPermissionPrefix(String moduleName, String businessName) {
|
||||
return StrUtil.format("{}:{}" , moduleName, businessName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据列类型获取字典组
|
||||
*
|
||||
* @param columns columns
|
||||
* @return 返回字典组
|
||||
*/
|
||||
private static String getDict(List<GeneratorTableColumn> columns) {
|
||||
|
||||
Set<String> dictSet = new HashSet<String>();
|
||||
addDictList(dictSet, columns);
|
||||
return StringUtils.join(dictSet, ", ");
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加字典列表
|
||||
*
|
||||
* @param dictSet 字典列表
|
||||
* @param columns 列集合
|
||||
*/
|
||||
private static void addDictList(Set<String> dictSet, List<GeneratorTableColumn> columns) {
|
||||
for (GeneratorTableColumn column : columns) {
|
||||
if (StrUtil.isNotBlank(column.getDictType()) && StringUtils.equalsAny(
|
||||
column.getHtmlType(),
|
||||
new String[]{GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX})) {
|
||||
dictSet.add("'" + column.getDictType() + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件名
|
||||
*/
|
||||
public static String getFileName(String template, GeneratorTable genTable) {
|
||||
// 文件名称
|
||||
String fileName = "";
|
||||
// 包路径
|
||||
String packageName = genTable.getPackageName();
|
||||
// 模块名
|
||||
String moduleName = genTable.getModuleName();
|
||||
// 大写类名
|
||||
String className = genTable.getClassName();
|
||||
// 业务名称
|
||||
String businessName = genTable.getBusinessName();
|
||||
|
||||
String javaPath = PROJECT_PATH + "/" + StrUtil.replace(packageName, "." , "/");
|
||||
String vuePath = "vue";
|
||||
|
||||
if (template.contains(VM_DOMAIN)) {
|
||||
fileName = StrUtil.format("{}/entity/{}.java" , javaPath, className);
|
||||
} else if (template.contains(VM_DTO)) {
|
||||
fileName = StrUtil.format("{}/entity/dto/{}Dto.java" , javaPath, className);
|
||||
} else if (template.contains(VM_EXCEL_EXPORT)) {
|
||||
fileName = StrUtil.format("{}/entity/template/{}Export.java" , javaPath, className);
|
||||
} else if (template.contains(VM_PARAM)) {
|
||||
fileName = StrUtil.format("{}/entity/param/{}Param.java" , javaPath, className);
|
||||
} else if (template.contains(VM_MAPPER)) {
|
||||
fileName = StrUtil.format("{}/mapper/{}Mapper.java" , javaPath, className);
|
||||
} else if (template.contains(VM_SERVICE)) {
|
||||
fileName = StrUtil.format("{}/service/{}Service.java" , javaPath, className);
|
||||
} else if (template.contains(VM_SERVICE_IMPL)) {
|
||||
fileName = StrUtil.format("{}/service/impl/{}ServiceImpl.java" , javaPath, className);
|
||||
} else if (template.contains(VM_CONTROLLER)) {
|
||||
fileName = StrUtil.format("{}/controller/{}Controller.java" , javaPath, className);
|
||||
} else if (template.contains(VM_SQL)) {
|
||||
fileName = businessName + "Menu.sql";
|
||||
} else if (template.contains(VM_API_JS)) {
|
||||
fileName = StrUtil.format("{}/api/{}/{}.js" , vuePath, moduleName, businessName);
|
||||
} else if (template.contains(VM_INDEX_VUE)) {
|
||||
fileName = StrUtil.format("{}/views/{}/{}/index.vue" , vuePath, moduleName, businessName);
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.qiaoba.module.generator.mapper.GeneratorTableColumnMapper">
|
||||
|
||||
<resultMap type="com.qiaoba.module.generator.entity.vo.TableColumnVo" id="DbTableColumnVoResult">
|
||||
<result property="columnName" column="column_name"/>
|
||||
<result property="columnComment" column="column_comment"/>
|
||||
<result property="columnType" column="column_type"/>
|
||||
<result property="isRequired" column="is_required"/>
|
||||
<result property="isPk" column="is_pk"/>
|
||||
<result property="sort" column="sort"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectDbColumnList" resultMap="DbTableColumnVoResult">
|
||||
select 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, column_type
|
||||
from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})
|
||||
order by ordinal_position
|
||||
</select>
|
||||
|
||||
<delete id="deleteByTableIds">
|
||||
delete from generator_table_column where table_id in
|
||||
<foreach collection="list" item="tableId" open="(" separator="," close=")">
|
||||
#{tableId}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.qiaoba.module.generator.mapper.GeneratorTableMapper">
|
||||
|
||||
<resultMap type="com.qiaoba.module.generator.entity.vo.DbTableVo" id="DbTableVoResult">
|
||||
<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>
|
||||
|
||||
<select id="selectPageDbTableList" resultMap="DbTableVoResult">
|
||||
<if test="dto.dbType=='MySQL'.toString()">
|
||||
select table_name, table_comment, create_time, update_time from information_schema.tables
|
||||
where table_schema = (select database())
|
||||
AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'generator_%'
|
||||
AND table_name NOT IN (select table_name from generator_table)
|
||||
<if test="dto.tableName != null and dto.tableName != ''">
|
||||
AND lower(table_name) like lower(concat('%', #{dto.tableName}, '%'))
|
||||
</if>
|
||||
<if test="dto.tableComment != null and dto.tableComment != ''">
|
||||
AND lower(table_comment) like lower(concat('%', #{dto.tableComment}, '%'))
|
||||
</if>
|
||||
order by create_time desc
|
||||
</if>
|
||||
|
||||
<if test="dto.dbType=='Oracle'.toString()">
|
||||
select lower(dt.table_name) as table_name, dtc.comments as table_comment, uo.created as create_time,
|
||||
uo.last_ddl_time as update_time
|
||||
from user_tables dt, user_tab_comments dtc, user_objects uo
|
||||
where dt.table_name = dtc.table_name
|
||||
and dt.table_name = uo.object_name
|
||||
and uo.object_type = 'TABLE'
|
||||
AND dt.table_name NOT LIKE 'XXL_JOB_%' AND dt.table_name NOT LIKE 'GEN_%'
|
||||
AND dt.table_name NOT IN (select table_name from generator_table)
|
||||
<if test="dto.tableName != null and dto.tableName != ''">
|
||||
AND lower(dt.table_name) like lower(concat(concat('%', #{dto.tableName}), '%'))
|
||||
</if>
|
||||
<if test="dto.tableComment != null and dto.tableComment != ''">
|
||||
AND lower(dtc.comments) like lower(concat(concat('%', #{dto.tableComment}), '%'))
|
||||
</if>
|
||||
order by create_time desc
|
||||
</if>
|
||||
|
||||
<if test="dto.dbType=='PostgreSQL'.toString()">
|
||||
select table_name, table_comment, create_time, update_time
|
||||
from (
|
||||
SELECT c.relname AS table_name,
|
||||
obj_description(c.oid) AS table_comment,
|
||||
CURRENT_TIMESTAMP AS create_time,
|
||||
CURRENT_TIMESTAMP AS update_time
|
||||
FROM pg_class c
|
||||
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
|
||||
WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"]))
|
||||
AND c.relname != 'spatial_%'::text
|
||||
AND n.nspname = #{dto.schema}::name
|
||||
AND n.nspname <![CDATA[ <> ]]> ''::name
|
||||
) list_table
|
||||
where table_name NOT LIKE 'xxl_job_%' AND table_name NOT LIKE 'gen_%'
|
||||
AND table_name NOT IN (select table_name from generator_table)
|
||||
<if test="dto.tableName != null and dto.tableName != ''">
|
||||
AND lower(table_name) like lower(concat('%', #{dto.tableName}, '%'))
|
||||
</if>
|
||||
<if test="dto.tableComment != null and dto.tableComment != ''">
|
||||
AND lower(table_comment) like lower(concat('%', #{dto.tableComment}, '%'))
|
||||
</if>
|
||||
order by create_time desc
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
BIN
qiaoba-module/qiaoba-module-generator/src/main/resources/vm.zip
Normal file
BIN
qiaoba-module/qiaoba-module-generator/src/main/resources/vm.zip
Normal file
Binary file not shown.
@ -0,0 +1,127 @@
|
||||
package ${packageName}.controller;
|
||||
|
||||
import com.qiaoba.common.base.result.AjaxResult;
|
||||
import com.qiaoba.common.database.entity.PageQuery;
|
||||
import com.qiaoba.common.database.entity.TableDataInfo;
|
||||
#if($docFlag)
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
#end
|
||||
#if($excelFlag)
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import com.qiaoba.common.poi.util.ExcelUtil;
|
||||
import ${packageName}.entity.template.${ClassName}Export;
|
||||
#end
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ${packageName}.entity.${ClassName};
|
||||
import ${packageName}.entity.dto.${ClassName}Dto;
|
||||
import ${packageName}.entity.param.${ClassName}Param;
|
||||
import ${packageName}.service.${ClassName}Service;
|
||||
|
||||
|
||||
/**
|
||||
* ${functionName} Web层
|
||||
*
|
||||
* @author ${author}
|
||||
* @version 1.0
|
||||
* @since ${datetime}
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/${moduleName}/${businessName}")
|
||||
@RequiredArgsConstructor
|
||||
#if($docFlag)
|
||||
@Tag(name = "${functionName}管理")
|
||||
#end
|
||||
public class ${ClassName}Controller {
|
||||
|
||||
private final ${ClassName}Service ${className}Service;
|
||||
|
||||
#if($docFlag)
|
||||
@Operation(summary = "获取列表")
|
||||
#else
|
||||
/**
|
||||
* 获取列表
|
||||
*/
|
||||
#end
|
||||
@PreAuthorize("hasAuthority('${permissionPrefix}:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<${ClassName}> list(${ClassName}Param param, PageQuery pageQuery) {
|
||||
return ${className}Service.selectPageList(param, pageQuery);
|
||||
}
|
||||
|
||||
#if($docFlag)
|
||||
@Operation(summary = "获取详情")
|
||||
#else
|
||||
/**
|
||||
* 获取详情
|
||||
*/
|
||||
#end
|
||||
@PreAuthorize("hasAuthority('${permissionPrefix}:query')")
|
||||
@GetMapping(value = "/{${pkColumn.javaField}}")
|
||||
public AjaxResult getInfo(@PathVariable String ${pkColumn.javaField}) {
|
||||
return AjaxResult.success(${className}Service.selectById(${pkColumn.javaField}, false));
|
||||
}
|
||||
|
||||
#if($docFlag)
|
||||
@Operation(summary = "新增${functionName}")
|
||||
#else
|
||||
/**
|
||||
* 新增${functionName}
|
||||
*/
|
||||
#end
|
||||
@PreAuthorize("hasAuthority('${permissionPrefix}:add')")
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody ${ClassName}Dto dto) {
|
||||
return AjaxResult.toAjax(${className}Service.insert(dto));
|
||||
|
||||
}
|
||||
|
||||
#if($docFlag)
|
||||
@Operation(summary = "修改${functionName}")
|
||||
#else
|
||||
/**
|
||||
* 修改${functionName}
|
||||
*/
|
||||
#end
|
||||
@PreAuthorize("hasAuthority('${permissionPrefix}:edit')")
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody ${ClassName}Dto dto) {
|
||||
return AjaxResult.toAjax(${className}Service.updateById(dto));
|
||||
|
||||
}
|
||||
|
||||
#if($docFlag)
|
||||
@Operation(summary = "删除${functionName}")
|
||||
#else
|
||||
/**
|
||||
* 删除${functionName}
|
||||
*/
|
||||
#end
|
||||
@PreAuthorize("hasAuthority('${permissionPrefix}:remove')")
|
||||
@DeleteMapping("/{${pkColumn.javaField}s}")
|
||||
public AjaxResult remove(@PathVariable List<String> ${pkColumn.javaField}s) {
|
||||
return AjaxResult.toAjax(${className}Service.deleteByIds(${pkColumn.javaField}s));
|
||||
}
|
||||
|
||||
#if($excelFlag)
|
||||
#if($docFlag)
|
||||
@Operation(summary = "导出${functionName}")
|
||||
#else
|
||||
/**
|
||||
* 导出${functionName}
|
||||
*/
|
||||
#end
|
||||
@PreAuthorize("hasAuthority('${permissionPrefix}:export')")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, ${ClassName}Param param) {
|
||||
List<${ClassName}> list = ${className}Service.selectList(param);
|
||||
ExcelUtil.exportExcel(list, ${ClassName}Export.class, "${functionName}数据", response);
|
||||
}
|
||||
|
||||
#end
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package ${packageName}.entity;
|
||||
|
||||
#if($docFlag)
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
#end
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* ${functionName} Dto
|
||||
*
|
||||
* @author ${author}
|
||||
* @version 1.0
|
||||
* @since ${datetime}
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class ${ClassName}Dto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
## 遍历字段
|
||||
#foreach ($column in $columns)
|
||||
## 忽略基础(父类)字段
|
||||
#if(!$generator.isBaseColumn($column.javaField))
|
||||
## 是主键
|
||||
#if($generator.isPk($column.isPk))
|
||||
private String $column.javaField;
|
||||
|
||||
## 不是主键
|
||||
#else
|
||||
#if($docFlag)
|
||||
@Schema(description = "$column.columnComment")
|
||||
#else
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
#end
|
||||
private $column.javaType $column.javaField;
|
||||
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package ${packageName}.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.qiaoba.common.base.entity.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* ${functionName} ${tableName}
|
||||
*
|
||||
* @author ${author}
|
||||
* @version 1.0
|
||||
* @since ${datetime}
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("${tableName}")
|
||||
public class ${ClassName} extends BaseEntity{
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
## 遍历字段
|
||||
#foreach ($column in $columns)
|
||||
## 忽略基础(父类)字段
|
||||
#if(!$generator.isBaseColumn($column.javaField))
|
||||
## 是主键
|
||||
#if($generator.isPk($column.isPk))
|
||||
@TableId
|
||||
private String $column.javaField;
|
||||
|
||||
## 不是主键
|
||||
#else
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
private $column.javaType $column.javaField;
|
||||
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package ${packageName}.entity.template;
|
||||
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* ${functionName} 导出模板
|
||||
*
|
||||
* @author ${author}
|
||||
* @version 1.0
|
||||
* @since ${datetime}
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class ${ClassName}Export implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
#foreach ($column in $columns)
|
||||
#if($column.isList == "1")
|
||||
#if($column.javaType == "Date")
|
||||
@Excel(name = "$column.columnComment", width = 30, format = "yyyy-MM-dd HH:mm:ss")
|
||||
#else
|
||||
@Excel(name = "$column.columnComment", width = 20)
|
||||
#end
|
||||
private $column.javaType $column.javaField;
|
||||
|
||||
#end
|
||||
#end
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package ${packageName}.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import ${packageName}.entity.${ClassName};
|
||||
|
||||
/**
|
||||
* ${functionName}管理 数据层
|
||||
*
|
||||
* @author ${author}
|
||||
* @version 1.0
|
||||
* @since ${datetime}
|
||||
*/
|
||||
public interface ${ClassName}Mapper extends BaseMapper<${ClassName}> {
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package ${packageName}.entity;
|
||||
|
||||
#if($docFlag)
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
#end
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* ${functionName} 查询参数
|
||||
*
|
||||
* @author ${author}
|
||||
* @version 1.0
|
||||
* @since ${datetime}
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class ${ClassName}Param implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
## 遍历字段
|
||||
#foreach ($column in $queryColumns)
|
||||
#if($column.queryType == "BETWEEN")
|
||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||
|
||||
#if($docFlag)
|
||||
@Schema(description = "开始$column.columnComment")
|
||||
#else
|
||||
/**
|
||||
* 开始$column.columnComment
|
||||
*/
|
||||
#end
|
||||
#if($column.javaType == "Date")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
#end
|
||||
private $column.javaType start$AttrName;
|
||||
|
||||
#if($docFlag)
|
||||
@Schema(description = "结束$column.columnComment")
|
||||
#else
|
||||
/**
|
||||
* 结束$column.columnComment
|
||||
*/
|
||||
#end
|
||||
#if($column.javaType == "Date")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
#end
|
||||
private $column.javaType end$AttrName;
|
||||
|
||||
#else
|
||||
|
||||
#if($docFlag)
|
||||
@Schema(description = "$column.columnComment")
|
||||
#else
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
#end
|
||||
#if($column.javaType == "Date")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
#end
|
||||
private $column.javaType $column.javaField;
|
||||
#end
|
||||
#end
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package ${packageName}.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.qiaoba.common.database.entity.PageQuery;
|
||||
import com.qiaoba.common.database.entity.TableDataInfo;
|
||||
import ${packageName}.entity.${ClassName};
|
||||
import ${packageName}.entity.dto.${ClassName}Dto;
|
||||
import ${packageName}.entity.param.${ClassName}Param;
|
||||
|
||||
/**
|
||||
* ${functionName} 服务层
|
||||
*
|
||||
* @author ${author}
|
||||
* @version 1.0
|
||||
* @since ${datetime}
|
||||
*/
|
||||
public interface ${ClassName}Service {
|
||||
|
||||
/**
|
||||
* 查询${functionName}列表
|
||||
*
|
||||
* @param param 查询条件
|
||||
* @return ${functionName}集合
|
||||
*/
|
||||
List<${ClassName}> selectList(${ClassName}Param param);
|
||||
|
||||
/**
|
||||
* 分页查询${functionName}列表
|
||||
*
|
||||
* @param param 查询条件
|
||||
* @param pageQuery 分页信息
|
||||
* @return ${functionName}集合
|
||||
*/
|
||||
TableDataInfo<${ClassName}> selectPageList(${ClassName}Param param, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询${functionName}
|
||||
*
|
||||
* @param ${pkColumn.javaField} ${pkColumn.javaField}
|
||||
* @param allowNull 允许空
|
||||
* @return ${functionName}
|
||||
*/
|
||||
${ClassName} selectById(String ${pkColumn.javaField}, boolean allowNull);
|
||||
|
||||
/**
|
||||
* 新增${functionName}
|
||||
*
|
||||
* @param dto dto
|
||||
* @return 结果
|
||||
*/
|
||||
int insert(${ClassName}Dto dto);
|
||||
|
||||
/**
|
||||
* 修改${functionName}
|
||||
*
|
||||
* @param dto dto
|
||||
* @return 结果
|
||||
*/
|
||||
int updateById(${ClassName}Dto dto);
|
||||
|
||||
/**
|
||||
* 删除${functionName}信息
|
||||
*
|
||||
* @param ${pkColumn.javaField} ${pkColumn.javaField}
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteById(String ${pkColumn.javaField});
|
||||
|
||||
/**
|
||||
* 批量删除${functionName}
|
||||
*
|
||||
* @param ${pkColumn.javaField}s ${pkColumn.javaField}s
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteByIds(List<String> ${pkColumn.javaField}s);
|
||||
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
package ${packageName}.service.impl;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.qiaoba.api.auth.utils.SecurityUtil;
|
||||
import com.qiaoba.common.base.exception.ServiceException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.qiaoba.common.database.entity.PageQuery;
|
||||
import com.qiaoba.common.database.entity.TableDataInfo;
|
||||
|
||||
import ${packageName}.entity.${ClassName};
|
||||
import ${packageName}.entity.dto.${ClassName}Dto;
|
||||
import ${packageName}.entity.param.${ClassName}Param;
|
||||
import ${packageName}.service.${ClassName}Service;
|
||||
import ${packageName}.mapper.${ClassName}Mapper;
|
||||
|
||||
/**
|
||||
* ${functionName} 服务层实现
|
||||
*
|
||||
* @author ${author}
|
||||
* @version 1.0
|
||||
* @since ${datetime}
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ${ClassName}ServiceImpl implements ${ClassName}Service {
|
||||
|
||||
private final ${ClassName}Mapper ${className}Mapper;
|
||||
|
||||
@Override
|
||||
public List<${ClassName}> selectList(${ClassName}Param param) {
|
||||
return ${className}Mapper.selectList(param2Wrapper(param));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo<${ClassName}> selectPageList(${ClassName}Param param, PageQuery pageQuery) {
|
||||
return TableDataInfo.build(${className}Mapper.selectPage(pageQuery.build(), param2Wrapper(param)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ${ClassName} selectById(String ${pkColumn.javaField}, boolean allowNull) {
|
||||
${ClassName} ${className} =${className}Mapper.selectById(${pkColumn.javaField});
|
||||
|
||||
if (!allowNull && Objects.isNull(${className})) {
|
||||
throw new ServiceException("未查询到有关信息");
|
||||
}
|
||||
|
||||
return ${className};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(${ClassName}Dto dto) {
|
||||
|
||||
${ClassName} ${className} =dto2Entity(dto);
|
||||
${className}.setCreateTime(new Date());
|
||||
${className}.setCreateUser(SecurityUtil.getLoginUsername());
|
||||
|
||||
return ${className}Mapper.insert(${className});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateById(${ClassName}Dto dto) {
|
||||
|
||||
${ClassName} ${className} =dto2Entity(dto);
|
||||
${className}.setUpdateTime(new Date());
|
||||
${className}.setUpdateUser(SecurityUtil.getLoginUsername());
|
||||
|
||||
return ${className}Mapper.updateById(${className});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteById(String ${pkColumn.javaField}) {
|
||||
return ${className}Mapper.deleteById(${pkColumn.javaField});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteByIds(List<String> ${pkColumn.javaField}s) {
|
||||
return ${className}Mapper.deleteBatchIds(${pkColumn.javaField}s);
|
||||
}
|
||||
|
||||
private ${ClassName} dto2Entity(${ClassName}Dto dto) {
|
||||
${ClassName} ${className} = new ${ClassName}();
|
||||
#foreach ($column in $columns)
|
||||
#if(!$generator.isBaseColumn($column.javaField))
|
||||
## 首字母大写
|
||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||
${className}.set$AttrName(dto.get$AttrName());
|
||||
#end
|
||||
#end
|
||||
return ${className};
|
||||
}
|
||||
|
||||
private QueryWrapper<${ClassName}> param2Wrapper(${ClassName}Param param) {
|
||||
QueryWrapper<${ClassName}> wrapper = new QueryWrapper<>();
|
||||
#if($queryColumns.size() > 0)
|
||||
wrapper.lambda()
|
||||
#foreach ($column in $queryColumns)
|
||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||
#if($column.queryType == "EQ")
|
||||
.eq(ObjectUtil.isNotEmpty(param.get${AttrName}()), ${ClassName}::get${AttrName}, param.get${AttrName}())#if($foreach.count == $queryColumns.size());#end
|
||||
#elseif($column.queryType == "NE")
|
||||
.ne(ObjectUtil.isNotEmpty(param.get${AttrName}()), ${ClassName}::get${AttrName}, param.get${AttrName}())#if($foreach.count == $queryColumns.size());#end
|
||||
#elseif($column.queryType == "GT")
|
||||
.gt(ObjectUtil.isNotEmpty(param.get${AttrName}()), ${ClassName}::get${AttrName}, param.get${AttrName}())#if($foreach.count == $queryColumns.size());#end
|
||||
#elseif($column.queryType == "GTE")
|
||||
.ge(ObjectUtil.isNotEmpty(param.get${AttrName}()), ${ClassName}::get${AttrName}, param.get${AttrName}())#if($foreach.count == $queryColumns.size());#end
|
||||
#elseif($column.queryType == "LT")
|
||||
.lt(ObjectUtil.isNotEmpty(param.get${AttrName}()), ${ClassName}::get${AttrName}, param.get${AttrName}())#if($foreach.count == $queryColumns.size());#end
|
||||
#elseif($column.queryType == "LTE")
|
||||
.le(ObjectUtil.isNotEmpty(param.get${AttrName}()), ${ClassName}::get${AttrName}, param.get${AttrName}())#if($foreach.count == $queryColumns.size());#end
|
||||
#elseif($column.queryType == "LIKE")
|
||||
.like(ObjectUtil.isNotEmpty(param.get${AttrName}()), ${ClassName}::get${AttrName}, param.get${AttrName}())#if($foreach.count == $queryColumns.size());#end
|
||||
#elseif($column.queryType == "BETWEEN")
|
||||
.between((ObjectUtil.isNotEmpty(param.getStart${AttrName}()) && ObjectUtil.isNotEmpty(param.getEnd${AttrName}())),
|
||||
${ClassName}::get${AttrName}, param.getStart${AttrName}(), param.getEnd${AttrName}())#if($foreach.count == $queryColumns.size());#end
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
return wrapper;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
// 查询${functionName}列表
|
||||
export function list${BusinessName}(query) {
|
||||
return request({
|
||||
url: '/${moduleName}/${businessName}/list',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
// 查询${functionName}详细
|
||||
export function get${BusinessName}(${pkColumn.javaField}) {
|
||||
return request({
|
||||
url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 新增${functionName}
|
||||
export function add${BusinessName}(data) {
|
||||
return request({
|
||||
url: '/${moduleName}/${businessName}',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 修改${functionName}
|
||||
export function update${BusinessName}(data) {
|
||||
return request({
|
||||
url: '/${moduleName}/${businessName}',
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除${functionName}
|
||||
export function del${BusinessName}(${pkColumn.javaField}) {
|
||||
return request({
|
||||
url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
|
||||
method: 'delete'
|
||||
})
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
-- 菜单 SQL
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, is_visible, perms, icon, create_user, create_time, update_user, update_time, remark, tenant_id)
|
||||
values('${parentId}', '${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 0, 0, 'C', '1', '${permissionPrefix}:list', '#', 'admin', '${datetime}', '', null, '${functionName}菜单', '${tenantId}');
|
||||
|
||||
-- 按钮 SQL
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, is_visible, perms, icon, create_user, create_time, update_user, update_time, remark, tenant_id)
|
||||
values('${selectMenuId}', '${functionName}查询', '${parentId}', '1', '#', '', 0, 0, 'F', '1', '${permissionPrefix}:query', '#', 'admin', '${datetime}', '', null, '', '${tenantId}');
|
||||
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, is_visible, perms, icon, create_user, create_time, update_user, update_time, remark, tenant_id)
|
||||
values('${insertMenuId}', '${functionName}新增', '${parentId}', '2', '#', '', 0, 0, 'F', '1', '${permissionPrefix}:add', '#', 'admin', '${datetime}', '', null, '', '${tenantId}');
|
||||
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, is_visible, perms, icon, create_user, create_time, update_user, update_time, remark, tenant_id)
|
||||
values('${updateMenuId}', '${functionName}修改', '${parentId}', '3', '#', '', 0, 0, 'F', '1', '${permissionPrefix}:edit', '#', 'admin', '${datetime}', '', null, '', '${tenantId}');
|
||||
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, is_visible, perms, icon, create_user, create_time, update_user, update_time, remark, tenant_id)
|
||||
values('${deleteMenuId}', '${functionName}删除', '${parentId}', '4', '#', '', 0, 0, 'F', '1', '${permissionPrefix}:remove', '#', 'admin', '${datetime}', '', null, '', '${tenantId}');
|
||||
|
||||
#if($excelFlag)
|
||||
insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, is_visible, perms, icon, create_user, create_time, update_user, update_time, remark, tenant_id)
|
||||
values('${exportMenuId}', '${functionName}导出', '${parentId}', '5', '#', '', 0, 0, 'F', '1', '${permissionPrefix}:export', '#', 'admin', '${datetime}', '', null, '', '${tenantId}');
|
||||
#end
|
@ -0,0 +1,480 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
|
||||
#foreach($column in $columns)
|
||||
#if($column.isQuery)
|
||||
#set($dictType=$column.dictType)
|
||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||
#if($parentheseIndex != -1)
|
||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||
#else
|
||||
#set($comment=$column.columnComment)
|
||||
#end
|
||||
#if($column.htmlType == "input")
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-input
|
||||
v-model="queryParams.${column.javaField}"
|
||||
placeholder="请输入${comment}"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType)
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable>
|
||||
<el-option
|
||||
v-for="dict in ${dictType}"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType)
|
||||
<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.htmlType == "datetime" && $column.queryType != "BETWEEN")
|
||||
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||
<el-date-picker clearable
|
||||
v-model="queryParams.${column.javaField}"
|
||||
type="date"
|
||||
value-format="YYYY-MM-DD"
|
||||
placeholder="请选择${comment}">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||
<el-form-item label="${comment}" style="width: 308px">
|
||||
<el-date-picker
|
||||
v-model="daterange${AttrName}"
|
||||
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" icon="Search" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
icon="Plus"
|
||||
@click="handleAdd"
|
||||
v-hasPermi="['${moduleName}:${businessName}:add']"
|
||||
>新增</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="success"
|
||||
plain
|
||||
icon="Edit"
|
||||
:disabled="single"
|
||||
@click="handleUpdate"
|
||||
v-hasPermi="['${moduleName}:${businessName}:edit']"
|
||||
>修改</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="danger"
|
||||
plain
|
||||
icon="Delete"
|
||||
:disabled="multiple"
|
||||
@click="handleDelete"
|
||||
v-hasPermi="['${moduleName}:${businessName}:remove']"
|
||||
>删除</el-button>
|
||||
</el-col>
|
||||
#if($excelFlag)
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="warning"
|
||||
plain
|
||||
icon="Download"
|
||||
@click="handleExport"
|
||||
v-hasPermi="['${moduleName}:${businessName}:export']"
|
||||
>导出</el-button>
|
||||
</el-col>
|
||||
#end
|
||||
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
|
||||
<el-table v-loading="loading" :data="${businessName}List" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
#foreach($column in $columns)
|
||||
#set($javaField=$column.javaField)
|
||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||
#if($parentheseIndex != -1)
|
||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||
#else
|
||||
#set($comment=$column.columnComment)
|
||||
#end
|
||||
#if($column.isPk == "1")
|
||||
<el-table-column label="${comment}" align="center" prop="${javaField}" />
|
||||
#elseif($column.isList == "1" && $column.htmlType == "datetime")
|
||||
<el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
|
||||
<template #default="scope">
|
||||
<span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
#elseif($column.isList == "1" && $column.htmlType == "imageUpload")
|
||||
<el-table-column label="${comment}" align="center" prop="${javaField}" width="100">
|
||||
<template #default="scope">
|
||||
<image-preview :src="scope.row.${javaField}" :width="50" :height="50"/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
#elseif($column.isList == "1" && "" != $column.dictType)
|
||||
<el-table-column label="${comment}" align="center" prop="${javaField}">
|
||||
<template #default="scope">
|
||||
#if($column.htmlType == "checkbox")
|
||||
<dict-tag :options="${column.dictType}" :value="scope.row.${javaField} ? scope.row.${javaField}.split(',') : []"/>
|
||||
#else
|
||||
<dict-tag :options="${column.dictType}" :value="scope.row.${javaField}"/>
|
||||
#end
|
||||
</template>
|
||||
</el-table-column>
|
||||
#elseif($column.isList == "1" && "" != $javaField)
|
||||
<el-table-column label="${comment}" align="center" prop="${javaField}" />
|
||||
#end
|
||||
#end
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template #default="scope">
|
||||
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['${moduleName}:${businessName}:edit']">修改</el-button>
|
||||
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['${moduleName}:${businessName}:remove']">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination
|
||||
v-show="total>0"
|
||||
:total="total"
|
||||
v-model:page="queryParams.pageNum"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
|
||||
<!-- 添加或修改${functionName}对话框 -->
|
||||
<el-dialog :title="title" v-model="open" width="500px" append-to-body>
|
||||
<el-form ref="${businessName}Ref" :model="form" :rules="rules" label-width="80px">
|
||||
#foreach($column in $columns)
|
||||
#set($field=$column.javaField)
|
||||
#if($column.isInsert == "1" && "1" != $column.isPk)
|
||||
#if(($column.usableColumn) || (!$column.superColumn))
|
||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||
#if($parentheseIndex != -1)
|
||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||
#else
|
||||
#set($comment=$column.columnComment)
|
||||
#end
|
||||
#set($dictType=$column.dictType)
|
||||
#if($column.htmlType == "input")
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<el-input v-model="form.${field}" placeholder="请输入${comment}" />
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "imageUpload")
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<image-upload v-model="form.${field}"/>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "fileUpload")
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<file-upload v-model="form.${field}"/>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "editor")
|
||||
<el-form-item label="${comment}">
|
||||
<editor v-model="form.${field}" :min-height="192"/>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "select" && "" != $dictType)
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<el-select v-model="form.${field}" placeholder="请选择${comment}">
|
||||
<el-option
|
||||
v-for="dict in ${dictType}"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
#if($column.javaType == "Integer" || $column.javaType == "Long")
|
||||
:value="parseInt(dict.value)"
|
||||
#else
|
||||
:value="dict.value"
|
||||
#end
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "select" && $dictType)
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<el-select v-model="form.${field}" placeholder="请选择${comment}">
|
||||
<el-option label="请选择字典生成" value="" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "checkbox" && "" != $dictType)
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<el-checkbox-group v-model="form.${field}">
|
||||
<el-checkbox
|
||||
v-for="dict in ${dictType}"
|
||||
:key="dict.value"
|
||||
:label="dict.value">
|
||||
{{dict.label}}
|
||||
</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "checkbox" && $dictType)
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<el-checkbox-group v-model="form.${field}">
|
||||
<el-checkbox>请选择字典生成</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "radio" && "" != $dictType)
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<el-radio-group v-model="form.${field}">
|
||||
<el-radio
|
||||
v-for="dict in ${dictType}"
|
||||
:key="dict.value"
|
||||
#if($column.javaType == "Integer" || $column.javaType == "Long")
|
||||
:label="parseInt(dict.value)"
|
||||
#else
|
||||
:label="dict.value"
|
||||
#end
|
||||
>{{dict.label}}</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "radio" && $dictType)
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<el-radio-group v-model="form.${field}">
|
||||
<el-radio label="1">请选择字典生成</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "datetime")
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<el-date-picker clearable
|
||||
v-model="form.${field}"
|
||||
type="date"
|
||||
value-format="YYYY-MM-DD"
|
||||
placeholder="请选择${comment}">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
#elseif($column.htmlType == "textarea")
|
||||
<el-form-item label="${comment}" prop="${field}">
|
||||
<el-input v-model="form.${field}" type="textarea" placeholder="请输入内容" />
|
||||
</el-form-item>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="${BusinessName}">
|
||||
import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName} } from "@/api/${moduleName}/${businessName}";
|
||||
|
||||
const { proxy } = getCurrentInstance();
|
||||
#if(${dicts} != '')
|
||||
#set($dictsNoSymbol=$dicts.replace("'", ""))
|
||||
const { ${dictsNoSymbol} } = proxy.useDict(${dicts});
|
||||
#end
|
||||
|
||||
const ${businessName}List = ref([]);
|
||||
const open = ref(false);
|
||||
const loading = ref(true);
|
||||
const showSearch = ref(true);
|
||||
const ids = ref([]);
|
||||
const single = ref(true);
|
||||
const multiple = ref(true);
|
||||
const total = ref(0);
|
||||
const title = ref("");
|
||||
#foreach ($column in $columns)
|
||||
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||
const daterange${AttrName} = ref([]);
|
||||
#end
|
||||
#end
|
||||
|
||||
const data = reactive({
|
||||
form: {},
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
#foreach ($column in $columns)
|
||||
#if($column.isQuery)
|
||||
$column.javaField: null#if($foreach.count != $columns.size()),#end
|
||||
#end
|
||||
#end
|
||||
},
|
||||
rules: {
|
||||
#foreach ($column in $columns)
|
||||
#if($column.isRequired)
|
||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||
#if($parentheseIndex != -1)
|
||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||
#else
|
||||
#set($comment=$column.columnComment)
|
||||
#end
|
||||
$column.javaField: [
|
||||
{ required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio")"change"#else"blur"#end }
|
||||
]#if($foreach.count != $columns.size()),#end
|
||||
#end
|
||||
#end
|
||||
}
|
||||
});
|
||||
|
||||
const { queryParams, form, rules } = toRefs(data);
|
||||
|
||||
/** 查询${functionName}列表 */
|
||||
function getList() {
|
||||
loading.value = true;
|
||||
#foreach ($column in $columns)
|
||||
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||
queryParams.value.params = {};
|
||||
#break
|
||||
#end
|
||||
#end
|
||||
#foreach ($column in $columns)
|
||||
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||
if (null != daterange${AttrName} && '' != daterange${AttrName}) {
|
||||
queryParams.start${AttrName} = daterange${AttrName}.value[0];
|
||||
queryParams.end${AttrName} = daterange${AttrName}.value[1];
|
||||
}
|
||||
#end
|
||||
#end
|
||||
list${BusinessName}(queryParams.value).then(response => {
|
||||
${businessName}List.value = response.rows;
|
||||
total.value = response.total;
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
// 取消按钮
|
||||
function cancel() {
|
||||
open.value = false;
|
||||
reset();
|
||||
}
|
||||
|
||||
// 表单重置
|
||||
function reset() {
|
||||
form.value = {
|
||||
#foreach ($column in $columns)
|
||||
#if(!$generator.isBaseColumn($column.javaField))
|
||||
#if($column.htmlType == "checkbox")
|
||||
$column.javaField: []#if($foreach.count != $columns.size()),#end
|
||||
#else
|
||||
$column.javaField: null#if($foreach.count != $columns.size()),#end
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
};
|
||||
proxy.resetForm("${businessName}Ref");
|
||||
}
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
function handleQuery() {
|
||||
queryParams.value.pageNum = 1;
|
||||
getList();
|
||||
}
|
||||
|
||||
/** 重置按钮操作 */
|
||||
function resetQuery() {
|
||||
#foreach ($column in $columns)
|
||||
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.string(1)})
|
||||
daterange${AttrName}.value = [];
|
||||
#end
|
||||
#end
|
||||
proxy.resetForm("queryRef");
|
||||
handleQuery();
|
||||
}
|
||||
|
||||
// 多选框选中数据
|
||||
function handleSelectionChange(selection) {
|
||||
ids.value = selection.map(item => item.${pkColumn.javaField});
|
||||
single.value = selection.length != 1;
|
||||
multiple.value = !selection.length;
|
||||
}
|
||||
|
||||
/** 新增按钮操作 */
|
||||
function handleAdd() {
|
||||
reset();
|
||||
open.value = true;
|
||||
title.value = "添加${functionName}";
|
||||
}
|
||||
|
||||
/** 修改按钮操作 */
|
||||
function handleUpdate(row) {
|
||||
reset();
|
||||
const _${pkColumn.javaField} = row.${pkColumn.javaField} || ids.value
|
||||
get${BusinessName}(_${pkColumn.javaField}).then(response => {
|
||||
form.value = response.data;
|
||||
#foreach ($column in $columns)
|
||||
#if($column.htmlType == "checkbox")
|
||||
form.value.$column.javaField = form.value.${column.javaField}.split(",");
|
||||
#end
|
||||
#end
|
||||
open.value = true;
|
||||
title.value = "修改${functionName}";
|
||||
});
|
||||
}
|
||||
|
||||
/** 提交按钮 */
|
||||
function submitForm() {
|
||||
proxy.#[[$]]#refs["${businessName}Ref"].validate(valid => {
|
||||
if (valid) {
|
||||
#foreach ($column in $columns)
|
||||
#if($column.htmlType == "checkbox")
|
||||
form.value.$column.javaField = form.value.${column.javaField}.join(",");
|
||||
#end
|
||||
#end
|
||||
if (form.value.${pkColumn.javaField} != null) {
|
||||
update${BusinessName}(form.value).then(response => {
|
||||
proxy.#[[$modal]]#.msgSuccess("修改成功");
|
||||
open.value = false;
|
||||
getList();
|
||||
});
|
||||
} else {
|
||||
add${BusinessName}(form.value).then(response => {
|
||||
proxy.#[[$modal]]#.msgSuccess("新增成功");
|
||||
open.value = false;
|
||||
getList();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** 删除按钮操作 */
|
||||
function handleDelete(row) {
|
||||
const _${pkColumn.javaField}s = row.${pkColumn.javaField} || ids.value;
|
||||
proxy.#[[$modal]]#.confirm('是否确认删除${functionName}编号为"' + _${pkColumn.javaField}s + '"的数据项?').then(function() {
|
||||
return del${BusinessName}(_${pkColumn.javaField}s);
|
||||
}).then(() => {
|
||||
getList();
|
||||
proxy.#[[$modal]]#.msgSuccess("删除成功");
|
||||
}).catch(() => {});
|
||||
}
|
||||
|
||||
#if($excelFlag)
|
||||
/** 导出按钮操作 */
|
||||
function handleExport() {
|
||||
proxy.download('${moduleName}/${businessName}/export', {
|
||||
...queryParams.value
|
||||
}, `${businessName}_#[[${new Date().getTime()}]]#.xlsx`)
|
||||
}
|
||||
#end
|
||||
|
||||
getList();
|
||||
</script>
|
Reference in New Issue
Block a user