mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-03-13 20:53:42 +08:00
Merge branch 'ageerle:main' into main
This commit is contained in:
@@ -8,6 +8,7 @@ import lombok.EqualsAndHashCode;
|
||||
import org.ruoyi.core.domain.BaseEntity;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 聊天模型对象 chat_model
|
||||
@@ -80,5 +81,10 @@ public class ChatModel extends BaseEntity {
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 模型能力
|
||||
*/
|
||||
private String modelCapability;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,14 +5,14 @@ import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import org.ruoyi.common.sensitive.annotation.Sensitive;
|
||||
import org.ruoyi.common.sensitive.core.SensitiveStrategy;
|
||||
import org.ruoyi.domain.ChatModel;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@@ -96,4 +96,138 @@ public class ChatModelVo implements Serializable {
|
||||
@ExcelProperty(value = "备注")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 模型能力
|
||||
*/
|
||||
@ExcelProperty(value = "模型能力")
|
||||
private String modelCapability;
|
||||
|
||||
/**
|
||||
* 模型能力列表
|
||||
*/
|
||||
private List<Ability> modelAbilities = getModelAbilities();
|
||||
|
||||
/**
|
||||
* 模型能力类,类似枚举的静态内部类
|
||||
*/
|
||||
@Getter
|
||||
public static final class Ability {
|
||||
// 获取能力名称
|
||||
private final String name;
|
||||
private final String description;
|
||||
|
||||
// 静态字段存储默认能力(类似枚举常量)
|
||||
public static final Ability IMAGE = new Ability("IMAGE", "图片理解");
|
||||
public static final Ability VIDEO = new Ability("VIDEO", "视频理解");
|
||||
public static final Ability SPEECH = new Ability("SPEECH", "语音理解");
|
||||
|
||||
// 动态扩展能力存储
|
||||
private static final java.util.Map<String, Ability> EXTENDED_ABILITIES = new java.util.HashMap<>();
|
||||
|
||||
// 私有构造确保受限
|
||||
private Ability(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
// 静态工厂方法(类似枚举valueOf)
|
||||
public static Ability valueOf(String name) {
|
||||
// 先检查默认能力
|
||||
switch (name) {
|
||||
case "IMAGE": return IMAGE;
|
||||
case "VIDEO": return VIDEO;
|
||||
case "SPEECH": return SPEECH;
|
||||
default:
|
||||
// 检查扩展能力
|
||||
Ability ability = EXTENDED_ABILITIES.get(name);
|
||||
if (ability != null) return ability;
|
||||
throw new IllegalArgumentException("Unknown ability: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
// 动态注册新能力(后期从数据库调用)
|
||||
public static synchronized Ability registerAbility(String name, String description) {
|
||||
if (name == null || name.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("Ability name cannot be empty");
|
||||
}
|
||||
|
||||
// 避免重复注册
|
||||
if (EXTENDED_ABILITIES.containsKey(name)) {
|
||||
return EXTENDED_ABILITIES.get(name);
|
||||
}
|
||||
|
||||
// 检查是否与默认能力冲突
|
||||
try {
|
||||
valueOf(name);
|
||||
throw new IllegalArgumentException("Ability already exists as default: " + name);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// 正常情况,继续注册
|
||||
}
|
||||
|
||||
Ability newAbility = new Ability(name, description);
|
||||
EXTENDED_ABILITIES.put(name, newAbility);
|
||||
return newAbility;
|
||||
}
|
||||
|
||||
// 获取所有能力(默认+扩展)
|
||||
public static java.util.Set<Ability> getAllAbilities() {
|
||||
java.util.Map<String, Ability> all = new java.util.HashMap<>();
|
||||
all.put(IMAGE.name, IMAGE);
|
||||
all.put(VIDEO.name, VIDEO);
|
||||
all.put(SPEECH.name, SPEECH);
|
||||
all.putAll(EXTENDED_ABILITIES);
|
||||
return java.util.Collections.unmodifiableSet((java.util.Set<? extends Ability>) all.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Ability ability = (Ability) o;
|
||||
return name.equals(ability.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 modelCapability 字符串转换为 Ability 列表
|
||||
* @return Ability 列表
|
||||
*/
|
||||
public java.util.List<Ability> getModelAbilities() {
|
||||
if (modelCapability == null || modelCapability.trim().isEmpty()) {
|
||||
return java.util.Collections.emptyList();
|
||||
}
|
||||
|
||||
// 解析 JSON 格式的字符串数组
|
||||
String trimmed = modelCapability.trim();
|
||||
if (!trimmed.startsWith("[") || !trimmed.endsWith("]")) {
|
||||
throw new IllegalArgumentException("Invalid modelCapability format: " + modelCapability);
|
||||
}
|
||||
|
||||
String content = trimmed.substring(1, trimmed.length() - 1).trim();
|
||||
if (content.isEmpty()) {
|
||||
return java.util.Collections.emptyList();
|
||||
}
|
||||
|
||||
java.util.List<Ability> abilities = new java.util.ArrayList<>();
|
||||
String[] items = content.split(",");
|
||||
for (String item : items) {
|
||||
String cleanedItem = item.trim();
|
||||
if (cleanedItem.startsWith("\"") && cleanedItem.endsWith("\"") && cleanedItem.length() >= 2) {
|
||||
String abilityName = cleanedItem.substring(1, cleanedItem.length() - 1);
|
||||
abilities.add(Ability.valueOf(abilityName));
|
||||
}
|
||||
}
|
||||
|
||||
return abilities;
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,18 @@ import org.ruoyi.service.IKnowledgeAttachService;
|
||||
import org.ruoyi.service.IKnowledgeFragmentService;
|
||||
import org.ruoyi.service.IKnowledgeInfoService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 知识库管理
|
||||
@@ -60,7 +68,9 @@ public class KnowledgeController extends BaseController {
|
||||
if (!StpUtil.isLogin()) {
|
||||
throw new SecurityException("请先去登录!");
|
||||
}
|
||||
bo.setUid(LoginHelper.getUserId());
|
||||
if (!Objects.equals(LoginHelper.getUserId(), 1L)) {
|
||||
bo.setUid(LoginHelper.getUserId());
|
||||
}
|
||||
return knowledgeInfoService.queryPageList(bo, pageQuery);
|
||||
}
|
||||
|
||||
@@ -72,13 +82,15 @@ public class KnowledgeController extends BaseController {
|
||||
if (!StpUtil.isLogin()) {
|
||||
throw new SecurityException("请先去登录!");
|
||||
}
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
|
||||
// 管理员跳过权限
|
||||
if (loginUser.getUserId().equals(1L) || !knowledgeRoleConfig.getEnable()) {
|
||||
if (Objects.equals(LoginHelper.getUserId(), 1L)) {
|
||||
return knowledgeInfoService.queryPageList(bo, pageQuery);
|
||||
} else if (!knowledgeRoleConfig.getEnable()) {
|
||||
bo.setUid(LoginHelper.getUserId());
|
||||
return knowledgeInfoService.queryPageList(bo, pageQuery);
|
||||
} else {
|
||||
// TODO 自己创建的知识库+角色分配的知识库
|
||||
return knowledgeInfoService.queryPageListByRole(pageQuery);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
|
||||
@@ -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)) {
|
||||
@@ -136,6 +166,8 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
boolean autoRemovePre = GenConfig.getAutoRemovePre();
|
||||
|
||||
// 处理表名和类名
|
||||
Long schemaGroupId = schema.getSchemaGroupId();
|
||||
SchemaGroupVo schemaGroupVo = schemaGroupService.queryById(schemaGroupId);
|
||||
String tableName = schema.getTableName();
|
||||
String baseClassName = schema.getTableName();
|
||||
|
||||
@@ -153,7 +185,7 @@ 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);
|
||||
@@ -194,16 +226,6 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
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);
|
||||
|
||||
// 处理字段信息
|
||||
@@ -284,18 +306,19 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据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 -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从包名中提取模块名
|
||||
@@ -412,16 +435,17 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
return "String";
|
||||
}
|
||||
String type = dbType.toLowerCase();
|
||||
if (type.contains("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);
|
||||
}
|
||||
@@ -211,7 +209,6 @@ public class SchemaFieldServiceImpl implements SchemaFieldService {
|
||||
result.put("tableName", schema.getTableName());
|
||||
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());
|
||||
@@ -265,8 +262,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 +276,26 @@ 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.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 +365,15 @@ public class SchemaFieldServiceImpl implements SchemaFieldService {
|
||||
}
|
||||
|
||||
String type = dbType.toLowerCase();
|
||||
if (type.contains("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)
|
||||
|
||||
@@ -2496,11 +2496,56 @@ CREATE TABLE prompt_template
|
||||
ROW_FORMAT = Dynamic;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `dev_schema_group`;
|
||||
create table dev_schema_group
|
||||
(
|
||||
id bigint auto_increment comment '主键' primary key,
|
||||
name varchar(100) null comment '分组名称',
|
||||
code varchar(100) null comment '分组编码',
|
||||
icon varchar(100) null comment '图标',
|
||||
remark varchar(500) null comment '备注',
|
||||
del_flag char default '0' null comment '删除标志(0代表存在 2代表删除)',
|
||||
create_dept bigint null comment '创建部门',
|
||||
create_by bigint null comment '创建者',
|
||||
create_time datetime null comment '创建时间',
|
||||
update_by bigint null comment '更新者',
|
||||
update_time datetime null comment '更新时间'
|
||||
) ENGINE = InnoDB
|
||||
CHARACTER SET = utf8mb4
|
||||
COLLATE = utf8mb4_general_ci COMMENT = '数据模型分组表';
|
||||
|
||||
INSERT INTO dev_schema_group (id, name, code, icon, remark, del_flag, create_dept, create_by, create_time, update_by, update_time) VALUES
|
||||
(1944240213530648567, '系统管理', 'system', 'eos-icons:system-group', '系统默认分组', '0', null, null, '2025-07-13 11:37:28', 1, '2025-07-13 18:42:48');
|
||||
INSERT INTO dev_schema_group (id, name, code, icon, remark, del_flag, create_dept, create_by, create_time, update_by, update_time) VALUES
|
||||
(1944240213530648577, '运营管理', 'operator', 'icon-park-outline:appointment', '运营管理', '0', null, null, '2025-07-13 11:39:24', 1, '2025-07-13 18:42:31');
|
||||
INSERT INTO dev_schema_group (id, name, code, icon, remark, del_flag, create_dept, create_by, create_time, update_by, update_time) VALUES
|
||||
(1944346023254429697, '在线开发', 'dev', 'carbon:development', '在线开发', '0', null, null, '2025-07-13 18:39:51', 1, '2025-07-13 18:42:07');
|
||||
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `dev_schema`;
|
||||
create table dev_schema
|
||||
(
|
||||
id bigint auto_increment comment '主键' primary key,
|
||||
schema_group_id bigint null comment '分组ID',
|
||||
name varchar(100) null comment '模型名称',
|
||||
code varchar(100) null comment '模型编码',
|
||||
table_name varchar(100) null comment '表名',
|
||||
remark varchar(500) null comment '备注',
|
||||
del_flag char default '0' null comment '删除标志(0代表存在 2代表删除)',
|
||||
create_dept bigint null comment '创建部门',
|
||||
create_by bigint null comment '创建者',
|
||||
create_time datetime null comment '创建时间',
|
||||
update_by bigint null comment '更新者',
|
||||
update_time datetime null comment '更新时间'
|
||||
) ENGINE = InnoDB
|
||||
CHARACTER SET = utf8mb4
|
||||
COLLATE = utf8mb4_general_ci COMMENT = '数据模型表';
|
||||
|
||||
DROP TABLE IF EXISTS `dev_schema_field`;
|
||||
create table dev_schema_field
|
||||
(
|
||||
id bigint auto_increment comment '主键'
|
||||
primary key,
|
||||
id bigint auto_increment comment '主键' primary key,
|
||||
schema_id bigint null comment '模型ID',
|
||||
schema_name varchar(64) null comment '模型名称',
|
||||
name varchar(100) null comment '字段名称',
|
||||
@@ -2513,17 +2558,6 @@ create table dev_schema_field
|
||||
default_value varchar(200) null comment '默认值',
|
||||
length int null comment '字段长度',
|
||||
scale int null comment '小数位数',
|
||||
sort int null comment '排序',
|
||||
status char default '0' null comment '状态(0正常 1停用)',
|
||||
extend_json text null comment '扩展配置',
|
||||
remark varchar(500) null comment '备注',
|
||||
del_flag char default '0' null comment '删除标志(0代表存在 2代表删除)',
|
||||
tenant_id varchar(20) default '000000' null comment '租户编号',
|
||||
create_dept bigint null comment '创建部门',
|
||||
create_by bigint null comment '创建者',
|
||||
create_time datetime null comment '创建时间',
|
||||
update_by bigint null comment '更新者',
|
||||
update_time datetime null comment '更新时间',
|
||||
is_list char default '1' null comment '是否列表显示(0否 1是)',
|
||||
is_query char default '1' null comment '是否查询字段(0否 1是)',
|
||||
is_insert char default '1' null comment '是否插入字段(0否 1是)',
|
||||
@@ -2531,125 +2565,23 @@ create table dev_schema_field
|
||||
query_type varchar(200) default null comment '查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围)',
|
||||
html_type varchar(200) default 'input' null comment '显示类型(input输入框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、image图片上传、upload文件上传、editor富文本编辑器)',
|
||||
dict_type varchar(200) default '' null comment '字典类型',
|
||||
constraint fk_schema_field_schema
|
||||
foreign key (schema_id) references dev_schema (id)
|
||||
on delete cascade
|
||||
) comment '数据模型字段表';
|
||||
|
||||
create index idx_html_type
|
||||
on dev_schema_field (html_type);
|
||||
|
||||
create index idx_is_list
|
||||
on dev_schema_field (is_list);
|
||||
|
||||
create index idx_is_query
|
||||
on dev_schema_field (is_query);
|
||||
|
||||
create index idx_query_type
|
||||
on dev_schema_field (query_type);
|
||||
|
||||
create index idx_schema_field_code
|
||||
on dev_schema_field (code);
|
||||
|
||||
create index idx_schema_field_schema_id
|
||||
on dev_schema_field (schema_id);
|
||||
|
||||
create index idx_schema_field_status
|
||||
on dev_schema_field (status);
|
||||
|
||||
create index idx_schema_field_tenant
|
||||
on dev_schema_field (tenant_id);
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `dev_schema`;
|
||||
create table dev_schema
|
||||
(
|
||||
id bigint auto_increment comment '主键'
|
||||
primary key,
|
||||
schema_group_id bigint null comment '分组ID',
|
||||
name varchar(100) null comment '模型名称',
|
||||
code varchar(100) null comment '模型编码',
|
||||
table_name varchar(100) null comment '表名',
|
||||
comment varchar(500) null comment '表注释',
|
||||
engine varchar(50) default 'InnoDB' null comment '存储引擎',
|
||||
list_keys text null comment '列表字段',
|
||||
search_form_keys text null comment '搜索表单字段',
|
||||
designer longtext null comment '表单设计',
|
||||
status char default '0' null comment '状态(0正常 1停用)',
|
||||
sort int null comment '排序',
|
||||
remark varchar(500) null comment '备注',
|
||||
del_flag char default '0' null comment '删除标志(0代表存在 2代表删除)',
|
||||
tenant_id varchar(20) default '000000' null comment '租户编号',
|
||||
create_dept bigint null comment '创建部门',
|
||||
create_by bigint null comment '创建者',
|
||||
create_time datetime null comment '创建时间',
|
||||
update_by bigint null comment '更新者',
|
||||
update_time datetime null comment '更新时间',
|
||||
constraint fk_schema_group
|
||||
foreign key (schema_group_id) references dev_schema_group (id)
|
||||
on delete set null
|
||||
)
|
||||
comment '数据模型表';
|
||||
|
||||
create index idx_schema_code
|
||||
on dev_schema (code);
|
||||
|
||||
create index idx_schema_group_id
|
||||
on dev_schema (schema_group_id);
|
||||
|
||||
create index idx_schema_status
|
||||
on dev_schema (status);
|
||||
|
||||
create index idx_schema_table_name
|
||||
on dev_schema (table_name);
|
||||
|
||||
create index idx_schema_tenant
|
||||
on dev_schema (tenant_id);
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `dev_schema_group`;
|
||||
create table dev_schema_group
|
||||
(
|
||||
id bigint auto_increment comment '主键'
|
||||
primary key,
|
||||
name varchar(100) null comment '分组名称',
|
||||
code varchar(100) null comment '分组编码',
|
||||
icon varchar(100) null comment '图标',
|
||||
sort int null comment '排序',
|
||||
status char default '0' null comment '状态(0正常 1停用)',
|
||||
remark varchar(500) null comment '备注',
|
||||
del_flag char default '0' null comment '删除标志(0代表存在 2代表删除)',
|
||||
tenant_id varchar(20) default '000000' null comment '租户编号',
|
||||
create_dept bigint null comment '创建部门',
|
||||
create_by bigint null comment '创建者',
|
||||
create_time datetime null comment '创建时间',
|
||||
update_by bigint null comment '更新者',
|
||||
update_time datetime null comment '更新时间'
|
||||
)
|
||||
comment '数据模型分组表';
|
||||
|
||||
create index idx_schema_group_code
|
||||
on dev_schema_group (code);
|
||||
|
||||
create index idx_schema_group_status
|
||||
on dev_schema_group (status);
|
||||
|
||||
create index idx_schema_group_tenant
|
||||
on dev_schema_group (tenant_id);
|
||||
|
||||
|
||||
INSERT INTO dev_schema_group (id, name, code, icon, sort, status, remark, del_flag, tenant_id, create_dept, create_by, create_time, update_by, update_time) VALUES (1944240213530648567, '系统管理', 'system', 'eos-icons:system-group', 2, '0', '系统默认分组', '0', '000000', null, null, '2025-07-13 11:37:28', 1, '2025-07-13 18:42:48');
|
||||
INSERT INTO dev_schema_group (id, name, code, icon, sort, status, remark, del_flag, tenant_id, create_dept, create_by, create_time, update_by, update_time) VALUES (1944240213530648577, '运营管理', 'operator', 'icon-park-outline:appointment', 1, '0', null, '0', '000000', null, null, '2025-07-13 11:39:24', 1, '2025-07-13 18:42:31');
|
||||
INSERT INTO dev_schema_group (id, name, code, icon, sort, status, remark, del_flag, tenant_id, create_dept, create_by, create_time, update_by, update_time) VALUES (1944346023254429697, '在线开发', 'dev', 'carbon:development', 3, '0', null, '0', '000000', null, null, '2025-07-13 18:39:51', 1, '2025-07-13 18:42:07');
|
||||
|
||||
|
||||
|
||||
sort int null comment '排序',
|
||||
del_flag char default '0' null comment '删除标志(0代表存在 2代表删除)',
|
||||
create_dept bigint null comment '创建部门',
|
||||
create_by bigint null comment '创建者',
|
||||
create_time datetime null comment '创建时间',
|
||||
update_by bigint null comment '更新者',
|
||||
update_time datetime null comment '更新时间',
|
||||
remark varchar(500) null comment '备注'
|
||||
) ENGINE = InnoDB
|
||||
CHARACTER SET = utf8mb4
|
||||
COLLATE = utf8mb4_general_ci COMMENT = '数据模型字段表';
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `knowledge_role`;
|
||||
-- ----------------------------
|
||||
-- Table structure for knowledge_role
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `knowledge_role`;
|
||||
CREATE TABLE `knowledge_role` (
|
||||
`id` bigint NOT NULL COMMENT '知识库角色id',
|
||||
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '知识库角色name',
|
||||
@@ -2664,10 +2596,10 @@ CREATE TABLE `knowledge_role` (
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '知识库角色表' ROW_FORMAT = DYNAMIC;
|
||||
|
||||
DROP TABLE IF EXISTS `knowledge_role_group`;
|
||||
-- ----------------------------
|
||||
-- Table structure for knowledge_role_group
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `knowledge_role_group`;
|
||||
CREATE TABLE `knowledge_role_group` (
|
||||
`id` bigint NOT NULL COMMENT '知识库角色组id',
|
||||
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '知识库角色组name',
|
||||
|
||||
3
script/sql/update/20250808.sql
Normal file
3
script/sql/update/20250808.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
-- 聊天模型表添加模型能力字段
|
||||
alter table chat_model
|
||||
add model_capability varchar(255) default '[]' not null comment '模型能力';
|
||||
@@ -74,7 +74,7 @@ SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
|
||||
-- 菜单
|
||||
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `query_param`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_dept`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (1946483381643743233, '知识库角色管理', 1775500307898949634, '12', 'knowledgeRole', 'system/knowledgeRole/index', NULL, 1, 0, 'C', '0', '0', NULL, 'ri:user-3-fill', 103, 1, '2025-07-19 16:41:17', NULL, NULL, '知识库角色管理');
|
||||
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `query_param`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_dept`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (1946483381643743233, '知识库角色管理', 1775500307898949634, '12', 'knowledgeRole', 'operator/knowledgeRole/index', NULL, 1, 0, 'C', '0', '0', NULL, 'ri:user-3-fill', 103, 1, '2025-07-19 16:41:17', NULL, NULL, '知识库角色管理');
|
||||
|
||||
-- 用户表添加字段
|
||||
ALTER TABLE sys_user
|
||||
|
||||
Reference in New Issue
Block a user