diff --git a/zlt-business/file-center/src/main/java/com/central/file/controller/FileController.java b/zlt-business/file-center/src/main/java/com/central/file/controller/FileController.java index c5501187..7b7992a9 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/controller/FileController.java +++ b/zlt-business/file-center/src/main/java/com/central/file/controller/FileController.java @@ -6,6 +6,7 @@ import com.central.common.model.Result; import com.central.file.service.IFileService; import com.central.file.utils.HexToJpeg; import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.collections.MapUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.*; import org.springframework.util.LinkedMultiValueMap; @@ -81,11 +82,16 @@ public class FileController { return fileService.getViewUrl(id); } - @PostMapping("/files/name") - public String getViewUrlByName(@RequestBody String name) { + @GetMapping("/files/name") + public String getViewUrlByName(@RequestParam String name) { return fileService.getViewUrlByName(name); } + @GetMapping("/files/name/style") + public String getViewUrlByNameStyle(@RequestParam Map params) { + return fileService.getZipViewUrlByName(MapUtils.getString(params,"name"),MapUtils.getString(params, "style")); + } + @GetMapping("/type/{id}") public String getFileInfo(@PathVariable String id) { FileInfo fileInfo = fileService.getFileInfo(id); diff --git a/zlt-business/file-center/src/main/java/com/central/file/service/IFileService.java b/zlt-business/file-center/src/main/java/com/central/file/service/IFileService.java index c1c02bf4..485965d4 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/service/IFileService.java +++ b/zlt-business/file-center/src/main/java/com/central/file/service/IFileService.java @@ -29,6 +29,8 @@ public interface IFileService extends IService { String getViewUrlByName(String name); + String getZipViewUrlByName(String name, String style); + FileInfo getFileInfo(String id); FileInfo createFile(String path); diff --git a/zlt-business/file-center/src/main/java/com/central/file/service/impl/CosService.java b/zlt-business/file-center/src/main/java/com/central/file/service/impl/CosService.java index 52b46bf3..222d23aa 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/service/impl/CosService.java +++ b/zlt-business/file-center/src/main/java/com/central/file/service/impl/CosService.java @@ -54,6 +54,11 @@ public class CosService extends AbstractIFileService { return ""; } + @Override + public String getZipViewUrlByName(String name, String style) { + return ""; + } + @Override public void out(String id, OutputStream os) { FileInfo fileInfo = baseMapper.selectById(id); diff --git a/zlt-business/file-center/src/main/java/com/central/file/service/impl/FastdfsService.java b/zlt-business/file-center/src/main/java/com/central/file/service/impl/FastdfsService.java index 47fa25d5..31540c65 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/service/impl/FastdfsService.java +++ b/zlt-business/file-center/src/main/java/com/central/file/service/impl/FastdfsService.java @@ -50,6 +50,11 @@ public class FastdfsService extends AbstractIFileService { return ""; } + @Override + public String getZipViewUrlByName(String name, String style) { + return ""; + } + @Override public void out(String id, OutputStream os) { } diff --git a/zlt-business/file-center/src/main/java/com/central/file/service/impl/OssService.java b/zlt-business/file-center/src/main/java/com/central/file/service/impl/OssService.java index a5e4469f..37743808 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/service/impl/OssService.java +++ b/zlt-business/file-center/src/main/java/com/central/file/service/impl/OssService.java @@ -80,6 +80,11 @@ public class OssService extends AbstractIFileService { } + @Override + public String getZipViewUrlByName(String name, String style) { + return ossTemplate.getViewUrl(name,style); + } + @Override public FileInfo getFileInfo(String id) { return baseMapper.findById(id); diff --git a/zlt-business/file-center/src/main/java/com/central/file/service/impl/S3Service.java b/zlt-business/file-center/src/main/java/com/central/file/service/impl/S3Service.java index 62ee00bf..e3d5ec9c 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/service/impl/S3Service.java +++ b/zlt-business/file-center/src/main/java/com/central/file/service/impl/S3Service.java @@ -55,6 +55,11 @@ public class S3Service extends AbstractIFileService { return ""; } + @Override + public String getZipViewUrlByName(String name, String style) { + return ""; + } + @Override public void out(String id, OutputStream os) { FileInfo fileInfo = baseMapper.selectById(id); diff --git a/zlt-business/order-center/src/main/java/com/central/order/controller/OrderController.java b/zlt-business/order-center/src/main/java/com/central/order/controller/OrderController.java index fb55580b..73cb37b4 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/controller/OrderController.java +++ b/zlt-business/order-center/src/main/java/com/central/order/controller/OrderController.java @@ -1,6 +1,8 @@ package com.central.order.controller; +import com.central.common.constant.CommonConstant; import com.central.common.context.LoginUserContextHolder; +import com.central.common.context.TenantContextHolder; import com.central.common.model.LoginAppUser; import com.central.common.model.PageResult; import com.central.common.model.Result; @@ -74,12 +76,15 @@ public class OrderController { @Autowired private TencentPayProperties tencentPayProperties; - @Value("${cdn.oss-url}") + @Value("${file.oss-url}") private String cdnOssUrl; - @Value("${cdn.url}") + @Value("${file.cdn-url}") private String cdnUrl; + @Value("${file.style}") + private String fileStyle; + /** * 列表 */ @@ -125,11 +130,13 @@ public class OrderController { params.put("userId", user.getId()); // 获取当前日期,格式化为 yyyyMMdd - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + SimpleDateFormat sdf = new SimpleDateFormat(CommonConstant.DATEMINUTE_FORMAT); PageResult result = orderService.findListByUser(params); if (result.getCount() > 0){ List page = new ArrayList<>(); + Map fileMap = new HashMap<>(); + fileMap.put("style", fileStyle); for(Order order : result.getData()){ Map orderFileMap = new HashMap<>(); orderFileMap.put("time", sdf.format(order.getCreateTime())); @@ -143,6 +150,9 @@ public class OrderController { String url = fileCenterService.getViewUrlByName(orderFile.getFilePath()); imgMap.put("url", url.replace(cdnOssUrl,cdnUrl)); imgMap.put("contentType", ContentTypeUtil.getContentTypeFromUrl(url)); + + fileMap.put("name",orderFile.getFilePath()); + imgMap.put("viewUrl", fileCenterService.getViewUrlByNameStyle(fileMap)); resultList.add(imgMap); } } @@ -167,9 +177,13 @@ public class OrderController { public Result createOrder(@RequestBody Order order) { LoginAppUser user = LoginUserContextHolder.getUser(); + //@TODO 设置价格逻辑优化 order.setOrderAmount("1990"); order.setUserId(user.getId()); + order.setTenantId(TenantContextHolder.getTenant()); + + //景区唯一二维码codeId,该二维码中包含价格信息 if (order.getCodeId() == null){ order.setCodeId("f83be3a9-2888-4000-8cf9-e6acdb3a22cd"); } diff --git a/zlt-business/order-center/src/main/java/com/central/order/controller/OrderFileController.java b/zlt-business/order-center/src/main/java/com/central/order/controller/OrderFileController.java index 15c7a3a2..23dd5c78 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/controller/OrderFileController.java +++ b/zlt-business/order-center/src/main/java/com/central/order/controller/OrderFileController.java @@ -18,9 +18,11 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -46,6 +48,9 @@ public class OrderFileController { @Autowired private IOrderService orderService; + @Value("${file.style}") + private String fileStyle; + /** * 列表 */ @@ -56,7 +61,17 @@ public class OrderFileController { }) @GetMapping public PageResult list(@RequestParam Map params) { - return orderFileService.findList(params); + PageResult pageResult = orderFileService.findList(params); + Map fileMap = new HashMap<>(); + fileMap.put("style", fileStyle); + if (pageResult.getResp_code() == 0){ + for (OrderFile orderFile: pageResult.getData()){ + orderFile.setViewUrl(fileCenterService.getViewUrlByName(orderFile.getFilePath())); + fileMap.put("name", orderFile.getFilePath()); + orderFile.setZipViewUrl(fileCenterService.getViewUrlByNameStyle(fileMap)); + } + } + return pageResult; } /** diff --git a/zlt-business/order-center/src/main/java/com/central/order/feign/FileCenterService.java b/zlt-business/order-center/src/main/java/com/central/order/feign/FileCenterService.java index 2e30e849..aaf459b4 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/feign/FileCenterService.java +++ b/zlt-business/order-center/src/main/java/com/central/order/feign/FileCenterService.java @@ -5,10 +5,7 @@ import com.central.common.model.FileInfo; import com.central.common.model.Result; import com.central.order.feign.fallback.FileCenterServiceFallbackFactory; import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.*; import java.util.Map; @@ -41,6 +38,9 @@ public interface FileCenterService { @PostMapping("/path") FileInfo creatFileInfo(@RequestBody String path); - @PostMapping("/files/name") - String getViewUrlByName(@RequestBody String name) ; + @GetMapping("/files/name") + String getViewUrlByName(@RequestParam("name") String name) ; + + @GetMapping("/files/name/style") + String getViewUrlByNameStyle(@RequestParam("params") Map params) ; } diff --git a/zlt-business/order-center/src/main/java/com/central/order/feign/fallback/FileCenterServiceFallbackFactory.java b/zlt-business/order-center/src/main/java/com/central/order/feign/fallback/FileCenterServiceFallbackFactory.java index 975a5447..33ed8d3c 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/feign/fallback/FileCenterServiceFallbackFactory.java +++ b/zlt-business/order-center/src/main/java/com/central/order/feign/fallback/FileCenterServiceFallbackFactory.java @@ -50,6 +50,11 @@ public class FileCenterServiceFallbackFactory implements FallbackFactory params) { + return ""; + } + }; } } diff --git a/zlt-business/order-center/src/main/java/com/central/order/model/OrderFile.java b/zlt-business/order-center/src/main/java/com/central/order/model/OrderFile.java index a16aaad5..1dfe97e5 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/model/OrderFile.java +++ b/zlt-business/order-center/src/main/java/com/central/order/model/OrderFile.java @@ -29,6 +29,9 @@ public class OrderFile extends SuperEntity { private Long userId; private transient String viewUrl; + + //文件缩略图 + private transient String zipViewUrl; // 景区ID private Long tourismId; diff --git a/zlt-business/order-center/src/main/resources/application.yml b/zlt-business/order-center/src/main/resources/application.yml index 6abb07f7..b2261618 100644 --- a/zlt-business/order-center/src/main/resources/application.yml +++ b/zlt-business/order-center/src/main/resources/application.yml @@ -42,9 +42,10 @@ tencent: appSecret: ${zlt.security.tencent.app-secret} accessTokenUrl: ${zlt.security.tencent.accessTokenUrl} getwxacodeUrl: https://api.weixin.qq.com/wxa/getwxacode?access_token= -cdn: +file: oss-url: goflyapp.oss-cn-beijing.aliyuncs.com - url: cdn.goflytec.com + cdn-url: cdn.goflytec.com + style: image/resize,m_fixed,w_100,h_90 #审计日志 # audit-log: # enabled: true diff --git a/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/CommonConstant.java b/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/CommonConstant.java index f7004656..211d46fe 100644 --- a/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/CommonConstant.java +++ b/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/CommonConstant.java @@ -94,6 +94,7 @@ public interface CommonConstant { */ String MONTH_FORMAT = "yyyy-MM"; String DATE_FORMAT = "yyyy-MM-dd"; + String DATEMINUTE_FORMAT = "yyyy-MM-dd HH:mm"; String DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; String SIMPLE_MONTH_FORMAT = "yyyyMM"; String SIMPLE_DATE_FORMAT = "yyyyMMdd"; diff --git a/zlt-commons/zlt-oss-spring-boot-starter/src/main/java/com/central/oss/template/OssTemplate.java b/zlt-commons/zlt-oss-spring-boot-starter/src/main/java/com/central/oss/template/OssTemplate.java index 73203904..44986346 100644 --- a/zlt-commons/zlt-oss-spring-boot-starter/src/main/java/com/central/oss/template/OssTemplate.java +++ b/zlt-commons/zlt-oss-spring-boot-starter/src/main/java/com/central/oss/template/OssTemplate.java @@ -1,7 +1,9 @@ package com.central.oss.template; +import com.aliyun.oss.HttpMethod; import com.aliyun.oss.OSS; import com.aliyun.oss.OSSClientBuilder; +import com.aliyun.oss.model.GeneratePresignedUrlRequest; import com.aliyun.oss.model.OSSObject; import com.aliyun.oss.model.ObjectMetadata; import com.aliyun.oss.model.PutObjectRequest; @@ -134,6 +136,24 @@ public class OssTemplate implements InitializingBean { return url.toString(); } + /** + * 获取缩略图预览地址 + * @param objectName 对象名 + * @return + */ + public String getViewUrl(String objectName,String style) { + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.MINUTE, 7); + if (style == null) { + style = "image/resize,m_fixed,w_100,h_90"; // 默认缩略图样式 + } + GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(fileProperties.getOss().getBucketName(), objectName, HttpMethod.GET); + req.setProcess(style); + req.setExpiration(cal.getTime()); + URL url = ossClient.generatePresignedUrl(req); + return url.toString(); + } + /** * 获取预览地址 * @param objectName 对象名 diff --git a/zlt-web/react-web/src/main/frontend/config/routes.ts b/zlt-web/react-web/src/main/frontend/config/routes.ts index 057a21eb..f3a2cdf5 100644 --- a/zlt-web/react-web/src/main/frontend/config/routes.ts +++ b/zlt-web/react-web/src/main/frontend/config/routes.ts @@ -61,6 +61,10 @@ { path: '/orders/tourism.html', component: './orders/Tourism', + }, + { + path: '/orders/qrcode.html', + component: './orders/Qrcode', } ], }, diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/Order/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/Order/index.tsx index e4c01dc5..9be1310c 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/orders/Order/index.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/Order/index.tsx @@ -6,7 +6,7 @@ import { ProTable, QueryFilter, } from '@ant-design/pro-components'; -import { Typography, message, Popconfirm } from 'antd'; +import { Typography, message, Popconfirm, Tag } from 'antd'; import React, { useRef, useState } from 'react'; const { Link } = Typography; @@ -30,6 +30,20 @@ const { Link } = Typography; // } // }; +// 状态颜色映射 +const statusColorMap = { + 0: { color: 'yellow', text: '待处理' }, + 1: { color: 'orange', text: '待处理' }, + 3: { color: 'green', text: '已完成' }, + 2: { color: 'red', text: '已取消' }, +}; + +// 渲染状态标签 +const renderStatus = (status: {} | null | undefined) => { + const statusInfo = statusColorMap[status] || { color: 'gray', text: '未知状态' }; + return {statusInfo.text}; +}; + const TableList: React.FC = () => { const actionRef = useRef(); const [params, setParams] = useState>({ }); @@ -49,6 +63,7 @@ const TableList: React.FC = () => { { title: '状态', dataIndex: 'orderStatus', + render: (status) => renderStatus(status), }, { title: '创建时间', diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/OrderFile/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/OrderFile/index.tsx index 8f15825e..423d5efd 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/orders/OrderFile/index.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/OrderFile/index.tsx @@ -6,7 +6,7 @@ import { ProTable, QueryFilter, } from '@ant-design/pro-components'; -import { Typography, message, Popconfirm } from 'antd'; +import { Typography, message, Popconfirm, Image } from 'antd'; import React, { useRef, useState } from 'react'; const { Link } = Typography; @@ -30,6 +30,8 @@ const handleDelete = async (deletefile: ORDERS.OrderFile) => { } }; +const imagePreviewTypes = ['image/jpeg', 'image/png', 'image/gif']; // 可预览的图片类型 + const TableList: React.FC = () => { const actionRef = useRef(); const [params, setParams] = useState>({ }); @@ -47,8 +49,27 @@ const TableList: React.FC = () => { dataIndex: 'fileId', }, { - title: '文件路径', - dataIndex: 'filePath', + title: '文件', + dataIndex: 'zipViewUrl', + render: (zipViewUrl, entity) => ( + <> + {imagePreviewTypes.includes(entity.fileType) ? ( + + ) : ( + + 下载文件 + + )} + + 预览原图 + + + ), }, { title: '文件类型', diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/Qrcode/index.less b/zlt-web/react-web/src/main/frontend/src/pages/orders/Qrcode/index.less new file mode 100644 index 00000000..8d289828 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/Qrcode/index.less @@ -0,0 +1 @@ +@import (reference) '~antd/es/style/themes/index'; diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/Qrcode/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/Qrcode/index.tsx new file mode 100644 index 00000000..39826af6 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/Qrcode/index.tsx @@ -0,0 +1,121 @@ +import { qrcode } from '@/services/orders/api'; +import type { ActionType, ProColumns } from '@ant-design/pro-components'; +import { + PageContainer, + ProFormText, + ProTable, + QueryFilter, +} from '@ant-design/pro-components'; +import { Typography, Popconfirm } from 'antd'; +import React, { useRef, useState } from 'react'; + +const { Link } = Typography; + +// const handleDelete = async (deletefile: FILES.File) => { +// const hide = message.loading('正在删除'); +// try { +// const result = await deleteFile(deletefile.id); +// hide(); +// if (result.resp_code === 0) { +// message.success('删除File成功'); +// return true; +// } else { +// message.error(result.resp_msg); +// return false; +// } +// } catch (error) { +// hide(); +// message.error('删除File失败'); +// return false; +// } +// }; + +const TableList: React.FC = () => { + const actionRef = useRef(); + const [params, setParams] = useState>({ }); + const columns: ProColumns[] = [ + { + dataIndex: 'index', + valueType: 'indexBorder', + }, + { + title: 'ID', + dataIndex: 'id', + }, + { + title: 'CodeID', + dataIndex: 'codeId', + }, + { + title: '景区ID', + dataIndex: 'tourismId', + }, + { + title: '文件路径', + dataIndex: 'path', + }, + { + title: '文件ID', + dataIndex: 'fileId', + }, + { + title: '设备SN', + dataIndex: 'deviceSn', + }, + { + title: '状态', + dataIndex: 'status', + }, + { + title: '创建时间', + dataIndex: 'createTime', + valueType: 'dateTime', + }, + { + title: '操作', + key: 'action', + render: (_, entity) => { + // const success = await handleDelete(entity); + // if (success) { + // if (actionRef.current) { + // actionRef.current.reload(); + // } + // } + }} + > + 删除 + , + }, + ]; + + return ( + + setParams(values)} + > + + + + rowKey="id" + headerTitle="二维码列表" + request={qrcode} + actionRef={actionRef} + columns={columns} + search={false} + params={params} + pagination={{ + showSizeChanger: true, + showQuickJumper: true, + }} + /> + + ); +}; + +export default TableList; diff --git a/zlt-web/react-web/src/main/frontend/src/services/orders/api.ts b/zlt-web/react-web/src/main/frontend/src/services/orders/api.ts index a818b3c4..b93c15f3 100644 --- a/zlt-web/react-web/src/main/frontend/src/services/orders/api.ts +++ b/zlt-web/react-web/src/main/frontend/src/services/orders/api.ts @@ -51,4 +51,13 @@ export async function deleteTourism(id: number) { method: 'DELETE', }); return result; +} + +export async function qrcode(params?: { [key: string]: string | number }) { + const { current, pageSize, ...rest } = params ?? {}; + const result = await request>('/api-order/qrcode', { + method: 'GET', + params: { page: current, limit: pageSize, ...rest }, + }); + return { data: result.data, total: result.count }; } \ No newline at end of file diff --git a/zlt-web/react-web/src/main/frontend/src/services/orders/typings.d.ts b/zlt-web/react-web/src/main/frontend/src/services/orders/typings.d.ts index 2abab5ff..e98702ae 100644 --- a/zlt-web/react-web/src/main/frontend/src/services/orders/typings.d.ts +++ b/zlt-web/react-web/src/main/frontend/src/services/orders/typings.d.ts @@ -17,6 +17,8 @@ declare namespace ORDERS { userId: string; fileId: string; filePath: string; + viewUrl: string; + zipViewUrl: string; orderNo: string; fileType: string; createTime?: string; @@ -36,4 +38,18 @@ declare namespace ORDERS { tenantId?: string; updateTime?: string; } + + type Qrcode = { + id: number; + codeId: string; + tourismId: string; + path: string; + fileId: string; + deviceSn: string; + createTime?: string; + status: number; + tenantId?: string; + updateTime?: string; + } + } \ No newline at end of file