|
@ -65,6 +65,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* Created by Bing on 2021/4/6.
|
|
@ -1812,7 +1813,20 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
* 最近 血糖 血压记录
|
|
|
* 监控
|
|
|
*/
|
|
|
public JSONObject patientMonitoringInfo2(String patient) {
|
|
|
public JSONObject patientMonitoringInfo2(String patient,String date) {
|
|
|
String startDate = "";
|
|
|
String endDate="";
|
|
|
|
|
|
boolean flagDate = false;
|
|
|
|
|
|
if (StringUtils.isNotBlank(date)){
|
|
|
flagDate = true;
|
|
|
startDate = date+" 00:00:00";
|
|
|
endDate = date+" 23:59:59";
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject result = new JSONObject();
|
|
|
result.put("atHome", null);// 居家状态
|
|
|
result.put("location", null);
|
|
@ -1829,6 +1843,12 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
" on dict.code = ord.topic_item COLLATE utf8_unicode_ci and ord.status=" + SecurityMonitoringOrderDO.Status.apply.getType() + " where dict.dict_code='service_item' " +
|
|
|
"and dict.remark='security' and ord.patient='" + patient + "' GROUP BY dict.code ";
|
|
|
List<Map<String, Object>> sqlResult = jdbcTemplate.queryForList(sql);
|
|
|
String dateCreateSql = " ";
|
|
|
String dateOCreateSql = " ";
|
|
|
String dateRSql = " ";
|
|
|
String dateRTSql = " ";
|
|
|
if (flagDate)dateCreateSql = " and create_time >='"+startDate+"' and create_time<= '"+endDate+"' ";
|
|
|
if (flagDate)dateOCreateSql = " and o.create_time >='"+startDate+"' and o.create_time<= '"+endDate+"' ";
|
|
|
for (Map<String, Object> tmp : sqlResult) {
|
|
|
switch (tmp.get("code").toString()) {
|
|
|
case "preventGasLeakage":
|
|
@ -1860,7 +1880,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
if (count > 0) {
|
|
|
result.put("sleep", true);
|
|
|
sql = " select serve_desc from base_security_monitoring_order where topic_item='preventOutOfBed' " +
|
|
|
"and patient='" + patient + "' and `status`=1 order by create_time desc limit 1 ";
|
|
|
"and patient='" + patient + "' and `status`=1 "+dateCreateSql+" order by create_time desc limit 1 ";
|
|
|
List<String> serveDesces = jdbcTemplate.queryForList(sql, String.class);
|
|
|
if (serveDesces.size() > 0) {
|
|
|
result.put("sleepOrderInfo", serveDesces.get(0));
|
|
@ -1874,7 +1894,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
if (count > 0) {
|
|
|
result.put("dailyWater", true);
|
|
|
sql = " select serve_desc from base_security_monitoring_order where topic_item='dailyWater' " +
|
|
|
"and patient='" + patient + "' and `status`=1 order by create_time desc limit 1 ";
|
|
|
"and patient='" + patient + "' and `status`=1 "+dateCreateSql+" order by create_time desc limit 1 ";
|
|
|
List<String> serveDesces = jdbcTemplate.queryForList(sql, String.class);
|
|
|
if (serveDesces.size() > 0) {
|
|
|
result.put("dailyWaterOrderInfo", serveDesces.get(0));
|
|
@ -1888,7 +1908,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
if (count > 0) {
|
|
|
result.put("accessControl", true);
|
|
|
sql = " select serve_desc from base_security_monitoring_order where topic_item='accessControl' " +
|
|
|
"and patient='" + patient + "' and `status`=1 order by create_time desc limit 1 ";
|
|
|
"and patient='" + patient + "' and `status`=1 "+dateCreateSql+" order by create_time desc limit 1 ";
|
|
|
List<String> serveDesces = jdbcTemplate.queryForList(sql, String.class);
|
|
|
if (serveDesces.size() > 0) {
|
|
|
result.put("accessControlOrderInfo", serveDesces.get(0));
|
|
@ -1902,7 +1922,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
if (count > 0) {
|
|
|
result.put("electricControl", true);
|
|
|
sql = " select serve_desc from base_security_monitoring_order where topic_item='electricControl' " +
|
|
|
"and patient='" + patient + "' and `status`=1 order by create_time desc limit 1 ";
|
|
|
"and patient='" + patient + "' and `status`=1 "+dateCreateSql+" order by create_time desc limit 1 ";
|
|
|
List<String> serveDesces = jdbcTemplate.queryForList(sql, String.class);
|
|
|
if (serveDesces.size() > 0) {
|
|
|
result.put("electricControlOrderInfo", serveDesces.get(0));
|
|
@ -1913,17 +1933,23 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
sql = " select count(id) from base_emergency_assistance_order where patient='" + patient + "' and status=" + EmergencyAssistanceDO.Status.apply.getType();
|
|
|
sql = " select count(id) from base_emergency_assistance_order where patient='" + patient + "' "+dateCreateSql+" and status=" + EmergencyAssistanceDO.Status.apply.getType();
|
|
|
Integer counnt = jdbcTemplate.queryForObject(sql, Integer.class);
|
|
|
if (counnt > 0) {
|
|
|
result.put("emeAssistance", true);
|
|
|
}
|
|
|
List<DevicePatientDevice> devices4 = patientDeviceDao.findByUserAndCategoryCode(patient, "4");//手表
|
|
|
|
|
|
if (flagDate)dateRSql = " and record_date>= '"+startDate+"' and record_date<= '"+endDate+"'";
|
|
|
if (flagDate)dateRTSql = " and record_time>= '"+startDate+"' and record_time<= '"+endDate+"'";
|
|
|
//手表佩戴
|
|
|
result.put("wear_flag","");
|
|
|
result.put("wear_flagName","");
|
|
|
|
|
|
result.put("wear_power",0);
|
|
|
result.put("wear_heart",0);
|
|
|
result.put("wear_heartS","");
|
|
|
result.put("wear_steps",0);
|
|
|
result.put("wear_serveDesc","无");
|
|
|
result.put("wear_online",0);
|
|
|
|
|
|
if (devices4.size() > 0) {
|
|
|
result = patientSignTopicInfo(result, patient, "preventLost", devices4.get(0).getDeviceSn(), true);
|
|
@ -1933,15 +1959,190 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
result.put("wear_flag", response.get("wear_flag"));
|
|
|
result.put("wear_flagName", 1==response.getInteger("wear_flag")?"未佩戴":"已佩戴");
|
|
|
}
|
|
|
if (response.containsKey("remaining_power") && response.get("remaining_power") != null) {
|
|
|
result.put("wear_power",response.get("remaining_power").toString());
|
|
|
}
|
|
|
|
|
|
if (response.getBoolean("online")) {//设备在线状态
|
|
|
result.put("wear_online",1);
|
|
|
}
|
|
|
|
|
|
|
|
|
//心率
|
|
|
sql = " select value1,device_sn,CAST(DATE_FORMAT(record_date,'%Y-%m-%d %H:%i:%S') as char) record_date from wlyy_patient_health_index " +
|
|
|
" where type=5 and device_sn='" + devices4.get(0).getDeviceSn() + "' and del=1 "+dateRSql+" ORDER BY record_date DESC ";
|
|
|
sqlResult = jdbcTemplate.queryForList(sql);
|
|
|
if (sqlResult.size() > 0) {
|
|
|
Integer num = sqlResult.stream().mapToInt(obj -> Integer.parseInt(obj.get("value1").toString())).sum();
|
|
|
result.put("wear_heart",(num / sqlResult.size()) + "");
|
|
|
result.put("wear_heartS",JSONObject.toJSONString(sqlResult));
|
|
|
}
|
|
|
|
|
|
//手表步数数据
|
|
|
sql = "select steps from base_patient_step where 1=1 and device_sn='" + devices4.get(0).getDeviceSn() + "' "+dateCreateSql+" order by create_time desc limit 2 ";
|
|
|
sqlResult = jdbcTemplate.queryForList(sql);
|
|
|
if (sqlResult.size() > 0) {
|
|
|
result.put("wear_steps",sqlResult.get(0).get("steps").toString());
|
|
|
}
|
|
|
|
|
|
//检测异常
|
|
|
sql = " select '紧急呼叫' serve_desc ,o.create_time " +
|
|
|
" from base_emergency_assistance_order o " +
|
|
|
" INNER JOIN base_patient p on p.id = o.patient where device_sn='" + devices4.get(0).getDeviceSn() + "' and o.status=1 " +dateOCreateSql+
|
|
|
" UNION " +
|
|
|
" select o.serve_desc ,o.create_time " +
|
|
|
" from base_security_monitoring_order o " +
|
|
|
" INNER JOIN base_patient p on p.id = o.patient where device_sn='" + devices4.get(0).getDeviceSn() + "' and o.status=1 " +dateOCreateSql +
|
|
|
" order by create_time desc limit 1 ";
|
|
|
sqlResult = jdbcTemplate.queryForList(sql);
|
|
|
if (sqlResult.size() > 0) {
|
|
|
result.put("wear_serveDesc",sqlResult.get(0).get("serve_desc").toString());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
patientSignTopicInfo(result, patient, "preventFall", null, true);
|
|
|
|
|
|
result.put("video_serveDesc","无");
|
|
|
result.put("video_emeStatus",0);
|
|
|
|
|
|
List<DevicePatientDevice> video = patientDeviceDao.findByUserAndCategoryCode(patient, "12");//视频
|
|
|
if (video.size()>0){
|
|
|
sql = " select o.serve_desc,o.id " +
|
|
|
" from base_security_monitoring_order o " +
|
|
|
" INNER JOIN base_patient p on p.id = o.patient where device_sn='"+video.get(0).getDeviceSn()+"' and o.status=1 "+dateOCreateSql+" and topic_item = 'preventFall' ORDER BY o.create_time desc limit 1 ";
|
|
|
sqlResult = jdbcTemplate.queryForList(sql);
|
|
|
if (sqlResult.size()>0){
|
|
|
result.put("video_serveDesc",sqlResult.get(0).get("serve_desc").toString());
|
|
|
result.put("video_emeStatus",1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
List<DevicePatientDevice> bjqDevice = patientDeviceDao.findByUserAndCategoryCode(patient, "7");//报警器
|
|
|
|
|
|
result.put("bjq_online",0);
|
|
|
result.put("bjq_serveDesc","未发出主动报警");
|
|
|
result.put("bjq_emeStatus",0);
|
|
|
|
|
|
if (bjqDevice.size()>0){
|
|
|
|
|
|
sql = " select o.id,o.create_time from base_emergency_assistance_order o " +
|
|
|
" INNER JOIN base_patient p on p.id = o.patient where device_sn='"+bjqDevice.get(0).getDeviceSn()+"' and o.status=1 "+dateOCreateSql+" ORDER BY create_time desc limit 1 ";
|
|
|
List<Map<String, Object>> jjbjqList = jdbcTemplate.queryForList(sql);
|
|
|
if (jjbjqList.size()>0) {
|
|
|
result.put("bjq_serveDesc","发出紧急呼叫");
|
|
|
result.put("bjq_emeStatus",1);
|
|
|
}
|
|
|
|
|
|
JSONObject aqgDeviceInfo2 = patientDeviceService.getAqgDeviceInfo2(bjqDevice.get(0).getDeviceSn());
|
|
|
if (null!=aqgDeviceInfo2){
|
|
|
//电量
|
|
|
//在线状态实时获取
|
|
|
if (aqgDeviceInfo2.getBoolean("online")) {//设备在线状态
|
|
|
result.put("bjq_online",1);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
List<DevicePatientDevice> smdDevice = patientDeviceDao.findByUserAndCategoryCode(patient, "13");//睡眠带
|
|
|
result.put("sleep_online",0);
|
|
|
result.put("sleep_serveDesc","无");
|
|
|
result.put("sleep_avgbr",0);
|
|
|
result.put("sleep_avghr",0);
|
|
|
result.put("sleep_yestGetUpTime","无");
|
|
|
result.put("sleep_getUpTime","无");
|
|
|
if (smdDevice.size()>0) {
|
|
|
JSONObject sleepDeviceInfo = patientDeviceService.getSleepDeviceInfo(smdDevice.get(0).getDeviceSn());
|
|
|
|
|
|
if (sleepDeviceInfo.getBooleanValue("success")) {
|
|
|
JSONArray objs = sleepDeviceInfo.getJSONArray("objs");
|
|
|
JSONObject response = objs.getJSONObject(0);
|
|
|
if (response.getBoolean("online")) {//设备在线状态
|
|
|
result.put("sleep_online",1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
sql = " select o.id,p.id patient,p.name,p.idcard,p.residential_area,'22' OrderType,'1' type,o.serve_address,o.serve_desc, " +
|
|
|
" o.status,DATE_FORMAT(o.create_time,'%Y-%m-%d %H:%i:%S') create_time from base_security_monitoring_order o " +
|
|
|
" INNER JOIN base_patient p on p.id = o.patient where device_sn='"+smdDevice.get(0).getDeviceSn()+"' and o.status=1 "+dateOCreateSql+" ORDER BY create_time desc limit 1 ";
|
|
|
sqlResult = jdbcTemplate.queryForList(sql);
|
|
|
if (sqlResult.size()>0) {
|
|
|
result.put("sleep_serveDesc",sqlResult.get(0).get("serve_desc").toString());
|
|
|
}
|
|
|
|
|
|
//起夜次数
|
|
|
sql = "SELECT count(id) FROM base_sleep_night_record WHERE patient = '"+patient+"' AND device_sn = '"+smdDevice.get(0).getDeviceSn()+"' "+dateCreateSql+" and `status` = 1";
|
|
|
Integer getUpNum = jdbcTemplate.queryForObject(sql, Integer.class);
|
|
|
result.put("sleep_upNum",getUpNum);
|
|
|
//呼吸心率曲线
|
|
|
sql = "select avghr,avgbr, DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%S') as create_time from base_sleep_device where patient = '" + patient + "' and device_sn ='" + smdDevice.get(0).getDeviceSn() + "' "+dateCreateSql+" GROUP BY DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%S') ";
|
|
|
List<Map<String, Object>> avghrList = jdbcTemplate.queryForList(sql);
|
|
|
result.put("sleep_avghr_avgbra",JSONObject.toJSONString(avghrList));
|
|
|
|
|
|
|
|
|
sql = "select avghr,avgbr,bucket from base_sleep_device where patient = '" + patient + "' and device_sn ='" + smdDevice.get(0).getDeviceSn() + "' "+dateCreateSql+" order by create_time DESC limit 1";
|
|
|
|
|
|
List<Map<String, Object>> sleepList = jdbcTemplate.queryForList(sql);
|
|
|
if (sleepList.size() > 0) {
|
|
|
//呼吸频率
|
|
|
result.put("sleep_avgbr",sleepList.get(0).get("avgbr").toString());
|
|
|
//心率
|
|
|
result.put("sleep_avghr",sleepList.get(0).get("avghr").toString());
|
|
|
|
|
|
String[] split = sleepList.get(0).get("bucket").toString().split(",");
|
|
|
split = split[split.length - 1].replace("]", "").split("-");
|
|
|
String end = split[split.length - 1].replace("\"", "");
|
|
|
String start = split[0].replace("\"", "");
|
|
|
//昨日睡眠时间
|
|
|
result.put("sleep_yestGetUpTime",start);
|
|
|
//起床时间
|
|
|
result.put("sleep_getUpTime",end);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
List<DevicePatientDevice> fireDevice = patientDeviceDao.findByUserAndCategoryCode(patient, "14");//火灾
|
|
|
|
|
|
result.put("yg_secStatus",0);
|
|
|
result.put("yg_fireCurve","");
|
|
|
result.put("yg_online",1);
|
|
|
if (fireDevice.size()>0) {
|
|
|
sql = " select count(o.id) as total from base_security_monitoring_order o " +
|
|
|
" INNER JOIN base_patient p on p.id = o.patient where device_sn='" + fireDevice.get(0).getDeviceSn() + "' and o.status=1 "+dateOCreateSql+" ORDER BY o.create_time desc ";
|
|
|
Integer ygTotal = jdbcTemplate.queryForObject(sql, Integer.class);
|
|
|
sql = " select value, DATE_FORMAT( record_time, '%H:%i:%S' ) as record_time from base_device_health_index where device_sn='" + fireDevice.get(0).getDeviceSn() + "' "+dateRTSql+" ORDER BY record_time desc";
|
|
|
List<Map<String, Object>> ygList = jdbcTemplate.queryForList(sql);
|
|
|
result.put("yg_secStatus",ygTotal>0?1:0);
|
|
|
result.put("yg_fireCurve",ygList);
|
|
|
}
|
|
|
|
|
|
List<DevicePatientDevice> gasDevice = patientDeviceDao.findByUserAndCategoryCode(patient, "15");//气感
|
|
|
|
|
|
result.put("qg_secStatus",0);
|
|
|
result.put("qg_fireCurve","");
|
|
|
result.put("qg_online",1);
|
|
|
|
|
|
if (gasDevice.size()>0) {
|
|
|
sql = " select count(o.id) as total from base_security_monitoring_order o " +
|
|
|
" INNER JOIN base_patient p on p.id = o.patient where device_sn='"+gasDevice.get(0).getDeviceSn()+"' and o.status=1 "+dateOCreateSql+" ORDER BY o.create_time desc limit 1 ";
|
|
|
Integer qgTotal = jdbcTemplate.queryForObject(sql, Integer.class);
|
|
|
result.put("qg_secStatus",qgTotal>0?1:0);
|
|
|
|
|
|
sql = " select value,DATE_FORMAT( record_time, '%H:%i:%S' ) as record_time from base_device_health_index where device_sn='"+gasDevice.get(0).getDeviceSn()+"' "+dateRTSql+" ORDER BY record_time desc limit 1 ";
|
|
|
List<Map<String, Object>> qgList = jdbcTemplate.queryForList(sql);
|
|
|
result.put("qg_fireCurve",JSON.toJSONString(qgList));
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String healthXYSql ="SELECT value1,value2,value3 FROM wlyy_patient_health_index WHERE `user` = '"+patient+"' AND type = 2 ORDER BY record_date DESC LIMIT 1";
|
|
|
|
|
|
String healthXYSql ="SELECT value1,value2,value3 FROM wlyy_patient_health_index WHERE `user` = '"+patient+"' AND type = 2 "+dateRSql+" ORDER BY record_date DESC LIMIT 1";
|
|
|
List<Map<String, Object>> XY = jdbcTemplate.queryForList(healthXYSql);
|
|
|
|
|
|
String healthXTSql ="SELECT value1,value2,value3,value4 FROM wlyy_patient_health_index WHERE `user` = '"+patient+"' AND type = 1 ORDER BY record_date DESC LIMIT 1";
|
|
|
String healthXTSql ="SELECT value1,value2,value3,value4 FROM wlyy_patient_health_index WHERE `user` = '"+patient+"' AND type = 1 "+dateRSql+" ORDER BY record_date DESC LIMIT 1";
|
|
|
List<Map<String, Object>> XT = jdbcTemplate.queryForList(healthXTSql);
|
|
|
|
|
|
if (XY.size()!= 0) {
|
|
@ -1980,8 +2181,20 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
|
|
|
}else {
|
|
|
result.put("xt",null);
|
|
|
}
|
|
|
String patientDeviceCategoryCode = deviceService.getPatientDeviceCategoryCode(patient);
|
|
|
result.put("deviceShowInfo",patientDeviceCategoryCode);
|
|
|
//String patientDeviceCategoryCode = deviceService.getPatientDeviceCategoryCode(patient);
|
|
|
|
|
|
if (StringUtils.isNotBlank(patient)){
|
|
|
sql = "select Distinct category_code from wlyy_patient_device where user='"+patient+"' and category_code in (7,4,12,13,14,15) and del=0 order by category_code asc";
|
|
|
List<String> categorys = jdbcTemplate.queryForList(sql,String.class);
|
|
|
if (categorys.size()>0){
|
|
|
String categoryStr = categorys.stream().map(String::valueOf).collect(Collectors.joining(","));
|
|
|
result.put("deviceShowInfo",categoryStr);
|
|
|
}else {
|
|
|
result.put("deviceShowInfo",0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|