从源更新
This commit is contained in:
@@ -28,8 +28,7 @@ public class TenantConfig {
|
||||
* description:
|
||||
* 实现多租户和无租户模式数据可以兼容在一个数据库中
|
||||
* 多租户模式:根据tenant_id=租户id来筛选个人数据
|
||||
* 无租户模式:根据tenant_id is null来筛选数据
|
||||
* mybatis-plus不支持多租户租户同时id为null的情况
|
||||
* 无租户模式:根据tenant_id=-1来筛选数据
|
||||
*/
|
||||
@Bean
|
||||
public PaginationInterceptor paginationInterceptor(HttpServletRequest request) {
|
||||
@@ -45,8 +44,8 @@ public class TenantConfig {
|
||||
//多租户模式,租户id从当前用户获取
|
||||
return new LongValue(Long.parseLong(tenantId.toString()));
|
||||
} else {
|
||||
//多租户模式,租户id为null
|
||||
return null;
|
||||
//无租户模式,租户id为-1
|
||||
return new LongValue(Long.valueOf(-1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,19 +56,11 @@ public class TenantConfig {
|
||||
|
||||
@Override
|
||||
public boolean doTableFilter(String tableName) {
|
||||
//获取开启状态
|
||||
Object mybatisPlusStatus = request.getSession().getAttribute("mybatisPlusStatus");
|
||||
if(mybatisPlusStatus !=null && mybatisPlusStatus.toString().equals("open")) {
|
||||
//从session中获取租户id
|
||||
// 这里可以判断是否过滤表
|
||||
if ("tbl_sequence".equals(tableName) || "dual".equals(tableName)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
//无租户模式
|
||||
// 这里可以判断是否过滤表
|
||||
if ("tbl_sequence".equals(tableName) || "dual".equals(tableName)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -80,19 +71,14 @@ public class TenantConfig {
|
||||
@Override
|
||||
public boolean doFilter(MetaObject metaObject) {
|
||||
MappedStatement ms = SqlParserHelper.getMappedStatement(metaObject);
|
||||
//获取开启状态
|
||||
Object mybatisPlusStatus = request.getSession().getAttribute("mybatisPlusStatus");
|
||||
if(mybatisPlusStatus !=null && mybatisPlusStatus.toString().equals("open")) {
|
||||
//多租户模式
|
||||
// 过滤自定义查询,此处跳过指定id的查询(不追加租户id过滤条件)
|
||||
if ("com.jsh.erp.datasource.mappers.UserMapperEx.getUserListByUserNameOrLoginName".equals(ms.getId())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
//无租户模式
|
||||
// 过滤自定义查询,此处跳过指定id的查询(不追加租户id过滤条件)
|
||||
if ("com.jsh.erp.datasource.mappers.UserMapperEx.getUserListByLoginName".equals(ms.getId())||
|
||||
"com.jsh.erp.datasource.mappers.UserMapperEx.getUserListByloginNameAndPassword".equals(ms.getId())||
|
||||
"com.jsh.erp.datasource.mappers.DepotItemMapperEx.getCurrentRepByMaterialIdAndDepotId".equals(ms.getId())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
});
|
||||
return paginationInterceptor;
|
||||
|
||||
@@ -101,7 +101,7 @@ public class UserController {
|
||||
default:
|
||||
try {
|
||||
//验证通过 ,可以登录,放入session,记录登录日志
|
||||
user = userService.getUserByUserName(username);
|
||||
user = userService.getUserListByloginNameAndPassword(username,password);
|
||||
// logService.create(new Logdetails(user, "登录系统", model.getClientIp(),
|
||||
// new Timestamp(System.currentTimeMillis()), (short) 0, "管理用户:" + username + " 登录系统", username + " 登录系统"));
|
||||
msgTip = "user can login";
|
||||
|
||||
@@ -32,9 +32,7 @@ public interface UserMapperEx {
|
||||
/**
|
||||
* 这个查询不添加租户id,保证登录名全局唯一
|
||||
* */
|
||||
@SqlParser(filter = true)
|
||||
List<User> getUserListByUserNameOrLoginName(@Param("userName") String userName,
|
||||
@Param("loginame") String loginame);
|
||||
List<User> getUserListByLoginName(@Param("loginame") String loginame);
|
||||
|
||||
int batDeleteOrUpdateUser(@Param("ids") String ids[], @Param("status") byte status);
|
||||
|
||||
@@ -44,4 +42,5 @@ public interface UserMapperEx {
|
||||
List<User> getUserListByUserNameAndTenantId(@Param("userName")String userName, @Param("tenantId")Long tenantId);
|
||||
|
||||
String addRegisterUserNotInclueUser(@Param("userId") Long userId,@Param("tenantId") Long tenantId,@Param("roleId") Long roleId);
|
||||
List<User> getUserListByloginNameAndPassword(@Param("loginame")String loginame, @Param("password")String password);
|
||||
}
|
||||
@@ -252,12 +252,10 @@ public class UserService {
|
||||
/**默认是可以登录的*/
|
||||
List<User> list = null;
|
||||
try {
|
||||
UserExample example = new UserExample();
|
||||
example.createCriteria().andLoginameEqualTo(username);
|
||||
list = userMapper.selectByExample(example);
|
||||
list=this.getUserListByloginName(username);
|
||||
} catch (Exception e) {
|
||||
logger.error("异常码[{}],异常提示[{}],异常[{}]",
|
||||
ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e);
|
||||
ExceptionConstants.DATA_READ_FAIL_CODE, ExceptionConstants.DATA_READ_FAIL_MSG,e);
|
||||
logger.error(">>>>>>>>访问验证用户姓名是否存在后台信息异常", e);
|
||||
return ExceptionCodeConstants.UserExceptionCode.USER_ACCESS_EXCEPTION;
|
||||
}
|
||||
@@ -265,17 +263,15 @@ public class UserService {
|
||||
if (null != list && list.size() == 0) {
|
||||
return ExceptionCodeConstants.UserExceptionCode.USER_NOT_EXIST;
|
||||
}
|
||||
|
||||
User user=null;
|
||||
try {
|
||||
UserExample example = new UserExample();
|
||||
example.createCriteria().andLoginameEqualTo(username).andPasswordEqualTo(password);
|
||||
list = userMapper.selectByExample(example);
|
||||
user = this.getUserListByloginNameAndPassword(username,password);
|
||||
} catch (Exception e) {
|
||||
logger.error(">>>>>>>>>>访问验证用户密码后台信息异常", e);
|
||||
return ExceptionCodeConstants.UserExceptionCode.USER_ACCESS_EXCEPTION;
|
||||
}
|
||||
|
||||
if (null != list && list.size() == 0) {
|
||||
if (null == user ) {
|
||||
return ExceptionCodeConstants.UserExceptionCode.USER_PASSWORD_ERROR;
|
||||
}
|
||||
return ExceptionCodeConstants.UserExceptionCode.USER_CONDITION_FIT;
|
||||
@@ -663,15 +659,33 @@ public class UserService {
|
||||
public List<User> getUserListByloginName(String loginName){
|
||||
List<User> list =null;
|
||||
try{
|
||||
list=userMapperEx.getUserListByUserNameOrLoginName(null,loginName);
|
||||
list=userMapperEx.getUserListByLoginName(loginName);
|
||||
}catch(Exception e){
|
||||
logger.error("异常码[{}],异常提示[{}],异常[{}]",
|
||||
ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e);
|
||||
ExceptionConstants.DATA_READ_FAIL_CODE, ExceptionConstants.DATA_READ_FAIL_MSG,e);
|
||||
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
|
||||
ExceptionConstants.DATA_READ_FAIL_MSG);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
/**
|
||||
* 通过登录名和密码获取用户列表
|
||||
* */
|
||||
public User getUserListByloginNameAndPassword(String loginName,String password){
|
||||
List<User> list =null;
|
||||
try{
|
||||
list=userMapperEx.getUserListByloginNameAndPassword(loginName,password);
|
||||
}catch(Exception e){
|
||||
logger.error("异常码[{}],异常提示[{}],异常[{}]",
|
||||
ExceptionConstants.DATA_READ_FAIL_CODE, ExceptionConstants.DATA_READ_FAIL_MSG,e);
|
||||
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
|
||||
ExceptionConstants.DATA_READ_FAIL_MSG);
|
||||
}
|
||||
if(list!=null&&list.size()>0){
|
||||
return list.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 批量删除用户
|
||||
* */
|
||||
|
||||
Reference in New Issue
Block a user