Browse Source

🎉 增加多租户模块,修复部分bug

test
smallchill 6 years ago
parent
commit
0f521694e6
  1. 8
      blade-auth/src/main/java/org/springblade/auth/controller/AuthController.java
  2. 4
      blade-service-api/blade-desk-api/src/main/java/org/springblade/desk/entity/Notice.java
  3. 4
      blade-service-api/blade-system-api/src/main/java/org/springblade/system/entity/Param.java
  4. 4
      blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/entity/User.java
  5. 4
      blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/feign/IUserClient.java
  6. 5
      blade-service-api/pom.xml
  7. 2
      blade-service/blade-desk/src/main/java/org/springblade/desk/service/impl/NoticeServiceImpl.java
  8. 2
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/DeptMapper.xml
  9. 9
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/DictMapper.xml
  10. 4
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.xml
  11. 2
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/RoleMapper.xml
  12. 4
      blade-service/blade-user/src/main/java/org/springblade/system/user/feign/UserClient.java
  13. 3
      blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserMapper.java
  14. 3
      blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserMapper.xml
  15. 3
      blade-service/blade-user/src/main/java/org/springblade/system/user/service/IUserService.java
  16. 4
      blade-service/blade-user/src/main/java/org/springblade/system/user/service/impl/UserServiceImpl.java
  17. 5
      blade-service/pom.xml
  18. 7
      doc/nacos/blade.yaml
  19. 1109
      doc/sql/bladex-oracle.sql
  20. 47
      doc/sql/bladex-saber-mysql.sql
  21. 53
      doc/sql/bladex-sword-mysql.sql
  22. 22
      doc/sql/bladex-tenant-mysql-update-RC5.sql

8
blade-auth/src/main/java/org/springblade/auth/controller/AuthController.java

@ -50,15 +50,16 @@ public class AuthController {
@ApiLog("登录用户验证")
@PostMapping("token")
@ApiOperation(value = "获取认证token", notes = "传入账号:account,密码:password")
public R<AuthInfo> token(@ApiParam(value = "账号", required = true) @RequestParam String account,
@ApiOperation(value = "获取认证token", notes = "传入租户编号:code,账号:account,密码:password")
public R<AuthInfo> token(@ApiParam(value = "租户编号", required = true) @RequestParam String code,
@ApiParam(value = "账号", required = true) @RequestParam String account,
@ApiParam(value = "密码", required = true) @RequestParam String password) {
if (Func.hasEmpty(account, password)) {
return R.fail("接口调用不合法");
}
R<UserInfo> res = client.userInfo(account, DigestUtil.encrypt(password));
R<UserInfo> res = client.userInfo(code, account, DigestUtil.encrypt(password));
User user = res.getData().getUser();
@ -71,6 +72,7 @@ public class AuthController {
Map<String, String> param = new HashMap<>(16);
param.put(SecureUtil.USER_ID, Func.toStr(user.getId()));
param.put(SecureUtil.ROLE_ID, user.getRoleId());
param.put(SecureUtil.TENANT_CODE, user.getTenantCode());
param.put(SecureUtil.ACCOUNT, user.getAccount());
param.put(SecureUtil.USER_NAME, user.getRealName());
param.put(SecureUtil.ROLE_NAME, Func.join(res.getData().getRoles()));

4
blade-service-api/blade-desk-api/src/main/java/org/springblade/desk/entity/Notice.java

@ -20,7 +20,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.mp.base.BaseEntity;
import org.springblade.core.tenant.mp.TenantEntity;
import java.util.Date;
@ -32,7 +32,7 @@ import java.util.Date;
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("blade_notice")
public class Notice extends BaseEntity {
public class Notice extends TenantEntity {
private static final long serialVersionUID = 1L;

4
blade-service-api/blade-system-api/src/main/java/org/springblade/system/entity/Param.java

@ -21,7 +21,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.mp.base.BaseEntity;
import org.springblade.core.tenant.mp.TenantEntity;
/**
* 实体类
@ -32,7 +32,7 @@ import org.springblade.core.mp.base.BaseEntity;
@TableName("blade_param")
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "Param对象", description = "Param对象")
public class Param extends BaseEntity {
public class Param extends TenantEntity {
private static final long serialVersionUID = 1L;

4
blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/entity/User.java

@ -19,7 +19,7 @@ package org.springblade.system.user.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.mp.base.BaseEntity;
import org.springblade.core.tenant.mp.TenantEntity;
import java.time.LocalDateTime;
@ -31,7 +31,7 @@ import java.time.LocalDateTime;
@Data
@TableName("blade_user")
@EqualsAndHashCode(callSuper = true)
public class User extends BaseEntity {
public class User extends TenantEntity {
private static final long serialVersionUID = 1L;

4
blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/feign/IUserClient.java

@ -26,6 +26,7 @@ import org.springframework.web.bind.annotation.RequestParam;
/**
* User Feign接口类
*
* @author Chill
*/
@FeignClient(
@ -38,11 +39,12 @@ public interface IUserClient {
/**
* 获取用户信息
*
* @param code 租户编号
* @param account 账号
* @param password 密码
* @return
*/
@GetMapping(API_PREFIX + "/user-info")
R<UserInfo> userInfo(@RequestParam("account") String account, @RequestParam("password") String password);
R<UserInfo> userInfo(@RequestParam("code") String code, @RequestParam("account") String account, @RequestParam("password") String password);
}

5
blade-service-api/pom.xml

@ -28,6 +28,11 @@
<artifactId>blade-starter-mybatis</artifactId>
<version>${bladex.tool.version}</version>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-starter-tenant</artifactId>
<version>${bladex.tool.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>

2
blade-service/blade-desk/src/main/java/org/springblade/desk/service/impl/NoticeServiceImpl.java

@ -18,8 +18,8 @@ package org.springblade.desk.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.desk.mapper.NoticeMapper;
import org.springblade.desk.entity.Notice;
import org.springblade.desk.mapper.NoticeMapper;
import org.springblade.desk.service.INoticeService;
import org.springframework.stereotype.Service;

2
blade-service/blade-system/src/main/java/org/springblade/system/mapper/DeptMapper.xml

@ -32,7 +32,7 @@
</select>
<select id="tree" resultMap="treeNodeResultMap">
select id, parent_id, dept_name as title, id as `value`, id as `key` from blade_dept where is_deleted = 0
select id, parent_id, dept_name as title, id as 'value', id as 'key' from blade_dept where is_deleted = 0
</select>
</mapper>

9
blade-service/blade-system/src/main/java/org/springblade/system/mapper/DictMapper.xml

@ -38,12 +38,19 @@
from blade_dict where code = #{param1} and dict_key = #{param2} limit 1
</select>
<!-- oracle 版本 -->
<!--<select id="getValue" resultType="java.lang.String">
select
dict_value
from blade_dict where code = #{param1, jdbcType=VARCHAR} and dict_key = #{param2} rownum 1
</select>-->
<select id="getList" resultMap="dictResultMap">
select code, dict_key, dict_value, sort, remark from blade_dict where code = #{param1}
</select>
<select id="tree" resultMap="treeNodeResultMap">
select id, parent_id, dict_value as title, id as `value`, id as `key` from blade_dict where is_deleted = 0
select id, parent_id, dict_value as title, id as 'value', id as 'key' from blade_dict where is_deleted = 0
</select>
</mapper>

4
blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.xml

@ -38,7 +38,7 @@
</select>
<select id="tree" resultMap="treeNodeResultMap">
select id, parent_id, name as title, id as `value`, id as `key` from blade_menu where is_deleted = 0 and category = 1
select id, parent_id, name as title, id as 'value', id as 'key' from blade_menu where is_deleted = 0 and category = 1
</select>
<select id="allMenu" resultMap="menuResultMap">
@ -109,7 +109,7 @@
</select>
<select id="grantTree" resultMap="treeNodeResultMap">
select id, parent_id, name as title, id as `value`, id as `key` from blade_menu where is_deleted = 0
select id, parent_id, name as title, id as 'value', id as 'key' from blade_menu where is_deleted = 0
</select>
<select id="authRoutes" resultType="org.springblade.system.dto.MenuDTO">

2
blade-service/blade-system/src/main/java/org/springblade/system/mapper/RoleMapper.xml

@ -31,7 +31,7 @@
</select>
<select id="tree" resultMap="treeNodeResultMap">
select id, parent_id, role_name as title, id as `value`, id as `key` from blade_role where is_deleted = 0
select id, parent_id, role_name as title, id as 'value', id as 'key' from blade_role where is_deleted = 0
</select>
</mapper>

4
blade-service/blade-user/src/main/java/org/springblade/system/user/feign/UserClient.java

@ -36,8 +36,8 @@ public class UserClient implements IUserClient {
@Override
@GetMapping(API_PREFIX + "/user-info")
public R<UserInfo> userInfo(String account, String password) {
return R.data(service.userInfo(account, password));
public R<UserInfo> userInfo(String code, String account, String password) {
return R.data(service.userInfo(code, account, password));
}
}

3
blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserMapper.java

@ -41,11 +41,12 @@ public interface UserMapper extends BaseMapper<User> {
/**
* 获取用户
*
* @param code
* @param account
* @param password
* @return
*/
User getUser(String account, String password);
User getUser(String code, String account, String password);
/**
* 获取角色名

3
blade-service/blade-user/src/main/java/org/springblade/system/user/mapper/UserMapper.xml

@ -5,6 +5,7 @@
<!-- 通用查询映射结果 -->
<resultMap id="userResultMap" type="org.springblade.system.user.entity.User">
<result column="id" property="id"/>
<result column="tenant_code" property="tenantCode"/>
<result column="create_user" property="createUser"/>
<result column="create_time" property="createTime"/>
<result column="update_user" property="updateUser"/>
@ -45,7 +46,7 @@
FROM
blade_user
WHERE
account = #{param1} AND password = #{param2}
tenant_code = #{param1} and account = #{param2} AND password = #{param3}
</select>
<select id="getRoleName" resultType="java.lang.String">

3
blade-service/blade-user/src/main/java/org/springblade/system/user/service/IUserService.java

@ -43,11 +43,12 @@ public interface IUserService extends BaseService<User> {
/**
* 用户信息
*
* @param code
* @param account
* @param password
* @return
*/
UserInfo userInfo(String account, String password);
UserInfo userInfo(String code, String account, String password);
/**
* 给用户设置角色

4
blade-service/blade-user/src/main/java/org/springblade/system/user/service/impl/UserServiceImpl.java

@ -46,9 +46,9 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
}
@Override
public UserInfo userInfo(String account, String password) {
public UserInfo userInfo(String code, String account, String password) {
UserInfo userInfo = new UserInfo();
User user = baseMapper.getUser(account, password);
User user = baseMapper.getUser(code, account, password);
userInfo.setUser(user);
if (Func.isNotEmpty(user)) {
List<String> roleAlias = baseMapper.getRoleAlias(Func.toStrArray(user.getRoleId()));

5
blade-service/pom.xml

@ -29,6 +29,11 @@
<artifactId>blade-common</artifactId>
<version>${bladex.project.version}</version>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-starter-tenant</artifactId>
<version>${bladex.tool.version}</version>
</dependency>
</dependencies>
<build>

7
doc/nacos/blade.yaml

@ -65,3 +65,10 @@ management:
endpoint:
health:
show-details: always
# 租户表维护
blade:
tenant:
column: tenant_code
tables:
- blade_notice

1109
doc/sql/bladex-oracle.sql

File diff suppressed because it is too large Load Diff

47
doc/sql/bladex-saber-mysql.sql

File diff suppressed because one or more lines are too long

53
doc/sql/bladex-sword-mysql.sql

File diff suppressed because one or more lines are too long

22
doc/sql/bladex-tenant-mysql-update-RC5.sql

@ -0,0 +1,22 @@
ALTER TABLE `bladex`.`blade_notice`
ADD COLUMN `tenant_code` varchar(12) NULL DEFAULT '000000' COMMENT '租户编号' AFTER `id`;
ALTER TABLE `bladex`.`blade_dept`
ADD COLUMN `tenant_code` varchar(12) NULL DEFAULT '000000' COMMENT '租户编号' AFTER `id`;
ALTER TABLE `bladex`.`blade_dict`
ADD COLUMN `tenant_code` varchar(12) NULL DEFAULT '000000' COMMENT '租户编号' AFTER `id`;
ALTER TABLE `bladex`.`blade_menu`
ADD COLUMN `tenant_code` varchar(12) NULL DEFAULT '000000' COMMENT '租户编号' AFTER `id`;
ALTER TABLE `bladex`.`blade_role`
ADD COLUMN `tenant_code` varchar(12) NULL DEFAULT '000000' COMMENT '租户编号' AFTER `id`;
ALTER TABLE `bladex`.`blade_role_menu`
ADD COLUMN `tenant_code` varchar(12) NULL DEFAULT '000000' COMMENT '租户编号' AFTER `id`;
ALTER TABLE `bladex`.`blade_param`
ADD COLUMN `tenant_code` varchar(12) NULL DEFAULT '000000' COMMENT '租户编号' AFTER `id`;
ALTER TABLE `bladex`.`blade_user`
ADD COLUMN `tenant_code` varchar(12) NULL DEFAULT '000000' COMMENT '租户编号' AFTER `id`;
ALTER TABLE `bladex`.`blade_log_api`
ADD COLUMN `tenant_code` varchar(12) NULL DEFAULT '000000' COMMENT '租户编号' AFTER `id`;
ALTER TABLE `bladex`.`blade_log_error`
ADD COLUMN `tenant_code` varchar(12) NULL DEFAULT '000000' COMMENT '租户编号' AFTER `id`;
ALTER TABLE `bladex`.`blade_log_usual`
ADD COLUMN `tenant_code` varchar(12) NULL DEFAULT '000000' COMMENT '租户编号' AFTER `id`;
Loading…
Cancel
Save