yeshijie 7 سال پیش
والد
کامیت
00216b3771

+ 16 - 12
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/SystemDataRedis.java

@ -1,7 +1,7 @@
package com.yihu.wlyy.util;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.entity.security.Token;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Set;
/**
@ -22,6 +23,8 @@ public class SystemDataRedis {
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private ObjectMapper objectMapper;
    /**
     * tokenTypeName
@ -37,7 +40,7 @@ public class SystemDataRedis {
     * 设置医生缓存
     * @param token
     */
    public String setDoctorToken(Token token){
    public String setDoctorToken(Token token) throws Exception{
        return setToken(doctorTokens,token);
    }
@ -45,7 +48,7 @@ public class SystemDataRedis {
     * 设置pc端缓存
     * @param token
     */
    public String setDoctorPCToken(Token token){
    public String setDoctorPCToken(Token token) throws Exception{
       return setToken(doctorPCTokens,token);
    }
@ -53,7 +56,7 @@ public class SystemDataRedis {
     * 设置居民缓存
     * @param token
     */
    public String setPatientToken(Token token){
    public String setPatientToken(Token token) throws Exception{
        return setToken(patientTokens,token);
    }
@ -61,7 +64,7 @@ public class SystemDataRedis {
     *  设置医生微信缓存
     * @param token
     */
    public String setDoctorWXToken(Token token){
    public String setDoctorWXToken(Token token) throws Exception{
        return setToken(doctorWXTokens,token);
    }
//====设置token==end===
@ -88,12 +91,12 @@ public class SystemDataRedis {
     * @param tokenTypeName
     * @param token
     */
    public String setToken(String tokenTypeName,Token token){
    public String setToken(String tokenTypeName,Token token) throws Exception{
        JSONObject json = JSONObject.fromObject(token);
        String tokenStr = objectMapper.writeValueAsString(token);
        String key = "token:"+tokenTypeName+":"+token.getUser();
        redisTemplate.opsForValue().set(key,json.toString());
        return json.toString();
        redisTemplate.opsForValue().set(key,tokenStr);
        return tokenStr;
    }
    /**
@ -105,9 +108,10 @@ public class SystemDataRedis {
    public Token getToken(String tokenTypeName,String uid) {
        try{
            //获取token
            String tokenJosn = redisTemplate.opsForValue().get("token:" + tokenTypeName + ":" + uid);
            if(StringUtils.isNotBlank(tokenJosn)){
                Token token = (Token)JSONObject.toBean(JSONObject.fromObject(tokenJosn),Token.class);
            String tokenJson = redisTemplate.opsForValue().get("token:" + tokenTypeName + ":" + uid);
            if(StringUtils.isNotBlank(tokenJson)){
                objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
                Token token = objectMapper.readValue(tokenJson, Token.class);
                return token;
            }
            return null;

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/account/LoginController.java

@ -565,7 +565,7 @@ public class LoginController extends BaseController {
    @RequestMapping(value = "setTokenTest", method = RequestMethod.POST)
    @ResponseBody
    public String setToken(String uid){
    public String setToken(String uid) throws Exception{
        Token token = new Token();
        token.setToken("123456");
        token.setDel("1");