Procházet zdrojové kódy

中医体检,声音图片上传bug

chenyongxing před 7 roky
rodič
revize
d6626dde2b
13 změnil soubory, kde provedl 744 přidání a 88 odebrání
  1. 1 1
      common/common-entity/src/main/java/com/yihu/mm/entity/questionnaire/MedicineAnswerLog.java
  2. 9 4
      patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/controller/WeixinBaseController.java
  3. 37 11
      patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/controller/medicine/PhysicalExaminationController.java
  4. 4 0
      patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/repository/mm/exam/MedicineAnswerLogDao.java
  5. 13 0
      patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/service/MedicineAnswerLogService.java
  6. 56 12
      patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/service/PhysicalExaminationService.java
  7. 4 55
      patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/util/CommonUtil.java
  8. 208 0
      patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/util/SystemConf.java
  9. 134 0
      patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/util/fastdfs/FastDFSClientPool.java
  10. 258 0
      patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/util/fastdfs/FastDFSUtil.java
  11. 15 0
      patient-co-customization/patient-co-modern-medicine/src/main/resources/config/fdfs_client.conf
  12. 5 0
      patient-co-customization/patient-co-modern-medicine/src/main/resources/system.properties
  13. 0 5
      patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/service/manager/family/FamilyMemberService.java

+ 1 - 1
common/common-entity/src/main/java/com/yihu/mm/entity/questionnaire/MedicineAnswerLog.java

@ -26,7 +26,7 @@ public class MedicineAnswerLog extends IdEntity {
    private String ctId;//咨询编号
    private String question;//问题描述
    private String opti;//问题选项
    private String type;//选项
    private String type;// 1单选  2多选   3面部   4舌部   5声音
    public String getPatientCode() {
        return patientCode;

+ 9 - 4
patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/controller/WeixinBaseController.java

@ -3,6 +3,7 @@ package com.yihu.mm.controller;
import com.yihu.mm.service.AccessTokenService;
import com.yihu.mm.util.CommonUtil;
import com.yihu.mm.util.HttpUtil;
import com.yihu.mm.util.SystemConf;
import com.yihu.wlyy.entity.security.AccessToken;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
@ -26,6 +27,10 @@ public class WeixinBaseController extends BaseController {
	private String appId;
	@Value("${wechat.appSecret}")
	private String appSecret;
	@Autowired
	private CommonUtil CommonUtil;
	@Autowired
	private HttpUtil HttpUtil;
	/**
	 * 获取微信的access_token
@ -47,7 +52,7 @@ public class WeixinBaseController extends BaseController {
			}
			String token_url = "https://api.weixin.qq.com/cgi-bin/token";
			String params = "grant_type=client_credential&appid=" + appId + "&secret=" + appSecret;
			String result = new HttpUtil().sendGet(token_url, params);
			String result = HttpUtil.sendGet(token_url, params);
			JSONObject json = new JSONObject(result);
			if (json.has("access_token")) {
				String token = json.get("access_token").toString();
@ -107,7 +112,7 @@ public class WeixinBaseController extends BaseController {
	 */
	public String saveVoiceToDisk(String mediaId) throws Exception {
		// 文件保存的临时路径
		String tempPath = Class.class.getClass().getResource("/").getPath() + "temp/";
		String tempPath = SystemConf.getInstance().getTempPath() + File.separator;
		// 重命名文件
		String fileBase = UUID.randomUUID().toString();
		String newFileName = fileBase+ ".amr";
@ -130,7 +135,7 @@ public class WeixinBaseController extends BaseController {
			}
			String amrFilePath = tempPath+newFileName;
			String Mp3FilePath = tempPath+mp3FileName;
			new CommonUtil().changeToMp3(amrFilePath,Mp3FilePath);
			CommonUtil.changeToMp3(amrFilePath,Mp3FilePath);
			// 返回保存路径
			return Mp3FilePath;
		} catch (IOException e) {
@ -190,7 +195,7 @@ public class WeixinBaseController extends BaseController {
	public String getOpenId(String code) throws Exception {
		String token_url = "https://api.weixin.qq.com/sns/oauth2/access_token";
		String params = "appid=" + appId+ "&secret=" + appSecret + "&code=" + code + "&grant_type=authorization_code";
		String result = new HttpUtil().sendGet(token_url, params);
		String result = HttpUtil.sendGet(token_url, params);
		JSONObject json = new JSONObject(result);
		if (json.has("openid")) {
			return json.get("openid").toString();

+ 37 - 11
patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/controller/medicine/PhysicalExaminationController.java

@ -93,8 +93,7 @@ public class PhysicalExaminationController extends WeixinBaseController {
    @ApiOperation(value = "获取试题")
    @RequestMapping(value = "/findQuestion",produces="application/json;charset=UTF-8")
    @ResponseBody
    public String findQuestion(
                               @ApiParam(name = "pb_id", value = "问卷编号,第一题为0", required = true)@RequestParam(required = true, name = "pb_id") String pb_id,
    public String findQuestion(@ApiParam(name = "pb_id", value = "问卷编号,第一题为0", required = true)@RequestParam(required = true, name = "pb_id") String pb_id,
                               @ApiParam(name = "patientCode", value = "居民code", required = true)@RequestParam(required = true, name = "patientCode") String patientCode,
                               @ApiParam(name = "ct_id", value = "咨询编号", required = true)@RequestParam(required = true, name = "ct_id") String ct_id) throws IOException {
@ -186,34 +185,44 @@ public class PhysicalExaminationController extends WeixinBaseController {
    @ApiOperation(value = "获取微信文件,传到越人接口(四象采集,声音文件需要从微信接口获取)")
    @RequestMapping(value = "/dealVoice", produces="application/json;charset=UTF-8")
    @ResponseBody
    public String getFileFromWechat( @ApiParam(name = "mediaId", value = "微信媒体id", required = true)@RequestParam(required = true, name = "mediaId") String mediaId,
    public String getFileFromWechat(@ApiParam(name = "patientCode", value = "居民code", required = true)@RequestParam(required = true, name = "patientCode") String patientCode,
                                    @ApiParam(name = "mediaId", value = "微信媒体id", required = true)@RequestParam(required = true, name = "mediaId") String mediaId,
                                   @ApiParam(name = "type", value = "1.脸型  2.舌像  3.声音", required = true)@RequestParam(required = true, name = "type") String type,
                                   @ApiParam(name = "ct_id", value = "咨询编号", required = true)@RequestParam(required = true, name = "ct_id") String ct_id) throws Exception {
        System.out.println("===================================");
        System.out.println(mediaId);
        System.out.println("======================================");
        String voice = saveVoiceToDisk(mediaId);
        String uploadAttachment = physicalExaminationService.uploadAttachment(voice);
        JSONObject uploadResult = new JSONObject(uploadAttachment);
        if(physicalExaminationService.getSuccess(uploadResult)){
            JSONObject recordset = uploadResult.getJSONObject("recordset");
            String at_id =  recordset.get("at_id").toString();
            String at_realname = (String) recordset.get("at_realname");
            String result = physicalExaminationService.dillphoneimgdata(at_id, at_realname, type, ct_id);
            JSONObject resultJson = new JSONObject(result);
            if(physicalExaminationService.getSuccess(resultJson)){
                String type1=Integer.valueOf(type)+2+"";
                MedicineAnswerLog medicineAnswerLog = medicineAnswerLogService.findByTypeAndCtid(type1,ct_id ,patientCode);
                if(medicineAnswerLog==null){
                    medicineAnswerLog = new MedicineAnswerLog();
                    medicineAnswerLog.setCreateTime(new Date());
                    medicineAnswerLog.setType(type1);
                }
                medicineAnswerLog.setPatientCode(patientCode);
                medicineAnswerLog.setTpId(examCode);
                medicineAnswerLog.setAnswer(uploadResult.getString("fileUrl"));
                medicineAnswerLog.setCtId(ct_id);
                medicineAnswerLogService.save(medicineAnswerLog);
            }
            return result;
        }
        return uploadAttachment;
    }
    @ApiOperation(value = "四诊资料采集")
    @RequestMapping(value = "/dillphoneimgdata", method = RequestMethod.POST,produces="application/json;charset=UTF-8")
    @ResponseBody
    public String dillphoneimgdata(@RequestParam MultipartFile file,
                              @ApiParam(name = "patientCode", value = "居民code", required = true)@RequestParam(required = true, name = "patientCode") String patientCode,
                              @ApiParam(name = "type", value = "1.脸型  2.舌像  3.声音", required = true)@RequestParam(required = true, name = "type") String type,
                             @ApiParam(name = "ct_id", value = "咨询编号", required = true)@RequestParam(required = true, name = "ct_id") String ct_id){
        String uploadAttachment = physicalExaminationService.uploadAttachment(file);
@ -223,6 +232,23 @@ public class PhysicalExaminationController extends WeixinBaseController {
            String at_id =  recordset.get("at_id").toString();
            String at_realname = (String) recordset.get("at_realname");
            String result = physicalExaminationService.dillphoneimgdata(at_id, at_realname, type, ct_id);
            JSONObject resultJson = new JSONObject(result);
            if(physicalExaminationService.getSuccess(resultJson)){
                String type1=Integer.valueOf(type)+2+"";
                MedicineAnswerLog medicineAnswerLog = medicineAnswerLogService.findByTypeAndCtid(type1,ct_id ,patientCode);
                if(medicineAnswerLog==null){
                    medicineAnswerLog = new MedicineAnswerLog();
                    medicineAnswerLog.setCreateTime(new Date());
                    medicineAnswerLog.setType(type1);
                }
                medicineAnswerLog.setPatientCode(patientCode);
                medicineAnswerLog.setTpId(examCode);
                medicineAnswerLog.setAnswer(uploadResult.getString("fileUrl"));
                medicineAnswerLog.setCtId(ct_id);
                medicineAnswerLogService.save(medicineAnswerLog);
            }
            return result;
        }
        return uploadAttachment;

+ 4 - 0
patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/repository/mm/exam/MedicineAnswerLogDao.java

@ -14,4 +14,8 @@ public interface MedicineAnswerLogDao extends PagingAndSortingRepository<Medicin
	@Query("select m from MedicineAnswerLog m where m.patientCode=?1 and m.tpId=?2 and m.pbId=?3 and m.ctId=?4")
    MedicineAnswerLog findAnswer(String patientCode, String tp_id, String pb_id,String ct_id);
	@Query("select m from MedicineAnswerLog m where m.type=?1 and m.ctId=?2 and m.patientCode=?3")
    MedicineAnswerLog findByTypeAndCtid(String type, String ct_id,String patientCode);
}

+ 13 - 0
patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/service/MedicineAnswerLogService.java

@ -33,4 +33,17 @@ public class MedicineAnswerLogService {
    public MedicineAnswerLog findAnswer(String patientCode,String tp_id,String pb_id,String ct_id){
        return  medicineAnswerLogDao.findAnswer(patientCode,tp_id,pb_id,ct_id);
    }
    /**
     * type 为  3,4,5 (3面部   4舌部   5声音)   时,才能返回查询的记录 ,否则返回 null
     * @param type
     * @param ct_id
     * @return
     */
    public MedicineAnswerLog findByTypeAndCtid(String type, String ct_id,String patientCode) {
        if("3".equals(type)||"4".equals(type)||"5".equals(type)){
            return medicineAnswerLogDao.findByTypeAndCtid(type,ct_id,patientCode);
        }
        return null;
    }
}

+ 56 - 12
patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/service/PhysicalExaminationService.java

@ -1,9 +1,13 @@
package com.yihu.mm.service;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.mm.entity.patient.ExamReport;
import com.yihu.mm.entity.yueren.MedicineStroresNo;
import com.yihu.mm.util.CommonUtil;
import com.yihu.mm.util.HttpClientUtil;
import com.yihu.mm.util.fastdfs.FastDFSUtil;
import com.yihu.wlyy.entity.patient.Patient;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -14,8 +18,7 @@ import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -32,6 +35,11 @@ public class PhysicalExaminationService {
    @Autowired
    private ExamReportService examReportService;
    @Autowired
    private CommonUtil CommonUtil;
    @Value("${fastDFS.fastdfs_file_url}")
    private String fastdfs_file_url;
    public boolean getSuccess(JSONObject result ){
@ -211,6 +219,10 @@ public class PhysicalExaminationService {
        }
        try {
            file.transferTo(dest);
            //上传图片到fastDFS
            String fileUrl = uploadToFastDfs(dest);
            RestTemplate rest = new RestTemplate();
            FileSystemResource resource = new FileSystemResource(filePath);
            param.add("file", resource);
@ -218,25 +230,57 @@ public class PhysicalExaminationService {
            if (dest.exists() && dest.isFile()) {
                dest.delete();
            }
            return postStr;
            postStr.replace("exception", "msg");
            JSONObject result = new JSONObject(postStr);
            result.put("fileUrl",fileUrl);
            return result.toString();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "{\"status\":500,\"msg\":\"上传文件出错\"}";
    }
    public String uploadAttachment(String filePath) {
    public String uploadAttachment(String file){
        MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
        File dest = new File(filePath);
        RestTemplate rest = new RestTemplate();
        FileSystemResource resource = new FileSystemResource(filePath);
        param.add("file", resource);
        String postStr = rest.postForObject(yuerenApi+"/uploadattachment" , param, String.class);
        if (dest.exists() && dest.isFile()) {
            dest.delete();
        File dest = new File(file);
        try {
            //上传图片到fastDFS
            String fileUrl = uploadToFastDfs(dest);
            RestTemplate rest = new RestTemplate();
            FileSystemResource resource = new FileSystemResource(file);
            param.add("file", resource);
            String postStr = rest.postForObject(yuerenApi+"/uploadattachment" , param, String.class);
            if (dest.exists() && dest.isFile()) {
                dest.delete();
            }
            postStr.replace("exception", "msg");
            JSONObject result = new JSONObject(postStr);
            result.put("fileUrl",fileUrl);
            return result.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "{\"status\":500,\"msg\":\"上传文件出错\"}";
    }
    private String uploadToFastDfs(File file) throws Exception {
        String fileUrls = "";
        FastDFSUtil fastDFSUtil = new FastDFSUtil();
        String fileName = file.getName();
        InputStream in = new FileInputStream(file);
        ObjectNode result = fastDFSUtil.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
        in.close();
        if (result != null) {
            fileUrls += (StringUtils.isEmpty(fileUrls) ? "" : ",") + fastdfs_file_url
                    + result.get("groupName").toString().replaceAll("\"", "") + "/"
                    + result.get("remoteFileName").toString().replaceAll("\"", "");
        }
        return postStr.replace("exception", "msg");
        return fileUrls;
    }
}

+ 4 - 55
patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/util/CommonUtil.java

@ -1,5 +1,7 @@
package com.yihu.mm.util;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.mm.util.fastdfs.FastDFSUtil;
import it.sauronsoftware.jave.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
@ -96,7 +98,6 @@ public class CommonUtil {
     */
/*
    public String copyTempVoice(String voices) throws  Exception {
        // 文件保存的临时路径
        String serverUrl = fastdfs_file_url;
@ -117,7 +118,6 @@ public class CommonUtil {
        }
        return fileUrls;
    }
*/
    /**
     * double转字符串,在转int
@ -180,7 +180,7 @@ public class CommonUtil {
     * @return
     * @throws Exception
     */
    /*public  String copyTempImage(String files) throws Exception {
    public  String copyTempImage(String files) throws Exception {
        // 文件保存的临时路径
        String tempPath = SystemConf.getInstance().getTempPath() + File.separator;
        String serverUrl = fastdfs_file_url;
@ -209,7 +209,7 @@ public class CommonUtil {
        }
        return fileUrls;
    }*/
    }
    public  void changeToMp3(String sourcePath, String targetPath) {
        File source = new File(sourcePath);
@ -257,16 +257,9 @@ public class CommonUtil {
        File target = new File(targetPath);
        AudioAttributes audio = new AudioAttributes();
        //audio.setCodec("aac");
        audio.setCodec("libvorbis");
       // audio.setBitRate(new Integer(64000));
        //audio.setChannels(new Integer(1));
       // audio.setSamplingRate(new Integer(22050));
        VideoAttributes video = new VideoAttributes();
        //video.setCodec("libxvid");// 转MP4
        video.setCodec("libtheora");//
       // video.setBitRate(new Integer(240000));// 180kb/s比特率
       // video.setFrameRate(new Integer(28));// 1f/s帧频,1是目前测试比较清楚的,越大越模糊
        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setFormat("ogg");// 转MP4
        attrs.setAudioAttributes(audio);
@ -305,48 +298,4 @@ public class CommonUtil {
            return content.substring(min,max);
        }
    }
    /*public  String  saveVoiceToDisk(InputStream inputStream,String newFileName) throws Exception {
        // 文件保存的临时路径
        String tempPath = SystemConf.getInstance().getTempPath() + File.separator;
        // 拼接年月日路径
        String datePath = DateUtil.getStringDate("yyyy") + File.separator + DateUtil.getStringDate("MM") + File.separator + DateUtil.getStringDate("dd") + File.separator;
        // 保存路径
        File uploadFile = new File(tempPath + datePath + newFileName);
        FileOutputStream fileOutputStream = null;
        try {
            if (!uploadFile.getParentFile().exists()) {
                uploadFile.getParentFile().mkdirs();
            }
            byte[] data = new byte[1024];
            int len = 0;
            fileOutputStream = new FileOutputStream(uploadFile);
            while ((len = inputStream.read(data)) != -1) {
                fileOutputStream.write(data, 0, len);
            }
            // 返回保存路径
            return tempPath+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;
    }*/
}

+ 208 - 0
patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/util/SystemConf.java

@ -0,0 +1,208 @@
package com.yihu.mm.util;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
@Component
public class SystemConf {
    // 别处登录
    public static final int LOGIN_OTHER = 999;
    // 登录超时
    public static final int LOGIN_TIMEOUT = 998;
    // 未登录
    public static final int NOT_LOGIN = 997;
    // 文件保存临时路径
    private static final String TEMP_PATH = "upload_temp_path";
    // 血糖餐前最小值
    public static final double HEALTH_STANDARD_ST_MIN_BEFORE = 4;
    // 血糖餐前最大值
    public static final double HEALTH_STANDARD_ST_MAX_BEFORE = 7;
    // 血糖餐后最小值
    public static final double HEALTH_STANDARD_ST_MIN_AFTER = 4;
    // 血糖餐后最大值
    public static final double HEALTH_STANDARD_ST_MAX_AFTER = 11.1;
    // 舒张压最小值
    public static final double HEALTH_STANDARD_SZY_MIN = 60;
    // 舒张压最大值
    public static final double HEALTH_STANDARD_SZY_MAX = 90;
    // 收缩压最小值
    public static final double HEALTH_STANDARD_SSY_MIN = 90;
    // 收缩压最大值
    public static final double HEALTH_STANDARD_SSY_MAX = 140;
    // 同一手机号大最短信数
    public static final int MAX_SMS_MOBILE = 5;
    // 发送短信验证码间隔(分钟)
    public static final int SMS_INTERVAL = 2;
    private static Object lock = new Object();
    // 全局系统配置信息
    private static SystemConf systemConf;
    // 系统配置文件
    private Properties systemProperties;
    //im列表
    private String imListGet;
    public static SystemConf getInstance() {
        if (systemConf == null) {
            synchronized (lock) {
                systemConf = new SystemConf();
            }
        }
        return systemConf;
    }
    /**
     * 加载系统配置文件
     *
     * @return
     */
    public Properties getSystemProperties() {
        if (systemProperties == null) {
            InputStream is = null;
            try {
                is = this.getClass().getResourceAsStream("/system.properties");
                systemProperties = new Properties();
                systemProperties.load(is);
            } catch (IOException e1) {
                e1.printStackTrace();
            } finally {
                if (is != null) {
                    try {
                        is.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        return systemProperties;
    }
    /**
     * 短信接口地址
     */
    public String getSmsUrl() {
        return getSystemProperties().getProperty("yihu_sms_url");
    }
    /**
     * 短信企业编号
     */
    public String getSmsCode() {
        return getSystemProperties().getProperty("yihu_sms_code");
    }
    /**
     * 短信用户名
     */
    public String getSmsName() {
        return getSystemProperties().getProperty("yihu_sms_name");
    }
    /**
     * 短信登录密码
     */
    public String getSmsPassword() {
        return getSystemProperties().getProperty("yihu_sms_password");
    }
    ;
    /**
     * 挂号接口地址
     */
    public String getGuahaoUrl() {
        return getSystemProperties().getProperty("yihu_guahao_url");
    }
    /**
     * 挂号接口对接appid
     */
    public String getGuahaoAppid() {
        return getSystemProperties().getProperty("yihu_guahao_appid");
    }
    /**
     * 挂号接口对接app secret
     */
    public String getGuahaoSecret() {
        return getSystemProperties().getProperty("yihu_guahao_secret");
    }
    /**
     * 获取文件保存的临时路径
     *
     * @return
     */
    public String getTempPath() {
        return getSystemProperties().getProperty(TEMP_PATH);
    }
    /**
     * 获取图片存在地址
     *
     * @return
     */
    /**
     * 获取服务全路径
     *
     * @return
     */
    /******************************** 挂号配置 ********************************************/
    /**
     * 获取厦门预约服务地址
     */
    public String getXMGuahaoUrl() {
        return getSystemProperties().getProperty("guahao_url");
    }
    /**
     * 获取厦门预约服务命名空间
     */
    public String getXMGuahaoNamespace() {
        return getSystemProperties().getProperty("guahao_namespace");
    }
    /****************************************************************************************/
    /********************************* EHR配置 **********************************************/
    /**
     * 是否启用EHR演示
     */
    public Boolean getEhrUsed() {
        return Boolean.valueOf(getSystemProperties().getProperty("ehr_used"));
    }
    /**
     * EHR档案服务地址
     */
    public String getEhrServices() {
        return getSystemProperties().getProperty("ehr_services");
    }
    /**
     * EHR底层地址
     */
    public String getEhrServicesBase() {
        return getSystemProperties().getProperty("ehr_services_base");
    }
    /**************************************************************************************/
    /**************************************************************************************/
}

+ 134 - 0
patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/util/fastdfs/FastDFSClientPool.java

@ -0,0 +1,134 @@
package com.yihu.mm.util.fastdfs;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
/**
 * Created by szx on 2015/9/19.
 */
public class FastDFSClientPool {
    private static volatile FastDFSClientPool pool;
    private Map<StorageClient, Boolean> map;
    private int maxPoolSize = 20;
    private int waitTime = 500;
    private int initPoolSize = 5;
    static {
        try {
            
            String basePath = FastDFSClientPool.class.getResource("/").getPath();
           
            ClientGlobal.init(FastDFSUtil.class.getResource("/config/fdfs_client.conf").getPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private FastDFSClientPool() {
        init();
    }
    public static FastDFSClientPool getInstance() {
        if (pool == null) {
            synchronized (FastDFSClientPool.class) {
                if(pool == null) {
                    pool = new FastDFSClientPool();
                }
            }
        }
        System.out.println("FastDFSClientPool:"+pool.toString());
        return pool;
    }
    private void init() {
        try {
            map = new HashMap<StorageClient, Boolean>();
            //不做初始缓存
//            for (int i = 0; i < initPoolSize; i++) {
//                map.put(getNewStorageClient(), true);
//            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public TrackerServer getTrackerServer(){
        try {
            TrackerClient tracker = new TrackerClient();
            return tracker.getConnection();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
    private StorageClient getNewStorageClient() {
        try {
            TrackerClient tracker = new TrackerClient();
            TrackerServer trackerServer = tracker.getConnection();
            StorageClient client = new StorageClient(trackerServer, null);
            return client;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public synchronized StorageClient getStorageClient() {
        StorageClient client = null;
        try {
            for (Entry<StorageClient, Boolean> entry : map.entrySet()) {
                if (entry.getValue()) {
                    client = entry.getKey();
                    System.out.println("从缓存中获得fastdfs client");
                    map.put(client, false);
                    break;
                }
            }
            if (client == null) {
                if(map.size()<maxPoolSize) {
                    System.out.println("创建新fastdfs client:");
                    client = getNewStorageClient();
                    map.put(client, false);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return client;
    }
    public void releaseStorageClient(StorageClient client) {
        if (client == null) {
            return;
        }
        try {
            if(map.containsKey(client)) {
                    map.put(client, true);
            } else {
                client =null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

+ 258 - 0
patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/util/fastdfs/FastDFSUtil.java

@ -0,0 +1,258 @@
package com.yihu.mm.util.fastdfs;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.csource.common.MyException;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
/**
 * FastDFS 客户端工具.
 *
 * @author szx
 */
public class FastDFSUtil {
    public final static String GroupField = "groupName";
    public final static String RemoteFileField = "remoteFileName";
    public final static String FileIdField = "fid";
    public final static String FileUrlField = "fileUrl";
    final static int BUFFER_SIZE = 4096;
    /**
     * 以输入流的方式上传文件
     * InputStream in = new FileInputStream("C://Desert.jpg");
     * ObjectNode msg = FileUtil.upload(in,"jpg", "沙漠");
     * in.close();
     *
     * @param in                输入流
     * @param fileExtension   文件扩展名,不要带“.”
     * @param description             文件名称(中文)
     * @return 返回值的格式如下:
     * {
     *      "groupName": "healthArchiveGroup",
     *      "remoteFileName": "/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg",
     *      "fid": "group1/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg",
     *      "fileURL": "http://172.19.103.13/healthArchiveGroup/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg"
     * }
     *
     * groupName 及 remoteFileName 可以用于查询在 fastDFS 中文件的信息,如果只是图片显示,可以忽略这两个值。
     * fid 保存了在 fastDFS 上的完整路径,为了避免将来服务器域名发生变更,最好使用本值.服务器的域名另外配置。
     * fileURL 保存了完整的 web 访问路径,为了避免将来服务器域名发生变更,最好不要直接使用本值。
     * 如果需要在下载时,可以显示原始文件名,请在访问file_url时,增加 attname 参数,如:
     *
     * http://host/healthArchiveGroup/M00/00/00/rBFuH1XdIseAUTZZAA1rIuRd3Es062.jpg?attname=a.jpg
     *
     * @throws Exception
     */
    public static ObjectNode upload(InputStream in, String fileExtension,
                                    String description) throws Exception {
        StorageClient client = FastDFSClientPool.getInstance().getStorageClient();
        try {
            NameValuePair[] fileMetaData;
            fileMetaData = new NameValuePair[1];
            fileMetaData[0] = new NameValuePair("description", description == null ? "" : description);
            ObjectMapper objectMapper = new ObjectMapper();
            ObjectNode message = objectMapper.createObjectNode();
            ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
            byte[] buff = new byte[BUFFER_SIZE]; //buff用于存放循环读取的临时数据
            int rc = 0;
            while ((rc = in.read(buff, 0, BUFFER_SIZE)) > 0) {
                swapStream.write(buff, 0, rc);
            }
            byte[] fileBuffer = swapStream.toByteArray(); //in_b为转换之后的结果
            TrackerServer trackerServer = FastDFSClientPool.getInstance().getTrackerServer();
            String[] results = client.upload_file(fileBuffer, fileExtension, fileMetaData);
            if (results != null) {
                String fileId;
                int ts;
                String token;
                String fileURl;
                InetSocketAddress socketAddress;
                String groupName = results[0];
                String remoteFile = results[1];
                message.put(GroupField, groupName);
                message.put(RemoteFileField, remoteFile);
                fileId = groupName + StorageClient1.SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR + remoteFile;
                message.put(FileIdField, fileId);
                socketAddress = trackerServer.getInetSocketAddress();
                fileURl = "http://" + socketAddress.getAddress().getHostAddress();
                if (ClientGlobal.g_tracker_http_port != 80) {
                    fileURl += ":" + ClientGlobal.g_tracker_http_port;
                }
                fileURl += "/" + fileId;
                if (ClientGlobal.g_anti_steal_token) {
                    ts = (int) (System.currentTimeMillis() / 1000);
                    token = ProtoCommon.getToken(fileId, ts, ClientGlobal.g_secret_key);
                    fileURl += "?token=" + token + "&ts=" + ts;
                }
                message.put(FileUrlField, fileURl);
                
                return message;
            } else {
                return null;
            }
        }finally {
            FastDFSClientPool.getInstance().releaseStorageClient(client);
        }
    }
    /**
     * 上传本地文件
     * ObjectNode  a = FileUtil.upload("C://Desert.jpg", "沙漠");
     * System.out.println(a.toString());
     *
     * @param fileName 本地文件的绝对路径,如 C://Desert.jpg
     * @param description    文件备注, 可以为空
     * @return {"groupName":"group1","remoteFileName":"/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg"
     * {
     *      "groupName": "healthArchiveGroup",
     *      "remoteFileName": "/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg",
     *      "fid": "group1/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg",
     *      "fileURL": "http://172.19.103.13/healthArchiveGroup/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg"
     * }
     *
     * groupName 及 remoteFileName 可以用于查询在 fastDFS 中文件的信息,如果只是图片显示,可以忽略这两个值。
     * fid 保存了在 fastDFS 上的完整路径,为了避免将来服务器域名发生变更,最好使用本值.服务器的域名另外配置。
     * fileURL 保存了完整的 web 访问路径,为了避免将来服务器域名发生变更,最好不要直接使用本值。
     * 如果需要在下载时,可以显示原始文件名,请在访问file_url时,增加 attname 参数,如:
     *
     * http://host/healthArchiveGroup/M00/00/00/rBFuH1XdIseAUTZZAA1rIuRd3Es062.jpg?attname=a.jpg
     *
     * @throws Exception
     */
    public static ObjectNode upload(String fileName, String description) throws Exception {
        StorageClient client = FastDFSClientPool.getInstance().getStorageClient();
        try {
            NameValuePair[] meta_list;
            meta_list = new NameValuePair[1];
            meta_list[0] = new NameValuePair("description", description == null ? "" : description);
            ObjectMapper objectMapper = new ObjectMapper();
            ObjectNode message = objectMapper.createObjectNode();
            String fileExtName = "";
            if (fileName.contains(".")) {
                fileExtName = fileName.substring(fileName.lastIndexOf(".") + 1);
            } else {
                throw new RuntimeException("上传失败, 文件缺失扩展名.");
            }
            TrackerServer trackerServer = FastDFSClientPool.getInstance().getTrackerServer();
            String[] results = client.upload_file(fileName, fileExtName, meta_list);
            if (results != null) {
                String fileId;
                int ts;
                String token;
                String fileUrl;
                InetSocketAddress inetSockAddr;
                String groupName = results[0];
                String remoteFileName = results[1];
                message.put(GroupField, groupName);
                message.put(RemoteFileField, remoteFileName);
                fileId = groupName + StorageClient1.SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR + remoteFileName;
                message.put(FileIdField, fileId);
                inetSockAddr = trackerServer.getInetSocketAddress();
                fileUrl = "http://" + inetSockAddr.getAddress().getHostAddress();
                if (ClientGlobal.g_tracker_http_port != 80) {
                    fileUrl += ":" + ClientGlobal.g_tracker_http_port;
                }
                fileUrl += "/" + fileId;
                if (ClientGlobal.g_anti_steal_token) {
                    ts = (int) (System.currentTimeMillis() / 1000);
                    token = ProtoCommon.getToken(fileId, ts, ClientGlobal.g_secret_key);
                    fileUrl += "?token=" + token + "&ts=" + ts;
                }
                message.put(FileUrlField, fileUrl);
                
                return message;
            } else {
                return null;
            }
        }finally {
            FastDFSClientPool.getInstance().releaseStorageClient(client);
        }
    }
    /**
     * 下载文件, 返回文件字节数组.
     *
     * @param groupName      在fastdfs上的卷名
     * @param remoteFileName 在fastdfs上的路径
     * @return 文件的字节码
     * @throws Exception
     */
    public static byte[] download(String groupName, String remoteFileName) throws Exception {
        StorageClient client = FastDFSClientPool.getInstance().getStorageClient();
        try {
            byte[] b = client.download_file(groupName, remoteFileName);
            return b;
        }
        finally {
            FastDFSClientPool.getInstance().releaseStorageClient(client);
        }
    }
    /**
     * 下载文件到本地路径上.
     *
     * @param groupName          在 fastDFS 上的卷名
     * @param remoteFileName    在 fastDFS 上的路径
     * @param localPath          本地路径
     *
     * @return 是否下载成功
     */
    public static String download(String groupName, String remoteFileName, String localPath) throws IOException, MyException {
        StorageClient client = FastDFSClientPool.getInstance().getStorageClient();
        try {
            String localFileName = localPath + "\\" + remoteFileName.replaceAll("/", "_");
            client.download_file(groupName, remoteFileName, 0, 0, localFileName);
            return localFileName;
        }finally {
            FastDFSClientPool.getInstance().releaseStorageClient(client);
        }
    }
    /**
     * 删除文件。
     *
     * @param groupName
     * @param remoteFileName
     */
    public static void delete(String groupName, String remoteFileName) throws IOException, MyException {
        StorageClient client = FastDFSClientPool.getInstance().getStorageClient();
        try {
            client.delete_file(groupName, remoteFileName);
        }finally {
            FastDFSClientPool.getInstance().releaseStorageClient(client);
        }
    }
}

+ 15 - 0
patient-co-customization/patient-co-modern-medicine/src/main/resources/config/fdfs_client.conf

@ -0,0 +1,15 @@
connect_timeout = 2
network_timeout = 30
charset = ISO8859-1
http.tracker_http_port = 80
http.anti_steal_token = no
http.secret_key = FastDFS1234567890
#-------------开发环境---------------#
tracker_server = 172.19.103.54:22122
#-------------测试环境---------------#
#tracker_server = 172.19.103.54:22122
#-------------正式环境---------------#
#tracker_server = 192.168.0.239:22122

+ 5 - 0
patient-co-customization/patient-co-modern-medicine/src/main/resources/system.properties

@ -0,0 +1,5 @@
# \u4E0A\u4F20\u6587\u4EF6\u914D\u7F6E
upload_temp_path=/var/local/temp
image_path=/var/local/upload/images
voice_path=/var/local/upload/voice
chat_file_path=/var/local/upload/chat

+ 0 - 5
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/service/manager/family/FamilyMemberService.java

@ -118,11 +118,6 @@ public class FamilyMemberService extends BaseService {
                }else {
                    list.add(map1);
                }
                if(family_relation==0){
                    tem.put(map1);
                }else {
                    list.add(map1);
                }
            }
        }
        return list;