|
@ -3,9 +3,10 @@ package com.yihu.iot.service.monitorPlatform;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.gson.JsonObject;
|
|
|
import com.yihu.iot.dao.dict.IotSystemDictDao;
|
|
|
import com.yihu.iot.dao.equipment.IotEquipmentDetailDao;
|
|
|
import com.yihu.iot.service.analyzer.WlyyIotTzDict;
|
|
|
import com.yihu.iot.service.analyzer.WlyyIotTzDictDao;
|
|
|
import com.yihu.iot.service.common.MyJdbcTemplate;
|
|
|
import com.yihu.iot.service.device.IotPatientDeviceService;
|
|
|
import com.yihu.iot.service.equipment.IotEqtDetailService;
|
|
@ -24,23 +25,18 @@ import iot.device.LocationDataVO;
|
|
|
import org.apache.http.Consts;
|
|
|
import org.apache.http.client.utils.URLEncodedUtils;
|
|
|
import org.apache.http.message.BasicNameValuePair;
|
|
|
import org.apache.jasper.tagplugins.jstl.core.ForEach;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.jdbc.core.SqlInOutParameter;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
|
import javax.print.DocFlavor;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.IOException;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.time.temporal.Temporal;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@ -81,6 +77,8 @@ public class MonitorPlatformService {
|
|
|
private IotInterfaceLogService iotInterfaceLogService;
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
|
private WlyyIotTzDictDao wlyyIotTzDictDao;
|
|
|
|
|
|
/**
|
|
|
* 获取位置信息
|
|
@ -118,19 +116,6 @@ public class MonitorPlatformService {
|
|
|
locationDataVO = iotPatientDeviceService.addNameAndCodeToLocationVO(locationDataVO);
|
|
|
locationDataVOList.add(locationDataVO);
|
|
|
});
|
|
|
// JSONArray jsonArrayTemp = new JSONArray();
|
|
|
// JSONObject deviceSn = new JSONObject();
|
|
|
// deviceSn.put("andOr","or");
|
|
|
// deviceSn.put("field","deviceSn");
|
|
|
// deviceSn.put("condition","=");
|
|
|
// deviceSn.put("value",list.getString(i));
|
|
|
// jsonArrayTemp.add(deviceSn);
|
|
|
// JSONObject jsonObject = new JSONObject();
|
|
|
// jsonObject.put("filter",jsonArrayTemp);
|
|
|
// jsonObject.put("page",page);
|
|
|
// jsonObject.put("size",size);
|
|
|
// List<LocationDataVO> locationDataVOList = iotPatientDeviceService.findDeviceLocationsByIdCard(jsonObject.toString());
|
|
|
//figureLabelSerachService.getFigureLabelByList(locationDataVOList);
|
|
|
envelop.getDetailModelList().addAll(locationDataVOList);
|
|
|
}
|
|
|
envelop.setTotalCount(total);
|
|
@ -140,24 +125,20 @@ public class MonitorPlatformService {
|
|
|
int totalEqCount=0;
|
|
|
int totalCount=0;
|
|
|
//小屋总数
|
|
|
if(deviceType.contains("5")){
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(deviceName)||(org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName) &&deviceName.contains("健康小屋"))){
|
|
|
totalEqCount = iotEqtDetailService.getEquipmentCount();
|
|
|
}
|
|
|
String manufacturerCode = deviceType;
|
|
|
manufacturerCode = manufacturerCode.replace(",","','").replace("5","yituo").replace("10","xeek").replace("11","xiaomi");
|
|
|
if(deviceType.contains("5")||deviceType.contains("10")||deviceType.contains("11")){
|
|
|
totalEqCount = iotEqtDetailService.getEquipmentCount(manufacturerCode);
|
|
|
}
|
|
|
String[] categoryCodes= deviceType.split(",");
|
|
|
if(categoryCodes.length==1&&"5".equals(deviceType)){
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(deviceName)||(org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName) &&deviceName.contains("健康小屋"))){
|
|
|
euipmentList = iotEqtDetailService.getEquipmentLocation(page,size);
|
|
|
envelop.getDetailModelList().addAll(euipmentList);
|
|
|
}
|
|
|
if(categoryCodes.length==1&&(deviceType.contains("5")||deviceType.contains("10")||deviceType.contains("11"))){
|
|
|
euipmentList = iotEqtDetailService.getEquipmentLocation(page,size,manufacturerCode);
|
|
|
envelop.getDetailModelList().addAll(euipmentList);
|
|
|
}
|
|
|
else{
|
|
|
if(deviceType.contains("5")){
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(deviceName)||(org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName) &&deviceName.contains("健康小屋"))){
|
|
|
euipmentList = iotEqtDetailService.getEquipmentLocation(page,size);
|
|
|
envelop.getDetailModelList().addAll(euipmentList);
|
|
|
}
|
|
|
if(deviceType.contains("5")||deviceType.contains("10")||deviceType.contains("11")){
|
|
|
euipmentList = iotEqtDetailService.getEquipmentLocation(page,size,manufacturerCode);
|
|
|
envelop.getDetailModelList().addAll(euipmentList);
|
|
|
}
|
|
|
StringBuffer sql = new StringBuffer("select id,idcard idCard,category_code categoryCode,device_sn deviceSn,location,device_time deviceTime,disease_condition diseaseCondition,\n" +
|
|
|
"create_time createTime,device_name equimentName\n" +
|
|
@ -198,60 +179,6 @@ public class MonitorPlatformService {
|
|
|
locationDataVOList.add(locationDataVO);
|
|
|
});
|
|
|
envelop.getDetailModelList().addAll(locationDataVOList);
|
|
|
// for (String categoryCode:categoryCodes){
|
|
|
// JSONObject json = new JSONObject();
|
|
|
// JSONArray jsonArray = new JSONArray();
|
|
|
// if(diseaseCondition!=null){
|
|
|
// json.put("andOr","and");
|
|
|
// json.put("field","diseaseCondition");
|
|
|
// json.put("condition","=");
|
|
|
// json.put("value",diseaseCondition);
|
|
|
// jsonArray.add(json);
|
|
|
// }
|
|
|
// if(!"5".equals(categoryCode)){
|
|
|
// json = new JSONObject();
|
|
|
// List<String> listTmp = new ArrayList<>();
|
|
|
// if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName)){
|
|
|
// String[] deviceNames = deviceName.split(",");
|
|
|
// for (String tmp :deviceNames){
|
|
|
// String sql="select DISTINCT device_code from device.wlyy_devices wd where wd.device_name like '%"+tmp+"%' ";
|
|
|
// List<String> tmpList = jdbcTemplate.queryForList(sql,String.class);
|
|
|
// listTmp.addAll(tmpList);
|
|
|
// }
|
|
|
// if (listTmp.size()!=0){
|
|
|
// json.put("andOr","and");
|
|
|
// json.put("field","deviceSn");
|
|
|
// json.put("condition","in");
|
|
|
// json.put("value",listTmp);
|
|
|
// jsonArray.add(json);
|
|
|
// }
|
|
|
// }
|
|
|
// else{
|
|
|
// if(!"5".equals(categoryCode)) {
|
|
|
// json.put("andOr", "and");
|
|
|
// json.put("field", "categoryCode");
|
|
|
// json.put("condition", "=");
|
|
|
// json.put("value", Integer.parseInt(categoryCode));
|
|
|
// jsonArray.add(json);
|
|
|
// }
|
|
|
// }
|
|
|
// JSONObject jsonObject = new JSONObject();
|
|
|
// jsonObject.put("filter",jsonArray);
|
|
|
// jsonObject.put("page",page);
|
|
|
// jsonObject.put("size",size);
|
|
|
// if (jsonArray.size()!=0){
|
|
|
// List<LocationDataVO> locationDataVOList = iotPatientDeviceService.findDeviceLocationsByIdCard(jsonObject.toString());
|
|
|
// List<LocationDataVO> list2 = iotPatientDeviceService.addNameAndCodeToList(locationDataVOList);
|
|
|
// //figureLabelSerachService.getFigureLabelByList(locationDataVOList);
|
|
|
// envelop.getDetailModelList().addAll(list2);
|
|
|
// totalCount += iotPatientDeviceService.getESCount(jsonObject.toString());
|
|
|
// }
|
|
|
// }
|
|
|
// if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName)){
|
|
|
// break;
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
envelop.setTotalCount(totalCount>totalEqCount?totalCount:totalEqCount);
|
|
|
return envelop;
|
|
@ -1206,7 +1133,7 @@ public class MonitorPlatformService {
|
|
|
params.put("appid", appid);
|
|
|
params.put("appSecret", appSecret);
|
|
|
String url = "/gc/accesstoken";
|
|
|
String response = httpClientUtil.httpPost(wlyyUrl + url, params);
|
|
|
String response = HttpClientUtil.httpPost(wlyyUrl + url, params);
|
|
|
JSONObject jsonObject = JSON.parseObject(response);
|
|
|
if(jsonObject.getInteger("status")==10000){
|
|
|
String accesstoken = jsonObject.getJSONObject("result").getString("accesstoken");
|
|
@ -1248,7 +1175,7 @@ public class MonitorPlatformService {
|
|
|
"and wd.manufacturer_code is not null and wd.manufacturer_code <>'' and pd.device_name<>'血压计-null' and pd.device_name<>'血糖仪-自助体检一体机' \n" +
|
|
|
"GROUP BY wd.manufacturer_code,pd.device_name\n" +
|
|
|
"UNION\n" +
|
|
|
"select '健康小屋' device_name,manufacturer from xmiot.iot_equipmet_detail group BY manufacturer_code,device_name\n" +
|
|
|
"select case device_name when '自助体检一体机' then '健康小屋' else device_name end AS device_name,manufacturer from xmiot.iot_equipmet_detail group BY manufacturer_code,device_name\n" +
|
|
|
")A\n" +
|
|
|
"GROUP BY A.manufacturer\n" +
|
|
|
"ORDER BY total desc";
|
|
@ -1262,7 +1189,7 @@ public class MonitorPlatformService {
|
|
|
"and wd.manufacturer_code is not null and wd.manufacturer_code <>'' and pd.device_name<>'血压计-null' and pd.device_name<>'血糖仪-自助体检一体机' \n" +
|
|
|
"GROUP BY wd.manufacturer_code,pd.device_name\n" +
|
|
|
"UNION\n" +
|
|
|
"select '健康小屋' device_name from xmiot.iot_equipmet_detail group BY manufacturer_code,device_name\n" +
|
|
|
"select case device_name when '自助体检一体机' then '健康小屋' else device_name end AS device_name from xmiot.iot_equipmet_detail group BY manufacturer_code,device_name\n" +
|
|
|
")A";
|
|
|
Integer BrandsCount = jdbcTemplate.queryForObject(sql,Integer.class);
|
|
|
|
|
@ -1285,6 +1212,8 @@ public class MonitorPlatformService {
|
|
|
*/
|
|
|
public JSONObject getEquipmentStatistics(String deviceType,String deviceName,String showLevel){
|
|
|
try {
|
|
|
WlyyIotTzDict dictObj =wlyyIotTzDictDao.findByCodeAndDel("IOT_LOST_DAY",1);
|
|
|
String lost_day = dictObj.getValue();
|
|
|
JSONObject result = new JSONObject();
|
|
|
JSONArray arrTmp = new JSONArray();
|
|
|
result.put("deviceInfo",arrTmp);
|
|
@ -1378,7 +1307,7 @@ public class MonitorPlatformService {
|
|
|
|
|
|
//失联设备(一周未上传当作失联)
|
|
|
sql.append("and d.device_sn not in (select device_sn from ( select device_sn,MAX(record_date) record_date from device.wlyy_patient_health_index where device_sn<>'' GROUP BY device_sn)a ");
|
|
|
sql.append("where TIMESTAMPDIFF(DAY,record_date,NOW()) <= 30)");
|
|
|
sql.append("where TIMESTAMPDIFF(DAY,record_date,NOW()) <= "+lost_day+")");
|
|
|
Integer lostContact = jdbcTemplate.queryForObject(sql.toString(),Integer.class);
|
|
|
result.put("lostContact",lostContact);
|
|
|
}
|
|
@ -1448,6 +1377,8 @@ public class MonitorPlatformService {
|
|
|
*/
|
|
|
public JSONObject iotAndLostRange(String startTime,String endTime,
|
|
|
String deviceType,String area,String hospital,String quotaCode){
|
|
|
WlyyIotTzDict dictObj =wlyyIotTzDictDao.findByCodeAndDel("IOT_LOST_DAY",1);
|
|
|
String lost_day = dictObj.getValue();
|
|
|
JSONObject result = new JSONObject();
|
|
|
StringBuffer sql = new StringBuffer("select count(*) from wlyy.wlyy_patient_device d ,wlyy.wlyy_sign_family f WHERE f.`status`>0 and d.del=0 and f.patient = d.`user` ");
|
|
|
StringBuffer sqlCondition = new StringBuffer(" ");
|
|
@ -1501,7 +1432,7 @@ public class MonitorPlatformService {
|
|
|
sqlCondition.append("and record_date >='"+startTime+" 00:00:00' and record_date<='"+endTime+" 23:59:59' ");
|
|
|
}
|
|
|
else{
|
|
|
sqlCondition.append("and TIMESTAMPDIFF(DAY,record_date,NOW()) <= 30 ");
|
|
|
sqlCondition.append("and TIMESTAMPDIFF(DAY,record_date,NOW()) <= "+lost_day+" ");
|
|
|
}
|
|
|
sqlCondition.append(")");
|
|
|
sql.append(sqlCondition);
|
|
@ -1564,7 +1495,7 @@ public class MonitorPlatformService {
|
|
|
}
|
|
|
sql.append("GROUP BY wd.manufacturer_code,pd.device_name ");
|
|
|
if ((org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)&&deviceType.contains("5"))||org.apache.commons.lang3.StringUtils.isBlank(deviceType)){
|
|
|
sql.append("UNION select '健康小屋' device_name from xmiot.iot_equipmet_detail group BY manufacturer_code,device_name");
|
|
|
sql.append("UNION select case device_name when '自助体检一体机' then '健康小屋' else device_name end AS device_name from xmiot.iot_equipmet_detail group BY manufacturer_code,device_name");
|
|
|
}
|
|
|
sql.append(")A");
|
|
|
List<String> list = jdbcTemplate.queryForList(sql.toString(),String.class);
|
|
@ -1634,7 +1565,7 @@ public class MonitorPlatformService {
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
JSONArray result = new JSONArray();
|
|
|
for (Map<String,Object> map :list){
|
|
|
sql="select `code`,`value` from xmiot.iot_system_dict where dict_name='DEVICE_TYPE' and del=1 and parent_code='"+map.get("id").toString()+"'";
|
|
|
sql="select `code`,`value` from xmiot.iot_system_dict where dict_name='DEVICE_TYPE' and del=1 and code!=10 and code!=11 and parent_code='"+map.get("id").toString()+"'";
|
|
|
StringBuffer buffer = new StringBuffer();
|
|
|
List<Map<String,Object>> reList = jdbcTemplate.queryForList(sql);
|
|
|
for (Map<String,Object> reMap:reList){
|
|
@ -1726,13 +1657,13 @@ public class MonitorPlatformService {
|
|
|
return deviceName;
|
|
|
}
|
|
|
|
|
|
public JSONObject savePatientDeviceLocation(){
|
|
|
public JSONObject savePatientDeviceLocation(String categoryCode){
|
|
|
String sql = "select DISTINCT pd.category_code ,pd.czrq create_time,pd.device_sn ,pd.device_name, p.disease_condition ,p.`code`,p.idcard ,p.address,sf.hospital_name\n" +
|
|
|
"from wlyy.wlyy_patient_device pd \n" +
|
|
|
"INNER JOIN wlyy.wlyy_sign_family sf on pd.`user` = sf.patient and sf.type=2 \n" +
|
|
|
"INNER JOIN wlyy.wlyy_patient p on p.idcard = sf.idcard and p.`status`=1\n" +
|
|
|
"where pd.del=0 and pd.category_code in (1,2)";
|
|
|
// sql="select * from device.wlyy_patient_device_location_tmp";
|
|
|
"where pd.del=0 and pd.category_code in ("+categoryCode+")";
|
|
|
// "where pd.del=0 and pd.category_code in (1,2)";
|
|
|
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
list.forEach(map->{
|
|
|
try {
|
|
@ -1771,4 +1702,45 @@ public class MonitorPlatformService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public List<Map<String, Object>> getHealthScoreByPatient(String patient,String date,String endDate){
|
|
|
String sql = "SELECT chhs.device_sn deviceSn,chhs.export_key exportKey,chhs.export_time exportTime,chhs.name name,chhs.score score,chhs.total total,chhs.date date FROM xmiot.wlyy_copd_huami_device chd,xmiot.wlyy_copd_huami_health_score chhs,wlyy.hm_token t\n" +
|
|
|
"WHERE t.patient = '"+patient+"' AND t.patient = chd.patient AND chd.device_sn = chhs.device_sn and chhs.date > '"+endDate+"' and chhs.date < '"+date+"' ORDER BY export_time DESC ";
|
|
|
List<Map<String, Object>> scoreDO = jdbcTemplate.queryForList(sql);
|
|
|
return scoreDO;
|
|
|
}
|
|
|
|
|
|
public List<Map<String,Object>> getRealtimeDateByPatient(String patient,String date){
|
|
|
String sql = "SELECT chrd.device_sn deviceSn,chrd.hr hr,chrd.st st,chrd.cal cal,chrd.date date FROM xmiot.wlyy_copd_huami_device chd,xmiot.wlyy_copd_huami_realtime_date chrd,wlyy.hm_token t\n" +
|
|
|
"WHERE t.patient = '"+patient+"' AND t.patient = chd.patient AND chd.device_sn = chrd.device_sn and chrd.date = '"+date+"' ORDER BY chrd.`date` DESC";
|
|
|
List<Map<String, Object>> realtimeDateDo = jdbcTemplate.queryForList(sql);
|
|
|
return realtimeDateDo;
|
|
|
}
|
|
|
|
|
|
public List<Map<String,Object>> getRundatePatient(String patient,String date){
|
|
|
String sql = "SELECT chr.device_sn deviceSn,chr.date date,chr.last_sync_time lastSyncTime,chr.steps steps,chr.distance distance,chr.run_distance runDistance,chr.run_time runTime,chr.walk_time walkTime,chr.calories calories,chr.run_calories runCalories,chr.hour hour FROM xmiot.wlyy_copd_huami_device chd,xmiot.wlyy_copd_huami_rundate chr,wlyy.hm_token t\n" +
|
|
|
"WHERE t.patient = '"+patient+"' AND t.patient = chd.patient AND chd.device_sn = chr.device_sn and chr.date = '"+date+"' ORDER BY chr.`date` DESC";
|
|
|
List<Map<String, Object>> rundataDo = jdbcTemplate.queryForList(sql);
|
|
|
return rundataDo;
|
|
|
}
|
|
|
|
|
|
public List<Map<String,Object>> getPaiPatient(String patient,String date){
|
|
|
String sql = "SELECT chp.device_sn deviceSn,chp.calendar_day calendarDay,chp.timestamp timestamp,chp.total_pai totalPai,chp.daily_pai dailyPai,chp.date date FROM xmiot.wlyy_copd_huami_device chd,xmiot.wlyy_copd_huami_pai chp,wlyy.hm_token t\n" +
|
|
|
"WHERE t.patient = '"+patient+"' AND t.patient = chd.patient AND chd.device_sn = chp.device_sn and chp.date = '"+date+"' ORDER BY chp.`timestamp` DESC";
|
|
|
List<Map<String, Object>> paiDo = jdbcTemplate.queryForList(sql);
|
|
|
return paiDo;
|
|
|
}
|
|
|
|
|
|
public List<Map<String,Object>> getSleepByPatient(String patient,String date){
|
|
|
String sql = "SELECT chs.device_sn deviceSn,chs.date date,chs.last_sync_time lastSyncTime,chs.deep_sleep_time deepSleepTime,chs.shallow_sleep_time shallowSleepTime,chs.wake_time wakeTime,chs.sleep_score sleepScore,chs.start start,chs.stop stop,chs.mode mode FROM xmiot.wlyy_copd_huami_device chd,xmiot.wlyy_copd_huami_sleep chs,wlyy.hm_token t\n" +
|
|
|
"WHERE t.patient = '"+patient+"' AND t.patient = chd.patient AND chd.device_sn = chs.device_sn and chs.date = '"+date+"' ORDER BY chs.`last_sync_time` DESC";
|
|
|
List<Map<String, Object>> paiDo = jdbcTemplate.queryForList(sql);
|
|
|
return paiDo;
|
|
|
}
|
|
|
|
|
|
public List<Map<String , Object>> getHeartByPatient(String patient,String date,String endDate){
|
|
|
String sql = "SELECT chh.device_sn deviceSn,chh.date date,chh.minute minute,chh.last_sync_time lastSyncTime,chh.timestamp timestamp,chh.heart_rate_data heartRateData,chh.measure_type measureType FROM xmiot.wlyy_copd_huami_device chd,xmiot.wlyy_copd_huami_heart chh,wlyy.hm_token t\n" +
|
|
|
"WHERE t.patient = '"+patient+"' AND t.patient = chd.patient AND chd.device_sn = chh.device_sn and chh.`date` > '"+endDate+"' and chh.`date` < '"+date+"' ORDER BY chh.`date` DESC";
|
|
|
List<Map<String, Object>> heartDo = jdbcTemplate.queryForList(sql);
|
|
|
return heartDo;
|
|
|
}
|
|
|
}
|