Commit 3a2c691af085c4e649373961e827627b8fcfaf9a
1 parent
ce919d12
【功能新增】IoT:产品分类的维护
Showing
10 changed files
with
369 additions
and
4 deletions
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java
| @@ -9,20 +9,20 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; | @@ -9,20 +9,20 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; | ||
| 9 | */ | 9 | */ |
| 10 | public interface ErrorCodeConstants { | 10 | public interface ErrorCodeConstants { |
| 11 | 11 | ||
| 12 | - // ========== IoT 产品相关 1-050-001-000 ============ | 12 | + // ========== 产品相关 1-050-001-000 ============ |
| 13 | ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(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, "产品标识已经存在"); | 14 | ErrorCode PRODUCT_IDENTIFICATION_EXISTS = new ErrorCode(1_050_001_001, "产品标识已经存在"); |
| 15 | ErrorCode PRODUCT_STATUS_NOT_DELETE = new ErrorCode(1_050_001_002, "产品状是发布状态,不允许删除"); | 15 | ErrorCode PRODUCT_STATUS_NOT_DELETE = new ErrorCode(1_050_001_002, "产品状是发布状态,不允许删除"); |
| 16 | ErrorCode PRODUCT_STATUS_NOT_ALLOW_FUNCTION = new ErrorCode(1_050_001_003, "产品状是发布状态,不允许操作物模型"); | 16 | ErrorCode PRODUCT_STATUS_NOT_ALLOW_FUNCTION = new ErrorCode(1_050_001_003, "产品状是发布状态,不允许操作物模型"); |
| 17 | 17 | ||
| 18 | - // ========== IoT 产品物模型 1-050-002-000 ============ | 18 | + // ========== 产品物模型 1-050-002-000 ============ |
| 19 | ErrorCode THINK_MODEL_FUNCTION_NOT_EXISTS = new ErrorCode(1_050_002_000, "产品物模型不存在"); | 19 | ErrorCode THINK_MODEL_FUNCTION_NOT_EXISTS = new ErrorCode(1_050_002_000, "产品物模型不存在"); |
| 20 | ErrorCode THINK_MODEL_FUNCTION_EXISTS_BY_PRODUCT_KEY = new ErrorCode(1_050_002_001, "ProductKey 对应的产品物模型已存在"); | 20 | ErrorCode THINK_MODEL_FUNCTION_EXISTS_BY_PRODUCT_KEY = new ErrorCode(1_050_002_001, "ProductKey 对应的产品物模型已存在"); |
| 21 | ErrorCode THINK_MODEL_FUNCTION_IDENTIFIER_EXISTS = new ErrorCode(1_050_002_002, "存在重复的功能标识符。"); | 21 | ErrorCode THINK_MODEL_FUNCTION_IDENTIFIER_EXISTS = new ErrorCode(1_050_002_002, "存在重复的功能标识符。"); |
| 22 | ErrorCode THINK_MODEL_FUNCTION_NAME_EXISTS = new ErrorCode(1_050_002_003, "存在重复的功能名称。"); | 22 | ErrorCode THINK_MODEL_FUNCTION_NAME_EXISTS = new ErrorCode(1_050_002_003, "存在重复的功能名称。"); |
| 23 | ErrorCode THINK_MODEL_FUNCTION_IDENTIFIER_INVALID = new ErrorCode(1_050_002_003, "产品物模型标识无效"); | 23 | ErrorCode THINK_MODEL_FUNCTION_IDENTIFIER_INVALID = new ErrorCode(1_050_002_003, "产品物模型标识无效"); |
| 24 | 24 | ||
| 25 | - // ========== IoT 设备 1-050-003-000 ============ | 25 | + // ========== 设备 1-050-003-000 ============ |
| 26 | ErrorCode DEVICE_NOT_EXISTS = new ErrorCode(1_050_003_000, "设备不存在"); | 26 | ErrorCode DEVICE_NOT_EXISTS = new ErrorCode(1_050_003_000, "设备不存在"); |
| 27 | ErrorCode DEVICE_NAME_EXISTS = new ErrorCode(1_050_003_001, "设备名称在同一产品下必须唯一"); | 27 | ErrorCode DEVICE_NAME_EXISTS = new ErrorCode(1_050_003_001, "设备名称在同一产品下必须唯一"); |
| 28 | ErrorCode DEVICE_HAS_CHILDREN = new ErrorCode(1_050_003_002, "有子设备,不允许删除"); | 28 | ErrorCode DEVICE_HAS_CHILDREN = new ErrorCode(1_050_003_002, "有子设备,不允许删除"); |
| @@ -30,4 +30,7 @@ public interface ErrorCodeConstants { | @@ -30,4 +30,7 @@ public interface ErrorCodeConstants { | ||
| 30 | ErrorCode DEVICE_PRODUCT_CANNOT_BE_MODIFIED = new ErrorCode(1_050_003_004, "产品不能修改"); | 30 | ErrorCode DEVICE_PRODUCT_CANNOT_BE_MODIFIED = new ErrorCode(1_050_003_004, "产品不能修改"); |
| 31 | ErrorCode DEVICE_INVALID_DEVICE_STATUS = new ErrorCode(1_050_003_005, "无效的设备状态"); | 31 | ErrorCode DEVICE_INVALID_DEVICE_STATUS = new ErrorCode(1_050_003_005, "无效的设备状态"); |
| 32 | 32 | ||
| 33 | + // ========== 产品分类 1-050-004-000 ========== | ||
| 34 | + ErrorCode PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_050_004_000, "产品分类不存在"); | ||
| 35 | + | ||
| 33 | } | 36 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/IotProductCategoryController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.product; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 6 | +import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategoryPageReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategoryRespVO; | ||
| 8 | +import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategorySaveReqVO; | ||
| 9 | +import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO; | ||
| 10 | +import cn.iocoder.yudao.module.iot.service.product.IotProductCategoryService; | ||
| 11 | +import io.swagger.v3.oas.annotations.Operation; | ||
| 12 | +import io.swagger.v3.oas.annotations.Parameter; | ||
| 13 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 14 | +import jakarta.annotation.Resource; | ||
| 15 | +import jakarta.validation.Valid; | ||
| 16 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 17 | +import org.springframework.validation.annotation.Validated; | ||
| 18 | +import org.springframework.web.bind.annotation.*; | ||
| 19 | + | ||
| 20 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 21 | + | ||
| 22 | +@Tag(name = "管理后台 - IoT 产品分类") | ||
| 23 | +@RestController | ||
| 24 | +@RequestMapping("/iot/product-category") | ||
| 25 | +@Validated | ||
| 26 | +public class IotProductCategoryController { | ||
| 27 | + | ||
| 28 | + @Resource | ||
| 29 | + private IotProductCategoryService productCategoryService; | ||
| 30 | + | ||
| 31 | + @PostMapping("/create") | ||
| 32 | + @Operation(summary = "创建IoT 产品分类") | ||
| 33 | + @PreAuthorize("@ss.hasPermission('iot:product-category:create')") | ||
| 34 | + public CommonResult<Long> createProductCategory(@Valid @RequestBody IotProductCategorySaveReqVO createReqVO) { | ||
| 35 | + return success(productCategoryService.createProductCategory(createReqVO)); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + @PutMapping("/update") | ||
| 39 | + @Operation(summary = "更新IoT 产品分类") | ||
| 40 | + @PreAuthorize("@ss.hasPermission('iot:product-category:update')") | ||
| 41 | + public CommonResult<Boolean> updateProductCategory(@Valid @RequestBody IotProductCategorySaveReqVO updateReqVO) { | ||
| 42 | + productCategoryService.updateProductCategory(updateReqVO); | ||
| 43 | + return success(true); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + @DeleteMapping("/delete") | ||
| 47 | + @Operation(summary = "删除IoT 产品分类") | ||
| 48 | + @Parameter(name = "id", description = "编号", required = true) | ||
| 49 | + @PreAuthorize("@ss.hasPermission('iot:product-category:delete')") | ||
| 50 | + public CommonResult<Boolean> deleteProductCategory(@RequestParam("id") Long id) { | ||
| 51 | + productCategoryService.deleteProductCategory(id); | ||
| 52 | + return success(true); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + @GetMapping("/get") | ||
| 56 | + @Operation(summary = "获得IoT 产品分类") | ||
| 57 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | ||
| 58 | + @PreAuthorize("@ss.hasPermission('iot:product-category:query')") | ||
| 59 | + public CommonResult<IotProductCategoryRespVO> getProductCategory(@RequestParam("id") Long id) { | ||
| 60 | + IotProductCategoryDO productCategory = productCategoryService.getProductCategory(id); | ||
| 61 | + return success(BeanUtils.toBean(productCategory, IotProductCategoryRespVO.class)); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @GetMapping("/page") | ||
| 65 | + @Operation(summary = "获得IoT 产品分类分页") | ||
| 66 | + @PreAuthorize("@ss.hasPermission('iot:product-category:query')") | ||
| 67 | + public CommonResult<PageResult<IotProductCategoryRespVO>> getProductCategoryPage(@Valid IotProductCategoryPageReqVO pageReqVO) { | ||
| 68 | + PageResult<IotProductCategoryDO> pageResult = productCategoryService.getProductCategoryPage(pageReqVO); | ||
| 69 | + return success(BeanUtils.toBean(pageResult, IotProductCategoryRespVO.class)); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | +} | ||
| 0 | \ No newline at end of file | 73 | \ 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/IotProductSaveReqVO.java
| @@ -14,9 +14,13 @@ public class IotProductSaveReqVO { | @@ -14,9 +14,13 @@ public class IotProductSaveReqVO { | ||
| 14 | @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.AUTO, example = "1") | 14 | @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.AUTO, example = "1") |
| 15 | private Long id; | 15 | private Long id; |
| 16 | 16 | ||
| 17 | - @Schema(description = "产品Key", requiredMode = Schema.RequiredMode.AUTO, example = "12345abc") | 17 | + @Schema(description = "产品 Key", requiredMode = Schema.RequiredMode.AUTO, example = "12345abc") |
| 18 | private String productKey; | 18 | private String productKey; |
| 19 | 19 | ||
| 20 | + // TODO 芋艿:品类 | ||
| 21 | + | ||
| 22 | + // TODO 芋艿:【待确定】保活时长、产品图标、产品图片 | ||
| 23 | + | ||
| 20 | @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "温湿度") | 24 | @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "温湿度") |
| 21 | @NotEmpty(message = "产品名称不能为空") | 25 | @NotEmpty(message = "产品名称不能为空") |
| 22 | private String name; | 26 | private String name; |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/category/IotProductCategoryPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.product.vo.category; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.EqualsAndHashCode; | ||
| 7 | +import lombok.ToString; | ||
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 9 | + | ||
| 10 | +import java.time.LocalDateTime; | ||
| 11 | + | ||
| 12 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||
| 13 | + | ||
| 14 | +@Schema(description = "管理后台 - IoT 产品分类分页 Request VO") | ||
| 15 | +@Data | ||
| 16 | +@EqualsAndHashCode(callSuper = true) | ||
| 17 | +@ToString(callSuper = true) | ||
| 18 | +public class IotProductCategoryPageReqVO extends PageParam { | ||
| 19 | + | ||
| 20 | + @Schema(description = "分类名字", example = "王五") | ||
| 21 | + private String name; | ||
| 22 | + | ||
| 23 | + @Schema(description = "创建时间") | ||
| 24 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 25 | + private LocalDateTime[] createTime; | ||
| 26 | + | ||
| 27 | +} | ||
| 0 | \ No newline at end of file | 28 | \ 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/category/IotProductCategoryRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.product.vo.category; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | ||
| 4 | +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; | ||
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 6 | +import lombok.Data; | ||
| 7 | + | ||
| 8 | +import java.time.LocalDateTime; | ||
| 9 | + | ||
| 10 | +@Schema(description = "管理后台 - IoT 产品分类 Response VO") | ||
| 11 | +@Data | ||
| 12 | +public class IotProductCategoryRespVO { | ||
| 13 | + | ||
| 14 | + @Schema(description = "分类 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25284") | ||
| 15 | + private Long id; | ||
| 16 | + | ||
| 17 | + @Schema(description = "分类名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") | ||
| 18 | + private String name; | ||
| 19 | + | ||
| 20 | + @Schema(description = "分类排序") | ||
| 21 | + private Integer sort; | ||
| 22 | + | ||
| 23 | + @Schema(description = "分类状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 24 | + @DictFormat(DictTypeConstants.COMMON_STATUS) | ||
| 25 | + private Integer status; | ||
| 26 | + | ||
| 27 | + @Schema(description = "分类描述", example = "随便") | ||
| 28 | + private String description; | ||
| 29 | + | ||
| 30 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 31 | + private LocalDateTime createTime; | ||
| 32 | + | ||
| 33 | +} | ||
| 0 | \ No newline at end of file | 34 | \ 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/category/IotProductCategorySaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.product.vo.category; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import jakarta.validation.constraints.NotEmpty; | ||
| 5 | +import jakarta.validation.constraints.NotNull; | ||
| 6 | +import lombok.Data; | ||
| 7 | + | ||
| 8 | +@Schema(description = "管理后台 - IoT 产品分类新增/修改 Request VO") | ||
| 9 | +@Data | ||
| 10 | +public class IotProductCategorySaveReqVO { | ||
| 11 | + | ||
| 12 | + @Schema(description = "分类 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25284") | ||
| 13 | + private Long id; | ||
| 14 | + | ||
| 15 | + @Schema(description = "分类名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") | ||
| 16 | + @NotEmpty(message = "分类名字不能为空") | ||
| 17 | + private String name; | ||
| 18 | + | ||
| 19 | + @Schema(description = "分类排序") | ||
| 20 | + private Integer sort; | ||
| 21 | + | ||
| 22 | + @Schema(description = "分类状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 23 | + @NotNull(message = "分类状态不能为空") | ||
| 24 | + private Integer status; | ||
| 25 | + | ||
| 26 | + @Schema(description = "分类描述", example = "随便") | ||
| 27 | + private String description; | ||
| 28 | + | ||
| 29 | +} | ||
| 0 | \ No newline at end of file | 30 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/product/IotProductCategoryDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.dal.dataobject.product; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 4 | +import com.baomidou.mybatisplus.annotation.KeySequence; | ||
| 5 | +import com.baomidou.mybatisplus.annotation.TableId; | ||
| 6 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 7 | +import lombok.*; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * IoT 产品分类 DO | ||
| 11 | + * | ||
| 12 | + * @author 芋道源码 | ||
| 13 | + */ | ||
| 14 | +@TableName("iot_product_category") | ||
| 15 | +@KeySequence("iot_product_category_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | ||
| 16 | +@Data | ||
| 17 | +@EqualsAndHashCode(callSuper = true) | ||
| 18 | +@ToString(callSuper = true) | ||
| 19 | +@Builder | ||
| 20 | +@NoArgsConstructor | ||
| 21 | +@AllArgsConstructor | ||
| 22 | +public class IotProductCategoryDO extends BaseDO { | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 分类 ID | ||
| 26 | + */ | ||
| 27 | + @TableId | ||
| 28 | + private Long id; | ||
| 29 | + /** | ||
| 30 | + * 分类名字 | ||
| 31 | + */ | ||
| 32 | + private String name; | ||
| 33 | + /** | ||
| 34 | + * 分类排序 | ||
| 35 | + */ | ||
| 36 | + private Integer sort; | ||
| 37 | + /** | ||
| 38 | + * 分类状态 | ||
| 39 | + * | ||
| 40 | + * 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum} | ||
| 41 | + */ | ||
| 42 | + private Integer status; | ||
| 43 | + /** | ||
| 44 | + * 分类描述 | ||
| 45 | + */ | ||
| 46 | + private String description; | ||
| 47 | + | ||
| 48 | +} | ||
| 0 | \ No newline at end of file | 49 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/product/IotProductCategoryMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.dal.mysql.product; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 6 | +import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategoryPageReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO; | ||
| 8 | +import org.apache.ibatis.annotations.Mapper; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * IoT 产品分类 Mapper | ||
| 12 | + * | ||
| 13 | + * @author 芋道源码 | ||
| 14 | + */ | ||
| 15 | +@Mapper | ||
| 16 | +public interface IotProductCategoryMapper extends BaseMapperX<IotProductCategoryDO> { | ||
| 17 | + | ||
| 18 | + default PageResult<IotProductCategoryDO> selectPage(IotProductCategoryPageReqVO reqVO) { | ||
| 19 | + return selectPage(reqVO, new LambdaQueryWrapperX<IotProductCategoryDO>() | ||
| 20 | + .likeIfPresent(IotProductCategoryDO::getName, reqVO.getName()) | ||
| 21 | + .betweenIfPresent(IotProductCategoryDO::getCreateTime, reqVO.getCreateTime()) | ||
| 22 | + .orderByDesc(IotProductCategoryDO::getId)); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | +} | ||
| 0 | \ No newline at end of file | 26 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.service.product; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | +import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategoryPageReqVO; | ||
| 5 | +import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategorySaveReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO; | ||
| 7 | +import jakarta.validation.Valid; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * IoT 产品分类 Service 接口 | ||
| 11 | + * | ||
| 12 | + * @author 芋道源码 | ||
| 13 | + */ | ||
| 14 | +public interface IotProductCategoryService { | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 创建IoT 产品分类 | ||
| 18 | + * | ||
| 19 | + * @param createReqVO 创建信息 | ||
| 20 | + * @return 编号 | ||
| 21 | + */ | ||
| 22 | + Long createProductCategory(@Valid IotProductCategorySaveReqVO createReqVO); | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 更新IoT 产品分类 | ||
| 26 | + * | ||
| 27 | + * @param updateReqVO 更新信息 | ||
| 28 | + */ | ||
| 29 | + void updateProductCategory(@Valid IotProductCategorySaveReqVO updateReqVO); | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 删除IoT 产品分类 | ||
| 33 | + * | ||
| 34 | + * @param id 编号 | ||
| 35 | + */ | ||
| 36 | + void deleteProductCategory(Long id); | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 获得IoT 产品分类 | ||
| 40 | + * | ||
| 41 | + * @param id 编号 | ||
| 42 | + * @return IoT 产品分类 | ||
| 43 | + */ | ||
| 44 | + IotProductCategoryDO getProductCategory(Long id); | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 获得IoT 产品分类分页 | ||
| 48 | + * | ||
| 49 | + * @param pageReqVO 分页查询 | ||
| 50 | + * @return IoT 产品分类分页 | ||
| 51 | + */ | ||
| 52 | + PageResult<IotProductCategoryDO> getProductCategoryPage(IotProductCategoryPageReqVO pageReqVO); | ||
| 53 | + | ||
| 54 | +} | ||
| 0 | \ No newline at end of file | 55 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.service.product; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 5 | +import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategoryPageReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategorySaveReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO; | ||
| 8 | +import cn.iocoder.yudao.module.iot.dal.mysql.product.IotProductCategoryMapper; | ||
| 9 | +import jakarta.annotation.Resource; | ||
| 10 | +import org.springframework.stereotype.Service; | ||
| 11 | +import org.springframework.validation.annotation.Validated; | ||
| 12 | + | ||
| 13 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 14 | +import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.PRODUCT_CATEGORY_NOT_EXISTS; | ||
| 15 | + | ||
| 16 | +/** | ||
| 17 | + * IoT 产品分类 Service 实现类 | ||
| 18 | + * | ||
| 19 | + * @author 芋道源码 | ||
| 20 | + */ | ||
| 21 | +@Service | ||
| 22 | +@Validated | ||
| 23 | +public class IotProductCategoryServiceImpl implements IotProductCategoryService { | ||
| 24 | + | ||
| 25 | + @Resource | ||
| 26 | + private IotProductCategoryMapper productCategoryMapper; | ||
| 27 | + | ||
| 28 | + @Override | ||
| 29 | + public Long createProductCategory(IotProductCategorySaveReqVO createReqVO) { | ||
| 30 | + // 插入 | ||
| 31 | + IotProductCategoryDO productCategory = BeanUtils.toBean(createReqVO, IotProductCategoryDO.class); | ||
| 32 | + productCategoryMapper.insert(productCategory); | ||
| 33 | + // 返回 | ||
| 34 | + return productCategory.getId(); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + @Override | ||
| 38 | + public void updateProductCategory(IotProductCategorySaveReqVO updateReqVO) { | ||
| 39 | + // 校验存在 | ||
| 40 | + validateProductCategoryExists(updateReqVO.getId()); | ||
| 41 | + // 更新 | ||
| 42 | + IotProductCategoryDO updateObj = BeanUtils.toBean(updateReqVO, IotProductCategoryDO.class); | ||
| 43 | + productCategoryMapper.updateById(updateObj); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + @Override | ||
| 47 | + public void deleteProductCategory(Long id) { | ||
| 48 | + // 校验存在 | ||
| 49 | + validateProductCategoryExists(id); | ||
| 50 | + // 删除 | ||
| 51 | + productCategoryMapper.deleteById(id); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + private void validateProductCategoryExists(Long id) { | ||
| 55 | + if (productCategoryMapper.selectById(id) == null) { | ||
| 56 | + throw exception(PRODUCT_CATEGORY_NOT_EXISTS); | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + @Override | ||
| 61 | + public IotProductCategoryDO getProductCategory(Long id) { | ||
| 62 | + return productCategoryMapper.selectById(id); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + @Override | ||
| 66 | + public PageResult<IotProductCategoryDO> getProductCategoryPage(IotProductCategoryPageReqVO pageReqVO) { | ||
| 67 | + return productCategoryMapper.selectPage(pageReqVO); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | +} | ||
| 0 | \ No newline at end of file | 71 | \ No newline at end of file |