|
@ -5,10 +5,9 @@ import com.yihu.jw.care.config.AqgConfig;
|
|
|
import com.yihu.jw.care.dao.device.DeviceDao;
|
|
|
import com.yihu.jw.care.dao.device.PatientDeviceDao;
|
|
|
import com.yihu.jw.care.dao.device.WlyyDeviceDao;
|
|
|
import com.yihu.jw.care.util.DeviceLostMessageUtil;
|
|
|
import com.yihu.jw.entity.care.device.Device;
|
|
|
import com.yihu.jw.entity.care.device.DevicePatientDevice;
|
|
|
import com.yihu.jw.restmodel.iot.device.WlyyDeviceVO;
|
|
|
import com.yihu.jw.restmodel.iot.device.WlyyPatientDeviceVO;
|
|
|
import com.yihu.jw.util.common.GpsUtil;
|
|
|
import com.yihu.jw.util.http.HttpClientUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@ -50,7 +49,8 @@ public class PatientDeviceService {
|
|
|
private WlyyDeviceDao wlyyDeviceDao;
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
@Autowired
|
|
|
private DeviceLostMessageUtil deviceLostMessageUtil;
|
|
|
Map<Integer, String> relations = new HashMap<>();
|
|
|
|
|
|
@PostConstruct
|
|
@ -229,6 +229,7 @@ public class PatientDeviceService {
|
|
|
|
|
|
|
|
|
/**************************************物联网检测大屏失联率start************************************************/
|
|
|
@Transactional
|
|
|
public void selectAndUpdate(){
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
String endTime = sdf.format(new Date());
|
|
@ -244,77 +245,55 @@ public class PatientDeviceService {
|
|
|
Date nowDate2 = device2.getTime();
|
|
|
String startTimeDevice2 = sdf.format(nowDate2);
|
|
|
try {
|
|
|
/**血糖仪,血压计。30天内有数据上传,则改为未失联**/
|
|
|
String sql = "SELECT bb.device_sn FROM (\n" +
|
|
|
"SELECT pd.device_sn FROM base.wlyy_patient_device pd LEFT JOIN wlyy_patient_health_index phi ON pd.device_sn = phi.device_sn WHERE\n" +
|
|
|
"phi.record_date BETWEEN '"+startTimeDevice1+"' AND '"+endTime+"' AND phi.del = 1 AND pd.category_code IN (1,2) GROUP BY phi.device_sn\n" +
|
|
|
") aa RIGHT JOIN (SELECT device_sn FROM wlyy_patient_device WHERE category_code IN (1,2)) bb ON aa.device_sn = bb.device_sn\n" +
|
|
|
"WHERE aa.device_sn IS NOT NULL OR aa.device_sn != ''";
|
|
|
List<Map<String , Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
if (list.size() > 0) {
|
|
|
for (int i=0;i<list.size();i++) {
|
|
|
wlyyDeviceDao.updateContactStatus1(new Date(), (String) list.get(i).get("device_sn"));
|
|
|
}
|
|
|
}
|
|
|
/**智能拐杖、智能手表。2天内有数据上传,则改为未失联**/
|
|
|
sql = "SELECT bb.device_sn FROM (\n" +
|
|
|
"SELECT pd.device_sn FROM base.wlyy_patient_device pd LEFT JOIN wlyy_patient_health_index phi ON pd.device_sn = phi.device_sn WHERE\n" +
|
|
|
"phi.record_date BETWEEN '"+startTimeDevice2+"' AND '"+endTime+"' AND phi.del = 1 AND pd.category_code IN (16) GROUP BY phi.device_sn\n" +
|
|
|
") aa RIGHT JOIN (SELECT device_sn FROM wlyy_patient_device WHERE category_code IN (16)) bb ON aa.device_sn = bb.device_sn\n" +
|
|
|
"WHERE aa.device_sn IS NOT NULL OR aa.device_sn != ''";
|
|
|
list = jdbcTemplate.queryForList(sql);
|
|
|
if (list.size() > 0) {
|
|
|
for (int i=0;i<list.size();i++) {
|
|
|
wlyyDeviceDao.updateContactStatus1(new Date(), (String) list.get(i).get("device_sn"));
|
|
|
}
|
|
|
List<String> lostSN = new ArrayList<>();
|
|
|
List<String> onContact = new ArrayList<>();
|
|
|
/*******************未失联**/
|
|
|
//血糖仪,血压计。30天内有数据上传,则改为未失联
|
|
|
String sql = " SELECT pd.device_sn FROM base.wlyy_patient_device pd where pd.del=0 and pd.category_code in (1,2) and EXISTS ( " +
|
|
|
"select dp.device_sn from device_data_push_log dp where dp.device_sn = pd.device_sn and dp.create_time " +
|
|
|
" BETWEEN '"+startTimeDevice1+"' AND '"+endTime+"') ";
|
|
|
List<String> devices = jdbcTemplate.queryForList(sql,String.class) ;
|
|
|
if (devices.size() > 0) {
|
|
|
onContact.addAll(devices);
|
|
|
}
|
|
|
|
|
|
//智能拐杖。手表2天内有数据上传,则改为未失联**
|
|
|
sql = " SELECT pd.device_sn FROM base.wlyy_patient_device pd where pd.del=0 and pd.category_code in (4,16) and EXISTS ( " +
|
|
|
"select dp.device_sn from device_data_push_log dp where dp.device_sn = pd.device_sn and dp.create_time " +
|
|
|
" BETWEEN '"+startTimeDevice2+"' AND '"+endTime+"') ";
|
|
|
|
|
|
/**血糖仪**/
|
|
|
String sql1 = "SELECT bb.device_sn FROM (\n" +
|
|
|
"SELECT pd.device_sn FROM base.wlyy_patient_device pd LEFT JOIN wlyy_patient_health_index phi ON pd.device_sn = phi.device_sn WHERE\n" +
|
|
|
"phi.record_date BETWEEN '"+startTimeDevice1+"' AND '"+endTime+"' AND phi.del = 1 AND pd.category_code = 1 GROUP BY phi.device_sn\n" +
|
|
|
") aa RIGHT JOIN (SELECT device_sn FROM wlyy_patient_device WHERE category_code = 1) bb ON aa.device_sn = bb.device_sn\n" +
|
|
|
"WHERE aa.device_sn IS NULL OR aa.device_sn = ''";
|
|
|
List<Map<String , Object>> list1 = jdbcTemplate.queryForList(sql1);
|
|
|
if (list1.size() > 0) {
|
|
|
for (int i=0;i<list1.size();i++) {
|
|
|
wlyyDeviceDao.updateContactStatus(new Date(), (String) list1.get(i).get("device_sn"));
|
|
|
}
|
|
|
devices = jdbcTemplate.queryForList(sql,String.class) ;
|
|
|
if (devices.size() > 0) {
|
|
|
onContact.addAll(devices);
|
|
|
}
|
|
|
/**血压计**/
|
|
|
String sql2 = "SELECT bb.device_sn FROM (\n" +
|
|
|
"SELECT pd.device_sn FROM base.wlyy_patient_device pd LEFT JOIN wlyy_patient_health_index phi ON pd.device_sn = phi.device_sn WHERE\n" +
|
|
|
"phi.record_date BETWEEN '"+startTimeDevice1+"' AND '"+endTime+"' AND phi.del = 1 AND pd.category_code = 2 GROUP BY phi.device_sn\n" +
|
|
|
") aa RIGHT JOIN (SELECT device_sn FROM wlyy_patient_device WHERE category_code = 2) bb ON aa.device_sn = bb.device_sn\n" +
|
|
|
"WHERE aa.device_sn IS NULL OR aa.device_sn = ''";
|
|
|
List<Map<String , Object>> list2 = jdbcTemplate.queryForList(sql2);
|
|
|
if (list2.size() > 0) {
|
|
|
for (int i=0;i<list2.size();i++) {
|
|
|
wlyyDeviceDao.updateContactStatus(new Date(), (String) list2.get(i).get("device_sn"));
|
|
|
}
|
|
|
/***************失联**/
|
|
|
//血糖仪、血压**/
|
|
|
sql = " SELECT pd.device_sn FROM base.wlyy_patient_device pd where pd.del=0 and pd.category_code in (1,2) and not EXISTS ( " +
|
|
|
"select dp.device_sn from device_data_push_log dp where dp.device_sn = pd.device_sn and dp.create_time " +
|
|
|
" BETWEEN '"+startTimeDevice1+"' AND '"+endTime+"') ";
|
|
|
devices = jdbcTemplate.queryForList(sql,String.class) ;
|
|
|
if (devices.size() > 0) {
|
|
|
lostSN.addAll(devices);
|
|
|
}
|
|
|
|
|
|
/**智能手表**/
|
|
|
//startTimeDevice2 2天
|
|
|
|
|
|
/**智能拐杖**/
|
|
|
String sql3 = "SELECT bb.device_sn FROM (\n" +
|
|
|
"SELECT pd.device_sn FROM base.wlyy_patient_device pd LEFT JOIN wlyy_patient_health_index phi ON pd.device_sn = phi.device_sn WHERE\n" +
|
|
|
"phi.record_date BETWEEN '"+startTimeDevice2+"' AND '"+endTime+"' AND phi.del = 1 AND pd.category_code = 16 GROUP BY phi.device_sn\n" +
|
|
|
") aa RIGHT JOIN (SELECT device_sn FROM wlyy_patient_device WHERE category_code = 16) bb ON aa.device_sn = bb.device_sn\n" +
|
|
|
"WHERE aa.device_sn IS NULL OR aa.device_sn = ''";
|
|
|
List<Map<String , Object>> list3 = jdbcTemplate.queryForList(sql3);
|
|
|
if (list3.size() > 0) {
|
|
|
for (int i=0;i<list3.size();i++) {
|
|
|
wlyyDeviceDao.updateContactStatus(new Date(), (String) list3.get(i).get("device_sn"));
|
|
|
}
|
|
|
//智能拐杖、手表
|
|
|
sql = " SELECT pd.device_sn FROM base.wlyy_patient_device pd where pd.del=0 and pd.category_code in (4,16) and not EXISTS ( " +
|
|
|
"select dp.device_sn from device_data_push_log dp where dp.device_sn = pd.device_sn and dp.create_time " +
|
|
|
" BETWEEN '"+startTimeDevice2+"' AND '"+endTime+"') ";
|
|
|
devices = jdbcTemplate.queryForList(sql,String.class) ;
|
|
|
if (devices.size() > 0) {
|
|
|
lostSN.addAll(devices);
|
|
|
}
|
|
|
if (onContact.size()>0){
|
|
|
wlyyDeviceDao.updateByContactStatus(1,new Date(),onContact);
|
|
|
}
|
|
|
if (lostSN.size()>0){
|
|
|
wlyyDeviceDao.updateByContactStatus(0,new Date(),lostSN);
|
|
|
deviceLostMessageUtil.deviceLostMessage(lostSN);
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
logger.info(e.getMessage());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|