|
@ -3,17 +3,27 @@ package com.yihu.jw.care.service;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.jw.care.config.YsConfig;
|
|
|
import com.yihu.jw.care.dao.device.PatientDeviceDao;
|
|
|
import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
|
import com.yihu.jw.entity.care.device.DevicePatientDevice;
|
|
|
import com.yihu.jw.entity.util.AesEncryptUtils;
|
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
import com.yihu.jw.util.common.LatitudeUtils;
|
|
|
import com.yihu.jw.util.http.HttpClientUtil;
|
|
|
import com.yihu.jw.utils.encode.Base64;
|
|
|
import org.apache.commons.lang3.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.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import javax.crypto.Cipher;
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.security.Security;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@ -24,6 +34,16 @@ public class YsDeviceService {
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(YsDeviceService.class);
|
|
|
private Map<String,String> msgType = new HashMap<>();
|
|
|
@Value("${cloudCare.url}")
|
|
|
private String cloudCareUrl;
|
|
|
@Autowired
|
|
|
private PatientDeviceDao patientDeviceDao;
|
|
|
@Autowired
|
|
|
private BasePatientDao patientDao;
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
|
private HttpClientUtil httpClientUtil;
|
|
|
|
|
|
/**
|
|
|
* 消息推送
|
|
@ -53,12 +73,79 @@ public class YsDeviceService {
|
|
|
String decodeStr = messageDecrypt(message,YsConfig.msgDataKey);
|
|
|
result = JSONObject.parseObject(decodeStr);
|
|
|
JSONArray tmpArr = result.getJSONObject("eps").getJSONArray("alert");
|
|
|
boolean fallFlag = false;
|
|
|
String deviceSN = null;
|
|
|
for (int i=0;i<tmpArr.size();i++){
|
|
|
JSONObject tmpObj = tmpArr.getJSONObject(i);
|
|
|
String msgType = tmpObj.getString("msgType");
|
|
|
if (this.msgType.containsKey(msgType)){
|
|
|
tmpObj.put("msgTypeName",this.msgType.get(msgType));
|
|
|
}
|
|
|
if ("10005".equals(msgType)){//报警消息
|
|
|
String bodyStr = tmpObj.getString("body");
|
|
|
if (StringUtils.isNotBlank(bodyStr)){
|
|
|
JSONObject bodyJsonObj = JSONObject.parseObject(bodyStr);
|
|
|
if (bodyJsonObj!=null&&bodyJsonObj.containsKey("body")){
|
|
|
JSONObject bodyJsonObj2 = bodyJsonObj.getJSONObject("body");
|
|
|
if (bodyJsonObj2!=null&&bodyJsonObj2.containsKey("alarmType")){
|
|
|
String alarmType = bodyJsonObj2.getString("alarmType");
|
|
|
if ("tumble_detection".equals(alarmType)){//tumble_detection跌倒类型 //有人出现SmartHumanDet
|
|
|
fallFlag = true;
|
|
|
deviceSN = bodyJsonObj2.getString("devSerial");//设备SN
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (fallFlag){//发起安防工单
|
|
|
String lat = "";
|
|
|
String lon = "";
|
|
|
List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByDeviceSn(deviceSN);
|
|
|
if (devicePatientDeviceDos.size()>0){
|
|
|
DevicePatientDevice deviceDO = devicePatientDeviceDos.get(0);
|
|
|
Map<String, String> json = null;
|
|
|
if (org.apache.commons.lang.StringUtils.isNotBlank(deviceDO.getSosAddress())) {
|
|
|
json = LatitudeUtils.getGeocoderLatitude(deviceDO.getSosAddress().replace("G.", "").replace("(糖友网)", "").replace("(高友网)", ""));
|
|
|
}
|
|
|
if (json != null) {
|
|
|
lat = json.get("lat").toString();
|
|
|
lon = json.get("lng").toString();
|
|
|
}
|
|
|
|
|
|
BasePatientDO patientDO = patientDao.findById(deviceDO.getUser());
|
|
|
String url = cloudCareUrl+"/cloudCare/noLogin/security/createOrder";
|
|
|
Map map = new HashMap<String, String>();
|
|
|
map = new HashMap();
|
|
|
String sql ="select DISTINCT item.org_code,item.org_name\n" +
|
|
|
" from base_service_package_sign_record sr,base_service_package_record pr,base_service_package_item item ,base_service_package pack\n" +
|
|
|
"where pr.patient = '"+patientDO.getId()+"' and sr.id = pr.sign_id and pr.service_package_id = item.service_package_id \tand item.`code`='preventFall' and item.service_package_id = pack.id \n" +
|
|
|
" and pack.del=1";
|
|
|
List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql);
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("patient",patientDO.getId());
|
|
|
jsonObject.put("patientName",patientDO.getName());
|
|
|
jsonObject.put("patientPhone",patientDO.getMobile());
|
|
|
jsonObject.put("serveDesc","疑似跌倒!");
|
|
|
jsonObject.put("hospital",sqlResult.get(0).get("org_code"));
|
|
|
jsonObject.put("serveAddress",deviceDO.getAddress());
|
|
|
jsonObject.put("serveLat",lat);
|
|
|
jsonObject.put("serveLon",lon);
|
|
|
jsonObject.put("topicItem","preventFall");
|
|
|
JSONObject jsonObjectParam = new JSONObject();
|
|
|
jsonObjectParam.put("order", jsonObject);
|
|
|
map.put("jsonData", jsonObjectParam.toJSONString());
|
|
|
map.put("orderSource", 2);
|
|
|
map.put("warnStr", "疑似跌倒");
|
|
|
|
|
|
String content = com.alibaba.fastjson.JSONObject.toJSONString(map);
|
|
|
String postParams = AesEncryptUtils.agEncrypt(content);
|
|
|
String response = httpClientUtil.postBodyRawForm(url,postParams);
|
|
|
result = com.alibaba.fastjson.JSONObject.parseObject(response);
|
|
|
JSONObject jsonObjectData =JSONObject.parseObject(AesEncryptUtils.agDecrypt(result.getString("data")));
|
|
|
System.out.println(jsonObjectData.toJSONString());
|
|
|
}
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
}
|