DeviceController.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package com.zswl.dataservice.controller.hardware;
  2. import com.zswl.dataservice.model.mqtt.DeviceInfoAddParam;
  3. import com.zswl.dataservice.model.mqtt.DeviceInfoModel;
  4. import com.zswl.dataservice.model.mqtt.DeviceInfoSearchParam;
  5. import com.zswl.dataservice.service.mqtt.DeviceInfoService;
  6. import com.zswl.dataservice.utils.result.ResultContent;
  7. import io.swagger.v3.oas.annotations.Operation;
  8. import io.swagger.v3.oas.annotations.Parameter;
  9. import io.swagger.v3.oas.annotations.tags.Tag;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.data.domain.Page;
  12. import org.springframework.data.domain.Pageable;
  13. import org.springframework.data.web.PageableDefault;
  14. import org.springframework.util.Assert;
  15. import org.springframework.validation.annotation.Validated;
  16. import org.springframework.web.bind.annotation.RequestBody;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RequestMethod;
  19. import org.springframework.web.bind.annotation.RestController;
  20. /**
  21. * 设备管理 服务
  22. *
  23. * @author TRX
  24. * @date 2024/3/21
  25. */
  26. @RequestMapping("/device/free")
  27. @RestController
  28. @Validated
  29. @Tag(name = "设备管理")
  30. public class DeviceController {
  31. @Autowired
  32. DeviceInfoService deviceInfoService;
  33. @Operation(summary = "添加设备")
  34. @RequestMapping(value = "addDeviceInfo", method = {RequestMethod.POST})
  35. public ResultContent addDeviceInfo(@RequestBody DeviceInfoAddParam param) {
  36. Assert.hasText(param.getDeviceId(), "设备ID不能为空");
  37. Assert.hasText(param.getDeviceName(), "设备名称不能为空");
  38. return deviceInfoService.addDeviceInfo(param);
  39. }
  40. @Operation(summary = "设备列表-分页查询")
  41. @RequestMapping(value = {"pageActivity"}, method = {RequestMethod.POST})
  42. public ResultContent<Page<DeviceInfoModel>> pageActivity(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable, @Parameter(required = false) DeviceInfoSearchParam param) {
  43. return deviceInfoService.pageDevice(pageable, param);
  44. }
  45. @Operation(summary = "删除设备")
  46. @RequestMapping(value = "deleteDeviceInfo", method = {RequestMethod.GET})
  47. public ResultContent deleteDeviceInfo(String deviceId) {
  48. return deviceInfoService.deleteDeviceInfo(deviceId);
  49. }
  50. @Operation(summary = "查询设备")
  51. @RequestMapping(value = "getDeviceById", method = {RequestMethod.GET})
  52. public ResultContent<DeviceInfoModel> getDeviceById(String deviceId) {
  53. return deviceInfoService.getDeviceById(deviceId);
  54. }
  55. }