Browse Source

Merge branch 'develop' of gitadmin/tuoheng_air_monitor into release

tags/v1.0.3
wanjing 11 months ago
parent
commit
7291b0a5df
4 changed files with 41 additions and 36 deletions
  1. +0
    -3
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/AirDataController.java
  2. +2
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/vo/airData/AirDataExcelVo.java
  3. +30
    -25
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/airData/query/QueryAirDataListService.java
  4. +9
    -8
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/airData/syncdata/SyncAirDataService.java

+ 0
- 3
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/AirDataController.java View File

package com.tuoheng.admin.controller; package com.tuoheng.admin.controller;


import com.tuoheng.admin.entity.domain.AirData;
import com.tuoheng.admin.entity.request.report.ExportReportRequest; import com.tuoheng.admin.entity.request.report.ExportReportRequest;
import com.tuoheng.admin.service.airData.IAirDataService; import com.tuoheng.admin.service.airData.IAirDataService;
import com.tuoheng.common.core.utils.JsonResult; import com.tuoheng.common.core.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;


import java.util.List;

/** /**
* @Author ChengWang * @Author ChengWang
* @Date 2023/5/23 * @Date 2023/5/23

+ 2
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/vo/airData/AirDataExcelVo.java View File

package com.tuoheng.admin.entity.vo.airData; package com.tuoheng.admin.entity.vo.airData;


import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;


/** /**
* @Author ChengWang * @Author ChengWang

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

import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.InputStream; import java.io.InputStream;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;


/** /**
* @Author ChengWang * @Author ChengWang
String userId = user.getId(); String userId = user.getId();
//校验 //校验
JsonResult jsonResult = this.check(id); JsonResult jsonResult = this.check(id);
if(0 != jsonResult.getCode()){
log.info("生成excel表格数据校验失败:{}",jsonResult.getMsg());
if (0 != jsonResult.getCode()) {
log.info("生成excel表格数据校验失败:{}", jsonResult.getMsg());
return jsonResult; return jsonResult;
} }
AirDataExport airDataExport = this.checkAirDataExport(id); AirDataExport airDataExport = this.checkAirDataExport(id);
} }
//获取任务名称 //获取任务名称
Inspection inspection = inspectionMapper.selectById(id); Inspection inspection = inspectionMapper.selectById(id);
if(ObjectUtil.isNull(inspection)){
return JsonResult.error(AirDataEnum.INSPECTION_IS_NOT_EXIST.getCode(),AirDataEnum.INSPECTION_IS_NOT_EXIST.getMsg());
if (ObjectUtil.isNull(inspection)) {
return JsonResult.error(AirDataEnum.INSPECTION_IS_NOT_EXIST.getCode(), AirDataEnum.INSPECTION_IS_NOT_EXIST.getMsg());
} }
String name = inspection.getName(); String name = inspection.getName();
if(StringUtils.isEmpty(name)){
if (StringUtils.isEmpty(name)) {
log.info("对应的任务名称为空"); log.info("对应的任务名称为空");
throw new ServiceException(ServiceExceptionEnum.FILE_DATA_TIME_IS_ERROR); throw new ServiceException(ServiceExceptionEnum.FILE_DATA_TIME_IS_ERROR);
} }
.eq(AirData::getMark, MarkEnum.VALID.getCode()) .eq(AirData::getMark, MarkEnum.VALID.getCode())
.eq(AirData::getInspectionId, id) .eq(AirData::getInspectionId, id)
.orderByAsc(AirData::getCUtcTime)); .orderByAsc(AirData::getCUtcTime));
if(CollectionUtils.isEmpty(airDataList) || airDataList.size() == 0){
return JsonResult.error(AirDataEnum.AIR_DATA_IS_NOT_EXIST.getCode(),AirDataEnum.AIR_DATA_IS_NOT_EXIST.getMsg());
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<>(); List<AirDataExcelVo> airDataExcelVoList = new ArrayList<>();
airDataList.forEach(x->{
airDataList.forEach(x -> {
AirDataExcelVo vo = new AirDataExcelVo(); AirDataExcelVo vo = new AirDataExcelVo();
BeanUtils.copyProperties(x,vo);
BeanUtils.copyProperties(x, vo);
vo.setSo2(x.getSo2()); vo.setSo2(x.getSo2());
vo.setNo2(x.getNo2()); vo.setNo2(x.getNo2());
vo.setO3(x.getO3()); vo.setO3(x.getO3());
//对列表进行排序 //对列表进行排序
//airDataExcelVoList.stream().sorted(Comparator.comparing(AirDataExcelVo::getCUtcTime)).collect(Collectors.toList()); //airDataExcelVoList.stream().sorted(Comparator.comparing(AirDataExcelVo::getCUtcTime)).collect(Collectors.toList());


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


private Integer addAirDataExport(String id, String ossUrl, String tenantId,String userId) {
private Integer addAirDataExport(String id, String ossUrl, String tenantId, String userId) {
AirDataExport airDataExport = new AirDataExport(); AirDataExport airDataExport = new AirDataExport();
airDataExport.setInspectionId(id); airDataExport.setInspectionId(id);
airDataExport.setTenantId(tenantId); airDataExport.setTenantId(tenantId);
try { try {
in = new FileInputStream(file); in = new FileInputStream(file);
//上传到oss //上传到oss
aliyunOSSUtil.uploadFile2OSS(in,fileName);
aliyunOSSUtil.uploadFile2OSS(in, fileName);
//通过文件名获取文件完整路径 //通过文件名获取文件完整路径
ossUrl = aliyunOSSUtil.getFileUrl(fileName); ossUrl = aliyunOSSUtil.getFileUrl(fileName);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {


/** /**
* 大气报告导出记录表数据校验 * 大气报告导出记录表数据校验
*
* @param id * @param id
* @return * @return
*/ */


/** /**
* 生成excel表格 * 生成excel表格
*
* @param voArrayList * @param voArrayList
* @param inspection * @param inspection
* @return * @return
*/ */
public JsonResult easyExcel(List<AirDataExcelVo> voArrayList,Inspection inspection,String filePath) {
log.info("文件输出目录及格式:filePathName={}",filePath);
public JsonResult easyExcel(List<AirDataExcelVo> voArrayList, Inspection inspection, String filePath) {
log.info("文件输出目录及格式:filePathName={}", filePath);
List<List<String>> heads = new ArrayList<>(); List<List<String>> heads = new ArrayList<>();
String totalName = "项目名称:"+ inspection.getName();
String totalName = "项目名称:" + inspection.getName();
String[] nameString = SystemConstant.EXCEL_SECOND_NAME; String[] nameString = SystemConstant.EXCEL_SECOND_NAME;
for (String excelName : nameString) { for (String excelName : nameString) {
heads.add(Arrays.asList(totalName,excelName));
heads.add(Arrays.asList(totalName, excelName));
} }
//需要写出的表格(对应实体类) //需要写出的表格(对应实体类)
try { try {
} }


private JsonResult check(String id) { private JsonResult check(String id) {
if(StringUtils.isEmpty(id)){
return JsonResult.error(AirDataEnum.INSPECTION_ID_IS_NULL.getCode(),AirDataEnum.INSPECTION_ID_IS_NULL.getMsg());
if (StringUtils.isEmpty(id)) {
return JsonResult.error(AirDataEnum.INSPECTION_ID_IS_NULL.getCode(), AirDataEnum.INSPECTION_ID_IS_NULL.getMsg());
} }
return JsonResult.success(); return JsonResult.success();
} }

+ 9
- 8
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/airData/syncdata/SyncAirDataService.java View File

import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;


import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;


airData.setHumidity(response.getHumidity()); // 湿度 airData.setHumidity(response.getHumidity()); // 湿度
airData.setHdop(response.getHdop()); // 水平精度因子 airData.setHdop(response.getHdop()); // 水平精度因子
airData.setPressure(response.getPressure()); // 大气压 airData.setPressure(response.getPressure()); // 大气压
airData.setCUtcTime(DateUtils.convert(DateUtils.YYYY_MM_DD_HH_MM_SS_2, DateUtils.YYYY_MM_DD_HH_MM_SS, response.getUtcTime())); // UTC时间
// if (StringUtils.isNotEmpty(response.getUtcTime())) {
// String utcTime = DateUtils.convert(DateUtils.YYYY_MM_DD_HH_MM_SS_2, DateUtils.YYYY_MM_DD_HH_MM_SS, response.getUtcTime()); // UTC时间
// Date dateTimeStr = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, utcTime);
// Date dateTime = DateUtils.addDateTimeToDate(dateTimeStr, 0, 8, 0, 0);
// String result = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, dateTime);
// airData.setCUtcTime(result);
// }
// airData.setCUtcTime(DateUtils.convert(DateUtils.YYYY_MM_DD_HH_MM_SS_2, DateUtils.YYYY_MM_DD_HH_MM_SS, response.getUtcTime())); // UTC时间
if (StringUtils.isNotEmpty(response.getUtcTime())) {
String utcTime = DateUtils.convert(DateUtils.YYYY_MM_DD_HH_MM_SS_2, DateUtils.YYYY_MM_DD_HH_MM_SS, response.getUtcTime()); // UTC时间
Date dateTimeStr = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, utcTime);
Date dateTime = DateUtils.addDateTimeToDate(dateTimeStr, 0, 8, 0, 0);
String result = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, dateTime);
airData.setCUtcTime(result);
}


Map<String, Object> airDataMap = response.getAirData(); Map<String, Object> airDataMap = response.getAirData();
String cl2 = this.getValue(airDataMap, "CL2(ppm)"); // 氯气(单位ppm) String cl2 = this.getValue(airDataMap, "CL2(ppm)"); // 氯气(单位ppm)

Loading…
Cancel
Save