Kaynağa Gözat

修改监测数据,新增前端分页

余思翰 1 hafta önce
ebeveyn
işleme
884c277af4

+ 7
- 3
cmc-temperature-back/cmc-monitoring/src/main/java/com/ruoyi/monitoring/controller/CmcTemperatureController.java Dosyayı Görüntüle

@@ -65,7 +65,8 @@ public class CmcTemperatureController extends BaseController {
65 65
         QueryWrapper qw = getQW(cmcTemperature, Info);
66 66
         List<CmcTemperature> records = cmcTemperatureService.list(qw);
67 67
         List<CmcTemperature> temperatureList = new ArrayList<>();
68
-        if (records.size() > 2) {
68
+        int total = 0;
69
+        if (records.size() > 0) {
69 70
             long diffInMillis;
70 71
             // 第30条与第31条数据时间差 毫秒
71 72
             if (channelSize > 30) {
@@ -102,14 +103,17 @@ public class CmcTemperatureController extends BaseController {
102 103
                     }
103 104
                 }
104 105
             }
106
+            total = temperatureList.size() / channelSize;
105 107
             if (temperatureList.size() >= page.getPageSize()) {
106
-                if (page.getPageNumber() > 1)
108
+                if (page.getPageNumber() > 1) {
109
+                    temperatureList.subList((int) (page.getPageSize() * (page.getPageNumber())), temperatureList.size()).clear();
107 110
                     temperatureList.subList(0, (int) (page.getPageSize() * (page.getPageNumber() - 1))).clear();
111
+                }
108 112
                 else
109 113
                     temperatureList.subList((int) page.getPageSize(), temperatureList.size()).clear();
110 114
             }
111 115
         }
112
-        return getPageData(temperatureList).total(temperatureList.size() / channelSize);
116
+        return getPageData(temperatureList).total(total);
113 117
     }
114 118
 
115 119
     /**

+ 123
- 32
cmc-temperature-ui/src/views/temperature/temMonitor.vue Dosyayı Görüntüle

@@ -84,12 +84,18 @@
84 84
                     </el-table-column>
85 85
                   </el-table>
86 86
                 </div>
87
+                <!-- 分页 -->
88
+                <div class="pagination-container">
89
+                  <el-pagination background v-model:current-page="queryParams.pageNumber"
90
+                    v-model:page-size="queryParams.pageSize" :total="totalCount" layout="total, prev, pager, next"
91
+                    @current-change="handleCurrentChange" />
92
+                </div>
87 93
               </el-tab-pane>
88 94
 
89 95
               <!-- 分析图表标签页 -->
90 96
               <el-tab-pane label="分析图表" name="chart">
91 97
                 <div class="chart-container">
92
-                  <TemperatureChart ref="chartRef" :chart-data="tableData" :sensor-columns="sensorColumns" />
98
+                  <TemperatureChart ref="chartRef" :chart-data="chartData" :sensor-columns="chartSensorColumns" />
93 99
                 </div>
94 100
               </el-tab-pane>
95 101
             </el-tabs>
@@ -97,11 +103,6 @@
97 103
         </div>
98 104
       </el-card>
99 105
     </div>
100
-    <!-- 分页 -->
101
-    <div class="pagination-container">
102
-      <el-pagination v-model:current-page="queryParams.pageNumber" v-model:page-size="queryParams.pageSize"
103
-        :total="totalCount" layout="total, prev, pager, next, jumper" @current-change="handleCurrentChange" />
104
-    </div>
105 106
   </div>
106 107
 </template>
107 108
 
@@ -109,7 +110,7 @@
109 110
 import { ref, reactive, computed, onMounted, nextTick } from 'vue'
110 111
 import { ElMessage } from 'element-plus'
111 112
 import { Search, Refresh, Download } from '@element-plus/icons-vue'
112
-import { listTemperature, listByInfo } from '@/api/monitoring/temperature'
113
+import { listTemperature, listByInfo, listAllByInfo } from '@/api/monitoring/temperature'
113 114
 import { listChannel, channelInfoList } from '@/api/monitoring/channel'
114 115
 import TemperatureChart from './TemperatureChart.vue'
115 116
 
@@ -144,7 +145,11 @@ const hasData = computed(() => {
144 145
 // 表格数据相关
145 146
 const tableData = ref([])
146 147
 const sensorColumns = ref([])
147
-const tableList = ref([])
148
+
149
+// 图表数据相关
150
+const chartData = ref([])
151
+const chartSensorColumns = ref([])
152
+const allDataList = ref([])
148 153
 
149 154
 const getDeviceList = () => {
150 155
   channelInfoList().then(res => {
@@ -156,9 +161,51 @@ const getDeviceList = () => {
156 161
 }
157 162
 getDeviceList()
158 163
 
159
-// 处理表格数据,按sensorNo分组
164
+// 处理图表数据,使用全部数据
165
+const processChartData = (dataList) => {
166
+  if (!dataList || dataList.length === 0) {
167
+    chartData.value = []
168
+    chartSensorColumns.value = []
169
+    return
170
+  }
171
+
172
+  // 获取所有唯一的传感器编号和对应的设备信息
173
+  const sensorMap = new Map()
174
+  dataList.forEach(item => {
175
+    if (!sensorMap.has(item.sensorNo)) {
176
+      sensorMap.set(item.sensorNo, {
177
+        sensorNo: item.sensorNo,
178
+        sensorName: item.channel?.info || `传感器${item.sensorNo}`
179
+      })
180
+    }
181
+  })
182
+
183
+  // 生成传感器列配置
184
+  chartSensorColumns.value = Array.from(sensorMap.values()).sort((a, b) => a.sensorNo - b.sensorNo)
185
+
186
+  // 按时间分组数据
187
+  const timeGroups = {}
188
+  dataList.forEach(item => {
189
+    if (!timeGroups[item.datetime]) {
190
+      timeGroups[item.datetime] = {
191
+        datetime: item.datetime,
192
+        ...chartSensorColumns.value.reduce((acc, sensor) => {
193
+          acc[sensor.sensorName] = null
194
+          return acc
195
+        }, {})
196
+      }
197
+    }
198
+    const sensorName = item.channel?.info || `传感器${item.sensorNo}`
199
+    timeGroups[item.datetime][sensorName] = item.data
200
+  })
201
+
202
+  // 转换为数组并排序
203
+  chartData.value = Object.values(timeGroups)
204
+}
205
+
206
+// 处理表格数据,使用全部数据并进行前端分页
160 207
 const processTableData = () => {
161
-  if (!tableList.value || tableList.value.length === 0) {
208
+  if (!allDataList.value || allDataList.value.length === 0) {
162 209
     tableData.value = []
163 210
     sensorColumns.value = []
164 211
     return
@@ -166,7 +213,7 @@ const processTableData = () => {
166 213
 
167 214
   // 获取所有唯一的传感器编号和对应的设备信息
168 215
   const sensorMap = new Map()
169
-  tableList.value.forEach(item => {
216
+  allDataList.value.forEach(item => {
170 217
     if (!sensorMap.has(item.sensorNo)) {
171 218
       sensorMap.set(item.sensorNo, {
172 219
         sensorNo: item.sensorNo,
@@ -180,7 +227,7 @@ const processTableData = () => {
180 227
 
181 228
   // 按时间分组数据
182 229
   const timeGroups = {}
183
-  tableList.value.forEach(item => {
230
+  allDataList.value.forEach(item => {
184 231
     if (!timeGroups[item.datetime]) {
185 232
       timeGroups[item.datetime] = {
186 233
         datetime: item.datetime,
@@ -193,42 +240,82 @@ const processTableData = () => {
193 240
     const sensorName = item.channel?.info || `传感器${item.sensorNo}`
194 241
     timeGroups[item.datetime][sensorName] = item.data
195 242
   })
196
-
243
+  
197 244
   // 转换为数组并排序
198
-  tableData.value = Object.values(timeGroups)
245
+  const allTableData = Object.values(timeGroups)
246
+
247
+  // 前端分页处理
248
+  const startIndex = (queryParams.value.pageNumber - 1) * queryParams.value.pageSize
249
+  const endIndex = startIndex + queryParams.value.pageSize
250
+  tableData.value = allTableData.slice(startIndex, endIndex)
199 251
 }
200 252
 
201 253
 const handleCurrentChange = (page) => {
202 254
   queryParams.value.pageNumber = page
203
-  console.log(queryParams.value)
204
-  // handleSearch()
255
+  // 前端分页,直接重新处理表格数据
256
+  processTableData()
205 257
 }
206 258
 
207 259
 // 查询监控数据
208 260
 const handleSearch = async () => {
209
-  loading.value = true
210
-  try {
211
-    // 验证表单
212
-    if (!searchForm.timeRange || searchForm.timeRange.length === 0) {
213
-      ElMessage.warning('请选择时间范围')
214
-      return
215
-    }
216
-    if (!searchForm.Info || searchForm.Info.trim() === '') {
217
-      ElMessage.warning('请选择查询条件')
261
+  // 验证表单
262
+  if (!searchForm.timeRange || searchForm.timeRange.length === 0) {
263
+    ElMessage.warning('请选择时间范围')
264
+    return
265
+  }
266
+  if (!searchForm.Info || searchForm.Info.trim() === '') {
267
+    ElMessage.warning('请选择查询条件')
268
+    return
269
+  }
270
+
271
+  // 检查时间范围是否超过31天
272
+  const startDate = new Date(searchForm.timeRange[0])
273
+  const endDate = new Date(searchForm.timeRange[1])
274
+  const daysDiff = Math.ceil((endDate - startDate) / (1000 * 60 * 60 * 24)) + 1
275
+
276
+  if (daysDiff > 31) {
277
+    // 使用 Element Plus 的确认对话框
278
+    const { ElMessageBox } = await import('element-plus')
279
+    try {
280
+      await ElMessageBox.confirm(
281
+        '查询超过1个月,数据量过大,可能会导致卡顿或崩溃,是否继续?',
282
+        '查询确认',
283
+        {
284
+          confirmButtonText: '继续查询',
285
+          cancelButtonText: '取消',
286
+          type: 'warning',
287
+        }
288
+      )
289
+    } catch (error) {
290
+      // 用户点击取消
218 291
       return
219 292
     }
293
+  }
294
+
295
+  loading.value = true
296
+  queryParams.value.pageNumber = 1
297
+  try {
220 298
     let startTime = searchForm.timeRange[0] + ' 00:00:00'
221 299
     let endTime = searchForm.timeRange[1] + ' 23:59:59'
222
-    const res = await listByInfo({
300
+
301
+    // 使用 listAllByInfo 获取全部数据
302
+    const allDataRes = await listAllByInfo({
223 303
       startTime: startTime,
224 304
       endTime: endTime,
225
-      Info: searchForm.Info,
226
-      ...queryParams.value
305
+      Info: searchForm.Info
227 306
     })
228
-    totalCount.value = res.total
229
-    tableList.value = res.list
230 307
 
231
-    // 处理数据,生成表格数据
308
+    // 为图表和表格准备全部数据
309
+    const allData = allDataRes.list || allDataRes
310
+    totalCount.value = Number(allDataRes.total)
311
+
312
+    // 存储全部数据
313
+    allDataList.value = allData
314
+
315
+    // 处理全部数据,生成图表数据
316
+    processChartData(allData)
317
+
318
+    // 处理全部数据,生成表格数据(前端分页)
232 319
     processTableData()
233 320
 
234 321
     ElMessage.success('查询成功')
@@ -245,9 +332,13 @@ const handleReset = () => {
245 332
   searchForm.timeRange = []
246 333
   searchForm.Info = ''
247 334
   totalCount.value = 0
248
-  tableList.value = []
249 335
   tableData.value = []
250 336
   sensorColumns.value = []
337
+  chartData.value = []
338
+  chartSensorColumns.value = []
339
+  allDataList.value = []
340
+  // 重置分页参数
341
+  queryParams.value.pageNumber = 1
251 342
   ElMessage.info('已重置搜索条件')
252 343
 }
253 344
 

Loading…
İptal
Kaydet