Переглянути джерело

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

wangzhinan 5 роки тому
батько
коміт
aa8cd9786a

+ 4 - 4
business/base-service/src/main/java/com/yihu/jw/doctor/service/BaseDoctorService.java

@ -268,11 +268,11 @@ public class BaseDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDa
    public Boolean updateInfo(JSONObject jsonObject)throws Exception{
        //取出数据
        String doctorId = jsonObject.get("doctorId").toString();
        String introduce = jsonObject.get("introduce").toString();
        String expertise = jsonObject.get("expertise").toString();
        String photo = jsonObject.get("photo").toString();
        String outpatientType = jsonObject.get("outpatientType").toString();
        baseDoctorDao.update(doctorId,introduce,expertise,photo,outpatientType);
        logger.info("doctor:"+doctorId+" outpatientType:"+outpatientType);
        BaseDoctorDO doctorDO = baseDoctorDao.findOne(doctorId);
        doctorDO.setOutpatientType(outpatientType);
        baseDoctorDao.save(doctorDO);
        return true;
    }

+ 5 - 0
business/base-service/src/main/java/com/yihu/jw/wechat/dao/WxAccessTokenDao.java

@ -2,6 +2,7 @@ package com.yihu.jw.wechat.dao;
import com.yihu.jw.entity.base.wx.WxAccessTokenDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
@ -14,4 +15,8 @@ public interface WxAccessTokenDao extends PagingAndSortingRepository<WxAccessTok
    @Query("from WxAccessTokenDO w where w.wechatId =?1 order by w.addTimestamp desc")
    List<WxAccessTokenDO> getWxAccessTokenById(String wechatId);
    
    @Modifying
    @Query("delete from WxAccessTokenDO p where p.wechatId=?1 ")
    void deleteByWechatId(String wechatId);
}

+ 58 - 1
business/base-service/src/main/java/com/yihu/jw/wechat/service/WxAccessTokenService.java

@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.transaction.Transactional;
import java.util.*;
/**
@ -105,7 +106,63 @@ public class WxAccessTokenService extends BaseJpaService<WxAccessTokenDO, WxAcce
            return null;
        }
    }
    
    /**
     * wechatId 删除无效 wechatId
     * @param wechatId
     */
    @Transactional
    public void deleteByWechatId(String wechatId){
        wxAccessTokenDao.deleteByWechatId(wechatId);
    }
    
    /**
     * 过期后删掉accesstoken,  重新获取
     * @param wechatId
     * @return
     */
    public String updateAccessToken(String wechatId){
        try {
            //根据wechatCode查找出appid和appSecret
            WxWechatDO wxWechat = wechatDao.findById(wechatId);
            String token_url = "https://api.weixin.qq.com/cgi-bin/token";
            String appId="";
            String appSecret="";
            appId = wxWechat.getAppId();
            appSecret = wxWechat.getAppSecret();
            if (StringUtils.isEmpty(appId)){
                throw new ApiException(WechatRequestMapping.WxConfig.message_fail_appId_is_null, ExceptionCode.common_error_params_code);
            }
            if (StringUtils.isEmpty(appSecret)){
                throw new ApiException(WechatRequestMapping.WxConfig.message_fail_appSecret_is_null, ExceptionCode.common_error_params_code);
            }
            Map<String, Object> params = new HashMap<>();
            params.put("grant_type", "client_credential");
            params.put("appid", appId);
            params.put("secret", appSecret);
            String result = HttpUtils.doGet(token_url, params).getContent();
            logger.info("--------------wechat token return:"+result+"---------------");
            JSONObject json = new JSONObject(result);
            if (json.has("access_token")) {
                String token = json.get("access_token").toString();
                String expires_in = json.get("expires_in").toString();
                WxAccessTokenDO newaccessToken = new WxAccessTokenDO();
                newaccessToken.setAccessToken(token);
                newaccessToken.setExpiresIn(Long.parseLong(expires_in));
                newaccessToken.setAddTimestamp(System.currentTimeMillis());
                newaccessToken.setCzrq(new Date());
                newaccessToken.setCode(UUID.randomUUID().toString().replace("-",""));
                newaccessToken.setWechatId(wechatId);
                wxAccessTokenDao.save(newaccessToken);
                return token;
            } else {
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    public WxAccessTokenDO getWxAccessTokenById(String wechatId) {
        try {

+ 16 - 2
business/base-service/src/main/java/com/yihu/jw/wlyy/service/WlyyBusinessService.java

@ -472,6 +472,21 @@ public class WlyyBusinessService {
                                doctor.setJobTitleName(jobName);
                                baseDoctorDao.save(doctor);
                                //更新机构科室信息
                                String orgCode =doctorJson.getString("hospital");
                                if(StringUtils.isNotBlank(orgCode)){
                                    List<BaseDoctorHospitalDO> hospitalDOs = baseDoctorHospitalDao.findByOrgCodeAndDoctorCode(orgCode,doctor.getId());
                                    if(hospitalDOs!=null&&hospitalDOs.size()>0){
                                        BaseDoctorHospitalDO hospitalDO = hospitalDOs.get(0);
                                        hospitalDO.setOrgCode(doctorJson.getString("hospital"));
                                        hospitalDO.setOrgName(doctorJson.getString("hospitalName"));
                                        hospitalDO.setDeptCode(doctorJson.getString("dept"));
                                        hospitalDO.setDeptName(doctorJson.getString("deptName"));
                                        baseDoctorHospitalDao.save(hospitalDO);
                                    }
                                }
                            } else {
                                BaseDoctorDO doctor = new BaseDoctorDO();
@ -516,13 +531,12 @@ public class WlyyBusinessService {
                                Integer level = doctorJson.getInteger("level");
                                BaseDoctorRoleDO role = new BaseDoctorRoleDO();
                                role.setDoctorCode(temp.getId());
                                if (level != null && level == 1) {
                                    role.setRoleCode("specialist");
                                } else {
                                    role.setRoleCode("generalDoctor");
                                }
                                role.setDoctorCode(temp.getId());
                                role.setRoleCode("generalDoctor");
                                baseDoctorRoleDao.save(role);

+ 62 - 6
business/im-service/src/main/java/com/yihu/jw/im/service/ImService.java

@ -663,14 +663,64 @@ public class ImService {
	 *
	 * @return
	 */
	public InputStream getInputStream(String mediaId,String wechat_appid) {
	public InputStream getInputStream(String mediaId,String wechat_appid) throws Exception {
		String accessToken = "";
		//中山医院互联网医院
		if("xm_zsyy_wx".equals(wechat_appid)){
			accessToken = entranceService.getAccessToken("100033");
		}else{
			accessToken = wxAccessTokenService.getWxAccessTokenById(wechat_appid).getAccessToken();
//		//中山医院互联网医院
//		if("xm_zsyy_wx".equals(wechat_appid)){
//			accessToken = entranceService.getAccessToken("100033");
//		}else{
//			accessToken = wxAccessTokenService.getWxAccessTokenById(wechat_appid).getAccessToken();
//		}
		InputStream is = null;
		String url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" + accessToken + "&media_id=" + mediaId;
//		String url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=30_OBJbMMPW9TnyGHKf32bcjkXtxWnzBrtqWlSMBnNk8MWpJ6qis2TnsecRYNZImgahdx30WrsI1bGco6K67-j4sT1QkDxYKBrVvjaYF6QgbY8dgBMzuoARKoaxtX3ehiYvdCLSUHvogrpF3n0GANIfCHAHUP&media_id=R_060hnyXAFyHD9HaOLl15xhDIzDvcA61-Wz34GkXmCakdrsFJqxrPEBHewmAEK9";
		logger.info("media/get"+url);
		try {
			URL urlGet = new URL(url);
			HttpURLConnection http = (HttpURLConnection) urlGet.openConnection();
			http.setRequestMethod("GET"); // 必须是get方式请求
			http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
			http.setDoOutput(true);
			http.setDoInput(true);
			System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
			System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
			http.connect();
			
			// 获取文件转化为byte流
			is = http.getInputStream();
			if(is.available() <= 200){
				logger.info("下载多媒体文件 accessToken 过期");
				//中山医院互联网医院
				if("xm_zsyy_wx".equals(wechat_appid)){
					accessToken = entranceService.getAccessToken("100033");
				}else{
					wxAccessTokenService.deleteByWechatId(wechat_appid);
					accessToken = wxAccessTokenService.updateAccessToken(wechat_appid);
					is = getInputStreamReLoad(mediaId,wechat_appid,accessToken);
					return is;
				}
			}
			
			
		} catch (Exception e) {
			logger.info(e.getMessage());
			e.printStackTrace();
			throw new Exception("下载失败,"+e.getMessage());
		}
		return is;
	}
	
	
	/**
	 * accessToken 过期时重新下载多媒体文件
	 * 下载多媒体文件(请注意,视频文件不支持下载,调用该接口需http协议)
	 *
	 * @return
	 */
	public InputStream getInputStreamReLoad(String mediaId,String wechat_appid,String accessToken) throws Exception {
		logger.info("accessToken 过期时重新下载多媒体文件:accessToken:"+accessToken);
		logger.info("accessToken 过期时重新下载多媒体文件:wechat_appid:"+wechat_appid);
		logger.info("accessToken 过期时重新下载多媒体文件:mediaId:"+mediaId);
		InputStream is = null;
		String url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" + accessToken + "&media_id=" + mediaId;
		logger.info("media/get"+url);
@ -686,13 +736,19 @@ public class ImService {
			http.connect();
			// 获取文件转化为byte流
			is = http.getInputStream();
			
		} catch (Exception e) {
			logger.info(e.getMessage());
			e.printStackTrace();
			throw new Exception("下载失败,"+e.getMessage());
		}
		return is;
	}
	
	
	
	
	
	/**
	 * 获取微信服务器图片
	 * @param wechat_appid 微信公众号appid

+ 3 - 0
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/consult/PatientConsultEndpoint.java

@ -234,6 +234,9 @@ public class PatientConsultEndpoint extends EnvelopRestEndpoint {
		
		//处理语音文件
		if(!org.springframework.util.StringUtils.isEmpty(wechat_appid)){
			
//			imService.getInputStream("1",wechat_appid);
			
			String path = imService.fetchWxVoices(wechat_appid);
			logger.info("voice_path:"+path);
			JSONObject obj = new JSONObject();