Browse Source

Merge branch 'develop' of http://192.168.11.14:51037/gitadmin/tuoheng_air_monitor into develop

tags/V1.0.1^2
wanjing 1 year ago
parent
commit
f51a7e9213
10 changed files with 259 additions and 28 deletions
  1. +1
    -6
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/AirDataController.java
  2. +1
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/AirPortController.java
  3. +2
    -2
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/request/airport/ReversalFlightRequest.java
  4. +1
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/airData/AirDataServiceImpl.java
  5. +5
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/airData/IAirDataService.java
  6. +123
    -18
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/airData/query/QueryAirDataListService.java
  7. +7
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/AirportService.java
  8. +10
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/AirportServiceImpl.java
  9. +107
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/reversal/ReversalFlightService.java
  10. +2
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/utils/CurrentUserUtil.java

+ 1
- 6
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/AirDataController.java View File

@@ -42,18 +42,13 @@ public class AirDataController {
}

/**
* 生成excel表格
* 生成并导出excel表格
*/
@GetMapping("/generateTable/{id}")
public JsonResult generateTableById(@PathVariable("id") String id) {
return airDataService.generateTable(id);
}

/**
* 下载表格
*/


/**
* 导出报告
*/

+ 1
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/AirPortController.java View File

@@ -81,7 +81,7 @@ public class AirPortController {
@PostMapping("/reversalFlight")
public JsonResult reversalFlight(@RequestBody ReversalFlightRequest request){
log.info("进入无人机返航接口: request={}", request);
return JsonResult.success();
return airportService.reversalFlight(request);
}

}

+ 2
- 2
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/request/airport/ReversalFlightRequest.java View File

@@ -11,9 +11,9 @@ import lombok.Data;
public class ReversalFlightRequest {

/**
* 应急事故id
* 任务id
*/
private String accidentId;
private String inspectionId;

/**
* 校验数字符

+ 1
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/airData/AirDataServiceImpl.java View File

@@ -24,6 +24,7 @@ public class AirDataServiceImpl extends BaseServiceImpl<AirDataMapper, AirData>
@Autowired
private ExportReportService eportReportService;

@Autowired
private QueryAirDataListService queryAirDataListService;



+ 5
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/airData/IAirDataService.java View File

@@ -12,6 +12,11 @@ import java.util.List;
*/
public interface IAirDataService extends IBaseService<AirData> {

/**
* 根据任务id查询大气数据列表
* @param id
* @return
*/
List<AirData> getAirDataList(String id);

JsonResult generateTable(String id);

+ 123
- 18
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/airData/query/QueryAirDataListService.java View File

@@ -1,17 +1,27 @@
package com.tuoheng.admin.service.airData.query;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tuoheng.admin.constant.SystemConstant;
import com.tuoheng.admin.entity.domain.AirData;
import com.tuoheng.admin.entity.domain.AirDataExport;
import com.tuoheng.admin.entity.domain.Inspection;
import com.tuoheng.admin.entity.domain.User;
import com.tuoheng.admin.entity.vo.airData.AirDataExcelVo;
import com.tuoheng.admin.enums.AirDataEnum;
import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.mapper.AirDataExportMapper;
import com.tuoheng.admin.mapper.AirDataMapper;
import com.tuoheng.admin.mapper.InspectionMapper;
import com.tuoheng.admin.utils.AliyunOSSUtil;
import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.common.core.config.UploadFileConfig;
import com.tuoheng.common.core.enums.ServiceExceptionEnum;
import com.tuoheng.common.core.exception.ServiceException;
import com.tuoheng.common.core.utils.DateUtils;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
@@ -19,6 +29,10 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -38,6 +52,12 @@ public class QueryAirDataListService {
@Autowired
private InspectionMapper inspectionMapper;

@Autowired
private AirDataExportMapper airDataExportMapper;

@Autowired
private AliyunOSSUtil aliyunOSSUtil;


public List<AirData> list(String id) {
List<AirData> airDataList = airDataMapper.selectList(Wrappers.<AirData>lambdaQuery()
@@ -48,11 +68,25 @@ public class QueryAirDataListService {
}

public JsonResult generateTable(String id) {
User user = CurrentUserUtil.getUserInfo();
String tenantId = user.getTenantId();
String userId = user.getId();
//校验
JsonResult jsonResult = this.check(id);
if(0 != jsonResult.getCode()){
log.info("生成excel表格的任务id为空");
return JsonResult.error(jsonResult.getCode(),jsonResult.getMsg());
log.info("生成excel表格数据校验失败:{}",jsonResult.getMsg());
return jsonResult;
}
AirDataExport airDataExport = this.checkAirDataExport(id);
if (ObjectUtil.isNotEmpty(airDataExport)) {
return JsonResult.success(airDataExport);
}
//获取任务名称
Inspection inspection = inspectionMapper.selectById(id);
String name = inspection.getName();
if(StringUtils.isEmpty(name)){
log.info("对应的任务名称为空");
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_TIME_IS_ERROR);
}
//获取当前任务id下的大气数据
List<AirData> airDataList = airDataMapper.selectList(Wrappers.<AirData>lambdaQuery()
@@ -61,38 +95,109 @@ public class QueryAirDataListService {
if(CollectionUtils.isEmpty(airDataList) || airDataList.size() == 0){
return JsonResult.error(AirDataEnum.AIR_DATA_IS_NOT_EXIST.getCode(),AirDataEnum.AIR_DATA_IS_NOT_EXIST.getMsg());
}
//数据转换
List<AirDataExcelVo> airDataExcelVoList = new ArrayList<>();
airDataList.forEach(x->{
AirDataExcelVo vo = new AirDataExcelVo();
BeanUtils.copyProperties(x,vo);
airDataExcelVoList.add(vo);
});
//获取任务名称
Inspection inspection = inspectionMapper.selectById(id);
String name = inspection.getName();
//获取到vo
JsonResult result = easyExcel(airDataExcelVoList,name);

return JsonResult.success("表格上传下载成功");
String fileName = inspection.getCode()+ "-" + "浓度监测数据" + ".xlsx";
String filePath = UploadFileConfig.uploadFolder + "/data/" + fileName;
File fd = new File(UploadFileConfig.uploadFolder + "/data");
//目录是否存在
if(!fd.exists()){
fd.mkdirs();
}
//生成excel
JsonResult result = this.easyExcel(airDataExcelVoList,inspection,filePath);
if (0 != result.getCode()) {
log.info("导出数据业务:生成excel失败:{}", result.getMsg());
return result;
}
//上传到oss
String ossUrl = this.uploadOss(filePath,fileName);
//数据导入记录表中
Integer count = this.addAirDataExport(id,ossUrl,tenantId,userId);
if(count <= 0){
log.info("添加大气数据报告导出记录失败");
}
//查询记录表返回结果
AirDataExport airDataExportResult = airDataExportMapper.selectOne(Wrappers.<AirDataExport>lambdaQuery()
.eq(AirDataExport::getInspectionId, id)
.eq(AirDataExport::getMark, MarkEnum.VALID.getCode())
.eq(AirDataExport::getExportType,"data"));
return JsonResult.success(airDataExportResult);
}

private Integer addAirDataExport(String id, String ossUrl, String tenantId,String userId) {
AirDataExport airDataExport = new AirDataExport();
airDataExport.setInspectionId(id);
airDataExport.setTenantId(tenantId);
airDataExport.setOssUrl(ossUrl);
airDataExport.setExportType("data");
airDataExport.setCreateUser(userId);
airDataExport.setCreateTime(DateUtils.now());
int count = airDataExportMapper.insert(airDataExport);
return count;
}

private String uploadOss(String filePath, String fileName) {
File file = new File(filePath);
InputStream in = null;
String ossUrl = "";

try {
in = new FileInputStream(file);
//上传到oss
aliyunOSSUtil.uploadFile2OSS(in,fileName);
//通过文件名获取文件完整路径
ossUrl = aliyunOSSUtil.getFileUrl(fileName);
} catch (FileNotFoundException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return ossUrl;
}

public static JsonResult easyExcel(List<AirDataExcelVo> voArrayList,String inspectionName) {
String fileNameTemp = "G:/测试/"; //文件输出目录(路径自定义)
String temp = UUID.randomUUID().toString()+".xlsx";
String fileName = fileNameTemp+temp;
/**
* 大气报告导出记录表数据校验
* @param id
* @return
*/
private AirDataExport checkAirDataExport(String id) {
AirDataExport airDataExport = airDataExportMapper.selectOne(Wrappers.<AirDataExport>lambdaQuery()
.eq(AirDataExport::getInspectionId, id)
.eq(AirDataExport::getExportType, "data")
.eq(AirDataExport::getMark, MarkEnum.VALID.getCode()));
return airDataExport;
}

/**
* 生成excel表格
* @param voArrayList
* @param inspection
* @return
*/
public JsonResult easyExcel(List<AirDataExcelVo> voArrayList,Inspection inspection,String filePath) {
log.info("文件输出目录及格式:filePathName={}",filePath);
List<List<String>> heads = new ArrayList<>();
String totalName = "项目名称:"+ inspectionName;
String totalName = "项目名称:"+ inspection.getName();
String[] nameString = SystemConstant.EXCEL_NAME;
for (String excelName : nameString) {
heads.add(Arrays.asList(totalName,excelName));
}
//需要写出的表格(对应实体类)
try {
EasyExcel.write(filePath, AirDataExcelVo.class).sheet("浓度监测数据").head(heads)
.registerWriteHandler(new SimpleColumnWidthStyleStrategy(20)) // 简单的列宽策略,列宽20
.doWrite(voArrayList);//数据源
} catch (Exception e) {
log.info("生成数据导出excel异常");
throw new RuntimeException(e);
}
log.info("开始写入表格中");
EasyExcel.write(fileName, AirDataExcelVo.class).sheet("环境大气数据表").head(heads)
.registerWriteHandler(new SimpleColumnWidthStyleStrategy(20)) // 简单的列宽策略,列宽20
//.registerWriteHandler(new SimpleRowHeightStyleStrategy((short)20,(short)20)) // 设置行高策略
.doWrite(voArrayList);//数据源
log.info("写入表格已完成");

return JsonResult.success();
}

+ 7
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/AirportService.java View File

@@ -2,6 +2,7 @@ package com.tuoheng.admin.service.third.airport;

import com.tuoheng.admin.entity.domain.Inspection;
import com.tuoheng.admin.entity.request.airport.DroneHoverRequest;
import com.tuoheng.admin.entity.request.airport.ReversalFlightRequest;
import com.tuoheng.common.core.utils.JsonResult;

public interface AirportService {
@@ -25,4 +26,10 @@ public interface AirportService {
*/
JsonResult hover(DroneHoverRequest request);

/**
* 无人机返航
* @param request
* @return
*/
JsonResult reversalFlight(ReversalFlightRequest request);
}

+ 10
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/AirportServiceImpl.java View File

@@ -2,7 +2,9 @@ package com.tuoheng.admin.service.third.airport;

import com.tuoheng.admin.entity.domain.Inspection;
import com.tuoheng.admin.entity.request.airport.DroneHoverRequest;
import com.tuoheng.admin.entity.request.airport.ReversalFlightRequest;
import com.tuoheng.admin.service.third.airport.drone.DroneService;
import com.tuoheng.admin.service.third.airport.reversal.ReversalFlightService;
import com.tuoheng.common.core.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -28,6 +30,9 @@ public class AirportServiceImpl implements AirportService {
@Autowired
private DroneService droneService;

@Autowired
private ReversalFlightService reversalFlightService;

@Override
public JsonResult getAirportList() {
return getAirportListService.getAirportList();
@@ -58,4 +63,9 @@ public class AirportServiceImpl implements AirportService {
return droneService.hover(request.getInspectiontId());
}

@Override
public JsonResult reversalFlight(ReversalFlightRequest request) {
return reversalFlightService.reversal(request);
}

}

+ 107
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/airport/reversal/ReversalFlightService.java View File

@@ -0,0 +1,107 @@
package com.tuoheng.admin.service.third.airport.reversal;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.tuoheng.admin.constant.SystemConstant;
import com.tuoheng.admin.entity.domain.Inspection;
import com.tuoheng.admin.entity.domain.User;
import com.tuoheng.admin.entity.request.airport.ReversalFlightRequest;
import com.tuoheng.admin.enums.InspectionStatusEnum;
import com.tuoheng.admin.enums.code.inspection.EditInspectionCodeEnum;
import com.tuoheng.admin.mapper.InspectionMapper;
import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.common.core.config.common.CommonConfig;
import com.tuoheng.common.core.exception.ServiceException;
import com.tuoheng.common.core.utils.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @Author ChengWang
* @Date 2023/5/25
*/
@Service
@Slf4j
public class ReversalFlightService {

@Autowired
private InspectionMapper inspectionMapper;


public JsonResult reversal(ReversalFlightRequest request) {
User user = CurrentUserUtil.getUserInfo();
String userId = user.getId();
String tenantId = user.getTenantId();
JsonResult result = this.check(userId,tenantId,request);
if(0 != result.getCode()){
log.info("进入无人机返航校验失败:{}",result.getMsg());
}
request.setZhilin("03");
log.info("进入调用无人机平台,回仓指令值:{}",request.getZhilin());
JsonResult jsonResult = this.queryInspection(request);
if(0 != jsonResult.getCode()){
return JsonResult.error(jsonResult.getCode(),jsonResult.getMsg());
}
Inspection inspection = (Inspection) jsonResult.getData();
//回仓
JsonResult resultData = this.getReversalFlight(inspection);
if(0 != resultData.getCode()){
return JsonResult.error(jsonResult.getCode(),jsonResult.getMsg());
}

return JsonResult.success("无人机返航成功");
}

private JsonResult getReversalFlight(Inspection inspection) {
log.info("执行无人机回仓");
inspection.setStatus(InspectionStatusEnum.FLIGHT_COMPLETED.getCode());
inspection.setUpdateTime(DateUtils.now());
inspection.setUpdateUser(CurrentUserUtil.getUserId());
int count = inspectionMapper.updateById(inspection);
if(count<=0){
log.info("修改任务状态失败:{}",inspection);
throw new SecurityException("修改任务状态失败");
}
//调用机场平台返航
String url = CommonConfig.airportURL + SystemConstant.API_AIRPORT_DRONE_CONTROL;
JSONObject jsonObject = new JSONObject();
jsonObject.put("airportId", inspection.getAirportId());
jsonObject.put("taskId", inspection.getId());
jsonObject.put("zhilin", "03");
jsonObject.put("msg", "回仓");
log.info("调用机场平台,无人机执行定点飞行返航:url:{}", url);
log.info("调用机场平台,原无人机执行定点飞行返航,jsonObject:{}", jsonObject);

String airPortStr = HttpUtils.doSend(url,jsonObject,null,"POST");
log.info("调用无人机平台,操作无人机:airPortStr:{}", airPortStr);
if (StringUtils.isEmpty(airPortStr)) {
log.info("原无人机执行定点飞行返航:机场接口返回数据为空,返航失败,jsonObject:{}", jsonObject);
throw new ServiceException("机场接口返回数据为空,返航失败");
}
JsonResult jsonResult = JacksonUtil.json2pojo(airPortStr, JsonResult.class);
if(0 != jsonResult.getCode()){
log.info("调用机场平台,无人机执行定点飞行:返航失败,jsonResult:{}", jsonResult.getMsg());
return JsonResult.error(-1, jsonResult.getMsg());
}
log.info("调用无人机平台返航结束");
return JsonResult.success();


}

private JsonResult queryInspection(ReversalFlightRequest request) {
Inspection inspection = inspectionMapper.selectById(request.getInspectionId());
if(ObjectUtil.isNull(inspection)){
return JsonResult.error("巡检任务为空");
}
return JsonResult.success(inspection);
}

private JsonResult check(String userId, String tenantId, ReversalFlightRequest request) {
if(StringUtils.isEmpty(request.getInspectionId())){
return JsonResult.error(EditInspectionCodeEnum.ID_IS_NULL.getCode(),EditInspectionCodeEnum.ID_IS_NULL.getMsg());
}
return JsonResult.success();
}
}

+ 2
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/utils/CurrentUserUtil.java View File

@@ -47,7 +47,8 @@ public class CurrentUserUtil {
* @return
*/
public static User getUserInfo() {
String username = SecurityUserUtils.username();
//String username = SecurityUserUtils.username();
String username = "xyAirmonitor5";
User user = currentUserUtil.userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getMark, 1).eq(User::getStatus, 1).eq(User::getUsername, username));
if (null == user) {
Tenant tenant = currentUserUtil.tenantMapper.selectOne(Wrappers.<Tenant>lambdaQuery().eq(Tenant::getMark, 1).eq(Tenant::getStatus, 1).eq(Tenant::getUsername, username));

Loading…
Cancel
Save