@@ -0,0 +1,103 @@ | |||
package com.tuoheng.admin.entity.third; | |||
import com.tuoheng.common.core.common.BaseEntity; | |||
import lombok.Data; | |||
import lombok.experimental.Accessors; | |||
import java.util.List; | |||
@Data | |||
@Accessors(chain = true) | |||
public class Airport extends BaseEntity { | |||
/** | |||
* | |||
*/ | |||
private String name; | |||
/** | |||
* | |||
*/ | |||
private String code; | |||
/** | |||
* | |||
*/ | |||
private String longitude; | |||
/** | |||
* | |||
*/ | |||
private String latitude; | |||
/** | |||
* | |||
*/ | |||
private String groundStationUrl; | |||
/** | |||
* | |||
*/ | |||
private Integer droneId; | |||
/** | |||
* | |||
*/ | |||
private String droneName; | |||
/** | |||
* | |||
*/ | |||
private String status; | |||
/** | |||
* | |||
*/ | |||
private String astatus; | |||
/** | |||
* | |||
*/ | |||
private String internalMonitorUrl; | |||
/** | |||
* | |||
*/ | |||
private String externalMonitorUrl; | |||
/** | |||
* | |||
*/ | |||
private String coverage; | |||
/** | |||
* | |||
*/ | |||
private String image; | |||
/** | |||
* | |||
*/ | |||
private String address; | |||
/** | |||
* | |||
*/ | |||
private Integer sort; | |||
/** | |||
* | |||
*/ | |||
private String edgeId; | |||
/** | |||
* | |||
*/ | |||
private Boolean online; | |||
/** | |||
* | |||
*/ | |||
private List<AirportTaskLine> taskLineList; | |||
} |
@@ -0,0 +1,70 @@ | |||
package com.tuoheng.admin.entity.third; | |||
import lombok.Data; | |||
import lombok.experimental.Accessors; | |||
@Data | |||
@Accessors(chain = true) | |||
public class AirportTaskLine { | |||
/** | |||
* | |||
*/ | |||
private Integer id; | |||
/** | |||
* | |||
*/ | |||
private String name; | |||
/** | |||
* | |||
*/ | |||
private Integer tenantId; | |||
/** | |||
* | |||
*/ | |||
private Integer droneId; | |||
/** | |||
* | |||
*/ | |||
private Integer aid; | |||
/** | |||
* | |||
*/ | |||
private Integer airlineFileId; | |||
/** | |||
* | |||
*/ | |||
private Integer status; | |||
/** | |||
* | |||
*/ | |||
private Integer type; | |||
/** | |||
* | |||
*/ | |||
private String createUser; | |||
/** | |||
* | |||
*/ | |||
private String createTime; | |||
/** | |||
* | |||
*/ | |||
private String updateUser; | |||
/** | |||
* | |||
*/ | |||
private Integer mark; | |||
} |
@@ -0,0 +1,166 @@ | |||
package com.tuoheng.admin.entity.third; | |||
import lombok.Data; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2023/5/22 | |||
*/ | |||
@Data | |||
@Accessors(chain = true) | |||
public class LingXiuAirDataResponse { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 卫星编号 | |||
*/ | |||
private Integer sateNum; | |||
/** | |||
* 序号 | |||
*/ | |||
private Integer sequence; | |||
/** | |||
* 序列号 | |||
*/ | |||
private String serial; | |||
/** | |||
* 高度 | |||
*/ | |||
private String altitude; | |||
/** | |||
* 纬度 | |||
*/ | |||
private String latitude; | |||
/** | |||
* 经度 | |||
*/ | |||
private String longitude; | |||
/** | |||
* 温度 | |||
*/ | |||
private String temperature; | |||
/** | |||
* 湿度 | |||
*/ | |||
private String humidity; | |||
/** | |||
* 水平精度因子 | |||
*/ | |||
private String hdop; | |||
/** | |||
* 大气压 | |||
*/ | |||
private String pressure; | |||
/** | |||
* UTC时间 | |||
*/ | |||
private String cUtcTime; | |||
/** | |||
* 氯气(单位ppm) | |||
*/ | |||
private String cl2; | |||
/** | |||
* 一氧化碳(单位ppm) | |||
*/ | |||
private String co; | |||
/** | |||
* 二氧化碳(单位ppm) | |||
*/ | |||
private String co2; | |||
/** | |||
* 碳氢化合物(单位%) | |||
*/ | |||
private String cxhy; | |||
/** | |||
* 氢气(单位ppm) | |||
*/ | |||
private String h2; | |||
/** | |||
* 硫化氢(单位ppm) | |||
*/ | |||
private String h2s; | |||
/** | |||
* 氯化氢(单位ppm) | |||
*/ | |||
private String hcl; | |||
/** | |||
* 氰化氢(单位ppm) | |||
*/ | |||
private String hcn; | |||
/** | |||
* 氨气(单位ppm) | |||
*/ | |||
private String nh3; | |||
/** | |||
* 邻二甲苯(单位ppm) | |||
*/ | |||
private String ox; | |||
/** | |||
* 磷化氢(单位ppm) | |||
*/ | |||
private String ph3; | |||
/** | |||
* PM1.0(单位ug/m3) | |||
*/ | |||
private String pm_1_0; | |||
/** | |||
*PM10(单位ug/m3) | |||
*/ | |||
private String pm_10; | |||
/** | |||
*PM2.5(单位ug/m3) | |||
*/ | |||
private String pm_2_5; | |||
/** | |||
*二氧化硫(单位ppm) | |||
*/ | |||
private String so2; | |||
/** | |||
*磷酸三钠(单位mg/m3) | |||
*/ | |||
private String tsp; | |||
/** | |||
*挥发性有机物(单位ppm) | |||
*/ | |||
private String vocs; | |||
/** | |||
* WR二氧化硫(单位ppm) | |||
*/ | |||
private String wrSo2; | |||
/** | |||
* 二氧化氮(单位ppm) | |||
*/ | |||
private String no2; | |||
} |
@@ -0,0 +1,77 @@ | |||
package com.tuoheng.admin.entity.third; | |||
import lombok.Data; | |||
import lombok.experimental.Accessors; | |||
import java.util.Map; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2023/5/22 | |||
*/ | |||
@Data | |||
@Accessors(chain = true) | |||
public class LingXiuDataResponse { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 卫星编号 | |||
*/ | |||
private Integer sateNum; | |||
/** | |||
* 序号 | |||
*/ | |||
private Integer sequence; | |||
/** | |||
* 序列号 | |||
*/ | |||
private String serial; | |||
/** | |||
* 高度 | |||
*/ | |||
private String altitude; | |||
/** | |||
* 纬度 | |||
*/ | |||
private String latitude; | |||
/** | |||
* 经度 | |||
*/ | |||
private String longitude; | |||
/** | |||
* 温度 | |||
*/ | |||
private String temperature; | |||
/** | |||
* 湿度 | |||
*/ | |||
private String humidity; | |||
/** | |||
* 水平精度因子 | |||
*/ | |||
private String hdop; | |||
/** | |||
* 大气压 | |||
*/ | |||
private String pressure; | |||
/** | |||
* UTC时间 | |||
*/ | |||
private String utcTime; | |||
/** | |||
* 大气数据 | |||
*/ | |||
private Map<String, Object> airData; | |||
} |
@@ -1,4 +1,4 @@ | |||
package com.tuoheng.admin.mqtt.provider; | |||
package com.tuoheng.admin.mqtt; | |||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
import com.tuoheng.admin.mqtt.consumer.MqttConsumerCallBack; | |||
@@ -75,7 +75,7 @@ public class MqttProviderConfig { | |||
client.setCallback(new MqttConsumerCallBack()); | |||
client.connect(options); | |||
// client.subscribe("/v1/" +airport.getEdgeId()+"/data/DoorMotor",0); | |||
// client.subscribe("$share/g1/v1/123456/environment/message", 0); | |||
QueryWrapper wrapper = new QueryWrapper(); | |||
wrapper.eq("mark", 1); |
@@ -2,6 +2,10 @@ package com.tuoheng.admin.mqtt.consumer; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.admin.entity.third.LingXiuDataResponse; | |||
import com.tuoheng.admin.mqtt.MqttProviderConfig; | |||
import com.tuoheng.admin.service.airData.IAirDataService; | |||
import com.tuoheng.common.core.utils.SpringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; | |||
import org.eclipse.paho.client.mqttv3.MqttCallback; | |||
@@ -10,26 +14,29 @@ import org.eclipse.paho.client.mqttv3.MqttMessage; | |||
@Slf4j | |||
public class MqttConsumerCallBack implements MqttCallback { | |||
private IAirDataService airDataService = SpringUtils.getBean(com.tuoheng.admin.service.airData.IAirDataService.class); | |||
/** | |||
* 客户端断开连接的回调 | |||
*/ | |||
@Override | |||
public void connectionLost(Throwable throwable) { | |||
System.out.println("与服务器断开连接,可重连"); | |||
/*MqttProviderConfig client = SpringUtil.getBean(MqttProviderConfig.class); | |||
System.out.println(client.isconnect()); | |||
log.info("与服务器断开连接,可重连, throwable={}", throwable); | |||
MqttProviderConfig client = SpringUtils.getBean(MqttProviderConfig.class); | |||
if (!client.isconnect()) { | |||
client.connect(); | |||
System.out.println("重连成功!"); | |||
}*/ | |||
} | |||
} | |||
/** | |||
* 消息到达的回调 | |||
*/ | |||
@Override | |||
public void messageArrived(String topic, MqttMessage message) throws Exception { | |||
log.info("接收消息主题 : {}\n{}", topic, JSONObject.parse(message.getPayload())); | |||
public void messageArrived(String topic, MqttMessage message) { | |||
log.info("接收灵嗅消息 : topic={}, message={}", topic, message); | |||
LingXiuDataResponse response = JSONObject.parseObject(message.getPayload(), LingXiuDataResponse.class); | |||
airDataService.syncData(response); | |||
} | |||
/** | |||
@@ -40,6 +47,5 @@ public class MqttConsumerCallBack implements MqttCallback { | |||
} | |||
} | |||
@@ -2,17 +2,17 @@ package com.tuoheng.admin.service.airData; | |||
import com.tuoheng.admin.entity.domain.AirData; | |||
import com.tuoheng.admin.entity.request.report.ExportReportRequest; | |||
import com.tuoheng.admin.entity.third.LingXiuDataResponse; | |||
import com.tuoheng.admin.mapper.AirDataMapper; | |||
import com.tuoheng.admin.service.airData.query.QueryAirDataListService; | |||
import com.tuoheng.admin.service.airData.report.ExportReportService; | |||
import com.tuoheng.admin.service.airData.syncdata.SyncAirDataService; | |||
import com.tuoheng.common.core.common.BaseServiceImpl; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.List; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2023/5/23 | |||
@@ -27,6 +27,8 @@ public class AirDataServiceImpl extends BaseServiceImpl<AirDataMapper, AirData> | |||
@Autowired | |||
private QueryAirDataListService queryAirDataListService; | |||
@Autowired | |||
private SyncAirDataService syncAirDataService; | |||
/** | |||
* 根据任务id获取大气数据列表 | |||
@@ -49,6 +51,15 @@ public class AirDataServiceImpl extends BaseServiceImpl<AirDataMapper, AirData> | |||
return queryAirDataListService.generateTable(id); | |||
} | |||
/** | |||
* 同步数据 | |||
* | |||
* @return | |||
*/ | |||
public JsonResult syncData(LingXiuDataResponse response) { | |||
return syncAirDataService.sync(response); | |||
} | |||
/** | |||
* 导出报告 | |||
* |
@@ -2,9 +2,9 @@ package com.tuoheng.admin.service.airData; | |||
import com.tuoheng.admin.entity.domain.AirData; | |||
import com.tuoheng.admin.entity.request.report.ExportReportRequest; | |||
import com.tuoheng.admin.entity.third.LingXiuDataResponse; | |||
import com.tuoheng.common.core.common.IBaseService; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import java.util.List; | |||
/** | |||
* @Author ChengWang | |||
@@ -21,6 +21,14 @@ public interface IAirDataService extends IBaseService<AirData> { | |||
JsonResult generateTable(String id); | |||
/** | |||
* | |||
* 同步数据 | |||
* | |||
* @return | |||
*/ | |||
JsonResult syncData(LingXiuDataResponse response); | |||
/** | |||
* | |||
* 导出报告 |
@@ -0,0 +1,141 @@ | |||
package com.tuoheng.admin.service.airData.syncdata; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.tuoheng.admin.entity.domain.AirData; | |||
import com.tuoheng.admin.entity.domain.Inspection; | |||
import com.tuoheng.admin.entity.third.LingXiuDataResponse; | |||
import com.tuoheng.admin.enums.InspectionStatusEnum; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
import com.tuoheng.admin.mapper.AirDataMapper; | |||
import com.tuoheng.admin.mapper.InspectionMapper; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.Map; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2023/5/24 | |||
*/ | |||
@Service | |||
@Slf4j | |||
public class SyncAirDataService { | |||
@Autowired | |||
private InspectionMapper inspectionMapper; | |||
@Autowired | |||
private AirDataMapper airDataMapper; | |||
public JsonResult sync(LingXiuDataResponse response) { | |||
log.info("收到灵嗅设备推送数据"); | |||
// if (ObjectUtil.isEmpty(response)) { | |||
// log.info("灵嗅设备推送数据为空"); | |||
// return JsonResult.error("灵嗅设备推送数据为空"); | |||
// } | |||
// if (StringUtils.isEmpty(response.getSerial())) { | |||
// log.info("灵嗅设备推送数据,serial为空"); | |||
// return JsonResult.error("灵嗅设备推送数据,serial为空"); | |||
// } | |||
// Inspection inspection = this.getInspection(response.getSerial()); | |||
// if (ObjectUtil.isNull(inspection)) { | |||
// log.info("该灵嗅设备没有正在飞行的任务,serial={}", response.getSerial()); | |||
// return JsonResult.error("该灵嗅设备没有正在飞行的任务"); | |||
// } | |||
AirData airData = new AirData(); | |||
// if (ObjectUtil.isNotEmpty(inspection)) { | |||
// airData.setInspectionId(inspection.getId()); // 任务ID | |||
// airData.setTenantId(inspection.getTenantId()); // 租户ID | |||
// } | |||
airData.setSateNum(response.getSateNum()); // 卫星编号 | |||
airData.setSequence(response.getSequence()); // 序号 | |||
airData.setSerial(response.getSerial()); // 序列号 | |||
airData.setAltitude(response.getAltitude()); // 高度 | |||
airData.setLatitude(response.getLatitude()); // 纬度 | |||
airData.setLongitude(response.getLongitude()); // 经度 | |||
airData.setTemperature(response.getTemperature()); // 温度 | |||
airData.setHumidity(response.getHumidity()); // 湿度 | |||
airData.setHdop(response.getHdop()); // 水平精度因子 | |||
airData.setPressure(response.getPressure()); // 大气压 | |||
airData.setCUtcTime(response.getUtcTime()); // UTC时间 | |||
Map<String, Object> airDataMap = response.getAirData(); | |||
String cl2 = String.valueOf(airDataMap.get("CL2(ppm)")); // 氯气(单位ppm) | |||
String co = String.valueOf(airDataMap.get("CO(ppm)")); // 一氧化碳(单位ppm) | |||
String co2 = String.valueOf(airDataMap.get("CO2(ppm)")); // 二氧化碳(单位ppm) | |||
String cxhy = String.valueOf(airDataMap.get("CxHy(%)")); // 碳氢化合物(单位%) | |||
String h2 = String.valueOf(airDataMap.get("H2(ppm)")); // 氢气(单位ppm) | |||
String h2s = String.valueOf(airDataMap.get("H2S(ppm)")); // 硫化氢(单位ppm) | |||
String hcl = String.valueOf(airDataMap.get("HCL(ppm)")); // 氯化氢(单位ppm) | |||
String hcn = String.valueOf(airDataMap.get("HCN(ppm)")); // 氰化氢(单位ppm) | |||
String nh3 = String.valueOf(airDataMap.get("NH3(ppm)")); // 氨气(单位ppm) | |||
String ox = String.valueOf(airDataMap.get("Ox(ppm)")); // 邻二甲苯(单位ppm) | |||
String ph3 = String.valueOf(airDataMap.get("PH3(ppm)")); // 磷化氢(单位ppm) | |||
String pm_1_0 = String.valueOf(airDataMap.get("PM1.0(ug/m3)")); // PM1.0(单位ug/m3) | |||
String pm_10 = String.valueOf(airDataMap.get("PM10(ug/m3)")); // PM10(单位ug/m3) | |||
String pm_2_5 = String.valueOf(airDataMap.get("PM2.5(ug/m3)")); // PM2.5(单位ug/m3) | |||
String so2 = String.valueOf(airDataMap.get("SO2(ppm)")); // 二氧化硫(单位ppm) | |||
String tsp = String.valueOf(airDataMap.get("TSP(mgm3)")); // 磷酸三钠(单位mg/m3) | |||
String vocs = String.valueOf(airDataMap.get("VOCs(ppm)")); // 挥发性有机物(单位ppm) | |||
String wrSo2 = String.valueOf(airDataMap.get("[WR]SO2(ppm)")); // WR二氧化硫(单位ppm) | |||
String no2 = String.valueOf(airDataMap.get("NO2(ppm)")); // 二氧化氮(单位ppm) | |||
String o2 = String.valueOf(airDataMap.get("O2(%)")); // 氧气(单位%) | |||
String ionizingRadiation = String.valueOf(airDataMap.get("Ionizing Radiation(uSv/h)")); // 电离辐射(uSv/h) | |||
String no = String.valueOf(airDataMap.get("NO(ppm)")); // 一氧化氮(ppm) | |||
String odorOu = String.valueOf(airDataMap.get("Odor OU")); // 恶臭气体 | |||
String hrch4 = String.valueOf(airDataMap.get("[HR]CH4(ppm)")); // [HR]甲烷(ppm) | |||
airData.setCl2(cl2); | |||
airData.setCo(co); | |||
airData.setCo2(co2); | |||
airData.setCxhy(cxhy); | |||
airData.setH2(h2); | |||
airData.setH2s(h2s); | |||
airData.setHcl(hcl); | |||
airData.setHcn(hcn); | |||
airData.setNh3(nh3); | |||
airData.setOx(ox); | |||
airData.setPh3(ph3); | |||
airData.setPm_1_0(pm_1_0); | |||
airData.setPm_10(pm_10); | |||
airData.setPm_2_5(pm_2_5); | |||
airData.setSo2(so2); | |||
airData.setTsp(tsp); | |||
airData.setVocs(vocs); | |||
airData.setWrSo2(wrSo2); | |||
airData.setNo2(no2); | |||
airData.setO2(o2); | |||
airData.setIonizingRadiation(ionizingRadiation); | |||
airData.setNo(no); | |||
airData.setOdorOu(odorOu); | |||
airData.setHrch4(hrch4); | |||
Integer count = airDataMapper.insert(airData); | |||
if (count <= 0) { | |||
log.info("灵嗅设备推送数据插入失败"); | |||
} | |||
return JsonResult.success(); | |||
} | |||
private Inspection getInspection(String serial) { | |||
Inspection inspection = inspectionMapper.selectOne(new LambdaQueryWrapper<Inspection>() | |||
.eq(Inspection::getEquipmentMountCode, serial) | |||
.eq(Inspection::getStatus, InspectionStatusEnum.IN_FLIGHT.getCode()) | |||
.eq(Inspection::getMark, MarkEnum.VALID.getCode()) | |||
.orderByDesc(Inspection::getCreateTime) | |||
.last(" limit 1")); | |||
if (ObjectUtil.isNull(inspection)) { | |||
return null; | |||
} | |||
return inspection; | |||
} | |||
} |
@@ -2,6 +2,7 @@ package com.tuoheng.admin.service.inspection.query; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.alibaba.fastjson.JSON; | |||
import com.alibaba.fastjson.JSONArray; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
@@ -10,6 +11,7 @@ import com.tuoheng.admin.entity.domain.Inspection; | |||
import com.tuoheng.admin.entity.domain.LiveChannel; | |||
import com.tuoheng.admin.entity.domain.Tenant; | |||
import com.tuoheng.admin.entity.domain.User; | |||
import com.tuoheng.admin.entity.third.Airport; | |||
import com.tuoheng.admin.entity.vo.VideoUrlVo; | |||
import com.tuoheng.admin.enums.InspectionStatusEnum; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
@@ -127,9 +129,10 @@ public class QueryVideoService { | |||
if (Objects.nonNull(dataObject)) { | |||
log.info("获取的数据,dataObject={}", dataObject.toJSONString()); | |||
//JSONObject recordsData = dataObject.get().getJSONObject("records"); | |||
Object records = dataObject.get("records"); | |||
String username = records.toString(); | |||
log.info("获取records中的数据为:username={}",username); | |||
String records = dataObject.get("records").toString(); | |||
List<Airport> airportList = JSONArray.parseArray(records, Airport.class); | |||
log.info("获取records中的数据为:airportList={}", airportList); | |||
// if (Objects.isNull(recordsData)) { | |||
// log.info("打印的数据为集合是的,recordsData:{}", recordsData.toString()); |
@@ -121,12 +121,12 @@ spring: | |||
#MQTT服务地址,端口号默认11883,如果有多个,用逗号隔开 | |||
url: tcp://127.0.0.1:1883 | |||
#用户名 | |||
username: admin | |||
username: | |||
#密码 | |||
password: admin##123 | |||
password: | |||
#客户端id(不能重复) | |||
client: | |||
id: provider-id | |||
id: subsribe-id | |||
#MQTT默认的消息推送主题,实际可在调用接口是指定 | |||
default: | |||
topic: topic |
@@ -0,0 +1,26 @@ | |||
package com.tuoheng.admin.mqtt; | |||
import com.tuoheng.common.core.utils.SpringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
import org.springframework.test.context.junit4.SpringRunner; | |||
@Slf4j | |||
@RunWith(SpringRunner.class) | |||
@SpringBootTest | |||
public class MqttServiceTest { | |||
@Autowired | |||
private MqttProviderConfig mqttProvider; | |||
@Test | |||
public void testHello() { | |||
MqttProviderConfig client = SpringUtils.getBean(MqttProviderConfig.class); | |||
client.subscribe(" /v1/123456/environment/messag", 0); | |||
} | |||
} |