Parcourir la source

登录缓存存储Redis

trick9191 il y a 7 ans
Parent
commit
36fcb6af8d

+ 10 - 5
common/common-entity/pom.xml

@ -64,11 +64,16 @@
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
        </dependency>
 <!--       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
            <version>1.3.5.RELEASE</version>
        </dependency>-->
        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.4</version>
        </dependency>
        <!--       <dependency>
                   <groupId>org.springframework.boot</groupId>
                   <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
                   <version>1.3.5.RELEASE</version>
               </dependency>-->
    </dependencies>
</project>

+ 10 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/patient/PatientAimSports.java

@ -20,6 +20,7 @@ public class PatientAimSports extends IdEntity {
    private Integer dailyStepCount;     //运动步数
    private String bmiMax;              //bmi标准上限
    private String bmiMin;              //bmi标准下线
    private String createDate;      //上传日期
    private Date createTime;       //创建时间
@ -84,4 +85,13 @@ public class PatientAimSports extends IdEntity {
        this.createTime = createTime;
    }
    @Basic
    @Column(name = "create_date")
    public String getCreateDate() {
        return createDate;
    }
    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }
}

+ 6 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/security/Token.java

@ -2,6 +2,7 @@ package com.yihu.wlyy.entity.security;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.wlyy.entity.IdEntity;
import net.sf.json.JSONObject;
import javax.persistence.Entity;
import javax.persistence.Table;
@ -78,4 +79,9 @@ public class Token extends IdEntity {
		this.del = del;
	}
	public String toJson(){
		JSONObject jsonObject = JSONObject.fromObject(this);
		return jsonObject.toString();
	}
}

+ 11 - 4
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/interceptors/PatientInterceptor.java

@ -5,10 +5,12 @@ import com.yihu.wlyy.logs.InterfaceCallLogs;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.SystemConf;
import com.yihu.wlyy.util.SystemData;
import com.yihu.wlyy.util.SystemDataRedis;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
@ -29,6 +31,8 @@ import java.util.Date;
public class PatientInterceptor extends BaseInterceptor {
    private Logger logger = LoggerFactory.getLogger(PatientInterceptor.class);
    @Autowired
    private SystemDataRedis systemDataRedis;
    public static String status = "1";
@ -67,16 +71,18 @@ public class PatientInterceptor extends BaseInterceptor {
            if (StringUtils.isEmpty(imei)) {
                imei = openid;
            }
            //1.5.0 获取token redis
            Token token = null;
            if (platform == 3) {
                token = SystemData.patientTokens.get(user);
                token = systemDataRedis.getPatientToken(user);
//                token = SystemData.patientTokens.get(user);
            }
            if (token == null) {
                token = tokenDao.findByPatient(user, platform);
                // 加入缓存
                if (platform == 3) {
                    SystemData.patientTokens.put(user, token);
                    systemDataRedis.setPatientToken(token);
                    //SystemData.patientTokens.put(user, token);
                }
            }
            if (token == null || StringUtils.isEmpty(tokenStr) || (token.getPlatform() != 1 && token.getPlatform() != 3)) {
@ -95,7 +101,8 @@ public class PatientInterceptor extends BaseInterceptor {
                        token.setCzrq(new Date());
                        // 更新内存
                        if (platform == 3) {
                            SystemData.patientTokens.put(user, token);
                            systemDataRedis.setPatientToken(token);
                            //SystemData.patientTokens.put(user, token);
                        }
                        // 更新数据库
                        tokenDao.save(token);

+ 6 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/common/account/PatientService.java

@ -121,9 +121,11 @@ public class PatientService extends TokenService {
            for (Token token : tokens) {
                i++;
                Patient p = patientDao.findByCode(token.getUser());
                //1.5.0 redis token
                if (p == null || i <= last) {
                    tokenDao.delete(token);
                    SystemData.patientTokens.remove(token.getUser());
                    systemDataRedis.delToken(SystemDataRedis.patientTokens,token.getUser());
                    //SystemData.patientTokens.remove(token.getUser());
                    continue;
                }
//                p.setOpenid("");
@ -131,7 +133,9 @@ public class PatientService extends TokenService {
                signFamilyDao.updateOpenidByPatient("", p.getCode());
                patientDao.save(p);
                tokenDao.delete(token);
                SystemData.patientTokens.remove(p.getCode());
                systemDataRedis.delToken(SystemDataRedis.patientTokens,token.getUser());
//                SystemData.patientTokens.remove(p.getCode());
                break;
            }
        }

+ 3 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/common/account/TokenService.java

@ -97,8 +97,10 @@ public class TokenService extends BaseService {
		if (token == null) {
			throw new Exception("Token生成失败");
		}
		//1.5.0 redis token
		// 更新token缓存
		SystemData.patientTokens.put(user, token);
		//SystemData.patientTokens.put(user, token);
		systemDataRedis.setPatientToken(token);
		return token;
	}

+ 10 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/SystemDataRedis.java

@ -6,6 +6,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import java.util.Set;
/**
 * Created by Trick on 2018/8/20.
 * 1.5.0 版本 将token 存储在redis
@ -111,4 +113,12 @@ public class SystemDataRedis {
        String key = "token:"+tokenTypeName+":"+uid;
        redisTemplate.delete(key);
    }
    public int getTokenMember(String tokenTypeName){
        Set set =  redisTemplate.keys("token:" + tokenTypeName);
        if(set!=null&&set.size()>0){
            return set.size();
        }
        return 0;
    }
}

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

@ -438,13 +438,15 @@ public class LoginController extends BaseController {
                // response.getWriter().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!"));
                return error(-1, "系统异常,操作失败");
            }
            Token token = SystemData.doctorTokens.get(uid);
            //1.5.0 存储redis缓存
            Token token = systemDataRedis.getDoctorToken(uid);
            //Token token = SystemData.doctorTokens.get(uid);
            if (token == null) {
                token = tokenDao.findByToken(tokenStr);
                if (token != null) {
                    // 加入缓存
                    SystemData.doctorTokens.put(uid, token);
                    systemDataRedis.setDoctorToken(token);
                    //SystemData.doctorTokens.put(uid, token);
                }
            }
            if (token == null || token.getPlatform() != 2) {
@ -466,7 +468,8 @@ public class LoginController extends BaseController {
                        // 今天未更新,则更新缓存
                        token.setCzrq(new Date());
                        // 更新内存
                        SystemData.doctorTokens.put(uid, token);
                        systemDataRedis.setDoctorToken(token);
                        //SystemData.doctorTokens.put(uid, token);
                        // 更新数据库
                        tokenDao.save(token);
                    }
@ -577,4 +580,10 @@ public class LoginController extends BaseController {
        return write(200,systemDataRedis.getDoctorPCToken(uid).toJson());
    }
    @RequestMapping(value = "getTokenNumberTest", method = RequestMethod.POST)
    @ResponseBody
    public String getTokenNumber(){
        return write(200,systemDataRedis.getTokenMember(SystemDataRedis.doctorTokens)+"");
    }
}

+ 9 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/util/ManagerUtilController.java

@ -12,6 +12,7 @@ import com.yihu.wlyy.service.common.util.ManageUtilService;
import com.yihu.wlyy.service.common.util.SignTeamAndGroupRunnable;
import com.yihu.wlyy.util.SpringUtil;
import com.yihu.wlyy.util.SystemData;
import com.yihu.wlyy.util.SystemDataRedis;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -50,6 +51,8 @@ public class ManagerUtilController extends BaseController {
    JdbcTemplate jdbcTemplate;
    @Autowired
    ConsultTeamDoctorDao consultTeamDoctorDao;
    @Autowired
    SystemDataRedis systemDataRedis;
    /*********************************************患者疾病相关******************************************/
    /**
@ -268,9 +271,12 @@ public class ManagerUtilController extends BaseController {
    public String online_num() {
        try {
            JSONObject jo = new JSONObject();
            jo.put("doctor_online", SystemData.doctorTokens.size());
            jo.put("pc_online", SystemData.doctorPCTokens.size());
            jo.put("patient_online", SystemData.patientTokens.size());
//            jo.put("doctor_online", SystemData.doctorTokens.size());
//            jo.put("pc_online", SystemData.doctorPCTokens.size());
//            jo.put("patient_online", SystemData.patientTokens.size());
            jo.put("doctor_online", systemDataRedis.getTokenMember(SystemDataRedis.doctorTokens));
            jo.put("pc_online", systemDataRedis.getTokenMember(SystemDataRedis.doctorPCTokens));
            jo.put("patient_online", systemDataRedis.getTokenMember(SystemDataRedis.patientTokens));
            return write(200, "启动成功","data",jo);
        } catch (Exception e) {
            error(e);

+ 4 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/account/PatientController.java

@ -409,7 +409,10 @@ public class PatientController extends WeixinBaseController {
                token.setDel("0");
                tokenDao.save(token);
                SystemData.patientTokens.remove(getUID());
                systemDataRedis.delToken(SystemDataRedis.patientTokens,getUID());
//                SystemData.patientTokens.remove(getUID());
                //清空患者的微信标签
                weiXinTagUtil.deleteTagWithOpenid(patient.getOpenid(),patient.getWxtagid());
                patient.setIsWxtag(Patient.isWchatTage.no.getValue());