给租户增加有效期

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

@ -833,7 +833,7 @@ CREATE TABLE `jsh_tenant` (
`tenant_id` bigint(20) DEFAULT NULL COMMENT '用户id',
`login_name` varchar(255) DEFAULT NULL COMMENT '登录名',
`user_num_limit` int(11) DEFAULT NULL COMMENT '用户数量限制',
`type` varchar(1) DEFAULT '0' COMMENT '租户类型0免费用户1付费用',
`type` varchar(1) DEFAULT '0' COMMENT '租户类型0免费租户1付费租',
`enabled` bit(1) DEFAULT b'1' COMMENT '启用 0-禁用 1-启用',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`expire_time` datetime DEFAULT NULL COMMENT '到期时间',
@ -843,7 +843,7 @@ CREATE TABLE `jsh_tenant` (
-- ----------------------------
-- Records of jsh_tenant
-- ----------------------------
INSERT INTO `jsh_tenant` VALUES ('13', '63', 'jsh', '20', '0', '', '2021-02-17 23:19:17', '2099-02-17 23:19:17');
INSERT INTO `jsh_tenant` VALUES ('13', '63', 'jsh', '2000', '1', '', '2021-02-17 23:19:17', '2099-02-17 23:19:17');
-- ----------------------------
-- Table structure for jsh_unit

View File

@ -1198,6 +1198,6 @@ INSERT INTO `jsh_function` VALUES ('248', '030150', '调拨明细', '0301', '/re
-- 给租户表加sku字段
-- 给租户表移除单据数量限制字段
-- --------------------------------------------------------
alter table jsh_tenant add type varchar(1) DEFAULT '0' COMMENT '租户类型0免费用户1付费用户' after bills_num_limit;
alter table jsh_tenant add type varchar(1) DEFAULT '0' COMMENT '租户类型0免费租户1付费租户' after bills_num_limit;
alter table jsh_tenant drop column bills_num_limit;
alter table jsh_tenant add expire_time datetime DEFAULT NULL COMMENT '到期时间' after create_time;

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

View File

@ -18,6 +18,8 @@ spring.redis.password=1234abcd
manage.roleId=10
#租户允许创建的用户数
tenant.userNumLimit=1000000
#租户允许试用的天数
tenant.tryDayLimit=3000
#演示模式开关-默认关闭:false
demonstrate.open=false
#插件配置

View File

@ -13,6 +13,12 @@
<bind name="bindLoginName" value="'%'+loginName+'%'"/>
and login_name like #{bindLoginName}
</if>
<if test="type != null and type != ''">
and type = #{type}
</if>
<if test="enabled != null and enabled != ''">
and enabled = #{enabled}
</if>
order by id desc
<if test="offset != null and rows != null">
limit #{offset},#{rows}
@ -27,5 +33,11 @@
<bind name="bindLoginName" value="'%'+loginName+'%'"/>
and login_name like #{bindLoginName}
</if>
<if test="type != null and type != ''">
and type = #{type}
</if>
<if test="enabled != null and enabled != ''">
and enabled = #{enabled}
</if>
</select>
</mapper>