@@ -0,0 +1,27 @@ | |||
-- 2023-11-25 10:30 | |||
-- v1.3.3 | |||
use tuoheng_freeway; | |||
-- 物联设备表表 | |||
create table th_iot_equipment | |||
( | |||
id varchar(36) default '' not null comment '主键ID' primary key, | |||
tenant_id varchar(36) default '0' not null comment '租户ID', | |||
dept_id varchar(36) not null comment '部门ID', | |||
code varchar(36) not null comment '设备编码', | |||
name varchar(155) not null comment '设备名称', | |||
road_id varchar(36) not null comment '公路ID', | |||
section_id varchar(36) not null comment '路段ID', | |||
location varchar(255) not null comment '位置', | |||
latitude varchar(25) not null comment '纬度', | |||
longitude varchar(25) not null comment '经度', | |||
play_url varchar(255) not null comment '监控播放地址', | |||
status tinyint default 1 null comment '状态:0:禁用;1:启用;', | |||
create_user varchar(36) null comment '创建人', | |||
create_time timestamp default CURRENT_TIMESTAMP null comment '创建时间', | |||
update_user varchar(36) null comment '修改人', | |||
update_time timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '修改时间', | |||
mark tinyint default 1 null comment '有效标识(1正常 0删除)' | |||
) | |||
comment '物联设备表' collate = utf8mb4_bin; |
@@ -49,6 +49,16 @@ public interface SystemConstant { | |||
*/ | |||
String API_AIRPORT_DRONE_CONTROL = "/airportInterface/droneCommand"; | |||
/** | |||
* 机场平台:获取天气温湿度及挂载状态 | |||
*/ | |||
String API_AIRPORT_GET_WEATHER_STATUS = "/airportInterface/getAirportStatus"; | |||
/** | |||
* 机场平台:获取机场信息 | |||
*/ | |||
String API_AIRPORT_GET_AIRPORT_MSG = "/airportInterface/getAirportMsg"; | |||
/** | |||
* 机场平台:获取机场状态 | |||
*/ |
@@ -31,6 +31,17 @@ public class AirPortController { | |||
return airportService.getAirportList(); | |||
} | |||
/** | |||
* 获取机场详细信息 | |||
* @param airportId | |||
* @return | |||
*/ | |||
@GetMapping("/getAirportDetail/{airportId}/{airportCode}") | |||
public JsonResult getAirportDetail(@PathVariable("airportId") Integer airportId,@PathVariable("airportCode") String airportCode) { | |||
log.info("Index getAirportDetail start... airportId:{},airportCode:{}", airportId.toString(),airportCode); | |||
return airportService.getAirportDetail(airportId,airportCode); | |||
} | |||
/** | |||
* 获取巡检线路 | |||
* |
@@ -11,6 +11,8 @@ import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
import java.util.List; | |||
/** | |||
@@ -145,7 +147,7 @@ public class InspectionFileController { | |||
* @return | |||
*/ | |||
@GetMapping("/export/{idList}") | |||
public JsonResult exportExcleByIdList(@PathVariable("idList") List<String> idList) { | |||
return iInspectionFileService.exportExcleByIdList(idList); | |||
public JsonResult exportExcleByIdList(HttpServletRequest request, HttpServletResponse response, @PathVariable("idList") List<String> idList) { | |||
return iInspectionFileService.exportExcleByIdList(response, idList); | |||
} | |||
} |
@@ -0,0 +1,70 @@ | |||
package com.tuoheng.admin.dto; | |||
import lombok.AllArgsConstructor; | |||
import lombok.Data; | |||
import lombok.NoArgsConstructor; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* @author chenjiandong | |||
* @description: TODO | |||
* @date 2022/12/28 14:53 | |||
*/ | |||
@Data | |||
@AllArgsConstructor | |||
@NoArgsConstructor | |||
@Accessors(chain = true) | |||
public class AirportDetailDto { | |||
/** | |||
* 风速 | |||
*/ | |||
private String wspd; | |||
/** | |||
* 风向 | |||
*/ | |||
private String wdir; | |||
/** | |||
* 风向名称 | |||
*/ | |||
private String wdirName; | |||
/** | |||
* 大气压力 | |||
*/ | |||
private String hpa; | |||
/** | |||
* 空气湿度 | |||
*/ | |||
private String hum; | |||
/** | |||
* 空气温度 | |||
*/ | |||
private String tmp; | |||
/** | |||
* 机场状态 | |||
*/ | |||
private String status; | |||
/** | |||
* 可选挂载 | |||
*/ | |||
private String mountName; | |||
/** | |||
* 降雨量 | |||
*/ | |||
private String rainfull; | |||
/** | |||
* 电池电量% | |||
*/ | |||
private String battery; | |||
} |
@@ -0,0 +1,135 @@ | |||
package com.tuoheng.admin.dto; | |||
import lombok.Data; | |||
/** | |||
* @Author ChengWang | |||
* @Date 2023/4/15 | |||
*/ | |||
@Data | |||
public class AirportMsgDto { | |||
/** | |||
* 机场id | |||
*/ | |||
private String id; | |||
/** | |||
* 机场代码 | |||
*/ | |||
private String code; | |||
/** | |||
* 机场名称 | |||
*/ | |||
private String name; | |||
/** | |||
* 经度 | |||
*/ | |||
private String lon; | |||
/** | |||
* 纬度 | |||
*/ | |||
private String lat; | |||
/** | |||
* 机场运行状态: | |||
* 1,2 舱门(命令接收,动作完成) | |||
* 3,4 升降器(命令接收,动作完成) | |||
* 5,6 固定器(命令接收,动作完成) | |||
* 7,8 出舱(命令接收,动作完成) | |||
* 9,10 回舱(命令接收,动作完成) | |||
* 11 任务中 | |||
* 12 返航中 | |||
* 13 悬停中 | |||
*/ | |||
private String status; | |||
/** | |||
* 环境温度 | |||
*/ | |||
private String Tmp; | |||
/** | |||
* 舱内温度 | |||
*/ | |||
private String ACDTmp; | |||
/** | |||
* 舱内湿度% | |||
*/ | |||
private String Hum; | |||
/** | |||
* 风速m | |||
*/ | |||
private String WSPD; | |||
/** | |||
* 降雨量,单位mm | |||
*/ | |||
private String Rainfull; | |||
/** | |||
* 可飞行时间min | |||
*/ | |||
private String allflytime; | |||
/** | |||
* rtk数 | |||
*/ | |||
private String rtk; | |||
/** | |||
* gps数 | |||
*/ | |||
private String gps; | |||
/** | |||
* 电池电量% | |||
*/ | |||
private String battery; | |||
/** | |||
* 充电状态:true:充电,false:空闲 | |||
*/ | |||
private String chgrStatus; | |||
/** | |||
* 机库内部视频地址 | |||
*/ | |||
private String innerLiveUrl; | |||
/** | |||
* 机库外部视频地址 | |||
*/ | |||
private String outLiveUrl; | |||
/** | |||
* 无人机直播地址 | |||
*/ | |||
private String cameraUrl; | |||
/** | |||
* 相机code | |||
*/ | |||
private String cameraCode; | |||
/** | |||
* 相机名称 | |||
*/ | |||
private String cameraName; | |||
/** | |||
* 无人机code | |||
*/ | |||
private String droneCode; | |||
/** | |||
* 无人机名称 | |||
*/ | |||
private String droneName; | |||
} |
@@ -5,6 +5,7 @@ import com.tuoheng.admin.request.inspectionfile.*; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import org.springframework.web.bind.annotation.PathVariable; | |||
import javax.servlet.http.HttpServletResponse; | |||
import java.util.List; | |||
/** | |||
@@ -117,5 +118,5 @@ public interface IInspectionFileService { | |||
* | |||
* @return | |||
*/ | |||
JsonResult exportExcleByIdList(List<String> idList); | |||
JsonResult exportExcleByIdList(HttpServletResponse response, List<String> idList); | |||
} |
@@ -30,6 +30,7 @@ import org.springframework.beans.BeanUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import javax.servlet.http.HttpServletResponse; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.stream.Collectors; | |||
@@ -322,8 +323,8 @@ public class InspectionFileServiceImpl implements IInspectionFileService { | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult exportExcleByIdList(List<String> idList) { | |||
return exportInspectionFileByIdListService.exportExcleByIdList(idList); | |||
public JsonResult exportExcleByIdList(HttpServletResponse response, List<String> idList) { | |||
return exportInspectionFileByIdListService.exportExcleByIdList(response, idList); | |||
} | |||
} |
@@ -1,7 +1,9 @@ | |||
package com.tuoheng.admin.service.inspectionfile.export; | |||
import cn.hutool.core.collection.CollectionUtil; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.alibaba.excel.EasyExcel; | |||
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; | |||
import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.tuoheng.admin.constant.SystemConstant; | |||
@@ -10,15 +12,31 @@ import com.tuoheng.admin.dto.InspectionFileExportExcelDto; | |||
import com.tuoheng.admin.entity.Inspection; | |||
import com.tuoheng.admin.entity.InspectionFile; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.admin.enums.InspectionFileStatusEnum; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
import com.tuoheng.admin.mapper.InspectionFileMapper; | |||
import com.tuoheng.admin.mapper.InspectionMapper; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.admin.utils.DownloadUtil; | |||
import com.tuoheng.admin.utils.excel.CustomCellWriteHandler; | |||
import com.tuoheng.admin.utils.excel.ImageModifyHandler; | |||
import com.tuoheng.admin.utils.excel.StyleUtils; | |||
import com.tuoheng.common.core.config.UploadFileConfig; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
import com.tuoheng.common.core.exception.ServiceException; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.RequiredArgsConstructor; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import javax.servlet.http.HttpServletResponse; | |||
import java.io.File; | |||
import java.net.MalformedURLException; | |||
import java.net.URL; | |||
import java.net.URLEncoder; | |||
import java.nio.charset.StandardCharsets; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
@@ -32,33 +50,56 @@ import java.util.List; | |||
*/ | |||
@Slf4j | |||
@Service | |||
@RequiredArgsConstructor | |||
public class ExportInspectionFileByIdListService { | |||
@Autowired | |||
private InspectionFileMapper inspectionFileMapper; | |||
private final InspectionMapper inspectionMapper; | |||
private final InspectionFileMapper inspectionFileMapper; | |||
/** | |||
* 修改任务问题类型 | |||
* | |||
* @return | |||
*/ | |||
public JsonResult exportExcleByIdList(List<String> idList) { | |||
public JsonResult exportExcleByIdList(HttpServletResponse response, List<String> idList) { | |||
log.info("进入导出任务问题清单接口"); | |||
User user = CurrentUserUtil.getUserInfo(); | |||
String userId = CurrentUserUtil.getUserId(); | |||
JsonResult result = this.check(idList); | |||
if (0 != result.getCode()) { | |||
log.info("导出任务问题清单:校验失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
List<InspectionFile> inspectionFileList = inspectionFileMapper.selectList(Wrappers.<InspectionFile>lambdaQuery() | |||
.eq(InspectionFile::getTenantId, user.getTenantId()) | |||
.in(InspectionFile::getId, idList) | |||
.eq(InspectionFile::getMark, MarkEnum.VALID.getCode())); | |||
if (CollectionUtil.isEmpty(inspectionFileList)) { | |||
log.info("问题列表不存在, idList={}", idList); | |||
return JsonResult.success(); | |||
} | |||
InspectionFile inspectionFile = inspectionFileList.get(0); | |||
Inspection inspection = inspectionMapper.selectById(inspectionFile.getInspectionId()); | |||
if (ObjectUtil.isEmpty(inspection)) { | |||
log.info("该任务不存在, inspectionId={}", inspection.getId()); | |||
return JsonResult.success(); | |||
} | |||
String fileName = inspection.getName() + "-疑似问题清单.xlsx"; | |||
String filePath = UploadFileConfig.uploadFolder + "inspection_file/" + fileName; | |||
File fd = new File(UploadFileConfig.uploadFolder + "inspection_file"); | |||
if (!fd.exists()) { | |||
fd.mkdirs(); | |||
} | |||
List<InspectionFileExportExcelDto> inspectionFileExportExcelDtoList = this.buildInspectionFileExportExcelDto(inspection, inspectionFileList); | |||
this.easyExcel(inspection, inspectionFileExportExcelDtoList, filePath); | |||
response.setContentType("application/octet-stream;charset=UTF-8"); | |||
response.setCharacterEncoding("UTF-8"); | |||
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8)); | |||
DownloadUtil.download(response, filePath, fileName); | |||
return JsonResult.success(); | |||
} | |||
@@ -71,37 +112,118 @@ public class ExportInspectionFileByIdListService { | |||
*/ | |||
private JsonResult check(List<String> idList) { | |||
if (CollectionUtil.isEmpty(idList)) { | |||
throw new ServiceException("任务ID为空"); | |||
throw new ServiceException("问题ID为空"); | |||
} | |||
return JsonResult.success(); | |||
} | |||
private List<InspectionFileExportExcelDto> buildInspectionFileExportExcelDto(Inspection inspection, List<InspectionFile> inspectionFileList) { | |||
List<InspectionFileExportExcelDto> inspectionFileExportExcelDtoList = new ArrayList<>(); | |||
InspectionFile inspectionFile; | |||
InspectionFileExportExcelDto inspectionFileExportExcelDto; | |||
for (int i = 0; i < inspectionFileList.size(); i++) { | |||
inspectionFile = inspectionFileList.get(i); | |||
inspectionFileExportExcelDto = new InspectionFileExportExcelDto(); | |||
inspectionFileExportExcelDto.setSequence(i + 1); | |||
inspectionFileExportExcelDto.setQuestionDesc(inspectionFile.getQuestionDesc()); | |||
try { | |||
inspectionFileExportExcelDto.setFileOriginal(new URL(CommonConfig.imageURL + inspectionFile.getFileOriginal())); | |||
inspectionFileExportExcelDto.setFileImage(new URL(CommonConfig.imageURL + inspectionFile.getFileImage())); | |||
} catch (MalformedURLException e) { | |||
throw new RuntimeException(e); | |||
} | |||
inspectionFileExportExcelDto.setLocation(inspectionFile.getLongitude() + "," + inspectionFile.getLatitude()); | |||
inspectionFileExportExcelDto.setSectionName(inspection.getSectionName()); | |||
inspectionFileExportExcelDto.setRoadName(inspection.getRoadName()); | |||
if (InspectionFileStatusEnum.WAIT_CONFIRMED.getCode() == inspectionFile.getStatus()) { | |||
inspectionFileExportExcelDto.setStatus("待确认"); | |||
} else if (InspectionFileStatusEnum.IGNORED.getCode() == inspectionFile.getStatus()) { | |||
inspectionFileExportExcelDto.setStatus("已忽略"); | |||
} else if (InspectionFileStatusEnum.CONFIRMED.getCode() == inspectionFile.getStatus()) { | |||
inspectionFileExportExcelDto.setStatus("已确认"); | |||
} else if (InspectionFileStatusEnum.GENERATE_ORDER.getCode() == inspectionFile.getStatus()) { | |||
inspectionFileExportExcelDto.setStatus("已生成工单"); | |||
} else if (InspectionFileStatusEnum.PROCESSED.getCode() == inspectionFile.getStatus()) { | |||
inspectionFileExportExcelDto.setStatus("已处理"); | |||
} | |||
inspectionFileExportExcelDtoList.add(inspectionFileExportExcelDto); | |||
} | |||
return inspectionFileExportExcelDtoList; | |||
} | |||
/** | |||
* 生成excel表格 | |||
* | |||
* @param inspection | |||
* @param inspectionFileList | |||
* @param inspectionFileExportExcelDtoList | |||
* @param filePath | |||
* | |||
* @return | |||
*/ | |||
public JsonResult easyExcel(Inspection inspection, List<InspectionFile> inspectionFileList, String filePath) { | |||
log.info("文件输出目录及格式:filePathName={}",filePath); | |||
List<InspectionFileExportExcelDto> inspectionFileExportExcelDtoList = InspectionFileConverMapper.INSTANCE.fromInspectionFileListToInspectionFileExportExcelDtoList(inspectionFileList); | |||
private JsonResult easyExcel(Inspection inspection, List<InspectionFileExportExcelDto> inspectionFileExportExcelDtoList, String filePath) { | |||
log.info("文件输出目录及格式:filePathName={}", filePath); | |||
List<List<String>> heads = new ArrayList<>(); | |||
String totalName = "项目名称:"+ inspection.getName(); | |||
String[] nameString = {"序号", "问题类型","问题图片", "标注图片", "位置", "所属路段", "所属高速", "状态"}; | |||
String totalName = "疑似问题清单"; | |||
String totalName2 = "巡检任务:" + inspection.getName() + " 巡检时间:" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, inspection.getInspectionTime()) ; | |||
String[] nameString = {"序号", "问题类型", "问题图片", "标注图片", "位置", "所属路段", "所属高速", "状态"}; | |||
for (String excelName : nameString) { | |||
heads.add(Arrays.asList(totalName, excelName)); | |||
heads.add(Arrays.asList(totalName, totalName2, excelName)); | |||
} | |||
//需要写出的表格(对应实体类) | |||
try { | |||
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(StyleUtils.getHeadStyle(), StyleUtils.getContentStyle()); | |||
EasyExcel.write(filePath, InspectionFileExportExcelDto.class).sheet("问题清单数据") | |||
.head(heads) | |||
.registerWriteHandler(new SimpleColumnWidthStyleStrategy(20)) // 简单的列宽策略,列宽20 | |||
// .registerWriteHandler(new SimpleColumnWidthStyleStrategy(20)) // 简单的列宽策略,列宽20 | |||
.registerWriteHandler(new CustomCellWriteHandler()) | |||
// .registerWriteHandler(new CustomCellWriteHeightConfig()) | |||
.registerWriteHandler(horizontalCellStyleStrategy) | |||
.registerWriteHandler(new ImageModifyHandler()) | |||
.doWrite(inspectionFileExportExcelDtoList); // 数据源 | |||
// // 内容样式 | |||
// WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); | |||
// contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 水平居中 | |||
// contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); // 垂直居中 | |||
// contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);//细实线 | |||
// contentWriteCellStyle.setBorderTop(BorderStyle.THIN); | |||
// contentWriteCellStyle.setBorderRight(BorderStyle.THIN); | |||
// contentWriteCellStyle.setBorderBottom(BorderStyle.THIN); | |||
// | |||
// | |||
// //设计内容居中 | |||
// contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); //设置内容自动换行 | |||
// contentWriteCellStyle.setWrapped(true); | |||
// | |||
// //设置头部样式 | |||
// WriteCellStyle headWriteCellStyle = new WriteCellStyle(); | |||
// //设置头部标题居中 | |||
// headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); | |||
// // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现 | |||
// HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle); | |||
// | |||
// // 将数据写进流,如果是响应流则写进header对应的文件里 | |||
// ExcelWriter excelWriter = EasyExcel.write(filePath, InspectionFileExportExcelDto.class).build(); | |||
// | |||
// //指定sheet的名字和头信息 | |||
// WriteSheet writeSheet = EasyExcel.writerSheet(0, "日历导出") | |||
// .head(heads) | |||
// .registerWriteHandler(new SimpleColumnWidthStyleStrategy(20)) | |||
// .registerWriteHandler(horizontalCellStyleStrategy) | |||
// .registerWriteHandler(new CustomCellWriteHandler()) | |||
//// .registerWriteHandler(new CustomCellWriteHeightConfig()) | |||
// .registerWriteHandler(new ImageModifyHandler()) | |||
// .build(); | |||
// //将数据真正写入excel中 | |||
// excelWriter.write(inspectionFileExportExcelDtoList, writeSheet); | |||
// //千万别忘记finish 会帮忙关闭流 | |||
// excelWriter.finish(); | |||
} catch (Exception e) { | |||
log.info("生成数据导出excel异常"); | |||
throw new RuntimeException(e); |
@@ -9,6 +9,8 @@ public interface AirportService { | |||
JsonResult getAirportList(); | |||
JsonResult getAirportDetail(Integer airportId,String airportCode); | |||
JsonResult getAirLineList(Integer droneId); | |||
JsonResult executeTask(String userId, Inspection inspection); |
@@ -13,6 +13,9 @@ public class AirportServiceImpl implements AirportService { | |||
@Autowired | |||
private GetAirportListService getAirportListService; | |||
@Autowired | |||
private GetAirportDetailService getAirportDetailService; | |||
@Autowired | |||
private GetAirLineListService getAirLineListService; | |||
@@ -33,6 +36,11 @@ public class AirportServiceImpl implements AirportService { | |||
return getAirportListService.getAirportList(); | |||
} | |||
@Override | |||
public JsonResult getAirportDetail(Integer airportId,String airportCode) { | |||
return getAirportDetailService.getAirportDetail(airportId,airportCode); | |||
} | |||
@Override | |||
public JsonResult getAirLineList(Integer droneId) { | |||
return getAirLineListService.getAirLineList(droneId); |
@@ -0,0 +1,235 @@ | |||
package com.tuoheng.admin.service.third.airport; | |||
import cn.hutool.core.collection.CollectionUtil; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.alibaba.fastjson.JSON; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.tuoheng.admin.constant.SystemConstant; | |||
import com.tuoheng.admin.dto.AirportDetailDto; | |||
import com.tuoheng.admin.dto.AirportMsgDto; | |||
import com.tuoheng.admin.entity.Tenant; | |||
import com.tuoheng.admin.mapper.TenantMapper; | |||
import com.tuoheng.admin.utils.CurrentUserUtil; | |||
import com.tuoheng.common.core.config.common.CommonConfig; | |||
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.beans.factory.annotation.Qualifier; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.web.client.RestTemplate; | |||
import org.springframework.web.util.UriComponentsBuilder; | |||
import java.lang.reflect.Field; | |||
import java.util.*; | |||
/** | |||
* @Author xiaoying | |||
* @Date 2023/4/14 16:05 | |||
*/ | |||
@Service | |||
@Slf4j | |||
public class GetAirportDetailService { | |||
@Autowired | |||
private TenantMapper tenantMapper; | |||
@Autowired | |||
@Qualifier("restTemplate") | |||
private RestTemplate restTemplate; | |||
public JsonResult getAirportDetail(Integer airportId, String airportCode) { | |||
JsonResult resultData = this.check(airportId, airportCode); | |||
if (resultData.getCode() != 0) { | |||
return JsonResult.error(resultData.getCode(), resultData.getMsg()); | |||
} | |||
//获取当前租户code | |||
String tenantId = CurrentUserUtil.getTenantId(); | |||
Tenant tenant = tenantMapper.selectOne(Wrappers.<Tenant>lambdaQuery() | |||
.eq(Tenant::getId, tenantId) | |||
.eq(Tenant::getMark, 1)); | |||
if (StringUtils.isEmpty(tenant.getCode())) { | |||
throw new RuntimeException("租户code为空"); | |||
} | |||
String tenantCode = tenant.getCode(); | |||
String url = UriComponentsBuilder.fromHttpUrl(CommonConfig.airportURL + SystemConstant.API_AIRPORT_GET_WEATHER_STATUS) | |||
.queryParam("airportId", airportId) | |||
.toUriString(); | |||
JsonResult jsonResult; | |||
try { | |||
jsonResult = restTemplate.getForObject(url, JsonResult.class); | |||
} catch (Exception e) { | |||
log.info("获取机场状态,机场平台返回异常, url:{}", url); | |||
return JsonResult.error("获取机场状态,机场平台返回异常"); | |||
} | |||
if (0 != jsonResult.getCode()) { | |||
log.info("获取机场状态,机场平台返回失败,jsonResult={}", jsonResult); | |||
return JsonResult.error("获取机场状态,机场平台返回失败"); | |||
} | |||
List<AirportMsgDto> msgList = this.getMsgList(tenantCode, airportCode); | |||
log.info("获取机场信息列表,msgList={}", JSON.toJSONString(msgList)); | |||
AirportDetailDto vo = new AirportDetailDto(); | |||
if (CollectionUtil.isNotEmpty(msgList) || msgList.size() != 0) { | |||
AirportMsgDto airportMsgDto = msgList.get(0); | |||
if (ObjectUtil.isNotNull(airportMsgDto)) { | |||
//电量数据% | |||
vo.setBattery(airportMsgDto.getBattery() + "%"); | |||
} | |||
} | |||
JSONObject dataObject = (JSONObject) JSONObject.toJSON(jsonResult.getData()); | |||
log.info("响应信息:{}", dataObject.toJSONString()); | |||
JSONObject wthJson = dataObject.getJSONObject("WTH"); | |||
if (Objects.nonNull(wthJson)) { | |||
log.info("参数信息:{}", wthJson.toJSONString()); | |||
JSONObject parmJson = wthJson.getJSONObject("parmNew"); | |||
log.info("参数信息parmJson:{}", parmJson.toJSONString()); | |||
String wspd = ""; | |||
String wdir = ""; | |||
String hpa = ""; | |||
String hum = ""; | |||
String rainfull = ""; | |||
String tmp = ""; | |||
if (ObjectUtil.isNotEmpty(parmJson.getString("WSPD"))) { | |||
wspd = parmJson.getString("WSPD") + "m/s"; | |||
} | |||
if (ObjectUtil.isNotEmpty(parmJson.getString("WDIRNAME"))) { | |||
wdir = parmJson.getString("WDIRNAME"); | |||
} | |||
if (ObjectUtil.isNotEmpty(parmJson.getString("Hpa"))) { | |||
hpa = parmJson.getString("Hpa") + "Mpa"; | |||
} | |||
if (ObjectUtil.isNotEmpty(parmJson.getString("Hum"))) { | |||
hum = parmJson.getString("Hum") + "%rh"; | |||
} | |||
if (ObjectUtil.isNotEmpty(parmJson.getString("Rainfull"))) { | |||
rainfull = parmJson.getString("Rainfull"); | |||
} | |||
if (ObjectUtil.isNotEmpty(parmJson.getString("Tmp"))) { | |||
tmp = parmJson.getString("Tmp") + "℃"; | |||
} | |||
vo.setWspd(wspd) | |||
.setWdir(wdir) | |||
.setHpa(hpa) | |||
.setHum(hum) | |||
.setRainfull(rainfull) | |||
.setTmp(tmp); | |||
} | |||
JSONObject tahJson = dataObject.getJSONObject("TAH"); | |||
if (Objects.nonNull(tahJson)) { | |||
JSONObject parmJson = tahJson.getJSONObject("parmNew"); | |||
String hum = ""; | |||
String tmp = ""; | |||
if (ObjectUtil.isNotEmpty(parmJson.getString("Hum"))) { | |||
hum = parmJson.getString("Hum") + "%rh"; | |||
} | |||
if (ObjectUtil.isNotEmpty(parmJson.getString("Tmp"))) { | |||
tmp = parmJson.getString("Tmp") + "℃"; | |||
} | |||
vo.setHum(hum).setTmp(tmp); | |||
} | |||
JSONObject mountJson = dataObject.getJSONObject("mount"); | |||
if (Objects.nonNull(mountJson)) { | |||
String cameraName = ""; | |||
String megaphoneName = ""; | |||
String searchlightName = ""; | |||
if (ObjectUtil.isNotEmpty(mountJson.getString("cameraName"))) { | |||
cameraName = mountJson.getString("cameraName") + "、"; | |||
} | |||
if (ObjectUtil.isNotEmpty(mountJson.getString("megaphoneName"))) { | |||
megaphoneName = mountJson.getString("megaphoneName") + "、"; | |||
} | |||
if (ObjectUtil.isNotEmpty(mountJson.getString("searchlightName"))) { | |||
searchlightName = mountJson.getString("searchlightName"); | |||
} | |||
vo.setMountName(cameraName + megaphoneName + searchlightName); | |||
} | |||
String status = ""; | |||
if (ObjectUtil.isNotEmpty(dataObject.getString("status"))) { | |||
status = dataObject.getString("status"); | |||
} | |||
vo.setStatus(status); | |||
return JsonResult.success(vo); | |||
} | |||
private JsonResult check(Integer airportId, String airportCode) { | |||
if (ObjectUtil.isEmpty(airportId) || 0 == airportId) { | |||
return JsonResult.error("机场id为空"); | |||
} | |||
if (ObjectUtil.isEmpty(airportCode)) { | |||
return JsonResult.error("机场code为空"); | |||
} | |||
return JsonResult.success(); | |||
} | |||
public List<AirportMsgDto> getMsgList(String tenantCode, String airportCode) { | |||
String url = UriComponentsBuilder.fromHttpUrl(CommonConfig.airportURL + SystemConstant.API_AIRPORT_GET_AIRPORT_MSG) | |||
.queryParam("tenantCode", tenantCode) | |||
.queryParam("airportCode", airportCode) | |||
.toUriString(); | |||
JsonResult jsonResult; | |||
try { | |||
jsonResult = restTemplate.getForObject(url, JsonResult.class); | |||
} catch (Exception e) { | |||
log.info("获取机场状态,机场平台返回异常, url:{}", url); | |||
return null; | |||
} | |||
if (0 != jsonResult.getCode()) { | |||
log.info("获取机场状态,机场平台返回失败,jsonResult={}", jsonResult); | |||
return null; | |||
} | |||
if (ObjectUtil.isEmpty(jsonResult) || (!ObjectUtil.isEmpty(Objects.requireNonNull(jsonResult).getData()) && jsonResult.getCode() != 0)) { | |||
log.info("获取机场列表失败"); | |||
return null; | |||
} | |||
List<Object> list = (List<Object>) jsonResult.getData(); | |||
List<AirportMsgDto> airportMsgDtoList = new ArrayList<>(); | |||
AirportMsgDto airportMsgDto; | |||
Map<String, String> map; | |||
for (Object obj : list) { | |||
map = new HashMap<>(); | |||
for (Object entry : ((Map) obj).entrySet()) { | |||
String key = ((Map.Entry) entry).getKey().toString(); | |||
String value = ""; | |||
if (ObjectUtil.isNotEmpty(((Map.Entry) entry).getValue())) { | |||
value = ((Map.Entry) entry).getValue().toString(); | |||
} | |||
map.put(key, value); | |||
} | |||
airportMsgDto = (AirportMsgDto) this.copyObject(map); | |||
if (ObjectUtil.isNotEmpty(airportMsgDto)) { | |||
airportMsgDtoList.add(airportMsgDto); | |||
} | |||
} | |||
return airportMsgDtoList; | |||
} | |||
public static <T> Object copyObject(Map<String, String> field_Val) { | |||
Object o; | |||
try { | |||
Class clz = AirportMsgDto.class; | |||
o = clz.newInstance(); | |||
for (Field tf : clz.getDeclaredFields()) { | |||
String fieldName = tf.getName(); | |||
Object targetV = field_Val.get(fieldName); | |||
if (targetV == null) { | |||
continue; | |||
} | |||
tf.setAccessible(true); | |||
tf.set(o, targetV); | |||
} | |||
} catch (InstantiationException e) { | |||
log.error("获取机场信息,InstantiationException:{}", e); | |||
throw new RuntimeException(e); | |||
} catch (IllegalAccessException e) { | |||
log.error("获取机场信息,IllegalAccessException:{}", e); | |||
throw new RuntimeException(e); | |||
} | |||
return o; | |||
} | |||
} |