Browse Source

用户锁定踢出用户优化

anderx 4 years ago
parent
commit
bc61bb3b8f

+ 7 - 5
src/main/java/com/goafanti/admin/controller/AdminSuperviserApiController.java

@@ -1,14 +1,14 @@
 package com.goafanti.admin.controller;
 
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.List;
-import java.util.UUID;
+import java.util.*;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 
 import com.goafanti.common.utils.RedisUtil;
+import org.apache.shiro.SecurityUtils;
 import org.springframework.beans.BeanUtils;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.types.RedisClientInfo;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -42,6 +42,8 @@ public class AdminSuperviserApiController extends CertifyApiController {
 	private AdminLocationService	adminLocationService;
 	@Resource
 	private RedisUtil redisUtil;
+	@Resource
+	private RedisTemplate  redisTemplate;
 
 	/**管理员列表*/
 	@RequestMapping(value = "/adminList", method = RequestMethod.GET)
@@ -160,7 +162,7 @@ public class AdminSuperviserApiController extends CertifyApiController {
 			}
 			//如果锁定,清楚登陆者的token
 			if (!aa.getStatus().equals(ad.getStatus())&&!ad.getStatus().equals("正常")){
-				redisUtil.deleteString("SHIRO_SESSION:"+aa.getToken());
+				redisUtil.deleteAid(aa.getId());
 			}
 		res.setData(newAdminService.updateByPrimaryKeySelective(ad, roles));
 		}

+ 4 - 15
src/main/java/com/goafanti/common/mapper/AdminMapper.xml

@@ -24,12 +24,11 @@
     <result column="open_id" jdbcType="VARCHAR" property="openId" />
     <result column="type" jdbcType="INTEGER" property="type" />
     <result column="reviewer" jdbcType="VARCHAR" property="reviewer" />
-    <result column="token" jdbcType="VARCHAR" property="token" />
   </resultMap>
   <sql id="Base_Column_List">
     id, mobile, `name`, `password`, email, create_time, `number`, province, `position`,
     superior_id, city, department_id, `status`, user_no, duty, district, head_portrait_url,
-    contact_mobile, last_login_time, open_id, `type`, reviewer, token
+    contact_mobile, last_login_time, open_id, `type`, reviewer
   </sql>
   <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
     select
@@ -49,7 +48,7 @@
       `status`, user_no, duty,
       district, head_portrait_url, contact_mobile,
       last_login_time, open_id, `type`,
-      reviewer, token)
+      reviewer)
     values (#{id,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
       #{password,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
       #{number,jdbcType=INTEGER}, #{province,jdbcType=VARCHAR}, #{position,jdbcType=VARCHAR},
@@ -57,7 +56,7 @@
       #{status,jdbcType=VARCHAR}, #{userNo,jdbcType=VARCHAR}, #{duty,jdbcType=VARCHAR},
       #{district,jdbcType=VARCHAR}, #{headPortraitUrl,jdbcType=VARCHAR}, #{contactMobile,jdbcType=VARCHAR},
       #{lastLoginTime,jdbcType=TIMESTAMP}, #{openId,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER},
-      #{reviewer,jdbcType=VARCHAR}, #{token,jdbcType=VARCHAR})
+      #{reviewer,jdbcType=VARCHAR})
   </insert>
   <insert id="insertSelective" parameterType="com.goafanti.common.model.Admin">
     insert into admin
@@ -128,9 +127,6 @@
       <if test="reviewer != null">
         reviewer,
       </if>
-      <if test="token != null">
-        token,
-      </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides=",">
       <if test="id != null">
@@ -199,9 +195,6 @@
       <if test="reviewer != null">
         #{reviewer,jdbcType=VARCHAR},
       </if>
-      <if test="token != null">
-        #{token,jdbcType=VARCHAR},
-      </if>
     </trim>
   </insert>
   <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.Admin">
@@ -270,9 +263,6 @@
       <if test="reviewer != null">
         reviewer = #{reviewer,jdbcType=VARCHAR},
       </if>
-      <if test="token != null">
-        token = #{token,jdbcType=VARCHAR},
-      </if>
     </set>
     where id = #{id,jdbcType=VARCHAR}
   </update>
@@ -298,8 +288,7 @@
       last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP},
       open_id = #{openId,jdbcType=VARCHAR},
       `type` = #{type,jdbcType=INTEGER},
-      reviewer = #{reviewer,jdbcType=VARCHAR},
-      token = #{token,jdbcType=VARCHAR}
+      reviewer = #{reviewer,jdbcType=VARCHAR}
     where id = #{id,jdbcType=VARCHAR}
   </update>
 

+ 0 - 9
src/main/java/com/goafanti/common/model/Admin.java

@@ -117,7 +117,6 @@ public class Admin extends BaseModel implements AftUser {
      */
     private String reviewer;
 
-    private String token;
     /**
      * 上级管理用户名称
      */
@@ -329,12 +328,4 @@ public class Admin extends BaseModel implements AftUser {
     public void setReviewer(String reviewer) {
         this.reviewer = reviewer;
     }
-
-    public String getToken() {
-        return token;
-    }
-
-    public void setToken(String token) {
-        this.token = token;
-    }
 }

+ 21 - 0
src/main/java/com/goafanti/common/utils/RedisUtil.java

@@ -40,6 +40,7 @@ public class RedisUtil {
 	private  JedisPool pool;//创建代理对象
 
 
+	public static String SHIRO_SESSION="SHIRO_SESSION:";
 
 //	 /**
 //     * 初始化Redis连接池
@@ -180,6 +181,25 @@ public class RedisUtil {
 			}
 		}
 
+
+	public void deleteAid(String id) {
+		Jedis jedis = pool.getResource();
+		String str=new String();
+		try {
+			Set<String> set=jedis.keys(SHIRO_SESSION+"*");
+			for (String s : set) {
+				String value=getString(s);
+				LoggerUtils.debug(this.getClass(),"获得值{%s}",value);
+				if (value.contains(id)){
+					deleteString(s);
+					LoggerUtils.debug(this.getClass(),"清除缓存token{%s}",id);
+				}
+			}
+		} finally {
+			jedis.close();
+		}
+	}
+
 		public String getString(String key) {
 			Jedis jedis = pool.getResource();
 			String str=new String();
@@ -202,6 +222,7 @@ public class RedisUtil {
 			jedis.close();
 		}
 	}
+
 }