Zimo 13 godzin temu
rodzic
commit
9d6156514b

+ 94 - 0
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/ThingModelCommonController.java

@@ -0,0 +1,94 @@
+package cn.iocoder.yudao.module.iot.controller.admin.thingmodel;
+
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.ThingModelCommonPageReqVO;
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.ThingModelCommonRespVO;
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.ThingModelCommonSaveReqVO;
+import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.ThingModelCommonDO;
+import cn.iocoder.yudao.module.iot.service.thingmodel.ThingModelCommonService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import javax.validation.Valid;
+import java.io.IOException;
+import java.util.List;
+
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+
+
+@Tag(name = "管理后台 - IoT通用物模型")
+@RestController
+@RequestMapping("/iot/thing-model-common")
+@Validated
+public class ThingModelCommonController {
+
+    @Resource
+    private ThingModelCommonService thingModelCommonService;
+
+    @PostMapping("/create")
+    @Operation(summary = "创建IoT通用物模型")
+    @PreAuthorize("@ss.hasPermission('iot:thing-model-common:create')")
+    public CommonResult<Long> createThingModelCommon(@Valid @RequestBody ThingModelCommonSaveReqVO createReqVO) {
+        return success(thingModelCommonService.createThingModelCommon(createReqVO));
+    }
+
+    @PutMapping("/update")
+    @Operation(summary = "更新IoT通用物模型")
+    @PreAuthorize("@ss.hasPermission('iot:thing-model-common:update')")
+    public CommonResult<Boolean> updateThingModelCommon(@Valid @RequestBody ThingModelCommonSaveReqVO updateReqVO) {
+        thingModelCommonService.updateThingModelCommon(updateReqVO);
+        return success(true);
+    }
+
+    @DeleteMapping("/delete")
+    @Operation(summary = "删除IoT通用物模型")
+    @Parameter(name = "id", description = "编号", required = true)
+    @PreAuthorize("@ss.hasPermission('iot:thing-model-common:delete')")
+    public CommonResult<Boolean> deleteThingModelCommon(@RequestParam("id") Long id) {
+        thingModelCommonService.deleteThingModelCommon(id);
+        return success(true);
+    }
+
+    @GetMapping("/get")
+    @Operation(summary = "获得IoT通用物模型")
+    @Parameter(name = "id", description = "编号", required = true, example = "1024")
+    @PreAuthorize("@ss.hasPermission('iot:thing-model-common:query')")
+    public CommonResult<ThingModelCommonRespVO> getThingModelCommon(@RequestParam("id") Long id) {
+        ThingModelCommonDO thingModelCommon = thingModelCommonService.getThingModelCommon(id);
+        return success(BeanUtils.toBean(thingModelCommon, ThingModelCommonRespVO.class));
+    }
+
+    @GetMapping("/page")
+    @Operation(summary = "获得IoT通用物模型分页")
+    @PreAuthorize("@ss.hasPermission('iot:thing-model-common:query')")
+    public CommonResult<PageResult<ThingModelCommonRespVO>> getThingModelCommonPage(@Valid ThingModelCommonPageReqVO pageReqVO) {
+        PageResult<ThingModelCommonDO> pageResult = thingModelCommonService.getThingModelCommonPage(pageReqVO);
+        return success(BeanUtils.toBean(pageResult, ThingModelCommonRespVO.class));
+    }
+
+    @GetMapping("/export-excel")
+    @Operation(summary = "导出IoT通用物模型 Excel")
+    @PreAuthorize("@ss.hasPermission('iot:thing-model-common:export')")
+    @ApiAccessLog(operateType = EXPORT)
+    public void exportThingModelCommonExcel(@Valid ThingModelCommonPageReqVO pageReqVO,
+              HttpServletResponse response) throws IOException {
+        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        List<ThingModelCommonDO> list = thingModelCommonService.getThingModelCommonPage(pageReqVO).getList();
+        // 导出 Excel
+        ExcelUtils.write(response, "IoT通用物模型.xls", "数据", ThingModelCommonRespVO.class,
+                        BeanUtils.toBean(list, ThingModelCommonRespVO.class));
+    }
+
+}

+ 45 - 0
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/ThingModelCommonPageReqVO.java

@@ -0,0 +1,45 @@
+package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo;
+
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.time.LocalDateTime;
+
+import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
+
+@Schema(description = "管理后台 - IoT通用物模型分页 Request VO")
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+public class ThingModelCommonPageReqVO extends PageParam {
+
+    @Schema(description = "功能标识")
+    private String identifier;
+
+    @Schema(description = "功能名称", example = "赵六")
+    private String name;
+
+    @Schema(description = "功能描述", example = "你猜")
+    private String description;
+
+    @Schema(description = "功能类型(1 - 属性,2 - 服务,3 - 事件)", example = "1")
+    private Integer type;
+
+    @Schema(description = "属性(存储 ThingModelProperty 的 JSON 数据)")
+    private String property;
+
+    @Schema(description = "事件(存储 ThingModelEvent 的 JSON 数据)")
+    private String event;
+
+    @Schema(description = "服务(存储服务的 JSON 数据)")
+    private String service;
+
+    @Schema(description = "创建时间")
+    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+    private LocalDateTime[] createTime;
+
+}

+ 51 - 0
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/ThingModelCommonRespVO.java

@@ -0,0 +1,51 @@
+package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo;
+
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
+import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+@Schema(description = "管理后台 - IoT通用物模型 Response VO")
+@Data
+@ExcelIgnoreUnannotated
+public class ThingModelCommonRespVO {
+
+    @Schema(description = "物模型功能编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20707")
+    @ExcelProperty("物模型功能编号")
+    private Long id;
+
+    @Schema(description = "功能标识", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("功能标识")
+    private String identifier;
+
+    @Schema(description = "功能名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
+    @ExcelProperty("功能名称")
+    private String name;
+
+    @Schema(description = "功能描述", example = "你猜")
+    @ExcelProperty("功能描述")
+    private String description;
+
+    @Schema(description = "功能类型(1 - 属性,2 - 服务,3 - 事件)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
+    @ExcelProperty("功能类型(1 - 属性,2 - 服务,3 - 事件)")
+    private Integer type;
+
+    @Schema(description = "属性(存储 ThingModelProperty 的 JSON 数据)")
+    @ExcelProperty("属性(存储 ThingModelProperty 的 JSON 数据)")
+    private String property;
+
+    @Schema(description = "事件(存储 ThingModelEvent 的 JSON 数据)")
+    @ExcelProperty("事件(存储 ThingModelEvent 的 JSON 数据)")
+    private String event;
+
+    @Schema(description = "服务(存储服务的 JSON 数据)")
+    @ExcelProperty("服务(存储服务的 JSON 数据)")
+    private String service;
+
+    @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("创建时间")
+    private LocalDateTime createTime;
+
+}

+ 40 - 0
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/ThingModelCommonSaveReqVO.java

@@ -0,0 +1,40 @@
+package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+
+@Schema(description = "管理后台 - IoT通用物模型新增/修改 Request VO")
+@Data
+public class ThingModelCommonSaveReqVO {
+
+    @Schema(description = "物模型功能编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20707")
+    private Long id;
+
+    @Schema(description = "功能标识", requiredMode = Schema.RequiredMode.REQUIRED)
+    @NotEmpty(message = "功能标识不能为空")
+    private String identifier;
+
+    @Schema(description = "功能名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
+    @NotEmpty(message = "功能名称不能为空")
+    private String name;
+
+    @Schema(description = "功能描述", example = "你猜")
+    private String description;
+
+    @Schema(description = "功能类型(1 - 属性,2 - 服务,3 - 事件)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
+    @NotNull(message = "功能类型(1 - 属性,2 - 服务,3 - 事件)不能为空")
+    private Integer type;
+
+    @Schema(description = "属性(存储 ThingModelProperty 的 JSON 数据)")
+    private String property;
+
+    @Schema(description = "事件(存储 ThingModelEvent 的 JSON 数据)")
+    private String event;
+
+    @Schema(description = "服务(存储服务的 JSON 数据)")
+    private String service;
+
+}

+ 58 - 0
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/thingmodel/ThingModelCommonDO.java

@@ -0,0 +1,58 @@
+package cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel;
+
+import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
+import com.baomidou.mybatisplus.annotation.KeySequence;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.*;
+
+/**
+ * IoT通用物模型 DO
+ *
+ * @author 超级管理员
+ */
+@TableName("iot_thing_model_common")
+@KeySequence("iot_thing_model_common_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class ThingModelCommonDO extends BaseDO {
+
+    /**
+     * 物模型功能编号
+     */
+    @TableId
+    private Long id;
+    /**
+     * 功能标识
+     */
+    private String identifier;
+    /**
+     * 功能名称
+     */
+    private String name;
+    /**
+     * 功能描述
+     */
+    private String description;
+    /**
+     * 功能类型(1 - 属性,2 - 服务,3 - 事件)
+     */
+    private Integer type;
+    /**
+     * 属性(存储 ThingModelProperty 的 JSON 数据)
+     */
+    private String property;
+    /**
+     * 事件(存储 ThingModelEvent 的 JSON 数据)
+     */
+    private String event;
+    /**
+     * 服务(存储服务的 JSON 数据)
+     */
+    private String service;
+
+}

+ 31 - 0
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thingmodel/ThingModelCommonMapper.java

@@ -0,0 +1,31 @@
+package cn.iocoder.yudao.module.iot.dal.mysql.thingmodel;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
+import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.ThingModelCommonPageReqVO;
+import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.ThingModelCommonDO;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * IoT通用物模型 Mapper
+ *
+ * @author 超级管理员
+ */
+@Mapper
+public interface ThingModelCommonMapper extends BaseMapperX<ThingModelCommonDO> {
+
+    default PageResult<ThingModelCommonDO> selectPage(ThingModelCommonPageReqVO reqVO) {
+        return selectPage(reqVO, new LambdaQueryWrapperX<ThingModelCommonDO>()
+                .eqIfPresent(ThingModelCommonDO::getIdentifier, reqVO.getIdentifier())
+                .likeIfPresent(ThingModelCommonDO::getName, reqVO.getName())
+                .eqIfPresent(ThingModelCommonDO::getDescription, reqVO.getDescription())
+                .eqIfPresent(ThingModelCommonDO::getType, reqVO.getType())
+                .eqIfPresent(ThingModelCommonDO::getProperty, reqVO.getProperty())
+                .eqIfPresent(ThingModelCommonDO::getEvent, reqVO.getEvent())
+                .eqIfPresent(ThingModelCommonDO::getService, reqVO.getService())
+                .betweenIfPresent(ThingModelCommonDO::getCreateTime, reqVO.getCreateTime())
+                .orderByDesc(ThingModelCommonDO::getId));
+    }
+
+}

+ 55 - 0
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/ThingModelCommonService.java

@@ -0,0 +1,55 @@
+package cn.iocoder.yudao.module.iot.service.thingmodel;
+
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.ThingModelCommonPageReqVO;
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.ThingModelCommonSaveReqVO;
+import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.ThingModelCommonDO;
+
+import javax.validation.Valid;
+
+/**
+ * IoT通用物模型 Service 接口
+ *
+ * @author 超级管理员
+ */
+public interface ThingModelCommonService {
+
+    /**
+     * 创建IoT通用物模型
+     *
+     * @param createReqVO 创建信息
+     * @return 编号
+     */
+    Long createThingModelCommon(@Valid ThingModelCommonSaveReqVO createReqVO);
+
+    /**
+     * 更新IoT通用物模型
+     *
+     * @param updateReqVO 更新信息
+     */
+    void updateThingModelCommon(@Valid ThingModelCommonSaveReqVO updateReqVO);
+
+    /**
+     * 删除IoT通用物模型
+     *
+     * @param id 编号
+     */
+    void deleteThingModelCommon(Long id);
+
+    /**
+     * 获得IoT通用物模型
+     *
+     * @param id 编号
+     * @return IoT通用物模型
+     */
+    ThingModelCommonDO getThingModelCommon(Long id);
+
+    /**
+     * 获得IoT通用物模型分页
+     *
+     * @param pageReqVO 分页查询
+     * @return IoT通用物模型分页
+     */
+    PageResult<ThingModelCommonDO> getThingModelCommonPage(ThingModelCommonPageReqVO pageReqVO);
+
+}

+ 72 - 0
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/ThingModelCommonServiceImpl.java

@@ -0,0 +1,72 @@
+package cn.iocoder.yudao.module.iot.service.thingmodel;
+
+import cn.iocoder.yudao.framework.common.exception.ErrorCode;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.ThingModelCommonPageReqVO;
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.ThingModelCommonSaveReqVO;
+import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.ThingModelCommonDO;
+import cn.iocoder.yudao.module.iot.dal.mysql.thingmodel.ThingModelCommonMapper;
+import org.springframework.stereotype.Service;
+import org.springframework.validation.annotation.Validated;
+
+import javax.annotation.Resource;
+
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
+
+/**
+ * IoT通用物模型 Service 实现类
+ *
+ * @author 超级管理员
+ */
+@Service
+@Validated
+public class ThingModelCommonServiceImpl implements ThingModelCommonService {
+
+    @Resource
+    private ThingModelCommonMapper thingModelCommonMapper;
+
+    @Override
+    public Long createThingModelCommon(ThingModelCommonSaveReqVO createReqVO) {
+        // 插入
+        ThingModelCommonDO thingModelCommon = BeanUtils.toBean(createReqVO, ThingModelCommonDO.class);
+        thingModelCommon.setDeleted(false);
+        thingModelCommonMapper.insert(thingModelCommon);
+        // 返回
+        return thingModelCommon.getId();
+    }
+
+    @Override
+    public void updateThingModelCommon(ThingModelCommonSaveReqVO updateReqVO) {
+        // 校验存在
+        validateThingModelCommonExists(updateReqVO.getId());
+        // 更新
+        ThingModelCommonDO updateObj = BeanUtils.toBean(updateReqVO, ThingModelCommonDO.class);
+        thingModelCommonMapper.updateById(updateObj);
+    }
+
+    @Override
+    public void deleteThingModelCommon(Long id) {
+        // 校验存在
+        validateThingModelCommonExists(id);
+        // 删除
+        thingModelCommonMapper.deleteById(id);
+    }
+
+    private void validateThingModelCommonExists(Long id) {
+        if (thingModelCommonMapper.selectById(id) == null) {
+            throw exception(new ErrorCode(1,"不存在"));
+        }
+    }
+
+    @Override
+    public ThingModelCommonDO getThingModelCommon(Long id) {
+        return thingModelCommonMapper.selectById(id);
+    }
+
+    @Override
+    public PageResult<ThingModelCommonDO> getThingModelCommonPage(ThingModelCommonPageReqVO pageReqVO) {
+        return thingModelCommonMapper.selectPage(pageReqVO);
+    }
+
+}