Jelajahi Sumber

Merge branch 'dev' of trick9191/patient-co-management into dev

trick9191 7 tahun lalu
induk
melakukan
6c954b0ae3

+ 25 - 6
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/interceptors/DoctorInterceptor.java

@ -6,10 +6,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;
@ -34,6 +36,9 @@ public class DoctorInterceptor extends BaseInterceptor {
    public static String status = "1";
    @Autowired
    public SystemDataRedis systemDataRedis;
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        boolean flag = true;
@ -121,14 +126,19 @@ public class DoctorInterceptor extends BaseInterceptor {
            Token token = null;
            Map<String, Token> tempMap = null;
            //1.50 登录缓存存储为redis
            if (platform == 2) {
                tempMap = SystemData.doctorTokens;
                //tempMap = SystemData.doctorTokens;
                token = systemDataRedis.getDoctorToken(uid);
            } else if (platform == 4) {
                tempMap = SystemData.doctorPCTokens;
                //tempMap = SystemData.doctorPCTokens;
                token = systemDataRedis.getDoctorPCToken(uid);
            }else if(platform ==5){
                tempMap = SystemData.doctorWXTokens;
                //tempMap = SystemData.doctorWXTokens;
                token = systemDataRedis.getDoctorWXToken(uid);
            }
            token = tempMap.get(uid);
            //token = tempMap.get(uid);
            if (token == null) {
                token = tokenDao.findByPatient(uid, platform);
                if (token != null) {
@ -155,8 +165,17 @@ public class DoctorInterceptor extends BaseInterceptor {
                    if (DateUtil.getDays(token.getCzrq(), DateUtil.getNowDateShort()) != 0) {
                        // 今天未更新,则更新缓存
                        token.setCzrq(new Date());
                        // 更新内存
                        tempMap.put(uid, token);
                        //1.5.0更新redis缓存
                        if (platform == 2) {
                            systemDataRedis.setDoctorToken(token);
                        } else if (platform == 4) {
                            systemDataRedis.setDoctorPCToken(token);
                        }else if(platform ==5){
                            systemDataRedis.setDoctorWXToken(token);
                        }
//                        // 更新内存
//                        tempMap.put(uid, token);
                        // 更新数据库
                        tokenDao.save(token);
                    }

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

@ -17,10 +17,7 @@ import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.PatientRecordLogDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.security.TokenDao;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.EncodesUtil;
import com.yihu.wlyy.util.IdcardInfoExtractor;
import com.yihu.wlyy.util.SystemData;
import com.yihu.wlyy.util.*;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
@ -60,6 +57,8 @@ public class PatientService extends TokenService {
    TokenDao tokenDao;
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    private SystemDataRedis systemDataRedis;
    private Clock clock = Clock.DEFAULT;
    //可续签月份
@ -1145,7 +1144,10 @@ public class PatientService extends TokenService {
            patientRecordLogDao.save(patientRecordLog);
            //清登录缓存
            SystemData.patientTokens.remove(patient.getCode());
            //SystemData.patientTokens.remove(patient.getCode());
            //1.5.0清楚redis缓存
            systemDataRedis.delToken(SystemDataRedis.patientTokens,patient.getCode());
        }
        patientDao.clearOpenidByOpenid(openid);
        return "";

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

@ -7,6 +7,7 @@ import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.MD5;
import com.yihu.wlyy.util.SystemData;
import com.yihu.wlyy.util.SystemDataRedis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@ -21,6 +22,8 @@ public class TokenService extends BaseService {
	public TokenDao tokenDao;
	@Autowired
	private PatientDao patientDao;
	@Autowired
	private SystemDataRedis systemDataRedis;
	/**
	 * 生成token
@ -56,14 +59,19 @@ public class TokenService extends BaseService {
			throw new Exception("Token生成失败");
		}
		// 更新token缓存
		//1.5.0 更新redis token缓存
		if (platform == 3) {
			SystemData.patientTokens.put(user, token);
			systemDataRedis.setPatientToken(token);
			//SystemData.patientTokens.put(user, token);
		} else if (platform == 2) {
			SystemData.doctorTokens.put(user, token);
			systemDataRedis.setDoctorToken(token);
			//SystemData.doctorTokens.put(user, token);
		}else if(platform == 4){
			SystemData.doctorPCTokens.put(user,token);
			systemDataRedis.setDoctorPCToken(token);
			//SystemData.doctorPCTokens.put(user,token);
		}else if(platform == 5){
			SystemData.doctorWXTokens.put(user,token);
			systemDataRedis.setDoctorWXToken(token);
			//SystemData.doctorWXTokens.put(user,token);
		}
		return token;
	}
@ -103,11 +111,14 @@ public class TokenService extends BaseService {
	public void delToken(int platform, String uid) throws Exception {
		// 删除老的token
		tokenDao.deleteByUser(uid);
		// 更新token缓存
		// 1.5.0 更新token缓存 redis
		if (platform == 3) {
			SystemData.patientTokens.remove(uid);
			//1.5.0 删除居民Token
			systemDataRedis.delToken(SystemDataRedis.patientTokens,uid);
			//SystemData.patientTokens.remove(uid);
		} else if (platform == 2) {
			SystemData.doctorTokens.remove(uid);
			systemDataRedis.delToken(SystemDataRedis.doctorTokens,uid);
			//SystemData.doctorTokens.remove(uid);
		}
	}

+ 2 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/weixin/applets/AppletsService.java

@ -6,6 +6,7 @@ import com.yihu.wlyy.repository.patient.PatientAimSportsDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.health.bank.TaskService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.SecretUtils;
import com.yihu.wlyy.util.http.HttpResponse;
import com.yihu.wlyy.util.http.HttpUtils;
@ -138,6 +139,7 @@ public class AppletsService extends BaseService {
            patientAimSports.setDailyStepCount(step);
            patientAimSports.setCreateTime(new Date());
            patientAimSports.setPatientcode(patient);
            patientAimSports.setCreateDate(DateUtil.getStringDateShort());
            patientAimSportsDao.save(patientAimSports);
        }

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

@ -0,0 +1,114 @@
package com.yihu.wlyy.util;
import com.yihu.wlyy.entity.security.Token;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
/**
 * Created by Trick on 2018/8/20.
 * 1.5.0 版本 将token 存储在redis
 */
@Component
public class SystemDataRedis {
    @Autowired
    private StringRedisTemplate redisTemplate;
    /**
     * tokenTypeName
     */
    public final static String doctorTokens = "doctorTokens";//医生缓存
    public final static String doctorPCTokens = "doctorPCTokens";//pc端缓存
    public final static String patientTokens = "patientTokens";//居民缓存
    public final static String doctorWXTokens = "doctorWXTokens";//医生微信缓存
//====设置token========
    /**
     * 设置医生缓存
     * @param token
     */
    public String setDoctorToken(Token token){
        return setToken(doctorTokens,token);
    }
    /**
     * 设置pc端缓存
     * @param token
     */
    public String setDoctorPCToken(Token token){
       return setToken(doctorPCTokens,token);
    }
    /**
     * 设置居民缓存
     * @param token
     */
    public String setPatientToken(Token token){
        return setToken(patientTokens,token);
    }
    /**
     *  设置医生微信缓存
     * @param token
     */
    public String setDoctorWXToken(Token token){
        return setToken(doctorWXTokens,token);
    }
//====设置token==end===
//====获取token========
    public Token getDoctorToken(String uid){
        return getToken(doctorTokens,uid);
    }
    public Token getDoctorPCToken(String uid){
        return getToken(doctorPCTokens,uid);
    }
    public Token getPatientToken(String uid){
        return getToken(patientTokens,uid);
    }
    public Token getDoctorWXToken(String uid){
        return getToken(doctorWXTokens,uid);
    }
//=====获取token===end===
    /**
     * 设置token
     * @param tokenTypeName
     * @param token
     */
    public String setToken(String tokenTypeName,Token token){
        JSONObject json = JSONObject.fromObject(token);
        String key = "token:"+tokenTypeName+":"+token.getUser();
        redisTemplate.opsForValue().set(key,json.toString());
        return json.toString();
    }
    /**
     * 获取token
     * @param tokenTypeName
     * @param uid
     * @return
     */
    public Token getToken(String tokenTypeName,String uid) {
        String tokenJosn = redisTemplate.opsForValue().get("token:" + tokenTypeName + ":" + uid);
        Token token = (Token)JSONObject.toBean(JSONObject.fromObject(tokenJosn),Token.class);
        return token;
    }
    /**
     * 删除token
     * @param tokenTypeName
     * @param uid
     * @return
     */
    public void delToken(String tokenTypeName,String uid){
        String key = "token:"+tokenTypeName+":"+uid;
        redisTemplate.delete(key);
    }
}

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

@ -12,10 +12,7 @@ import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.common.account.RoleService;
import com.yihu.wlyy.service.common.account.TokenService;
import com.yihu.wlyy.service.common.login.LoginLogService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.MD5;
import com.yihu.wlyy.util.RSAUtils;
import com.yihu.wlyy.util.SystemData;
import com.yihu.wlyy.util.*;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
@ -75,6 +72,9 @@ public class LoginController extends BaseController {
    @Autowired
    private DoctorInfoService doctorInfoService;
    @Autowired
    private SystemDataRedis systemDataRedis;
    /**
     * 公钥生成并返回接口
@ -560,5 +560,21 @@ public class LoginController extends BaseController {
        }
    }
    @RequestMapping(value = "setTokenTest", method = RequestMethod.POST)
    @ResponseBody
    public String setToken(String uid){
        Token token = new Token();
        token.setToken("123456");
        token.setDel("1");
        token.setCzrq(new Date());
        token.setUser(uid);
        return write(200,systemDataRedis.setDoctorPCToken(token));
    }
    @RequestMapping(value = "getTokenTest", method = RequestMethod.POST)
    @ResponseBody
    public String getToken(String uid){
        return write(200,systemDataRedis.getDoctorPCToken(uid).toJson());
    }
}

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

@ -76,6 +76,8 @@ public class PatientController extends WeixinBaseController {
    private WeiXinTagUtil weiXinTagUtil;
    @Autowired
    private RSAUtils rsaUtils;
    @Autowired
    private SystemDataRedis systemDataRedis;
    /**
     * 患者基本信息查询接口
@ -393,7 +395,10 @@ public class PatientController extends WeixinBaseController {
            } else {
                //patient.setOpenid("");
                //patientInfoService.updateUser(patient);
                Token token = SystemData.patientTokens.get(getUID());
                //1.5.0 token存储redis
                //Token token = SystemData.patientTokens.get(getUID());
                Token token = systemDataRedis.getPatientToken(getUID());
                if (token == null) {
                    token = tokenDao.findByPatient(getUID(), 3);
                }