Browse Source

区域互联网医院,居民发送语音消息

huangwenjie 5 years ago
parent
commit
e549523aea

+ 5 - 0
business/base-service/pom.xml

@ -137,6 +137,11 @@
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>4.3.13.RELEASE</version>
        </dependency>
    </dependencies>
    <build>

+ 51 - 3
business/base-service/src/main/java/com/yihu/jw/file_upload/FileUploadService.java

@ -14,19 +14,19 @@ import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.apache.poi.util.IOUtils;
import org.csource.common.MyException;
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.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.security.NoSuchAlgorithmException;
@ -203,6 +203,54 @@ public class FileUploadService {
        }
        throw new Exception();
    }
    
    
    /**
     * 调用健康上传语音文件
     * @param voices_Path
     * @return
     * @throws Exception
     */
    public String uploadWxVoice(String voices_Path) throws Exception {
        String url = "";
        // 文件保存的临时路径
        FastDFSUtil fastDFSUtil = new FastDFSUtil();
        String fileUrls = "";
        File f = new File(voices_Path);
        if (f.exists()) {
            FileInputStream input = new FileInputStream(f);
            MultipartFile multipartFile = new MockMultipartFile("file", f.getName(), "text/plain", IOUtils.toByteArray(input));
            
            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;
//        }
            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") + "";
//                map.put("uploadStatus", 0);//文件类型正确
//                map.put("accessory", url);//
                return url;
            }
            throw new Exception();
        }
        return url;
    }
    public String request(String remote_url, MultipartFile file, String type) {
        CloseableHttpClient httpClient = HttpClientBuilder.create().build();

+ 23 - 10
business/im-service/src/main/java/com/yihu/jw/im/service/ImService.java

@ -413,15 +413,22 @@ public class ImService {
		}
		
		String[] arr = null;
		if (type == 3) {
//			String path = fetchWxVoices(wechat_appid);
//			JSONObject obj = new JSONObject();
//			// 将临时语音拷贝到正式存储路径下
//			if (org.apache.commons.lang3.StringUtils.isNotEmpty(path)) {
//				content = fileUtil.copyTempVoice(path,fastdfs_file_url);
//				obj.put("path", path);
//				obj.put("times", times);
//				content = obj.toString();
		if (type == 3) {//语音文件处理
//			if(!StringUtils.isEmpty(wechat_appid)){
//				String path = fetchWxVoices(wechat_appid);
//				JSONObject obj = new JSONObject();
//				// 将临时语音拷贝到正式存储路径下
//				if (org.apache.commons.lang3.StringUtils.isNotEmpty(path)) {
//					if("xm_ihealth_wx".equals(wechat_appid)){
//						Map<String, Object> map = fileUploadService.uploadImg(file);
//						uploadVO.setFullUri(map.get("accessory").toString());
//					}else{
//						content = fileUtil.copyTempVoice(path,fastdfs_file_url);
//					}
//					obj.put("path", path);
//					obj.put("times", times);
//					content = obj.toString();
//				}
//			}
			ConsultTeamLogDo log = new ConsultTeamLogDo();
			log.setConsult(consult);
@ -649,7 +656,13 @@ public class ImService {
	 * @return
	 */
	public InputStream getInputStream(String mediaId,String wechat_appid) {
		String accessToken = wxAccessTokenService.getWxAccessTokenById(wechat_appid).getAccessToken();
		String accessToken = "";
		//中山医院互联网医院
		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;
		try {

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

@ -8,6 +8,7 @@ import com.yihu.jw.entity.base.im.ConsultTeamDo;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.wx.WxWechatDO;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.file_upload.FileUploadService;
import com.yihu.jw.hospital.prescription.service.PrescriptionService;
import com.yihu.jw.hospital.service.SystemMessage.HospitalSystemMessageService;
import com.yihu.jw.im.service.ImService;
@ -20,6 +21,7 @@ import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
import com.yihu.jw.rm.patient.PatientRequestMapping;
import com.yihu.jw.util.common.FileUtil;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.wechat.dao.WechatDao;
@ -33,6 +35,7 @@ import org.apache.axis.utils.StringUtils;
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.web.bind.annotation.*;
import java.net.URLEncoder;
@ -80,6 +83,14 @@ public class PatientConsultEndpoint extends EnvelopRestEndpoint {
	@Autowired
	private BasePatientDao basePatientDao;
	
	@Autowired
	FileUploadService fileUploadService;
	
	public FileUtil fileUtil;
	
	@Value("${fastDFS.fastdfs_file_url}")
	private String fastdfs_file_url;
	
	@GetMapping(value = BaseHospitalRequestMapping.PatientIM.records)
	@ApiOperation(value = "患者咨询记录查询")
	public Envelop records(
@ -214,11 +225,30 @@ public class PatientConsultEndpoint extends EnvelopRestEndpoint {
			@RequestParam(value = "type",required = true) Integer type,
			@ApiParam(name = "times", value = "")
			@RequestParam(value = "times",required = false) Integer times,
			@ApiParam(name = "wechat_appid", value = "")
			@ApiParam(name = "wechat_appid", value = "来源:xm_ihealth_wx厦门i健康,xm_zsyy_wx中山医院")
			@RequestParam(value = "wechat_appid",required = false) String wechat_appid,
			@ApiParam(name = "patientCode", value = "居民CODE")
			@RequestParam(value = "patientCode",required = false) String patientCode) throws Exception {
		List<String> failed = new ArrayList<>();
		
		//处理语音文件
		if(!org.springframework.util.StringUtils.isEmpty(wechat_appid)){
			String path = imService.fetchWxVoices(wechat_appid);
			JSONObject obj = new JSONObject();
			// 将临时语音拷贝到正式存储路径下
			if (org.apache.commons.lang3.StringUtils.isNotEmpty(path)) {
				if("xm_ihealth_wx".equals(wechat_appid)){
					content = fileUploadService.uploadWxVoice(path);
//					uploadVO.setFullUri(map.get("accessory").toString());
				}else{
					content = fileUtil.copyTempVoice(path,fastdfs_file_url);
				}
				obj.put("path", path);
				obj.put("times", times);
				content = obj.toString();
			}
		}
		
		failed = imService.append(consult,content,type,times,patientCode,wechat_appid);
		return success(failed);
	}