Merge pull request !64 from 鸭先知/test
This commit is contained in:
+24
-9
@@ -2,6 +2,7 @@ package com.central.order.controller;
|
||||
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.utils.StringUtils;
|
||||
import com.central.order.feign.FileCenterService;
|
||||
import com.central.order.model.*;
|
||||
import com.central.order.service.IOrderService;
|
||||
@@ -25,11 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -127,16 +124,34 @@ public class QrCodeController {
|
||||
Assert.notNull(qrCode,"QRCODE不能为空");
|
||||
Tourism tourism = tourismService.getTourismById(qrCode.getTourismId());
|
||||
Assert.notNull(tourism,"TOURISM数据不能为空");
|
||||
List<TourismFile> tourismFiles = tourismFileService.getByTourismId(qrCode.getTourismId());
|
||||
if (!CollectionUtils.isEmpty(tourismFiles)) {
|
||||
for (TourismFile tourismFile: tourismFiles) {
|
||||
tourismFile.setImageUrl(fileCenterService.getViewUrlByPath(tourismFile.getImageUrl()));
|
||||
tourism.setTourismName(StringUtils.isEmpty(qrCode.getName())?tourism.getTourismName():qrCode.getName());
|
||||
tourism.setTourismDesc(StringUtils.isEmpty(qrCode.getQrDescribe())?tourism.getTourismDesc():qrCode.getQrDescribe());
|
||||
//根据codeId获取套餐
|
||||
List<PackagePlan> list = packagePlanService.getByCodeId(codeId);
|
||||
List<TourismFile> tourismFiles = new ArrayList<>();
|
||||
if(!CollectionUtils.isEmpty(list)){
|
||||
PackagePlan plan = list.get(0);
|
||||
String fileIds = plan.getTourismFileIds();
|
||||
if(fileIds!=null){
|
||||
List<Long> fileIdsList = Arrays.stream(fileIds.split(","))
|
||||
.map(String::trim) // 去除空格
|
||||
.filter(s -> !s.isEmpty()) // 过滤空字符串
|
||||
.map(Long::parseLong)
|
||||
.collect(Collectors.toList());
|
||||
for (Long fileId: fileIdsList ){
|
||||
TourismFile tourismFile = tourismFileService.getById(fileId);
|
||||
if(Objects.nonNull(tourismFile)){
|
||||
tourismFile.setImageUrl(fileCenterService.getViewUrlByPath(tourismFile.getImageUrl()));
|
||||
tourismFiles.add(tourismFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QrCodeVO qrCodeVO = new QrCodeVO();
|
||||
qrCodeVO.setCodeId(codeId);
|
||||
qrCodeVO.setTourism(tourism);
|
||||
qrCodeVO.setTourismFiles(tourismFiles);
|
||||
// qrCodeVO.setQrCode(qrCode);
|
||||
return Result.succeed(qrCodeVO,"获取成功");
|
||||
}
|
||||
|
||||
|
||||
@@ -117,4 +117,7 @@ public class QrCode extends SuperEntity {
|
||||
@Schema(description = "是否只显示一键成片(0:否,1:是)")
|
||||
private Integer showVideoEditOnly;
|
||||
|
||||
@Schema(description = "描述")
|
||||
private String qrDescribe;
|
||||
|
||||
}
|
||||
|
||||
@@ -22,5 +22,6 @@ public class QrCodeVO {
|
||||
private String codeId;
|
||||
private Tourism tourism;
|
||||
private List<TourismFile> tourismFiles;
|
||||
// private QrCode qrCode;
|
||||
|
||||
}
|
||||
|
||||
@@ -300,9 +300,77 @@ const OrderResourcesModal: React.FC<OrderResourcesModalProps> = ({ visible, reco
|
||||
|
||||
} catch (error) {
|
||||
console.error(`❌ ZIP 打包失败:`, error);
|
||||
message.error('打包下载失败,请重试');
|
||||
removeDownloadProgress('batch_all');
|
||||
} finally {
|
||||
|
||||
// 判断错误类型并给出提示
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
if (errorMessage.includes('CORS') || errorMessage.includes('Failed to fetch')) {
|
||||
message.error('ZIP打包失败:跨域问题,请使用"分别下载"功能');
|
||||
} else {
|
||||
message.error('打包下载失败,文件可能过大,建议使用"分别下载"');
|
||||
}
|
||||
setBatchDownloading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 批量分别下载(备用方案)- 使用 iframe 避免 CORS
|
||||
const handleBatchDownloadSeparately = async () => {
|
||||
if (!record?.orderNo) {
|
||||
return;
|
||||
}
|
||||
|
||||
const orderNo = record.orderNo;
|
||||
console.log(`📦 开始分别下载: ${orderNo}`);
|
||||
message.info('正在分别下载所有文件,请查看浏览器下载列表');
|
||||
|
||||
try {
|
||||
let successCount = 0;
|
||||
let failureCount = 0;
|
||||
|
||||
// 获取所有文件的下载URL
|
||||
for (let i = 0; i < resources.length; i++) {
|
||||
const file = resources[i];
|
||||
try {
|
||||
if (!file.fileId) {
|
||||
failureCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
const downloadUrl = await ordersApi.getFileDownloadUrl(file.fileId);
|
||||
if (downloadUrl) {
|
||||
// 使用 iframe 触发下载
|
||||
setTimeout(() => {
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.style.display = 'none';
|
||||
iframe.src = downloadUrl;
|
||||
document.body.appendChild(iframe);
|
||||
|
||||
// 5秒后移除 iframe
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(iframe);
|
||||
}, 5000);
|
||||
}, i * 100); // 每个文件间隔 100ms
|
||||
|
||||
successCount++;
|
||||
console.log(`✅ 触发下载: ${file.fileId}`);
|
||||
} else {
|
||||
failureCount++;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(`⚠️ 获取下载链接失败: ${file.fileId}`, error);
|
||||
failureCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// 延迟显示完成消息
|
||||
setTimeout(() => {
|
||||
message.success(`✅ 分别下载已启动!成功: ${successCount} 个,失败: ${failureCount} 个`);
|
||||
setBatchDownloading(false);
|
||||
}, resources.length * 100 + 500);
|
||||
|
||||
} catch (error) {
|
||||
console.error(`❌ 分别下载失败:`, error);
|
||||
message.error('下载失败,请重试');
|
||||
setBatchDownloading(false);
|
||||
}
|
||||
};
|
||||
@@ -627,13 +695,23 @@ const OrderResourcesModal: React.FC<OrderResourcesModalProps> = ({ visible, reco
|
||||
关闭
|
||||
</Button>,
|
||||
<Button
|
||||
key="batch-download"
|
||||
key="separate-download"
|
||||
type="primary"
|
||||
icon={<DownloadOutlined />}
|
||||
loading={batchDownloading}
|
||||
disabled={resources.length === 0 || loading || batchDownloading}
|
||||
onClick={handleBatchDownloadSeparately}
|
||||
title="分别下载所有文件(推荐用于大文件)"
|
||||
>
|
||||
{batchDownloading ? '下载中...' : '分别下载'}
|
||||
</Button>,
|
||||
<Button
|
||||
key="zip-download"
|
||||
icon={<FileZipOutlined />}
|
||||
loading={batchDownloading}
|
||||
disabled={resources.length === 0 || loading || batchDownloading}
|
||||
onClick={handleBatchDownload}
|
||||
title={batchDownloading ? `正在打包下载中...` : '批量下载为ZIP'}
|
||||
title="打包为ZIP下载(适合小文件,大文件可能导致浏览器崩溃)"
|
||||
>
|
||||
{batchDownloading ? (() => {
|
||||
const batchProgress = Array.from(downloadingFiles.values()).find(
|
||||
@@ -642,8 +720,8 @@ const OrderResourcesModal: React.FC<OrderResourcesModalProps> = ({ visible, reco
|
||||
if (batchProgress) {
|
||||
return `打包中... ${batchProgress.progress}%`;
|
||||
}
|
||||
return `打包中... ${batchDownloadProgress}%`;
|
||||
})() : '批量下载'}
|
||||
return `打包中...`;
|
||||
})() : '打包ZIP'}
|
||||
</Button>,
|
||||
]}
|
||||
>
|
||||
|
||||
@@ -29,6 +29,7 @@ export interface QrcodeItem {
|
||||
videoCount?: number;
|
||||
photoCount?: number;
|
||||
tourismFileIds?: number[];
|
||||
qrDescribe?: string;
|
||||
}
|
||||
export interface QrcodeFormProps {
|
||||
open: boolean;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { ModalForm, ProForm, ProFormDigit, ProFormSelect, ProFormText } from '@ant-design/pro-components';
|
||||
import { ModalForm, ProForm, ProFormDigit, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-components';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
import { deviceApi } from '@/services/device';
|
||||
import { miniAppApi } from '@/services/miniapp';
|
||||
@@ -26,6 +26,7 @@ const QrcodeTourismForm: React.FC<QrcodeTourismFormProps> = ({ open, title, init
|
||||
vlogCount: 0,
|
||||
videoCount: 0,
|
||||
photoCount: 0,
|
||||
qrDescribe: '', // 描述
|
||||
};
|
||||
|
||||
// 过滤 initialValues 中的 undefined,避免覆盖默认值
|
||||
@@ -250,6 +251,18 @@ const QrcodeTourismForm: React.FC<QrcodeTourismFormProps> = ({ open, title, init
|
||||
colProps={{ span: 12 }}
|
||||
/>
|
||||
|
||||
<ProFormTextArea
|
||||
name="qrDescribe"
|
||||
label="描述"
|
||||
placeholder="请输入二维码描述"
|
||||
fieldProps={{
|
||||
rows: 3,
|
||||
showCount: true,
|
||||
maxLength: 500,
|
||||
}}
|
||||
colProps={{ span: 24 }}
|
||||
/>
|
||||
|
||||
{/* 注册一个隐藏字段以提交素材ID数组 */}
|
||||
<ProForm.Item name="tourismFileIds" hidden>
|
||||
<div />
|
||||
|
||||
Reference in New Issue
Block a user