| | |
| | | |
| | | |
| | | 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; |
| | |
| | | public class WeightController { |
| | | |
| | | @PostMapping("/handleWeights") |
| | | public ResponseEntity<String> handleWeights(@RequestBody WeightRequestDto weightRequest) { |
| | | try { |
| | | public Result handleWeights(@RequestBody WeightRequestDto weightRequest) { |
| | | 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()); |
| | | } |
| | | return Result.success(); |
| | | } |
| | | |
| | | private void processValueDataStream(List<Double> weightList, String dataStream) { |
| | | // 处理 weightList 为 null 的情况 |
| | | if (weightList == null) { |