添加获取设备实时数据定时任务等
This commit is contained in:
parent
9011a5bd07
commit
00165f5123
@ -54,6 +54,12 @@
|
||||
<version>3.8.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fastbee</groupId>
|
||||
<artifactId>fastbee-device-service</artifactId>
|
||||
<version>3.8.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.fastbee</groupId>-->
|
||||
|
@ -0,0 +1,28 @@
|
||||
package com.fastbee.data.controller.media;
|
||||
|
||||
import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.device.api.yingshiyun.service.YingshiyunService;
|
||||
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;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/media/yingshiyun")
|
||||
public class YingshiyunVideoController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private YingshiyunService yingshiyunService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取视频播放地址
|
||||
* @param deviceSerial 设备的序列号/编号
|
||||
* @return 视频播放地址
|
||||
*/
|
||||
@GetMapping("/video-playUrl/get")
|
||||
public AjaxResult getVideoUrl(String deviceSerial){
|
||||
return success(yingshiyunService.getVideoPlayUrl(deviceSerial));
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@
|
||||
<version>3.8.5</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>fastbee-deviceData-service</artifactId>
|
||||
<artifactId>fastbee-device-service</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
@ -0,0 +1,10 @@
|
||||
package com.fastbee.device.api.renke.constant;
|
||||
|
||||
/**
|
||||
* 建大仁科设备类型常量
|
||||
*/
|
||||
public class RenKeDeviceTypeConstant {
|
||||
public static final String MET = "met";//气象设备
|
||||
public static final String WORM = "wormFlagship";//虫情设备
|
||||
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
package com.fastbee.device.api.renke.service;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
public class RenkeDeviceDataService {
|
||||
@Autowired
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备实时数据
|
||||
* @param deviceAddrs 设备地址,支持多个用英文逗号分隔
|
||||
*/
|
||||
public void getDeviceRealtimeData(String deviceAddrs) {
|
||||
//处理鉴权
|
||||
String token = getAuth();
|
||||
//获取设备实时数据
|
||||
HttpResponse response = HttpRequest.get("http://api.farm.0531yun.cn/api/v2.0/entrance/device/getRealTimeData")
|
||||
.header("token", token)
|
||||
.form("deviceAddrs", deviceAddrs)
|
||||
.execute();
|
||||
String respBodyStr = response.body();
|
||||
if(StringUtils.isBlank(respBodyStr)) {
|
||||
throw new RuntimeException("获取设备实时数据失败!");
|
||||
}
|
||||
JSONObject respBody = JSONUtil.parseObj(respBodyStr);
|
||||
JSONArray realtimeDataList = JSONUtil.parseArray(respBody.get("data"));
|
||||
System.err.println("设备实时数据:"+realtimeDataList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//获取token
|
||||
private String getAuth(){
|
||||
//判断token是否过期
|
||||
String cacheToken = stringRedisTemplate.opsForValue().get("rkckth:user:token");
|
||||
if (!Objects.isNull(cacheToken)){
|
||||
System.err.println("缓存中获取token:"+cacheToken);
|
||||
return cacheToken;
|
||||
}
|
||||
//获取token
|
||||
//构建请求体
|
||||
Map<String,Object> reqBody =new HashMap<>();
|
||||
reqBody.put("loginName","heilongjiang");
|
||||
reqBody.put("loginPwd","123456");
|
||||
|
||||
HttpResponse response = HttpRequest.post("http://api.farm.0531yun.cn/api/v2.0/entrance/user/userLogin")
|
||||
.body(JSONUtil.toJsonStr(reqBody)).execute();
|
||||
System.err.println("响应:"+response.body());
|
||||
String resultObjectStr = response.body();
|
||||
if(StringUtils.isBlank(response.toString())){
|
||||
throw new RuntimeException("获取token失败!");
|
||||
}
|
||||
JSONObject resultObject = JSONUtil.parseObj(resultObjectStr);
|
||||
JSONObject tokenObject = JSONUtil.parseObj(resultObject.get("data"));
|
||||
int currDate = Integer.parseInt(tokenObject.get("currDate").toString());
|
||||
int expDate = Integer.parseInt(tokenObject.get("expDate").toString());
|
||||
Integer periodValidity= expDate - currDate;
|
||||
//将token存入redis
|
||||
stringRedisTemplate.opsForValue().set("rkckth:user:token", tokenObject.get("token").toString(),2, TimeUnit.HOURS);
|
||||
System.err.println("请求获取到token:"+tokenObject.get("token").toString());
|
||||
return stringRedisTemplate.opsForValue().get("rkckth:user:token").toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.fastbee.device.api.renke.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 建大仁科气象设备服务
|
||||
*/
|
||||
@Service
|
||||
public class RenkeMetDeviceService {
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.fastbee.device.api.renke.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 建大仁科虫情设备服务
|
||||
*/
|
||||
@Service
|
||||
public class RenkeWormSituationDeviceService {
|
||||
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.fastbee.deviceData.api.yingshiyun.service;
|
||||
package com.fastbee.device.api.yingshiyun.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
@ -12,6 +12,8 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Service
|
||||
@ -49,6 +51,10 @@ public class YingshiyunService {
|
||||
JSONObject jsonObject = JSONUtil.parseObj(response.body());
|
||||
String videoPlayUrl = JSONUtil.parseObj(jsonObject.get("data")).get("url").toString();
|
||||
String expireTime = JSONUtil.parseObj(jsonObject.get("data")).get("expireTime").toString();
|
||||
Map<String, Object> resp= new HashMap<>();
|
||||
resp.put("videoPlayUrl",videoPlayUrl);
|
||||
resp.put("expireTime",expireTime);
|
||||
resp.put("deviceSerial",deviceSerial);
|
||||
return videoPlayUrl;
|
||||
}
|
||||
|
@ -1,11 +1,9 @@
|
||||
package com.fastbee.deviceData.domain;
|
||||
package com.fastbee.device.domain;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.fastbee.common.annotation.Excel;
|
||||
import com.fastbee.common.core.domain.BaseEntity;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.fastbee.deviceData.mapper;
|
||||
package com.fastbee.device.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.fastbee.deviceData.domain.DeviceRealtimedataWorms;
|
||||
import com.fastbee.device.domain.DeviceRealtimedataWorms;
|
||||
|
||||
/**
|
||||
* 虫情设备实时数据Mapper接口
|
@ -1,7 +1,7 @@
|
||||
package com.fastbee.deviceData.service;
|
||||
package com.fastbee.device.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.fastbee.deviceData.domain.DeviceRealtimedataWorms;
|
||||
import com.fastbee.device.domain.DeviceRealtimedataWorms;
|
||||
|
||||
/**
|
||||
* 虫情设备实时数据Service接口
|
@ -1,11 +1,11 @@
|
||||
package com.fastbee.deviceData.service.impl;
|
||||
package com.fastbee.device.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.fastbee.deviceData.mapper.DeviceRealtimedataWormsMapper;
|
||||
import com.fastbee.deviceData.domain.DeviceRealtimedataWorms;
|
||||
import com.fastbee.deviceData.service.IDeviceRealtimedataWormsService;
|
||||
import com.fastbee.device.mapper.DeviceRealtimedataWormsMapper;
|
||||
import com.fastbee.device.domain.DeviceRealtimedataWorms;
|
||||
import com.fastbee.device.service.IDeviceRealtimedataWormsService;
|
||||
|
||||
/**
|
||||
* 虫情设备实时数据Service业务层处理
|
@ -6,6 +6,7 @@ import com.fastbee.common.annotation.Excel;
|
||||
import com.fastbee.iot.model.ThingsModelItem.*;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@ -17,8 +18,7 @@ import java.util.List;
|
||||
* @author kerwincui
|
||||
* @date 2021-12-16
|
||||
*/
|
||||
public class DeviceShortOutput
|
||||
{
|
||||
public class DeviceShortOutput implements Serializable {
|
||||
public DeviceShortOutput(){
|
||||
this.stringList=new ArrayList<>();
|
||||
this.integerList=new ArrayList<>();
|
||||
|
@ -0,0 +1,87 @@
|
||||
package com.fastbee.iot.timer;
|
||||
|
||||
import cn.hutool.http.HttpConfig;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.fastbee.common.core.redis.RedisCache;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author mijiupro
|
||||
*/
|
||||
@Component("renkeDeviceDateTask")
|
||||
public class DeviceDateTask {
|
||||
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
/**
|
||||
* 在执行定时任务中出现了异常会终止调度,所以需要捕获异常以便于下一轮
|
||||
* 执行,不会影响下一次执行
|
||||
*/
|
||||
public void getRenkeDeviceRealtimeData() throws Exception{
|
||||
//处理鉴权
|
||||
String token = getAuth();
|
||||
//获取设备实时数据
|
||||
//请求参数
|
||||
HttpResponse response = HttpRequest.get("http://api.farm.0531yun.cn/api/v2.0/entrance/device/getRealTimeData")
|
||||
.header("token", token)
|
||||
.execute();
|
||||
String respBodyStr = response.body();
|
||||
if(StringUtils.isBlank(respBodyStr)) {
|
||||
throw new RuntimeException("获取设备实时数据失败!");
|
||||
}
|
||||
JSONObject respBody = JSONUtil.parseObj(respBodyStr);
|
||||
JSONArray realtimeList = JSONUtil.parseArray(respBody.get("data"));
|
||||
System.err.println("设备实时数据:"+realtimeList);
|
||||
//TODO 解析实时数据保存到数据库
|
||||
|
||||
}
|
||||
|
||||
|
||||
private String getAuth(){
|
||||
//判断token是否过期
|
||||
String cacheToken = stringRedisTemplate.opsForValue().get("rkckth:user:token");
|
||||
if (!Objects.isNull(cacheToken)){
|
||||
System.err.println("缓存中获取token:"+cacheToken);
|
||||
return cacheToken;
|
||||
}
|
||||
//获取token
|
||||
//构建请求体
|
||||
Map<String,Object> reqBody =new HashMap<>();
|
||||
reqBody.put("loginName","heilongjiang");
|
||||
reqBody.put("loginPwd","123456");
|
||||
|
||||
HttpResponse response = HttpRequest.post("http://api.farm.0531yun.cn/api/v2.0/entrance/user/userLogin")
|
||||
.body(JSONUtil.toJsonStr(reqBody)).execute();
|
||||
System.err.println("响应:"+response.body());
|
||||
String resultObjectStr = response.body();
|
||||
if(StringUtils.isBlank(response.toString())){
|
||||
throw new RuntimeException("获取token失败!");
|
||||
}
|
||||
JSONObject resultObject = JSONUtil.parseObj(resultObjectStr);
|
||||
JSONObject tokenObject = JSONUtil.parseObj(resultObject.get("data"));
|
||||
int currDate = Integer.parseInt(tokenObject.get("currDate").toString());
|
||||
int expDate = Integer.parseInt(tokenObject.get("expDate").toString());
|
||||
Integer periodValidity= expDate - currDate;
|
||||
//将token存入redis
|
||||
stringRedisTemplate.opsForValue().set("rkckth:user:token", tokenObject.get("token").toString(),2,TimeUnit.HOURS);
|
||||
System.err.println("请求获取到token:"+tokenObject.get("token").toString());
|
||||
return stringRedisTemplate.opsForValue().get("rkckth:user:token").toString();
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
<module>fastbee-waterele-service</module>
|
||||
<module>fastbee-project-service</module>
|
||||
<module>fastbee-ggroup-service</module>
|
||||
<module>fastbee-deviceData-service</module>
|
||||
<module>fastbee-device-service</module>
|
||||
</modules>
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user