From 733c290fe5862899ad3fae483552e1f01af26696 Mon Sep 17 00:00:00 2001 From: ruying408 <1877972603@qq.com> Date: Fri, 2 Aug 2024 01:39:32 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=EF=BC=9A=E6=8F=92=E4=BB=B6ja?= =?UTF-8?q?r=E4=BA=8C=E8=BF=9B=E5=88=B6=E6=96=87=E4=BB=B6=E5=85=A5?= =?UTF-8?q?=E5=BA=93,=20=E8=B0=83=E6=95=B4=EF=BC=9A=E5=AE=9E=E4=BD=93?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=B3=A8=E8=A7=A3=E7=B1=BB=E5=9E=8B=EF=BC=8C?= =?UTF-8?q?=E5=85=BC=E5=AE=B9postgresql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 9 ++-- ...CustomJavaTypeToDatabaseTypeConverter.java | 53 +++++++++++++++++++ .../plugin/service/CoolPluginService.java | 16 +----- .../com/cool/core/request/CrudOption.java | 4 +- .../base/entity/sys/BaseSysMenuEntity.java | 2 +- .../base/entity/sys/BaseSysParamEntity.java | 7 ++- .../base/entity/sys/BaseSysUserEntity.java | 8 ++- .../sys/impl/BaseSysPermsServiceImpl.java | 18 ++++--- .../sys/impl/BaseSysUserServiceImpl.java | 22 ++++++-- .../admin/AdminPluginInfoController.java | 4 +- .../plugin/entity/PluginInfoEntity.java | 3 -- .../service/impl/PluginInfoServiceImpl.java | 11 ++-- .../modules/space/entity/SpaceInfoEntity.java | 5 +- .../modules/space/entity/SpaceTypeEntity.java | 6 +-- .../modules/task/entity/TaskInfoEntity.java | 8 ++- src/main/resources/application-local.yml | 4 ++ src/main/resources/application.yml | 5 -- 17 files changed, 114 insertions(+), 71 deletions(-) create mode 100644 src/main/java/com/cool/core/autotable/CustomJavaTypeToDatabaseTypeConverter.java diff --git a/pom.xml b/pom.xml index 5f8cc0f..3d6a9d1 100644 --- a/pom.xml +++ b/pom.xml @@ -49,10 +49,6 @@ org.springframework.boot spring-boot-starter-security - - org.springframework.boot - spring-boot-starter-data-redis - org.springframework.boot spring-boot-starter-quartz @@ -83,6 +79,11 @@ mysql-connector-j runtime + + org.postgresql + postgresql + runtime + com.zaxxer HikariCP diff --git a/src/main/java/com/cool/core/autotable/CustomJavaTypeToDatabaseTypeConverter.java b/src/main/java/com/cool/core/autotable/CustomJavaTypeToDatabaseTypeConverter.java new file mode 100644 index 0000000..181e708 --- /dev/null +++ b/src/main/java/com/cool/core/autotable/CustomJavaTypeToDatabaseTypeConverter.java @@ -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 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); + } +} diff --git a/src/main/java/com/cool/core/plugin/service/CoolPluginService.java b/src/main/java/com/cool/core/plugin/service/CoolPluginService.java index 3c06943..f6f8756 100644 --- a/src/main/java/com/cool/core/plugin/service/CoolPluginService.java +++ b/src/main/java/com/cool/core/plugin/service/CoolPluginService.java @@ -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 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); diff --git a/src/main/java/com/cool/core/request/CrudOption.java b/src/main/java/com/cool/core/request/CrudOption.java index 9f287ce..66add2f 100644 --- a/src/main/java/com/cool/core/request/CrudOption.java +++ b/src/main/java/com/cool/core/request/CrudOption.java @@ -107,14 +107,14 @@ public class CrudOption { 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")); } } diff --git a/src/main/java/com/cool/modules/base/entity/sys/BaseSysMenuEntity.java b/src/main/java/com/cool/modules/base/entity/sys/BaseSysMenuEntity.java index 65f957b..c404785 100644 --- a/src/main/java/com/cool/modules/base/entity/sys/BaseSysMenuEntity.java +++ b/src/main/java/com/cool/modules/base/entity/sys/BaseSysMenuEntity.java @@ -23,7 +23,7 @@ public class BaseSysMenuEntity extends BaseEntity { @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 = "图标") diff --git a/src/main/java/com/cool/modules/base/entity/sys/BaseSysParamEntity.java b/src/main/java/com/cool/modules/base/entity/sys/BaseSysParamEntity.java index 97db9e7..7edf81e 100644 --- a/src/main/java/com/cool/modules/base/entity/sys/BaseSysParamEntity.java +++ b/src/main/java/com/cool/modules/base/entity/sys/BaseSysParamEntity.java @@ -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 { @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 = "备注") diff --git a/src/main/java/com/cool/modules/base/entity/sys/BaseSysUserEntity.java b/src/main/java/com/cool/modules/base/entity/sys/BaseSysUserEntity.java index 8098af9..03fad92 100644 --- a/src/main/java/com/cool/modules/base/entity/sys/BaseSysUserEntity.java +++ b/src/main/java/com/cool/modules/base/entity/sys/BaseSysUserEntity.java @@ -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 { @ColumnDefine(comment = "备注") private String remark; - @ColumnDefine(comment = "状态 0:禁用 1:启用", defaultValue = "1", type = "tinyint") + @ColumnDefine(comment = "状态 0:禁用 1:启用", defaultValue = "1") private Integer status; // 部门名称 diff --git a/src/main/java/com/cool/modules/base/service/sys/impl/BaseSysPermsServiceImpl.java b/src/main/java/com/cool/modules/base/service/sys/impl/BaseSysPermsServiceImpl.java index 208550f..b97e9d3 100644 --- a/src/main/java/com/cool/modules/base/service/sys/impl/BaseSysPermsServiceImpl.java +++ b/src/main/java/com/cool/modules/base/service/sys/impl/BaseSysPermsServiceImpl.java @@ -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); } diff --git a/src/main/java/com/cool/modules/base/service/sys/impl/BaseSysUserServiceImpl.java b/src/main/java/com/cool/modules/base/service/sys/impl/BaseSysUserServiceImpl.java index 7fde5d0..c144c6d 100644 --- a/src/main/java/com/cool/modules/base/service/sys/impl/BaseSysUserServiceImpl.java +++ b/src/main/java/com/cool/modules/base/service/sys/impl/BaseSysUserServiceImpl.java @@ -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 page, QueryWrapper qw) { String keyWord = requestParams.getStr("keyWord"); @@ -53,11 +57,21 @@ public class BaseSysUserServiceImpl extends BaseServiceImpl { @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 config; diff --git a/src/main/java/com/cool/modules/plugin/service/impl/PluginInfoServiceImpl.java b/src/main/java/com/cool/modules/plugin/service/impl/PluginInfoServiceImpl.java index e213845..d7650d0 100644 --- a/src/main/java/com/cool/modules/plugin/service/impl/PluginInfoServiceImpl.java +++ b/src/main/java/com/cool/modules/plugin/service/impl/PluginInfoServiceImpl.java @@ -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 { @ColumnDefine(comment = "类型", notNull = true) private String type; - @ColumnDefine(comment = "分类ID", type = "tinyint") + @ColumnDefine(comment = "分类ID") private Integer classifyId; @Index() diff --git a/src/main/java/com/cool/modules/space/entity/SpaceTypeEntity.java b/src/main/java/com/cool/modules/space/entity/SpaceTypeEntity.java index ad8155d..f50f61f 100644 --- a/src/main/java/com/cool/modules/space/entity/SpaceTypeEntity.java +++ b/src/main/java/com/cool/modules/space/entity/SpaceTypeEntity.java @@ -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 { @ColumnDefine(comment = "类别名称", notNull = true) private String name; - @ColumnDefine(comment = "父分类ID", type = "tinyint") + @ColumnDefine(comment = "父分类ID") private Integer parentId; } diff --git a/src/main/java/com/cool/modules/task/entity/TaskInfoEntity.java b/src/main/java/com/cool/modules/task/entity/TaskInfoEntity.java index 91b9672..79e815c 100644 --- a/src/main/java/com/cool/modules/task/entity/TaskInfoEntity.java +++ b/src/main/java/com/cool/modules/task/entity/TaskInfoEntity.java @@ -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 { @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 = "任务数据") diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index b01e42b..3fd6e43 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -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: # 启用自动维护表功能 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 7c03747..21fc220 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -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: # 过期时间 单位:秒 半小时