|
@@ -0,0 +1,74 @@
|
|
|
+package com.pig4cloud.pig.marketing.controller;
|
|
|
+
|
|
|
+
|
|
|
+import com.pig4cloud.pig.common.core.util.R;
|
|
|
+import com.pig4cloud.pig.marketing.api.mongo.Device;
|
|
|
+import com.pig4cloud.pig.marketing.api.mongo.Message;
|
|
|
+import com.pig4cloud.pig.marketing.repository.service.DeviceService;
|
|
|
+import com.pig4cloud.pig.marketing.repository.service.MessageService;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: lwh
|
|
|
+ * @date: 2025-08-27
|
|
|
+ * @description: TCP数据控制器
|
|
|
+ */
|
|
|
+
|
|
|
+@RestController
|
|
|
+@AllArgsConstructor
|
|
|
+@RequestMapping("/tcp")
|
|
|
+@Tag(description = "TcpData", name = "TCP数据上报服务")
|
|
|
+@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
|
|
+public class TcpDataController {
|
|
|
+ @Autowired
|
|
|
+ private MessageService messageService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DeviceService deviceService;
|
|
|
+
|
|
|
+ /************************* 设备 *************************
|
|
|
+ * 保存或更新设备信息
|
|
|
+ */
|
|
|
+ @PostMapping("/device/save")
|
|
|
+ @Operation(summary = "保存或更新设备信息")
|
|
|
+ public R<String> saveOrUpdateDevice(@RequestBody Device device) {
|
|
|
+ deviceService.saveOrUpdateDevice(device);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据clientID查询设备信息
|
|
|
+ */
|
|
|
+ @GetMapping("/device/get/{clientID}")
|
|
|
+ @Operation(summary = "根据客户端ID查询设备信息")
|
|
|
+ public R<Device> getDevice(@PathVariable String clientID) {
|
|
|
+ return R.ok(deviceService.getDeviceByClientID(clientID));
|
|
|
+ }
|
|
|
+
|
|
|
+ /************************* 消息 *************************
|
|
|
+ * 保存消息
|
|
|
+ */
|
|
|
+ @PostMapping("/msg/save")
|
|
|
+ @Operation(summary = "保存上报数据")
|
|
|
+ public R<String> saveMessage(@RequestBody Message message) {
|
|
|
+ messageService.saveMessage(message);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据clientID查询消息列表
|
|
|
+ */
|
|
|
+ @GetMapping("/msg/get/{clientID}")
|
|
|
+ @Operation(summary = "根据客户端ID查询数据列表")
|
|
|
+ public R<List<Message>> getMessagesByClient(@PathVariable String clientID) {
|
|
|
+ return R.ok(messageService.getMessagesByClientID(clientID));
|
|
|
+ }
|
|
|
+}
|