Commit b143bc177f8fccb778eb60a2f470cc99f33a77a2

Authored by YunaiV
1 parent 9041de2d

【功能新增】IoT:设备分组的管理

yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java
@@ -33,4 +33,7 @@ public interface ErrorCodeConstants { @@ -33,4 +33,7 @@ public interface ErrorCodeConstants {
33 // ========== 产品分类 1-050-004-000 ========== 33 // ========== 产品分类 1-050-004-000 ==========
34 ErrorCode PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_050_004_000, "产品分类不存在"); 34 ErrorCode PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_050_004_000, "产品分类不存在");
35 35
  36 + // ========== 设备分组 1-050-005-000 ==========
  37 + ErrorCode DEVICE_GROUP_NOT_EXISTS = new ErrorCode(1_050_005_000, "设备分组不存在");
  38 +
36 } 39 }
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/group/IotDeviceGroupPageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.device.vo.group;
  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 IotDeviceGroupPageReqVO 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/device/vo/group/IotDeviceGroupRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.device.vo.group;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +import java.time.LocalDateTime;
  7 +
  8 +@Schema(description = "管理后台 - IoT 设备分组 Response VO")
  9 +@Data
  10 +public class IotDeviceGroupRespVO {
  11 +
  12 + @Schema(description = "分组 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "3583")
  13 + private Long id;
  14 +
  15 + @Schema(description = "分组名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
  16 + private String name;
  17 +
  18 + @Schema(description = "分组状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  19 + private Integer status;
  20 +
  21 + @Schema(description = "分组描述", example = "你说的对")
  22 + private String description;
  23 +
  24 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  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/device/vo/group/IotDeviceGroupSaveReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.controller.admin.device.vo.group;
  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 IotDeviceGroupSaveReqVO {
  11 +
  12 + @Schema(description = "分组 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "3583")
  13 + private Long id;
  14 +
  15 + @Schema(description = "分组名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
  16 + @NotEmpty(message = "分组名字不能为空")
  17 + private String name;
  18 +
  19 + @Schema(description = "分组状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  20 + @NotNull(message = "分组状态不能为空")
  21 + private Integer status;
  22 +
  23 + @Schema(description = "分组描述", example = "你说的对")
  24 + private String description;
  25 +
  26 +}
0 \ No newline at end of file 27 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceGroupDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.dal.dataobject.device;
  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_device_group")
  15 +@KeySequence("iot_device_group_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 IotDeviceGroupDO extends BaseDO {
  23 +
  24 + /**
  25 + * 分组 ID
  26 + */
  27 + @TableId
  28 + private Long id;
  29 + /**
  30 + * 分组名字
  31 + */
  32 + private String name;
  33 + /**
  34 + * 分组状态
  35 + *
  36 + * 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum}
  37 + */
  38 + private Integer status;
  39 + /**
  40 + * 分组描述
  41 + */
  42 + private String description;
  43 +
  44 +}
0 \ No newline at end of file 45 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceGroupMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.dal.mysql.device;
  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.device.vo.group.IotDeviceGroupPageReqVO;
  7 +import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceGroupDO;
  8 +import org.apache.ibatis.annotations.Mapper;
  9 +
  10 +/**
  11 + * IoT 设备分组 Mapper
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@Mapper
  16 +public interface IotDeviceGroupMapper extends BaseMapperX<IotDeviceGroupDO> {
  17 +
  18 + default PageResult<IotDeviceGroupDO> selectPage(IotDeviceGroupPageReqVO reqVO) {
  19 + return selectPage(reqVO, new LambdaQueryWrapperX<IotDeviceGroupDO>()
  20 + .likeIfPresent(IotDeviceGroupDO::getName, reqVO.getName())
  21 + .betweenIfPresent(IotDeviceGroupDO::getCreateTime, reqVO.getCreateTime())
  22 + .orderByDesc(IotDeviceGroupDO::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/device/IotDeviceGroupService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.service.device;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.group.IotDeviceGroupPageReqVO;
  5 +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.group.IotDeviceGroupSaveReqVO;
  6 +import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceGroupDO;
  7 +import jakarta.validation.Valid;
  8 +
  9 +/**
  10 + * IoT 设备分组 Service 接口
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +public interface IotDeviceGroupService {
  15 +
  16 + /**
  17 + * 创建IoT 设备分组
  18 + *
  19 + * @param createReqVO 创建信息
  20 + * @return 编号
  21 + */
  22 + Long createDeviceGroup(@Valid IotDeviceGroupSaveReqVO createReqVO);
  23 +
  24 + /**
  25 + * 更新IoT 设备分组
  26 + *
  27 + * @param updateReqVO 更新信息
  28 + */
  29 + void updateDeviceGroup(@Valid IotDeviceGroupSaveReqVO updateReqVO);
  30 +
  31 + /**
  32 + * 删除IoT 设备分组
  33 + *
  34 + * @param id 编号
  35 + */
  36 + void deleteDeviceGroup(Long id);
  37 +
  38 + /**
  39 + * 获得IoT 设备分组
  40 + *
  41 + * @param id 编号
  42 + * @return IoT 设备分组
  43 + */
  44 + IotDeviceGroupDO getDeviceGroup(Long id);
  45 +
  46 + /**
  47 + * 获得IoT 设备分组分页
  48 + *
  49 + * @param pageReqVO 分页查询
  50 + * @return IoT 设备分组分页
  51 + */
  52 + PageResult<IotDeviceGroupDO> getDeviceGroupPage(IotDeviceGroupPageReqVO 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/device/IotDeviceGroupServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.service.device;
  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.device.vo.group.IotDeviceGroupPageReqVO;
  6 +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.group.IotDeviceGroupSaveReqVO;
  7 +import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceGroupDO;
  8 +import cn.iocoder.yudao.module.iot.dal.mysql.device.IotDeviceGroupMapper;
  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.DEVICE_GROUP_NOT_EXISTS;
  15 +
  16 +/**
  17 + * IoT 设备分组 Service 实现类
  18 + *
  19 + * @author 芋道源码
  20 + */
  21 +@Service
  22 +@Validated
  23 +public class IotDeviceGroupServiceImpl implements IotDeviceGroupService {
  24 +
  25 + @Resource
  26 + private IotDeviceGroupMapper deviceGroupMapper;
  27 +
  28 + @Override
  29 + public Long createDeviceGroup(IotDeviceGroupSaveReqVO createReqVO) {
  30 + // 插入
  31 + IotDeviceGroupDO deviceGroup = BeanUtils.toBean(createReqVO, IotDeviceGroupDO.class);
  32 + deviceGroupMapper.insert(deviceGroup);
  33 + // 返回
  34 + return deviceGroup.getId();
  35 + }
  36 +
  37 + @Override
  38 + public void updateDeviceGroup(IotDeviceGroupSaveReqVO updateReqVO) {
  39 + // 校验存在
  40 + validateDeviceGroupExists(updateReqVO.getId());
  41 + // 更新
  42 + IotDeviceGroupDO updateObj = BeanUtils.toBean(updateReqVO, IotDeviceGroupDO.class);
  43 + deviceGroupMapper.updateById(updateObj);
  44 + }
  45 +
  46 + @Override
  47 + public void deleteDeviceGroup(Long id) {
  48 + // 校验存在
  49 + validateDeviceGroupExists(id);
  50 + // 删除
  51 + deviceGroupMapper.deleteById(id);
  52 + }
  53 +
  54 + private void validateDeviceGroupExists(Long id) {
  55 + if (deviceGroupMapper.selectById(id) == null) {
  56 + throw exception(DEVICE_GROUP_NOT_EXISTS);
  57 + }
  58 + }
  59 +
  60 + @Override
  61 + public IotDeviceGroupDO getDeviceGroup(Long id) {
  62 + return deviceGroupMapper.selectById(id);
  63 + }
  64 +
  65 + @Override
  66 + public PageResult<IotDeviceGroupDO> getDeviceGroupPage(IotDeviceGroupPageReqVO pageReqVO) {
  67 + return deviceGroupMapper.selectPage(pageReqVO);
  68 + }
  69 +
  70 +}
0 \ No newline at end of file 71 \ No newline at end of file