|
|
@ -1,20 +1,38 @@ |
|
|
|
package org.dromara.sample.wayline.controller; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Optional; |
|
|
|
import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.date.DateTime; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.img.ImgUtil; |
|
|
|
import cn.hutool.core.io.FileUtil; |
|
|
|
import cn.hutool.core.util.NumberUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.RandomUtil; |
|
|
|
import cn.hutool.json.JSONArray; |
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import jakarta.servlet.http.HttpServletResponse; |
|
|
|
import jakarta.validation.constraints.*; |
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission; |
|
|
|
import org.dromara.common.core.utils.file.FileUtils; |
|
|
|
import org.dromara.common.sdk.common.HttpResultResponse; |
|
|
|
import org.dromara.sample.manage.domain.ManageDevicePayloadCustom; |
|
|
|
import org.dromara.sample.manage.service.IManageDevicePayloadCustomService; |
|
|
|
import org.dromara.sample.utils.AtmosphereCalculateUtil; |
|
|
|
import org.dromara.sample.wayline.domain.bo.WaylineJobAtmosphereData; |
|
|
|
import org.dromara.sample.wayline.model.dto.WaylineJobDTO; |
|
|
|
import org.dromara.sample.wayline.model.entity.WaylineJobEntity; |
|
|
|
import org.dromara.sample.wayline.service.IWaylineJobService; |
|
|
|
import org.springframework.core.io.ClassPathResource; |
|
|
|
import org.springframework.util.StreamUtils; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
import org.dromara.common.idempotent.annotation.RepeatSubmit; |
|
|
@ -30,6 +48,7 @@ import org.dromara.sample.wayline.domain.vo.WaylineJobAtmosphereVo; |
|
|
|
import org.dromara.sample.wayline.domain.bo.WaylineJobAtmosphereBo; |
|
|
|
import org.dromara.sample.wayline.service.IWaylineJobAtmosphereService; |
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
/** |
|
|
|
* 无人机任务-空气质量 |
|
|
@ -46,6 +65,7 @@ public class WaylineJobAtmosphereController extends BaseController { |
|
|
|
|
|
|
|
private final IWaylineJobAtmosphereService waylineJobAtmosphereService; |
|
|
|
private final IWaylineJobService waylineJobService; |
|
|
|
private final IManageDevicePayloadCustomService manageDevicePayloadCustomService; |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询无人机任务-空气质量列表 |
|
|
@ -110,6 +130,335 @@ public class WaylineJobAtmosphereController extends BaseController { |
|
|
|
ExcelUtil.exportExcel(list, "无人机任务-空气质量", WaylineJobAtmosphereVo.class, response); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//NO2
|
|
|
|
/** 导出大气检测报告-单类型 **/ |
|
|
|
@Log(title = "无人机任务-空气质量-导出", businessType = BusinessType.EXPORT) |
|
|
|
@PostMapping("/exportPdf") |
|
|
|
// public void exportPdf( WaylineJobAtmosphereData data, @RequestPart("img") MultipartFile img, HttpServletResponse response) {
|
|
|
|
public void exportPdf(@RequestBody WaylineJobAtmosphereData data, HttpServletResponse response) { |
|
|
|
|
|
|
|
float areaWidth = 150.0f;//网格默认宽
|
|
|
|
float areaLength = 150.0f;//网格默认高
|
|
|
|
// AtmosphereCalculateUtil.GridGasStatResult result = waylineJobAtmosphereService.dealBasicData(data, areaWidth, areaLength);
|
|
|
|
//处理任务信息
|
|
|
|
WaylineJobEntity waylineJob = waylineJobService.queryById(data.getWaylineJobId()); |
|
|
|
data.setStartTime(DateUtil.format(waylineJob.getExecuteTime(), "yyyy-MM-dd HH:mm:ss")); |
|
|
|
data.setEndTime(DateUtil.format(waylineJob.getCompletedTime(), "yyyy-MM-dd HH:mm:ss")); |
|
|
|
|
|
|
|
//处理设备信息
|
|
|
|
ManageDevicePayloadCustom payloadCustom = manageDevicePayloadCustomService.selectDevicePayloadBySerial(data.getSerial()); |
|
|
|
data.setDeviceName(waylineJob.getName()); |
|
|
|
data.setDeviceSerial(data.getSerial()); |
|
|
|
data.setDeviceId(payloadCustom.getId()+""); |
|
|
|
data.setDeptDetectName(waylineJob.getWaylineName()+"大气监测"); |
|
|
|
|
|
|
|
if(JSONUtil.isTypeJSON(payloadCustom.getPayloadDesc())){ |
|
|
|
JSONObject entries = JSONUtil.parseObj(payloadCustom.getPayloadDesc()); |
|
|
|
String companyName = entries.getStr("companyName",""); |
|
|
|
data.setCompanyName(companyName); |
|
|
|
areaWidth = entries.getFloat("areaWidth",150.0f); |
|
|
|
areaLength = entries.getFloat("areaLength",150.0f); |
|
|
|
} |
|
|
|
|
|
|
|
//处理监测点+网格信息
|
|
|
|
WaylineJobAtmosphereBo bo = new WaylineJobAtmosphereBo(); |
|
|
|
bo.setWaylineJobId(data.getWaylineJobId()); |
|
|
|
List<WaylineJobAtmosphereVo> atmospherList = waylineJobAtmosphereService.queryList(bo); |
|
|
|
data.setAnalysisCount(atmospherList.size()); |
|
|
|
|
|
|
|
data.setAreaWidth(areaWidth); |
|
|
|
data.setAreaLength(areaLength); |
|
|
|
data.setAreaSize(NumberUtil.round(NumberUtil.mul(areaWidth,areaLength),3).floatValue()); |
|
|
|
//计算关键参数
|
|
|
|
double latGridSize = areaWidth / 111000.0; // latGridSize(转经纬度计算)
|
|
|
|
double lonGridSize = areaLength / (85000.0 * Math.cos(Math.toRadians(34.27))); // lonGridSize(转经纬度计算)
|
|
|
|
AtmosphereCalculateUtil.GridGasStatResult result = AtmosphereCalculateUtil.computeStats( |
|
|
|
atmospherList, |
|
|
|
latGridSize, |
|
|
|
lonGridSize, |
|
|
|
data.getAtmosphereType() |
|
|
|
); |
|
|
|
|
|
|
|
data.setAreaTotalSize(result.getAreaTotalSize().floatValue()); |
|
|
|
data.setAreaLat(result.getAreaLat().floatValue()); |
|
|
|
data.setAreaLon(result.getAreaLon().floatValue()); |
|
|
|
|
|
|
|
data.setConcentrationAvag(result.getConcentrationAvag()); |
|
|
|
data.setConcentrationMax(result.getConcentrationMax()); |
|
|
|
data.setConcentrationMin(result.getConcentrationMin()); |
|
|
|
data.setConcentrationPointMax(result.getConcentrationPointMax()); |
|
|
|
data.setConcentrationPointMin(result.getConcentrationPointMin()); |
|
|
|
|
|
|
|
//模拟数据-PM2_5
|
|
|
|
// getAtmosphereData(data);
|
|
|
|
|
|
|
|
waylineJobAtmosphereService.exportPdf(data,response); |
|
|
|
// List<WaylineJobAtmosphereVo> list = waylineJobAtmosphereService.queryList(bo);
|
|
|
|
// ExcelUtil.exportExcel(list, "无人机任务-空气质量", WaylineJobAtmosphereVo.class, response);
|
|
|
|
} |
|
|
|
|
|
|
|
/** 导出大气检测报告-多类型 **/ |
|
|
|
@Log(title = "无人机任务-空气质量-导出", businessType = BusinessType.EXPORT) |
|
|
|
@PostMapping("/exportBatchPdf") |
|
|
|
// public void exportPdf( WaylineJobAtmosphereData data, @RequestPart("img") MultipartFile img, HttpServletResponse response) {
|
|
|
|
// public void exportBatchPdf(JSONArray json,WaylineJobAtmosphereData atmosphereType, HttpServletResponse response) {
|
|
|
|
// public void exportBatchPdf(@RequestBody List<WaylineJobAtmosphereData> list, HttpServletResponse response) {
|
|
|
|
public void exportBatchPdf(@RequestParam(name = "data_list") String dataList, |
|
|
|
@RequestParam(name = "data_cal_list") String dataCalList, |
|
|
|
@RequestPart(name = "file_list") List<MultipartFile> fileList, |
|
|
|
HttpServletResponse response) { |
|
|
|
// public void exportBatchPdf(@PathVariable(name = "data_ist") String dataList,
|
|
|
|
// @RequestPart("fileList") List<MultipartFile> fileList,
|
|
|
|
// HttpServletResponse response) {
|
|
|
|
|
|
|
|
// List<WaylineJobAtmosphereData> list = JSONUtil.toList(json, WaylineJobAtmosphereData.class);
|
|
|
|
//模拟数据-PM2_5
|
|
|
|
// List<WaylineJobAtmosphereData> list = JSONUtil.toList(dataList, WaylineJobAtmosphereData.class);
|
|
|
|
// System.out.println("dataCalList" + dataCalList);
|
|
|
|
WaylineJobAtmosphereData calData = JSONUtil.toBean(dataCalList, WaylineJobAtmosphereData.class);//数据从前台接收
|
|
|
|
|
|
|
|
WaylineJobAtmosphereData dataObj = JSONUtil.toBean(dataList, WaylineJobAtmosphereData.class); |
|
|
|
List<WaylineJobAtmosphereData> list = new ArrayList<>(); |
|
|
|
String[] split = dataObj.getAtmosphereType().split(","); |
|
|
|
for (int i = 0; i < split.length; i++) { |
|
|
|
WaylineJobAtmosphereData newData = new WaylineJobAtmosphereData(); |
|
|
|
BeanUtil.copyProperties(dataObj,newData); |
|
|
|
newData.setAtmosphereType(split[i].toUpperCase()); |
|
|
|
newData.setAtmosphereTypeStr(split[i].toUpperCase()); |
|
|
|
list.add(newData); |
|
|
|
} |
|
|
|
|
|
|
|
if(ObjectUtil.isEmpty(list)) {return;} |
|
|
|
WaylineJobAtmosphereData data = list.get(0); |
|
|
|
//找设备序列号
|
|
|
|
ManageDevicePayloadCustom manageDevicePayloadCustom = manageDevicePayloadCustomService.selectDevicePayloadByDocnSn(data.getDeviceSn()); |
|
|
|
if (ObjectUtil.isNotEmpty(manageDevicePayloadCustom)) { |
|
|
|
for (WaylineJobAtmosphereData atmosphereData : list) { |
|
|
|
atmosphereData.setSerial(manageDevicePayloadCustom.getPayloadSn()); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
//处理任务信息
|
|
|
|
WaylineJobEntity waylineJob = waylineJobService.queryById(data.getWaylineJobId()); |
|
|
|
data.setStartTime(DateUtil.format(waylineJob.getExecuteTime(), "yyyy-MM-dd HH:mm:ss")); |
|
|
|
data.setEndTime(DateUtil.format(waylineJob.getCompletedTime(), "yyyy-MM-dd HH:mm:ss")); |
|
|
|
|
|
|
|
//处理设备信息
|
|
|
|
ManageDevicePayloadCustom payloadCustom = manageDevicePayloadCustomService.selectDevicePayloadBySerial(data.getSerial()); |
|
|
|
data.setDeviceName(waylineJob.getName()); |
|
|
|
data.setDeviceSerial(data.getSerial()); |
|
|
|
data.setDeviceId(payloadCustom.getId()+""); |
|
|
|
data.setDeptDetectName(waylineJob.getWaylineName()+"大气监测"); |
|
|
|
|
|
|
|
float areaWidth = 150.0f;//网格默认宽
|
|
|
|
float areaLength = 150.0f;//网格默认高
|
|
|
|
if(JSONUtil.isTypeJSON(payloadCustom.getPayloadDesc())){ |
|
|
|
JSONObject entries = JSONUtil.parseObj(payloadCustom.getPayloadDesc()); |
|
|
|
String companyName = entries.getStr("companyName",""); |
|
|
|
data.setCompanyName(companyName); |
|
|
|
areaWidth = entries.getFloat("areaWidth",150.0f); |
|
|
|
areaLength = entries.getFloat("areaLength",150.0f); |
|
|
|
} |
|
|
|
|
|
|
|
//处理监测点+网格信息
|
|
|
|
WaylineJobAtmosphereBo bo = new WaylineJobAtmosphereBo(); |
|
|
|
bo.setWaylineJobId(data.getWaylineJobId()); |
|
|
|
List<WaylineJobAtmosphereVo> atmospherList = waylineJobAtmosphereService.queryList(bo); |
|
|
|
data.setAnalysisCount(atmospherList.size()); |
|
|
|
|
|
|
|
data.setAreaWidth(areaWidth); |
|
|
|
data.setAreaLength(areaLength); |
|
|
|
data.setAreaSize(NumberUtil.round(NumberUtil.mul(areaWidth,areaLength),3).floatValue()); |
|
|
|
|
|
|
|
//计算关键参数
|
|
|
|
List<String> atmosphereTypeList = list.stream().map(WaylineJobAtmosphereData::getAtmosphereType).distinct().collect(Collectors.toList()); |
|
|
|
double latGridSize = areaWidth / 111000.0; // latGridSize(转经纬度计算)
|
|
|
|
double lonGridSize = areaLength / (85000.0 * Math.cos(Math.toRadians(34.27))); // lonGridSize(转经纬度计算)
|
|
|
|
List<AtmosphereCalculateUtil.GridGasStatResult> resultList = AtmosphereCalculateUtil.computeStats( |
|
|
|
atmospherList, |
|
|
|
latGridSize, |
|
|
|
lonGridSize, |
|
|
|
atmosphereTypeList |
|
|
|
); |
|
|
|
|
|
|
|
// List<WaylineJobAtmosphereData> dataList = new ArrayList<WaylineJobAtmosphereData>();
|
|
|
|
|
|
|
|
for (WaylineJobAtmosphereData atmosphereData : list) { |
|
|
|
AtmosphereCalculateUtil.GridGasStatResult result = resultList.stream().filter(item -> item.getGasKey().equals(atmosphereData.getAtmosphereType())).findFirst().orElse(null); |
|
|
|
atmosphereData.setAtmosphereTypeStr(atmosphereData.getAtmosphereType()); |
|
|
|
atmosphereData.setAreaTotalSize(result.getAreaTotalSize().floatValue()); |
|
|
|
atmosphereData.setAreaLat(result.getAreaLat().floatValue()); |
|
|
|
atmosphereData.setAreaLon(result.getAreaLon().floatValue()); |
|
|
|
|
|
|
|
atmosphereData.setConcentrationAvag(result.getConcentrationAvag()); |
|
|
|
atmosphereData.setConcentrationMax(result.getConcentrationMax()); |
|
|
|
atmosphereData.setConcentrationMin(result.getConcentrationMin()); |
|
|
|
atmosphereData.setConcentrationPointMax(result.getConcentrationPointMax()); |
|
|
|
atmosphereData.setConcentrationPointMin(result.getConcentrationPointMin()); |
|
|
|
|
|
|
|
// fileList.get()
|
|
|
|
// atmosphereData.setImgUrl();
|
|
|
|
} |
|
|
|
if(list.size() > 0){//数据从前端覆盖
|
|
|
|
list.getFirst().setConcentrationMax(calData.getConcentrationMax()); |
|
|
|
list.getFirst().setConcentrationMin(calData.getConcentrationMin()); |
|
|
|
} |
|
|
|
|
|
|
|
//统一排序,渲染图片-临时文件
|
|
|
|
List<File> tempFiles = new ArrayList<>(); |
|
|
|
List<String> imgPaths = new ArrayList<>(); |
|
|
|
|
|
|
|
for (int i = 0; i < list.size(); i++) { |
|
|
|
WaylineJobAtmosphereData item = list.get(i); |
|
|
|
MultipartFile multipartFile = fileList.get(i); |
|
|
|
|
|
|
|
try { |
|
|
|
String suffix = FileUtil.extName(multipartFile.getOriginalFilename()); |
|
|
|
File tempFile = File.createTempFile("pdfimg-", suffix); |
|
|
|
multipartFile.transferTo(tempFile); |
|
|
|
|
|
|
|
tempFiles.add(tempFile); |
|
|
|
imgPaths.add(tempFile.toURI().toString()); |
|
|
|
item.setImgUrl(imgPaths.get(i)); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
System.err.println("pdfimg处理异常"); |
|
|
|
} |
|
|
|
|
|
|
|
item.setImgName(multipartFile.getName()); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
waylineJobAtmosphereService.exportBatchPdf(list,response); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} finally { |
|
|
|
//清除临时文件
|
|
|
|
for (File tempFile : tempFiles) { |
|
|
|
if(tempFile.exists()){ |
|
|
|
tempFile.delete(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// List<WaylineJobAtmosphereVo> list = waylineJobAtmosphereService.queryList(bo);
|
|
|
|
// ExcelUtil.exportExcel(list, "无人机任务-空气质量", WaylineJobAtmosphereVo.class, response);
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void getAtmosphereData(WaylineJobAtmosphereData data) { |
|
|
|
|
|
|
|
if(ObjectUtil.isEmpty(data.getImgUrl())) { |
|
|
|
// File file = FileUtil.file("");
|
|
|
|
// byte[] bytes = FileUtil.readBytes(file);
|
|
|
|
// String base64 = Base64.getEncoder().encodeToString(bytes);
|
|
|
|
// data.setAtmosphereType(base64);
|
|
|
|
|
|
|
|
try { |
|
|
|
ClassPathResource resource = new ClassPathResource("templates/empty.png"); |
|
|
|
byte[] bytes = StreamUtils.copyToByteArray(resource.getInputStream()); |
|
|
|
data.setImgUrl( "data:image/png;base64," + Base64.getEncoder().encodeToString(bytes)); |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
float v = 901.230543f; |
|
|
|
double v1 = RandomUtil.randomDouble(); |
|
|
|
double v2 = RandomUtil.randomDouble(); |
|
|
|
double v3 = RandomUtil.randomDouble(); |
|
|
|
double v4 = RandomUtil.randomDouble(); |
|
|
|
|
|
|
|
switch (data.getAtmosphereType()){ |
|
|
|
case "PM2_5": |
|
|
|
data.setAtmosphereTypeStr("PM2.5"); |
|
|
|
data.setDeptDetectName("和平街道大气监测"); |
|
|
|
data.setCompanyName("徐州市低空产业公司"); |
|
|
|
data.setStartTime("2020-01-01 00:00:00"); |
|
|
|
data.setEndTime("2020-12-31 23:59:59"); |
|
|
|
data.setDeviceName("低空-徐州鼓楼琵琶街道"); |
|
|
|
data.setDeviceSerial("37c12953"); |
|
|
|
data.setDeviceId("100"); |
|
|
|
data.setAnalysisCount(901); |
|
|
|
|
|
|
|
data.setAreaWidth(NumberUtil.round(v1, 3, RoundingMode.DOWN).floatValue());//剪切数字长度
|
|
|
|
data.setAreaLength(NumberUtil.round(v2, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
data.setAreaSize(NumberUtil.round(v3, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
data.setAreaTotalSize(NumberUtil.round(v4, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
data.setAreaLat(NumberUtil.round(v1, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
data.setAreaLon(NumberUtil.round(v2, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
|
|
|
|
data.setConcentrationAvag(NumberUtil.round(v1, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
data.setConcentrationMax(NumberUtil.round(v2, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
data.setConcentrationMin(NumberUtil.round(v3, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
data.setConcentrationPointMax(NumberUtil.round(v3, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
data.setConcentrationPointMin(NumberUtil.round(v4, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
|
|
|
|
// String imgBase64 = convertToBase64(img);
|
|
|
|
// data.setImgUrl(imgBase64);
|
|
|
|
// data.setImgUrl("templates/灵嗅-pm2.5.png");
|
|
|
|
|
|
|
|
break; |
|
|
|
case "PM1_0": |
|
|
|
break; |
|
|
|
case "NO2": |
|
|
|
data.setAtmosphereTypeStr("NO2"); |
|
|
|
data.setDeptDetectName("和平街道大气监测"); |
|
|
|
data.setCompanyName("徐州市低空产业公司"); |
|
|
|
data.setStartTime("2020-01-01 00:00:00"); |
|
|
|
data.setEndTime("2020-12-31 23:59:59"); |
|
|
|
data.setDeviceName("低空-徐州鼓楼琵琶街道"); |
|
|
|
data.setDeviceSerial("37c12953"); |
|
|
|
data.setDeviceId("100"); |
|
|
|
data.setAnalysisCount(901); |
|
|
|
|
|
|
|
data.setAreaWidth(NumberUtil.round(v1, 3, RoundingMode.DOWN).floatValue());//剪切数字长度
|
|
|
|
data.setAreaLength(NumberUtil.round(v2, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
data.setAreaSize(NumberUtil.round(v3, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
data.setAreaTotalSize(NumberUtil.round(v4, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
data.setAreaLat(NumberUtil.round(v1, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
data.setAreaLon(NumberUtil.round(v2, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
|
|
|
|
data.setConcentrationAvag(NumberUtil.round(v1, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
data.setConcentrationMax(NumberUtil.round(v2, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
data.setConcentrationMin(NumberUtil.round(v3, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
data.setConcentrationPointMax(NumberUtil.round(v3, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
data.setConcentrationPointMin(NumberUtil.round(v4, 3, RoundingMode.DOWN).floatValue()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static String toBase64(MultipartFile file) { |
|
|
|
try { |
|
|
|
byte[] bytes = file.getBytes(); |
|
|
|
String base64 = Base64.getEncoder().encodeToString(bytes); |
|
|
|
String contentType = file.getContentType(); // eg: "image/png"
|
|
|
|
return "data:" + contentType + ";base64," + base64; |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException("图片转换失败", e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 将上传的 MultipartFile 转为 Base64 字符串
|
|
|
|
public String convertToBase64(MultipartFile file) { |
|
|
|
|
|
|
|
String base64 = null; |
|
|
|
try { |
|
|
|
byte[] bytes = file.getBytes(); |
|
|
|
base64 = Base64.getEncoder().encodeToString(bytes); |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
return "data:image/png;base64," + base64; // 注意类型可能是 image/jpeg 或其他
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 获取无人机任务-空气质量详细信息 |
|
|
|
* |
|
|
|