给租户增加有效期

This commit is contained in:
季圣华
2021-08-25 00:44:05 +08:00
parent ce1ca8beed
commit be9786087f
12 changed files with 91 additions and 24 deletions

View File

@@ -110,6 +110,9 @@ public class UserController {
case ExceptionCodeConstants.UserExceptionCode.BLACK_TENANT:
msgTip = "tenant is black";
break;
case ExceptionCodeConstants.UserExceptionCode.EXPIRE_TENANT:
msgTip = "tenant is expire";
break;
case ExceptionCodeConstants.UserExceptionCode.USER_CONDITION_FIT:
msgTip = "user can login";
//验证通过 可以登录放入session记录登录日志
@@ -428,4 +431,33 @@ public class UserController {
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
/**
* 获取当前用户的用户数量和租户信息
* @param request
* @return
*/
@GetMapping(value = "/infoWithTenant")
public BaseResponseInfo randomImage(HttpServletRequest request){
BaseResponseInfo res = new BaseResponseInfo();
try {
Map<String, Object> data = new HashMap<>();
Long userId = Long.parseLong(redisService.getObjectFromSessionByKey(request,"userId").toString());
User user = userService.getUser(userId);
//获取当前用户数
Long userCurrentNum = userService.countUser(null, null);
Tenant tenant = tenantService.getTenantByTenantId(user.getTenantId());
data.put("type", tenant.getType()); //租户类型0免费租户1付费租户
data.put("expireTime", Tools.parseDateToStr(tenant.getExpireTime()));
data.put("userCurrentNum", userCurrentNum);
data.put("userNumLimit", tenant.getUserNumLimit());
res.code = 200;
res.data = data;
} catch (Exception e) {
e.printStackTrace();
res.code = 500;
res.data = "获取失败";
}
return res;
}
}

View File

@@ -22,8 +22,6 @@ public class UserEx extends User{
private String userType;
private String userNumLimit;
public String getOrgAbr() {
return orgAbr;
}
@@ -79,12 +77,4 @@ public class UserEx extends User{
public void setUserType(String userType) {
this.userType = userType;
}
public String getUserNumLimit() {
return userNumLimit;
}
public void setUserNumLimit(String userNumLimit) {
this.userNumLimit = userNumLimit;
}
}

View File

@@ -10,9 +10,13 @@ public interface TenantMapperEx {
List<TenantEx> selectByConditionTenant(
@Param("loginName") String loginName,
@Param("type") String type,
@Param("enabled") String enabled,
@Param("offset") Integer offset,
@Param("rows") Integer rows);
Long countsByTenant(
@Param("loginName") String loginName);
@Param("loginName") String loginName,
@Param("type") String type,
@Param("enabled") String enabled);
}

View File

@@ -34,14 +34,18 @@ public class TenantComponent implements ICommonQuery {
private List<?> getTenantList(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String loginName = StringUtil.getInfo(search, "loginName");
return tenantService.select(loginName, QueryUtils.offset(map), QueryUtils.rows(map));
String type = StringUtil.getInfo(search, "type");
String enabled = StringUtil.getInfo(search, "enabled");
return tenantService.select(loginName, type, enabled, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String loginName = StringUtil.getInfo(search, "loginName");
return tenantService.countTenant(loginName);
String type = StringUtil.getInfo(search, "type");
String enabled = StringUtil.getInfo(search, "enabled");
return tenantService.countTenant(loginName, type, enabled);
}
@Override

View File

@@ -39,6 +39,9 @@ public class TenantService {
@Value("${tenant.userNumLimit}")
private Integer userNumLimit;
@Value("${tenant.tryDayLimit}")
private Integer tryDayLimit;
public Tenant getTenant(long id)throws Exception {
Tenant result=null;
try{
@@ -60,10 +63,10 @@ public class TenantService {
return list;
}
public List<TenantEx> select(String loginName, int offset, int rows)throws Exception {
public List<TenantEx> select(String loginName, String type, String enabled, int offset, int rows)throws Exception {
List<TenantEx> list= new ArrayList<>();
try{
list = tenantMapperEx.selectByConditionTenant(loginName, offset, rows);
list = tenantMapperEx.selectByConditionTenant(loginName, type, enabled, offset, rows);
if (null != list) {
for (TenantEx tenantEx : list) {
tenantEx.setCreateTimeStr(Tools.getCenternTime(tenantEx.getCreateTime()));
@@ -76,10 +79,10 @@ public class TenantService {
return list;
}
public Long countTenant(String loginName)throws Exception {
public Long countTenant(String loginName, String type, String enabled)throws Exception {
Long result=null;
try{
result=tenantMapperEx.countsByTenant(loginName);
result=tenantMapperEx.countsByTenant(loginName, type, enabled);
}catch(Exception e){
JshException.readFail(logger, e);
}
@@ -91,10 +94,13 @@ public class TenantService {
Tenant tenant = JSONObject.parseObject(obj.toJSONString(), Tenant.class);
int result=0;
try{
tenant.setCreateTime(new Date());
if(tenant.getUserNumLimit()==null) {
tenant.setUserNumLimit(userNumLimit); //默认用户限制数量
}
tenant.setCreateTime(new Date());
if(tenant.getExpireTime()==null) {
tenant.setExpireTime(Tools.addDays(new Date(), tryDayLimit)); //租户允许试用的天数
}
result=tenantMapper.insertSelective(tenant);
}catch(Exception e){
JshException.writeFail(logger, e);

View File

@@ -297,8 +297,13 @@ public class UserService {
}
Long tenantId = list.get(0).getTenantId();
Tenant tenant = tenantService.getTenantByTenantId(tenantId);
if(tenant!=null && tenant.getEnabled()!=null && !tenant.getEnabled()) {
return ExceptionCodeConstants.UserExceptionCode.BLACK_TENANT;
if(tenant!=null) {
if(tenant.getEnabled()!=null && !tenant.getEnabled()) {
return ExceptionCodeConstants.UserExceptionCode.BLACK_TENANT;
}
if(tenant.getExpireTime()!=null && tenant.getExpireTime().getTime()<System.currentTimeMillis()){
return ExceptionCodeConstants.UserExceptionCode.EXPIRE_TENANT;
}
}
}
} catch (Exception e) {
@@ -516,7 +521,6 @@ public class UserService {
JSONObject tenantObj = new JSONObject();
tenantObj.put("tenantId", ue.getId());
tenantObj.put("loginName",ue.getLoginName());
tenantObj.put("userNumLimit",ue.getUserNumLimit());
tenantService.insertTenant(tenantObj, request);
logger.info("===============创建租户信息完成===============");
if (result > 0) {

View File

@@ -34,5 +34,10 @@ public interface ExceptionCodeConstants {
* 租户被加入黑名单
*/
public static final int BLACK_TENANT = 6;
/**
* 租户已经过期
*/
public static final int EXPIRE_TENANT = 7;
}
}

View File

@@ -665,6 +665,14 @@ public class Tools {
return new SimpleDateFormat(pattern).parse(strDate);
}
public static Date addDays(Date date, int num) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date); //需要将date数据转移到Calender对象中操作
calendar.add(calendar.DATE, num);//把日期往后增加n天.正数往后推,负数往前移动
date=calendar.getTime(); //这个时间就是日期往后推一天的结果
return date;
}
/**
* 生成随机数字和字母组合
* @param length