From 6f1d0287fafda3f7a9b79725c19bd535d34485c7 Mon Sep 17 00:00:00 2001 From: Raod <1130305001@qq.com> Date: Sun, 26 Sep 2021 10:05:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=BC=80=E5=90=AFflyway?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/config/DatabaseInitializer.java | 2 ++ .../dao/entity/AccessAuthority.java | 4 +-- .../accessrole/dao/entity/AccessRole.java | 4 +-- .../dao/entity/AccessRoleAuthority.java | 2 +- .../service/impl/AccessRoleServiceImpl.java | 12 ++++++-- .../accessuser/dao/entity/AccessUser.java | 4 +-- .../accessuser/dao/entity/AccessUserRole.java | 4 +-- .../service/impl/AccessUserServiceImpl.java | 29 +++++++++++++++---- .../dashboard/dao/entity/ReportDashboard.java | 2 +- .../dao/entity/ReportDashboardWidget.java | 2 +- .../modules/dataset/dao/entity/DataSet.java | 2 +- .../datasetparam/dao/entity/DataSetParam.java | 2 +- .../dao/entity/DataSetTransform.java | 2 +- .../datasource/dao/entity/DataSource.java | 2 +- .../modules/dict/dao/entity/GaeaDict.java | 2 +- .../modules/dict/dao/entity/GaeaDictItem.java | 2 +- .../modules/file/entity/GaeaFile.java | 2 +- .../modules/report/dao/entity/Report.java | 2 +- .../reportshare/dao/entity/ReportShare.java | 2 +- report-core/src/main/resources/bootstrap.yml | 1 + 20 files changed, 57 insertions(+), 27 deletions(-) diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/config/DatabaseInitializer.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/config/DatabaseInitializer.java index be4afc9f..129c42dd 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/config/DatabaseInitializer.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/config/DatabaseInitializer.java @@ -3,6 +3,7 @@ package com.anjiplus.template.gaea.business.config; import com.zaxxer.hikari.HikariDataSource; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.flyway.FlywayProperties; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.stereotype.Component; @@ -18,6 +19,7 @@ import java.sql.Statement; @Slf4j @Component @AllArgsConstructor +@ConditionalOnProperty(value = {"spring.flyway.enabled"}) public class DatabaseInitializer { private final FlywayProperties flywayProperties; diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessauthority/dao/entity/AccessAuthority.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessauthority/dao/entity/AccessAuthority.java index 54e08689..1d04d89f 100755 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessauthority/dao/entity/AccessAuthority.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessauthority/dao/entity/AccessAuthority.java @@ -12,7 +12,7 @@ import java.util.Date; * @author 木子李·De * @date 2019-02-17 08:50:10.009 **/ -@TableName(value="access_authority") +@TableName(keepGlobalPrefix=true, value="access_authority") @Data public class AccessAuthority extends GaeaBaseEntity { /** 父菜单代码 */ @@ -40,4 +40,4 @@ public class AccessAuthority extends GaeaBaseEntity { -} \ No newline at end of file +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessrole/dao/entity/AccessRole.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessrole/dao/entity/AccessRole.java index 36254f06..e8e7b1ae 100755 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessrole/dao/entity/AccessRole.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessrole/dao/entity/AccessRole.java @@ -11,7 +11,7 @@ import java.util.Date; * @author 木子李·De * @date 2019-02-17 08:50:14.136 **/ -@TableName(value="access_role") +@TableName(keepGlobalPrefix=true, value="access_role") @Data public class AccessRole extends GaeaBaseEntity { @@ -27,4 +27,4 @@ public class AccessRole extends GaeaBaseEntity { /** 0--已禁用 1--已启用 DIC_NAME=ENABLE_FLAG */ private Integer enableFlag; -} \ No newline at end of file +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessrole/dao/entity/AccessRoleAuthority.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessrole/dao/entity/AccessRoleAuthority.java index a32d04e7..cb20a8f2 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessrole/dao/entity/AccessRoleAuthority.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessrole/dao/entity/AccessRoleAuthority.java @@ -14,7 +14,7 @@ import java.util.Date; * @author 木子李·De * @date 2019-02-17 08:50:14.136 **/ -@TableName(value="access_role_authority") +@TableName(keepGlobalPrefix=true, value="access_role_authority") @Data public class AccessRoleAuthority extends GaeaBaseEntity { diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessrole/service/impl/AccessRoleServiceImpl.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessrole/service/impl/AccessRoleServiceImpl.java index 0d93b0ec..dea1b15a 100755 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessrole/service/impl/AccessRoleServiceImpl.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessrole/service/impl/AccessRoleServiceImpl.java @@ -21,6 +21,7 @@ import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * @desc AccessRole 角色管理服务实现 @@ -52,7 +53,14 @@ public class AccessRoleServiceImpl implements AccessRoleService { List treeData = accessAuthorityService.getAuthorityTree(operator, true); // 该角色已选中的菜单及按钮 - List checkedKeys = accessRoleMapper.checkedAuthoritys(roleCode); +// List checkedKeys = accessRoleMapper.checkedAuthoritys(roleCode); + + LambdaQueryWrapper accessRoleAuthorityWrapper = Wrappers.lambdaQuery(); + accessRoleAuthorityWrapper.select(AccessRoleAuthority::getTarget, AccessRoleAuthority::getAction); + accessRoleAuthorityWrapper.eq(AccessRoleAuthority::getRoleCode, roleCode); + List accessRoleAuthorities = accessRoleAuthorityMapper.selectList(accessRoleAuthorityWrapper); + List checkedKeys = accessRoleAuthorities.stream() + .map(accessRoleAuthority -> accessRoleAuthority.getTarget().concat("_").concat(accessRoleAuthority.getAction())).distinct().collect(Collectors.toList()); result.put("treeData", treeData); result.put("checkedKeys", checkedKeys); @@ -90,4 +98,4 @@ public class AccessRoleServiceImpl implements AccessRoleService { }); return true; } -} \ No newline at end of file +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/dao/entity/AccessUser.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/dao/entity/AccessUser.java index 26e706a4..5cd38158 100755 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/dao/entity/AccessUser.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/dao/entity/AccessUser.java @@ -11,7 +11,7 @@ import java.util.Date; * @author 木子李·De * @date 2019-02-17 08:50:11.902 **/ -@TableName(value="access_user") +@TableName(keepGlobalPrefix=true, value="access_user") @Data public class AccessUser extends GaeaBaseEntity { @@ -45,4 +45,4 @@ public class AccessUser extends GaeaBaseEntity { /** 最后一次登陆时间 */ private Date lastLoginTime; -} \ No newline at end of file +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/dao/entity/AccessUserRole.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/dao/entity/AccessUserRole.java index b43af5b5..a56be7ab 100755 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/dao/entity/AccessUserRole.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/dao/entity/AccessUserRole.java @@ -13,7 +13,7 @@ import java.util.Date; * @author 木子李·De * @date 2019-02-17 08:50:11.902 **/ -@TableName(value="access_user_role") +@TableName(keepGlobalPrefix=true, value="access_user_role") @Data public class AccessUserRole extends GaeaBaseEntity { @@ -37,4 +37,4 @@ public class AccessUserRole extends GaeaBaseEntity { @TableField(exist = false) private Integer version; -} \ No newline at end of file +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/service/impl/AccessUserServiceImpl.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/service/impl/AccessUserServiceImpl.java index d066a3a5..33523b33 100755 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/service/impl/AccessUserServiceImpl.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessuser/service/impl/AccessUserServiceImpl.java @@ -13,8 +13,10 @@ import com.anji.plus.gaea.utils.GaeaUtils; import com.anji.plus.gaea.utils.JwtBean; import com.anjiplus.template.gaea.business.code.ResponseCode; import com.anjiplus.template.gaea.business.constant.BusinessConstant; +import com.anjiplus.template.gaea.business.modules.accessrole.dao.AccessRoleAuthorityMapper; import com.anjiplus.template.gaea.business.modules.accessrole.dao.AccessRoleMapper; import com.anjiplus.template.gaea.business.modules.accessrole.dao.entity.AccessRole; +import com.anjiplus.template.gaea.business.modules.accessrole.dao.entity.AccessRoleAuthority; import com.anjiplus.template.gaea.business.modules.accessuser.controller.dto.AccessUserDto; import com.anjiplus.template.gaea.business.modules.accessuser.controller.dto.GaeaUserDto; import com.anjiplus.template.gaea.business.modules.accessuser.controller.dto.UpdatePasswordDto; @@ -31,10 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -54,6 +53,9 @@ public class AccessUserServiceImpl implements AccessUserService { @Autowired private AccessUserRoleMapper accessUserRoleMapper; + @Autowired + private AccessRoleAuthorityMapper accessRoleAuthorityMapper; + @Value("${customer.user.default.password:'123456'}") private String defaultPassword; @@ -168,7 +170,24 @@ public class AccessUserServiceImpl implements AccessUserService { // 4.读取用户最新人权限主信息 String userKey = String.format(BusinessConstant.GAEA_SECURITY_LOGIN_USER, loginName); - List authorities = accessUserMapper.queryAuthoritiesByLoginName(loginName); + //为了兼容底层其他数据库,不再写自定义sql +// List authorities = accessUserMapper.queryAuthoritiesByLoginName(loginName); + + //当前用户的roleCode集合 + LambdaQueryWrapper accessUserWrapper = Wrappers.lambdaQuery(); + accessUserWrapper.select(AccessUserRole::getRoleCode); + accessUserWrapper.eq(AccessUserRole::getLoginName, loginName); + List accessUserRoles = accessUserRoleMapper.selectList(accessUserWrapper); + Set roleCodeSet = accessUserRoles.stream().map(AccessUserRole::getRoleCode).collect(Collectors.toSet()); + + LambdaQueryWrapper accessRoleAuthorityWrapper = Wrappers.lambdaQuery(); + accessRoleAuthorityWrapper.select(AccessRoleAuthority::getTarget, AccessRoleAuthority::getAction); + accessRoleAuthorityWrapper.in(AccessRoleAuthority::getRoleCode, roleCodeSet); + List accessRoleAuthorities = accessRoleAuthorityMapper.selectList(accessRoleAuthorityWrapper); + List authorities = accessRoleAuthorities.stream() + .map(accessRoleAuthority -> accessRoleAuthority.getTarget().concat(":").concat(accessRoleAuthority.getAction())).distinct().collect(Collectors.toList()); + + gaeaUser.setLoginName(loginName); gaeaUser.setRealName(accessUser.getRealName()); gaeaUser.setToken(token); diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboard/dao/entity/ReportDashboard.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboard/dao/entity/ReportDashboard.java index bf89396e..76ad6cb6 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboard/dao/entity/ReportDashboard.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboard/dao/entity/ReportDashboard.java @@ -13,7 +13,7 @@ import lombok.Data; * @author Raod * @date 2021-04-12 14:52:21.761 **/ -@TableName(value="gaea_report_dashboard") +@TableName(keepGlobalPrefix=true, value="gaea_report_dashboard") @Data public class ReportDashboard extends GaeaBaseEntity { @ApiModelProperty(value = "报表编码") diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboardwidget/dao/entity/ReportDashboardWidget.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboardwidget/dao/entity/ReportDashboardWidget.java index 671da4f3..2631236b 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboardwidget/dao/entity/ReportDashboardWidget.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboardwidget/dao/entity/ReportDashboardWidget.java @@ -11,7 +11,7 @@ import lombok.Data; * @author Raod * @date 2021-04-12 15:12:43.724 **/ -@TableName(value="gaea_report_dashboard_widget") +@TableName(keepGlobalPrefix=true, value="gaea_report_dashboard_widget") @Data public class ReportDashboardWidget extends GaeaBaseEntity { @ApiModelProperty(value = "报表编码") diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dataset/dao/entity/DataSet.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dataset/dao/entity/DataSet.java index 5a62b1a4..dfebbb07 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dataset/dao/entity/DataSet.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dataset/dao/entity/DataSet.java @@ -13,7 +13,7 @@ import lombok.Data; * @author Raod * @date 2021-03-18 12:11:31.150755900 **/ -@TableName(value="gaea_report_data_set") +@TableName(keepGlobalPrefix=true, value="gaea_report_data_set") @Data public class DataSet extends GaeaBaseEntity { @ApiModelProperty(value = "数据集编码") diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/datasetparam/dao/entity/DataSetParam.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/datasetparam/dao/entity/DataSetParam.java index 52a7e07b..96a1648f 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/datasetparam/dao/entity/DataSetParam.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/datasetparam/dao/entity/DataSetParam.java @@ -11,7 +11,7 @@ import lombok.Data; * @author Raod * @date 2021-03-18 12:12:33.108033200 **/ -@TableName(value="gaea_report_data_set_param") +@TableName(keepGlobalPrefix=true, value="gaea_report_data_set_param") @Data public class DataSetParam extends GaeaBaseEntity { @ApiModelProperty(value = "数据集编码") diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/datasettransform/dao/entity/DataSetTransform.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/datasettransform/dao/entity/DataSetTransform.java index 4ed3af3f..e81ad293 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/datasettransform/dao/entity/DataSetTransform.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/datasettransform/dao/entity/DataSetTransform.java @@ -11,7 +11,7 @@ import lombok.Data; * @author Raod * @date 2021-03-18 12:13:15.591309400 **/ -@TableName(value="gaea_report_data_set_transform") +@TableName(keepGlobalPrefix=true, value="gaea_report_data_set_transform") @Data public class DataSetTransform extends GaeaBaseEntity { @ApiModelProperty(value = "数据集编码") diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/datasource/dao/entity/DataSource.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/datasource/dao/entity/DataSource.java index d4939cc4..79f1e5b3 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/datasource/dao/entity/DataSource.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/datasource/dao/entity/DataSource.java @@ -13,7 +13,7 @@ import lombok.Data; * @author Raod * @date 2021-03-18 12:09:57.728203200 **/ -@TableName(value="gaea_report_data_source") +@TableName(keepGlobalPrefix=true, value="gaea_report_data_source") @Data public class DataSource extends GaeaBaseEntity { @ApiModelProperty(value = "数据源编码") diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/entity/GaeaDict.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/entity/GaeaDict.java index a2c68e9a..0bae6902 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/entity/GaeaDict.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/entity/GaeaDict.java @@ -13,7 +13,7 @@ import java.io.Serializable; * @author lr * @since 2021-02-23 10:01:02 */ -@TableName("gaea_dict") +@TableName(keepGlobalPrefix=true, value = "gaea_dict") public class GaeaDict extends GaeaBaseEntity implements Serializable { /** * 字典名称 diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/entity/GaeaDictItem.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/entity/GaeaDictItem.java index 49bfa5ea..37f75c2c 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/entity/GaeaDictItem.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dict/dao/entity/GaeaDictItem.java @@ -15,7 +15,7 @@ import java.io.Serializable; * @author lirui * @since 2021-03-09 15:52:41 */ -@TableName("gaea_dict_item") +@TableName(keepGlobalPrefix=true,value = "gaea_dict_item") @UnionUniqueCode(group = BusinessConstant.DICT_ITEM_EXIST_GROUP, code = ResponseCode.DICT_ITEM_REPEAT) public class GaeaDictItem extends GaeaBaseEntity implements Serializable { diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/file/entity/GaeaFile.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/file/entity/GaeaFile.java index 13747600..49a97343 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/file/entity/GaeaFile.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/file/entity/GaeaFile.java @@ -13,7 +13,7 @@ import java.io.Serializable; * @author peiyanni * @since 2021-02-18 14:48:20 */ -@TableName("gaea_file") +@TableName(keepGlobalPrefix=true, value = "gaea_file") @Data public class GaeaFile extends GaeaBaseEntity implements Serializable { diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/dao/entity/Report.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/dao/entity/Report.java index 32951b84..628255c8 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/dao/entity/Report.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/dao/entity/Report.java @@ -13,7 +13,7 @@ import lombok.Data; * @author chenkening * @date 2021/3/26 10:20 */ -@TableName(value="gaea_report") +@TableName(keepGlobalPrefix=true, value="gaea_report") @Data public class Report extends GaeaBaseEntity { diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/dao/entity/ReportShare.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/dao/entity/ReportShare.java index b2d06a52..88b4d748 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/dao/entity/ReportShare.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/dao/entity/ReportShare.java @@ -12,7 +12,7 @@ import java.util.Date; * @author Raod * @date 2021-08-18 13:37:26.663 **/ -@TableName(value="gaea_report_share") +@TableName(keepGlobalPrefix=true, value="gaea_report_share") @Data public class ReportShare extends GaeaBaseEntity { /** 分享编码,系统生成,默认UUID */ diff --git a/report-core/src/main/resources/bootstrap.yml b/report-core/src/main/resources/bootstrap.yml index e4157d82..7192afc6 100644 --- a/report-core/src/main/resources/bootstrap.yml +++ b/report-core/src/main/resources/bootstrap.yml @@ -37,6 +37,7 @@ spring: breakAfterAcquireFailure: true # 数据库服务宕机自动重连机制 timeBetweenConnectErrorMillis: 300000 # 连接出错后重试时间间隔 flyway: + enabled: true #是否开启flyway,默认true. baseline-on-migrate: true #数据库连接配置 url: ${spring.datasource.url}