feat: 打包下载调整和导出

This commit is contained in:
caiyuchao
2025-07-29 15:40:54 +08:00
parent 4c976d5400
commit 94e2e0c5c6
3 changed files with 133 additions and 50 deletions

View File

@@ -1,5 +1,7 @@
package org.agt.module.license.controller.admin.license;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -11,7 +13,10 @@ import org.agt.framework.common.pojo.CommonResult;
import org.agt.framework.common.pojo.PageParam;
import org.agt.framework.common.pojo.PageResult;
import org.agt.framework.common.util.object.BeanUtils;
import org.agt.framework.dict.core.DictFrameworkUtils;
import org.agt.framework.excel.core.util.ExcelUtils;
import org.agt.framework.translate.core.TranslateUtils;
import org.agt.module.license.controller.admin.license.vo.LicenseNeCodeVO;
import org.agt.module.license.controller.admin.license.vo.LicensePageReqVO;
import org.agt.module.license.controller.admin.license.vo.LicenseRespVO;
import org.agt.module.license.controller.admin.license.vo.LicenseSaveReqVO;
@@ -29,6 +34,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static org.agt.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
@@ -108,9 +114,48 @@ public class LicenseController {
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<LicenseDO> list = licenseService.getLicensePage(pageReqVO).getList();
List<LicenseRespVO> voList = BeanUtils.toBean(list, LicenseRespVO.class);
List<LicenseRespVO> results = new ArrayList<>();
for (LicenseRespVO license : voList) {
List<LicenseNeCodeVO> neCodeList = license.getNeCodeList();
if (CollUtil.isEmpty(neCodeList)) {
results.add(license);
} else {
for (LicenseNeCodeVO licenseNeCodeVO : neCodeList) {
LicenseRespVO licenseVO = new LicenseRespVO();
BeanUtils.copyProperties(license, licenseVO);
List<String> neLabels = new ArrayList<>();
for (Integer ne : licenseNeCodeVO.getNeList()) {
String label = DictFrameworkUtils.parseDictDataLabel("lic_ne_all", ne.toString());
if (StrUtil.isBlank(label)) {
label = DictFrameworkUtils.parseDictDataLabel("lic_ne_5g", ne.toString());
if (StrUtil.isBlank(label)) {
label = DictFrameworkUtils.parseDictDataLabel("lic_ne_4g", ne.toString());
if (StrUtil.isBlank(label)) {
label = DictFrameworkUtils.parseDictDataLabel("lic_ne_23g", ne.toString());
if (StrUtil.isBlank(label)) {
label = DictFrameworkUtils.parseDictDataLabel("lic_ne_add", ne.toString());
}
}
}
}
neLabels.add(label);
}
String neListStr = StrUtil.join("_", neLabels);
licenseVO.setNeListStr(neListStr);
licenseVO.setActivationCode(licenseNeCodeVO.getActivationCode());
results.add(licenseVO);
}
}
}
// 导出 Excel
ExcelUtils.write(response, "License.xls", "数据", LicenseRespVO.class,
BeanUtils.toBean(list, LicenseRespVO.class));
TranslateUtils.translate(results));
}
@GetMapping("/sn-unique")

View File

@@ -42,7 +42,7 @@ public class LicenseRespVO implements VO {
private String projectName;
@Schema(description = "sn", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("sn")
@ExcelProperty("SN")
private String serialNo;
@Schema(description = "到期时间")
@@ -50,10 +50,18 @@ public class LicenseRespVO implements VO {
private LocalDateTime expiryDate;
@Schema(description = "网元开关")
@ExcelProperty(value = "网元开关", converter = DictConvert.class)
// @ExcelProperty(value = "网元开关", converter = DictConvert.class)
@DictFormat("lic_ne_switch") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private List<Integer> neList;
@Schema(description = "网元")
@ExcelProperty("网元")
private String neListStr;
@Schema(description = "激活码")
@ExcelProperty("激活码")
private String activationCode;
@Schema(description = "网元激活码列表")
private List<LicenseNeCodeVO> neCodeList;
@@ -65,16 +73,12 @@ public class LicenseRespVO implements VO {
@ExcelProperty("基站数")
private Integer ranNumber;
@Schema(description = "激活码")
@ExcelProperty("激活码")
private String activationCode;
@Schema(description = "文件URL")
@ExcelProperty("文件URL")
// @ExcelProperty("文件URL")
private String fileUrl;
@Schema(description = "License内容")
@ExcelProperty("License内容")
// @ExcelProperty("License内容")
private String licenseContent;
@Schema(description = "申请人ID")
@@ -86,7 +90,7 @@ public class LicenseRespVO implements VO {
private String applicantName;
@Schema(description = "申请时间")
@ExcelProperty("申请时间")
// @ExcelProperty("申请时间")
private LocalDateTime applicationTime;
@Schema(description = "审批人")
@@ -103,7 +107,7 @@ public class LicenseRespVO implements VO {
private Integer status;
@Schema(description = "备注", example = "随便")
@ExcelProperty("备注")
@ExcelProperty("说明")
private String remark;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)

View File

@@ -1,5 +1,6 @@
package org.agt.module.license.service.license;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.StrUtil;
@@ -226,47 +227,73 @@ public class LicenseServiceImpl implements LicenseService {
String fileName = getFileName(licenseDO.getSerialNo(), detail.getNeList());
// 上传到文件服务
byte[] fileContent = null;
try {
String newFilePath1 = licenseProviderDO.getNewFilePath1();
log.info("45G_下载License文件路径为{}", newFilePath1);
fileContent = FileUtil.readBytes(newFilePath1);
} catch (Exception e) {
log.error("读取文件失败", e);
}
if (fileContent == null) {
log.error("读取文件失败为空");
fileContent = ResourceUtil.readBytes("file/MME_13750602_2024-08-02_system.ini");
List<String> fileUrls = new ArrayList<>();
String newFilePath1 = licenseProviderDO.getNewFilePath1();
if (StrUtil.isNotBlank(newFilePath1)) {
byte[] fileContent = null;
try {
log.info("下载License文件路径为{}", newFilePath1);
fileContent = FileUtil.readBytes(newFilePath1);
} catch (Exception e) {
log.error("读取文件失败", e);
}
if (fileContent == null) {
log.error("读取文件失败为空");
// fileContent = ResourceUtil.readBytes("file/MME_13750602_2024-08-02_system.ini");
} else {
// 上传到文件服务
String preFileName = "45G_";
if (newFilePath1.contains("Legacy_")) {
preFileName = "Legacy_";
}
String fileURL = fileApi.createFile(fileContent, preFileName + fileName);
fileUrls.add(fileURL);
}
}
String fileURL = fileApi.createFile(fileContent, "45G_" + fileName);
String newFilePath0 = licenseProviderDO.getNewFilePath0();
if (StrUtil.isNotBlank(newFilePath0)) {
byte[] fileContent0 = null;
try {
log.info("下载Legacy_License文件路径为{}", newFilePath0);
fileContent0 = FileUtil.readBytes(newFilePath0);
} catch (Exception e) {
log.error("读取文件失败", e);
}
if (fileContent0 == null) {
log.error("读取文件失败为空");
// fileContent0 = ResourceUtil.readBytes("file/MME_13750602_2024-08-02_system.ini");
} else {
// 上传到文件服务
String preFileName = "45G_";
if (newFilePath0.contains("Legacy_")) {
preFileName = "Legacy_";
}
String fileURL = fileApi.createFile(fileContent0, preFileName + fileName);
fileUrls.add(fileURL);
}
detail.setFileUrl(fileURL);
// 上传到文件服务
byte[] fileContent0 = null;
try {
String newFilePath0 = licenseProviderDO.getNewFilePath0();
log.info("下载Legacy_License文件路径为{}", newFilePath0);
fileContent0 = FileUtil.readBytes(newFilePath0);
} catch (Exception e) {
log.error("读取文件失败", e);
}
if (fileContent0 == null) {
log.error("读取文件失败为空");
fileContent0 = ResourceUtil.readBytes("file/MME_13750602_2024-08-02_system.ini");
}
String fileURL0 = fileApi.createFile(fileContent0, "Legacy_" + fileName);
if (CollUtil.isEmpty(fileUrls)) {
byte[] fileContent = ResourceUtil.readBytes("file/MME_13750602_2024-08-02_system.ini");
String fileURL = fileApi.createFile(fileContent, fileName);
fileUrls.add(fileURL);
}
detail.setFileUrlLegacy(fileURL0);
if (CollUtil.isNotEmpty(fileUrls)) {
detail.setFileUrl(fileUrls.get(0));
}
if (CollUtil.isNotEmpty(fileUrls) && fileUrls.size() > 1) {
detail.setFileUrlLegacy(fileUrls.get(1));
}
licenseDetailMapper.updateById(detail);
}
boolean isCompleted = licenseDetails.stream().allMatch(c -> StrUtil.isNotBlank(c.getFileUrl()));
if (isCompleted) {
if (isCompleted && CollUtil.isNotEmpty(licenseDetails)) {
// 打包压缩上传
List<String> pathList = new ArrayList<>();
List<ByteArrayInputStream> inputStreamList = new ArrayList<>();
@@ -274,23 +301,30 @@ public class LicenseServiceImpl implements LicenseService {
LicenseProviderDO licenseProviderDO = licenseProviderMapper.selectById(detail.getProviderId());
String fileName = getFileName(licenseDO.getSerialNo(), detail.getNeList());
if (StrUtil.isNotBlank(licenseProviderDO.getNewFilePath1())) {
pathList.add("45G_" + fileName);
String preFileName = "45G_";
if (licenseProviderDO.getNewFilePath1().contains("Legacy_")) {
preFileName = "Legacy_";
}
pathList.add(preFileName + fileName);
inputStreamList.add(new ByteArrayInputStream(FileUtil.readBytes(licenseProviderDO.getNewFilePath1())));
} else {
pathList.add("45G_" + fileName);
inputStreamList.add(new ByteArrayInputStream(FileUtil.readBytes("file/MME_13750602_2024-08-02_system.ini")));
}
if (StrUtil.isNotBlank(licenseProviderDO.getNewFilePath0())) {
pathList.add("Legacy_" + fileName);
String preFileName = "45G_";
if (licenseProviderDO.getNewFilePath0().contains("Legacy_")) {
preFileName = "Legacy_";
}
pathList.add(preFileName + fileName);
inputStreamList.add(new ByteArrayInputStream(FileUtil.readBytes(licenseProviderDO.getNewFilePath0())));
} else {
pathList.add("Legacy_" + fileName);
inputStreamList.add(new ByteArrayInputStream(FileUtil.readBytes("file/MME_13750602_2024-08-02_system.ini")));
}
if (StrUtil.isBlank(licenseProviderDO.getNewFilePath0()) && StrUtil.isBlank(licenseProviderDO.getNewFilePath1())) {
pathList.add(fileName);
inputStreamList.add(new ByteArrayInputStream(ResourceUtil.readBytes("file/MME_13750602_2024-08-02_system.ini")));
}
}
File tempFile = new File("D:/temp/temp.zip");
// File tempFile = new File("/usr/local/licGen");
// File tempFile = new File("/usr/local/licGen/temp.zip");
ZipUtil.zip(tempFile, pathList.toArray(new String[0]), inputStreamList.toArray(new ByteArrayInputStream[inputStreamList.size()]));
String fileURL = fileApi.createFile(FileUtil.readBytes(tempFile), licenseDO.getSerialNo() + "_" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))+".zip");