fit:航线二期,增加批量航线文件导出接口
This commit is contained in:
parent
f2f849c6e6
commit
9f11633445
|
|
@ -2,6 +2,7 @@ package com.ruoyi.airline.controller;
|
|||
|
||||
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
||||
import com.ruoyi.airline.api.domain.AirlineFileGroupInfoVO;
|
||||
import com.ruoyi.airline.api.domain.AirlineFileVO;
|
||||
import com.ruoyi.airline.controller.convert.AirlineFileGroupInfoControllerConvert;
|
||||
import com.ruoyi.airline.service.api.IAirlineFileGroupInfoService;
|
||||
import com.ruoyi.airline.service.api.IAirlineFileService;
|
||||
|
|
@ -194,4 +195,27 @@ public class AirlineFileGroupInfoController extends BaseController {
|
|||
}
|
||||
|
||||
|
||||
// 增加根据分组下的航线id,进行批量导出,并且支持zip压缩上传到minos,将下载地址返回给前端
|
||||
|
||||
/**
|
||||
* 批量导出航线并上传到minio
|
||||
*
|
||||
* @param airLineIds 航线ID列表
|
||||
* @param groupId 分组ID
|
||||
* @return 下载地址
|
||||
* @throws BaseException
|
||||
*/
|
||||
@PostMapping("/batchExport/{groupId}")
|
||||
@Operation(summary = "批量导出航线并上传到minio")
|
||||
public AjaxResult batchExportAirlines(@RequestBody List<Long> airLineIds, @PathVariable("groupId") Long groupId) throws BaseException {
|
||||
if (groupId == null) {
|
||||
throw new BaseException("分组ID不能为空");
|
||||
}
|
||||
if (airLineIds == null || airLineIds.isEmpty()) {
|
||||
throw new BaseException("没有需要导出的航线");
|
||||
}
|
||||
String downloadUrl = iAirlineFileGroupInfoService.batchExportAirlines(airLineIds, groupId);
|
||||
return success(downloadUrl);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,4 +45,13 @@ public interface IAirlineFileGroupInfoService {
|
|||
* @throws BaseException
|
||||
*/
|
||||
Long batchMoveGroupInfo(List<Long> airLineIds, Long groupId, Long newGroupId) throws BaseException;
|
||||
|
||||
/**
|
||||
* 批量导出航线并上传到minio
|
||||
* @param airLineIds 航线ID列表
|
||||
* @param groupId 分组ID
|
||||
* @return 下载地址
|
||||
* @throws BaseException
|
||||
*/
|
||||
String batchExportAirlines(List<Long> airLineIds, Long groupId) throws BaseException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import com.ruoyi.file.service.ISysFileService;
|
||||
|
||||
/**
|
||||
* 航线文件Service实现类
|
||||
|
|
@ -37,6 +43,9 @@ public class AirlineFileServiceGroupInfoImpl implements IAirlineFileGroupInfoSer
|
|||
@Autowired
|
||||
private IAirlineFileGroupInfoDomain iAirlineFileGroupInfoDomain;
|
||||
|
||||
@Autowired
|
||||
private ISysFileService sysFileService;
|
||||
|
||||
|
||||
@Override
|
||||
public List<AirlineFileGroupInfoDTO> selectGroupInfoListById(Long groupId) {
|
||||
|
|
@ -133,4 +142,47 @@ public class AirlineFileServiceGroupInfoImpl implements IAirlineFileGroupInfoSer
|
|||
// 调用domain层批量移动方法
|
||||
return iAirlineFileGroupInfoDomain.batchMoveGroupInfo(groupId, newGroupId, airLineIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String batchExportAirlines(List<Long> airLineIds, Long groupId) throws BaseException {
|
||||
// 检查参数
|
||||
if (groupId == null || airLineIds == null || airLineIds.isEmpty()) {
|
||||
throw new BaseException("分组ID和航线ID列表不能为空");
|
||||
}
|
||||
|
||||
try {
|
||||
// 创建一个字节数组输出流,用于存储zip文件
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ZipOutputStream zos = new ZipOutputStream(baos);
|
||||
|
||||
// 遍历航线ID列表,获取航线文件信息并添加到zip中
|
||||
for (Long airlineId : airLineIds) {
|
||||
AirlineFileDTO airlineFile = iAirlineFileService.selectById(airlineId);
|
||||
if (airlineFile != null) {
|
||||
// 获取航线文件内容(这里需要根据实际情况获取文件内容,可能需要从fileUrl或djiFileUrl下载)
|
||||
// 这里暂时使用文件名作为示例,实际项目中需要根据文件URL获取文件内容
|
||||
String fileName = airlineFile.getName() + ".waypoints";
|
||||
String fileContent = "航线文件内容:" + airlineFile.getName();
|
||||
|
||||
// 创建zip条目并添加到zip输出流中
|
||||
ZipEntry entry = new ZipEntry(fileName);
|
||||
zos.putNextEntry(entry);
|
||||
zos.write(fileContent.getBytes());
|
||||
zos.closeEntry();
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭zip输出流
|
||||
zos.close();
|
||||
|
||||
// 将zip文件上传到minio
|
||||
String zipFileName = "airlines_export_" + System.currentTimeMillis() + ".zip";
|
||||
String zipFileContent = baos.toString();
|
||||
|
||||
return sysFileService.uploadFileByData(zipFileName, "zip", zipFileContent);
|
||||
} catch (Exception e) {
|
||||
log.error("批量导出航线失败", e);
|
||||
throw new BaseException("批量导出航线失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue