@@ -1,12 +1,17 @@ | |||
package com.tuoheng.admin.mapper; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import com.tuoheng.admin.entity.FlightData; | |||
import com.tuoheng.admin.entity.FlightDataHl; | |||
import java.util.List; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2023/8/8 | |||
*/ | |||
public interface FlightDataHlMapper extends BaseMapper<FlightDataHl> { | |||
List<FlightData> selectListByInspectionId(String id); | |||
} |
@@ -5,6 +5,7 @@ import com.tuoheng.admin.entity.FlightData; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
import com.tuoheng.admin.enums.code.inspection.QueryInspectionInfoByIdCodeEnum; | |||
import com.tuoheng.admin.mapper.FlightDataHlMapper; | |||
import com.tuoheng.admin.mapper.FlightDataMapper; | |||
import com.tuoheng.admin.mapper.InspectionMapper; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
@@ -29,7 +30,7 @@ public class QueryFindFlightDataService { | |||
private InspectionMapper inspectionMapper; | |||
@Autowired | |||
private FlightDataMapper flightDataMapper; | |||
private FlightDataHlMapper flightDataHlMapper; | |||
public JsonResult findFlightData(String id) { | |||
if (StringUtils.isEmpty(id)) { | |||
@@ -42,7 +43,7 @@ public class QueryFindFlightDataService { | |||
id = inspection.getEmergencyDataInspectionId(); | |||
} | |||
//根据任务id查询对应的云盒遥测数据 | |||
List<FlightData> listData = flightDataMapper.selectListByInspectionId(id); | |||
List<FlightData> listData = flightDataHlMapper.selectListByInspectionId(id); | |||
return JsonResult.success(listData); | |||
} | |||
} |
@@ -65,7 +65,6 @@ public class QueryAirportMsgByIdService { | |||
} | |||
AirportMsgVo vo = new AirportMsgVo(); | |||
BeanUtils.copyProperties(flightData,vo); | |||
//属性赋值 | |||
//高度 | |||
Double.parseDouble(flightData.getAlt()); | |||
double round = CommonNumberTypeUtils.round(Double.parseDouble(flightData.getAlt()), 2); |
@@ -39,9 +39,6 @@ public class QueryInspectionListService { | |||
private UserMapper userMapper; | |||
public JsonResult getListByAirportId(InspectionDto dto) { | |||
// if(null == dto.getAirportId() && StringUtils.isEmpty(dto.getUserId())){ | |||
// return JsonResult.error(QueryInspectionListServiceEnum.QUERY_IS_FAILED.getCode(),QueryInspectionListServiceEnum.QUERY_IS_FAILED.getMsg()); | |||
// } | |||
String username = SecurityUserUtils.username(); | |||
if(StringUtils.isEmpty(username)){ | |||
return JsonResult.error(QueryInspectionListServiceEnum.QUERY_IS_FAILED.getCode(),QueryInspectionListServiceEnum.QUERY_IS_FAILED.getMsg()); |
@@ -18,6 +18,7 @@ import com.tuoheng.admin.tzhl.response.TZHLFlyDataResponse; | |||
import com.tuoheng.admin.tzhl.response.TZHLFlyLogResponse; | |||
import com.tuoheng.admin.tzhl.service.CallTianYiPlatformService; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.RedisUtils; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
@@ -33,6 +34,8 @@ import org.springframework.web.client.RestTemplate; | |||
import java.sql.Wrapper; | |||
import java.text.SimpleDateFormat; | |||
import java.util.ArrayList; | |||
import java.util.Comparator; | |||
import java.util.Date; | |||
import java.util.List; | |||
import java.util.stream.Collectors; | |||
@@ -44,25 +47,21 @@ public class FlyDataService { | |||
@Autowired | |||
private RedisUtils redisUtils; | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
@Autowired | |||
private FlightDataHlMapper flightDataHlMapper; | |||
@Autowired | |||
private CallTianYiPlatformService callTianYiPlatformService; | |||
public void getFlyData(Inspection inspection) { | |||
public void getFlyData(Inspection inspection,List<TZHLAirportFlightDataResponse> flightDataHlList) { | |||
String apiPath = TZHLConstant.TIAN_YI_API_FLIGHT_DATA; | |||
//String apiPath = TZHLConstant.TIAN_YI_API_FLIGHT_DATA; | |||
JSONObject jsonObject = this.jsonObjectRequest(inspection); | |||
//JSONObject jsonObject = this.jsonObjectRequest(inspection); | |||
String dataJson = callTianYiPlatformService.callPost(apiPath, jsonObject); | |||
//String dataJson = callTianYiPlatformService.callPost(apiPath, jsonObject); | |||
List<TZHLAirportFlightDataResponse> flightDataHlList = JSON.parseArray(dataJson, TZHLAirportFlightDataResponse.class); | |||
//List<TZHLAirportFlightDataResponse> flightDataHlList = JSON.parseArray(dataJson, TZHLAirportFlightDataResponse.class); | |||
//查询到的数据 入库 | |||
this.addFlightDataHl(inspection,flightDataHlList); | |||
@@ -77,20 +76,32 @@ public class FlyDataService { | |||
*/ | |||
private void addFlightDataHl(Inspection inspection, List<TZHLAirportFlightDataResponse> flightDataHlList) { | |||
if(CollectionUtil.isNotEmpty(flightDataHlList) && flightDataHlList.size() != 0){ | |||
List<FlightDataHl> flightDataHls = new ArrayList<>(flightDataHlList.size()); | |||
for (TZHLAirportFlightDataResponse responseData : flightDataHlList) { | |||
FlightDataHl flightDataHl = new FlightDataHl(); | |||
BeanUtils.copyProperties(responseData,flightDataHl); | |||
flightDataHl.setTenantId(inspection.getTenantId()); | |||
flightDataHl.setInspectionId(inspection.getId()); | |||
flightDataHl.setCreateTime(DateUtils.now()); | |||
flightDataHl.setCreateUser(inspection.getCreateUser()); | |||
//将最新的一条数据存入缓存,并设置过期时间 | |||
//将最新的一条数据存入缓存,并设置过期时间() | |||
redisUtils.set(String.valueOf(inspection.getId()),flightDataHl,10); | |||
int count = flightDataHlMapper.insert(flightDataHl); | |||
if(count<=0){ | |||
log.info("输入插入失败,responseData:{}",responseData); | |||
throw new SecurityException("飞行数据插入失败"); | |||
} | |||
flightDataHls.add(flightDataHl); | |||
} | |||
//将最新的一条数据存入缓存,并设置过期时间 | |||
if(CollectionUtil.isNotEmpty(flightDataHls) && flightDataHls.size()>0){ | |||
flightDataHls = flightDataHls.stream().sorted(Comparator.comparing(FlightDataHl::getCreateTime).reversed()).collect(Collectors.toList()); | |||
//倒序排列的第一个最新数据保存到缓存 | |||
redisUtils.set(inspection.getId(),flightDataHls.get(0),10); | |||
} | |||
} | |||
return; |
@@ -68,8 +68,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
<result property="mark" column="mark" /> | |||
</resultMap> | |||
<sql id="Base_Column_List"> | |||
id, tenant_id, inspection_id, recordId, attachRD, uavId, uavNo, time, alt, lng, lat, spd, ht, | |||
head, pit, roll, bat, vol, fuel, act, mode, flightMode, arm, air, absp, temp, tc, velocityZ, remainingFlightTime, | |||
moduleSignal, satellite, deptId, appConnected, groundConnected, controlDevice, rcControlPosition, gps, ultrasonicHeight, | |||
altitudeFused, latLonAltitude, homeLocation, duration, battery1CapacityPercent, battery1Voltage, battery1Temperature, | |||
battery1HeatState, battery2CapacityPercent, battery2Voltage, battery2Temperature, battery2HeatState, gimbalPitch, gimbalYaw, | |||
gimbalRoll, zoomRatio, focalLength, videoStreamSource, create_user, create_time, update_user, update_time, mark | |||
</sql> | |||
<sql id="selectThFlightDataHlVo"> | |||
select id, tenant_id, inspection_id, recordId, attachRD, uavId, uavNo, time, alt, lng, lat, spd, ht, head, pit, roll, bat, vol, fuel, act, mode, flightMode, arm, air, absp, temp, tc, velocityZ, remainingFlightTime, moduleSignal, satellite, deptId, appConnected, groundConnected, controlDevice, rcControlPosition, gps, ultrasonicHeight, altitudeFused, latLonAltitude, homeLocation, duration, battery1CapacityPercent, battery1Voltage, battery1Temperature, battery1HeatState, battery2CapacityPercent, battery2Voltage, battery2Temperature, battery2HeatState, gimbalPitch, gimbalYaw, gimbalRoll, zoomRatio, focalLength, videoStreamSource, create_user, create_time, update_user, update_time, mark from th_flight_data_hl | |||
</sql> | |||
<select id="selectListByInspectionId" resultMap="BaseResultMap"> | |||
select | |||
<include refid="Base_Column_List"/> | |||
from th_flight_data_hl | |||
where inspection_id = #{id} | |||
and mark = 1 | |||
order by create_time asc | |||
</select> | |||
</mapper> |
@@ -0,0 +1,103 @@ | |||
package com.tuoheng.admin.tzhl; | |||
import com.tuoheng.admin.tzhl.response.TZHLAirportFlightDataResponse; | |||
import com.tuoheng.admin.tzhl.service.fly.data.FlyDataService; | |||
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; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2023/8/16 | |||
*/ | |||
@Slf4j | |||
@RunWith(SpringRunner.class) | |||
@SpringBootTest | |||
public class TZHLGetFlightDataServiceTest { | |||
@Autowired | |||
private FlyDataService flyDataService; | |||
@Test | |||
public void test(){ | |||
List<TZHLAirportFlightDataResponse> list = new ArrayList<>(); | |||
TZHLAirportFlightDataResponse response = new TZHLAirportFlightDataResponse(); | |||
response.setAbsp("0"); | |||
response.setAct(1l); | |||
response.setAir("qww"); | |||
response.setAlt("rerer"); | |||
response.setAbsp("rrrr"); | |||
response.setAltitudeFused("gggg"); | |||
response.setAppConnected("kkkk"); | |||
response.setArm("llll"); | |||
response.setAttachRD(4l); | |||
response.setBat("eee"); | |||
response.setBattery1CapacityPercent("nnnn"); | |||
response.setBattery1HeatState("iiii"); | |||
response.setBattery1Temperature("45"); | |||
response.setBattery1Voltage("4.5"); | |||
response.setBattery2CapacityPercent("333"); | |||
response.setBattery2HeatState("2333"); | |||
response.setBattery2Temperature("334"); | |||
response.setBattery2Voltage("3.4"); | |||
response.setControlDevice("ffff"); | |||
response.setDeptId(23l); | |||
response.setAttachRD(5l); | |||
response.setDuration("kkkklll"); | |||
response.setFlightMode("hahah"); | |||
response.setAppConnected("sssss"); | |||
response.setFocalLength("3434"); | |||
response.setFuel("eee"); | |||
response.setGimbalPitch("ooooo"); | |||
response.setGimbalRoll("mmmm"); | |||
response.setGimbalYaw("ccccc"); | |||
response.setGps("223.44"); | |||
response.setGroundConnected("fffff"); | |||
response.setHead("eggffe"); | |||
response.setHomeLocation("江苏生"); | |||
response.setHt("dddd"); | |||
response.setId(3l); | |||
response.setInspectionId("23ddfgggg"); | |||
response.setLat("rrrr"); | |||
response.setLatLonAltitude("eet"); | |||
response.setLng("2222"); | |||
response.setMode(5l); | |||
response.setModuleSignal("qqqqq"); | |||
response.setPit("weffg"); | |||
response.setRcControlPosition("eeeeee"); | |||
response.setRecordId(34l); | |||
response.setRemainingFlightTime("223344"); | |||
response.setRoll("ergghy"); | |||
response.setSatellite("rnrnrne"); | |||
response.setSpd("rrrredddd"); | |||
response.setTc("lllleeee"); | |||
response.setTemp("eeedwws"); | |||
response.setTenantId("wewewew"); | |||
response.setTime(3344l); | |||
response.setUavId(3l); | |||
response.setUavNo("rewwqs"); | |||
response.setUltrasonicHeight("enrhhhh"); | |||
response.setVelocityZ("gghhffdr"); | |||
response.setVideoStreamSource("2gg33345"); | |||
response.setVol("eefght"); | |||
response.setZoomRatio("sddrhgt"); | |||
list.add(response); | |||
} | |||
} |