mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-03-13 20:53:42 +08:00
修改字典功能 和模板生成id 太长19位 改为1,2,3
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.ruoyi.generator.controller;
|
||||
|
||||
import cn.hutool.core.net.URLDecoder;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.ruoyi.common.core.domain.R;
|
||||
@@ -8,10 +9,11 @@ import org.ruoyi.generator.service.IGenTableService;
|
||||
import org.ruoyi.generator.service.SchemaFieldService;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* 代码生成 操作处理
|
||||
*
|
||||
@@ -46,4 +48,18 @@ public class GenController extends BaseController {
|
||||
genTableService.generateCodeToClasspathByTableNames(tableNameStr);
|
||||
return R.ok("代码生成成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成前端代码
|
||||
*
|
||||
* @param workPath 执行命令路径
|
||||
* @param previewCode 执行生成前端文件命令
|
||||
*/
|
||||
@GetMapping("/batchGenFrontendCode")
|
||||
public R<String> batchGenFrontendCode(@NotNull(message = "路径不能为空") String workPath, @NotNull(message = "指令不能为空") String previewCode) {
|
||||
String decodedWorkPath = URLDecoder.decode(workPath, StandardCharsets.UTF_8);
|
||||
String decodedPreviewCode = URLDecoder.decode(previewCode, StandardCharsets.UTF_8);
|
||||
genTableService.generateFrontendTemplateFiles(decodedWorkPath, decodedPreviewCode);
|
||||
return R.ok("代码生成成功");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ public class SchemaGroupController extends BaseController {
|
||||
/**
|
||||
* 获取数据模型分组选择列表
|
||||
*/
|
||||
@SaCheckPermission("dev:schemaGroup:select")
|
||||
@GetMapping("/select")
|
||||
public R<List<SchemaGroupVo>> select() {
|
||||
SchemaGroupBo bo = new SchemaGroupBo();
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package org.ruoyi.generator.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.ruoyi.core.domain.BaseEntity;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 数据模型对象 dev_schema
|
||||
@@ -16,12 +17,9 @@ import java.io.Serial;
|
||||
* @date 2024-01-01
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("dev_schema")
|
||||
public class Schema extends BaseEntity {
|
||||
public class Schema implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
@@ -49,41 +47,6 @@ public class Schema extends BaseEntity {
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表注释
|
||||
*/
|
||||
private String comment;
|
||||
|
||||
/**
|
||||
* 存储引擎
|
||||
*/
|
||||
private String engine;
|
||||
|
||||
/**
|
||||
* 列表字段
|
||||
*/
|
||||
private String listKeys;
|
||||
|
||||
/**
|
||||
* 搜索表单字段
|
||||
*/
|
||||
private String searchFormKeys;
|
||||
|
||||
/**
|
||||
* 表单设计
|
||||
*/
|
||||
private String designer;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@@ -96,8 +59,33 @@ public class Schema extends BaseEntity {
|
||||
private String delFlag;
|
||||
|
||||
/**
|
||||
* 租户编号
|
||||
* 创建部门
|
||||
*/
|
||||
private String tenantId;
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Long createDept;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Long updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
package org.ruoyi.generator.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.ruoyi.core.domain.BaseEntity;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 数据模型字段对象 dev_schema_field
|
||||
@@ -16,12 +17,8 @@ import java.io.Serial;
|
||||
* @date 2024-01-01
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("dev_schema_field")
|
||||
public class SchemaField extends BaseEntity {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
public class SchemaField implements Serializable {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
@@ -129,15 +126,6 @@ public class SchemaField extends BaseEntity {
|
||||
*/
|
||||
private String dictType;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 扩展JSON
|
||||
*/
|
||||
private String extendJson;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
@@ -151,8 +139,33 @@ public class SchemaField extends BaseEntity {
|
||||
private String delFlag;
|
||||
|
||||
/**
|
||||
* 租户编号
|
||||
* 创建部门
|
||||
*/
|
||||
private String tenantId;
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Long createDept;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Long updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
package org.ruoyi.generator.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.ruoyi.core.domain.BaseEntity;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 数据模型分组对象 dev_schema_group
|
||||
@@ -16,12 +17,8 @@ import java.io.Serial;
|
||||
* @date 2024-01-01
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("dev_schema_group")
|
||||
public class SchemaGroup extends BaseEntity {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
public class SchemaGroup implements Serializable {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
@@ -44,16 +41,6 @@ public class SchemaGroup extends BaseEntity {
|
||||
*/
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@@ -66,8 +53,32 @@ public class SchemaGroup extends BaseEntity {
|
||||
private String delFlag;
|
||||
|
||||
/**
|
||||
* 租户编号
|
||||
* 创建部门
|
||||
*/
|
||||
private String tenantId;
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Long createDept;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Long updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
}
|
||||
@@ -4,12 +4,12 @@ import io.github.linpeilie.annotations.AutoMapper;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.ruoyi.common.core.validate.AddGroup;
|
||||
import org.ruoyi.common.core.validate.EditGroup;
|
||||
import org.ruoyi.core.domain.BaseEntity;
|
||||
import org.ruoyi.generator.domain.Schema;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 数据模型业务对象 SchemaBo
|
||||
*
|
||||
@@ -17,9 +17,8 @@ import org.ruoyi.generator.domain.Schema;
|
||||
* @date 2024-01-01
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AutoMapper(target = Schema.class, reverseConvertGenerate = false)
|
||||
public class SchemaBo extends BaseEntity {
|
||||
public class SchemaBo implements Serializable {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
@@ -38,52 +37,12 @@ public class SchemaBo extends BaseEntity {
|
||||
@NotBlank(message = "模型名称不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 模型编码
|
||||
*/
|
||||
@NotBlank(message = "模型编码不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 表名
|
||||
*/
|
||||
@NotBlank(message = "表名不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表注释
|
||||
*/
|
||||
private String comment;
|
||||
|
||||
/**
|
||||
* 存储引擎
|
||||
*/
|
||||
private String engine;
|
||||
|
||||
/**
|
||||
* 列表字段
|
||||
*/
|
||||
private String listKeys;
|
||||
|
||||
/**
|
||||
* 搜索表单字段
|
||||
*/
|
||||
private String searchFormKeys;
|
||||
|
||||
/**
|
||||
* 表单设计
|
||||
*/
|
||||
private String designer;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
|
||||
@@ -4,12 +4,12 @@ import io.github.linpeilie.annotations.AutoMapper;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.ruoyi.common.core.validate.AddGroup;
|
||||
import org.ruoyi.common.core.validate.EditGroup;
|
||||
import org.ruoyi.core.domain.BaseEntity;
|
||||
import org.ruoyi.generator.domain.SchemaField;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 数据模型字段业务对象 SchemaFieldBo
|
||||
*
|
||||
@@ -17,9 +17,8 @@ import org.ruoyi.generator.domain.SchemaField;
|
||||
* @date 2024-01-01
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AutoMapper(target = SchemaField.class, reverseConvertGenerate = false)
|
||||
public class SchemaFieldBo extends BaseEntity {
|
||||
public class SchemaFieldBo implements Serializable {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
@@ -36,7 +35,7 @@ public class SchemaFieldBo extends BaseEntity {
|
||||
/**
|
||||
* 模型名称
|
||||
*/
|
||||
@NotNull(message = "模型名称不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
// @NotNull(message = "模型名称不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
private String schemaName;
|
||||
|
||||
/**
|
||||
@@ -131,16 +130,6 @@ public class SchemaFieldBo extends BaseEntity {
|
||||
*/
|
||||
private String dictType;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 扩展JSON
|
||||
*/
|
||||
private String extendJson;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
|
||||
@@ -4,12 +4,12 @@ import io.github.linpeilie.annotations.AutoMapper;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.ruoyi.common.core.validate.AddGroup;
|
||||
import org.ruoyi.common.core.validate.EditGroup;
|
||||
import org.ruoyi.core.domain.BaseEntity;
|
||||
import org.ruoyi.generator.domain.SchemaGroup;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 数据模型分组业务对象 SchemaGroupBo
|
||||
*
|
||||
@@ -17,9 +17,8 @@ import org.ruoyi.generator.domain.SchemaGroup;
|
||||
* @date 2024-01-01
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AutoMapper(target = SchemaGroup.class, reverseConvertGenerate = false)
|
||||
public class SchemaGroupBo extends BaseEntity {
|
||||
public class SchemaGroupBo implements Serializable {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
@@ -44,16 +43,6 @@ public class SchemaGroupBo extends BaseEntity {
|
||||
*/
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
|
||||
@@ -6,9 +6,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.ruoyi.generator.domain.SchemaField;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 数据模型字段视图对象 SchemaFieldVo
|
||||
@@ -20,9 +18,6 @@ import java.util.Date;
|
||||
@AutoMapper(target = SchemaField.class)
|
||||
public class SchemaFieldVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@@ -136,25 +131,8 @@ public class SchemaFieldVo implements Serializable {
|
||||
@Schema(description = "字典类型")
|
||||
private String dictType;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@Schema(description = "状态")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 扩展JSON
|
||||
*/
|
||||
private String extendJson;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
import org.ruoyi.generator.domain.SchemaGroup;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -18,9 +17,6 @@ import java.util.Date;
|
||||
@AutoMapper(target = SchemaGroup.class)
|
||||
public class SchemaGroupVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@@ -46,11 +42,6 @@ public class SchemaGroupVo implements Serializable {
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
|
||||
@@ -19,9 +19,6 @@ import java.util.Date;
|
||||
@AutoMapper(target = Schema.class)
|
||||
public class SchemaVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@@ -46,6 +43,11 @@ public class SchemaVo implements Serializable {
|
||||
* 表名
|
||||
*/
|
||||
private String tableName;
|
||||
/**
|
||||
* 字典
|
||||
*/
|
||||
private String dictType;
|
||||
|
||||
|
||||
/**
|
||||
* 表注释
|
||||
|
||||
@@ -11,26 +11,19 @@ import org.apache.velocity.app.Velocity;
|
||||
import org.ruoyi.common.core.constant.Constants;
|
||||
import org.ruoyi.generator.config.GenConfig;
|
||||
import org.ruoyi.generator.domain.vo.SchemaFieldVo;
|
||||
import org.ruoyi.generator.domain.vo.SchemaGroupVo;
|
||||
import org.ruoyi.generator.domain.vo.SchemaVo;
|
||||
import org.ruoyi.generator.service.IGenTableService;
|
||||
import org.ruoyi.generator.service.SchemaFieldService;
|
||||
import org.ruoyi.generator.service.SchemaGroupService;
|
||||
import org.ruoyi.generator.service.SchemaService;
|
||||
import org.ruoyi.generator.util.VelocityInitializer;
|
||||
import org.ruoyi.generator.util.VelocityUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 业务 服务层实现
|
||||
@@ -44,6 +37,7 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
|
||||
private final SchemaService schemaService;
|
||||
private final SchemaFieldService schemaFieldService;
|
||||
private final SchemaGroupService schemaGroupService;
|
||||
|
||||
/**
|
||||
* 基于表名称批量生成代码到classpath路径
|
||||
@@ -59,6 +53,41 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateFrontendTemplateFiles(String workPath, String previewCode) {
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
|
||||
ProcessBuilder builder;
|
||||
if (os.contains("win")) {
|
||||
// Windows下用 cmd /c 执行 previewCode
|
||||
builder = new ProcessBuilder("cmd.exe", "/c", previewCode);
|
||||
} else {
|
||||
// macOS/Linux 用 bash -c 执行 previewCode
|
||||
builder = new ProcessBuilder("bash", "-c", previewCode);
|
||||
}
|
||||
|
||||
// 设置工作目录
|
||||
builder.directory(new File(workPath));
|
||||
builder.redirectErrorStream(true);
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
builder.start().getInputStream(),
|
||||
StandardCharsets.UTF_8
|
||||
)
|
||||
)) {
|
||||
String line;
|
||||
log.info("执行结果:");
|
||||
while ((line = reader.readLine()) != null) {
|
||||
log.info(line);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("生成前端代码出错", e);
|
||||
throw new RuntimeException("生成前端代码失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据表名称生成代码到classpath
|
||||
*/
|
||||
@@ -69,6 +98,7 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
log.warn("Schema不存在,表名: {}", tableName);
|
||||
return;
|
||||
}
|
||||
|
||||
// 查询Schema字段信息
|
||||
List<SchemaFieldVo> fields = schemaFieldService.queryListByTableName(tableName);
|
||||
if (CollUtil.isEmpty(fields)) {
|
||||
@@ -128,17 +158,19 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
*/
|
||||
private VelocityContext prepareSchemaContext(SchemaVo schema, List<SchemaFieldVo> fields) {
|
||||
VelocityContext context = new VelocityContext();
|
||||
|
||||
|
||||
// 从配置文件读取基本配置
|
||||
String packageName = GenConfig.getPackageName();
|
||||
String author = GenConfig.getAuthor();
|
||||
String tablePrefix = GenConfig.getTablePrefix();
|
||||
boolean autoRemovePre = GenConfig.getAutoRemovePre();
|
||||
|
||||
|
||||
// 处理表名和类名
|
||||
Long schemaGroupId = schema.getSchemaGroupId();
|
||||
SchemaGroupVo schemaGroupVo = schemaGroupService.queryById(schemaGroupId);
|
||||
String tableName = schema.getTableName();
|
||||
String baseClassName = schema.getTableName();
|
||||
|
||||
|
||||
// 自动去除表前缀
|
||||
if (autoRemovePre && StrUtil.isNotBlank(tablePrefix)) {
|
||||
String[] prefixes = tablePrefix.split(",");
|
||||
@@ -149,12 +181,12 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String className = toCamelCase(baseClassName, true); // 首字母大写的类名,如:SysRole
|
||||
String classname = toCamelCase(baseClassName, false); // 首字母小写的类名,如:sysRole
|
||||
String businessName = toCamelCase(baseClassName, false);
|
||||
String moduleName = getModuleName(packageName);
|
||||
|
||||
String moduleName = schemaGroupVo.getCode();
|
||||
|
||||
// 基本信息
|
||||
context.put("tableName", tableName);
|
||||
context.put("tableComment", schema.getComment());
|
||||
@@ -168,18 +200,18 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
context.put("packageName", packageName);
|
||||
context.put("moduleName", moduleName);
|
||||
context.put("businessName", businessName);
|
||||
|
||||
|
||||
// 权限相关
|
||||
context.put("permissionPrefix", moduleName + ":" + businessName);
|
||||
context.put("parentMenuId", "2000"); // 默认父菜单ID,可配置
|
||||
|
||||
|
||||
// 生成菜单ID
|
||||
List<Long> menuIds = new ArrayList<>();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
menuIds.add(IdUtil.getSnowflakeNextId());
|
||||
}
|
||||
context.put("menuIds", menuIds);
|
||||
|
||||
|
||||
// 创建table对象,包含menuIds等信息和方法
|
||||
Map<String, Object> table = new HashMap<>();
|
||||
table.put("menuIds", menuIds);
|
||||
@@ -188,29 +220,19 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
table.put("className", className);
|
||||
table.put("classname", classname);
|
||||
table.put("functionName", schema.getName());
|
||||
|
||||
|
||||
// 添加表类型属性(默认为crud类型)
|
||||
table.put("crud", true);
|
||||
table.put("sub", false);
|
||||
table.put("tree", false);
|
||||
|
||||
// 添加isSuperColumn方法
|
||||
table.put("isSuperColumn", new Object() {
|
||||
public boolean isSuperColumn(String javaField) {
|
||||
// 定义超类字段(BaseEntity中的字段)
|
||||
return "createBy".equals(javaField) || "createTime".equals(javaField)
|
||||
|| "updateBy".equals(javaField) || "updateTime".equals(javaField)
|
||||
|| "remark".equals(javaField) || "tenantId".equals(javaField);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
context.put("table", table);
|
||||
|
||||
|
||||
// 处理字段信息
|
||||
List<Map<String, Object>> columns = new ArrayList<>();
|
||||
Map<String, Object> pkColumn = null;
|
||||
Set<String> importList = new HashSet<>();
|
||||
|
||||
|
||||
// 添加基础导入
|
||||
importList.add("java.io.Serializable");
|
||||
|
||||
@@ -218,7 +240,7 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
Map<String, Object> column = new HashMap<>();
|
||||
String javaType = getJavaType(field.getType());
|
||||
String javaField = StrUtil.toCamelCase(field.getCode());
|
||||
|
||||
|
||||
column.put("columnName", field.getCode());
|
||||
column.put("columnComment", field.getName());
|
||||
column.put("comment", field.getName()); // 添加comment别名
|
||||
@@ -226,15 +248,15 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
column.put("javaType", javaType);
|
||||
column.put("javaField", javaField);
|
||||
column.put("capJavaField", toCamelCase(field.getCode(), true));
|
||||
|
||||
// 布尔值属性(兼容两种格式)
|
||||
|
||||
// 布尔值dictType属性(兼容两种格式)
|
||||
boolean isPk = "1".equals(field.getIsPk());
|
||||
boolean isRequired = "1".equals(field.getIsRequired());
|
||||
boolean isInsert = "1".equals(field.getIsInsert());
|
||||
boolean isEdit = "1".equals(field.getIsEdit());
|
||||
boolean isList = "1".equals(field.getIsList());
|
||||
boolean isQuery = "1".equals(field.getIsQuery());
|
||||
|
||||
|
||||
column.put("isPk", isPk ? 1 : 0);
|
||||
column.put("pk", isPk); // 添加pk别名
|
||||
column.put("isRequired", isRequired);
|
||||
@@ -247,27 +269,27 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
column.put("list", isList); // 添加list别名
|
||||
column.put("isQuery", isQuery);
|
||||
column.put("query", isQuery); // 添加query别名
|
||||
|
||||
|
||||
column.put("queryType", field.getQueryType());
|
||||
column.put("htmlType", field.getHtmlType());
|
||||
column.put("dictType", field.getDictType());
|
||||
column.put("sort", field.getSort());
|
||||
|
||||
|
||||
// 添加readConverterExp方法
|
||||
column.put("readConverterExp", new Object() {
|
||||
});
|
||||
|
||||
|
||||
// 根据Java类型添加相应的导入
|
||||
addImportForJavaType(javaType, importList);
|
||||
|
||||
|
||||
columns.add(column);
|
||||
|
||||
|
||||
// 设置主键列
|
||||
if (isPk) {
|
||||
pkColumn = column;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 如果没有主键,使用第一个字段作为主键
|
||||
if (pkColumn == null && !columns.isEmpty()) {
|
||||
pkColumn = columns.get(0);
|
||||
@@ -275,27 +297,28 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
pkColumn.put("isPk", 1);
|
||||
pkColumn.put("pk", true);
|
||||
}
|
||||
|
||||
|
||||
context.put("columns", columns);
|
||||
context.put("pkColumn", pkColumn);
|
||||
context.put("importList", new ArrayList<>(importList));
|
||||
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据Java类型添加相应的导入
|
||||
*/
|
||||
private void addImportForJavaType(String javaType, Set<String> importList) {
|
||||
switch (javaType) {
|
||||
case "BigDecimal" -> importList.add("java.math.BigDecimal");
|
||||
case "Date" -> importList.add("java.util.Date");
|
||||
case "LocalDateTime" -> importList.add("java.time.LocalDateTime");
|
||||
case "LocalDate" -> importList.add("java.time.LocalDate");
|
||||
case "LocalTime" -> importList.add("java.time.LocalTime");
|
||||
default -> {}
|
||||
}
|
||||
}
|
||||
* 根据Java类型添加相应的导入
|
||||
*/
|
||||
private void addImportForJavaType(String javaType, Set<String> importList) {
|
||||
switch (javaType) {
|
||||
case "BigDecimal" -> importList.add("java.math.BigDecimal");
|
||||
case "Date" -> importList.add("java.util.Date");
|
||||
case "LocalDateTime" -> importList.add("java.time.LocalDateTime");
|
||||
case "LocalDate" -> importList.add("java.time.LocalDate");
|
||||
case "LocalTime" -> importList.add("java.time.LocalTime");
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从包名中提取模块名
|
||||
@@ -319,10 +342,10 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
String packageName = GenConfig.getPackageName();
|
||||
String tablePrefix = GenConfig.getTablePrefix();
|
||||
boolean autoRemovePre = GenConfig.getAutoRemovePre();
|
||||
|
||||
|
||||
// 处理类名
|
||||
String baseClassName = schema.getTableName();
|
||||
|
||||
|
||||
// 自动去除表前缀
|
||||
if (autoRemovePre && StrUtil.isNotBlank(tablePrefix)) {
|
||||
String[] prefixes = tablePrefix.split(",");
|
||||
@@ -333,13 +356,13 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String className = toCamelCase(baseClassName, true); // 首字母大写,如:SysRole
|
||||
// 首字母小写,如:sysRole
|
||||
String moduleName = getModuleName(packageName);
|
||||
String javaPath = "src/main/java/";
|
||||
String mybatisPath = "src/main/resources/mapper/";
|
||||
|
||||
|
||||
if (template.contains("domain.java.vm")) {
|
||||
return javaPath + packageName.replace(".", "/") + "/domain/" + className + ".java";
|
||||
} else if (template.contains("mapper.java.vm")) {
|
||||
@@ -412,16 +435,17 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
return "String";
|
||||
}
|
||||
String type = dbType.toLowerCase();
|
||||
if (Objects.equals(type,"int") || type.contains("tinyint") || type.contains("smallint")) {
|
||||
if (StrUtil.equalsAny(type, "int", "tinyint")) {
|
||||
return "Integer";
|
||||
} else if (type.contains("bigint")) {
|
||||
} else if (StrUtil.equalsAny(type, "bigint")) {
|
||||
return "Long";
|
||||
} else if (type.contains("decimal") || type.contains("numeric") || type.contains("float") || type.contains(
|
||||
"double")) {
|
||||
} else if (StrUtil.equalsAny(type, "decimal", "numeric", "float", "double")) {
|
||||
return "BigDecimal";
|
||||
} else if (type.contains("date") || type.contains("time")) {
|
||||
return "Date";
|
||||
} else if (type.contains("bit") || type.contains("boolean")) {
|
||||
} else if (StrUtil.equalsAny(type, "date")) {
|
||||
return "LocalDate";
|
||||
} else if (StrUtil.equalsAny(type, "datetime", "timestamp")) {
|
||||
return "LocalDateTime";
|
||||
} else if (StrUtil.equalsAny(type, "bit", "boolean")) {
|
||||
return "Boolean";
|
||||
} else {
|
||||
return "String";
|
||||
|
||||
@@ -79,7 +79,6 @@ public class SchemaFieldServiceImpl implements SchemaFieldService {
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getQueryType()), SchemaField::getQueryType, bo.getQueryType());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getHtmlType()), SchemaField::getHtmlType, bo.getHtmlType());
|
||||
lqw.like(StringUtils.isNotBlank(bo.getDictType()), SchemaField::getDictType, bo.getDictType());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), SchemaField::getStatus, bo.getStatus());
|
||||
lqw.orderByAsc(SchemaField::getSort);
|
||||
return lqw;
|
||||
}
|
||||
@@ -150,7 +149,6 @@ public class SchemaFieldServiceImpl implements SchemaFieldService {
|
||||
public List<SchemaFieldVo> queryListBySchemaId(Long schemaId) {
|
||||
LambdaQueryWrapper<SchemaField> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(SchemaField::getSchemaId, schemaId);
|
||||
lqw.eq(SchemaField::getStatus, "0"); // 只查询正常状态的字段
|
||||
lqw.orderByAsc(SchemaField::getSort);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
@@ -209,9 +207,9 @@ public class SchemaFieldServiceImpl implements SchemaFieldService {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("schemaGroupCode", schemaGroupVo.getCode());
|
||||
result.put("tableName", schema.getTableName());
|
||||
result.put("dictType",schema.getDictType());
|
||||
result.put("tableComment", schema.getComment());
|
||||
result.put("className", toCamelCase(schema.getTableName(), true));
|
||||
// result.put("className", StrUtil.toCamelCase(schema.getTableName()));
|
||||
result.put("tableCamelName", StrUtil.toCamelCase(schema.getTableName()));
|
||||
result.put("functionName", schema.getName());
|
||||
result.put("schemaName", schema.getName());
|
||||
@@ -225,6 +223,8 @@ public class SchemaFieldServiceImpl implements SchemaFieldService {
|
||||
if (pkField != null) {
|
||||
Map<String, Object> pkColumn = new HashMap<>();
|
||||
pkColumn.put("columnName", pkField.getCode());
|
||||
pkColumn.put("dictType", pkField.getDictType());
|
||||
|
||||
pkColumn.put("columnComment", pkField.getName());
|
||||
pkColumn.put("javaField", StrUtil.toCamelCase(pkField.getCode()));
|
||||
pkColumn.put("javaType", getJavaType(pkField.getType()));
|
||||
@@ -236,6 +236,7 @@ public class SchemaFieldServiceImpl implements SchemaFieldService {
|
||||
for (SchemaFieldVo field : fields) {
|
||||
Map<String, Object> column = new HashMap<>();
|
||||
column.put("columnName", field.getCode());
|
||||
column.put("dictType", field.getDictType());
|
||||
column.put("columnComment", field.getName());
|
||||
column.put("javaField", StrUtil.toCamelCase(field.getCode()));
|
||||
column.put("javaType", getJavaType(field.getType()));
|
||||
@@ -265,8 +266,7 @@ public class SchemaFieldServiceImpl implements SchemaFieldService {
|
||||
return false;
|
||||
}
|
||||
LambdaQueryWrapper<SchemaField> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(SchemaField::getSchemaName, tableName);
|
||||
lqw.eq(SchemaField::getStatus, "0");
|
||||
lqw.eq(SchemaField::getSchemaId, schemaId);
|
||||
// 检查是否已存在字段数据
|
||||
List<SchemaFieldVo> existingFields = baseMapper.selectVoList(lqw);
|
||||
if (CollUtil.isNotEmpty(existingFields)) {
|
||||
@@ -280,20 +280,27 @@ public class SchemaFieldServiceImpl implements SchemaFieldService {
|
||||
SchemaField field = new SchemaField();
|
||||
field.setSchemaId(schemaId);
|
||||
field.setSchemaName(tableName);
|
||||
field.setDefaultValue((String) columnInfo.get("columnDefault"));
|
||||
field.setComment((String) columnInfo.get("columnComment"));
|
||||
field.setName((String) columnInfo.get("columnComment"));
|
||||
field.setDictType(StrUtil.toCamelCase((String) columnInfo.get("dictType")));
|
||||
field.setCode(StrUtil.toCamelCase((String) columnInfo.get("columnName")));
|
||||
field.setType((String) columnInfo.get("dataType"));
|
||||
field.setLength(Integer.valueOf(String.valueOf(columnInfo.get("columnSize"))));
|
||||
field.setIsPk((Boolean) columnInfo.get("isPrimaryKey") ? "1" : "0");
|
||||
field.setIsRequired(!(Boolean) columnInfo.get("isNullable") ? "1" : "0");
|
||||
field.setIsInsert("1");
|
||||
field.setIsEdit("1");
|
||||
if ("1".equals(field.getIsPk())) {
|
||||
field.setIsInsert("0");
|
||||
field.setIsEdit("0");
|
||||
}else {
|
||||
field.setIsInsert("1");
|
||||
field.setIsEdit("1");
|
||||
}
|
||||
field.setIsList("1");
|
||||
field.setIsQuery("1");
|
||||
field.setQueryType("EQ");
|
||||
field.setHtmlType(getDefaultHtmlType((String) columnInfo.get("dataType")));
|
||||
field.setSort(sort++);
|
||||
field.setStatus("0");
|
||||
// 如果字段名为空,使用字段代码作为名称
|
||||
if (StringUtils.isBlank(field.getName())) {
|
||||
field.setName(field.getCode());
|
||||
@@ -363,16 +370,15 @@ public class SchemaFieldServiceImpl implements SchemaFieldService {
|
||||
}
|
||||
|
||||
String type = dbType.toLowerCase();
|
||||
if (Objects.equals(type,"int")|| type.contains("tinyint") || type.contains("smallint")) {
|
||||
if (StrUtil.equalsAny(type, "int", "tinyint", "smallint")) {
|
||||
return "Integer";
|
||||
} else if (type.contains("bigint")) {
|
||||
} else if (StrUtil.equalsAny(type, "bigint")) {
|
||||
return "Long";
|
||||
} else if (type.contains("decimal") || type.contains("numeric") || type.contains("float") || type.contains(
|
||||
"double")) {
|
||||
} else if (StrUtil.equalsAny(type, "decimal", "numeric", "float", "double")) {
|
||||
return "BigDecimal";
|
||||
} else if (type.contains("date") || type.contains("time")) {
|
||||
} else if (StrUtil.equalsAny(type, "date", "datetime","timestamp")) {
|
||||
return "Date";
|
||||
} else if (type.contains("bit") || type.contains("boolean")) {
|
||||
} else if (StrUtil.equalsAny(type, "bit", "boolean")) {
|
||||
return "Boolean";
|
||||
} else {
|
||||
return "String";
|
||||
|
||||
@@ -60,9 +60,6 @@ public class SchemaGroupServiceImpl implements SchemaGroupService {
|
||||
LambdaQueryWrapper<SchemaGroup> lqw = Wrappers.lambdaQuery();
|
||||
lqw.like(StringUtils.isNotBlank(bo.getName()), SchemaGroup::getName, bo.getName());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getCode()), SchemaGroup::getCode, bo.getCode());
|
||||
lqw.eq(bo.getSort() != null, SchemaGroup::getSort, bo.getSort());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), SchemaGroup::getStatus, bo.getStatus());
|
||||
lqw.orderByAsc(SchemaGroup::getSort);
|
||||
return lqw;
|
||||
}
|
||||
|
||||
@@ -102,9 +99,6 @@ public class SchemaGroupServiceImpl implements SchemaGroupService {
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,10 @@ import org.ruoyi.common.core.utils.MapstructUtils;
|
||||
import org.ruoyi.common.core.utils.StringUtils;
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.generator.domain.SchemaGroup;
|
||||
import org.ruoyi.generator.domain.vo.SchemaGroupVo;
|
||||
import org.ruoyi.generator.event.SchemaDeletedEvent;
|
||||
import org.ruoyi.generator.service.SchemaGroupService;
|
||||
import org.ruoyi.generator.service.SchemaService;
|
||||
import org.ruoyi.generator.domain.Schema;
|
||||
import org.ruoyi.generator.domain.bo.SchemaBo;
|
||||
@@ -20,6 +23,8 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 数据模型Service业务层处理
|
||||
@@ -31,6 +36,7 @@ import java.util.List;
|
||||
public class SchemaServiceImpl implements SchemaService {
|
||||
|
||||
private final SchemaMapper baseMapper;
|
||||
private final SchemaGroupService schemaGroupService;
|
||||
private final ApplicationEventPublisher eventPublisher;
|
||||
|
||||
/**
|
||||
@@ -64,10 +70,7 @@ public class SchemaServiceImpl implements SchemaService {
|
||||
LambdaQueryWrapper<Schema> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(bo.getSchemaGroupId() != null, Schema::getSchemaGroupId, bo.getSchemaGroupId());
|
||||
lqw.like(StringUtils.isNotBlank(bo.getName()), Schema::getName, bo.getName());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getCode()), Schema::getCode, bo.getCode());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getTableName()), Schema::getTableName, bo.getTableName());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), Schema::getStatus, bo.getStatus());
|
||||
lqw.orderByAsc(Schema::getSort);
|
||||
return lqw;
|
||||
}
|
||||
|
||||
@@ -76,15 +79,18 @@ public class SchemaServiceImpl implements SchemaService {
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(SchemaBo bo) {
|
||||
Schema add = MapstructUtils.convert(bo, Schema.class);
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
Schema schema = MapstructUtils.convert(bo, Schema.class);
|
||||
Long schemaGroupId = bo.getSchemaGroupId();
|
||||
SchemaGroupVo schemaGroupVo = schemaGroupService.queryById(schemaGroupId);
|
||||
if (Objects.nonNull(schemaGroupVo)) {
|
||||
schema.setCode(schemaGroupVo.getCode());
|
||||
}
|
||||
boolean flag = baseMapper.insert(schema) > 0;
|
||||
if (flag) {
|
||||
bo.setId(add.getId());
|
||||
|
||||
bo.setId(schema.getId());
|
||||
// 发布数据模型添加事件,由事件监听器处理字段插入
|
||||
if (StringUtils.isNotBlank(bo.getTableName())) {
|
||||
eventPublisher.publishEvent(new SchemaAddedEvent(this, add.getId(), bo.getTableName()));
|
||||
eventPublisher.publishEvent(new SchemaAddedEvent(this, schema.getId(), bo.getTableName()));
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
@@ -96,17 +102,9 @@ public class SchemaServiceImpl implements SchemaService {
|
||||
@Override
|
||||
public Boolean updateByBo(SchemaBo bo) {
|
||||
Schema update = MapstructUtils.convert(bo, Schema.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(Schema entity) {
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除数据模型
|
||||
*/
|
||||
@@ -127,8 +125,6 @@ public class SchemaServiceImpl implements SchemaService {
|
||||
public SchemaVo queryByTableName(String tableName) {
|
||||
LambdaQueryWrapper<Schema> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(Schema::getTableName, tableName);
|
||||
// 只查询正常状态的模型
|
||||
lqw.eq(Schema::getStatus, "0");
|
||||
return baseMapper.selectVoOne(lqw);
|
||||
}
|
||||
}
|
||||
@@ -13,4 +13,12 @@ public interface IGenTableService {
|
||||
* @param tableName 表名称数组
|
||||
*/
|
||||
void generateCodeToClasspathByTableNames(String tableName);
|
||||
|
||||
/**
|
||||
* 生成前端文件
|
||||
*
|
||||
* @param workPath 执行命令路径
|
||||
* @param previewCode 执行生成前端文件命令
|
||||
*/
|
||||
void generateFrontendTemplateFiles(String workPath, String previewCode);
|
||||
}
|
||||
|
||||
@@ -25,26 +25,28 @@ import org.ruoyi.common.core.validate.EditGroup;
|
||||
public class ${ClassName}Bo implements Serializable {
|
||||
|
||||
#foreach ($column in $columns)
|
||||
#if(!$table.isSuperColumn($column.javaField) && ($column.isPk || $column.query || $column.insert || $column.edit))
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
#if($column.insert && $column.edit)
|
||||
#set($Group="AddGroup.class, EditGroup.class")
|
||||
#elseif($column.insert)
|
||||
#set($Group="AddGroup.class")
|
||||
#elseif($column.edit)
|
||||
#set($Group="EditGroup.class")
|
||||
#end
|
||||
#if($column.required)
|
||||
#if($column.javaType == 'String')
|
||||
@NotBlank(message = "$column.columnComment不能为空", groups = { $Group })
|
||||
#else
|
||||
@NotNull(message = "$column.columnComment不能为空", groups = { $Group })
|
||||
#end
|
||||
#end
|
||||
#if($column.isPk)
|
||||
private $column.javaType $column.javaField;
|
||||
|
||||
#elseif($column.insert || $column.edit)
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
#if($column.insert && $column.edit)
|
||||
#set($Group="AddGroup.class, EditGroup.class")
|
||||
#elseif($column.insert)
|
||||
#set($Group="AddGroup.class")
|
||||
#elseif($column.edit)
|
||||
#set($Group="EditGroup.class")
|
||||
#end
|
||||
#if($column.required)
|
||||
#if($column.javaType == 'String')
|
||||
@NotBlank(message = "$column.columnComment不能为空", groups = { $Group })
|
||||
#else
|
||||
@NotNull(message = "$column.columnComment不能为空", groups = { $Group })
|
||||
#end
|
||||
#end
|
||||
private $column.javaType $column.javaField;
|
||||
#end
|
||||
#end
|
||||
|
||||
|
||||
@@ -1,22 +1,10 @@
|
||||
package ${packageName}.domain;
|
||||
|
||||
#foreach ($column in $columns)
|
||||
#if($column.javaField=='tenantId')
|
||||
#set($IsTenant=1)
|
||||
#end
|
||||
#end
|
||||
#if($IsTenant==1)
|
||||
import core.tenant.common.org.ruoyi.TenantEntity;
|
||||
#else
|
||||
#end
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
#foreach ($import in $importList)
|
||||
import ${import};
|
||||
#end
|
||||
|
||||
import org.ruoyi.core.domain.BaseEntity;
|
||||
#foreach ($import in $importList)
|
||||
import ${import};
|
||||
#end
|
||||
|
||||
/**
|
||||
* ${functionName}对象 ${tableName}
|
||||
@@ -24,15 +12,9 @@ import org.ruoyi.core.domain.BaseEntity;
|
||||
* @author ${author}
|
||||
* @date ${datetime}
|
||||
*/
|
||||
#if($IsTenant==1)
|
||||
#set($Entity="TenantEntity")
|
||||
#else
|
||||
#set($Entity="BaseEntity")
|
||||
#end
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("${tableName}")
|
||||
public class ${ClassName} extends ${Entity} {
|
||||
public class ${ClassName} implements Serializable {
|
||||
|
||||
|
||||
#foreach ($column in $columns)
|
||||
@@ -47,7 +29,7 @@ public class ${ClassName} extends ${Entity} {
|
||||
@Version
|
||||
#end
|
||||
#if($column.isPk==1)
|
||||
@TableId(value = "$column.columnName")
|
||||
@TableId(value = "${column.columnName}", type = IdType.AUTO)
|
||||
#end
|
||||
private $column.javaType $column.javaField;
|
||||
|
||||
|
||||
@@ -23,29 +23,30 @@ import java.util.Date;
|
||||
@AutoMapper(target = ${ClassName}.class)
|
||||
public class ${ClassName}Vo implements Serializable {
|
||||
|
||||
#foreach ($column in $columns)
|
||||
#if($column.list)
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||
#if($parentheseIndex != -1)
|
||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||
#else
|
||||
#set($comment=$column.columnComment)
|
||||
#end
|
||||
#if(${column.dictType} && ${column.dictType} != '')
|
||||
@ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(dictType = "${column.dictType}")
|
||||
#elseif($parentheseIndex != -1)
|
||||
@ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(readConverterExp = "$column.readConverterExp()")
|
||||
#else
|
||||
@ExcelProperty(value = "${comment}")
|
||||
#end
|
||||
private $column.javaType $column.javaField;
|
||||
|
||||
#end
|
||||
#foreach ($column in $columns)
|
||||
#if($column.isPk)
|
||||
private $column.javaType $column.javaField;
|
||||
#elseif($column.list)
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||
#if($parentheseIndex != -1)
|
||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||
#else
|
||||
#set($comment=$column.columnComment)
|
||||
#end
|
||||
#if(${column.dictType} && ${column.dictType} != '')
|
||||
@ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(dictType = "${column.dictType}")
|
||||
#elseif($parentheseIndex != -1)
|
||||
@ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(readConverterExp = "$column.readConverterExp()")
|
||||
#else
|
||||
@ExcelProperty(value = "${comment}")
|
||||
#end
|
||||
private $column.javaType $column.javaField;
|
||||
#end
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user