Commit db9c485285d99fef822557582fcf00fd9f26bd7e

Authored by YunaiV
1 parent 9841c869

【功能新增】IoT:产品导出功能

yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/DictTypeConstants.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.enums;
  2 +
  3 +/**
  4 + * IoT 字典类型的枚举类
  5 + *
  6 + * @author 芋道源码
  7 + */
  8 +public class DictTypeConstants {
  9 +
  10 + public static final String PRODUCT_STATUS = "iot_product_status";
  11 + public static final String PRODUCT_DEVICE_TYPE = "iot_product_device_type";
  12 + public static final String NET_TYPE = "iot_net_type";
  13 + public static final String PROTOCOL_TYPE = "iot_protocol_type";
  14 + public static final String DATA_FORMAT = "iot_data_format";
  15 + public static final String VALIDATE_TYPE = "iot_validate_type";
  16 +}
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/IotProductController.java
1 1 package cn.iocoder.yudao.module.iot.controller.admin.product;
2 2  
  3 +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
3 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
4 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 7 import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
6 8 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  9 +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
7 10 import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductPageReqVO;
8 11 import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductRespVO;
9 12 import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductSaveReqVO;
... ... @@ -15,14 +18,17 @@ import io.swagger.v3.oas.annotations.Operation;
15 18 import io.swagger.v3.oas.annotations.Parameter;
16 19 import io.swagger.v3.oas.annotations.tags.Tag;
17 20 import jakarta.annotation.Resource;
  21 +import jakarta.servlet.http.HttpServletResponse;
18 22 import jakarta.validation.Valid;
19 23 import org.springframework.security.access.prepost.PreAuthorize;
20 24 import org.springframework.validation.annotation.Validated;
21 25 import org.springframework.web.bind.annotation.*;
22 26  
  27 +import java.io.IOException;
23 28 import java.util.List;
24 29 import java.util.Map;
25 30  
  31 +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
26 32 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
27 33 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
28 34  
... ... @@ -101,6 +107,19 @@ public class IotProductController {
101 107 }));
102 108 }
103 109  
  110 + @GetMapping("/export-excel")
  111 + @Operation(summary = "导出产品 Excel")
  112 + @PreAuthorize("@ss.hasPermission('iot:product:export')")
  113 + @ApiAccessLog(operateType = EXPORT)
  114 + public void exportProductExcel(@Valid IotProductPageReqVO exportReqVO,
  115 + HttpServletResponse response) throws IOException {
  116 + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
  117 + CommonResult<PageResult<IotProductRespVO>> result = getProductPage(exportReqVO);
  118 + // 导出 Excel
  119 + ExcelUtils.write(response, "产品.xls", "数据", IotProductRespVO.class,
  120 + result.getData().getList());
  121 + }
  122 +
104 123 @GetMapping("/simple-list")
105 124 @Operation(summary = "获得所有产品列表")
106 125 @PreAuthorize("@ss.hasPermission('iot:product:query')")
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/product/IotProductRespVO.java
1 1 package cn.iocoder.yudao.module.iot.controller.admin.product.vo.product;
2 2  
  3 +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
  4 +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
  5 +import cn.iocoder.yudao.module.iot.enums.DictTypeConstants;
3 6 import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
4 7 import com.alibaba.excel.annotation.ExcelProperty;
5 8 import io.swagger.v3.oas.annotations.media.Schema;
... ... @@ -28,12 +31,15 @@ public class IotProductRespVO {
28 31 private Long categoryId;
29 32  
30 33 @Schema(description = "产品分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  34 + @ExcelProperty("产品分类")
31 35 private String categoryName;
32 36  
33 37 @Schema(description = "产品图标", example = "https://iocoder.cn/1.svg")
  38 + @ExcelProperty("产品图标")
34 39 private String icon;
35 40  
36 41 @Schema(description = "产品图标", example = "https://iocoder.cn/1.png")
  42 + @ExcelProperty("产品图标")
37 43 private String picUrl;
38 44  
39 45 @Schema(description = "产品描述", example = "你猜")
... ... @@ -41,19 +47,23 @@ public class IotProductRespVO {
41 47 private String description;
42 48  
43 49 @Schema(description = "产品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
44   - @ExcelProperty("产品状态")
  50 + @ExcelProperty(value = "产品状态", converter = DictConvert.class)
  51 + @DictFormat(DictTypeConstants.PRODUCT_STATUS)
45 52 private Integer status;
46 53  
47 54 @Schema(description = "设备类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
48   - @ExcelProperty("设备类型")
  55 + @ExcelProperty(value = "设备类型", converter = DictConvert.class)
  56 + @DictFormat(DictTypeConstants.PRODUCT_DEVICE_TYPE)
49 57 private Integer deviceType;
50 58  
51 59 @Schema(description = "联网方式", example = "2")
52   - @ExcelProperty("联网方式")
  60 + @ExcelProperty(value = "联网方式", converter = DictConvert.class)
  61 + @DictFormat(DictTypeConstants.NET_TYPE)
53 62 private Integer netType;
54 63  
55 64 @Schema(description = "接入网关协议", example = "2")
56   - @ExcelProperty("接入网关协议")
  65 + @ExcelProperty(value = "接入网关协议", converter = DictConvert.class)
  66 + @DictFormat(DictTypeConstants.PROTOCOL_TYPE)
57 67 private Integer protocolType;
58 68  
59 69 @Schema(description = "协议编号(脚本解析 id)", requiredMode = Schema.RequiredMode.REQUIRED, example = "13177")
... ... @@ -61,11 +71,13 @@ public class IotProductRespVO {
61 71 private Long protocolId;
62 72  
63 73 @Schema(description = "数据格式")
64   - @ExcelProperty("数据格式")
  74 + @ExcelProperty(value = "数据格式", converter = DictConvert.class)
  75 + @DictFormat(DictTypeConstants.DATA_FORMAT)
65 76 private Integer dataFormat;
66 77  
67 78 @Schema(description = "数据校验级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
68   - @ExcelProperty("数据校验级别")
  79 + @ExcelProperty(value = "数据校验级别", converter = DictConvert.class)
  80 + @DictFormat(DictTypeConstants.VALIDATE_TYPE)
69 81 private Integer validateType;
70 82  
71 83 @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
... ...