Преглед изворни кода

增加小程序端设备记录

hechunping пре 2 година
родитељ
комит
fba0ed0eb6

+ 92 - 0
device-api-service-merc-mini/src/main/java/com/xy/controller/MercMiniDeviceRecordsController.java

@@ -1,5 +1,26 @@
 package com.xy.controller;
 
+import com.xy.annotate.RestMappingController;
+import com.xy.dto.DeviceErrorsRecordDto;
+import com.xy.dto.DeviceNetRecordDto;
+import com.xy.dto.DeviceRecordsDto;
+import com.xy.dto.MiniDeviceRecordsDto;
+import com.xy.service.DeviceErrorsRecordService;
+import com.xy.service.DeviceNetRecordService;
+import com.xy.service.DeviceRecordsService;
+import com.xy.utils.MercAuthUtils;
+import com.xy.utils.PageBean;
+import com.xy.utils.R;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * <p>
  *
@@ -8,5 +29,76 @@ package com.xy.controller;
  * @author hechunping
  * @since 2023/3/4
  */
+@RestMappingController("merc-mini/deviceRecords")
+@AllArgsConstructor
+@Api(tags = "小程序-设备记录")
 public class MercMiniDeviceRecordsController {
+
+    private final static int INDEX_RECORDS_COUNT = 10;
+
+    private final DeviceRecordsService deviceRecordsService;
+
+    private final DeviceNetRecordService deviceNetRecordService;
+
+    private final DeviceErrorsRecordService deviceErrorsRecordService;
+
+    @ApiOperation("设备操作记录分页")
+    @PostMapping("deviceRecordsPage")
+    public R<PageBean<DeviceRecordsDto.Vo>> deviceRecordsPage(@RequestBody @Validated DeviceRecordsDto.Page dto) {
+        return deviceRecordsService.page(dto);
+    }
+
+    @ApiOperation("设备详情首页-设备操作记录")
+    @PostMapping("indexDeviceRecords")
+    public R<List<DeviceRecordsDto.Vo>> indexDeviceRecords(@RequestBody @Validated MiniDeviceRecordsDto.DeviceIdDto dto) {
+        DeviceRecordsDto.Page page = (DeviceRecordsDto.Page) new DeviceRecordsDto.Page().setMercId(MercAuthUtils.getMercId())
+                .setDeviceId(dto.getDeviceId());
+        page.setPage(getPageBean(INDEX_RECORDS_COUNT));
+        List<DeviceRecordsDto.Vo> recordsList = deviceRecordsPage(page).getData().getRecords();
+        return R.ok(recordsList);
+    }
+
+    @ApiOperation("联网记录分页")
+    @PostMapping("deviceNetRecordPage")
+    public R<PageBean<DeviceNetRecordDto.Vo>> deviceNetRecordPage(@RequestBody @Validated DeviceNetRecordDto.Page dto){
+        return deviceNetRecordService.page(dto);
+    }
+
+    @ApiOperation("设备详情首页-联网记录")
+    @PostMapping("indexDeviceNetRecords")
+    public R<List<DeviceNetRecordDto.Vo>> indexDeviceNetRecords(@RequestBody @Validated MiniDeviceRecordsDto.DeviceIdDto dto) {
+        DeviceNetRecordDto.Page page = (DeviceNetRecordDto.Page) new DeviceNetRecordDto.Page().setMercId(MercAuthUtils.getMercId())
+                .setDeviceId(dto.getDeviceId());
+        page.setPage(getPageBean(INDEX_RECORDS_COUNT));
+        List<DeviceNetRecordDto.Vo> recordsList = deviceNetRecordPage(page).getData().getRecords();
+        return R.ok(recordsList);
+    }
+
+    @ApiOperation("故障记录分页")
+    @PostMapping("deviceErrorPage")
+    public R<PageBean<DeviceErrorsRecordDto.Vo>> deviceErrorPage(@RequestBody DeviceErrorsRecordDto.Page page){
+        return deviceErrorsRecordService.page(page);
+    }
+
+    @ApiOperation("设备详情首页-故障记录")
+    @PostMapping("indexDeviceError")
+    public R<List<DeviceErrorsRecordDto.Vo>> indexDeviceError(@RequestBody @Validated MiniDeviceRecordsDto.DeviceErrorPageDto dto) {
+        DeviceErrorsRecordDto.Page page = (DeviceErrorsRecordDto.Page) new DeviceErrorsRecordDto.Page().setMercId(MercAuthUtils.getMercId())
+                .setDeviceId(dto.getDeviceId()).setErrorType(dto.getErrorType());
+        page.setPage(getPageBean(INDEX_RECORDS_COUNT));
+        List<DeviceErrorsRecordDto.Vo> recordsList = deviceErrorPage(page).getData().getRecords();
+        return R.ok(recordsList);
+    }
+
+    /**
+     * 获取分页信息
+     *
+     * @param count 显示条数
+     * @return {@link PageBean}
+     */
+    private PageBean getPageBean(int count){
+        List<PageBean.OrderItemBean> orderItemBeans = new ArrayList<>();
+        orderItemBeans.add(new PageBean.OrderItemBean().setColumn("id").setAsc(false));
+        return new PageBean<>().setSize(count).setSearchCount(false).setOrders(orderItemBeans);
+    }
 }

+ 40 - 0
device-api-service-merc-mini/src/main/java/com/xy/dto/MiniDeviceRecordsDto.java

@@ -0,0 +1,40 @@
+package com.xy.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * <p>
+ *  小程序设备记录相关DTO
+ * </p>
+ *
+ * @author hechunping
+ * @since 2023/3/3
+ */
+@Data
+@Accessors(chain = true)
+public class MiniDeviceRecordsDto {
+
+    @Data
+    @Accessors(chain = true)
+    public static class DeviceIdDto{
+        @ApiModelProperty("设备ID")
+        @NotNull(message = "设备ID不能为空")
+        private Long deviceId;
+    }
+
+    @Data
+    @Accessors(chain = true)
+    public static class DeviceErrorPageDto{
+        @ApiModelProperty("设备ID")
+        @NotNull(message = "设备ID不能为空")
+        private Long deviceId;
+
+        @ApiModelProperty("故障类型")
+        @NotNull(message = "故障类型不能为空")
+        private Integer errorType;
+    }
+}