diff --git a/zlt-business/device-center/pom.xml b/zlt-business/device-center/pom.xml index 53e03a10..d928ee12 100644 --- a/zlt-business/device-center/pom.xml +++ b/zlt-business/device-center/pom.xml @@ -94,6 +94,11 @@ org.springframework.boot spring-boot-starter-validation + + cn.hutool + hutool-all + 5.8.25 + diff --git a/zlt-business/device-center/src/main/java/com/central/device/controller/ApiDeviceController.java b/zlt-business/device-center/src/main/java/com/central/device/controller/ApiDeviceController.java index 38259f8b..fffeeab7 100644 --- a/zlt-business/device-center/src/main/java/com/central/device/controller/ApiDeviceController.java +++ b/zlt-business/device-center/src/main/java/com/central/device/controller/ApiDeviceController.java @@ -126,7 +126,6 @@ public class ApiDeviceController { Gson gson = new Gson(); JsonObject jsonObject = gson.fromJson(controlMessageConstant.CONTROL_MESSAGE_MAP.get(control), JsonObject.class); JsonObject data = jsonObject.getAsJsonObject("data"); - // 设置订单信息 data.addProperty("order_no", orderNo); @@ -134,7 +133,7 @@ public class ApiDeviceController { Map wayResult = orderCenterService.getWaylineByOrderNo(orderNo); String waylineFilePath = MapUtil.getStrValue(wayResult, "waylineFilePath"); String waylineId = MapUtil.getStrValue(wayResult, "waylineId"); - + log.info("waylineFilePath:{}, waylineId:{}", waylineFilePath, waylineId); data.addProperty("wayline_link_url", waylineFilePath); LineFile lineFile = lineFileService.findLineFileByWaylineId(waylineId); Assert.notNull(lineFile,"航线文件签名不正确"); diff --git a/zlt-business/device-center/src/main/java/com/central/device/listener/DeviceImportListener.java b/zlt-business/device-center/src/main/java/com/central/device/listener/DeviceImportListener.java index 31131a0b..74a01388 100644 --- a/zlt-business/device-center/src/main/java/com/central/device/listener/DeviceImportListener.java +++ b/zlt-business/device-center/src/main/java/com/central/device/listener/DeviceImportListener.java @@ -28,7 +28,7 @@ public class DeviceImportListener implements ReadListener { validateData(data); // 转换为实体 - AgeDevice device = data.convertToDevice(); + AgeDevice device = data.toDevice(); // 设置默认值 if (device.getCreateTime() == null) { diff --git a/zlt-business/device-center/src/main/java/com/central/device/service/impl/AgeDeviceServiceImpl.java b/zlt-business/device-center/src/main/java/com/central/device/service/impl/AgeDeviceServiceImpl.java index 3cc1a302..68ae00cd 100644 --- a/zlt-business/device-center/src/main/java/com/central/device/service/impl/AgeDeviceServiceImpl.java +++ b/zlt-business/device-center/src/main/java/com/central/device/service/impl/AgeDeviceServiceImpl.java @@ -11,7 +11,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.MapUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import cn.hutool.core.collection.CollUtil; +import org.springframework.util.CollectionUtils; import java.util.List; import java.util.Map; @@ -68,15 +68,18 @@ public class AgeDeviceServiceImpl extends SuperServiceImpl deviceList) { - if (CollUtil.isEmpty(deviceList)) { + if (CollectionUtils.isEmpty(deviceList)) { return false; } try { // 批量保存,每批100条 int batchSize = 100; - List> partition = CollUtil.partition(deviceList, batchSize); - for (List batch : partition) { + int totalSize = deviceList.size(); + + for (int i = 0; i < totalSize; i += batchSize) { + int endIndex = Math.min(i + batchSize, totalSize); + List batch = deviceList.subList(i, endIndex); this.saveBatch(batch, batchSize); } return true; diff --git a/zlt-web/react-web/src/main/frontend/src/pages/device/Device/components/UpdateForm.tsx b/zlt-web/react-web/src/main/frontend/src/pages/device/Device/components/UpdateForm.tsx index d2d5df4f..46cce167 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/device/Device/components/UpdateForm.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/device/Device/components/UpdateForm.tsx @@ -5,28 +5,61 @@ import { ProFormText, ProFormTextArea, } from '@ant-design/pro-components'; -import React from 'react'; +import React, { useEffect } from 'react'; interface UpdateFormProps { onSubmit: (values: DEVICE.Device) => Promise; onVisibleChange: (visible: boolean) => void; updateModalVisible: boolean; values?: DEVICE.Device; + waylineOptions: any[]; + tourismOptions: any[]; } const UpdateForm: React.FC = (props) => { - const { onSubmit, onVisibleChange, updateModalVisible, values } = props; + const { + onSubmit, + onVisibleChange, + updateModalVisible, + values, + waylineOptions, + tourismOptions, + } = props; + + useEffect(() => { + console.log('当前航线选项:', waylineOptions); + console.log('当前表单值:', values); + }, [waylineOptions, values]); return ( + + (option?.label ?? '').toLowerCase().includes(input.toLowerCase()), + }} + /> { const [searchParams, setSearchParams] = useState>({}); const actionRef = useRef(); - const [createModalVisible, setCreateModalVisible] = useState(false); - const [updateModalVisible, setUpdateModalVisible] = useState(false); - const [currentRow, setCurrentRow] = useState(); + const [createModalVisible, handleModalVisible] = useState(false); + const [updateModalVisible, handleUpdateModalVisible] = useState(false); + const [currentRow, setCurrentRow] = useState(); + const [waylineOptions, setWaylineOptions] = useState([]); + const [tourismOptions, setTourismOptions] = useState([]); // 统一的API请求处理函数 const handleRequest = async ( @@ -83,40 +87,104 @@ const TableList: React.FC = () => { } }; - // 处理导出 - const handleExport = async () => { - const hide = message.loading('正在导出...'); - try { - const response = await fetch('/api-device/device/export', { - method: 'POST', - }); - if (response.ok) { - const blob = await response.blob(); - const url = window.URL.createObjectURL(blob); - const link = document.createElement('a'); - link.href = url; - link.download = `设备信息_${moment().format('YYYY-MM-DD')}.xlsx`; - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - window.URL.revokeObjectURL(url); - message.success('导出成功'); - } else { - throw new Error('导出失败'); - } - } catch (error) { - message.error('导出失败'); - } finally { - hide(); - } + // 获取认证token + const getAuthHeader = () => { + // 从sessionStorage中获取token + const token = sessionStorage.getItem('access_token') || localStorage.getItem('access_token'); + return token ? `Bearer ${token}` : ''; }; - // 下载模板 + // 打印token信息用于调试 + console.log('当前token:', { + sessionToken: sessionStorage.getItem('access_token'), + localToken: localStorage.getItem('access_token'), + authHeader: getAuthHeader() + }); + + // 修改导出处理函数 + const handleExport = () => { + // 创建一个隐藏的表单 + const form = document.createElement('form'); + form.method = 'POST'; + form.action = '/api-device/device/export'; + form.style.display = 'none'; + + // 添加token到请求头 + const token = sessionStorage.getItem('access_token'); + if (token) { + const tokenInput = document.createElement('input'); + tokenInput.type = 'hidden'; + tokenInput.name = '_token'; // 添加一个隐藏字段携带token + tokenInput.value = token; + form.appendChild(tokenInput); + } + + document.body.appendChild(form); + form.submit(); + document.body.removeChild(form); + }; + + // 修改模板下载函数 const handleDownloadTemplate = () => { + // 直接通过链接下载模板 window.location.href = '/api-device/device/template'; }; - const columns: ProColumns[] = [ + // 重写获取航线数据的函数 + const loadWaylineOptions = async () => { + try { + const result = await wayline({ + current: 1, + pageSize: 999 // 获取更多数据 + }); + + if (result?.data) { + const options = result.data.map((item: any) => ({ + label: item.name || item.waylineId, + value: item.waylineId + })); + setWaylineOptions(options); + console.log('加载的航线选项:', options); + } + } catch (error) { + console.error('加载航线失败:', error); + message.error('获取航线列表失败'); + } + }; + + // 组件挂载时加载数据 + useEffect(() => { + loadWaylineOptions(); + }, []); + + // 添加操作处理函数 + const handleTableAction = async ( + action: 'add' | 'edit' | 'delete', + record?: ORDERS.Qrcode, + values?: any + ) => { + try { + if (action === 'add') { + await addDevice(values); + message.success('添加成功'); + } else if (action === 'edit') { + await updateDevice({ ...values, id: record?.id }); + message.success('修改成功'); + } else if (action === 'delete') { + await deleteDevice({ id: record?.id }); + message.success('删除成功'); + } + actionRef.current?.reload(); + return true; + } catch (error) { + console.error('操作失败:', error); + message.error('操作失败'); + return false; + } + }; + + // 修改列定义,确保操作列正确显示 + const columns: ProColumns[] = [ { dataIndex: 'index', valueType: 'indexBorder', @@ -184,34 +252,29 @@ const TableList: React.FC = () => { }, { title: '操作', - key: 'action', - render: (_, record) => ( - - { - setCurrentRow(record); - setUpdateModalVisible(true); - }} - > - 修改 - - { - const success = await handleRequest( - () => deleteDevice(record.deviceSn), - '正在删除', - '删除成功' - ); - if (success && actionRef.current) { - actionRef.current.reload(); - } - }} - > - 删除 - - - ), + dataIndex: 'option', + valueType: 'option', + render: (_, record) => [ + { + setCurrentRow(record); + handleUpdateModalVisible(true); + // 立即加载航线数据 + loadWaylineOptions(); + }} + > + 修改 + , + { + handleTableAction('delete', record); + }} + > + 删除 + , + ], }, ]; @@ -265,6 +328,21 @@ const TableList: React.FC = () => { label="设备描述" placeholder="请输入设备描述" /> + + (option?.label ?? '').toLowerCase().includes(input.toLowerCase()), + notFoundContent: waylineOptions.length === 0 ? '暂无数据' : undefined, + }} + /> ); @@ -287,7 +365,7 @@ const TableList: React.FC = () => { /> - + rowKey="deviceSn" headerTitle="设备管理" actionRef={actionRef} @@ -326,7 +404,6 @@ const TableList: React.FC = () => { if (info.file.status === 'done') { if (info.file.response.resp_code === 0) { message.success('导入成功'); - // 刷新表格数据 actionRef.current?.reload(); } else { message.error(info.file.response.resp_msg || '导入失败'); @@ -343,50 +420,73 @@ const TableList: React.FC = () => { , ]} /> - { - const success = await handleRequest( - () => saveOrUpdateDevice(values as DEVICE.Device), - '正在添加', - '添加成功', - ); - if (success) { - setCreateModalVisible(false); - actionRef.current?.reload(); - } - return success; - }} - > - {renderModalContent()} - - { - const success = await handleRequest( - () => saveOrUpdateDevice({ ...currentRow, ...values }), - '正在更新', - '更新成功', - ); - if (success) { - setUpdateModalVisible(false); - setCurrentRow(undefined); - actionRef.current?.reload(); - } - return success; - }} - onVisibleChange={setUpdateModalVisible} - updateModalVisible={updateModalVisible} - values={currentRow} - /> + {updateModalVisible && ( + { + const success = await handleTableAction('edit', currentRow, values); + if (success) { + handleUpdateModalVisible(false); + setCurrentRow(undefined); + } + }} + onVisibleChange={(visible) => { + if (!visible) { + handleUpdateModalVisible(false); + setCurrentRow(undefined); + } + }} + updateModalVisible={updateModalVisible} + values={currentRow} + waylineOptions={waylineOptions} + tourismOptions={tourismOptions} + /> + )} + {createModalVisible && ( + { + if (visible) { + loadWaylineOptions(); + } + handleModalVisible(visible); + }} + modalProps={{ destroyOnClose: true }} + onFinish={async (values) => { + const success = await handleTableAction('add', undefined, values); + if (success) { + handleModalVisible(false); + } + }} + > + + + (option?.label ?? '').toLowerCase().includes(input.toLowerCase()), + }} + /> + {renderModalContent()} + + + )} ); };