From 27c18a19c5889d5d03746d7add01eef02d3a78d9 Mon Sep 17 00:00:00 2001 From: Iamasoldier <1272745473@qq.com> Date: Tue, 11 Feb 2025 14:54:17 +0800 Subject: [PATCH] =?UTF-8?q?feat[=E6=99=AF=E5=8C=BA=E7=AE=A1=E7=90=86]:?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86=E7=95=8C=E9=9D=A2=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=99=AF=E5=8C=BA=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=EF=BC=8C=E4=BB=A5=E5=8F=8A=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=AD=89=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/controller/OrderController.java | 14 +- .../order/controller/TourismController.java | 19 +- .../com/central/order/enums/FileType.java | 41 +++ .../order/service/ITourismService.java | 3 +- .../service/impl/TourismServiceImpl.java | 10 +- .../central/order/util/ContentTypeUtil.java | 29 ++ .../src/main/frontend/config/routes.ts | 4 + .../src/pages/orders/OrderFile/index.tsx | 6 +- .../orders/Tourism/components/UpdateForm.tsx | 69 +++++ .../src/pages/orders/Tourism/index.less | 1 + .../src/pages/orders/Tourism/index.tsx | 259 ++++++++++++++++++ .../main/frontend/src/services/orders/api.ts | 27 +- .../frontend/src/services/orders/typings.d.ts | 17 +- 13 files changed, 464 insertions(+), 35 deletions(-) create mode 100644 zlt-business/order-center/src/main/java/com/central/order/enums/FileType.java create mode 100644 zlt-business/order-center/src/main/java/com/central/order/util/ContentTypeUtil.java create mode 100644 zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/components/UpdateForm.tsx create mode 100644 zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/index.less create mode 100644 zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/index.tsx 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 d4ec36a6..fb55580b 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 @@ -16,6 +16,7 @@ import com.central.order.service.IOrderFileService; import com.central.order.service.IOrderService; import com.central.order.service.IQrCodeService; import com.central.order.service.ITourismService; +import com.central.order.util.ContentTypeUtil; import com.wechat.pay.java.core.exception.ServiceException; import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension; import com.wechat.pay.java.service.payments.jsapi.model.*; @@ -141,18 +142,7 @@ public class OrderController { Map imgMap = new HashMap<>(); String url = fileCenterService.getViewUrlByName(orderFile.getFilePath()); imgMap.put("url", url.replace(cdnOssUrl,cdnUrl)); - //@TODO 待优化file_type获取方式 - if (url != null && !"".equals(url) ){ - if (url.contains(".jpeg")){ - imgMap.put("contentType", "image/jpeg"); - }else if (url.contains(".png")){ - imgMap.put("contentType", "image/png"); - }else if (url.contains(".gif")){ - imgMap.put("contentType", "image/gif"); - }else if (url.contains(".mp4")){ - imgMap.put("contentType", "video/mp4"); - } - } + imgMap.put("contentType", ContentTypeUtil.getContentTypeFromUrl(url)); resultList.add(imgMap); } } diff --git a/zlt-business/order-center/src/main/java/com/central/order/controller/TourismController.java b/zlt-business/order-center/src/main/java/com/central/order/controller/TourismController.java index 7c1ec216..a370d51d 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/controller/TourismController.java +++ b/zlt-business/order-center/src/main/java/com/central/order/controller/TourismController.java @@ -45,16 +45,9 @@ public class TourismController { return tourismService.findList(params); } - @Operation(summary = "创建Tourism") - @PostMapping - public Result createTourism(@RequestBody Tourism tourism) { - - boolean result = tourismService.createTourism(tourism); - if (result) { - return Result.succeed(tourism,"jq创建成功"); - } else { - return Result.failed("jq创建失败"); - } + @PostMapping() + public Result saveOrUpdate(@RequestBody Tourism tourism) { + return tourismService.saveOrUpdateTourism(tourism); } @Operation(summary = "查询Tourism") @@ -67,4 +60,10 @@ public class TourismController { return Result.succeed(tourism,"获取成功"); } + @DeleteMapping() +// @AuditLog(operation = "'新增或更新用户:' + #sysUser.username") + public Result delete(@RequestBody Tourism tourism) { + boolean result = tourismService.removeById(tourism); + return result ? Result.succeed(tourism, "操作成功") : Result.failed("操作失败"); + } } diff --git a/zlt-business/order-center/src/main/java/com/central/order/enums/FileType.java b/zlt-business/order-center/src/main/java/com/central/order/enums/FileType.java new file mode 100644 index 00000000..c93dd7fe --- /dev/null +++ b/zlt-business/order-center/src/main/java/com/central/order/enums/FileType.java @@ -0,0 +1,41 @@ +package com.central.order.enums; + +public enum FileType { + JPEG("image/jpeg", ".jpeg", ".jpg"), + PNG("image/png", ".png"), + GIF("image/gif", ".gif"), + MP4("video/mp4", ".mp4"); + + private final String contentType; + private final String[] extensions; + + FileType(String contentType, String... extensions) { + this.contentType = contentType; + this.extensions = extensions; + } + + public String getContentType() { + return contentType; + } + + public String[] getExtensions() { + return extensions; + } + + /** + * 根据文件扩展名获取对应的 FileType + * + * @param extension 文件扩展名 + * @return 对应的 FileType,如果不支持则返回 null + */ + public static FileType fromExtension(String extension) { + for (FileType type : values()) { + for (String ext : type.getExtensions()) { + if (ext.equalsIgnoreCase(extension)) { + return type; + } + } + } + return null; + } +} diff --git a/zlt-business/order-center/src/main/java/com/central/order/service/ITourismService.java b/zlt-business/order-center/src/main/java/com/central/order/service/ITourismService.java index 92c148e5..d63fc9d3 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/service/ITourismService.java +++ b/zlt-business/order-center/src/main/java/com/central/order/service/ITourismService.java @@ -1,6 +1,7 @@ package com.central.order.service; import com.central.common.model.PageResult; +import com.central.common.model.Result; import com.central.common.service.ISuperService; import com.central.order.model.Tourism; @@ -26,7 +27,7 @@ public interface ITourismService extends ISuperService { * @param tourism * @return */ - boolean createTourism(Tourism tourism) ; + Result saveOrUpdateTourism(Tourism tourism) ; /** * id查询 diff --git a/zlt-business/order-center/src/main/java/com/central/order/service/impl/TourismServiceImpl.java b/zlt-business/order-center/src/main/java/com/central/order/service/impl/TourismServiceImpl.java index 80a230cf..982ebcaf 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/service/impl/TourismServiceImpl.java +++ b/zlt-business/order-center/src/main/java/com/central/order/service/impl/TourismServiceImpl.java @@ -2,6 +2,7 @@ package com.central.order.service.impl; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.central.common.model.PageResult; +import com.central.common.model.Result; import com.central.common.service.impl.SuperServiceImpl; import com.central.order.mapper.TourismMapper; import com.central.order.model.Tourism; @@ -36,12 +37,9 @@ public class TourismServiceImpl extends SuperServiceImpl } @Override - public boolean createTourism(Tourism tourism) { - int result = baseMapper.insert(tourism); - if(result > 0){ - return true; - } - return false; + public Result saveOrUpdateTourism(Tourism tourism) { + boolean result = saveOrUpdate(tourism); + return result ? Result.succeed(tourism, "操作成功") : Result.failed("操作失败"); } @Override diff --git a/zlt-business/order-center/src/main/java/com/central/order/util/ContentTypeUtil.java b/zlt-business/order-center/src/main/java/com/central/order/util/ContentTypeUtil.java new file mode 100644 index 00000000..4f298455 --- /dev/null +++ b/zlt-business/order-center/src/main/java/com/central/order/util/ContentTypeUtil.java @@ -0,0 +1,29 @@ +package com.central.order.util; + +import com.central.order.enums.FileType; + +public class ContentTypeUtil { + + /** + * 根据 URL 的文件扩展名获取对应的 contentType + * + * @param url 文件的 URL + * @return 包含 contentType 的 Map,如果 URL 为空或不包含支持的扩展名,返回空的 Map + */ + public static String getContentTypeFromUrl(String url) { + + if (url != null && !url.isEmpty()) { + // 获取文件扩展名 + int lastDotIndex = url.lastIndexOf('.'); + if (lastDotIndex != -1) { + String extension = url.substring(lastDotIndex); + FileType fileType = FileType.fromExtension(extension); + if (fileType != null) { + return fileType.getContentType(); + } + } + } + + return FileType.JPEG.getContentType(); + } +} 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 c3616f7e..057a21eb 100644 --- a/zlt-web/react-web/src/main/frontend/config/routes.ts +++ b/zlt-web/react-web/src/main/frontend/config/routes.ts @@ -57,6 +57,10 @@ { path: '/orders/orderFiles.html', component: './orders/OrderFile', + }, + { + path: '/orders/tourism.html', + component: './orders/Tourism', } ], }, 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 0dc18a5f..8f15825e 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 @@ -11,7 +11,7 @@ import React, { useRef, useState } from 'react'; const { Link } = Typography; -const handleDelete = async (deletefile: ORDERS.orderFile) => { +const handleDelete = async (deletefile: ORDERS.OrderFile) => { const hide = message.loading('正在删除'); try { const result = await deleteFile(deletefile.id); @@ -33,7 +33,7 @@ const handleDelete = async (deletefile: ORDERS.orderFile) => { const TableList: React.FC = () => { const actionRef = useRef(); const [params, setParams] = useState>({ }); - const columns: ProColumns[] = [ + const columns: ProColumns[] = [ { dataIndex: 'index', valueType: 'indexBorder', @@ -94,7 +94,7 @@ const TableList: React.FC = () => { > - + rowKey="id" headerTitle="任务列表" request={orderFiles} diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/components/UpdateForm.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/components/UpdateForm.tsx new file mode 100644 index 00000000..9452b0f8 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/components/UpdateForm.tsx @@ -0,0 +1,69 @@ +import { + ModalForm, + ProForm, + ProFormText, +} from '@ant-design/pro-components'; +import { Form } from 'antd'; + +export type FormValueType = Partial; + +export type UpdateFormProps = { + onVisibleChange: (flag: boolean) => void; + onSubmit: (values: FormValueType) => Promise; + updateModalVisible: boolean; + values?: ORDERS.Tourism; +}; + +const UpdateForm: React.FC = (props) => { + const [form] = Form.useForm(); + return ( + + + + + + + + ); +}; + +export default UpdateForm; diff --git a/zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/index.less b/zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/index.less new file mode 100644 index 00000000..8d289828 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/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/Tourism/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/index.tsx new file mode 100644 index 00000000..2ca57454 --- /dev/null +++ b/zlt-web/react-web/src/main/frontend/src/pages/orders/Tourism/index.tsx @@ -0,0 +1,259 @@ +import UpdateForm from '@/pages/orders/Tourism/components/UpdateForm'; +import { tourism, saveOrUpdateTourism, deleteTourism } from '@/services/orders/api'; +import { PlusOutlined } from '@ant-design/icons'; +import type { ActionType, ProColumns } from '@ant-design/pro-components'; +import { + ModalForm, + PageContainer, + ProForm, + ProFormText, + ProTable, + QueryFilter, +} from '@ant-design/pro-components'; +import { Typography, message, Popconfirm, Button, Space } from 'antd'; +import React, { useRef, useState } from 'react'; + +const { Link } = Typography; + +const handleAdd = async (fields: ORDERS.Tourism) => { + const hide = message.loading('正在添加'); + try { + const result = await saveOrUpdateTourism({ ...fields }); + hide(); + if (result.resp_code === 0) { + message.success('添加用户成功'); + return true; + } else { + message.error(result.resp_msg); + return false; + } + } catch (error) { + hide(); + message.error('添加用户失败'); + return false; + } +}; + +const handleEdit = async (fields: ORDERS.Tourism) => { + const hide = message.loading('正在更新'); + try { + const result = await saveOrUpdateTourism({ ...fields }); + hide(); + if (result.resp_code === 0) { + message.success('修改景区成功'); + return true; + } else { + message.error(result.resp_msg); + return false; + } + } catch (error) { + hide(); + message.error('修改景区失败'); + return false; + } +}; +const handleDelete = async (tourism: ORDERS.Tourism) => { + const hide = message.loading('正在删除'); + try { + const result = await deleteTourism(tourism.id); + hide(); + if (result.resp_code === 0) { + message.success('删除景区成功'); + return true; + } else { + message.error(result.resp_msg); + return false; + } + } catch (error) { + hide(); + message.error('删除景区失败'); + return false; + } +}; + +const TableList: React.FC = () => { + const [params, setParams] = useState>({}); + const actionRef = useRef(); + const [createModalVisible, handleModalVisible] = useState(false); + const [updateModalVisible, handleUpdateModalVisible] = useState(false); + const [currentRow, setCurrentRow] = useState(); + const columns: ProColumns[] = [ + { + dataIndex: 'index', + valueType: 'indexBorder', + }, + { + title: 'ID', + dataIndex: 'id', + }, + { + title: '编号', + dataIndex: 'tourismNo', + }, + { + title: '名称', + dataIndex: 'tourismName', + }, + { + title: '地址', + dataIndex: 'tourismAddress', + }, + { + title: '联系电话', + dataIndex: 'tourismPhone', + }, + { + title: '状态', + dataIndex: 'status', + }, + { + title: '创建时间', + dataIndex: 'createTime', + valueType: 'dateTime', + }, + { + title: '操作', + key: 'action', + render: (_, entity) => + + { + setCurrentRow(entity); + handleUpdateModalVisible(true); + }} + > + 修改 + + { + const success = await handleDelete(entity); + if (success) { + if (actionRef.current) { + actionRef.current.reload(); + } + } + }} + > + 删除 + + + }, + ]; + + return ( + + setParams(values)} + > + + + + rowKey="id" + headerTitle="景区列表" + request={tourism} + actionRef={actionRef} + columns={columns} + search={false} + params={params} + pagination={{ + showSizeChanger: true, + showQuickJumper: true, + }} + toolBarRender={() => [ + <> + + , + ]} + /> + { + + const success = await handleAdd(values); + if (success) { + handleModalVisible(false); + if (actionRef.current) { + actionRef.current.reload(); + } + } + }} + > + + + + + + + { + if (currentRow) { + + const success = await handleEdit({ ...currentRow, ...values }); + if (success) { + handleUpdateModalVisible(false); + if (actionRef.current) { + actionRef.current.reload(); + } + } + setCurrentRow(undefined); + } + }} + onVisibleChange={handleUpdateModalVisible} + updateModalVisible={updateModalVisible} + values={currentRow} + /> + + + ); +}; + +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 e5e6bcff..a818b3c4 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 @@ -21,9 +21,34 @@ export async function deleteFile(id: number) { export async function orderFiles(params?: { [key: string]: string | number }) { const { current, pageSize, ...rest } = params ?? {}; - const result = await request>('/api-order/files', { + const result = await request>('/api-order/files', { method: 'GET', params: { page: current, limit: pageSize, ...rest }, }); return { data: result.data, total: result.count }; +} + +export async function tourism(params?: { [key: string]: string | number }) { + const { current, pageSize, ...rest } = params ?? {}; + const result = await request>('/api-order/tourism', { + method: 'GET', + params: { page: current, limit: pageSize, ...rest }, + }); + return { data: result.data, total: result.count }; +} + +export async function saveOrUpdateTourism(data: ORDERS.Tourism): Promise> { + const result = await request>('/api-order/tourism', { + method: 'POST', + data, + }); + return result; +} + +export async function deleteTourism(id: number) { + const url = `/api-order/tourism/${id}`; + const result = await request>(url, { + method: 'DELETE', + }); + return result; } \ 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 4d2744f6..2abab5ff 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 @@ -12,15 +12,28 @@ declare namespace ORDERS { updateTime?: string; } - type orderFile = { + type OrderFile = { id: number; userId: string; fileId: string; filePath: string; orderNo: string; - file_type: string; + fileType: string; createTime?: string; tenantId?: string; updateTime?: string; } + + type Tourism = { + id: number; + tourismName: string; + tourismDesc: string; + tourismNo: string; + tourismAddress: string; + tourismPhone: string; + createTime?: string; + status: number; + tenantId?: string; + updateTime?: string; + } } \ No newline at end of file