Commit 345065815945b5512a7a87bb3becd99e6229e99d
1 parent
b5ac5261
【功能新增】IoT:设备管理界面增加导出设备功能
Showing
3 changed files
with
41 additions
and
6 deletions
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/DictTypeConstants.java
| @@ -13,4 +13,7 @@ public class DictTypeConstants { | @@ -13,4 +13,7 @@ public class DictTypeConstants { | ||
| 13 | public static final String PROTOCOL_TYPE = "iot_protocol_type"; | 13 | public static final String PROTOCOL_TYPE = "iot_protocol_type"; |
| 14 | public static final String DATA_FORMAT = "iot_data_format"; | 14 | public static final String DATA_FORMAT = "iot_data_format"; |
| 15 | public static final String VALIDATE_TYPE = "iot_validate_type"; | 15 | public static final String VALIDATE_TYPE = "iot_validate_type"; |
| 16 | + | ||
| 17 | + public static final String DEVICE_STATUS = "iot_device_status"; | ||
| 18 | + | ||
| 16 | } | 19 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.java
| 1 | package cn.iocoder.yudao.module.iot.controller.admin.device; | 1 | package cn.iocoder.yudao.module.iot.controller.admin.device; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 8 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||
| 6 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDevicePageReqVO; | 9 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDevicePageReqVO; |
| 7 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceRespVO; | 10 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceRespVO; |
| 8 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceSaveReqVO; | 11 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceSaveReqVO; |
| @@ -13,13 +16,16 @@ import io.swagger.v3.oas.annotations.Operation; | @@ -13,13 +16,16 @@ import io.swagger.v3.oas.annotations.Operation; | ||
| 13 | import io.swagger.v3.oas.annotations.Parameter; | 16 | import io.swagger.v3.oas.annotations.Parameter; |
| 14 | import io.swagger.v3.oas.annotations.tags.Tag; | 17 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 15 | import jakarta.annotation.Resource; | 18 | import jakarta.annotation.Resource; |
| 19 | +import jakarta.servlet.http.HttpServletResponse; | ||
| 16 | import jakarta.validation.Valid; | 20 | import jakarta.validation.Valid; |
| 17 | import org.springframework.security.access.prepost.PreAuthorize; | 21 | import org.springframework.security.access.prepost.PreAuthorize; |
| 18 | import org.springframework.validation.annotation.Validated; | 22 | import org.springframework.validation.annotation.Validated; |
| 19 | import org.springframework.web.bind.annotation.*; | 23 | import org.springframework.web.bind.annotation.*; |
| 20 | 24 | ||
| 25 | +import java.io.IOException; | ||
| 21 | import java.util.List; | 26 | import java.util.List; |
| 22 | 27 | ||
| 28 | +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; | ||
| 23 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 29 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 24 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | 30 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| 25 | 31 | ||
| @@ -81,6 +87,19 @@ public class IotDeviceController { | @@ -81,6 +87,19 @@ public class IotDeviceController { | ||
| 81 | return success(BeanUtils.toBean(pageResult, IotDeviceRespVO.class)); | 87 | return success(BeanUtils.toBean(pageResult, IotDeviceRespVO.class)); |
| 82 | } | 88 | } |
| 83 | 89 | ||
| 90 | + @GetMapping("/export-excel") | ||
| 91 | + @Operation(summary = "导出设备 Excel") | ||
| 92 | + @PreAuthorize("@ss.hasPermission('iot:device:export')") | ||
| 93 | + @ApiAccessLog(operateType = EXPORT) | ||
| 94 | + public void exportDeviceExcel(@Valid IotDevicePageReqVO exportReqVO, | ||
| 95 | + HttpServletResponse response) throws IOException { | ||
| 96 | + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | ||
| 97 | + CommonResult<PageResult<IotDeviceRespVO>> result = getDevicePage(exportReqVO); | ||
| 98 | + // 导出 Excel | ||
| 99 | + ExcelUtils.write(response, "设备.xls", "数据", IotDeviceRespVO.class, | ||
| 100 | + result.getData().getList()); | ||
| 101 | + } | ||
| 102 | + | ||
| 84 | @GetMapping("/count") | 103 | @GetMapping("/count") |
| 85 | @Operation(summary = "获得设备数量") | 104 | @Operation(summary = "获得设备数量") |
| 86 | @Parameter(name = "productId", description = "产品编号", example = "1") | 105 | @Parameter(name = "productId", description = "产品编号", example = "1") |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceRespVO.java
| 1 | package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device; | 1 | package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | ||
| 4 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | ||
| 3 | import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | 5 | import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; |
| 4 | import com.alibaba.excel.annotation.ExcelProperty; | 6 | import com.alibaba.excel.annotation.ExcelProperty; |
| 5 | import io.swagger.v3.oas.annotations.media.Schema; | 7 | import io.swagger.v3.oas.annotations.media.Schema; |
| @@ -8,6 +10,8 @@ import lombok.Data; | @@ -8,6 +10,8 @@ import lombok.Data; | ||
| 8 | import java.time.LocalDateTime; | 10 | import java.time.LocalDateTime; |
| 9 | import java.util.Set; | 11 | import java.util.Set; |
| 10 | 12 | ||
| 13 | +import static cn.iocoder.yudao.module.iot.enums.DictTypeConstants.DEVICE_STATUS; | ||
| 14 | + | ||
| 11 | @Schema(description = "管理后台 - IoT 设备 Response VO") | 15 | @Schema(description = "管理后台 - IoT 设备 Response VO") |
| 12 | @Data | 16 | @Data |
| 13 | @ExcelIgnoreUnannotated | 17 | @ExcelIgnoreUnannotated |
| @@ -21,9 +25,21 @@ public class IotDeviceRespVO { | @@ -21,9 +25,21 @@ public class IotDeviceRespVO { | ||
| 21 | private String deviceKey; | 25 | private String deviceKey; |
| 22 | 26 | ||
| 23 | @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") | 27 | @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") |
| 24 | - @ExcelProperty("设备名称备") | 28 | + @ExcelProperty("设备名称") |
| 25 | private String deviceName; | 29 | private String deviceName; |
| 26 | 30 | ||
| 31 | + @Schema(description = "设备备注名称", example = "张三") | ||
| 32 | + @ExcelProperty("设备备注名称") | ||
| 33 | + private String nickname; | ||
| 34 | + | ||
| 35 | + @Schema(description = "设备序列号", example = "1024") | ||
| 36 | + @ExcelProperty("设备序列号") | ||
| 37 | + private String serialNumber; | ||
| 38 | + | ||
| 39 | + @Schema(description = "设备图片", example = "我是一名码农") | ||
| 40 | + @ExcelProperty("设备图片") | ||
| 41 | + private String picUrl; | ||
| 42 | + | ||
| 27 | @Schema(description = "设备分组编号数组", example = "1,2") | 43 | @Schema(description = "设备分组编号数组", example = "1,2") |
| 28 | private Set<Long> groupIds; | 44 | private Set<Long> groupIds; |
| 29 | 45 | ||
| @@ -39,15 +55,12 @@ public class IotDeviceRespVO { | @@ -39,15 +55,12 @@ public class IotDeviceRespVO { | ||
| 39 | @ExcelProperty("设备类型") | 55 | @ExcelProperty("设备类型") |
| 40 | private Integer deviceType; | 56 | private Integer deviceType; |
| 41 | 57 | ||
| 42 | - @Schema(description = "设备备注名称", example = "张三") | ||
| 43 | - @ExcelProperty("设备备注名称") | ||
| 44 | - private String nickname; | ||
| 45 | - | ||
| 46 | @Schema(description = "网关设备 ID", example = "16380") | 58 | @Schema(description = "网关设备 ID", example = "16380") |
| 47 | private Long gatewayId; | 59 | private Long gatewayId; |
| 48 | 60 | ||
| 49 | @Schema(description = "设备状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | 61 | @Schema(description = "设备状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 50 | - @ExcelProperty("设备状态") | 62 | + @ExcelProperty(value = "设备状态", converter = DictConvert.class) |
| 63 | + @DictFormat(DEVICE_STATUS) | ||
| 51 | private Integer status; | 64 | private Integer status; |
| 52 | 65 | ||
| 53 | @Schema(description = "设备状态最后更新时间") | 66 | @Schema(description = "设备状态最后更新时间") |