Преглед изворни кода

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

lyr пре 8 година
родитељ
комит
4fd3948cc2

+ 66 - 17
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/HealthEduArticleService.java

@ -1,29 +1,24 @@
package com.yihu.wlyy.service.app.health;
import java.io.File;
import java.util.*;
import com.yihu.wlyy.entity.education.HealthEduArticle;
import com.yihu.wlyy.entity.education.HealthEduArticleOpHistory;
import com.yihu.wlyy.entity.patient.PatientHealthRecordMedication;
import com.yihu.wlyy.entity.education.HealthEduArticlePatient;
import com.yihu.wlyy.repository.education.HealthEduArticleDao;
import com.yihu.wlyy.repository.education.HealthEduArticlePatientDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.util.SystemConf;
import com.yihu.wlyy.util.XMLUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.persistence.DynamicSpecifications;
import org.springside.modules.persistence.SearchFilter;
import org.springside.modules.persistence.SearchFilter.Operator;
import com.yihu.wlyy.entity.education.HealthEduArticle;
import com.yihu.wlyy.entity.education.HealthEduArticlePatient;
import com.yihu.wlyy.repository.education.HealthEduArticleDao;
import com.yihu.wlyy.repository.education.HealthEduArticlePatientDao;
import com.yihu.wlyy.service.BaseService;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
 * 健康教育业务控制类
@ -45,6 +40,60 @@ public class HealthEduArticleService extends BaseService {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 保存福州健康教育文章
     * @param result xml格式
     * @return
     * @throws Exception
     */
    public int saveHealthEduArticles(String result) throws Exception {
        XMLUtil xmlUtil = new XMLUtil();
        Map mapList = xmlUtil.xmltoMap(result);
        String code = mapList.get("").toString();
        String sql = "INSERT INTO wlyy_health_edu_article  " +
                "VALUES(NULL,?,?,?,?,NULL,?,?)";
        int rows = jdbcTemplate.update(sql,code);
        return  rows;
    }
    /**
     * 由请求参数获取福州健康教育文章
     * @param params
     * @return
     * @throws Exception
     */
    public String getHealthEduArticles(Map<String, String> params) throws Exception {
        SystemConf systemConf = SystemConf.getInstance();
        HttpClientUtil httpClientUtil = new HttpClientUtil();
        XMLUtil xmlUtil = new XMLUtil();
//      获取远程地址url 、App Key 和 App secret  
        String prixUrl = SystemConf.getInstance().getYihuOpenPlatformUrl();
//        String prixUrl ="http://apitest.yihu.com.cn/OpenPlatform/cgiBin/1.0/";
        String appId =SystemConf.getInstance().getYihuOpenPlatformAppId();
//        String appId = "9000276";
        String secret = SystemConf.getInstance().getYihuOpenPlatformSecret();
//        String secret = "OKC8BS1KGXTDE9GPP1EO4VYLUXF8DJ7QUP72H613ZXA";
//      请求参数(i健康接口说明文档)正式接口 由prixUrl获取apixUrl
        String apiUrl = prixUrl+"jkjy/JkjyImpl/queryHealtheducationForIHealth";
//      获取加密后参数集合
        Map<String,String> param = httpClientUtil.getSecretParams(params,appId,secret);
//      以xml格式入参param
        String strXml = xmlUtil.map2xml(param);
        String strXML = strXml.replace("QUERY_FORM","xml");
//      拼接请求URL (加密签名+apiUrl)
//      获取返回数据( HTTP post请求,参数需要utf-8编码)
//        String  results = httpClientUtil.httpPost(apiUrl,strXML);
//        String  results = HttpUtil.sendPost(apiUrl, strXML);
        String  results = httpClientUtil.httpPost(apiUrl,param);
        return results;
    }
    /**
     * 查询文章信息
     *

+ 44 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/HttpClientUtil.java

@ -1,6 +1,7 @@
package com.yihu.wlyy.util;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
@ -8,6 +9,7 @@ import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
@ -68,6 +70,48 @@ public class HttpClientUtil {
		return null;
	}
	/**
	 * http post调用方法
	 * @param url
	 * @param xmlData 格式字符串
	 * @return
	 * @throws Exception
	 */
	public String httpPost(String url, String xmlData)throws Exception {
		CloseableHttpClient httpclient = HttpClients.createDefault();
		String strResult="";
		try {
		HttpPost post = new HttpPost(url);
		StringEntity entity = new StringEntity(xmlData);
		post.setEntity(entity);
		post.setHeader("Content-Type", "text/xml;charset=UTF-8");
		HttpResponse response = httpclient.execute(post);
		if(response.getStatusLine().getStatusCode()==200){
			try {
//				读取服务器返回过来的json字符串数据
				strResult = EntityUtils.toString(response.getEntity(),"UTF-8");
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			// 关闭连接,释放资源
			try {
				httpclient.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return strResult;
	}
	/**
	 * 发送get请求
	 * @param url 请求地址

+ 5 - 11
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/SOAPUtil.java

@ -1,15 +1,5 @@
package com.yihu.wlyy.util;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import org.apache.commons.lang3.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
@ -22,6 +12,10 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
public class SOAPUtil {
	private static Logger logger = LoggerFactory.getLogger(SOAPUtil.class);
@ -103,7 +97,7 @@ public class SOAPUtil {
	 * @throws IOException
	 * @throws Exception
	 */
	private static byte[] readInputStream(InputStream inStream) throws IOException {
	public static byte[] readInputStream(InputStream inStream) throws IOException {
		ByteArrayOutputStream outStream = null;
		byte[] data = null;
		try {

+ 3 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/SystemConf.java

@ -365,7 +365,9 @@ public class SystemConf {
	 * 健康之路开放平台渠道号
	 */
	public String getYihuOpenPlatformAppId() {
		return getSystemProperties().getProperty("yihu_OpenPlatform_appId");
		String str = getSystemProperties().getProperty("yihu_OpenPlatform_appId");
		String str1 = getSystemProperties().getProperty("fastdfs_file_url");
		return str;
	}
	/**

+ 4 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/XMLUtil.java

@ -7,14 +7,16 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import org.dom4j.*;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
import org.dom4j.tree.DefaultAttribute;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.util.*;

+ 63 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/health/HealthEduArticlesController.java

@ -0,0 +1,63 @@
package com.yihu.wlyy.web.common.health;
import com.yihu.wlyy.service.app.health.HealthEduArticleService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.HashMap;
import java.util.Map;
/**
 * Created by Reece on 2017/2/13.
 */
@Controller
@RequestMapping(value = "/common")
@Api(description = "获取福州健康教育文章并保存")
public class HealthEduArticlesController extends BaseController{
    @Autowired
    private HealthEduArticleService healthEduArticleService;
    @RequestMapping(value = "getHealthEduArticles",method = RequestMethod.GET)
    @ResponseBody
    public String getHealthEduArticles(
            @RequestParam(value = "医院名称") String hospitalName,
            @RequestParam(value = "开始时间") String startTime,
            @RequestParam(value = "截至时间") String endTime,
            @RequestParam(value = "文章来源 0 医生自创 1健康之路 2 39健康网") String MessageFrom,
            @RequestParam(value = "获取文章数量默认10",defaultValue = "10") String pageSize,
            @RequestParam(value = "展示页数,从0开始",defaultValue = "0") String pageNumber
    ){
        try {
            Map<String,String> params = new HashMap<>();
            params.put("hospitalName",hospitalName);
            params.put("startTime",startTime);
            params.put("endTime",endTime);
            params.put("MessageFrom",MessageFrom);
            params.put("pageSize",pageSize);
            params.put("pageNumber",pageNumber);
//      timestamp必须与服务器时间相差在5分钟以内,否则调用将失败
            String timestamp = Long.toString(System.currentTimeMillis());
            params.put("timestamp",timestamp);
//          获取福州健康教育文章
            String result = healthEduArticleService.getHealthEduArticles(params);
//          保存福州健康教育文章
            int rows = healthEduArticleService.saveHealthEduArticles(result);
            if(rows>0){
                return write(200, "数据导入成功!","data",result);
            }
            return write(-1, "数据导入失败!");
        }catch (Exception e){
            return error(-1, "数据导入失败!");
        }
    }
}