|
@ -1,8 +1,17 @@
|
|
|
package com.yihu.jw.care.service.statistics;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.sun.org.apache.xerces.internal.xs.datatypes.ByteList;
|
|
|
import com.yihu.jw.care.dao.device.PatientDeviceDao;
|
|
|
import com.yihu.jw.care.service.device.PatientDeviceService;
|
|
|
import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
|
import com.yihu.jw.entity.care.device.DevicePatientDevice;
|
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
import com.yihu.jw.restmodel.web.PageEnvelop;
|
|
|
import io.swagger.models.auth.In;
|
|
|
import com.yihu.jw.rm.base.BaseRequestMapping;
|
|
|
import com.yihu.jw.utils.StringUtil;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@ -10,8 +19,10 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/***
|
|
|
* @ClassName: DetectionPlatformService
|
|
@ -26,14 +37,23 @@ public class DetectionPlatformService {
|
|
|
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
|
private PatientDeviceDao patientDeviceDao;
|
|
|
@Autowired
|
|
|
private BasePatientDao patientDao;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 体征监测 安防监护
|
|
|
* @param page
|
|
|
* @param pageSize
|
|
|
* @param type
|
|
|
* @return
|
|
|
*/
|
|
|
public PageEnvelop getHealthMonitoringListNew(Integer page, Integer pageSize, Integer type){
|
|
|
page = page>0?page-1:0;
|
|
|
if (type == 1) {
|
|
|
String sql = " SELECT id,user,`name`,'健康监测' as serve_desc,czrq,value1,value2,value3,value4,value5,value6,value7,type \n" +
|
|
|
"FROM wlyy_patient_health_index WHERE del = 1 AND type < 3 ORDER BY czrq ";
|
|
|
"FROM wlyy_patient_health_index WHERE del = 1 AND type < 3 ORDER BY czrq desc ";
|
|
|
String countSql = "select count(id) from ("+sql+")A ";
|
|
|
long count = jdbcTemplate.queryForObject(countSql,long.class);
|
|
|
sql +=" limit "+page*pageSize+","+pageSize;
|
|
@ -68,7 +88,7 @@ public class DetectionPlatformService {
|
|
|
}
|
|
|
String securitySql = "SELECT allCount,isUse,(allCount - isUse) inventory FROM \n" +
|
|
|
"(SELECT COUNT(1) allCount FROM wlyy_devices WHERE device_type = 1) allCount,\n" +
|
|
|
"(SELECT COUNT(1) isUse FROM wlyy_devices WHERE device_type = 1 AND is_binding = 1) isUse";
|
|
|
"(SELECT COUNT(pd.id) isUse FROM wlyy_devices d,wlyy_patient_device pd WHERE d.device_type = 1 AND d.device_code = pd.device_sn AND pd.del = 0) isUse";
|
|
|
List<Map<String , Object>> securityList = jdbcTemplate.queryForList(securitySql);
|
|
|
if (securityList.size() > 0) {
|
|
|
object.put("securityAllCount",securityList.get(0).get("allCount")); //安防设备总量
|
|
@ -81,7 +101,7 @@ public class DetectionPlatformService {
|
|
|
}
|
|
|
String healthSql = "SELECT allCount,isUse,(allCount - isUse) inventory FROM \n" +
|
|
|
"(SELECT COUNT(1) allCount FROM wlyy_devices WHERE device_type = 0) allCount,\n" +
|
|
|
"(SELECT COUNT(1) isUse FROM wlyy_devices WHERE device_type = 0 AND is_binding = 1) isUse";
|
|
|
"(SELECT COUNT(pd.id) isUse FROM wlyy_devices d,wlyy_patient_device pd WHERE d.device_type = 0 AND d.device_code = pd.device_sn AND pd.del = 0) isUse";
|
|
|
List<Map<String , Object>> healthList = jdbcTemplate.queryForList(healthSql);
|
|
|
if (healthList.size() > 0) {
|
|
|
object.put("healthAllCount",securityList.get(0).get("allCount"));//健康设备总量
|
|
@ -92,10 +112,21 @@ public class DetectionPlatformService {
|
|
|
object.put("healthIsUseCount",0);//健康设备使用中数量
|
|
|
object.put("healthInventoryCount",0);//健康设备库存量
|
|
|
}
|
|
|
//物联率
|
|
|
object.put("lawOfIOT",getRange( ((Integer)securityList.get(0).get("isUse") + (Integer) healthList.get(0).get("isUser")),( (Integer) securityList.get(0).get("allCount") + (Integer) healthList.get(0).get("allCount") ) ));
|
|
|
object.put("isUseAllIot",((Integer)securityList.get(0).get("isUse") + (Integer) healthList.get(0).get("isUser")));//已发放设备
|
|
|
object.put("allIot",(Integer) securityList.get(0).get("allCount") + (Integer) healthList.get(0).get("allCount"));//总设备
|
|
|
Long securityIsUser = (Long) securityList.get(0).get("isUse");
|
|
|
Long healthIsUser = (Long) healthList.get(0).get("isUse");
|
|
|
Long securityAllCount = (Long) securityList.get(0).get("allCount");
|
|
|
Long healthAllCount = (Long) healthList.get(0).get("allCount");
|
|
|
object.put("lawOfIOT",getRange( (securityIsUser.intValue() + healthIsUser.intValue() ),( securityAllCount.intValue() + healthAllCount.intValue() ) ));//物联率
|
|
|
object.put("isUseAllIot",(securityIsUser.intValue() + healthIsUser.intValue()));//已发放设备
|
|
|
object.put("allIot",securityAllCount.intValue() + healthAllCount.intValue());//总设备
|
|
|
// String unUseSql = "";//连续一周为上传数据
|
|
|
// List<Map<String , Object>> unUseList = jdbcTemplate.queryForList(unUseSql);
|
|
|
// Long unUseCount = (Long) securityList.get(0).get("allCount");
|
|
|
//// if (unUseList.size() > 0){
|
|
|
//// unUseCount = (Long) securityList.get(0).get("allCount");
|
|
|
//// }
|
|
|
// object.put("lostLaw",getRange(unUseCount.intValue(),securityIsUser.intValue() + healthIsUser.intValue()));//设备失联率
|
|
|
object.put("lostLaw","0%");//设备失联率
|
|
|
return object;
|
|
|
}
|
|
|
|
|
@ -114,4 +145,119 @@ public class DetectionPlatformService {
|
|
|
return filesize + "%";
|
|
|
}
|
|
|
|
|
|
public List<Map<String , Object>> getDeviceType(){
|
|
|
String sql = "SELECT category_code,device_name FROM wlyy_patient_device GROUP BY category_code";
|
|
|
return jdbcTemplate.queryForList(sql);
|
|
|
}
|
|
|
|
|
|
public JSONArray getDeviceByCondition(String categoryCode , String user){
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
List<DevicePatientDevice> patientDevices = patientDeviceDao.findAll();
|
|
|
if (StringUtils.isNotBlank(categoryCode)) { //categoryCode != null 根据设备类型查询
|
|
|
patientDevices = patientDeviceDao.findAllByCategoryCode(categoryCode);
|
|
|
}
|
|
|
Map<String, List<DevicePatientDevice>> byUser = patientDevices.stream().collect(Collectors.groupingBy(DevicePatientDevice::getUser));
|
|
|
List<BasePatientDO> patientDOS = patientDao.findAllByDel();
|
|
|
if (StringUtils.isNotBlank(user)) {
|
|
|
patientDOS = patientDao.findAllByDelAndId(user); //user != null 根据居民查询
|
|
|
}
|
|
|
Map<String, List<BasePatientDO>> byId = patientDOS.stream().collect(Collectors.groupingBy(BasePatientDO::getId));
|
|
|
//首页默认根据居民展示 绑定设备的居民
|
|
|
String userSql = "SELECT `user` FROM wlyy_patient_device WHERE del = 0 GROUP BY `user`";
|
|
|
List<Map<String , Object>> userList = jdbcTemplate.queryForList(userSql);
|
|
|
if (userList.size() > 0) {
|
|
|
JSONObject userObj = new JSONObject();
|
|
|
for (int i=0;i<userList.size();i++) {
|
|
|
JSONArray arrayAll = new JSONArray();
|
|
|
JSONArray array = new JSONArray();
|
|
|
userObj.put("patient",userList.get(i).get("user"));
|
|
|
userObj.put("patientName",byId.get(userList.get(i).get("user")).get(0).getName());
|
|
|
userObj.put("patientType",byId.get(userList.get(i).get("user")).get(0).getArchiveType());
|
|
|
userObj.put("latLon",byId.get(userList.get(i).get("user")).get(0).getLatLon());
|
|
|
List<DevicePatientDevice> deviceList = byUser.get(userList.get(i).get("user"));
|
|
|
if (deviceList.size() > 1) { //居民绑定多台设备
|
|
|
for (int j=0;j<deviceList.size();j++) {
|
|
|
JSONObject obj = new JSONObject();
|
|
|
obj.put("deviceSn",deviceList.get(j).getDeviceSn());
|
|
|
obj.put("deviceName",deviceList.get(j).getDeviceName());
|
|
|
obj.put("categoryCode",deviceList.get(j).getCategoryCode());
|
|
|
array.add(obj);
|
|
|
}
|
|
|
userObj.put("deviceCount",deviceList.size());
|
|
|
userObj.put("deviceInfo",array);
|
|
|
arrayAll.add(userObj);
|
|
|
} else { //居民只绑定一台设备
|
|
|
for (int j=0;j<deviceList.size();j++) {
|
|
|
JSONObject obj = new JSONObject();
|
|
|
obj.put("deviceSn",deviceList.get(j).getDeviceSn());
|
|
|
obj.put("deviceName",deviceList.get(j).getDeviceName());
|
|
|
obj.put("categoryCode",deviceList.get(j).getCategoryCode());
|
|
|
array.add(obj);
|
|
|
}
|
|
|
userObj.put("deviceCount",deviceList.size());
|
|
|
userObj.put("deviceInfo",array);
|
|
|
arrayAll.add(userObj);
|
|
|
}
|
|
|
jsonArray.add(arrayAll);
|
|
|
}
|
|
|
} else {
|
|
|
return jsonArray;
|
|
|
}
|
|
|
return jsonArray;
|
|
|
}
|
|
|
|
|
|
public JSONObject getDeviceInfo(String deviceSn) throws Exception{
|
|
|
String categoryCode = "";
|
|
|
JSONObject object = new JSONObject();
|
|
|
String deviceInfoSql = "SELECT device_name deviceName,device_type deviceType,device_code deviceSn,manufacturer FROM wlyy_devices WHERE device_code = '"+deviceSn+"' ";
|
|
|
List<Map<String , Object>> deviceInfoList = jdbcTemplate.queryForList(deviceInfoSql);
|
|
|
if (deviceInfoList.size() > 0){
|
|
|
object.put("deviceName",deviceInfoList.get(0).get("deviceName"));
|
|
|
object.put("deviceType",deviceInfoList.get(0).get("deviceType"));
|
|
|
object.put("deviceSn",deviceInfoList.get(0).get("deviceSn"));
|
|
|
object.put("manufacturer",deviceInfoList.get(0).get("manufacturer"));
|
|
|
String patientInfoSql = "SELECT p.`name` patientName,p.id patient,p.mobile,p.idcard,p.address,pd.category_code categoryCode " +
|
|
|
"FROM wlyy_patient_device pd,base_patient p WHERE p.id = pd.`user` AND p.del = 1 AND pd.del = 0 AND pd.device_sn = '"+deviceSn+"'";
|
|
|
List<Map<String , Object>> patientInfoList = jdbcTemplate.queryForList(patientInfoSql);
|
|
|
if (patientInfoList.size() > 0) {
|
|
|
categoryCode = patientInfoList.get(0).get("categoryCode").toString();
|
|
|
object.put("patientName",patientInfoList.get(0).get("patientName"));
|
|
|
object.put("patient",patientInfoList.get(0).get("patient"));
|
|
|
object.put("mobile",patientInfoList.get(0).get("mobile"));
|
|
|
object.put("idcard",patientInfoList.get(0).get("idcard"));
|
|
|
object.put("address",patientInfoList.get(0).get("address"));
|
|
|
String dataSql= "";
|
|
|
List<Map<String , Object>> dataList = new ArrayList<>();
|
|
|
switch (categoryCode) {
|
|
|
// 1=血糖仪 2=血压计 4=智能手表 13=智能床带/睡眠带 14=燃气报警器 15=烟雾报警器
|
|
|
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);
|
|
|
object.put("data",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 ORDER BY sort_date DESC LIMIT 10";
|
|
|
dataList = jdbcTemplate.queryForList(dataSql);
|
|
|
object.put("data",dataList);
|
|
|
break;
|
|
|
case "14" :
|
|
|
dataSql = "SELECT record_time recordDate,`value`,unit,device_type FROM base_device_health_index WHERE device_sn = '"+deviceSn+"' ORDER BY record_time DESC LIMIT 10 ";
|
|
|
dataList = jdbcTemplate.queryForList(dataSql);
|
|
|
object.put("data",dataList);
|
|
|
break;
|
|
|
case "15" :
|
|
|
dataSql = "SELECT record_time recordDate,`value`,unit,device_type FROM base_device_health_index WHERE device_sn = '"+deviceSn+"' ORDER BY record_time DESC LIMIT 10 ";
|
|
|
dataList = jdbcTemplate.queryForList(dataSql);
|
|
|
object.put("data",dataList);
|
|
|
break;
|
|
|
}
|
|
|
} else {
|
|
|
throw new Exception("无法找到该设备对应使用人");
|
|
|
}
|
|
|
}else {
|
|
|
throw new Exception("设备SN码对应的设备不存在!");
|
|
|
}
|
|
|
return object;
|
|
|
}
|
|
|
|
|
|
}
|