|
@ -15,6 +15,7 @@ import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@ -146,59 +147,67 @@ public class DetectionPlatformService {
|
|
|
}
|
|
|
|
|
|
public List<Map<String , Object>> getDeviceType(){
|
|
|
String sql = "SELECT category_code,device_name FROM wlyy_patient_device GROUP BY category_code";
|
|
|
String sql = "SELECT category_code categoryCode,name FROM dm_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();
|
|
|
List<DevicePatientDevice> patientDevices = patientDeviceDao.findAllGroupUser();
|
|
|
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 根据居民查询
|
|
|
if (StringUtils.isNotBlank(user)) { //categoryCode != null 根据设备类型查询
|
|
|
String sql = "select a.* from wlyy_patient_device a where a.user='"+user+"' and a.del=0 LIMIT 1";
|
|
|
patientDevices = jdbcTemplate.query(sql, new BeanPropertyRowMapper(DevicePatientDevice.class));
|
|
|
}
|
|
|
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++) {
|
|
|
// String userSql = "SELECT `user` FROM wlyy_patient_device WHERE del = 0 GROUP BY `user`";
|
|
|
// List<Map<String , Object>> userList = jdbcTemplate.queryForList(userSql);
|
|
|
if (patientDevices.size() > 0) {
|
|
|
for (int i=0;i<patientDevices.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);
|
|
|
JSONObject userObj = new JSONObject();
|
|
|
userObj.put("patient",patientDevices.get(i).getUser());
|
|
|
userObj.put("patientName",byId.get(patientDevices.get(i).getUser()).get(0).getName());
|
|
|
userObj.put("patientType",byId.get(patientDevices.get(i).getUser()).get(0).getArchiveType());
|
|
|
userObj.put("latLon",byId.get(patientDevices.get(i).getUser()).get(0).getLatLon());
|
|
|
List<DevicePatientDevice> deviceList = patientDeviceDao.findAllByUser(patientDevices.get(i).getUser());
|
|
|
if (StringUtils.isNotBlank(categoryCode)) {
|
|
|
deviceList = patientDeviceDao.findAllByUserAndCategoryCode(patientDevices.get(i).getUser(),categoryCode);
|
|
|
}
|
|
|
if (deviceList != null) {
|
|
|
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);
|
|
|
}
|
|
|
userObj.put("deviceCount",deviceList.size());
|
|
|
userObj.put("deviceInfo",array);
|
|
|
arrayAll.add(userObj);
|
|
|
jsonArray.add(arrayAll);
|
|
|
}
|
|
|
jsonArray.add(arrayAll);
|
|
|
}
|
|
|
} else {
|
|
|
return jsonArray;
|