diff --git a/blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetails.java b/blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetails.java index 593ac6fd..856356d5 100644 --- a/blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetails.java +++ b/blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetails.java @@ -46,6 +46,10 @@ public class BladeUserDetails extends User { * 账号 */ private String account; + /** + * 部门id + */ + private String deptId; /** * 角色id */ @@ -59,12 +63,13 @@ public class BladeUserDetails extends User { */ private String avatar; - public BladeUserDetails(Long userId, String tenantId, String name, String roleId, String roleName, String avatar, String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection authorities) { + public BladeUserDetails(Long userId, String tenantId, String name, String deptId, String roleId, String roleName, String avatar, String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection authorities) { super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); this.userId = userId; this.tenantId = tenantId; this.name = name; this.account = username; + this.deptId = deptId; this.roleId = roleId; this.roleName = roleName; this.avatar = avatar; diff --git a/blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetailsServiceImpl.java b/blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetailsServiceImpl.java index 4ca59085..320de2b3 100644 --- a/blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetailsServiceImpl.java +++ b/blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetailsServiceImpl.java @@ -73,7 +73,7 @@ public class BladeUserDetailsServiceImpl implements UserDetailsService { throw new UsernameNotFoundException(TokenUtil.USER_NOT_FOUND); } return new BladeUserDetails(user.getId(), - user.getTenantId(), user.getName(), user.getRoleId(), Func.join(result.getData().getRoles()), TokenUtil.DEFAULT_AVATAR, + user.getTenantId(), user.getName(), user.getDeptId(), user.getRoleId(), Func.join(result.getData().getRoles()), TokenUtil.DEFAULT_AVATAR, username, AuthConstant.ENCRYPT + user.getPassword(), true, true, true, true, AuthorityUtils.commaSeparatedStringToAuthorityList(Func.join(result.getData().getRoles()))); } else { diff --git a/blade-auth/src/main/java/org/springblade/auth/support/BladeJwtTokenEnhancer.java b/blade-auth/src/main/java/org/springblade/auth/support/BladeJwtTokenEnhancer.java index 2283969b..909c451b 100644 --- a/blade-auth/src/main/java/org/springblade/auth/support/BladeJwtTokenEnhancer.java +++ b/blade-auth/src/main/java/org/springblade/auth/support/BladeJwtTokenEnhancer.java @@ -39,6 +39,7 @@ public class BladeJwtTokenEnhancer implements TokenEnhancer { Map info = new HashMap<>(16); info.put(TokenUtil.CLIENT_ID, TokenUtil.getClientIdFromHeader()); info.put(TokenUtil.USER_ID, Func.toStr(principal.getUserId())); + info.put(TokenUtil.DEPT_ID, Func.toStr(principal.getDeptId())); info.put(TokenUtil.ROLE_ID, Func.toStr(principal.getRoleId())); info.put(TokenUtil.TENANT_ID, principal.getTenantId()); info.put(TokenUtil.ACCOUNT, principal.getAccount()); diff --git a/blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java b/blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java index ae0261b4..66743158 100644 --- a/blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java +++ b/blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java @@ -39,6 +39,7 @@ public class TokenUtil { public final static String USER_NAME = TokenConstant.USER_NAME; public final static String NICK_NAME = TokenConstant.NICK_NAME; public final static String USER_ID = TokenConstant.USER_ID; + public final static String DEPT_ID = TokenConstant.DEPT_ID; public final static String ROLE_ID = TokenConstant.ROLE_ID; public final static String ROLE_NAME = TokenConstant.ROLE_NAME; public final static String TENANT_ID = TokenConstant.TENANT_ID; diff --git a/blade-service-api/blade-desk-api/src/main/java/org/springblade/desk/vo/NoticeVO.java b/blade-service-api/blade-desk-api/src/main/java/org/springblade/desk/vo/NoticeVO.java index 49e23748..5b09e179 100644 --- a/blade-service-api/blade-desk-api/src/main/java/org/springblade/desk/vo/NoticeVO.java +++ b/blade-service-api/blade-desk-api/src/main/java/org/springblade/desk/vo/NoticeVO.java @@ -17,4 +17,7 @@ public class NoticeVO extends Notice { @ApiModelProperty(value = "通知类型名") private String categoryName; + @ApiModelProperty(value = "租户编号") + private String tenantId; + } diff --git a/blade-service/blade-desk/src/main/java/org/springblade/desk/controller/NoticeController.java b/blade-service/blade-desk/src/main/java/org/springblade/desk/controller/NoticeController.java index 40b9be47..42e17afd 100644 --- a/blade-service/blade-desk/src/main/java/org/springblade/desk/controller/NoticeController.java +++ b/blade-service/blade-desk/src/main/java/org/springblade/desk/controller/NoticeController.java @@ -71,6 +71,20 @@ public class NoticeController extends BladeController implements CacheNames { return R.data(NoticeWrapper.build().pageVO(pages)); } + /** + * 多表联合查询自定义分页 + */ + @GetMapping("/page") + @ApiImplicitParams({ + @ApiImplicitParam(name = "category", value = "公告类型", paramType = "query", dataType = "integer"), + @ApiImplicitParam(name = "title", value = "公告标题", paramType = "query", dataType = "string") + }) + @ApiOperation(value = "分页", notes = "传入notice", position = 1) + public R> page(@ApiIgnore NoticeVO notice, Query query) { + IPage pages = noticeService.selectNoticePage(Condition.getPage(query), notice); + return R.data(pages); + } + /** * 新增 */ diff --git a/blade-service/blade-desk/src/main/java/org/springblade/desk/mapper/NoticeMapper.java b/blade-service/blade-desk/src/main/java/org/springblade/desk/mapper/NoticeMapper.java index 87f4d1bb..e7e0812b 100644 --- a/blade-service/blade-desk/src/main/java/org/springblade/desk/mapper/NoticeMapper.java +++ b/blade-service/blade-desk/src/main/java/org/springblade/desk/mapper/NoticeMapper.java @@ -18,7 +18,9 @@ package org.springblade.desk.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import org.springblade.core.datascope.annotation.DataAuth; import org.springblade.desk.entity.Notice; +import org.springblade.desk.vo.NoticeVO; import java.util.List; @@ -42,6 +44,7 @@ public interface NoticeMapper extends BaseMapper { * @param notice * @return */ - List selectNoticePage(IPage page, Notice notice); + @DataAuth(resourceCode = "notice") + List selectNoticePage(IPage page, NoticeVO notice); } diff --git a/blade-service/blade-desk/src/main/java/org/springblade/desk/mapper/NoticeMapper.xml b/blade-service/blade-desk/src/main/java/org/springblade/desk/mapper/NoticeMapper.xml index 24e43293..eac197cc 100644 --- a/blade-service/blade-desk/src/main/java/org/springblade/desk/mapper/NoticeMapper.xml +++ b/blade-service/blade-desk/src/main/java/org/springblade/desk/mapper/NoticeMapper.xml @@ -16,24 +16,39 @@ - - - select id, - create_user AS createUser, - create_time AS createTime, - update_user AS updateUser, - update_time AS updateTime, - status, - is_deleted AS isDeleted, - title, content - + + + + + + + + + + + + + - + SELECT + n.*, + d.dict_value AS categoryName + FROM + blade_notice n + LEFT JOIN ( SELECT * FROM blade_dict WHERE CODE = 'notice' ) d ON n.category = d.dict_key + WHERE + n.is_deleted = 0 and n.tenant_id = #{notice.tenantId} + + and n.title like concat('%', #{notice.title}, '%') + + + and n.category = #{notice.category} + diff --git a/blade-service/blade-desk/src/main/java/org/springblade/desk/service/INoticeService.java b/blade-service/blade-desk/src/main/java/org/springblade/desk/service/INoticeService.java index 6fd35f31..aff42c8f 100644 --- a/blade-service/blade-desk/src/main/java/org/springblade/desk/service/INoticeService.java +++ b/blade-service/blade-desk/src/main/java/org/springblade/desk/service/INoticeService.java @@ -19,6 +19,7 @@ package org.springblade.desk.service; import com.baomidou.mybatisplus.core.metadata.IPage; import org.springblade.core.mp.base.BaseService; import org.springblade.desk.entity.Notice; +import org.springblade.desk.vo.NoticeVO; /** * 服务类 @@ -33,6 +34,6 @@ public interface INoticeService extends BaseService { * @param notice * @return */ - IPage selectNoticePage(IPage page, Notice notice); + IPage selectNoticePage(IPage page, NoticeVO notice); } diff --git a/blade-service/blade-desk/src/main/java/org/springblade/desk/service/impl/NoticeServiceImpl.java b/blade-service/blade-desk/src/main/java/org/springblade/desk/service/impl/NoticeServiceImpl.java index 5ac10336..da1cfa41 100644 --- a/blade-service/blade-desk/src/main/java/org/springblade/desk/service/impl/NoticeServiceImpl.java +++ b/blade-service/blade-desk/src/main/java/org/springblade/desk/service/impl/NoticeServiceImpl.java @@ -18,9 +18,11 @@ package org.springblade.desk.service.impl; import com.baomidou.mybatisplus.core.metadata.IPage; import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.secure.utils.SecureUtil; import org.springblade.desk.entity.Notice; import org.springblade.desk.mapper.NoticeMapper; import org.springblade.desk.service.INoticeService; +import org.springblade.desk.vo.NoticeVO; import org.springframework.stereotype.Service; /** @@ -32,7 +34,9 @@ import org.springframework.stereotype.Service; public class NoticeServiceImpl extends BaseServiceImpl implements INoticeService { @Override - public IPage selectNoticePage(IPage page, Notice notice) { + public IPage selectNoticePage(IPage page, NoticeVO notice) { + // 若不使用mybatis-plus自带的分页方法,则不会自动带入tenantId,所以我们需要自行注入 + notice.setTenantId(SecureUtil.getTenantId()); return page.setRecords(baseMapper.selectNoticePage(page, notice)); } diff --git a/doc/sql/bladex-datascope-update.sql b/doc/sql/bladex-datascope-update.sql new file mode 100644 index 00000000..41bf7fa6 --- /dev/null +++ b/doc/sql/bladex-datascope-update.sql @@ -0,0 +1,76 @@ +/* + Navicat Premium Data Transfer + + Source Server : mysql_localhost + Source Server Type : MySQL + Source Server Version : 50723 + Source Host : localhost:3306 + Source Schema : bladex_boot + + Target Server Type : MySQL + Target Server Version : 50723 + File Encoding : 65001 + + Date: 20/06/2019 00:31:21 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for blade_data_scope +-- ---------------------------- +DROP TABLE IF EXISTS `blade_data_scope`; +CREATE TABLE `blade_data_scope` ( + `id` bigint(64) NOT NULL COMMENT '主键', + `resource_code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '资源编号', + `scope_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '数据权限名称', + `scope_column` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '数据权限字段', + `scope_type` int(2) NULL DEFAULT NULL COMMENT '数据权限类型', + `scope_value` varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '数据权限值域', + `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '数据权限备注', + `create_user` bigint(64) NULL DEFAULT NULL COMMENT '创建人', + `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', + `update_user` bigint(64) NULL DEFAULT NULL COMMENT '修改人', + `update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', + `status` int(2) NULL DEFAULT NULL COMMENT '状态', + `is_deleted` int(2) NULL DEFAULT NULL COMMENT '是否已删除', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci; + +-- ---------------------------- +-- Table structure for blade_role_scope +-- ---------------------------- +DROP TABLE IF EXISTS `blade_role_scope`; +CREATE TABLE `blade_role_scope` ( + `id` bigint(64) NOT NULL COMMENT '主键', + `scope_id` bigint(64) NULL DEFAULT NULL COMMENT '数据权限id', + `role_id` bigint(64) NULL DEFAULT NULL COMMENT '角色id', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci; + +SET FOREIGN_KEY_CHECKS = 1; + +-- ---------------------------- +-- 部门表增加字段 +-- ---------------------------- +ALTER TABLE `blade_dept` + ADD COLUMN `ancestors` varchar(2000) NULL COMMENT '祖级列表' AFTER `parent_id`, + ADD COLUMN `dept_category` int(2) NULL COMMENT '部门类型' AFTER `ancestors`; + +UPDATE `blade_dept` SET `tenant_id` = '000000', `parent_id` = 0, `ancestors` = '0', `dept_category` = 1, `dept_name` = '刀锋科技', `full_name` = '江苏刀锋科技有限公司', `sort` = 1, `remark` = NULL, `is_deleted` = 0 WHERE `id` = 1123598813738675201; +UPDATE `blade_dept` SET `tenant_id` = '000000', `parent_id` = 1123598813738675201, `ancestors` = '0,1123598813738675201', `dept_category` = 1, `dept_name` = '常州刀锋', `full_name` = '常州刀锋科技有限公司', `sort` = 1, `remark` = NULL, `is_deleted` = 0 WHERE `id` = 1123598813738675202; +UPDATE `blade_dept` SET `tenant_id` = '000000', `parent_id` = 1123598813738675201, `ancestors` = '0,1123598813738675201', `dept_category` = 1, `dept_name` = '苏州刀锋', `full_name` = '苏州刀锋科技有限公司', `sort` = 1, `remark` = NULL, `is_deleted` = 0 WHERE `id` = 1123598813738675203; + +-- ---------------------------- +-- 增加字典项 +-- ---------------------------- +INSERT INTO `blade_dict`(`id`, `parent_id`, `code`, `dict_key`, `dict_value`, `sort`, `remark`, `is_deleted`) VALUES (1123598814738675227, 0, 'org_category', -1, '机构类型', 7, NULL, 0); +INSERT INTO `blade_dict`(`id`, `parent_id`, `code`, `dict_key`, `dict_value`, `sort`, `remark`, `is_deleted`) VALUES (1123598814738675228, 1123598814738675227, 'org_category', 1, '公司', 1, NULL, 0); +INSERT INTO `blade_dict`(`id`, `parent_id`, `code`, `dict_key`, `dict_value`, `sort`, `remark`, `is_deleted`) VALUES (1123598814738675229, 1123598814738675227, 'org_category', 2, '部门', 2, NULL, 0); +INSERT INTO `blade_dict`(`id`, `parent_id`, `code`, `dict_key`, `dict_value`, `sort`, `remark`, `is_deleted`) VALUES (1123598814738675230, 0, 'scope_type', -1, '数据权限类别', 8, NULL, 0); +INSERT INTO `blade_dict`(`id`, `parent_id`, `code`, `dict_key`, `dict_value`, `sort`, `remark`, `is_deleted`) VALUES (1123598814738675231, 1123598814738675230, 'scope_type', 1, '全部可见', 1, NULL, 0); +INSERT INTO `blade_dict`(`id`, `parent_id`, `code`, `dict_key`, `dict_value`, `sort`, `remark`, `is_deleted`) VALUES (1123598814738675232, 1123598814738675230, 'scope_type', 2, '本人可见', 2, NULL, 0); +INSERT INTO `blade_dict`(`id`, `parent_id`, `code`, `dict_key`, `dict_value`, `sort`, `remark`, `is_deleted`) VALUES (1123598814738675233, 1123598814738675230, 'scope_type', 3, '所在机构可见', 3, NULL, 0); +INSERT INTO `blade_dict`(`id`, `parent_id`, `code`, `dict_key`, `dict_value`, `sort`, `remark`, `is_deleted`) VALUES (1123598814738675234, 1123598814738675230, 'scope_type', 4, '所在机构及子级可见', 4, NULL, 0); +INSERT INTO `blade_dict`(`id`, `parent_id`, `code`, `dict_key`, `dict_value`, `sort`, `remark`, `is_deleted`) VALUES (1123598814738675235, 1123598814738675230, 'scope_type', 5, '自定义', 5, NULL, 0); diff --git a/doc/sql/bladex-tenantid-update.sql b/doc/sql/bladex-tenantid-update.sql deleted file mode 100644 index 4915aa51..00000000 --- a/doc/sql/bladex-tenantid-update.sql +++ /dev/null @@ -1,26 +0,0 @@ -ALTER TABLE `blade_dept` - CHANGE COLUMN `tenant_code` `tenant_id` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '000000' COMMENT '租户ID' AFTER `id`; - -ALTER TABLE `blade_log_api` - CHANGE COLUMN `tenant_code` `tenant_id` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '000000' COMMENT '租户ID' AFTER `id`; - -ALTER TABLE `blade_log_error` - CHANGE COLUMN `tenant_code` `tenant_id` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '000000' COMMENT '租户ID' AFTER `id`; - -ALTER TABLE `blade_log_usual` - CHANGE COLUMN `tenant_code` `tenant_id` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '000000' COMMENT '租户ID' AFTER `id`; - -ALTER TABLE `blade_notice` - CHANGE COLUMN `tenant_code` `tenant_id` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '000000' COMMENT '租户ID' AFTER `id`; - -ALTER TABLE `blade_oss` - CHANGE COLUMN `tenant_code` `tenant_id` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '000000' COMMENT '租户ID' AFTER `id`; - -ALTER TABLE `blade_role` - CHANGE COLUMN `tenant_code` `tenant_id` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '000000' COMMENT '租户ID' AFTER `id`; - -ALTER TABLE `blade_tenant` - CHANGE COLUMN `tenant_code` `tenant_id` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '000000' COMMENT '租户ID' AFTER `id`; - -ALTER TABLE `blade_user` - CHANGE COLUMN `tenant_code` `tenant_id` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '000000' COMMENT '租户ID' AFTER `id`; diff --git a/pom.xml b/pom.xml index 4a37adff..b1c435e3 100644 --- a/pom.xml +++ b/pom.xml @@ -25,11 +25,11 @@ 1.6.0 6.4.1 8.0.16 - 2.1.4 + 2.1.5 0.9.0.RELEASE - 2.1.5.RELEASE + 2.1.6.RELEASE Greenwich.SR1 Cairo-SR8