From 3793ba4a9b6be8faa6df0d4a76c06763ac03f873 Mon Sep 17 00:00:00 2001
From: zouyu <2723363702@qq.com>
Date: 星期三, 29 十月 2025 15:06:04 +0800
Subject: [PATCH] 外购成品报检相关问题调整
---
cnas-device/src/main/java/com/ruoyi/device/controller/WeightController.java | 65 +++++++++++++++++++++-----------
1 files changed, 42 insertions(+), 23 deletions(-)
diff --git a/cnas-device/src/main/java/com/ruoyi/device/controller/WeightController.java b/cnas-device/src/main/java/com/ruoyi/device/controller/WeightController.java
index 9e6676f..763ac61 100644
--- a/cnas-device/src/main/java/com/ruoyi/device/controller/WeightController.java
+++ b/cnas-device/src/main/java/com/ruoyi/device/controller/WeightController.java
@@ -1,10 +1,14 @@
package com.ruoyi.device.controller;
+import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONArray;
+import com.ruoyi.common.core.domain.Result;
import com.ruoyi.common.utils.RedisUtil;
import com.ruoyi.device.constant.DCResistanceMqttConstants;
import com.ruoyi.device.dto.WeightRequestDto;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -12,37 +16,52 @@
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
+import java.util.Objects;
@RestController
@RequestMapping("/weight")
public class WeightController {
+ @ApiOperation("淇濆瓨鍒嗘瀽澶╁钩璐ㄩ噺鏁版嵁鍒癛edis")
@PostMapping("/handleWeights")
- public ResponseEntity<String> handleWeights(@RequestBody WeightRequestDto weightRequest) {
- try {
- List<Double> weightList = weightRequest.getWeights();
- // 鍦ㄨ繖閲屾坊鍔犳暟鎹鐞嗛�昏緫锛屼緥濡傛墦鍗般�佸瓨鍌ㄥ埌鏁版嵁搴撶瓑
- System.out.println("鎺ユ敹鍒扮殑鏁版嵁: " + weightList);
- processThreeTimesValueDataStream(weightList, WeightRequestDto.DENSITY);
-
- // 澶勭悊鎴愬姛杩斿洖 200 鐘舵�佺爜鍜屾秷鎭�
- return ResponseEntity.ok("鏁版嵁澶勭悊鎴愬姛");
- } catch (Exception e) {
- // 澶勭悊澶辫触杩斿洖 500 鐘舵�佺爜鍜岄敊璇秷鎭�
- return ResponseEntity.internalServerError().body("鏁版嵁澶勭悊澶辫触: " + e.getMessage());
+ public Result<String> handleWeights(@RequestBody WeightRequestDto weightRequest) {
+// try {
+// List<Double> weightList = weightRequest.getWeights();
+// // 鍦ㄨ繖閲屾坊鍔犳暟鎹鐞嗛�昏緫锛屼緥濡傛墦鍗般�佸瓨鍌ㄥ埌鏁版嵁搴撶瓑
+// System.out.println("鎺ユ敹鍒扮殑鏁版嵁: " + weightList);
+// processValueDataStream(weightList, WeightRequestDto.DENSITY);
+//
+// // 澶勭悊鎴愬姛杩斿洖 200 鐘舵�佺爜鍜屾秷鎭�
+// return ResponseEntity.ok("鏁版嵁澶勭悊鎴愬姛");
+// } catch (Exception e) {
+// // 澶勭悊澶辫触杩斿洖 500 鐘舵�佺爜鍜岄敊璇秷鎭�
+// return ResponseEntity.internalServerError().body("鏁版嵁澶勭悊澶辫触: " + e.getMessage());
+// }
+ if(Objects.nonNull(weightRequest) && CollectionUtil.isNotEmpty(weightRequest.getWeights())){
+ List<?> objectList = RedisUtil.lGet(WeightRequestDto.DENSITY, 0, -1);
+ if(CollectionUtil.isNotEmpty(objectList)){
+ // 鍒犻櫎 Redis 涓棫鐨勫垪琛ㄦ暟鎹�
+ RedisUtil.del(WeightRequestDto.DENSITY);
+ // 瀛樺叆鏂扮殑鏁版嵁
+ RedisUtil.lSet(WeightRequestDto.DENSITY, weightRequest.getWeights());
+ }else {
+ RedisUtil.lSet(WeightRequestDto.DENSITY,weightRequest.getWeights());
+ }
+ return Result.success(null,"淇濆瓨鎴愬姛");
}
+ return Result.fail();
}
- private void processThreeTimesValueDataStream(List<Double> weightList, String dataStream) {
- // 澶勭悊 weightList 涓� null 鐨勬儏鍐�
- if (weightList == null) {
- // 鑻� weightList 涓� null锛屽彲閫夋嫨鍒犻櫎 Redis 涓殑瀵瑰簲閿垨瀛樺叆绌烘暟缁勶紝杩欓噷閫夋嫨瀛樺叆绌烘暟缁�
- RedisUtil.set(dataStream, "[]");
- return;
- }
- // 灏� weightList 杞崲涓� JSON 瀛楃涓插苟瀛樺叆 Redis
- String jsonStr = JSONArray.toJSONString(weightList);
- RedisUtil.set(dataStream, jsonStr);
- }
+// private void processValueDataStream(List<Double> weightList, String dataStream) {
+// // 澶勭悊 weightList 涓� null 鐨勬儏鍐�
+// if (weightList == null) {
+// // 鑻� weightList 涓� null锛屽彲閫夋嫨鍒犻櫎 Redis 涓殑瀵瑰簲閿垨瀛樺叆绌烘暟缁勶紝杩欓噷閫夋嫨瀛樺叆绌烘暟缁�
+// RedisUtil.set(dataStream, "[]");
+// return;
+// }
+// // 灏� weightList 杞崲涓� JSON 瀛楃涓插苟瀛樺叆 Redis
+// String jsonStr = JSONArray.toJSONString(weightList);
+// RedisUtil.set(dataStream, jsonStr);
+// }
}
--
Gitblit v1.9.3