소스 검색

导入五模型

Zimo 4 일 전
부모
커밋
bae5c47e4e

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

@@ -1,11 +1,16 @@
 package cn.iocoder.yudao.module.iot.controller.admin.thingmodel;
 
+import cn.iocoder.yudao.framework.common.exception.ErrorCode;
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 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.*;
 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
 import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO;
+import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.ThingModelCommonDO;
+import cn.iocoder.yudao.module.iot.dal.mysql.thingmodel.IotThingModelMapper;
+import cn.iocoder.yudao.module.iot.dal.mysql.thingmodel.ThingModelCommonMapper;
 import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelTypeEnum;
 import cn.iocoder.yudao.module.iot.service.product.IotProductService;
 import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService;
@@ -13,6 +18,7 @@ import com.google.common.base.Objects;
 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.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
@@ -35,6 +41,10 @@ public class IotThingModelController {
     private IotThingModelService thingModelService;
     @Resource
     private IotProductService productService;
+    @Autowired
+    private ThingModelCommonMapper thingModelCommonMapper;
+    @Autowired
+    private IotThingModelMapper iotThingModelMapper;
 
     @PostMapping("/create")
     @Operation(summary = "创建产品物模型")
@@ -108,4 +118,20 @@ public class IotThingModelController {
         return success(BeanUtils.toBean(pageResult, IotThingModelRespVO.class));
     }
 
+
+
+    @GetMapping("/import-common")
+    @Operation(summary = "产品导入通用物模型")
+    public CommonResult<String> importCommon(Long commonId, Long productId) {
+        ThingModelCommonDO thingModelCommonDO = thingModelCommonMapper.selectById(commonId);
+        if (thingModelCommonDO == null) {
+            throw new ServiceException(new ErrorCode(2, "不存在通用物模型"));
+        }
+        IotThingModelDO iotThingModelDO = new IotThingModelDO();
+        BeanUtils.copyProperties(thingModelCommonDO, iotThingModelDO);
+        iotThingModelDO.setProductId(productId);
+        iotThingModelDO.setDeleted(false);
+        iotThingModelMapper.insert(iotThingModelDO);
+        return success("导入成功");
+    }
 }

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

@@ -1,5 +1,8 @@
 package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo;
 
+import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.model.ThingModelEvent;
+import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.model.ThingModelProperty;
+import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.model.ThingModelService;
 import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
 import com.alibaba.excel.annotation.ExcelProperty;
 import io.swagger.v3.oas.annotations.media.Schema;
@@ -32,17 +35,14 @@ public class ThingModelCommonRespVO {
     @ExcelProperty("功能类型(1 - 属性,2 - 服务,3 - 事件)")
     private Integer type;
 
-    @Schema(description = "属性(存储 ThingModelProperty 的 JSON 数据)")
-    @ExcelProperty("属性(存储 ThingModelProperty 的 JSON 数据)")
-    private String property;
+    @Schema(description = "属性", requiredMode = Schema.RequiredMode.REQUIRED)
+    private ThingModelProperty property;
 
-    @Schema(description = "事件(存储 ThingModelEvent 的 JSON 数据)")
-    @ExcelProperty("事件(存储 ThingModelEvent 的 JSON 数据)")
-    private String event;
+    @Schema(description = "服务", requiredMode = Schema.RequiredMode.REQUIRED)
+    private ThingModelEvent event;
 
-    @Schema(description = "服务(存储服务的 JSON 数据)")
-    @ExcelProperty("服务(存储服务的 JSON 数据)")
-    private String service;
+    @Schema(description = "事件", requiredMode = Schema.RequiredMode.REQUIRED)
+    private ThingModelService service;
 
     @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
     @ExcelProperty("创建时间")

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

@@ -1,8 +1,12 @@
 package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo;
 
+import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.model.ThingModelEvent;
+import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.model.ThingModelProperty;
+import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.model.ThingModelService;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
+import javax.validation.Valid;
 import javax.validation.constraints.NotEmpty;
 import javax.validation.constraints.NotNull;
 
@@ -28,13 +32,16 @@ public class ThingModelCommonSaveReqVO {
     @NotNull(message = "功能类型(1 - 属性,2 - 服务,3 - 事件)不能为空")
     private Integer type;
 
-    @Schema(description = "属性(存储 ThingModelProperty 的 JSON 数据)")
-    private String property;
+    @Schema(description = "属性", requiredMode = Schema.RequiredMode.REQUIRED)
+    @Valid
+    private ThingModelProperty property;
 
-    @Schema(description = "事件(存储 ThingModelEvent 的 JSON 数据)")
-    private String event;
+    @Schema(description = "服务", requiredMode = Schema.RequiredMode.REQUIRED)
+    @Valid
+    private ThingModelService service;
 
-    @Schema(description = "服务(存储服务的 JSON 数据)")
-    private String service;
+    @Schema(description = "事件", requiredMode = Schema.RequiredMode.REQUIRED)
+    @Valid
+    private ThingModelEvent event;
 
 }

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

@@ -16,7 +16,7 @@ import lombok.*;
  *
  * @author 超级管理员
  */
-@TableName("iot_thing_model_common")
+@TableName(value = "iot_thing_model_common", autoResultMap = true)
 @KeySequence("iot_thing_model_common_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
 @Data
 @EqualsAndHashCode(callSuper = true)