Browse Source

优化:公众用户session不再失效

4.0
FLYPHT 2 years ago
parent
commit
d254a9df68
4 changed files with 17 additions and 3 deletions
  1. +1
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginHelper.java
  2. +7
    -0
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java
  3. +6
    -3
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/session/SessionManager.java
  4. +3
    -0
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/session/UserSession.java

+ 1
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginHelper.java View File

@@ -83,6 +83,7 @@ public class LoginHelper {
UserParty up = ups.iterator().next(); UserParty up = ups.iterator().next();
us.setPartyId(up.getPartyId()); us.setPartyId(up.getPartyId());
us.setDeptId(up.getDeptId()); us.setDeptId(up.getDeptId());
us.setUserLevel(user.getLevel());
} }
return us; return us;
} }


+ 7
- 0
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java View File

@@ -379,4 +379,11 @@ public interface SwEnum {
public static IntEnumBean LOCK = instance.addEnum(2, "已锁定"); public static IntEnumBean LOCK = instance.addEnum(2, "已锁定");
public static IntEnumBean STOP = instance.addEnum(9, "已停用"); public static IntEnumBean STOP = instance.addEnum(9, "已停用");
} }
// 用户等级
class UserLevel extends IntEnum {
public static UserLevel instance = new UserLevel();
public static IntEnumBean inner = instance.addEnum(102100, "内部用户");
public static IntEnumBean outer = instance.addEnum(102101, "外部用户");
public static IntEnumBean pub = instance.addEnum(102102, "公众用户");
}
} }

+ 6
- 3
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/session/SessionManager.java View File

@@ -2,6 +2,7 @@ package cc.smtweb.framework.core.session;


import cc.smtweb.framework.core.cache.redis.RedisBroadcastEvent; import cc.smtweb.framework.core.cache.redis.RedisBroadcastEvent;
import cc.smtweb.framework.core.cache.redis.RedisManager; import cc.smtweb.framework.core.cache.redis.RedisManager;
import cc.smtweb.framework.core.common.SwEnum;
import cc.smtweb.framework.core.db.jdbc.IdGenerator; import cc.smtweb.framework.core.db.jdbc.IdGenerator;
import cc.smtweb.framework.core.mvc.controller.IEditor; import cc.smtweb.framework.core.mvc.controller.IEditor;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -23,9 +24,11 @@ public class SessionManager {
public String login(UserSession userSession) { public String login(UserSession userSession) {
if (userSession != null) { if (userSession != null) {
String sid = RedisManager.PREFIX_SESSION + Long.toHexString(idGenerator.nextId()) + "_" + Integer.toHexString(new Random().nextInt()); String sid = RedisManager.PREFIX_SESSION + Long.toHexString(idGenerator.nextId()) + "_" + Integer.toHexString(new Random().nextInt());

redisManager.set(sid, userSession, RedisManager.SESSION_EXPIRE_SEC);

if(userSession.getUserLevel() == SwEnum.UserLevel.pub.value){
redisManager.set(sid, userSession, 0);
}else {
redisManager.set(sid, userSession, RedisManager.SESSION_EXPIRE_SEC);
}
return sid; return sid;
} }




+ 3
- 0
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/session/UserSession.java View File

@@ -1,6 +1,7 @@
package cc.smtweb.framework.core.session; package cc.smtweb.framework.core.session;


import cc.smtweb.framework.core.common.SwConsts; import cc.smtweb.framework.core.common.SwConsts;
import cc.smtweb.framework.core.common.SwEnum;
import cc.smtweb.framework.core.util.IpAddrUtil; import cc.smtweb.framework.core.util.IpAddrUtil;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@@ -28,6 +29,8 @@ public class UserSession implements Serializable {
private String loginIp; private String loginIp;
// 用户ID // 用户ID
private long userId; private long userId;
// 用户等级
private long userLevel = SwEnum.UserLevel.inner.value;
// 当前机构ID // 当前机构ID
private long partyId; private long partyId;
// 当前部门 // 当前部门


Loading…
Cancel
Save