Selaa lähdekoodia

Merge branch 'dev' of huangwenjie/wlyy2.0 into dev

huangwenjie 5 vuotta sitten
vanhempi
commit
98207df444

+ 60 - 0
business/base-service/src/main/java/com/yihu/jw/file_upload/FileUploadService.java

@ -255,6 +255,66 @@ public class FileUploadService {
                url = rs.get("urls") + "";
                logger.info("开始调用i健康接口上传文件成功:url:"+url);
//                map.put("uploadStatus", 0);//文件类型正确
//                map.put("accessory", url);//
                return url;
            }
            throw new Exception();
        }
        return url;
    }
    
    /**
     * 调用健康上传图片.
     * @param image_Path
     * @return
     * @throws Exception
     */
    public String uploadWxImage(String image_Path) throws Exception {
        String url = "";
        // 文件保存的临时路径
        FastDFSUtil fastDFSUtil = new FastDFSUtil();
        String fileUrls = "";
        File f = new File(image_Path);
        logger.info("图片文件转换file");
        if (f.exists()) {
            logger.info("图片文件转换file-start");
            FileInputStream input = new FileInputStream(f);
            String fileContenType = "text/plain";
            try {
                logger.info("获取文件类型--开始");
                fileContenType = new MimetypesFileTypeMap().getContentType(f);
                logger.info("获取文件类型--成功--fileContenType:"+fileContenType);
            } catch (Exception e) {
                logger.info("获取文件类型--失败:"+e.getMessage());
            }
            
            MultipartFile multipartFile = new MockMultipartFile("file", f.getName(), fileContenType, IOUtils.toByteArray(input));
            logger.info("图片文件转换file-转换-multipartFile");
            long size = multipartFile.getSize();
            if(size<=0){
//                map.put("uploadStatus",1);//size小于0
//                map.put("accessoryUrl",null);//
                return url;
            }
            String fileName = multipartFile.getOriginalFilename();
            String[] fs = fileName.split("\\.");
            String type = fs[1];
            logger.info("uploadImg type:"+type);
            //图片常见格式:bmp,jpg,png,tif,gif,pcx,tga,exif,fpx,svg,psd,cdr,pcd,dxf,ufo,eps,ai,raw,WMF,webp
//        List img = new ArrayList(Arrays.asList("bmp", "jpg", "png", "tif", "gif", "pcx", "tga", "exif", "fpx", "svg", "psd", "cdr", "pcd", "dxf", "ufo", "eps", "ai", "raw", "WMF", "webp"));
//        if (!img.contains(type)) {
//            map.put("uploadStatus",2);//文件类型不对
//            map.put("accessoryUrl",null);//
//            return map;
//        }
            logger.info("图片文件转换file-转换-multipartFile-成功,开始调用i健康接口上传文件");
            String response = request(wlyyUrl + "/upload/chat", multipartFile, null);
            org.json.JSONObject rs = new org.json.JSONObject(response);
            Integer status = (Integer) rs.get("status");
            if (status == 200) {
                url = rs.get("urls") + "";
                logger.info("开始调用i健康接口上传文件成功:url:"+url);
//                map.put("uploadStatus", 0);//文件类型正确
//                map.put("accessory", url);//
                return url;
            }

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

@ -121,6 +121,7 @@ public class WxAccessTokenService extends BaseJpaService<WxAccessTokenDO, WxAcce
     * @param wechatId
     * @return
     */
    @Transactional
    public String updateAccessToken(String wechatId){
        try {
            //根据wechatCode查找出appid和appSecret

+ 90 - 91
business/im-service/src/main/java/com/yihu/jw/im/service/ImService.java

@ -560,6 +560,39 @@ public class ImService {
		return failed;
	}
	
	/**
	 * 获取微信服务器图片
	 * @param wechat_appid 微信公众号appid
	 * @return
	 */
	public String fetchWxImages(String wechat_appid) {
		String photos = "";
		try {
			String images = request.getParameter("mediaIds");
			if (org.apache.commons.lang3.StringUtils.isEmpty(images)) {
				return photos;
			}
			String[] mediaIds = images.split(",");
			for (String mediaId : mediaIds) {
				if (org.apache.commons.lang3.StringUtils.isEmpty(mediaId)) {
					continue;
				}
				String temp = saveImageToDisk(mediaId,wechat_appid);
				if (org.apache.commons.lang3.StringUtils.isNotEmpty(temp)) {
					if (photos.length() == 0) {
						photos = temp;
					} else {
						photos += "," + temp;
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
//			error(e);
		}
		return photos;
	}
	
	/**
	 * 获取微信服务器语音
	 *
@ -658,6 +691,63 @@ public class ImService {
		return null;
	}
	
	
	/**
	 * 获取下载图片信息(jpg)
	 *
	 * @param mediaId 文件的id
	 * @param wechat_appid 微信appid
	 * @throws Exception
	 */
	public String saveImageToDisk(String mediaId,String wechat_appid) throws Exception {
		// 文件保存的临时路径
		String tempPath = upload_temp_path + File.separator;
		// 拼接年月日路径
		String datePath = DateUtil.getStringDate("yyyy") + File.separator + DateUtil.getStringDate("MM") + File.separator + DateUtil.getStringDate("dd") + File.separator;
		// 重命名文件
		String newFileName = DateUtil.dateToStr(new Date(), DateUtil.YYYYMMDDHHMMSS) + "_" + new Random().nextInt(1000) + ".png";
		// 保存路径
		File uploadFile = new File(tempPath + datePath + newFileName);
		
		InputStream inputStream = null;
		FileOutputStream fileOutputStream = null;
		try {
			if (!uploadFile.getParentFile().exists()) {
				uploadFile.getParentFile().mkdirs();
			}
			inputStream = getInputStream(mediaId,wechat_appid);
			byte[] data = new byte[1024];
			int len = 0;
			fileOutputStream = new FileOutputStream(uploadFile);
			while ((len = inputStream.read(data)) != -1) {
				fileOutputStream.write(data, 0, len);
			}
			// 生成缩略图
			ImageCompress.compress(uploadFile.getAbsolutePath(), uploadFile.getAbsolutePath() + "_small", 300, 300);
			// 返回保存路径
			return datePath + newFileName;
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (inputStream != null) {
				try {
					inputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (fileOutputStream != null) {
				try {
					fileOutputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return null;
	}
	
	
	/**
	 * 下载多媒体文件(请注意,视频文件不支持下载,调用该接口需http协议)
	 *
@ -746,97 +836,6 @@ public class ImService {
	}
	
	
	
	
	
	/**
	 * 获取微信服务器图片
	 * @param wechat_appid 微信公众号appid
	 * @return
	 */
	public String fetchWxImages(String wechat_appid) {
		String photos = "";
		try {
			String images = request.getParameter("mediaIds");
			if (org.apache.commons.lang3.StringUtils.isEmpty(images)) {
				return photos;
			}
			String[] mediaIds = images.split(",");
			for (String mediaId : mediaIds) {
				if (org.apache.commons.lang3.StringUtils.isEmpty(mediaId)) {
					continue;
				}
				String temp = saveImageToDisk(mediaId,wechat_appid);
				if (org.apache.commons.lang3.StringUtils.isNotEmpty(temp)) {
					if (photos.length() == 0) {
						photos = temp;
					} else {
						photos += "," + temp;
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
//			error(e);
		}
		return photos;
	}
	
	/**
	 * 获取下载图片信息(jpg)
	 *
	 * @param mediaId 文件的id
	 * @param wechat_appid 微信appid
	 * @throws Exception
	 */
	public String saveImageToDisk(String mediaId,String wechat_appid) throws Exception {
		// 文件保存的临时路径
		String tempPath = upload_temp_path + File.separator;
		// 拼接年月日路径
		String datePath = DateUtil.getStringDate("yyyy") + File.separator + DateUtil.getStringDate("MM") + File.separator + DateUtil.getStringDate("dd") + File.separator;
		// 重命名文件
		String newFileName = DateUtil.dateToStr(new Date(), DateUtil.YYYYMMDDHHMMSS) + "_" + new Random().nextInt(1000) + ".png";
		// 保存路径
		File uploadFile = new File(tempPath + datePath + newFileName);
		
		InputStream inputStream = null;
		FileOutputStream fileOutputStream = null;
		try {
			if (!uploadFile.getParentFile().exists()) {
				uploadFile.getParentFile().mkdirs();
			}
			inputStream = getInputStream(mediaId,wechat_appid);
			byte[] data = new byte[1024];
			int len = 0;
			fileOutputStream = new FileOutputStream(uploadFile);
			while ((len = inputStream.read(data)) != -1) {
				fileOutputStream.write(data, 0, len);
			}
			// 生成缩略图
			ImageCompress.compress(uploadFile.getAbsolutePath(), uploadFile.getAbsolutePath() + "_small", 300, 300);
			// 返回保存路径
			return datePath + newFileName;
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (inputStream != null) {
				try {
					inputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (fileOutputStream != null) {
				try {
					fileOutputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return null;
	}
	
	/**
	 * 患者端
	 * 发起专家咨询

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

@ -237,23 +237,42 @@ public class PatientConsultEndpoint extends EnvelopRestEndpoint {
			
//			imService.getInputStream("1",wechat_appid);
			
			String path = imService.fetchWxVoices(wechat_appid);
			logger.info("voice_path:"+path);
			JSONObject obj = new JSONObject();
			String voiceurl = "";
			// 将临时语音拷贝到正式存储路径下
			if (org.apache.commons.lang3.StringUtils.isNotEmpty(path)) {
				if("xm_ihealth_wx".equals(wechat_appid)){
					logger.info("voice_wx_type:"+wechat_appid);
					voiceurl = fileUploadService.uploadWxVoice(path);
			if(3 == type){//语音文件
				String voicepath = imService.fetchWxVoices(wechat_appid);
				logger.info("voice_path:"+voicepath);
				JSONObject obj = new JSONObject();
				String voiceurl = "";
				// 将临时语音拷贝到正式存储路径下
				if (org.apache.commons.lang3.StringUtils.isNotEmpty(voicepath)) {
					if("xm_ihealth_wx".equals(wechat_appid)){
						logger.info("voice_wx_type:"+wechat_appid);
						voiceurl = fileUploadService.uploadWxVoice(voicepath);
//					uploadVO.setFullUri(map.get("accessory").toString());
				}else{
					voiceurl = fileUtil.copyTempVoice(path,fastdfs_file_url);
					}else{
						voiceurl = fileUtil.copyTempVoice(voicepath,fastdfs_file_url);
					}
					obj.put("path", voiceurl);
					obj.put("times", times);
					content = obj.toString();
				}
				obj.put("path", voiceurl);
				obj.put("times", times);
				content = obj.toString();
			}
			}else if(2 == type){//图片文件
				String imagepath = imService.fetchWxImages(wechat_appid);
				logger.info("image_path:"+imagepath);
				JSONObject obj = new JSONObject();
				String imgeUrl = "";
				// 将临时语音拷贝到正式存储路径下
				if (org.apache.commons.lang3.StringUtils.isNotEmpty(imagepath)) {
					if("xm_ihealth_wx".equals(wechat_appid)){
						logger.info("imge_wx_type:"+wechat_appid);
						imgeUrl = fileUploadService.uploadWxImage(imagepath);
//					uploadVO.setFullUri(map.get("accessory").toString());
					}else{
						imgeUrl = fileUtil.copyTempVoice(imagepath,fastdfs_file_url);
					}
					content = imgeUrl;
				}
			}else{}
		}
		
		failed = imService.append(consult,content,type,times,patientCode,wechat_appid);