新增:
1.用户登录时判断租户是否过期,在登录时赋予 token有效期为当前租户到期时间和当前日期的差值; 2.实现租户名查 租户 Id 接口
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package com.yupi.springbootinit.service;
|
||||
|
||||
import com.yupi.springbootinit.common.BaseResponse;
|
||||
import com.yupi.springbootinit.model.entity.SystemTenant;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/6/20 14:50
|
||||
*/
|
||||
|
||||
public interface SystemTenantService extends IService<SystemTenant>{
|
||||
|
||||
|
||||
Long getTenantIdByName(String name);
|
||||
}
|
||||
@@ -10,7 +10,11 @@ import com.yupi.springbootinit.model.entity.SystemUsers;
|
||||
|
||||
public interface SystemUsersService extends IService<SystemUsers> {
|
||||
|
||||
SystemUsers getUserByUserName(String username);
|
||||
SystemUsers getUserByUserName(String username,Long tenantId);
|
||||
|
||||
boolean isPasswordMatch(String rawPassWord, String encodedPassword);
|
||||
|
||||
boolean isExpired(Long tendId);
|
||||
|
||||
Long getTenantExpiredTime(Long tenantId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.yupi.springbootinit.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.yupi.springbootinit.common.BaseResponse;
|
||||
import com.yupi.springbootinit.common.ErrorCode;
|
||||
import com.yupi.springbootinit.exception.BusinessException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yupi.springbootinit.model.entity.SystemTenant;
|
||||
import com.yupi.springbootinit.mapper.SystemTenantMapper;
|
||||
import com.yupi.springbootinit.service.SystemTenantService;
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/6/20 14:50
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class SystemTenantServiceImpl extends ServiceImpl<SystemTenantMapper, SystemTenant> implements SystemTenantService{
|
||||
|
||||
@Override
|
||||
public Long getTenantIdByName(String name) {
|
||||
QueryWrapper<SystemTenant> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("name",name);
|
||||
SystemTenant systemTenant = baseMapper.selectOne(queryWrapper);
|
||||
if (systemTenant == null){
|
||||
throw new BusinessException(ErrorCode.TENANT_NAME_NOT_EXISTS);
|
||||
}
|
||||
return systemTenant.getId();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
package com.yupi.springbootinit.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yupi.springbootinit.mapper.SystemTenantMapper;
|
||||
import com.yupi.springbootinit.model.entity.SystemTenant;
|
||||
import com.yupi.springbootinit.model.entity.SystemUsers;
|
||||
import com.yupi.springbootinit.service.SystemTenantService;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -24,10 +29,14 @@ public class SystemUsersServiceImpl extends ServiceImpl<SystemUsersMapper,System
|
||||
@Value("${md5.salt}")
|
||||
private String MD5_SALT;
|
||||
|
||||
@Resource
|
||||
private SystemTenantMapper systemTenantMapper;
|
||||
|
||||
@Override
|
||||
public SystemUsers getUserByUserName(String username) {
|
||||
public SystemUsers getUserByUserName(String username,Long tenantId) {
|
||||
QueryWrapper <SystemUsers> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("username",username);
|
||||
queryWrapper.eq("tenant_id",tenantId);
|
||||
return baseMapper.selectOne(queryWrapper);
|
||||
}
|
||||
|
||||
@@ -36,4 +45,22 @@ public class SystemUsersServiceImpl extends ServiceImpl<SystemUsersMapper,System
|
||||
String s = SecureUtil.md5(MD5_SALT + rawPassword);
|
||||
return s.equals(encodedPassword);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExpired(Long tendId) {
|
||||
SystemTenant systemTenant = systemTenantMapper.selectById(tendId);
|
||||
long between = DateUtil.between(systemTenant.getExpireTime(), DateUtil.date(), DateUnit.DAY);
|
||||
return between < 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getTenantExpiredTime(Long tenantId) {
|
||||
SystemTenant systemTenant = systemTenantMapper.selectById(tenantId);
|
||||
long between = DateUtil.between(systemTenant.getExpireTime(), DateUtil.date(), DateUnit.SECOND);
|
||||
if (between > 0 ) {
|
||||
return between;
|
||||
}
|
||||
return 0L;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user