浏览代码

Merge branch 'dev' of http://192.168.1.220:10080/Amoy/patient-co-management into dev

wangzhinan 7 年之前
父节点
当前提交
93b057578f

+ 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)

+ 0 - 16
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/task/PushMsgTask.java

@ -823,14 +823,6 @@ public class PushMsgTask {
                keyword3.setColor("#000000");
                keyword3.setValue(json.getString("keyword3"));
                m.put("keyword3", keyword3);
                WechatTemplateData keyword4 = new WechatTemplateData();
                keyword4.setColor("#000000");
                keyword4.setValue(json.getString("keyword4"));
                m.put("keyword4", keyword4);
                WechatTemplateData keyword5 = new WechatTemplateData();
                keyword5.setColor("#000000");
                keyword5.setValue(json.getString("keyword5"));
                m.put("keyword5", keyword5);
            }else if (type == 23) {//健康银行积分提醒
                if (json.has("url")) {
                    temp.setUrl(url + json.getString("url"));
@ -848,14 +840,6 @@ public class PushMsgTask {
                keyword3.setColor("#000000");
                keyword3.setValue(json.getString("keyword3"));
                m.put("keyword3", keyword3);
                WechatTemplateData keyword4 = new WechatTemplateData();
                keyword4.setColor("#000000");
                keyword4.setValue(json.getString("keyword4"));
                m.put("keyword4", keyword4);
                WechatTemplateData keyword5 = new WechatTemplateData();
                keyword5.setColor("#000000");
                keyword5.setValue(json.getString("keyword5"));
                m.put("keyword5", keyword5);
            }
            temp.setData(m);

+ 5 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/device/DoctorDeviceController.java

@ -15,6 +15,7 @@ import com.yihu.wlyy.service.app.team.AdminTeamService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.third.health.bank.CreditLogService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.web.BaseController;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import io.swagger.annotations.Api;
@ -135,13 +136,14 @@ public class DoctorDeviceController extends BaseController {
				first = templateConfig.getFirst();
				first = first.replace("key1",(deviceName==null?"":deviceName));
				remark = templateConfig.getRemark();
				String keyword1 = templateConfig.getKeyword1();
				sendJson.put("keyword1", keyword1);
				sendJson.put("keyword2", device.getCzrq());
				sendJson.put("keyword1", deviceName);
				sendJson.put("keyword2", DateUtil.dateToStrLong(device.getCzrq()));
				sendJson.put("keyword3", templateConfig.getKeyword3());
				sendJson.put("first", first);
				sendJson.put("remark", remark);
				sendJson.put("url", templateConfig.getUrl());//带参数的模板跳转链接
				System.out.println(sendJson.toString());
				pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 22, openId, name, sendJson);
//	                    //发送代理人
//	                    jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient, openId);

+ 48 - 36
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/device/PatientDeviceController.java

@ -15,14 +15,18 @@ import com.yihu.wlyy.service.app.health.PatientHealthIndexService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.third.health.bank.CreditLogService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.web.BaseController;
import com.yihu.wlyy.web.doctor.device.DoctorDeviceController;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
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.data.domain.Page;
@ -46,6 +50,7 @@ import java.util.Map;
@RequestMapping(value = "patient/device")
@Api(value = "患者设备管理", description = "患者设备管理")
public class PatientDeviceController extends BaseController {
    private static Logger logger = LoggerFactory.getLogger(PatientDeviceController.class);
    @Autowired
    private PatientDeviceService patientDeviceService;
@ -222,8 +227,8 @@ public class PatientDeviceController extends BaseController {
            if (deviceDetail!=null){
                //修改设备表中{"1":"0", "2":"0"}的绑定次数 和其他绑定信息,
                wlyyDeviceDetailService.updateAfterBinding(device.getDeviceSn(),device.getUserIdcard(),device.getUserType(),new Date(),flag);
                Patient patient = patientService.findByCode(device.getUser());
                if (flag){
                    Patient patient = patientService.findByCode(device.getUser());
                    String creditDetail = "{\"tradeType\":\"HEALTH_TASK\",\"flag\":\"BIND\",\"tradeDirection\":1,\"status\":1,\"patientId\":\""+device.getUser()+"\",\"hospital\":\""+patient.getTown()+"\"}";
                    com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(creditDetail);
                    com.alibaba.fastjson.JSONObject response = creditLogService.insert(jsonObject);
@ -236,44 +241,51 @@ public class PatientDeviceController extends BaseController {
                            String flagType = String.valueOf(list.get(0).get("flag"));
                            //@TODO 调用发送微信模板接口
	                        //Patient people = patientDao.findByCode(device.getUser());
	                        String openId = patient.getOpenid();
	                        String name = patient.getName();
	                        org.json.JSONObject sendJson = new org.json.JSONObject();
	                        String first = "";
	                        String remark = "";
	                        String deviceName = device.getDeviceName();
	                        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_patient_bind_device","bdsb");
	                        first = templateConfig.getFirst();
	                        first = first.replace("key1",(deviceName==null?"":deviceName));
	                        remark = templateConfig.getRemark();
	                        String keyword1 = templateConfig.getKeyword1();
	                        sendJson.put("keyword1", keyword1);
	                        sendJson.put("keyword2", device.getCzrq());
	                        sendJson.put("first", first);
	                        sendJson.put("remark", remark);
	                        sendJson.put("url", templateConfig.getUrl());//带参数的模板跳转链接
	                        pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 22, openId, name, sendJson);
//	                        //发送代理人
//	                        jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient, openId);
//	                        if (jsonArray != null && jsonArray.length() > 0) {
//		                        for (int i = 0; i < jsonArray.length(); i++) {
//			                        org.json.JSONObject j = jsonArray.getJSONObject(i);
//			                        Patient member = (Patient) j.get("member");
//			                        int start = url.indexOf("&toUser=");
//			                        int end = url.indexOf("&", start + 1);
//			                        String touser = url.substring(start, end);
//			                        url = url.replace(touser, "&toUser=" + member.getCode());
//			                        //name患者姓名
//			                        sendJson.put("first", weiXinOpenIdUtils.getTitleMes(people, (int) j.get("relation"), name) + first);
//			                        sendJson.put("url", url);
//			                        pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 19, member.getOpenid(), name, sendJson);
//		                        }
//	                        }
                        }
                    }
                }
    
                try {
                    String openId = patient.getOpenid();
                    String name = patient.getName();
        
                    org.json.JSONObject sendJson = new org.json.JSONObject();
                    String first = "";
                    String remark = "";
                    String deviceName = device.getDeviceName();
                    WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_patient_bind_device","bdsb");
                    first = templateConfig.getFirst();
                    first = first.replace("key1",(deviceName==null?"":deviceName));
                    remark = templateConfig.getRemark();
        
                    sendJson.put("keyword1", deviceName);
                    sendJson.put("keyword2", DateUtil.dateToStrLong(device.getCzrq()));
                    sendJson.put("keyword3", templateConfig.getKeyword3());
                    sendJson.put("first", first);
                    sendJson.put("remark", remark);
                    sendJson.put("url", templateConfig.getUrl());//带参数的模板跳转链接
                    System.out.println(sendJson.toString());
                    pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 22, openId, name, sendJson);
//	                    //发送代理人
//	                    jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient, openId);
//	                    if (jsonArray != null && jsonArray.length() > 0) {
//		                    for (int i = 0; i < jsonArray.length(); i++) {
//			                    org.json.JSONObject j = jsonArray.getJSONObject(i);
//			                    Patient member = (Patient) j.get("member");
//			                    int start = url.indexOf("&toUser=");
//			                    int end = url.indexOf("&", start + 1);
//			                    String touser = url.substring(start, end);
//			                    url = url.replace(touser, "&toUser=" + member.getCode());
//			                    //name患者姓名
//			                    sendJson.put("first", weiXinOpenIdUtils.getTitleMes(people, (int) j.get("relation"), name) + first);
//			                    sendJson.put("url", url);
//			                    pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 19, member.getOpenid(), name, sendJson);
//		                    }
//	                    }
                }catch (Exception e){
                    logger.info("设备绑定微信模板消息发送失败:"+e.getMessage());
//	                        e.printStackTrace();
                }
            }

+ 5 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/health/bank/CreditsLogController.java

@ -91,12 +91,15 @@ public class CreditsLogController extends BaseController {
            JSONObject result = service.insert(object);
    
            String status = result.getString("status");
    
            logger.info("健康银行居民新增积分:"+result.toString());
            if ("200".equals(status)){
                List<Map<String,Object>> list = (List<Map<String,Object>>)result.get("detailModelList");
                if (list!=null && list.size()>0){
                    //积分
                    String integrate = String.valueOf(list.get(0).get("integrate"));
                    String patientid = String.valueOf(list.get(0).get("patientId"));
                    String total = String.valueOf(list.get(0).get("total"));
                    
                    
                    try {
@ -117,11 +120,13 @@ public class CreditsLogController extends BaseController {
    
                        sendJson.put("keyword1", integrate);
                        sendJson.put("keyword2", DateUtil.getStringDate());
                        sendJson.put("keyword3", total);
                        sendJson.put("first", first);
                        sendJson.put("remark", remark);
                        url = templateConfig.getUrl();
                        url = url.replace("key1",(integrate==null?"":integrate));
                        sendJson.put("url", url);//带参数的模板跳转链接
                        System.out.println(sendJson.toString());
                        pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 23, openId, name, sendJson);
//	                    //发送代理人
//	                    jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient, openId);