移除:插件jar二进制文件入库,

调整:实体字段注解类型,兼容postgresql
This commit is contained in:
ruying408
2024-08-02 01:39:32 +08:00
parent fc16dd2c09
commit 733c290fe5
17 changed files with 114 additions and 71 deletions

View File

@@ -0,0 +1,53 @@
package com.cool.core.autotable;
import com.tangzc.autotable.annotation.ColumnType;
import com.tangzc.autotable.core.constants.DatabaseDialect;
import com.tangzc.autotable.core.converter.DatabaseTypeAndLength;
import com.tangzc.autotable.core.converter.JavaTypeToDatabaseTypeConverter;
import com.tangzc.autotable.core.strategy.pgsql.data.PgsqlDefaultTypeEnum;
import com.tangzc.autotable.core.utils.StringUtils;
import com.tangzc.autotable.core.utils.TableBeanUtils;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import org.springframework.stereotype.Component;
@Component
public class CustomJavaTypeToDatabaseTypeConverter implements JavaTypeToDatabaseTypeConverter {
/**
* 重新 java转数据库类型
* 兼容 mybatisflex 不兼容 postgresql 的json类型问题
*/
@Override
public DatabaseTypeAndLength convert(String databaseDialect, Class<?> clazz, Field field) {
ColumnType column = TableBeanUtils.getColumnType(field);
// 设置了类型
if (column != null) {
String type = column.value();
Integer length = column.length() > -1 ? column.length() : null;
Integer decimalLength = column.decimalLength() > -1 ? column.decimalLength() : null;
List<String> values = Arrays.asList(column.values());
// 如果明确指定了类型名,直接替换
if (StringUtils.hasText(type)) {
if (DatabaseDialect.PostgreSQL.equals(databaseDialect) &&
type.equalsIgnoreCase("json")) {
// json 类型在 postgresql 处理成 text
PgsqlDefaultTypeEnum typeEnum = PgsqlDefaultTypeEnum.TEXT;
return new DatabaseTypeAndLength(typeEnum.getTypeName(), typeEnum.getDefaultLength(), typeEnum.getDefaultLength(), values);
}
return new DatabaseTypeAndLength(type, length, decimalLength, values);
}
// 如果没有指定明确的类型名,但是却指定了长度。那么使用默认类型+指定长度
if (length != null || decimalLength != null) {
DatabaseTypeAndLength typeAndLength = getDatabaseTypeAndLength(databaseDialect, clazz, field);
typeAndLength.setLength(length);
typeAndLength.setDecimalLength(decimalLength);
return typeAndLength;
}
}
// 其他情况,使用默认类型
return getDatabaseTypeAndLength(databaseDialect, clazz, field);
}
}

View File

@@ -5,7 +5,6 @@ import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.codec.Base64Encoder;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.cool.core.config.PluginJson;
@@ -47,9 +46,6 @@ public class CoolPluginService {
@Value("${cool.plugin.path}")
private String pluginPath;
@Value("${cool.plugin.toDb:false}")
private Boolean toDb;
public void init() {
List<PluginInfoEntity> list = pluginInfoService
.list(QueryWrapper
@@ -71,12 +67,8 @@ public class CoolPluginService {
File file = new File(pluginJson.getJarPath());
// 检查文件是否存在
if (!file.exists()) {
PluginInfoEntity pluginInfoEntity = pluginInfoService.getById(entity.getId());
if (ObjUtil.isEmpty(pluginInfoEntity.getJarFile())) {
log.warn("插件文件不存在,请重新安装!");
return;
}
FileUtil.writeBytes(pluginInfoEntity.getJarFile(), file);
log.warn("插件文件不存在,请重新安装!");
return;
}
file = new File(pluginJson.getJarPath());
if (file.exists()) {
@@ -189,10 +181,6 @@ public class CoolPluginService {
setLogoOrReadme(pluginJson, pluginInfo);
pluginInfo.setKey(pluginJson.getKey());
pluginInfo.setPluginJson(pluginJson);
if (BooleanUtil.isTrue(toDb)) {
// 转二进制
pluginInfo.setJarFile(FileUtil.readBytes(jarFile));
}
if (force) {
// 判断是否有同名插件, 有将其关闭
closeSameNamePlugin(pluginJson);

View File

@@ -107,14 +107,14 @@ public class CrudOption<T> {
if (ObjectUtil.isNotEmpty(queryTables)) {
// 取主表作为排序字段别名
QueryTable queryTable = queryTables.get(0);
tableAlias = "`" + queryTable.getName() + "`.";
tableAlias = queryTable.getName() + ".";
}
String order = requestParams.getStr("order",
tableAnnotation.camelToUnderline() ? "create_time" : "createTime");
String sort = requestParams.getStr("sort", "desc");
if (StrUtil.isNotEmpty(order) && StrUtil.isNotEmpty(sort)) {
queryWrapper.orderBy(
tableAlias + "`" + (tableAnnotation.camelToUnderline() ? StrUtil.toUnderlineCase(order) : order) + "`",
tableAlias + (tableAnnotation.camelToUnderline() ? StrUtil.toUnderlineCase(order) : order),
sort.equals("asc"));
}
}

View File

@@ -23,7 +23,7 @@ public class BaseSysMenuEntity extends BaseEntity<BaseSysMenuEntity> {
@ColumnDefine(comment = "权限", type = "text")
private String perms;
@ColumnDefine(comment = "类型 0目录 1菜单 2按钮", type = "tinyint", defaultValue = "0")
@ColumnDefine(comment = "类型 0目录 1菜单 2按钮", defaultValue = "0")
private Integer type;
@ColumnDefine(comment = "图标")

View File

@@ -1,10 +1,9 @@
package com.cool.modules.base.entity.sys;
import com.cool.core.base.BaseEntity;
import com.tangzc.autotable.annotation.Index;
import com.tangzc.mybatisflex.autotable.annotation.ColumnDefine;
import com.mybatisflex.annotation.Table;
import com.tangzc.autotable.annotation.Index;
import com.tangzc.mybatisflex.autotable.annotation.ColumnDefine;
import lombok.Getter;
import lombok.Setter;
@@ -22,7 +21,7 @@ public class BaseSysParamEntity extends BaseEntity<BaseSysParamEntity> {
@ColumnDefine(comment = "数据", type = "text")
private String data;
@ColumnDefine(comment = "数据类型 0:字符串 1:数组 2:键值对", defaultValue = "0", type = "tinyint")
@ColumnDefine(comment = "数据类型 0:字符串 1:数组 2:键值对", defaultValue = "0")
private Integer dataType;
@ColumnDefine(comment = "备注")

View File

@@ -2,12 +2,10 @@ package com.cool.modules.base.entity.sys;
import com.cool.core.base.BaseEntity;
import com.mybatisflex.annotation.Column;
import com.tangzc.autotable.annotation.Index;
import com.tangzc.autotable.annotation.enums.IndexTypeEnum;
import com.tangzc.mybatisflex.autotable.annotation.ColumnDefine;
import com.mybatisflex.annotation.Table;
import com.tangzc.autotable.annotation.Index;
import com.tangzc.autotable.annotation.enums.IndexTypeEnum;
import com.tangzc.mybatisflex.autotable.annotation.ColumnDefine;
import lombok.Getter;
import lombok.Setter;
@@ -47,7 +45,7 @@ public class BaseSysUserEntity extends BaseEntity<BaseSysUserEntity> {
@ColumnDefine(comment = "备注")
private String remark;
@ColumnDefine(comment = "状态 0:禁用 1启用", defaultValue = "1", type = "tinyint")
@ColumnDefine(comment = "状态 0:禁用 1启用", defaultValue = "1")
private Integer status;
// 部门名称

View File

@@ -1,5 +1,9 @@
package com.cool.modules.base.service.sys.impl;
import static com.cool.modules.base.entity.sys.table.BaseSysMenuEntityTableDef.BASE_SYS_MENU_ENTITY;
import static com.cool.modules.base.entity.sys.table.BaseSysRoleMenuEntityTableDef.BASE_SYS_ROLE_MENU_ENTITY;
import static com.cool.modules.base.entity.sys.table.BaseSysUserRoleEntityTableDef.BASE_SYS_USER_ROLE_ENTITY;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Dict;
@@ -14,17 +18,12 @@ import com.cool.modules.base.security.CoolSecurityUtil;
import com.cool.modules.base.service.sys.BaseSysPermsService;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.row.Row;
import java.util.*;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Service;
import java.util.*;
import static com.cool.modules.base.entity.sys.table.BaseSysMenuEntityTableDef.BASE_SYS_MENU_ENTITY;
import static com.cool.modules.base.entity.sys.table.BaseSysRoleMenuEntityTableDef.BASE_SYS_ROLE_MENU_ENTITY;
import static com.cool.modules.base.entity.sys.table.BaseSysUserRoleEntityTableDef.BASE_SYS_USER_ROLE_ENTITY;
@Service
@RequiredArgsConstructor
public class BaseSysPermsServiceImpl implements BaseSysPermsService {
@@ -65,9 +64,12 @@ public class BaseSysPermsServiceImpl implements BaseSysPermsService {
}
private Long[] getLongs(Long[] roleIds) {
QueryWrapper queryWrapper = QueryWrapper.create();
if (roleIds != null && !CollUtil.toList(roleIds).contains(1L)) {
queryWrapper.in(BaseSysRoleDepartmentEntity::getRoleId, (Object) roleIds);
}
return baseSysRoleDepartmentMapper
.selectListByQuery(QueryWrapper.create().in(BaseSysRoleDepartmentEntity::getRoleId, (Object) roleIds,
roleIds != null && !CollUtil.toList(roleIds).contains(1L)))
.selectListByQuery(queryWrapper)
.stream().map(BaseSysRoleDepartmentEntity::getDepartmentId).toArray(Long[]::new);
}

View File

@@ -26,6 +26,7 @@ import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
@@ -44,6 +45,9 @@ public class BaseSysUserServiceImpl extends BaseServiceImpl<BaseSysUserMapper, B
final private BaseSysDepartmentMapper baseSysDepartmentMapper;
@Value("${spring.datasource.url}")
private String datasourceUrl;
@Override
public Object page(JSONObject requestParams, Page<BaseSysUserEntity> page, QueryWrapper qw) {
String keyWord = requestParams.getStr("keyWord");
@@ -53,11 +57,21 @@ public class BaseSysUserServiceImpl extends BaseServiceImpl<BaseSysUserMapper, B
// 用户的部门权限
Long[] permsDepartmentArr = coolCache.get("admin:department:" + tokenInfo.get("userId"),
Long[].class);
qw.select(BASE_SYS_USER_ENTITY.ALL_COLUMNS,
// TODO 临时兼容 postgresql
if (datasourceUrl.contains("postgresql")) {
qw.select(BASE_SYS_USER_ENTITY.ALL_COLUMNS
// ,
// groupConcat(BASE_SYS_ROLE_ENTITY.NAME).as("roleName"),
// BASE_SYS_DEPARTMENT_ENTITY.NAME.as("departmentName")
);
} else {
qw.select(BASE_SYS_USER_ENTITY.ALL_COLUMNS,
groupConcat(BASE_SYS_ROLE_ENTITY.NAME).as("roleName"),
BASE_SYS_DEPARTMENT_ENTITY.NAME.as("departmentName"))
.from(BASE_SYS_USER_ENTITY).leftJoin(BASE_SYS_USER_ROLE_ENTITY)
BASE_SYS_DEPARTMENT_ENTITY.NAME.as("departmentName")
);
}
qw.from(BASE_SYS_USER_ENTITY).leftJoin(BASE_SYS_USER_ROLE_ENTITY)
.on(BASE_SYS_USER_ENTITY.ID.eq(BASE_SYS_USER_ROLE_ENTITY.USER_ID))
.leftJoin(BASE_SYS_ROLE_ENTITY)
.on(BASE_SYS_USER_ROLE_ENTITY.USER_ID.eq(BASE_SYS_ROLE_ENTITY.ID))

View File

@@ -9,7 +9,6 @@ import com.cool.core.annotation.IgnoreRecycleData;
import com.cool.core.base.BaseController;
import com.cool.core.plugin.service.CoolPluginService;
import com.cool.core.request.R;
import com.cool.core.util.EntityUtils;
import com.cool.modules.plugin.entity.PluginInfoEntity;
import com.cool.modules.plugin.service.PluginInfoService;
import com.mybatisflex.core.query.QueryWrapper;
@@ -38,8 +37,7 @@ public class AdminPluginInfoController extends BaseController<PluginInfoService,
setPageOption(createOp().queryWrapper(
QueryWrapper.create().orderBy(PLUGIN_INFO_ENTITY.UPDATE_TIME, false))
.select(EntityUtils.getFieldNamesWithSuperClass(PLUGIN_INFO_ENTITY.DEFAULT_COLUMNS,
PLUGIN_INFO_ENTITY.JAR_FILE.getName())));
.select(PLUGIN_INFO_ENTITY.DEFAULT_COLUMNS));
}
@Override

View File

@@ -52,9 +52,6 @@ public class PluginInfoEntity extends BaseEntity<PluginInfoEntity> {
@Column(typeHandler = Fastjson2TypeHandler.class)
private PluginJson pluginJson;
@ColumnDefine(comment = "jar二进制文件(可配置是否入库)", type = "longblob")
private byte[] jarFile;
@ColumnDefine(comment = "配置", type = "json")
@Column(typeHandler = JacksonTypeHandler.class)
private Map<String, Object> config;

View File

@@ -3,7 +3,6 @@ package com.cool.modules.plugin.service.impl;
import static com.cool.modules.plugin.entity.table.PluginInfoEntityTableDef.PLUGIN_INFO_ENTITY;
import com.cool.core.base.BaseServiceImpl;
import com.cool.core.util.EntityUtils;
import com.cool.modules.plugin.entity.PluginInfoEntity;
import com.cool.modules.plugin.mapper.PluginInfoMapper;
import com.cool.modules.plugin.service.PluginInfoService;
@@ -18,7 +17,7 @@ public class PluginInfoServiceImpl extends BaseServiceImpl<PluginInfoMapper, Plu
implements PluginInfoService {
/**
* 通过key获取插件信息,不带jar二进制
* 通过key获取插件信息
*/
@Override
public PluginInfoEntity getByKey(String key) {
@@ -28,7 +27,7 @@ public class PluginInfoServiceImpl extends BaseServiceImpl<PluginInfoMapper, Plu
}
/**
* 通过hook获取插件信息,不带jar二进制
* 通过hook获取插件信息
*/
@Override
public PluginInfoEntity getPluginInfoEntityByHook(String hook) {
@@ -38,7 +37,7 @@ public class PluginInfoServiceImpl extends BaseServiceImpl<PluginInfoMapper, Plu
}
/**
* 通过id获取插件信息,不带jar二进制
* 通过id获取插件信息
*/
@Override
public PluginInfoEntity getPluginInfoEntityById(Long id) {
@@ -47,9 +46,9 @@ public class PluginInfoServiceImpl extends BaseServiceImpl<PluginInfoMapper, Plu
}
/**
* 获取查询对象,排除掉 jar二进制
* 获取查询对象
*/
private QueryWrapper getPluginInfoEntityQueryWrapper() {
return QueryWrapper.create().select(EntityUtils.getFieldNamesWithSuperClass(PLUGIN_INFO_ENTITY.DEFAULT_COLUMNS, PLUGIN_INFO_ENTITY.JAR_FILE.getName()));
return QueryWrapper.create();
}
}

View File

@@ -2,11 +2,10 @@ package com.cool.modules.space.entity;
import com.cool.core.base.BaseEntity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Table;
import com.tangzc.autotable.annotation.Ignore;
import com.tangzc.autotable.annotation.Index;
import com.tangzc.mybatisflex.autotable.annotation.ColumnDefine;
import com.mybatisflex.annotation.Table;
import lombok.Getter;
import lombok.Setter;
@@ -23,7 +22,7 @@ public class SpaceInfoEntity extends BaseEntity<SpaceInfoEntity> {
@ColumnDefine(comment = "类型", notNull = true)
private String type;
@ColumnDefine(comment = "分类ID", type = "tinyint")
@ColumnDefine(comment = "分类ID")
private Integer classifyId;
@Index()

View File

@@ -1,10 +1,8 @@
package com.cool.modules.space.entity;
import com.cool.core.base.BaseEntity;
import com.tangzc.mybatisflex.autotable.annotation.ColumnDefine;
import com.mybatisflex.annotation.Table;
import lombok.Data;
import com.tangzc.mybatisflex.autotable.annotation.ColumnDefine;
import lombok.Getter;
import lombok.Setter;
@@ -18,6 +16,6 @@ public class SpaceTypeEntity extends BaseEntity<SpaceTypeEntity> {
@ColumnDefine(comment = "类别名称", notNull = true)
private String name;
@ColumnDefine(comment = "父分类ID", type = "tinyint")
@ColumnDefine(comment = "父分类ID")
private Integer parentId;
}

View File

@@ -2,14 +2,12 @@ package com.cool.modules.task.entity;
import com.cool.core.base.BaseEntity;
import com.mybatisflex.annotation.Column;
import com.tangzc.mybatisflex.autotable.annotation.ColumnDefine;
import com.mybatisflex.annotation.Table;
import com.tangzc.mybatisflex.autotable.annotation.ColumnDefine;
import java.util.Date;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
@Getter
@Setter
@Table(value = "task_info", comment = "任务信息")
@@ -41,7 +39,7 @@ public class TaskInfoEntity extends BaseEntity<TaskInfoEntity> {
@ColumnDefine(comment = "状态 0:cron 1时间间隔", defaultValue = "0")
private Integer taskType;
@ColumnDefine(comment = "状态 0:系统 1用户", defaultValue = "0", type = "tinyint")
@ColumnDefine(comment = "状态 0:系统 1用户", defaultValue = "0")
private Integer type;
@ColumnDefine(comment = "任务数据")

View File

@@ -5,6 +5,10 @@ spring:
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:postgresql://127.0.0.1:5432/cool
# username: postgres
# password: 123456
# driver-class-name: org.postgresql.Driver
# AutoTable配置根据实体类自动生成表
auto-table:
# 启用自动维护表功能

View File

@@ -88,9 +88,6 @@ ignored:
- /admin/base/open/**
# 忽略记录请求日志url
logUrls:
- /*
- /css/*
- /js/*
# 文档
springdoc:
api-docs:
@@ -119,8 +116,6 @@ cool:
plugin:
# 插件安装位置
path: assets/plugin
# 插件文件是否入库(默认否),先预留该字段,如果是集群部署需要开启,
toDb: false
# token 相关配置
token:
# 过期时间 单位:秒 半小时