农业大屏统计相关接口
This commit is contained in:
parent
3d6372cee9
commit
eea03062dd
@ -0,0 +1,115 @@
|
|||||||
|
package com.fastbee.data.controller.deviceData;
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpUtil;
|
||||||
|
import cn.hutool.json.JSONArray;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.dtflys.forest.annotation.Get;
|
||||||
|
import com.fastbee.common.core.controller.BaseController;
|
||||||
|
import com.fastbee.common.core.domain.AjaxResult;
|
||||||
|
import com.fastbee.deviceData.api.devlink.service.DevLinkAuthorizationService;
|
||||||
|
import com.fastbee.deviceData.api.devlink.service.DevLinkBaseService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备告警
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/device/statistics")
|
||||||
|
public class DeviceAlarmController extends BaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DevLinkBaseService devLinkBaseService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备告警数量
|
||||||
|
*/
|
||||||
|
@GetMapping("/alarm/count")
|
||||||
|
public AjaxResult getDeviceAlarmCount() {
|
||||||
|
|
||||||
|
HashMap<String, Object> body = new HashMap<>();
|
||||||
|
body.put("method","get");
|
||||||
|
body.put("path","api/v1/product/device/statistics/months");
|
||||||
|
JSONObject data = devLinkBaseService.baseRequest(body);
|
||||||
|
return AjaxResult.success(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备相关统计
|
||||||
|
*/
|
||||||
|
@GetMapping("/count")
|
||||||
|
public AjaxResult getDeviceStatusCount() {
|
||||||
|
HashMap<String, Object> body = new HashMap<>();
|
||||||
|
body.put("method","get");
|
||||||
|
body.put("path","api/v1/product/device/statistics");
|
||||||
|
JSONObject data = devLinkBaseService.baseRequest(body);
|
||||||
|
//计算安全状态等级
|
||||||
|
String securityLevel="?";
|
||||||
|
JSONObject total = JSONUtil.parseObj(data.get("deviceTotal"));
|
||||||
|
|
||||||
|
int alarmTotal = Integer.parseInt(total.get("alarmTotal").toString());
|
||||||
|
if(alarmTotal < 2){
|
||||||
|
securityLevel= "A";
|
||||||
|
}
|
||||||
|
else if(alarmTotal<4){
|
||||||
|
securityLevel = "B";
|
||||||
|
}else if(alarmTotal<6){
|
||||||
|
securityLevel = "C";
|
||||||
|
}else if(alarmTotal<8){
|
||||||
|
securityLevel = "D";
|
||||||
|
}
|
||||||
|
total.put("securityLevel",securityLevel);
|
||||||
|
return AjaxResult.success(total);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计不同设备数量
|
||||||
|
*/
|
||||||
|
@GetMapping("/countByType")
|
||||||
|
public AjaxResult getDeviceCountByType() {
|
||||||
|
HashMap<String, Object> body = new HashMap<>();
|
||||||
|
body.put("method","get");
|
||||||
|
body.put("path","api/v1/product/device/list");
|
||||||
|
JSONObject data = devLinkBaseService.baseRequest(body);
|
||||||
|
//设备列表
|
||||||
|
JSONArray devArray = JSONUtil.parseArray(data);
|
||||||
|
//分组统计
|
||||||
|
Map<String, Integer> map = new HashMap<>();
|
||||||
|
for (int i = 0; i < devArray.size(); i++) {
|
||||||
|
JSONObject dev = devArray.getJSONObject(i);
|
||||||
|
String type = dev.get("type").toString();
|
||||||
|
if(map.containsKey(type)){
|
||||||
|
map.put(type,map.get(type)+1);
|
||||||
|
}else
|
||||||
|
map.put(type,1);
|
||||||
|
}
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计设备在线率
|
||||||
|
*/
|
||||||
|
@GetMapping("/onlineRate")
|
||||||
|
public AjaxResult getDeviceOnlineRate() {
|
||||||
|
HashMap<String, Object> body = new HashMap<>();
|
||||||
|
body.put("method","get");
|
||||||
|
body.put("path","api/v1/product/device/list");
|
||||||
|
JSONObject data = devLinkBaseService.baseRequest(body);
|
||||||
|
//设备列表
|
||||||
|
JSONArray devArray = JSONUtil.parseArray(data);
|
||||||
|
//分组统计
|
||||||
|
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -4,7 +4,7 @@ import cn.hutool.http.HttpUtil;
|
|||||||
import cn.hutool.json.JSONArray;
|
import cn.hutool.json.JSONArray;
|
||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.fastbee.common.utils.DateUtils;
|
import com.fastbee.common.exception.ServiceException;
|
||||||
import com.fastbee.deviceData.domain.DeviceRealtimedataMeteorology;
|
import com.fastbee.deviceData.domain.DeviceRealtimedataMeteorology;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -14,7 +14,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class DevLinkRealTimeDataService {
|
public class DevLinkBaseService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private DevLinkAuthorizationService authorizationService;
|
private DevLinkAuthorizationService authorizationService;
|
||||||
|
|
||||||
@ -92,6 +92,22 @@ public class DevLinkRealTimeDataService {
|
|||||||
return HttpUtil.post(authorization.getBaseUrl() + authorization.getAuth(), jsonStr);
|
return HttpUtil.post(authorization.getBaseUrl() + authorization.getAuth(), jsonStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基本请求
|
||||||
|
* @return 请求结果data
|
||||||
|
*/
|
||||||
|
public JSONObject baseRequest(Map<String,Object> body){
|
||||||
|
DevLinkAuthorizationService authorization = new DevLinkAuthorizationService();
|
||||||
|
String jsonStr = JSONUtil.toJsonStr(body);
|
||||||
|
System.err.println(authorization.getBaseUrl() + authorization.getAuth());
|
||||||
|
String respStr = HttpUtil.post(authorization.getBaseUrl() + authorization.getAuth(), jsonStr);
|
||||||
|
JSONObject resp = JSONUtil.parseObj(respStr);
|
||||||
|
if(!resp.get("code").toString().equals("200")){
|
||||||
|
throw new ServiceException(resp.get("message").toString());
|
||||||
|
}
|
||||||
|
return resp.getJSONObject("data");
|
||||||
|
}
|
||||||
|
|
||||||
public BigDecimal toBigDecimalValue(String str) {
|
public BigDecimal toBigDecimalValue(String str) {
|
||||||
if (str == null||"".equals(str)) {
|
if (str == null||"".equals(str)) {
|
||||||
return null;
|
return null;
|
||||||
@ -106,8 +122,8 @@ public class DevLinkRealTimeDataService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
DevLinkRealTimeDataService devLinkRealTimeDataService = new DevLinkRealTimeDataService();
|
DevLinkBaseService devLinkBaseService = new DevLinkBaseService();
|
||||||
Map<String, String> metDeviceRealData = devLinkRealTimeDataService.getMetDeviceRealData("3270");
|
Map<String, String> metDeviceRealData = devLinkBaseService.getMetDeviceRealData("3270");
|
||||||
// System.err.println(metDeviceRealData);
|
// System.err.println(metDeviceRealData);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,7 +17,7 @@ import java.util.Map;
|
|||||||
* devLink气象设备数据服务
|
* devLink气象设备数据服务
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class DevLinkMetDataService extends DevLinkRealTimeDataService {
|
public class DevLinkMetDataService extends DevLinkBaseService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DevLinkAuthorizationService authorizationService;
|
private DevLinkAuthorizationService authorizationService;
|
||||||
|
@ -3,9 +3,7 @@ package com.fastbee.deviceData.api.devlink.service;
|
|||||||
import com.fastbee.common.exception.ServiceException;
|
import com.fastbee.common.exception.ServiceException;
|
||||||
import com.fastbee.common.utils.DateUtils;
|
import com.fastbee.common.utils.DateUtils;
|
||||||
import com.fastbee.deviceData.domain.DeviceRealtimedataMiaoqing;
|
import com.fastbee.deviceData.domain.DeviceRealtimedataMiaoqing;
|
||||||
import com.fastbee.deviceData.domain.DeviceRealtimedataPhotovoltaic;
|
|
||||||
import com.fastbee.deviceData.mapper.DeviceRealtimedataMiaoqingMapper;
|
import com.fastbee.deviceData.mapper.DeviceRealtimedataMiaoqingMapper;
|
||||||
import com.fastbee.deviceData.mapper.DeviceRealtimedataPhotovoltaicMapper;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -18,7 +16,7 @@ import java.util.Map;
|
|||||||
* devLink苗情设备数据服务
|
* devLink苗情设备数据服务
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class DevLinkMiaoQingDataService extends DevLinkRealTimeDataService {
|
public class DevLinkMiaoQingDataService extends DevLinkBaseService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private DevLinkAuthorizationService authorizationService;
|
private DevLinkAuthorizationService authorizationService;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -2,14 +2,11 @@ package com.fastbee.deviceData.api.devlink.service;
|
|||||||
|
|
||||||
import com.fastbee.common.exception.ServiceException;
|
import com.fastbee.common.exception.ServiceException;
|
||||||
import com.fastbee.common.utils.DateUtils;
|
import com.fastbee.common.utils.DateUtils;
|
||||||
import com.fastbee.deviceData.domain.DeviceRealtimedataMeteorology;
|
|
||||||
import com.fastbee.deviceData.domain.DeviceRealtimedataMoisture;
|
import com.fastbee.deviceData.domain.DeviceRealtimedataMoisture;
|
||||||
import com.fastbee.deviceData.mapper.DeviceRealtimedataMeteorologyMapper;
|
|
||||||
import com.fastbee.deviceData.mapper.DeviceRealtimedataMoistureMapper;
|
import com.fastbee.deviceData.mapper.DeviceRealtimedataMoistureMapper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -19,7 +16,7 @@ import java.util.Map;
|
|||||||
* devLink墒情设备数据服务
|
* devLink墒情设备数据服务
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class DevLinkMoistureDataService extends DevLinkRealTimeDataService{
|
public class DevLinkMoistureDataService extends DevLinkBaseService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private DevLinkAuthorizationService authorizationService;
|
private DevLinkAuthorizationService authorizationService;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -16,7 +16,7 @@ import java.util.Map;
|
|||||||
* devLink光伏设备数据服务
|
* devLink光伏设备数据服务
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class DevLinkPhotovoltaicDataService extends DevLinkRealTimeDataService{
|
public class DevLinkPhotovoltaicDataService extends DevLinkBaseService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private DevLinkAuthorizationService authorizationService;
|
private DevLinkAuthorizationService authorizationService;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -73,7 +73,7 @@ import static com.fastbee.common.utils.SecurityUtils.isAdmin;
|
|||||||
* 设备Service业务层处理
|
* 设备Service业务层处理
|
||||||
*
|
*
|
||||||
* @author kerwincui
|
* @author kerwincui
|
||||||
* @date 2021-12-16
|
* @date 2021-12-16
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class DeviceServiceImpl implements IDeviceService {
|
public class DeviceServiceImpl implements IDeviceService {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user