fix(订单中心):新版UI订单素材接口逻辑

This commit is contained in:
2025-07-23 18:59:12 +08:00
parent ba5cbc21b9
commit 662518384b
9 changed files with 189 additions and 103 deletions
@@ -723,6 +723,87 @@ public class OrderController {
return new PageResult<>(); return new PageResult<>();
} }
/**
* 新版:查询用户订单详情列表(含视频/图片/一键成片)
*/
@Operation(summary = "新版-查询用户订单详情列表(含视频/图片/一键成片)")
@Parameters({
@Parameter(name = "page",description = "分页起始位置",required = true,in=ParameterIn.QUERY),
@Parameter(name = "limit",description = "分页结束位置",required = true,in=ParameterIn.QUERY)
})
@GetMapping("/user/v2")
public PageResult<Map> listInfoByUserV2(@RequestParam Map<String, Object> params) {
LoginAppUser user = LoginUserContextHolder.getUser();
params.put("userId", user.getId());
List<Integer> orderStatusList = List.of(OrderStatus.COMPLETE.getId(), OrderStatus.UPLOADING.getId(), OrderStatus.UPLOADED.getId());
params.put("orderStatusList", orderStatusList);
PageResult<Order> result = orderService.findListByUser(params);
if (result.getCount() > 0){
List<Map> page = new ArrayList<>();
Map<String, String> fileMap = new HashMap<>();
fileMap.put("style", fileStyle);
for(Order order : result.getData()){
Map<String,Object> orderFileMap = new HashMap<>();
orderFileMap.put("time", sdf.format(order.getCreateTime()));
orderFileMap.put("addr", tourismService.getTourismById(order.getTourismId()).getTourismAddress());
orderFileMap.put("orderNo", order.getOrderNo());
// 只查一次所有文件
List<OrderFile> allFiles = orderFileService.getOrderFileByOrderNo(order.getOrderNo());
// aiVideo
List<OrderFile> aiVideoFiles = allFiles.stream()
.filter(f -> "ai_video".equals(f.getFileTag()))
.toList();
String aiVideoUrl = null;
if (!aiVideoFiles.isEmpty()) {
fileMap.put("path", aiVideoFiles.get(0).getFilePath());
aiVideoUrl = fileCenterService.getViewUrlByPathStyle(fileMap);
}
orderFileMap.put("aiVideo", aiVideoUrl);
// 图片素材
List<OrderFile> imgFiles = allFiles.stream()
.filter(f -> "image/jpeg".equals(f.getFileType()))
.toList();
List<Map<String,String>> imgList = new ArrayList<>();
for (OrderFile orderFile : imgFiles){
Map<String,String> imgMap = new HashMap<>();
String url = fileCenterService.getViewUrlByPath(orderFile.getFilePath());
imgMap.put("url", url.replace(cdnOssUrl, cdnUrl));
imgMap.put("contentType", orderFile.getFileType());
imgMap.put("path", orderFile.getFilePath());
fileMap.put("path",orderFile.getFilePath());
imgMap.put("viewUrl", fileCenterService.getViewUrlByPathStyle(fileMap));
imgList.add(imgMap);
}
orderFileMap.put("imgList", imgList);
// 视频素材
List<OrderFile> videoFiles = allFiles.stream()
.filter(f -> "raw_video".equals(f.getFileTag()))
.toList();
List<Map<String,String>> videoList = new ArrayList<>();
for (OrderFile orderFile : videoFiles){
Map<String,String> videoMap = new HashMap<>();
String url = fileCenterService.getViewUrlByPath(orderFile.getFilePath());
videoMap.put("url", url.replace(cdnOssUrl, cdnUrl));
videoMap.put("contentType", orderFile.getFileType());
videoMap.put("path", orderFile.getFilePath());
fileMap.put("path",orderFile.getFilePath());
videoMap.put("viewUrl", fileCenterService.getViewUrlByPathStyle(fileMap));
videoList.add(videoMap);
}
orderFileMap.put("videoList", videoList);
page.add(orderFileMap);
}
return PageResult.<Map>builder().data(page).resp_code(0).count(result.getCount()).build();
}
return new PageResult<>();
}
/** /**
* 移除URL中的参数 * 移除URL中的参数
* @param url 原始URL * @param url 原始URL
@@ -220,6 +220,10 @@ public class OrderFileController {
orderFile.setFilePath(fileInfo.getPath()); orderFile.setFilePath(fileInfo.getPath());
orderFile.setFileType(fileInfo.getContentType()); orderFile.setFileType(fileInfo.getContentType());
orderFile.setTourismId(order.getTourismId()); orderFile.setTourismId(order.getTourismId());
// 新增:如果是视频素材且未指定fileTag,默认标记为raw_video
if ("video/mp4".equals(orderFile.getFileType()) && (orderFile.getFileTag() == null || orderFile.getFileTag().isEmpty())) {
orderFile.setFileTag("raw_video");
}
// 保存记录 // 保存记录
boolean saved = orderFileService.save(orderFile); boolean saved = orderFileService.save(orderFile);
@@ -14,7 +14,9 @@ public enum HomeCarouselType implements ZltEnum {
ACTIVITY(1, "活动"), ACTIVITY(1, "活动"),
SHOOTING_ANGLE(2,"拍照角度"), SHOOTING_ANGLE(2,"拍照角度"),
GUIDANCE(3,"引导"), GUIDANCE(3,"引导"),
BIG_PICTURE(4,"大图"); BIG_PICTURE(4,"大图"),
VIDEO(5,"景区视频"),
ORDER_SHOW(6,"订单展示图");
private Integer id; private Integer id;
private String content; private String content;
@@ -46,4 +46,8 @@ public class OrderFile extends SuperEntity {
private String tenantId; private String tenantId;
private Integer isDel; private Integer isDel;
/**
* 文件标签,如ai_video、raw_video等
*/
private String fileTag;
} }
@@ -153,6 +153,7 @@ public class VideoEditServiceImpl implements IVideoEditService {
orderFile.setFileId(fileInfo.getId()); orderFile.setFileId(fileInfo.getId());
orderFile.setOrderNo(orderNo); orderFile.setOrderNo(orderNo);
orderFile.setFileType("video/mp4"); orderFile.setFileType("video/mp4");
orderFile.setFileTag("ai_video");
orderFile.setFilePath(extractFilePath(outputUrl)); orderFile.setFilePath(extractFilePath(outputUrl));
orderFile.setUserId(order.getUserId()); orderFile.setUserId(order.getUserId());
orderFile.setTourismId(order.getTourismId()); orderFile.setTourismId(order.getTourismId());
@@ -3,7 +3,8 @@ import { Button, Upload, message } from 'antd';
import { UploadOutlined } from '@ant-design/icons'; import { UploadOutlined } from '@ant-design/icons';
import React, { useState } from 'react'; import React, { useState } from 'react';
import { TYPE_OPTIONS } from '../constants'; import { TYPE_OPTIONS } from '../constants';
import { importImage, saveOrUpdateTourismFile } from '@/services/orders/api'; import { importImage } from '@/services/system/api';
import { saveOrUpdateTourismFile } from '@/services/orders/api';
import type { RcFile } from 'antd/lib/upload'; import type { RcFile } from 'antd/lib/upload';
import styles from '../index.less'; import styles from '../index.less';
@@ -20,7 +21,8 @@ const CreateForm: React.FC<CreateFormProps> = ({
tourismOptions, tourismOptions,
onSuccess, onSuccess,
}) => { }) => {
const [imageUrl, setImageUrl] = useState<string>(); const [fileUrl, setFileUrl] = useState<string>();
const [fileType, setFileType] = useState<number>();
const handleUpload = async (file: RcFile) => { const handleUpload = async (file: RcFile) => {
const hide = message.loading('正在上传'); const hide = message.loading('正在上传');
@@ -29,8 +31,8 @@ const CreateForm: React.FC<CreateFormProps> = ({
formData.append('file', file); formData.append('file', file);
const result = await importImage(formData); const result = await importImage(formData);
hide(); hide();
if (result.name) { if (result.url) {
setImageUrl(result.name); setFileUrl(result.url);
message.success('上传成功'); message.success('上传成功');
} }
} catch (error) { } catch (error) {
@@ -41,20 +43,18 @@ const CreateForm: React.FC<CreateFormProps> = ({
}; };
const handleSubmit = async (values: Record<string, any>) => { const handleSubmit = async (values: Record<string, any>) => {
if (!imageUrl) { if (!fileUrl) {
message.error('请上传素材图片'); message.error('请上传素材文件');
return false; return false;
} }
const hide = message.loading('正在提交'); const hide = message.loading('正在提交');
try { try {
const result = await saveOrUpdateTourismFile({ const result = await saveOrUpdateTourismFile({
...values, ...values,
imageUrl, imageUrl: fileUrl,
status: 0, // 默认启用 status: 0, // 默认启用
}); });
hide(); hide();
if (result.resp_code === 0) { if (result.resp_code === 0) {
message.success('创建成功'); message.success('创建成功');
onSuccess(); onSuccess();
@@ -75,14 +75,12 @@ const CreateForm: React.FC<CreateFormProps> = ({
visible={visible} visible={visible}
onVisibleChange={(visible) => { onVisibleChange={(visible) => {
if (!visible) { if (!visible) {
setImageUrl(undefined); setFileUrl(undefined);
setFileType(undefined);
} }
onVisibleChange(visible); onVisibleChange(visible);
}} }}
modalProps={{ modalProps={{ destroyOnClose: true, maskClosable: false }}
destroyOnClose: true,
maskClosable: false,
}}
onFinish={handleSubmit} onFinish={handleSubmit}
> >
<ProForm.Group> <ProForm.Group>
@@ -96,7 +94,7 @@ const CreateForm: React.FC<CreateFormProps> = ({
showSearch showSearch
fieldProps={{ fieldProps={{
loading: !tourismOptions.length, loading: !tourismOptions.length,
filterOption: (input, option) => filterOption: (input: string, option: any) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()), (option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
}} }}
/> />
@@ -106,7 +104,10 @@ const CreateForm: React.FC<CreateFormProps> = ({
name="type" name="type"
label="素材类型" label="素材类型"
placeholder="请选择素材类型" placeholder="请选择素材类型"
options={TYPE_OPTIONS} options={TYPE_OPTIONS as any}
fieldProps={{
onChange: (val: number) => setFileType(val),
}}
/> />
<ProFormText <ProFormText
width="md" width="md"
@@ -121,36 +122,29 @@ const CreateForm: React.FC<CreateFormProps> = ({
placeholder="请输入素材描述" placeholder="请输入素材描述"
rules={[{ required: true, message: '请输入素材描述' }]} rules={[{ required: true, message: '请输入素材描述' }]}
/> />
<div style={{ width: '100%', marginBottom: 24 }}>
<div style={{ marginBottom: 8 }}> <div style={{ marginBottom: 8 }}>
<span style={{ color: '#666' }}>素材图片:</span> <span style={{ color: '#666' }}>素材文件:</span>
<span style={{ color: '#ff4d4f' }}>*</span> <span style={{ color: '#ff4d4f' }}>*</span>
</div> </div>
{imageUrl && ( {fileUrl && (
<div style={{ marginBottom: 8 }}> <div style={{ marginBottom: 8 }}>
<img {fileType === 5 ? (
src={imageUrl} <video src={fileUrl} controls style={{ maxWidth: '200px', maxHeight: '200px' }} />
alt="preview" ) : (
style={{ <img src={fileUrl} alt="preview" style={{ maxWidth: '200px', maxHeight: '200px', objectFit: 'contain' }} />
maxWidth: '200px', )}
maxHeight: '200px',
objectFit: 'contain'
}}
/>
</div> </div>
)} )}
<Upload <Upload
maxCount={1} maxCount={1}
showUploadList={false} showUploadList={false}
beforeUpload={handleUpload} beforeUpload={handleUpload}
accept="image/*" accept={fileType === 5 ? 'video/*' : 'image/*'}
> >
<Button icon={<UploadOutlined />}> <Button icon={<UploadOutlined />}>
{imageUrl ? '重新上传' : '上传素材'} {fileUrl ? '重新上传' : fileType === 5 ? '上传视频' : '上传图片'}
</Button> </Button>
</Upload> </Upload>
</div>
</ProForm.Group> </ProForm.Group>
</ModalForm> </ModalForm>
); );
@@ -11,6 +11,11 @@ import type { RcFile } from 'antd/lib/upload';
import React, { useState } from 'react'; import React, { useState } from 'react';
import type { TYPE_OPTIONS } from '../constants'; import type { TYPE_OPTIONS } from '../constants';
const STATUS_OPTIONS = [
{ label: '启用', value: 0, color: 'success' },
{ label: '未启用', value: 1, color: 'error' },
] as const;
interface UpdateFormProps { interface UpdateFormProps {
onSubmit: (values: any) => Promise<void>; onSubmit: (values: any) => Promise<void>;
onVisibleChange: (visible: boolean) => void; onVisibleChange: (visible: boolean) => void;
@@ -22,30 +27,26 @@ interface UpdateFormProps {
} }
const UpdateForm: React.FC<UpdateFormProps> = (props) => { const UpdateForm: React.FC<UpdateFormProps> = (props) => {
const [imageUrl, setImageUrl] = useState<string>(); const [fileUrl, setFileUrl] = useState<string>((props.values as any)?.fileUrl || (props.values as any)?.imageUrl || '');
const [imagePath, setImagePath] = useState<string>(); const [fileType, setFileType] = useState<number | undefined>((props.values as any)?.type);
const handleUpload = async (file: RcFile) => { const handleUpload = async (file: RcFile): Promise<boolean> => {
const hide = message.loading('正在上传...'); const hide = message.loading('正在上传');
try { try {
const formData = new FormData(); const formData = new FormData();
formData.append('file', file); formData.append('file', file);
const result = await importImage(formData); const result = await importImage(formData);
hide(); hide();
if (result.url) {
if (result.url && result.path) { setFileUrl(result.url);
message.success('上传成功'); message.success('上传成功');
setImageUrl(result.url);
setImagePath(result.path);
return true; return true;
} }
message.error('上传失败:未获取到文件信息');
return false;
} catch (error) { } catch (error) {
hide(); hide();
message.error('上传失败:' + (error.message || '未知错误')); message.error('上传失败');
return false;
} }
return false;
}; };
return ( return (
@@ -55,13 +56,13 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
onVisibleChange={props.onVisibleChange} onVisibleChange={props.onVisibleChange}
modalProps={{ destroyOnClose: true }} modalProps={{ destroyOnClose: true }}
onFinish={async (values) => { onFinish={async (values) => {
if (imagePath) { if (fileUrl) {
values.imageUrl = imagePath; values.fileUrl = fileUrl;
} }
const success = await props.onSubmit(values); const success = await props.onSubmit(values);
if (success) { if (success) {
setImageUrl(undefined); setFileUrl('');
setImagePath(undefined); setFileType(undefined);
} }
return success; return success;
}} }}
@@ -83,7 +84,10 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
name="type" name="type"
label="素材类型" label="素材类型"
placeholder="请选择素材类型" placeholder="请选择素材类型"
options={props.typeOptions} options={props.typeOptions as any}
fieldProps={{
onChange: (val: number) => setFileType(val),
}}
/> />
<ProFormSelect <ProFormSelect
rules={[{ required: true, message: '请选择状态' }]} rules={[{ required: true, message: '请选择状态' }]}
@@ -91,7 +95,7 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
name="status" name="status"
label="状态" label="状态"
placeholder="请选择状态" placeholder="请选择状态"
options={props.statusOptions} options={STATUS_OPTIONS as any}
/> />
<ProFormText <ProFormText
width="md" width="md"
@@ -105,11 +109,9 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
label="素材描述" label="素材描述"
placeholder="输入描述" placeholder="输入描述"
/> />
<Form.Item label="素材图片" required>
<Upload <Upload
maxCount={1} maxCount={1}
accept="image/*" accept={fileType === 5 ? 'video/*' : 'image/*'}
showUploadList={false} showUploadList={false}
customRequest={async ({ file, onSuccess, onError }) => { customRequest={async ({ file, onSuccess, onError }) => {
try { try {
@@ -118,25 +120,27 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
if (success) { if (success) {
onSuccess?.('ok'); onSuccess?.('ok');
} else { } else {
onError?.(new Error('上传失败')); onError?.(new Error('上传失败') as any);
} }
} }
} catch (error) { } catch (error) {
onError?.(error); onError?.(error as any);
} }
}} }}
> >
<Button icon={<UploadOutlined />}>上传素材</Button> <Button icon={<UploadOutlined />}>
{fileUrl ? '重新上传' : fileType === 5 ? '上传视频' : '上传图片'}
</Button>
</Upload> </Upload>
<div style={{ marginTop: 16 }}> <div style={{ marginTop: 16 }}>
<Image {fileUrl ? (
src={imageUrl || props.values?.imageUrl} fileType === 5 ? (
width={200} <video src={fileUrl} controls style={{ maxWidth: '200px', maxHeight: '200px' }} />
style={{ objectFit: 'cover' }} ) : (
/> <Image src={fileUrl} width={200} style={{ objectFit: 'cover' }} />
)
) : null}
</div> </div>
</Form.Item>
</ProForm.Group> </ProForm.Group>
</ModalForm> </ModalForm>
); );
@@ -1,5 +1,7 @@
// 将常量配置抽离到单独文件 // 将常量配置抽离到单独文件
export const TYPE_OPTIONS = [ export const TYPE_OPTIONS = [
{ label: '景区视频', value: 5 },
{ label: '景区订单展示图', value: 6 },
{ label: '展示大图', value: 4 }, { label: '展示大图', value: 4 },
{ label: '拍照引导图', value: 3 }, { label: '拍照引导图', value: 3 },
{ label: '拍照角度展示图', value: 2 }, { label: '拍照角度展示图', value: 2 },
@@ -17,4 +19,6 @@ export const TYPE_CONFIG = {
2: { color: '#13c2c2', text: '拍照角度' }, // 青色 2: { color: '#13c2c2', text: '拍照角度' }, // 青色
3: { color: '#722ed1', text: '引导' }, // 紫色 3: { color: '#722ed1', text: '引导' }, // 紫色
4: { color: '#52c41a', text: '大图' }, // 绿色 4: { color: '#52c41a', text: '大图' }, // 绿色
5: { color: '#f5222d', text: '景区视频' }, // 红色
6: { color: '#2f54eb', text: '订单展示图' }, // 蓝色
} as const; } as const;
@@ -14,7 +14,7 @@ import {
import { Typography, Popconfirm, Space, message, Image, Button, Tag, Upload, Spin } from 'antd'; import { Typography, Popconfirm, Space, message, Image, Button, Tag, Upload, Spin } from 'antd';
import type { RcFile } from 'antd/lib/upload'; import type { RcFile } from 'antd/lib/upload';
import React, { useRef, useState, useCallback, useEffect } from 'react'; import React, { useRef, useState, useCallback, useEffect } from 'react';
import { STATUS_CONFIG, TYPE_CONFIG } from './constants'; import { STATUS_CONFIG, TYPE_CONFIG, TYPE_OPTIONS } from './constants';
import CreateForm from './components/CreateForm'; import CreateForm from './components/CreateForm';
import UpdateForm from './components/UpdateForm'; import UpdateForm from './components/UpdateForm';
import SearchForm from './components/SearchForm'; import SearchForm from './components/SearchForm';
@@ -28,14 +28,6 @@ const STATUS_OPTIONS = [
{ label: '未启用', value: 1, color: 'error' }, { label: '未启用', value: 1, color: 'error' },
] as const; ] as const;
// 类型常量
const TYPE_OPTIONS = [
{ label: '展示大图', value: 4, color: 'blue' },
{ label: '拍照引导图', value: 3, color: 'green' },
{ label: '拍照角度展示图', value: 2, color: 'cyan' },
{ label: '活动', value: 1, color: 'orange' },
] as const;
// 状态映射 // 状态映射
const statusColorMap = { const statusColorMap = {
0: { color: 'green', text: '启用' }, 0: { color: 'green', text: '启用' },