|
|
@@ -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("导入成功");
|
|
|
+ }
|
|
|
}
|