Browse Source

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

huangwenjie 7 years ago
parent
commit
f6a51d3e34

+ 46 - 0
patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/common/http/HttpClientUtil.java

@ -2,10 +2,12 @@ package com.yihu.hos.device.common.http;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.*;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.client.utils.URLEncodedUtils;
@ -23,6 +25,7 @@ import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -197,4 +200,47 @@ public class HttpClientUtil {
        org.springframework.http.HttpEntity<String> formEntity = new org.springframework.http.HttpEntity<String>(params.toString(), headers);
        restTemplate.put(url, formEntity, String.class);
    }
    /**
     * 发送post请求
     *
     * @param url     请求地址
     * @param params  请求参数
     * @param chatSet 编码格式
     * @return
     */
    public  String post(String url, List<NameValuePair> params, String chatSet) {
        // 创建默认的httpClient实例.
        CloseableHttpClient httpclient = HttpClients.createDefault();
        // 创建httppost
        HttpPost httppost = new HttpPost(url);
        UrlEncodedFormEntity uefEntity;
        try {
            uefEntity = new UrlEncodedFormEntity(params, chatSet);
            httppost.setEntity(uefEntity);
            CloseableHttpResponse response = httpclient.execute(httppost);
            try {
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    return EntityUtils.toString(entity, chatSet);
                }
            } finally {
                response.close();
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭连接,释放资源
            try {
                httpclient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}

+ 23 - 10
patient-co-service/wlyy_device/src/main/java/com/yihu/hos/device/service/DeviceService.java

@ -15,6 +15,10 @@ import net.sf.json.JSONObject;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
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.jdbc.core.JdbcTemplate;
@ -82,6 +86,7 @@ public class DeviceService extends BaseService{
    @Autowired
    private IotDeviceService iotDeviceService;
    private static Logger logger = LoggerFactory.getLogger(DeviceService.class);
    private ObjectMapper objectMapper = new ObjectMapper();
    private Integer aStart;
@ -468,6 +473,19 @@ public class DeviceService extends BaseService{
                String sql = "select count(*) num from wlyy.wlyy_devices where device_code = '"+deviceSn+"'";
                Map<String,Object> deviceCountMap = jdbcTemplate.queryForMap(sql);
                if (Integer.valueOf(String.valueOf(deviceCountMap.get("num")))>0){
                    String url = wlyyService + "healthBank/insertCredits";
                    List<NameValuePair> params = new ArrayList<>();
                    params.add(new BasicNameValuePair("creditsDetail", "{\"tradeType\":\"HEALTH_TASK\",\"flag\":\"MEASURE\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+result.getUser()+"\",\"hospital\":\"350205\"}"));
                    String response = HttpClientUtil.post(url, params, "UTF-8");
                    System.out.println(response);
                    com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
                    String status = jsonObject.getString("status");
                    if (!"200".equals(status)){
                        logger.error(jsonObject.getString("msg"));
                    }
                /*if (Integer.valueOf(String.valueOf(deviceCountMap.get("num")))>0){
                    String url = wlyyService + "/healthBank/insertCredits";
                    org.json.JSONObject params = new org.json.JSONObject();
                    String creditDetail = "{\"tradeType\":\"HEALTH_TASK\",\"flag\":\"MEASURE\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+result.getUser()+"\",\"hospital\":\""+patient.getTown()+"\"}";
@ -475,18 +493,12 @@ public class DeviceService extends BaseService{
                    String response = HttpClientUtil.postBody(url, params);
                    com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
                    String status = jsonObject.getString("status");
                    if ("200".equals(status)){
                        List<Map<String,Object>> list = (List<Map<String,Object>>)jsonObject.get("detailModelList");
                        if (list!=null && list.size()>0){
                            String integrate = String.valueOf(list.get(0).get("integrate"));
                            //@TODO 调用发送微信模板接口
                            //这里调整到新增积分的接口中发送微信模板
                        }
                    if (!"200".equals(status)){
                        logger.error(jsonObject.getString("msg"));
                    }
                }*/
                }
	            //血糖、血压数据需校验,如果超标,需要发送消息给医生
                //血糖、血压数据需校验,如果超标,需要发送消息给医生
	            if (1 == deviceType || 2 == deviceType) {
		            verifyHealthIndex(result);
		            //发送华三demo推送
@ -505,6 +517,7 @@ public class DeviceService extends BaseService{
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return Result.success("Device data incoming success");

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/PatientDeviceService.java

@ -1163,7 +1163,7 @@ public class PatientDeviceService extends BaseService {
    public Map<String,Object> getDeviceByDeviceSn(String deviceSn)throws Exception {
        Map<String,Object> map  = new HashedMap();
        String sql = "SELECT d.id,d.device_name deviceName,d.device_model deviceMode,d.sim,d.device_activity_type deviceActivityType,e.is_multi_user isMultiUser,e.category_code as deviceType,e.multi_user multiUser FROM wlyy_devices d LEFT JOIN dm_device e ON d.device_model = e.model WHERE d.device_code='"+deviceSn+"'";
        String sql = "SELECT d.id,d.device_name deviceName,d.device_model deviceMode,d.sim,d.device_activity_type deviceActivityType,e.is_multi_user isMultiUser,e.category_code as deviceType,e.multi_user multiUser,e.id as device_id FROM wlyy_devices d LEFT JOIN dm_device e ON d.device_model = e.model WHERE d.device_code='"+deviceSn+"'";
        List<Map<String,Object>> mapSqlList = jdbcTemplate.queryForList(sql);
        if (mapSqlList!=null && mapSqlList.size()>0){
            map = mapSqlList.get(0);

+ 1 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/WlyyDeviceDetailService.java

@ -17,6 +17,7 @@ import java.util.List;
/**
 * 设备管理
 * zd
 */
@Component
@Transactional(rollbackFor = Exception.class)