|
@ -3,6 +3,7 @@ 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.common.MyJdbcTemplate;
|
|
@ -16,12 +17,14 @@ import com.yihu.jw.entity.iot.equipment.IotEquipmentDetailDO;
|
|
|
import com.yihu.jw.restmodel.web.MixEnvelop;
|
|
|
import com.yihu.jw.util.http.HttpClientUtil;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.util.Json;
|
|
|
import iot.device.LocationDataVO;
|
|
|
import org.apache.http.Consts;
|
|
|
import org.apache.http.client.utils.URLEncodedUtils;
|
|
|
import org.apache.http.message.BasicNameValuePair;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@ -30,6 +33,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.IOException;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.time.temporal.Temporal;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@ -38,8 +42,8 @@ import java.util.*;
|
|
|
@Service
|
|
|
public class MonitorPlatformService {
|
|
|
|
|
|
@Value("${spring.wlyy.url}")
|
|
|
private String wlyyUrl;
|
|
|
// @Value("${spring.wlyy.url}")
|
|
|
private String wlyyUrl = "http://127.0.0.1:8080/";
|
|
|
@Value("${spring.wlyy.appid}")
|
|
|
private String appid;
|
|
|
@Value("${spring.wlyy.appsecret}")
|
|
@ -68,6 +72,8 @@ public class MonitorPlatformService {
|
|
|
private IotSystemDictDao iotSystemDictDao;
|
|
|
@Autowired
|
|
|
private IotInterfaceLogService iotInterfaceLogService;
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
/**
|
|
|
* 获取位置信息
|
|
@ -1053,7 +1059,181 @@ public class MonitorPlatformService {
|
|
|
e.printStackTrace();
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取设备品牌以及商家品牌排行
|
|
|
*/
|
|
|
public JSONObject getBrandsAndManufacturer(){
|
|
|
try {
|
|
|
String sql = "select count(DISTINCT pd.device_name) as total,pd.device_name,wd.device_name,wd.manufacturer from wlyy.wlyy_patient_device pd,device.wlyy_devices wd \n" +
|
|
|
"where pd.device_sn = wd.device_code \n" +
|
|
|
"and wd.manufacturer_code is not null and wd.manufacturer_code <>'' \n" +
|
|
|
"group by wd.manufacturer_code \n" +
|
|
|
"ORDER BY total desc";
|
|
|
List<Map<String,Object>>Manufacturers = jdbcTemplate.queryForList(sql);
|
|
|
JSONObject result = new JSONObject();
|
|
|
JSONArray arr = JSONArray.parseArray(JSON.toJSONString(Manufacturers));
|
|
|
result.put("Manufacturers",arr);
|
|
|
sql = "select count(DISTINCT pd.device_name)from wlyy.wlyy_patient_device pd,device.wlyy_devices wd \n" +
|
|
|
"where pd.device_sn = wd.device_code \n" +
|
|
|
"and wd.manufacturer_code is not null and wd.manufacturer_code <>'' \n" +
|
|
|
"ORDER BY pd.device_name desc ";
|
|
|
Integer BrandsCount = jdbcTemplate.queryForObject(sql,Integer.class);
|
|
|
|
|
|
result.put("Brands",BrandsCount);
|
|
|
result.put("manufacturerCount",arr.size());
|
|
|
return result;
|
|
|
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 谁设备库存、使用中、总备案、物联率、失联率
|
|
|
* @param deviceType
|
|
|
* @param deviceName
|
|
|
* @param showLevel
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getEquipmentStatistics(String deviceType,String deviceName,String showLevel){
|
|
|
try {
|
|
|
JSONObject result = new JSONObject();
|
|
|
JSONArray arrTmp = new JSONArray();
|
|
|
result.put("deviceInfo",arrTmp);
|
|
|
result.put("iotCount",0);
|
|
|
result.put("grantCount",0);
|
|
|
result.put("lostContact",0);
|
|
|
if (deviceType.contains("1")||deviceType.contains("2")) {
|
|
|
StringBuffer sql = new StringBuffer("SELECT a.category_code type,a.device_name,a.c as 'using',b.c-a.c as 'stock',b.c as 'total' from ( ");
|
|
|
StringBuffer sqlCondition = new StringBuffer();
|
|
|
if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName)){
|
|
|
sqlCondition.append("and d.device_name='"+deviceName+"' ");
|
|
|
}
|
|
|
sql.append("SELECT d.category_code,d.device_name, COUNT(*) c from wlyy.wlyy_patient_device d,wlyy.wlyy_sign_family f WHERE f.`status`>0 and f.patient = d.`user` "+sqlCondition+" ");
|
|
|
if ("0".equals(showLevel)){//组合一体机(5健康小屋,取自物联网),单体征测量仪(2血压计、1血糖仪)
|
|
|
if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)){
|
|
|
sql.append("and d.category_code in ('").append(deviceType.replace(",","','")).append("'))a, ");
|
|
|
}
|
|
|
sql.append("(SELECT d.category_code,d.device_name,COUNT(*) c from wlyy.wlyy_patient_device d where 1=1 "+sqlCondition+" ");
|
|
|
if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)){
|
|
|
sql.append("and d.category_code in ('").append(deviceType.replace(",","','")).append("'))b ");
|
|
|
}
|
|
|
}
|
|
|
else if("1".equals(showLevel)){ //血压计,血糖仪。。。
|
|
|
sql.append("GROUP BY d.category_code )a, ");
|
|
|
sql.append("(SELECT d.category_code,d.device_name,COUNT(*) c from wlyy.wlyy_patient_device d where 1=1 "+sqlCondition+" ");
|
|
|
sql.append("GROUP BY d.category_code )b ");
|
|
|
sql.append("WHERE a.category_code = b.category_code ");
|
|
|
if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)){
|
|
|
sql.append("and a.category_code in ('").append(deviceType.replace(",","','")).append("') ");
|
|
|
}
|
|
|
}else if ("2".equals(showLevel)){//XX血压计1,XX血压计1
|
|
|
sql.append("GROUP BY d.category_code,d.device_name) a, ");
|
|
|
sql.append("(SELECT d.category_code,d.device_name,COUNT(*) c from wlyy.wlyy_patient_device d where 1=1 "+sqlCondition+" ");
|
|
|
sql.append("GROUP BY d.category_code,d.device_name) b ");
|
|
|
sql.append("WHERE a.category_code = b.category_code and a.device_name = b.device_name ");
|
|
|
if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)){
|
|
|
sql.append("and a.category_code in ('").append(deviceType.replace(",","','")).append("') ");
|
|
|
}
|
|
|
}
|
|
|
List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql.toString());
|
|
|
JSONArray arr = JSONArray.parseArray(JSON.toJSONString(sqlResult));
|
|
|
for(int i=0;i<arr.size();i++){
|
|
|
JSONObject obj = arr.getJSONObject(i);
|
|
|
if ("0".equals(showLevel)){
|
|
|
obj.put("device_name","单体征测量仪");
|
|
|
obj.put("Subdivision",true);//是否可查看下一层次
|
|
|
}
|
|
|
else if("1".equals(showLevel)){
|
|
|
String temp = obj.getString("type");
|
|
|
if("1".equals(temp)){
|
|
|
obj.put("device_name","血糖仪");
|
|
|
}else if("2".equals(temp)){
|
|
|
obj.put("device_name","血压计");
|
|
|
}
|
|
|
obj.put("Subdivision",true);
|
|
|
}
|
|
|
else{
|
|
|
obj.put("Subdivision",false);
|
|
|
}
|
|
|
}
|
|
|
result.put("deviceInfo",arr);//设备信息统计
|
|
|
//统计物联率设备,失联设备
|
|
|
sql = new StringBuffer("select count(*) from wlyy.wlyy_patient_device d ");
|
|
|
sql.append("where d.device_sn in(select DISTINCT device_sn from device.wlyy_patient_health_index where device_sn<>'') "+sqlCondition+" ");
|
|
|
if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)){
|
|
|
sql.append("and d.category_code in ('").append(deviceType.replace(",","','")).append("') ");
|
|
|
}
|
|
|
Integer iotCount = jdbcTemplate.queryForObject(sql.toString(),Integer.class);//物联设备数量
|
|
|
result.put("iotCount",iotCount);
|
|
|
|
|
|
sql = new StringBuffer("select count(*) from wlyy.wlyy_patient_device d ,wlyy.wlyy_sign_family f WHERE f.`status`>0 and f.patient = d.`user` "+sqlCondition+" ");
|
|
|
if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)){
|
|
|
sql.append("and d.category_code in ('").append(deviceType.replace(",","','")).append("') ");
|
|
|
}
|
|
|
Integer grantCount = jdbcTemplate.queryForObject(sql.toString(),Integer.class);//设备发放总数
|
|
|
result.put("grantCount",grantCount);
|
|
|
|
|
|
//失联设备(一周未上传当作失联)
|
|
|
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()) <= 7)");
|
|
|
Integer lostContact = jdbcTemplate.queryForObject(sql.toString(),Integer.class);
|
|
|
result.put("lostContact",lostContact);
|
|
|
}
|
|
|
//deviceType包含小屋且设备名称为空||deviceType包含小屋且设备名称为健康小屋。
|
|
|
if ((deviceType.contains("5")&&org.apache.commons.lang3.StringUtils.isBlank(deviceName))||(deviceType.contains("5")&&org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName)&&"健康小屋".equals(deviceName))){
|
|
|
String sql = "select COUNT(*) from xmiot.iot_equipmet_detail";
|
|
|
Integer count = jdbcTemplate.queryForObject(sql,Integer.class);
|
|
|
JSONObject tmp = new JSONObject();
|
|
|
tmp.put("using",count);
|
|
|
tmp.put("total",count);
|
|
|
tmp.put("type","5");
|
|
|
tmp.put("stock",0);
|
|
|
if("0".equals(showLevel)){
|
|
|
tmp.put("device_name","组合一体机");
|
|
|
tmp.put("Subdivision",true);
|
|
|
}else{
|
|
|
tmp.put("device_name","健康小屋");
|
|
|
tmp.put("Subdivision",false);
|
|
|
}
|
|
|
result.getJSONArray("deviceInfo").add(tmp);
|
|
|
result.put("grantCount",result.getInteger("grantCount")+count);
|
|
|
//统计健康小屋数据/ 小屋全部统计为正常使用
|
|
|
sql ="select count(*) from xmiot.iot_equipmet_detail where device_code in (select DISTINCT sn device_model from xmiot.wlyy_iot_m)";
|
|
|
count = jdbcTemplate.queryForObject(sql,Integer.class);
|
|
|
result.put("iotCount",result.getInteger("iotCount")+count);//小屋物联
|
|
|
}
|
|
|
arrTmp = result.getJSONArray("deviceInfo");
|
|
|
for (int i=0;i<arrTmp.size();i++){
|
|
|
JSONObject tmp = arrTmp.getJSONObject(i);
|
|
|
if (tmp.getInteger("total")==0){
|
|
|
arrTmp.remove(tmp);
|
|
|
}
|
|
|
}
|
|
|
result.put("iotRangeString",result.getInteger("iotCount")+"/"+result.getInteger("grantCount"));
|
|
|
result.put("lostRangeString",result.getInteger("lostContact")+"/"+result.getInteger("grantCount"));
|
|
|
result.put("iotRange",getRange(result.getInteger("iotCount"),result.getInteger("grantCount"),2));
|
|
|
result.put("lostRange",getRange(result.getInteger("lostContact"),result.getInteger("grantCount"),2));
|
|
|
return result;
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public String getRange(int first, int second, int i) {
|
|
|
if (second == 0 && first > 0) {
|
|
|
return "100%";
|
|
|
} else if (second == 0 && first == 0) {
|
|
|
return "0.00%";
|
|
|
}
|
|
|
float size = (float) (first * 100) / second;
|
|
|
DecimalFormat df = new DecimalFormat("0.00");//格式化小数,不足的补0
|
|
|
String filesize = df.format(size);
|
|
|
return filesize + "%";
|
|
|
}
|
|
|
|
|
|
}
|