|
@ -61,6 +61,7 @@ import javax.annotation.PostConstruct;
|
|
|
import java.text.MessageFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Component
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@ -172,9 +173,15 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
|
|
|
* 燃气浓度
|
|
|
* @param patient
|
|
|
*/
|
|
|
public List<Map<String,Object>> gasConcentration(String patient,String date){
|
|
|
public List<Map<String,Object>> gasConcentration(String patient,String date,String deviceSn){
|
|
|
String sql = "SELECT r.value,r.create_time from wlyy_patient_device pd,base_device_health_index r " +
|
|
|
"WHERE pd.device_sn = r.device_sn and pd.`user` = '"+patient+"' ";
|
|
|
"WHERE pd.device_sn = r.device_sn ";
|
|
|
if (StringUtils.isNotBlank(patient)){
|
|
|
sql +=" and pd.`user` = '"+patient+"' ";
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(deviceSn)){
|
|
|
sql +=" and r.device_sn = '"+deviceSn+"' ";
|
|
|
}
|
|
|
|
|
|
sql += " and pd.category_code='14' and r.create_time>'"+date+" 00:00:00' and r.create_time<'"+date+" 23:59:59' ORDER BY r.create_time desc ";
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
@ -209,6 +216,11 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
|
|
|
String userType = devicePatientDevice.getUserType();
|
|
|
String sosAddress = null;
|
|
|
String url ="";
|
|
|
String sql = " select count(id) from wlyy_patient_device where user='"+devicePatientDevice.getUser()+"' and device_sn='sn' and del=0 ";
|
|
|
if (jdbcTemplate.queryForObject(sql,Integer.class)>0){
|
|
|
return -5;
|
|
|
}
|
|
|
|
|
|
if (userType == null) {
|
|
|
userType = "-1";
|
|
|
devicePatientDevice.setUserType("-1");
|
|
@ -247,7 +259,7 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
|
|
|
|
|
|
//V1.0.0 监控器、报警器、燃气传感器 烟雾传感器支持一个设备绑定多个居民
|
|
|
//监控器 12 报警器 7 14 15
|
|
|
if ("12".equals(type) || "14".equals(type) || "15".equals(type) || "7".equals(type) ) {
|
|
|
if ("12".equals(type) || "14".equals(type) || "15".equals(type)) {
|
|
|
if (devicePatientDevice.getUser().equals(device.getUser())) {
|
|
|
System.out.println("居民已经绑定此sn码:"+sn);
|
|
|
return -5;
|
|
@ -902,12 +914,11 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
|
|
|
result.put(ResponseContant.resultFlag,ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg,"居民未绑定该设备");
|
|
|
}else {
|
|
|
String sql = "select dd.photo,pd.device_sn,dd.brands,dd.category_code,dd.model,pd.device_name,date_format(pd.czrq,'%Y-%m-%d %H:%i:%S' ) deviceTime " +
|
|
|
"from dm_device dd INNER JOIN wlyy_patient_device pd on dd.category_code = pd.category_code INNER JOIN wlyy_devices wd on dd.model = wd.device_model and pd.device_sn = wd.device_code \n" +
|
|
|
"where 1=1 and pd.del=0 and pd.device_sn ='"+deviceSn+"' group by pd.user";
|
|
|
String sql = "select dd.photo,GROUP_CONCAT( p.name) as patientName,pd.device_sn,dd.brands,dd.category_code,dd.model,pd.device_name,date_format(pd.czrq,'%Y-%m-%d %H:%i:%S' ) deviceTime " +
|
|
|
"from dm_device dd INNER JOIN wlyy_patient_device pd on dd.category_code = pd.category_code INNER JOIN base_patient p on p.id = pd.user \n" +
|
|
|
"where 1=1 and pd.del=0 and pd.device_sn ='"+deviceSn+"' group by pd.device_sn";
|
|
|
Map<String,Object> devInfo = jdbcTemplate.queryForMap(sql);
|
|
|
devInfo.put("patient",patient);
|
|
|
devInfo.put("patientName",patientDO.getName());
|
|
|
devInfo.put("sosContactsDOS",new ArrayList<>());
|
|
|
if ("4".equals(device.getCategoryCode())||"7".equals(device.getCategoryCode())){
|
|
|
devInfo.put("sosContactsDOS",contactsService.getPatientSosContacts(patient));
|
|
@ -919,9 +930,13 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
|
|
|
case "2"://血糖设备
|
|
|
break;
|
|
|
case "4"://手表 围栏与轨迹
|
|
|
if (StringUtils.isBlank(day)){
|
|
|
day = DateUtil.getStringDateShort();
|
|
|
}
|
|
|
devInfoObj = securityMonitoringOrderService.patientSignTopicInfo(devInfoObj,patient,"preventLost");
|
|
|
|
|
|
//轨迹动态
|
|
|
JSONArray locations = getX1Locations(deviceSn,day.replace("-",""));
|
|
|
devInfoObj.put("routes",locations);
|
|
|
break;
|
|
|
case "7"://报警器 紧急工单
|
|
|
break;
|
|
@ -942,13 +957,13 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
|
|
|
if (StringUtils.isBlank(day)){
|
|
|
day = DateUtil.getStringDateShort();
|
|
|
}
|
|
|
List<Map<String,Object>> listTmp = gasConcentration(patient,day);
|
|
|
List<Map<String,Object>> listTmp = gasConcentration(patient,day,deviceSn);
|
|
|
devInfoObj.put("monitorInfo",listTmp);
|
|
|
devInfoObj.put("day",day);
|
|
|
securityMonitoringOrderService.preventGasLeakage(devInfoObj,patient,false);
|
|
|
break;
|
|
|
case "15"://烟感报警器 获取最新浓度
|
|
|
securityMonitoringOrderService.preventFire(devInfoObj,patient,false);
|
|
|
securityMonitoringOrderService.preventFire(devInfoObj,patient,deviceSn,false);
|
|
|
devInfoObj.put("day",DateUtil.getStringDateShort());
|
|
|
break;
|
|
|
}
|
|
@ -975,13 +990,13 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
|
|
|
}else{
|
|
|
switch (device.getCategoryCode()){
|
|
|
case "1"://血压设备
|
|
|
result = getHealthIndex(result,deviceSn,patient,page,pageSize);
|
|
|
result = getHealthIndex(result,1,deviceSn,patient,page,pageSize);
|
|
|
break;
|
|
|
case "2"://血糖设备
|
|
|
result = getHealthIndex(result,deviceSn,patient,page,pageSize);
|
|
|
result = getHealthIndex(result,2,deviceSn,patient,page,pageSize);
|
|
|
break;
|
|
|
default://安防设备
|
|
|
result = getEmeWarn(result,deviceSn,patient,page,pageSize);
|
|
|
result = getEmeWarn(result,deviceSn,null,page,pageSize);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@ -991,29 +1006,105 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public JSONObject getHealthIndex(JSONObject result,String deviceSn,String patient,Integer page,Integer pageSize){
|
|
|
String sqlCount = "select count(id) from wlyy_patient_health_index where user ='"+patient+"' and device_sn='"+deviceSn+"' " +
|
|
|
" and del=1 ";
|
|
|
String sql = "select *,CAST(DATE_FORMAT(record_date,'%Y-%m-%d %H:%i:%S') as char) record_date from wlyy_patient_health_index where user ='"+patient+"' and device_sn='"+deviceSn+"' " +
|
|
|
" and del=1 order by record_date desc limit "+page*pageSize+","+pageSize;
|
|
|
long count = jdbcTemplate.queryForObject(sqlCount,long.class);
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
for (Map<String,Object> tmp:list){
|
|
|
Integer type =Integer.parseInt(tmp.get("type").toString());
|
|
|
String value1 = tmp.get("value1")==null?null:tmp.get("value1").toString();
|
|
|
String value2 = tmp.get("value2")==null?null:tmp.get("value2").toString();
|
|
|
String value3 = tmp.get("value3")==null?null:tmp.get("value3").toString();
|
|
|
String value4 = tmp.get("value4")==null?null:tmp.get("value4").toString();
|
|
|
String value5 = tmp.get("value5")==null?null:tmp.get("value5").toString();
|
|
|
String value6 = tmp.get("value6")==null?null:tmp.get("value6").toString();
|
|
|
String value7 = tmp.get("value7")==null?null:tmp.get("value7").toString();
|
|
|
com.alibaba.fastjson.JSONArray errorInfo = healthIndexUtil.verifyHealthIndex(type,value1,value2,value3,value4,value5,value6,value7);
|
|
|
tmp.put("errorInfo",errorInfo);
|
|
|
public JSONObject getHealthIndex(JSONObject result,Integer type,String deviceSn,String patient,Integer page,Integer pageSize){
|
|
|
page = page>0?page-1:0;
|
|
|
Long count =0l;
|
|
|
PageRequest pageRequest = new PageRequest(page, pageSize);
|
|
|
result.put("dataList",new ArrayList<>());
|
|
|
if (type == 1) {
|
|
|
List<Object> re = new ArrayList<>();
|
|
|
String countSql =" select count(Distinct DATE_FORMAT(a.record_date,'%Y-%m-%d')) from wlyy_patient_health_index a where a.user = '"+patient+"' " +
|
|
|
" and a.type=1 and a.device_sn='"+deviceSn+"' and a.del = '1' ";
|
|
|
count = jdbcTemplate.queryForObject(countSql,Long.class);
|
|
|
String sql =" select DATE_FORMAT(a.record_date,'%Y-%m-%d') from wlyy_patient_health_index a where a.user = '"+patient+"' " +
|
|
|
" and a.type=1 and a.device_sn='"+deviceSn+"' and a.del = '1' group by DATE_FORMAT(a.record_date,'%Y-%m-%d') order by DATE_FORMAT(a.record_date,'%Y-%m-%d') desc limit "+pageRequest.getOffset()+" ,"+pageRequest.getPageSize();
|
|
|
List<String> dateList = jdbcTemplate.queryForList(sql,String.class);
|
|
|
if (dateList != null && dateList.size() > 0) {
|
|
|
for (String dateString : dateList) {
|
|
|
com.alibaba.fastjson.JSONObject obj = healthIndexService.getPatientXT_Json(patient, dateString);
|
|
|
if (obj != null) {
|
|
|
re.add(obj);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
result.put("dataList",re);
|
|
|
}
|
|
|
else if (type == 2){
|
|
|
JSONArray re = new JSONArray();
|
|
|
// 排序
|
|
|
String countSql =" select count(distinct user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date ) from wlyy_patient_health_index a where a.user = '"+patient+"' " +
|
|
|
" and a.type=2 and a.device_sn='"+deviceSn+"' and a.del = '1' ";
|
|
|
count = jdbcTemplate.queryForObject(countSql,Long.class);
|
|
|
String sql = "SELECT " +
|
|
|
"MIN(id) id" +
|
|
|
", user" +
|
|
|
",value1" +
|
|
|
",value2" +
|
|
|
",value3" +
|
|
|
",value4" +
|
|
|
",value5" +
|
|
|
",value6" +
|
|
|
",value7" +
|
|
|
",device_sn" +
|
|
|
",type" +
|
|
|
",record_date" +
|
|
|
",sort_date" +
|
|
|
",czrq as createDate" +
|
|
|
",min(czrq) czrq " +
|
|
|
" from wlyy_patient_health_index " +
|
|
|
" WHERE `user` = '" + patient + "' " +
|
|
|
" and type =" + type +" "+
|
|
|
" and device_sn='"+deviceSn+"' "+
|
|
|
" and del = '1' " +
|
|
|
" GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date " +
|
|
|
" order by record_date desc ,sort_date desc limit " + pageRequest.getOffset() + " ," + pageRequest.getPageSize() + " ";
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
for (Map<String, Object> map : list) {
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("id", map.get("id"));
|
|
|
json.put("healthindexid", map.get("id"));
|
|
|
json.put("patient", map.get("user"));
|
|
|
json.put("value1", map.get("value1"));
|
|
|
json.put("value2", map.get("value2"));
|
|
|
json.put("value3", map.get("value3"));
|
|
|
json.put("value4", map.get("value4"));
|
|
|
json.put("value5", map.get("value5"));
|
|
|
json.put("value6", map.get("value6"));
|
|
|
json.put("value7", map.get("value7"));
|
|
|
json.put("deviceSn", map.get("device_sn") == null ? "" : map.get("device_sn"));
|
|
|
json.put("type", map.get("type"));
|
|
|
|
|
|
Date date = (Date) map.get("record_date");
|
|
|
if (type == 2) {
|
|
|
json.put("date", DateUtil.dateToStr(date, DateUtil.YYYY_MM_DD_HH_MM_SS));
|
|
|
} else {
|
|
|
json.put("date", DateUtil.dateToStr(date, DateUtil.YYYY_MM_DD));
|
|
|
}
|
|
|
json.put("sortDate", map.get("sort_date"));
|
|
|
json.put("czrq", map.get("czrq"));
|
|
|
//是否为补传数据(设备上传且测量时间和创建时间不匹配)
|
|
|
Date recordDate = (Date)map.get("record_date");
|
|
|
Date createDate = (Date) map.get("createDate");
|
|
|
String recordTime = DateUtil.dateToStr(recordDate,DateUtil.YYYY_MM_DD);
|
|
|
String createTime = DateUtil.dateToStr(createDate,DateUtil.YYYY_MM_DD);
|
|
|
if (map.get("device_sn") == null){
|
|
|
json.put("isSupplement",0);
|
|
|
}else {
|
|
|
if (recordTime.compareToIgnoreCase(createTime)==0){
|
|
|
json.put("isSupplement",0);
|
|
|
}else {
|
|
|
json.put("isSupplement",1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
re.put(json);
|
|
|
}
|
|
|
result.put("dataList",re);
|
|
|
}
|
|
|
|
|
|
result.put("total",count);
|
|
|
result.put("page",page+1);
|
|
|
result.put("pageSize",pageSize);
|
|
|
result.put("dataList",list);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@ -1024,15 +1115,23 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
|
|
|
" and ord.patient='"+patient+"' " +
|
|
|
"UNION All " +
|
|
|
"select count(ord.id) as total from base_security_monitoring_order ord where ord.device_sn='"+deviceSn+"' " +
|
|
|
" and ord.patient='"+patient+"' )A ";
|
|
|
long count = jdbcTemplate.queryForObject(sqlCount,long.class);
|
|
|
" {{patient}} )A ";
|
|
|
String sql = "select '20' as OrderType,ord.id,ord.patient,ord.patient_name,ord.doctor,ord.status,ord.doctor_name," +
|
|
|
"'紧急呼叫' as serve_desc,DATE_FORMAT(ord.create_time,'%Y-%m-%d %H:%i:%S') create_time " +
|
|
|
"from base_emergency_assistance_order ord where ord.device_sn='"+deviceSn+"' and ord.patient='"+patient+"' " +
|
|
|
"UNION " +
|
|
|
"select '22' as 'OrderType',ord.id,ord.patient,ord.patient_name,ord.doctor,ord.status,ord.doctor_name," +
|
|
|
"ord.serve_desc,DATE_FORMAT(ord.create_time,'%Y-%m-%d %H:%i:%S') create_time from base_security_monitoring_order ord " +
|
|
|
" where ord.device_sn='"+deviceSn+"' and ord.patient='"+patient+"' order by create_time desc limit "+page*pageSize+","+pageSize;
|
|
|
" where ord.device_sn='"+deviceSn+"' {{patient}} order by create_time desc limit "+page*pageSize+","+pageSize;
|
|
|
if (StringUtils.isNotBlank(patient)){
|
|
|
sqlCount = sqlCount.replace("{{patient}}","and ord.patient='"+patient+"' ");
|
|
|
sql = sql.replace("{{patient}}","and ord.patient='"+patient+"' ");
|
|
|
}else {
|
|
|
sqlCount = sqlCount.replace("{{patient}}"," ");
|
|
|
sql = sql.replace("{{patient}}"," ");
|
|
|
}
|
|
|
long count = jdbcTemplate.queryForObject(sqlCount,long.class);
|
|
|
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
result.put("total",count);
|
|
|
result.put("page",page+1);
|
|
@ -1202,7 +1301,9 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
|
|
|
* @param time_begin YYYYMMDD 日期
|
|
|
* @return
|
|
|
*/
|
|
|
public com.alibaba.fastjson.JSONObject getX1Locations(String deviceSn,String time_begin){
|
|
|
public JSONArray getX1Locations(String deviceSn,String time_begin){
|
|
|
|
|
|
JSONArray result = new JSONArray();
|
|
|
|
|
|
String url = AqgConfig.X1_locations+"?device="+deviceSn+"&depth="+1+"&rows_per_page="+300;
|
|
|
if (StringUtils.isNotBlank(time_begin)){
|
|
@ -1212,8 +1313,23 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
|
|
|
headers.put("Accept", MediaType.APPLICATION_JSON.toString());
|
|
|
headers.put("Cookie", getCookie());
|
|
|
String responseStr = httpClientUtil.get(url,"utf-8",headers);
|
|
|
com.alibaba.fastjson.JSONObject result = JSON.parseObject(responseStr);
|
|
|
com.alibaba.fastjson.JSONObject resObj = JSON.parseObject(responseStr);
|
|
|
if (resObj.getBooleanValue("success")){
|
|
|
com.alibaba.fastjson.JSONArray arr = resObj.getJSONArray("objs");
|
|
|
arr.sort(Comparator.comparing(obj -> ((com.alibaba.fastjson.JSONObject) obj).getJSONObject("created_at").getLong("$date")));
|
|
|
for (int i=0;i<arr.size();i++){
|
|
|
try {
|
|
|
com.alibaba.fastjson.JSONObject obj = arr.getJSONObject(i);
|
|
|
com.alibaba.fastjson.JSONArray pointArr = obj.getJSONObject("point").getJSONArray("coordinates");
|
|
|
Double lon = pointArr.getDouble(0);
|
|
|
Double lat = pointArr.getDouble(1);
|
|
|
com.alibaba.fastjson.JSONObject pointJson = gpsUtil.gcj02_To_Bd09(lat,lon);
|
|
|
result.put(pointJson);
|
|
|
}catch (Exception e){
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|