Commit 36a828866bcc0ba57fba16316a322204b79b3b9a

Authored by 安浩浩
1 parent 3f01ba75

新增:iot 产品

Showing 19 changed files with 868 additions and 12 deletions
... ... @@ -17,12 +17,12 @@
17 17 <module>yudao-module-infra</module>
18 18 <module>yudao-module-iot</module>
19 19 <!-- <module>yudao-module-member</module>-->
20   -<!-- <module>yudao-module-bpm</module>-->
  20 + <module>yudao-module-bpm</module>
21 21 <!-- <module>yudao-module-report</module>-->
22 22 <!-- <module>yudao-module-mp</module>-->
23 23 <!-- <module>yudao-module-pay</module>-->
24 24 <!-- <module>yudao-module-mall</module>-->
25   -<!-- <module>yudao-module-crm</module>-->
  25 + <module>yudao-module-crm</module>
26 26 <!-- <module>yudao-module-erp</module>-->
27 27 <!-- <module>yudao-module-ai</module>-->
28 28 </modules>
... ...
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.enums;
  2 +
  3 +import cn.iocoder.yudao.framework.common.exception.ErrorCode;
  4 +
  5 +/**
  6 + * iot 错误码枚举类
  7 + * <p>
  8 + * iot 系统,使用 1-050-000-000 段
  9 + */
  10 +public interface ErrorCodeConstants {
  11 +
  12 + // ========== 产品相关 1-050-001-000 ============
  13 + ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_050_001_000, "产品不存在");
  14 + ErrorCode PRODUCT_IDENTIFICATION_EXISTS = new ErrorCode(1_050_001_001, "产品标识已经存在");
  15 +}
... ...
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ProductDataFormatEnum.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.enums;
  2 +
  3 +import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Getter;
  6 +
  7 +import java.util.Arrays;
  8 +
  9 +/**
  10 + * 产品数据格式枚举类
  11 + * 1. 标准数据格式(JSON)2. 透传/自定义
  12 + */
  13 +@AllArgsConstructor
  14 +@Getter
  15 +public enum ProductDataFormatEnum implements IntArrayValuable {
  16 +
  17 + JSON(1, "标准数据格式(JSON)"),
  18 + SCRIPT(2, "透传/自定义");
  19 +
  20 + /**
  21 + * 类型
  22 + */
  23 + private final Integer type;
  24 +
  25 + /**
  26 + * 描述
  27 + */
  28 + private final String description;
  29 +
  30 + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ProductDataFormatEnum::getType).toArray();
  31 +
  32 + @Override
  33 + public int[] array() {
  34 + return ARRAYS;
  35 + }
  36 +
  37 +}
... ...
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ProductDeviceTypeConstants.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.enums;
  2 +
  3 +/**
  4 + * 产品设备类型常量
  5 + */
  6 +public interface ProductDeviceTypeConstants {
  7 +
  8 + // ========== 产品设备类型 ============
  9 + String DEVICE = "device"; // 直连设备
  10 + String GATEWAY = "gateway"; // 网关设备
  11 + String GATEWAY_SUB = "gateway_sub"; // 网关子设备
  12 +
  13 +}
... ...
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ProductProtocolTypeConstants.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.enums;
  2 +
  3 +/**
  4 + * 产品传输协议类型常量
  5 + */
  6 +public interface ProductProtocolTypeConstants {
  7 +
  8 + // ========== 产品传输协议类型 ============
  9 + String MQTT = "mqtt"; // MQTT
  10 + String COAP = "coap"; // COAP
  11 + String HTTP = "http"; // HTTP
  12 + String HTTPS = "https"; // HTTPS
  13 +}
... ...
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ProductStatusEnum.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.enums;
  2 +
  3 +import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Getter;
  6 +
  7 +/**
  8 + * 产品状态枚举类
  9 + * 禁用 启用
  10 + */
  11 +@AllArgsConstructor
  12 +@Getter
  13 +public enum ProductStatusEnum implements IntArrayValuable {
  14 +
  15 + DISABLE(0, "禁用"),
  16 + ENABLE(1, "启用");
  17 +
  18 + /**
  19 + * 类型
  20 + */
  21 + private final Integer type;
  22 +
  23 + /**
  24 + * 描述
  25 + */
  26 + private final String description;
  27 +
  28 + public static final int[] ARRAYS = {1, 2};
  29 +
  30 + @Override
  31 + public int[] array() {
  32 + return ARRAYS;
  33 + }
  34 +}
... ...
yudao-module-iot/yudao-module-iot-biz/pom.xml
... ... @@ -47,6 +47,12 @@
47 47 <artifactId>yudao-spring-boot-starter-test</artifactId>
48 48 </dependency>
49 49  
  50 + <!-- 工具类相关 -->
  51 + <dependency>
  52 + <groupId>cn.iocoder.boot</groupId>
  53 + <artifactId>yudao-spring-boot-starter-excel</artifactId>
  54 + </dependency>
  55 +
50 56 <!-- mqtt -->
51 57 <dependency>
52 58 <groupId>org.eclipse.paho</groupId>
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/ProductController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.product;
  2 +
  3 +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
  4 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  6 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  7 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  8 +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
  9 +import cn.iocoder.yudao.module.iot.controller.admin.product.vo.ProductPageReqVO;
  10 +import cn.iocoder.yudao.module.iot.controller.admin.product.vo.ProductRespVO;
  11 +import cn.iocoder.yudao.module.iot.controller.admin.product.vo.ProductSaveReqVO;
  12 +import cn.iocoder.yudao.module.iot.dal.dataobject.product.ProductDO;
  13 +import cn.iocoder.yudao.module.iot.service.product.ProductService;
  14 +import io.swagger.v3.oas.annotations.Operation;
  15 +import io.swagger.v3.oas.annotations.Parameter;
  16 +import io.swagger.v3.oas.annotations.tags.Tag;
  17 +import jakarta.annotation.Resource;
  18 +import jakarta.servlet.http.HttpServletResponse;
  19 +import jakarta.validation.Valid;
  20 +import org.springframework.security.access.prepost.PreAuthorize;
  21 +import org.springframework.validation.annotation.Validated;
  22 +import org.springframework.web.bind.annotation.*;
  23 +
  24 +import java.io.IOException;
  25 +import java.util.List;
  26 +
  27 +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
  28 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  29 +
  30 +@Tag(name = "管理后台 - iot 产品")
  31 +@RestController
  32 +@RequestMapping("/iot/product")
  33 +@Validated
  34 +public class ProductController {
  35 +
  36 + @Resource
  37 + private ProductService productService;
  38 +
  39 + @PostMapping("/create")
  40 + @Operation(summary = "创建产品")
  41 + @PreAuthorize("@ss.hasPermission('iot:product:create')")
  42 + public CommonResult<Long> createProduct(@Valid @RequestBody ProductSaveReqVO createReqVO) {
  43 + return success(productService.createProduct(createReqVO));
  44 + }
  45 +
  46 + @PutMapping("/update")
  47 + @Operation(summary = "更新产品")
  48 + @PreAuthorize("@ss.hasPermission('iot:product:update')")
  49 + public CommonResult<Boolean> updateProduct(@Valid @RequestBody ProductSaveReqVO updateReqVO) {
  50 + productService.updateProduct(updateReqVO);
  51 + return success(true);
  52 + }
  53 +
  54 + @DeleteMapping("/delete")
  55 + @Operation(summary = "删除产品")
  56 + @Parameter(name = "id", description = "编号", required = true)
  57 + @PreAuthorize("@ss.hasPermission('iot:product:delete')")
  58 + public CommonResult<Boolean> deleteProduct(@RequestParam("id") Long id) {
  59 + productService.deleteProduct(id);
  60 + return success(true);
  61 + }
  62 +
  63 + @GetMapping("/get")
  64 + @Operation(summary = "获得产品")
  65 + @Parameter(name = "id", description = "编号", required = true, example = "1024")
  66 + @PreAuthorize("@ss.hasPermission('iot:product:query')")
  67 + public CommonResult<ProductRespVO> getProduct(@RequestParam("id") Long id) {
  68 + ProductDO product = productService.getProduct(id);
  69 + return success(BeanUtils.toBean(product, ProductRespVO.class));
  70 + }
  71 +
  72 + @GetMapping("/page")
  73 + @Operation(summary = "获得产品分页")
  74 + @PreAuthorize("@ss.hasPermission('iot:product:query')")
  75 + public CommonResult<PageResult<ProductRespVO>> getProductPage(@Valid ProductPageReqVO pageReqVO) {
  76 + PageResult<ProductDO> pageResult = productService.getProductPage(pageReqVO);
  77 + return success(BeanUtils.toBean(pageResult, ProductRespVO.class));
  78 + }
  79 +
  80 + @GetMapping("/export-excel")
  81 + @Operation(summary = "导出产品 Excel")
  82 + @PreAuthorize("@ss.hasPermission('iot:product:export')")
  83 + @ApiAccessLog(operateType = EXPORT)
  84 + public void exportProductExcel(@Valid ProductPageReqVO pageReqVO,
  85 + HttpServletResponse response) throws IOException {
  86 + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
  87 + List<ProductDO> list = productService.getProductPage(pageReqVO).getList();
  88 + // 导出 Excel
  89 + ExcelUtils.write(response, "产品.xls", "数据", ProductRespVO.class,
  90 + BeanUtils.toBean(list, ProductRespVO.class));
  91 + }
  92 +
  93 +}
0 94 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/ProductPageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.product.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.v3.oas.annotations.media.Schema;
  6 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  7 +import org.springframework.format.annotation.DateTimeFormat;
  8 +import java.time.LocalDateTime;
  9 +
  10 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  11 +
  12 +@Schema(description = "管理后台 - iot 产品分页 Request VO")
  13 +@Data
  14 +@EqualsAndHashCode(callSuper = true)
  15 +@ToString(callSuper = true)
  16 +public class ProductPageReqVO extends PageParam {
  17 +
  18 + @Schema(description = "产品名称", example = "李四")
  19 + private String name;
  20 +
  21 + @Schema(description = "产品标识")
  22 + private String identification;
  23 +
  24 + @Schema(description = "设备类型:device、gatway、gatway_sub", example = "1")
  25 + private String deviceType;
  26 +
  27 + @Schema(description = "厂商名称", example = "李四")
  28 + private String manufacturerName;
  29 +
  30 + @Schema(description = "产品型号")
  31 + private String model;
  32 +
  33 + @Schema(description = "数据格式:1. 标准数据格式(JSON)2. 透传/自定义,脚本解析")
  34 + private Integer dataFormat;
  35 +
  36 + @Schema(description = "设备接入平台的协议类型,默认为MQTT", example = "2")
  37 + private String protocolType;
  38 +
  39 + @Schema(description = "产品描述", example = "随便")
  40 + private String description;
  41 +
  42 + @Schema(description = "产品状态 (0: 启用, 1: 停用)", example = "2")
  43 + private Integer status;
  44 +
  45 + @Schema(description = "物模型定义")
  46 + private String metadata;
  47 +
  48 + @Schema(description = "消息协议ID")
  49 + private Long messageProtocol;
  50 +
  51 + @Schema(description = "消息协议名称", example = "芋艿")
  52 + private String protocolName;
  53 +
  54 + @Schema(description = "创建时间")
  55 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  56 + private LocalDateTime[] createTime;
  57 +
  58 +}
0 59 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/ProductRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.product.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.*;
  5 +import java.util.*;
  6 +import org.springframework.format.annotation.DateTimeFormat;
  7 +import java.time.LocalDateTime;
  8 +import com.alibaba.excel.annotation.*;
  9 +
  10 +@Schema(description = "管理后台 - iot 产品 Response VO")
  11 +@Data
  12 +@ExcelIgnoreUnannotated
  13 +public class ProductRespVO {
  14 +
  15 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "778")
  16 + @ExcelProperty("编号")
  17 + private Long id;
  18 +
  19 + @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
  20 + @ExcelProperty("产品名称")
  21 + private String name;
  22 +
  23 + @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED)
  24 + @ExcelProperty("产品标识")
  25 + private String identification;
  26 +
  27 + @Schema(description = "设备类型:device、gatway、gatway_sub", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  28 + @ExcelProperty("设备类型:device、gatway、gatway_sub")
  29 + private String deviceType;
  30 +
  31 + @Schema(description = "厂商名称", example = "李四")
  32 + @ExcelProperty("厂商名称")
  33 + private String manufacturerName;
  34 +
  35 + @Schema(description = "产品型号")
  36 + @ExcelProperty("产品型号")
  37 + private String model;
  38 +
  39 + @Schema(description = "数据格式:1. 标准数据格式(JSON)2. 透传/自定义,脚本解析")
  40 + @ExcelProperty("数据格式:1. 标准数据格式(JSON)2. 透传/自定义,脚本解析")
  41 + private Integer dataFormat;
  42 +
  43 + @Schema(description = "设备接入平台的协议类型,默认为MQTT", example = "2")
  44 + @ExcelProperty("设备接入平台的协议类型,默认为MQTT")
  45 + private String protocolType;
  46 +
  47 + @Schema(description = "产品描述", example = "随便")
  48 + @ExcelProperty("产品描述")
  49 + private String description;
  50 +
  51 + @Schema(description = "产品状态 (0: 启用, 1: 停用)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  52 + @ExcelProperty("产品状态 (0: 启用, 1: 停用)")
  53 + private Integer status;
  54 +
  55 + @Schema(description = "物模型定义", requiredMode = Schema.RequiredMode.REQUIRED)
  56 + @ExcelProperty("物模型定义")
  57 + private String metadata;
  58 +
  59 + @Schema(description = "消息协议ID", requiredMode = Schema.RequiredMode.REQUIRED)
  60 + @ExcelProperty("消息协议ID")
  61 + private Long messageProtocol;
  62 +
  63 + @Schema(description = "消息协议名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
  64 + @ExcelProperty("消息协议名称")
  65 + private String protocolName;
  66 +
  67 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  68 + @ExcelProperty("创建时间")
  69 + private LocalDateTime createTime;
  70 +
  71 +}
0 72 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/ProductSaveReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.product.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import jakarta.validation.constraints.NotEmpty;
  5 +import lombok.Data;
  6 +
  7 +@Schema(description = "管理后台 - iot 产品新增/修改 Request VO")
  8 +@Data
  9 +public class ProductSaveReqVO {
  10 +
  11 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "778")
  12 + private Long id;
  13 +
  14 + @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "温湿度")
  15 + @NotEmpty(message = "产品名称不能为空")
  16 + private String name;
  17 +
  18 + @Schema(description = "产品标识", example = "123456")
  19 + private String identification;
  20 +
  21 + @Schema(description = "设备类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "device")
  22 + @NotEmpty(message = "设备类型不能为空")
  23 + private String deviceType;
  24 +
  25 + @Schema(description = "数据格式:1. 标准数据格式(JSON)2. 透传/自定义", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  26 + @NotEmpty(message = "数据格式不能为空")
  27 + private Integer dataFormat;
  28 +
  29 + @Schema(description = "设备接入平台的协议类型,默认为MQTT", requiredMode = Schema.RequiredMode.REQUIRED, example = "mqtt")
  30 + @NotEmpty(message = "设备接入平台的协议类型不能为空")
  31 + private String protocolType;
  32 +
  33 + @Schema(description = "厂商名称", example = "电信")
  34 + private String manufacturerName;
  35 +
  36 + @Schema(description = "产品型号", example = "wsd-01")
  37 + private String model;
  38 +
  39 + @Schema(description = "产品描述", example = "随便")
  40 + private String description;
  41 +
  42 +// @Schema(description = "产品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  43 +// private Integer status;
  44 +//
  45 +// @Schema(description = "物模型定义", requiredMode = Schema.RequiredMode.REQUIRED)
  46 +// private String metadata;
  47 +//
  48 +// @Schema(description = "消息协议ID", requiredMode = Schema.RequiredMode.REQUIRED)
  49 +// private Long messageProtocol;
  50 +//
  51 +// @Schema(description = "消息协议名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
  52 +// private String protocolName;
  53 +
  54 +}
0 55 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/product/ProductDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.dal.dataobject.product;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import java.time.LocalDateTime;
  6 +import java.time.LocalDateTime;
  7 +import com.baomidou.mybatisplus.annotation.*;
  8 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  9 +
  10 +/**
  11 + * iot 产品 DO
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@TableName("iot_product")
  16 +@KeySequence("iot_product_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  17 +@Data
  18 +@EqualsAndHashCode(callSuper = true)
  19 +@ToString(callSuper = true)
  20 +@Builder
  21 +@NoArgsConstructor
  22 +@AllArgsConstructor
  23 +public class ProductDO extends BaseDO {
  24 +
  25 + /**
  26 + * 编号
  27 + */
  28 + @TableId
  29 + private Long id;
  30 + /**
  31 + * 产品名称
  32 + */
  33 + private String name;
  34 + /**
  35 + * 产品标识
  36 + */
  37 + private String identification;
  38 + /**
  39 + * 设备类型:device、gatway、gatway_sub
  40 + */
  41 + private String deviceType;
  42 + /**
  43 + * 厂商名称
  44 + */
  45 + private String manufacturerName;
  46 + /**
  47 + * 产品型号
  48 + */
  49 + private String model;
  50 + /**
  51 + * 数据格式:1. 标准数据格式(JSON)2. 透传/自定义,脚本解析
  52 + */
  53 + private Integer dataFormat;
  54 + /**
  55 + * 设备接入平台的协议类型,默认为MQTT
  56 + */
  57 + private String protocolType;
  58 + /**
  59 + * 产品描述
  60 + */
  61 + private String description;
  62 + /**
  63 + * 产品状态 (0: 启用, 1: 停用)
  64 + */
  65 + private Integer status;
  66 + /**
  67 + * 物模型定义
  68 + */
  69 + private String metadata;
  70 + /**
  71 + * 消息协议ID
  72 + */
  73 + private Long messageProtocol;
  74 + /**
  75 + * 消息协议名称
  76 + */
  77 + private String protocolName;
  78 +
  79 +}
0 80 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/product/ProductMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.dal.mysql.product;
  2 +
  3 +import java.util.*;
  4 +
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  7 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  8 +import cn.iocoder.yudao.module.iot.dal.dataobject.product.ProductDO;
  9 +import jakarta.validation.constraints.NotEmpty;
  10 +import org.apache.ibatis.annotations.Mapper;
  11 +import cn.iocoder.yudao.module.iot.controller.admin.product.vo.*;
  12 +
  13 +/**
  14 + * iot 产品 Mapper
  15 + *
  16 + * @author 芋道源码
  17 + */
  18 +@Mapper
  19 +public interface ProductMapper extends BaseMapperX<ProductDO> {
  20 +
  21 + default PageResult<ProductDO> selectPage(ProductPageReqVO reqVO) {
  22 + return selectPage(reqVO, new LambdaQueryWrapperX<ProductDO>()
  23 + .likeIfPresent(ProductDO::getName, reqVO.getName())
  24 + .eqIfPresent(ProductDO::getIdentification, reqVO.getIdentification())
  25 + .eqIfPresent(ProductDO::getDeviceType, reqVO.getDeviceType())
  26 + .likeIfPresent(ProductDO::getManufacturerName, reqVO.getManufacturerName())
  27 + .eqIfPresent(ProductDO::getModel, reqVO.getModel())
  28 + .eqIfPresent(ProductDO::getDataFormat, reqVO.getDataFormat())
  29 + .eqIfPresent(ProductDO::getProtocolType, reqVO.getProtocolType())
  30 + .eqIfPresent(ProductDO::getDescription, reqVO.getDescription())
  31 + .eqIfPresent(ProductDO::getStatus, reqVO.getStatus())
  32 + .eqIfPresent(ProductDO::getMetadata, reqVO.getMetadata())
  33 + .eqIfPresent(ProductDO::getMessageProtocol, reqVO.getMessageProtocol())
  34 + .likeIfPresent(ProductDO::getProtocolName, reqVO.getProtocolName())
  35 + .betweenIfPresent(ProductDO::getCreateTime, reqVO.getCreateTime())
  36 + .orderByDesc(ProductDO::getId));
  37 + }
  38 +
  39 + default ProductDO selectByIdentification(String identification){
  40 + return selectOne(new LambdaQueryWrapperX<ProductDO>().eq(ProductDO::getIdentification, identification));
  41 + }
  42 +}
0 43 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/ProductService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.service.product;
  2 +
  3 +import java.util.*;
  4 +import jakarta.validation.*;
  5 +import cn.iocoder.yudao.module.iot.controller.admin.product.vo.*;
  6 +import cn.iocoder.yudao.module.iot.dal.dataobject.product.ProductDO;
  7 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  8 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  9 +
  10 +/**
  11 + * iot 产品 Service 接口
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +public interface ProductService {
  16 +
  17 + /**
  18 + * 创建iot 产品
  19 + *
  20 + * @param createReqVO 创建信息
  21 + * @return 编号
  22 + */
  23 + Long createProduct(@Valid ProductSaveReqVO createReqVO);
  24 +
  25 + /**
  26 + * 更新iot 产品
  27 + *
  28 + * @param updateReqVO 更新信息
  29 + */
  30 + void updateProduct(@Valid ProductSaveReqVO updateReqVO);
  31 +
  32 + /**
  33 + * 删除iot 产品
  34 + *
  35 + * @param id 编号
  36 + */
  37 + void deleteProduct(Long id);
  38 +
  39 + /**
  40 + * 获得iot 产品
  41 + *
  42 + * @param id 编号
  43 + * @return iot 产品
  44 + */
  45 + ProductDO getProduct(Long id);
  46 +
  47 + /**
  48 + * 获得iot 产品分页
  49 + *
  50 + * @param pageReqVO 分页查询
  51 + * @return iot 产品分页
  52 + */
  53 + PageResult<ProductDO> getProductPage(ProductPageReqVO pageReqVO);
  54 +
  55 +}
0 56 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/ProductServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.service.product;
  2 +
  3 +import cn.hutool.core.util.IdUtil;
  4 +import cn.hutool.core.util.StrUtil;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  7 +import cn.iocoder.yudao.module.iot.controller.admin.product.vo.ProductPageReqVO;
  8 +import cn.iocoder.yudao.module.iot.controller.admin.product.vo.ProductSaveReqVO;
  9 +import cn.iocoder.yudao.module.iot.dal.dataobject.product.ProductDO;
  10 +import cn.iocoder.yudao.module.iot.dal.mysql.product.ProductMapper;
  11 +import jakarta.annotation.Resource;
  12 +import jakarta.validation.constraints.NotEmpty;
  13 +import org.springframework.stereotype.Service;
  14 +import org.springframework.validation.annotation.Validated;
  15 +
  16 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  17 +import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.PRODUCT_IDENTIFICATION_EXISTS;
  18 +import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.PRODUCT_NOT_EXISTS;
  19 +
  20 +/**
  21 + * iot 产品 Service 实现类
  22 + *
  23 + * @author 芋道源码
  24 + */
  25 +@Service
  26 +@Validated
  27 +public class ProductServiceImpl implements ProductService {
  28 +
  29 + @Resource
  30 + private ProductMapper productMapper;
  31 +
  32 + @Override
  33 + public Long createProduct(ProductSaveReqVO createReqVO) {
  34 + // 不传自动生成产品标识
  35 + createIdentification(createReqVO);
  36 + // 校验产品标识是否重复
  37 + validateProductIdentification(createReqVO.getIdentification());
  38 + // 插入
  39 + ProductDO product = BeanUtils.toBean(createReqVO, ProductDO.class);
  40 + productMapper.insert(product);
  41 + // 返回
  42 + return product.getId();
  43 + }
  44 +
  45 + private void validateProductIdentification(@NotEmpty(message = "产品标识不能为空") String identification) {
  46 + if (productMapper.selectByIdentification(identification) != null) {
  47 + throw exception(PRODUCT_IDENTIFICATION_EXISTS);
  48 + }
  49 + }
  50 +
  51 + private void createIdentification(ProductSaveReqVO createReqVO) {
  52 + if (StrUtil.isNotBlank(createReqVO.getIdentification())) {
  53 + return;
  54 + }
  55 + // 生成 19 位数字
  56 + createReqVO.setIdentification(String.valueOf(IdUtil.getSnowflake(1, 1).nextId()));
  57 + }
  58 +
  59 + @Override
  60 + public void updateProduct(ProductSaveReqVO updateReqVO) {
  61 + // 校验存在
  62 + validateProductExists(updateReqVO.getId());
  63 + // 更新
  64 + ProductDO updateObj = BeanUtils.toBean(updateReqVO, ProductDO.class);
  65 + productMapper.updateById(updateObj);
  66 + }
  67 +
  68 + @Override
  69 + public void deleteProduct(Long id) {
  70 + // 校验存在
  71 + validateProductExists(id);
  72 + // 删除
  73 + productMapper.deleteById(id);
  74 + }
  75 +
  76 + private void validateProductExists(Long id) {
  77 + if (productMapper.selectById(id) == null) {
  78 + throw exception(PRODUCT_NOT_EXISTS);
  79 + }
  80 + }
  81 +
  82 + @Override
  83 + public ProductDO getProduct(Long id) {
  84 + return productMapper.selectById(id);
  85 + }
  86 +
  87 + @Override
  88 + public PageResult<ProductDO> getProductPage(ProductPageReqVO pageReqVO) {
  89 + return productMapper.selectPage(pageReqVO);
  90 + }
  91 +
  92 + public static void main(String[] args) {
  93 + System.out.println(String.valueOf(IdUtil.getSnowflake(1, 1).nextId()));
  94 + }
  95 +}
0 96 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/product/ProductMapper.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="cn.iocoder.yudao.module.iot.dal.mysql.product.ProductMapper">
  4 +
  5 + <!--
  6 + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
  7 + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
  8 + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
  9 + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
  10 + -->
  11 +
  12 +</mapper>
0 13 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/test/java/cn/iocoder/yudao/module/iot/service/product/ProductServiceImplTest.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.service.product;
  2 +
  3 +import org.junit.jupiter.api.Disabled;
  4 +import org.junit.jupiter.api.Test;
  5 +import org.springframework.boot.test.mock.mockito.MockBean;
  6 +
  7 +import jakarta.annotation.Resource;
  8 +
  9 +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
  10 +
  11 +import cn.iocoder.yudao.module.iot.controller.admin.product.vo.*;
  12 +import cn.iocoder.yudao.module.iot.dal.dataobject.product.ProductDO;
  13 +import cn.iocoder.yudao.module.iot.dal.mysql.product.ProductMapper;
  14 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  15 +
  16 +import jakarta.annotation.Resource;
  17 +import org.springframework.context.annotation.Import;
  18 +import java.util.*;
  19 +import java.time.LocalDateTime;
  20 +
  21 +import static cn.hutool.core.util.RandomUtil.*;
  22 +import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
  23 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
  24 +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
  25 +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
  26 +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
  27 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
  28 +import static org.junit.jupiter.api.Assertions.*;
  29 +import static org.mockito.Mockito.*;
  30 +
  31 +/**
  32 + * {@link ProductServiceImpl} 的单元测试类
  33 + *
  34 + * @author 芋道源码
  35 + */
  36 +@Import(ProductServiceImpl.class)
  37 +public class ProductServiceImplTest extends BaseDbUnitTest {
  38 +
  39 + @Resource
  40 + private ProductServiceImpl productService;
  41 +
  42 + @Resource
  43 + private ProductMapper productMapper;
  44 +
  45 + @Test
  46 + public void testCreateProduct_success() {
  47 + // 准备参数
  48 + ProductSaveReqVO createReqVO = randomPojo(ProductSaveReqVO.class).setId(null);
  49 +
  50 + // 调用
  51 + Long productId = productService.createProduct(createReqVO);
  52 + // 断言
  53 + assertNotNull(productId);
  54 + // 校验记录的属性是否正确
  55 + ProductDO product = productMapper.selectById(productId);
  56 + assertPojoEquals(createReqVO, product, "id");
  57 + }
  58 +
  59 + @Test
  60 + public void testUpdateProduct_success() {
  61 + // mock 数据
  62 + ProductDO dbProduct = randomPojo(ProductDO.class);
  63 + productMapper.insert(dbProduct);// @Sql: 先插入出一条存在的数据
  64 + // 准备参数
  65 + ProductSaveReqVO updateReqVO = randomPojo(ProductSaveReqVO.class, o -> {
  66 + o.setId(dbProduct.getId()); // 设置更新的 ID
  67 + });
  68 +
  69 + // 调用
  70 + productService.updateProduct(updateReqVO);
  71 + // 校验是否更新正确
  72 + ProductDO product = productMapper.selectById(updateReqVO.getId()); // 获取最新的
  73 + assertPojoEquals(updateReqVO, product);
  74 + }
  75 +
  76 + @Test
  77 + public void testUpdateProduct_notExists() {
  78 + // 准备参数
  79 + ProductSaveReqVO updateReqVO = randomPojo(ProductSaveReqVO.class);
  80 +
  81 + // 调用, 并断言异常
  82 + assertServiceException(() -> productService.updateProduct(updateReqVO), PRODUCT_NOT_EXISTS);
  83 + }
  84 +
  85 + @Test
  86 + public void testDeleteProduct_success() {
  87 + // mock 数据
  88 + ProductDO dbProduct = randomPojo(ProductDO.class);
  89 + productMapper.insert(dbProduct);// @Sql: 先插入出一条存在的数据
  90 + // 准备参数
  91 + Long id = dbProduct.getId();
  92 +
  93 + // 调用
  94 + productService.deleteProduct(id);
  95 + // 校验数据不存在了
  96 + assertNull(productMapper.selectById(id));
  97 + }
  98 +
  99 + @Test
  100 + public void testDeleteProduct_notExists() {
  101 + // 准备参数
  102 + Long id = randomLongId();
  103 +
  104 + // 调用, 并断言异常
  105 + assertServiceException(() -> productService.deleteProduct(id), PRODUCT_NOT_EXISTS);
  106 + }
  107 +
  108 + @Test
  109 + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
  110 + public void testGetProductPage() {
  111 + // mock 数据
  112 + ProductDO dbProduct = randomPojo(ProductDO.class, o -> { // 等会查询到
  113 + o.setName(null);
  114 + o.setIdentification(null);
  115 + o.setDeviceType(null);
  116 + o.setManufacturerName(null);
  117 + o.setModel(null);
  118 + o.setDataFormat(null);
  119 + o.setProtocolType(null);
  120 + o.setDescription(null);
  121 + o.setStatus(null);
  122 + o.setMetadata(null);
  123 + o.setMessageProtocol(null);
  124 + o.setProtocolName(null);
  125 + o.setCreateTime(null);
  126 + });
  127 + productMapper.insert(dbProduct);
  128 + // 测试 name 不匹配
  129 + productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setName(null)));
  130 + // 测试 identification 不匹配
  131 + productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setIdentification(null)));
  132 + // 测试 deviceType 不匹配
  133 + productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setDeviceType(null)));
  134 + // 测试 manufacturerName 不匹配
  135 + productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setManufacturerName(null)));
  136 + // 测试 model 不匹配
  137 + productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setModel(null)));
  138 + // 测试 dataFormat 不匹配
  139 + productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setDataFormat(null)));
  140 + // 测试 protocolType 不匹配
  141 + productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setProtocolType(null)));
  142 + // 测试 description 不匹配
  143 + productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setDescription(null)));
  144 + // 测试 status 不匹配
  145 + productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setStatus(null)));
  146 + // 测试 metadata 不匹配
  147 + productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setMetadata(null)));
  148 + // 测试 messageProtocol 不匹配
  149 + productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setMessageProtocol(null)));
  150 + // 测试 protocolName 不匹配
  151 + productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setProtocolName(null)));
  152 + // 测试 createTime 不匹配
  153 + productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setCreateTime(null)));
  154 + // 准备参数
  155 + ProductPageReqVO reqVO = new ProductPageReqVO();
  156 + reqVO.setName(null);
  157 + reqVO.setIdentification(null);
  158 + reqVO.setDeviceType(null);
  159 + reqVO.setManufacturerName(null);
  160 + reqVO.setModel(null);
  161 + reqVO.setDataFormat(null);
  162 + reqVO.setProtocolType(null);
  163 + reqVO.setDescription(null);
  164 + reqVO.setStatus(null);
  165 + reqVO.setMetadata(null);
  166 + reqVO.setMessageProtocol(null);
  167 + reqVO.setProtocolName(null);
  168 + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
  169 +
  170 + // 调用
  171 + PageResult<ProductDO> pageResult = productService.getProductPage(reqVO);
  172 + // 断言
  173 + assertEquals(1, pageResult.getTotal());
  174 + assertEquals(1, pageResult.getList().size());
  175 + assertPojoEquals(dbProduct, pageResult.getList().get(0));
  176 + }
  177 +
  178 +}
0 179 \ No newline at end of file
... ...
yudao-server/pom.xml
... ... @@ -46,11 +46,11 @@
46 46 <!-- <version>${revision}</version>-->
47 47 <!-- </dependency>-->
48 48 <!-- 工作流。默认注释,保证编译速度 -->
49   - <!-- <dependency>-->
50   - <!-- <groupId>cn.iocoder.boot</groupId>-->
51   - <!-- <artifactId>yudao-module-bpm-biz</artifactId>-->
52   - <!-- <version>${revision}</version>-->
53   - <!-- </dependency>-->
  49 + <dependency>
  50 + <groupId>cn.iocoder.boot</groupId>
  51 + <artifactId>yudao-module-bpm-biz</artifactId>
  52 + <version>${revision}</version>
  53 + </dependency>
54 54 <!-- 支付服务。默认注释,保证编译速度 -->
55 55 <!-- <dependency>-->
56 56 <!-- <groupId>cn.iocoder.boot</groupId>-->
... ... @@ -88,11 +88,11 @@
88 88 <!-- </dependency>-->
89 89  
90 90 <!-- CRM 相关模块。默认注释,保证编译速度 -->
91   - <!-- <dependency>-->
92   - <!-- <groupId>cn.iocoder.boot</groupId>-->
93   - <!-- <artifactId>yudao-module-crm-biz</artifactId>-->
94   - <!-- <version>${revision}</version>-->
95   - <!-- </dependency>-->
  91 + <dependency>
  92 + <groupId>cn.iocoder.boot</groupId>
  93 + <artifactId>yudao-module-crm-biz</artifactId>
  94 + <version>${revision}</version>
  95 + </dependency>
96 96  
97 97 <!-- ERP 相关模块。默认注释,保证编译速度 -->
98 98 <!-- <dependency>-->
... ...
yudao-server/src/main/resources/application-local.yaml
... ... @@ -174,6 +174,7 @@ logging:
174 174 cn.iocoder.yudao.module.statistics.dal.mysql: debug
175 175 cn.iocoder.yudao.module.crm.dal.mysql: debug
176 176 cn.iocoder.yudao.module.erp.dal.mysql: debug
  177 + cn.iocoder.yudao.module.iot.dal.mysql: debug
177 178 org.springframework.context.support.PostProcessorRegistrationDelegate: ERROR # TODO 芋艿:先禁用,Spring Boot 3.X 存在部分错误的 WARN 提示
178 179  
179 180 debug: false
... ...