|
@ -4,27 +4,23 @@ package com.yihu.jw.care.service.device;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.yihu.jw.care.config.AqgConfig;
|
|
|
import com.yihu.jw.care.dao.device.BaseSleepPlanDao;
|
|
|
import com.yihu.jw.care.dao.device.DeviceDao;
|
|
|
import com.yihu.jw.care.dao.device.DeviceDetailDao;
|
|
|
import com.yihu.jw.care.dao.device.PatientDeviceDao;
|
|
|
import com.yihu.jw.care.dao.device.*;
|
|
|
import com.yihu.jw.care.service.assistance.EmergencyAssistanceService;
|
|
|
import com.yihu.jw.care.service.contacts.ContactsService;
|
|
|
import com.yihu.jw.care.service.security.SecurityMonitoringOrderService;
|
|
|
import com.yihu.jw.care.service.wechat.WeiXinAccessTokenUtils;
|
|
|
import com.yihu.jw.care.util.ConcealUtil;
|
|
|
import com.yihu.jw.care.util.CountDistance;
|
|
|
import com.yihu.jw.care.util.MyJdbcTemplate;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorDao;
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
|
|
|
import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
|
import com.yihu.jw.entity.care.device.BaseSleepPlan;
|
|
|
import com.yihu.jw.entity.care.device.Device;
|
|
|
import com.yihu.jw.entity.care.device.DeviceDetail;
|
|
|
import com.yihu.jw.entity.care.device.DevicePatientDevice;
|
|
|
import com.yihu.jw.entity.care.device.*;
|
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
import com.yihu.jw.restmodel.ResponseContant;
|
|
|
import com.yihu.jw.util.common.GpsUtil;
|
|
|
import com.yihu.jw.util.common.IdCardUtil;
|
|
|
import com.yihu.jw.util.common.LatitudeUtils;
|
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
|
import com.yihu.jw.util.entity.ServiceException;
|
|
|
import com.yihu.jw.util.healthIndex.HealthIndexUtil;
|
|
@ -61,6 +57,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)
|
|
@ -114,6 +111,10 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
|
|
|
private EmergencyAssistanceService emergencyAssistanceService;
|
|
|
@Autowired
|
|
|
private SecurityMonitoringOrderService securityMonitoringOrderService;
|
|
|
@Autowired
|
|
|
private CountDistance countDistance;
|
|
|
@Autowired
|
|
|
private PatientSafeAreaDao safeAreaDao;
|
|
|
|
|
|
@PostConstruct
|
|
|
public void init() {
|
|
@ -172,9 +173,15 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
|
|
|
* 燃气浓度
|
|
|
* @param patient
|
|
|
*/
|
|
|
public List<Map<String,Object>> gasConcentration(String patient,String date){
|
|
|
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+"' ";
|
|
|
public List<Map<String,Object>> gasConcentration(String patient,String date,String deviceSn){
|
|
|
String sql = "SELECT r.value,CAST(DATE_FORMAT(r.create_time,'%Y-%m-%d %H:%i:%S') as char) create_time from wlyy_patient_device pd,base_device_health_index r " +
|
|
|
"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;
|
|
@ -376,7 +388,7 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
public List<Map<String , Object>> findDeviceFromAdmin(String patientName, int page, int pageSize) {
|
|
|
public List<Map<String , Object>> findDeviceFromAdmin(String doctor,String patientName, int page, int pageSize) {
|
|
|
String sql = "select Distinct p.id,p.`name`,dd.photo,pd.device_id deviceId,pd.category_code categoryCode,pd.device_name deviceName, " +
|
|
|
" pd.device_sn deviceSn,pd.czrq,pd.doctor,pd.doctor_name doctorName,pd.agent,pd.agent_name agentName " +
|
|
|
" from wlyy_patient_device pd,wlyy_devices wd,base_patient p,dm_device dd where p.id = pd.`user` and pd.del = 0 " +
|
|
@ -384,6 +396,12 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
|
|
|
if (StringUtils.isNotBlank(patientName)){
|
|
|
sql += " AND (p.`name` LIKE '%" + patientName +"%' or p.idcard LIKE '%" + patientName + "%') ";
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(doctor)){//著老远查看时之查看签约居民的绑定
|
|
|
sql += " and EXISTS (SELECT sr.patient from base_service_package_sign_record sr,base_service_package_record r,base_team_member m " +
|
|
|
" WHERE sr.patient = p.id and sr.status=1 and m.team_code = r.team_code and sr.id=r.sign_id " +
|
|
|
" and m.doctor_code = '"+doctor+"' and m.del = '1') ";
|
|
|
}
|
|
|
|
|
|
sql += " ORDER BY pd.czrq DESC LIMIT "+ (page-1)*pageSize +" , " + pageSize + " ";
|
|
|
List<Map<String , Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
return list;
|
|
@ -898,63 +916,156 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
|
|
|
result.put(ResponseContant.resultMsg,"未查询到该设备");
|
|
|
}else {
|
|
|
DevicePatientDevice device = devices.get(0);
|
|
|
if (!patient.equals(device.getUser())){
|
|
|
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";
|
|
|
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));
|
|
|
}
|
|
|
com.alibaba.fastjson.JSONObject devInfoObj = JSON.parseObject(JSON.toJSONString(devInfo, SerializerFeature.WriteMapNullValue));
|
|
|
switch (device.getCategoryCode()){
|
|
|
case "1"://血压设备
|
|
|
break;
|
|
|
case "2"://血糖设备
|
|
|
break;
|
|
|
case "4"://手表 围栏与轨迹
|
|
|
devInfoObj = securityMonitoringOrderService.patientSignTopicInfo(devInfoObj,patient,"preventLost");
|
|
|
// if (!patient.equals(device.getUser())){
|
|
|
// result.put(ResponseContant.resultFlag,ResponseContant.fail);
|
|
|
// result.put(ResponseContant.resultMsg,"居民未绑定该设备");
|
|
|
// }else {
|
|
|
String sql = "select dd.photo,GROUP_CONCAT(DISTINCT 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,wd.manufacturer,p.mobile,p.address,p.idcard,wd.device_type " +
|
|
|
"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 " +
|
|
|
" INNER JOIN wlyy_devices wd on dd.model = wd.device_model and pd.device_sn = wd.device_code " +
|
|
|
"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("sosContactsDOS", new ArrayList<>());
|
|
|
String dataSql = "";
|
|
|
String recordSql = "";
|
|
|
List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
List<Map<String, Object>> recordList = new ArrayList<>();
|
|
|
String addresSql = "SELECT sp.org_code orgCode,sp.org_name orgName FROM base_service_package_record spr , base_service_package sp\n" +
|
|
|
"WHERE spr.service_package_id = sp.id AND spr.patient = '" + patient + "' AND sp.org_code IS NOT NULL GROUP BY sp.org_code,sp.org_name";
|
|
|
List<Map<String, Object>> addressList = jdbcTemplate.queryForList(addresSql);
|
|
|
if (addressList.size() > 0) {
|
|
|
devInfo.put("orgName", addressList.get(0).get("orgName"));
|
|
|
devInfo.put("orgCode", addressList.get(0).get("orgCode"));
|
|
|
} else {
|
|
|
devInfo.put("orgName", "");
|
|
|
devInfo.put("orgCode", "");
|
|
|
}
|
|
|
|
|
|
//轨迹动态
|
|
|
break;
|
|
|
case "7"://报警器 紧急工单
|
|
|
break;
|
|
|
case "12"://监控 视频地址
|
|
|
com.alibaba.fastjson.JSONObject tmp =ysDeviceService.getDeviceLiveAddress(patient,deviceSn,1,null);
|
|
|
devInfoObj.put("monitorInfoStatus",tmp.getIntValue(ResponseContant.resultFlag));
|
|
|
if (tmp.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail){
|
|
|
devInfoObj.put("monitorInfo",tmp.getString(ResponseContant.resultMsg));
|
|
|
}
|
|
|
else {
|
|
|
devInfoObj.put("monitorInfo",tmp.getJSONObject(ResponseContant.resultMsg));
|
|
|
}
|
|
|
break;
|
|
|
case "13"://睡眠带 获取当天睡眠详情
|
|
|
securityMonitoringOrderService.preventOutOfBed(devInfoObj,patient,false,day);
|
|
|
break;
|
|
|
case "14"://气感报警器 当天监测记录以及最新浓度
|
|
|
if (StringUtils.isBlank(day)){
|
|
|
day = DateUtil.getStringDateShort();
|
|
|
if ("4".equals(device.getCategoryCode()) || "7".equals(device.getCategoryCode())|| "16".equals(device.getCategoryCode())) {
|
|
|
devInfo.put("sosContactsDOS", contactsService.getPatientSosContacts(patient));
|
|
|
}
|
|
|
com.alibaba.fastjson.JSONObject devInfoObj = JSON.parseObject(JSON.toJSONString(devInfo, SerializerFeature.WriteMapNullValue));
|
|
|
switch (device.getCategoryCode()) {
|
|
|
case "1"://血压设备
|
|
|
dataSql = "SELECT record_date recordDate,value1,value2,value3,value4,value5,value6,value7,type FROM wlyy_patient_health_index WHERE device_sn = '" + deviceSn + "' AND del = 1 ORDER BY sort_date DESC LIMIT 10";
|
|
|
dataList = jdbcTemplate.queryForList(dataSql);
|
|
|
devInfoObj.put("data", dataList);
|
|
|
|
|
|
String ssql = "SELECT record_date recordDate,value1,value2,value3,value4,value5,value6,value7,type FROM wlyy_patient_health_index WHERE device_sn = '" + deviceSn + "' AND del = 1 AND status = 1 ";
|
|
|
String bloodPressureSql = ssql + " AND type = 1 ORDER BY sort_date DESC LIMIT 10";
|
|
|
dataList = jdbcTemplate.queryForList(bloodPressureSql);
|
|
|
devInfoObj.put("bloodPressure",dataList); //血压
|
|
|
break;
|
|
|
case "2"://血糖设备
|
|
|
dataSql = "SELECT record_date recordDate,value1,value2,value3,value4,value5,value6,value7,type FROM wlyy_patient_health_index WHERE device_sn = '" + deviceSn + "' AND del = 1 ";
|
|
|
dataSql += " ORDER BY sort_date DESC LIMIT 10";
|
|
|
dataList = jdbcTemplate.queryForList(dataSql);
|
|
|
devInfoObj.put("data", dataList); //血糖数据
|
|
|
|
|
|
recordSql = "SELECT record_date recordDate,value1,value2,value3,value4,value5,value6,value7,type FROM wlyy_patient_health_index WHERE device_sn = '" + deviceSn + "' AND del = 1 AND status = 1 ORDER BY sort_date DESC LIMIT 10";
|
|
|
dataList = jdbcTemplate.queryForList(recordSql);
|
|
|
devInfoObj.put("bloodSugar", dataList); //血糖异常数据
|
|
|
break;
|
|
|
case "4"://手表 围栏与轨迹
|
|
|
if (StringUtils.isBlank(day)) {
|
|
|
day = DateUtil.getStringDateShort();
|
|
|
}
|
|
|
devInfoObj = securityMonitoringOrderService.patientSignTopicInfo(devInfoObj, patient, "preventLost",deviceSn);
|
|
|
//轨迹动态
|
|
|
JSONArray locations = getX1Locations(deviceSn, day.replace("-", ""));
|
|
|
devInfoObj.put("routes", locations);
|
|
|
break;
|
|
|
case "7"://报警器 紧急工单
|
|
|
break;
|
|
|
case "12"://监控 视频地址
|
|
|
com.alibaba.fastjson.JSONObject tmp = ysDeviceService.getDeviceLiveAddress(patient, deviceSn, 1, null);
|
|
|
devInfoObj.put("monitorInfoStatus", tmp.getIntValue(ResponseContant.resultFlag));
|
|
|
if (tmp.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail) {
|
|
|
devInfoObj.put("monitorInfo", tmp.getString(ResponseContant.resultMsg));
|
|
|
} else {
|
|
|
devInfoObj.put("monitorInfo", tmp.getJSONObject(ResponseContant.resultMsg));
|
|
|
}
|
|
|
break;
|
|
|
case "13"://睡眠带 获取当天睡眠详情
|
|
|
securityMonitoringOrderService.preventOutOfBed(devInfoObj, patient, false, day);
|
|
|
break;
|
|
|
case "14"://气感报警器 当天监测记录以及最新浓度
|
|
|
if (StringUtils.isBlank(day)) {
|
|
|
day = DateUtil.getStringDateShort();
|
|
|
}
|
|
|
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, deviceSn, false);
|
|
|
devInfoObj.put("day", DateUtil.getStringDateShort());
|
|
|
break;
|
|
|
case "16":
|
|
|
if (StringUtils.isBlank(day)) {
|
|
|
day = DateUtil.getStringDateShort();
|
|
|
}
|
|
|
// 电子围栏
|
|
|
devInfoObj.put("safeAreaGz", securityMonitoringOrderService.getElectronicFence(device.getUser()));
|
|
|
// 行动轨迹
|
|
|
devInfoObj.put("actionTrack", securityMonitoringOrderService.getActionTrack(deviceSn,day));
|
|
|
//当前定位
|
|
|
List<Map<String , Object>> newList = securityMonitoringOrderService.getNewList(deviceSn,day);
|
|
|
String lat = "";
|
|
|
String lon = "";
|
|
|
if (newList.size() > 0) {
|
|
|
lat = (String) newList.get(0).get("lat");
|
|
|
lon = (String) newList.get(0).get("lon");
|
|
|
devInfoObj.put("currentPositioning", LatitudeUtils.getLocationAddress(lat,lon)); //当前定位
|
|
|
} else { //当前地址为null,则获取居民坐标
|
|
|
newList = securityMonitoringOrderService.getPatientLatLon(deviceSn);
|
|
|
String safeArea = (String) newList.get(0).get("lat_lon");
|
|
|
String[] safeAreas = safeArea.split(";");
|
|
|
com.alibaba.fastjson.JSONArray fenceLocation = new com.alibaba.fastjson.JSONArray();
|
|
|
for (String area:safeAreas){
|
|
|
String[] areaPoint = area.split(",");
|
|
|
lat = areaPoint[0];
|
|
|
lon = areaPoint[1];
|
|
|
}
|
|
|
List<Map<String,Object>> listTmp = gasConcentration(patient,day);
|
|
|
devInfoObj.put("monitorInfo",listTmp);
|
|
|
devInfoObj.put("day",day);
|
|
|
securityMonitoringOrderService.preventGasLeakage(devInfoObj,patient,false);
|
|
|
break;
|
|
|
case "15"://烟感报警器 获取最新浓度
|
|
|
securityMonitoringOrderService.preventFire(devInfoObj,patient,false);
|
|
|
devInfoObj.put("day",DateUtil.getStringDateShort());
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
devInfoObj.put("currentPositioning",LatitudeUtils.getLocationAddress(lat,lon)); //当前定位
|
|
|
devInfoObj.put("currentLat",lat); //当前定位
|
|
|
devInfoObj.put("currentLon",lon); //当前定位
|
|
|
double dulat =Double.parseDouble(lat);
|
|
|
double dulon = Double.parseDouble(lon);
|
|
|
List<PatientSafeAreaDO> safeAreaDOS = safeAreaDao.findByPatient(device.getUser());
|
|
|
String safeArea=null;
|
|
|
if (safeAreaDOS.size()>0){
|
|
|
safeArea = safeAreaDOS.get(0).getSafeAreaGz();
|
|
|
}
|
|
|
String[] safeAreas = safeArea.split(";");
|
|
|
com.alibaba.fastjson.JSONArray fenceLocation = new com.alibaba.fastjson.JSONArray();
|
|
|
for (String area:safeAreas){
|
|
|
String[] areaPoint = area.split(",");
|
|
|
com.alibaba.fastjson.JSONObject positionTmp = new com.alibaba.fastjson.JSONObject();
|
|
|
Double areaLon = Double.parseDouble( areaPoint[0]);
|
|
|
Double areaLat = Double.parseDouble( areaPoint[1]);
|
|
|
// com.alibaba.fastjson.JSONObject positionTmp = gpsUtil.gcj02_To_Bd09(lat,lon);
|
|
|
positionTmp.put("lat",areaLat);
|
|
|
positionTmp.put("lon",areaLon);
|
|
|
fenceLocation.add(positionTmp);
|
|
|
}
|
|
|
if (!countDistance.isInPolygon(dulon,dulat,fenceLocation)){
|
|
|
// orderUtil.createSecurityOrder(sn,null,null,8,"1","yslkaqqy",null);
|
|
|
devInfoObj.put("isTrueFalse","已超出围栏范围");
|
|
|
devInfoObj.put("isNotAlarm","已报警");
|
|
|
} else {
|
|
|
devInfoObj.put("isTrueFalse","未超出围栏范围");
|
|
|
devInfoObj.put("isNotAlarm","未报警");
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
// }
|
|
|
result.put(ResponseContant.resultFlag,ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg,JSON.toJSONString(devInfoObj,SerializerFeature.WriteMapNullValue));
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
@ -970,50 +1081,128 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
|
|
|
List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSn(deviceSn);
|
|
|
if (devices.size()>0){
|
|
|
DevicePatientDevice device = devices.get(0);
|
|
|
if (!patient.equals(device.getUser())){
|
|
|
throw new Exception("居民未绑定该设备");
|
|
|
}else{
|
|
|
// if (!patient.equals(device.getUser())){
|
|
|
// throw new Exception("居民未绑定该设备");
|
|
|
// }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;
|
|
|
}
|
|
|
}
|
|
|
// }
|
|
|
}else {
|
|
|
throw new Exception("设备未被绑定");
|
|
|
}
|
|
|
result.put(ResponseContant.resultFlag,ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg,JSON.toJSONString(result,SerializerFeature.WriteMapNullValue));
|
|
|
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 SUM(total) from ( select count(id ) total from wlyy_patient_health_index a where a.user = '"+patient+"' " +
|
|
|
" and a.type=2 and a.device_sn='"+deviceSn+"' and a.del = '1' GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date )A ";
|
|
|
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,20 +1213,31 @@ 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);
|
|
|
String str = JSON.toJSONString(list,SerializerFeature.WriteMapNullValue);
|
|
|
com.alibaba.fastjson.JSONArray arr = com.alibaba.fastjson.JSONArray.parseArray(str);
|
|
|
|
|
|
result.put("total",count);
|
|
|
result.put("page",page+1);
|
|
|
result.put("pageSize",pageSize);
|
|
|
result.put("dataList",list);
|
|
|
result.put("dataList", arr);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@ -1158,42 +1358,89 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public com.alibaba.fastjson.JSONObject updateDeviceFenceArea(String deviceSn,Integer fenceNO,String enable,String name,String freq,
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String updateDeviceFenceArea(String patient,String deviceSn,Integer fenceNO,String enable,String name,String freq,
|
|
|
String time_begin,String time_end,String safe_area ,String clear) throws Exception{
|
|
|
List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSn(deviceSn);
|
|
|
String url ="";
|
|
|
if ("4".equals(devices.get(0).getCategoryCode())){//手表
|
|
|
Device device = deviceDao.findOne(devices.get(0).getDeviceId());
|
|
|
if (device!=null){
|
|
|
if ("X1".equals(device.getModel())){
|
|
|
url = MessageFormat.format(AqgConfig.X1fence_area, deviceSn,fenceNO);
|
|
|
|
|
|
if(StringUtils.isBlank(patient)){
|
|
|
List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSn(deviceSn);
|
|
|
if (devices.size()>0){
|
|
|
DevicePatientDevice deviceTmp = devices.get(0);
|
|
|
if ("4".equals(deviceTmp.getCategoryCode())||"16".equals(deviceTmp.getCategoryCode())){
|
|
|
patient = deviceTmp.getUser();
|
|
|
}
|
|
|
}
|
|
|
}else {
|
|
|
url = MessageFormat.format(AqgConfig.S3fence_area, deviceSn,fenceNO);
|
|
|
}
|
|
|
MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
|
|
|
if(StringUtils.isBlank(clear)){
|
|
|
if (StringUtils.isNotBlank(safe_area)){
|
|
|
String[] position = safe_area.split(";");
|
|
|
safe_area = "";
|
|
|
for (String tmp:position){
|
|
|
String[] point = tmp.split(",");
|
|
|
safe_area+= gpsUtil.bd09_To_Gcj02_str(Double.parseDouble(point[1]),Double.parseDouble(point[0]))+";";
|
|
|
|
|
|
List<DevicePatientDevice> devices = patientDeviceDao.findAllByUserAndCategoryCode(patient,"4");
|
|
|
PatientSafeAreaDO safeAreaDO = new PatientSafeAreaDO();
|
|
|
if (StringUtils.isNotBlank(patient)){
|
|
|
List<PatientSafeAreaDO> safeAreaDOS = safeAreaDao.findByPatient(patient);
|
|
|
// 1删除 空修改或删除
|
|
|
if (safeAreaDOS.size()>0){
|
|
|
safeAreaDO = safeAreaDOS.get(0);
|
|
|
}else {
|
|
|
safeAreaDO.setPatient(patient);
|
|
|
safeAreaDO.setCreateTime(new Date());
|
|
|
safeAreaDO.setUpdateTime(new Date());
|
|
|
safeAreaDO.setSuccessFlag(-1);
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(clear)) {//删除
|
|
|
safeAreaDao.deleteByPatient(patient);
|
|
|
}
|
|
|
else{//新增或修改
|
|
|
safeAreaDO.setSafeAreaGz(safe_area);
|
|
|
safeAreaDO.setUpdateTime(new Date());
|
|
|
safeAreaDO.setSuccessFlag(-1);
|
|
|
}
|
|
|
}
|
|
|
if (devices.size()>0){
|
|
|
DevicePatientDevice patientDevice = devices.get(0);
|
|
|
String deviceSnTmp = patientDevice.getDeviceSn();
|
|
|
String url ="";
|
|
|
if ("4".equals(devices.get(0).getCategoryCode())){//手表
|
|
|
Device device = deviceDao.findOne(devices.get(0).getDeviceId());
|
|
|
if (device!=null){
|
|
|
if ("X1".equals(device.getModel())){
|
|
|
url = MessageFormat.format(AqgConfig.X1fence_area, deviceSnTmp,fenceNO);
|
|
|
}
|
|
|
}
|
|
|
}else {
|
|
|
url = MessageFormat.format(AqgConfig.S3fence_area, deviceSnTmp,fenceNO);
|
|
|
}
|
|
|
param.add("name", name);
|
|
|
param.add("freq", freq);
|
|
|
param.add("enable",enable);
|
|
|
param.add("time_begin", time_begin);
|
|
|
param.add("time_end", time_end);
|
|
|
param.add("safe_area", safe_area);
|
|
|
MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
|
|
|
if(StringUtils.isBlank(clear)){
|
|
|
if (StringUtils.isNotBlank(safe_area)){
|
|
|
String[] position = safe_area.split(";");
|
|
|
safe_area = "";
|
|
|
for (String tmp:position){
|
|
|
String[] point = tmp.split(",");
|
|
|
safe_area+= gpsUtil.bd09_To_Gcj02_str(Double.parseDouble(point[1]),Double.parseDouble(point[0]))+";";
|
|
|
}
|
|
|
}
|
|
|
param.add("name", name);
|
|
|
param.add("freq", freq);
|
|
|
param.add("enable",enable);
|
|
|
param.add("time_begin", time_begin);
|
|
|
param.add("time_end", time_end);
|
|
|
param.add("safe_area", safe_area);
|
|
|
|
|
|
}else {
|
|
|
param.add("clear",clear);
|
|
|
}else {
|
|
|
param.add("clear",clear);
|
|
|
}
|
|
|
HttpEntity<com.alibaba.fastjson.JSONObject> response = httpClientUtil.aqgCookieHttp(url, param, HttpMethod.POST, getCookie());
|
|
|
com.alibaba.fastjson.JSONObject responseObj = response.getBody();
|
|
|
if (responseObj.getBoolean("success")){
|
|
|
safeAreaDO.setSuccessFlag(1);
|
|
|
}
|
|
|
else {
|
|
|
throw new Exception("安全区域设置失败!");
|
|
|
}
|
|
|
if (StringUtils.isBlank(clear)&&StringUtils.isNotBlank(patient)){
|
|
|
safeAreaDao.save(safeAreaDO);
|
|
|
}
|
|
|
}
|
|
|
HttpEntity<com.alibaba.fastjson.JSONObject> response = httpClientUtil.aqgCookieHttp(url, param, HttpMethod.POST, getCookie());
|
|
|
return response.getBody();
|
|
|
return "success";
|
|
|
}
|
|
|
|
|
|
/**
|
|
@ -1202,7 +1449,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 +1461,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;
|
|
|
}
|
|
|
|