|
@@ -1,25 +1,25 @@
|
|
|
-package cn.iocoder.yudao.module.iot.service.thinkmodel;
|
|
|
+package cn.iocoder.yudao.module.iot.service.thingmodel;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
|
|
-import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelEvent;
|
|
|
-import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelProperty;
|
|
|
-import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelService;
|
|
|
-import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.dataType.ThinkModelArgument;
|
|
|
-import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.dataType.ThinkModelArrayDataSpecs;
|
|
|
-import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.dataType.ThinkModelDateOrTextDataSpecs;
|
|
|
-import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.vo.IotProductThinkModelPageReqVO;
|
|
|
-import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.vo.IotProductThinkModelSaveReqVO;
|
|
|
-import cn.iocoder.yudao.module.iot.convert.thinkmodel.IotProductThinkModelConvert;
|
|
|
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelEvent;
|
|
|
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelProperty;
|
|
|
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelService;
|
|
|
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelArgument;
|
|
|
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelArrayDataSpecs;
|
|
|
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDateOrTextDataSpecs;
|
|
|
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotProductThingModelPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotProductThingModelSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.iot.convert.thingmodel.IotProductThingModelConvert;
|
|
|
import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
|
|
|
-import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodel.IotProductThinkModelDO;
|
|
|
-import cn.iocoder.yudao.module.iot.dal.mysql.thinkmodel.IotProductThinkModelMapper;
|
|
|
+import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotProductThingModelDO;
|
|
|
+import cn.iocoder.yudao.module.iot.dal.mysql.thingmodel.IotProductThingModelMapper;
|
|
|
import cn.iocoder.yudao.module.iot.enums.product.IotProductStatusEnum;
|
|
|
-import cn.iocoder.yudao.module.iot.enums.thinkmodel.IotProductThinkModelAccessModeEnum;
|
|
|
-import cn.iocoder.yudao.module.iot.enums.thinkmodel.IotProductThinkModelTypeEnum;
|
|
|
+import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelAccessModeEnum;
|
|
|
+import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum;
|
|
|
import cn.iocoder.yudao.module.iot.service.product.IotProductService;
|
|
|
import cn.iocoder.yudao.module.iot.service.tdengine.IotSuperTableService;
|
|
|
import jakarta.annotation.Resource;
|
|
@@ -43,10 +43,10 @@ import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
|
|
|
@Service
|
|
|
@Validated
|
|
|
@Slf4j
|
|
|
-public class IotProductThinkModelServiceImpl implements IotProductThinkModelService {
|
|
|
+public class IotProductThingModelServiceImpl implements IotProductThingModelService {
|
|
|
|
|
|
@Resource
|
|
|
- private IotProductThinkModelMapper productThinkModelMapper;
|
|
|
+ private IotProductThingModelMapper productThingModelMapper;
|
|
|
|
|
|
@Resource
|
|
|
private IotProductService productService;
|
|
@@ -55,7 +55,7 @@ public class IotProductThinkModelServiceImpl implements IotProductThinkModelServ
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public Long createProductThinkModel(IotProductThinkModelSaveReqVO createReqVO) {
|
|
|
+ public Long createProductThingModel(IotProductThingModelSaveReqVO createReqVO) {
|
|
|
// 1. 校验功能标识符在同一产品下是否唯一
|
|
|
validateIdentifierUnique(createReqVO.getProductId(), createReqVO.getIdentifier());
|
|
|
|
|
@@ -69,52 +69,49 @@ public class IotProductThinkModelServiceImpl implements IotProductThinkModelServ
|
|
|
validateProductStatus(createReqVO.getProductId());
|
|
|
|
|
|
// 5. 插入数据库
|
|
|
- IotProductThinkModelDO function = IotProductThinkModelConvert.INSTANCE.convert(createReqVO);
|
|
|
- productThinkModelMapper.insert(function);
|
|
|
+ IotProductThingModelDO thingModel = IotProductThingModelConvert.INSTANCE.convert(createReqVO);
|
|
|
+ productThingModelMapper.insert(thingModel);
|
|
|
|
|
|
// 6. 如果创建的是属性,需要更新默认的事件和服务
|
|
|
- if (Objects.equals(createReqVO.getType(), IotProductThinkModelTypeEnum.PROPERTY.getType())) {
|
|
|
+ if (Objects.equals(createReqVO.getType(), IotProductThingModelTypeEnum.PROPERTY.getType())) {
|
|
|
createDefaultEventsAndServices(createReqVO.getProductId(), createReqVO.getProductKey());
|
|
|
}
|
|
|
- return function.getId();
|
|
|
+ return thingModel.getId();
|
|
|
}
|
|
|
|
|
|
private void validateProductStatus(Long createReqVO) {
|
|
|
IotProductDO product = productService.getProduct(createReqVO);
|
|
|
if (Objects.equals(product.getStatus(), IotProductStatusEnum.PUBLISHED.getStatus())) {
|
|
|
- throw exception(PRODUCT_STATUS_NOT_ALLOW_FUNCTION);
|
|
|
+ throw exception(PRODUCT_STATUS_NOT_ALLOW_THING_MODEL);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void validateNotDefaultEventAndService(String identifier) {
|
|
|
// set, get, post, property, event, time, value 是系统保留字段,不能用于标识符定义
|
|
|
if (CollUtil.containsAny(Arrays.asList("set", "get", "post", "property", "event", "time", "value"), Collections.singletonList(identifier))) {
|
|
|
- throw exception(THINK_MODEL_FUNCTION_IDENTIFIER_INVALID);
|
|
|
+ throw exception(THING_MODEL_IDENTIFIER_INVALID);
|
|
|
}
|
|
|
-// if (CollUtil.containsAny(Arrays.asList("post", "set", "get"), identifier)) {
|
|
|
-// throw exception(THINK_MODEL_FUNCTION_IDENTIFIER_INVALID);
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
private void validateNameUnique(Long productId, String name) {
|
|
|
- IotProductThinkModelDO function = productThinkModelMapper.selectByProductIdAndName(productId, name);
|
|
|
- if (function != null) {
|
|
|
- throw exception(THINK_MODEL_FUNCTION_NAME_EXISTS);
|
|
|
+ IotProductThingModelDO thingModel = productThingModelMapper.selectByProductIdAndName(productId, name);
|
|
|
+ if (thingModel != null) {
|
|
|
+ throw exception(THING_MODEL_NAME_EXISTS);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void validateIdentifierUnique(Long productId, String identifier) {
|
|
|
- IotProductThinkModelDO function = productThinkModelMapper.selectByProductIdAndIdentifier(productId, identifier);
|
|
|
- if (function != null) {
|
|
|
- throw exception(THINK_MODEL_FUNCTION_IDENTIFIER_EXISTS);
|
|
|
+ IotProductThingModelDO thingModel = productThingModelMapper.selectByProductIdAndIdentifier(productId, identifier);
|
|
|
+ if (thingModel != null) {
|
|
|
+ throw exception(THING_MODEL_IDENTIFIER_EXISTS);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void updateProductThinkModel(IotProductThinkModelSaveReqVO updateReqVO) {
|
|
|
+ public void updateProductThingModel(IotProductThingModelSaveReqVO updateReqVO) {
|
|
|
// 1. 校验功能是否存在
|
|
|
- validateProductThinkModelMapperExists(updateReqVO.getId());
|
|
|
+ validateProductThingModelMapperExists(updateReqVO.getId());
|
|
|
|
|
|
// 2. 校验功能标识符是否唯一
|
|
|
validateIdentifierUniqueForUpdate(updateReqVO.getId(), updateReqVO.getProductId(), updateReqVO.getIdentifier());
|
|
@@ -123,40 +120,40 @@ public class IotProductThinkModelServiceImpl implements IotProductThinkModelServ
|
|
|
validateProductStatus(updateReqVO.getProductId());
|
|
|
|
|
|
// 4. 更新数据库
|
|
|
- IotProductThinkModelDO productThinkModelDO = IotProductThinkModelConvert.INSTANCE.convert(updateReqVO);
|
|
|
- productThinkModelMapper.updateById(productThinkModelDO);
|
|
|
+ IotProductThingModelDO thingModel = IotProductThingModelConvert.INSTANCE.convert(updateReqVO);
|
|
|
+ productThingModelMapper.updateById(thingModel);
|
|
|
|
|
|
// 5. 如果更新的是属性,需要更新默认的事件和服务
|
|
|
- if (Objects.equals(updateReqVO.getType(), IotProductThinkModelTypeEnum.PROPERTY.getType())) {
|
|
|
+ if (Objects.equals(updateReqVO.getType(), IotProductThingModelTypeEnum.PROPERTY.getType())) {
|
|
|
createDefaultEventsAndServices(updateReqVO.getProductId(), updateReqVO.getProductKey());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void validateIdentifierUniqueForUpdate(Long id, Long productId, String identifier) {
|
|
|
- IotProductThinkModelDO function = productThinkModelMapper.selectByProductIdAndIdentifier(productId, identifier);
|
|
|
- if (function != null && ObjectUtil.notEqual(function.getId(), id)) {
|
|
|
- throw exception(THINK_MODEL_FUNCTION_IDENTIFIER_EXISTS);
|
|
|
+ IotProductThingModelDO thingModel = productThingModelMapper.selectByProductIdAndIdentifier(productId, identifier);
|
|
|
+ if (thingModel != null && ObjectUtil.notEqual(thingModel.getId(), id)) {
|
|
|
+ throw exception(THING_MODEL_IDENTIFIER_EXISTS);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void deleteProductThinkModel(Long id) {
|
|
|
+ public void deleteProductThingModel(Long id) {
|
|
|
// 1. 校验功能是否存在
|
|
|
- IotProductThinkModelDO functionDO = productThinkModelMapper.selectById(id);
|
|
|
- if (functionDO == null) {
|
|
|
- throw exception(THINK_MODEL_FUNCTION_NOT_EXISTS);
|
|
|
+ IotProductThingModelDO thingModel = productThingModelMapper.selectById(id);
|
|
|
+ if (thingModel == null) {
|
|
|
+ throw exception(THING_MODEL_NOT_EXISTS);
|
|
|
}
|
|
|
|
|
|
// 3. 校验产品状态,发布状态下,不允许操作功能
|
|
|
- validateProductStatus(functionDO.getProductId());
|
|
|
+ validateProductStatus(thingModel.getProductId());
|
|
|
|
|
|
// 2. 删除功能
|
|
|
- productThinkModelMapper.deleteById(id);
|
|
|
+ productThingModelMapper.deleteById(id);
|
|
|
|
|
|
// 3. 如果删除的是属性,需要更新默认的事件和服务
|
|
|
- if (Objects.equals(functionDO.getType(), IotProductThinkModelTypeEnum.PROPERTY.getType())) {
|
|
|
- createDefaultEventsAndServices(functionDO.getProductId(), functionDO.getProductKey());
|
|
|
+ if (Objects.equals(thingModel.getType(), IotProductThingModelTypeEnum.PROPERTY.getType())) {
|
|
|
+ createDefaultEventsAndServices(thingModel.getProductId(), thingModel.getProductKey());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -165,25 +162,25 @@ public class IotProductThinkModelServiceImpl implements IotProductThinkModelServ
|
|
|
*
|
|
|
* @param id 功能编号
|
|
|
*/
|
|
|
- private void validateProductThinkModelMapperExists(Long id) {
|
|
|
- if (productThinkModelMapper.selectById(id) == null) {
|
|
|
- throw exception(THINK_MODEL_FUNCTION_NOT_EXISTS);
|
|
|
+ private void validateProductThingModelMapperExists(Long id) {
|
|
|
+ if (productThingModelMapper.selectById(id) == null) {
|
|
|
+ throw exception(THING_MODEL_NOT_EXISTS);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public IotProductThinkModelDO getProductThinkModel(Long id) {
|
|
|
- return productThinkModelMapper.selectById(id);
|
|
|
+ public IotProductThingModelDO getProductThingModel(Long id) {
|
|
|
+ return productThingModelMapper.selectById(id);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<IotProductThinkModelDO> getProductThinkModelListByProductId(Long productId) {
|
|
|
- return productThinkModelMapper.selectListByProductId(productId);
|
|
|
+ public List<IotProductThingModelDO> getProductThingModelListByProductId(Long productId) {
|
|
|
+ return productThingModelMapper.selectListByProductId(productId);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public PageResult<IotProductThinkModelDO> getProductThinkModelPage(IotProductThinkModelPageReqVO pageReqVO) {
|
|
|
- return productThinkModelMapper.selectPage(pageReqVO);
|
|
|
+ public PageResult<IotProductThingModelDO> getProductThingModelPage(IotProductThingModelPageReqVO pageReqVO) {
|
|
|
+ return productThingModelMapper.selectPage(pageReqVO);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -192,15 +189,15 @@ public class IotProductThinkModelServiceImpl implements IotProductThinkModelServ
|
|
|
IotProductDO product = productService.getProduct(productId);
|
|
|
|
|
|
// 2. 查询产品的物模型功能列表
|
|
|
- List<IotProductThinkModelDO> functionList = productThinkModelMapper.selectListByProductId(productId);
|
|
|
+ List<IotProductThingModelDO> thingModelList = productThingModelMapper.selectListByProductId(productId);
|
|
|
|
|
|
// 3. 生成 TDengine 的数据模型
|
|
|
- dbStructureDataService.createSuperTableDataModel(product, functionList);
|
|
|
+ dbStructureDataService.createSuperTableDataModel(product, thingModelList);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<IotProductThinkModelDO> getProductThinkModelListByProductKey(String productKey) {
|
|
|
- return productThinkModelMapper.selectListByProductKey(productKey);
|
|
|
+ public List<IotProductThingModelDO> getProductThingModelListByProductKey(String productKey) {
|
|
|
+ return productThingModelMapper.selectListByProductKey(productKey);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -208,124 +205,124 @@ public class IotProductThinkModelServiceImpl implements IotProductThinkModelServ
|
|
|
*/
|
|
|
public void createDefaultEventsAndServices(Long productId, String productKey) {
|
|
|
// 1. 获取当前属性列表
|
|
|
- List<IotProductThinkModelDO> propertyList = productThinkModelMapper
|
|
|
- .selectListByProductIdAndType(productId, IotProductThinkModelTypeEnum.PROPERTY.getType());
|
|
|
+ List<IotProductThingModelDO> propertyList = productThingModelMapper
|
|
|
+ .selectListByProductIdAndType(productId, IotProductThingModelTypeEnum.PROPERTY.getType());
|
|
|
|
|
|
// 2. 生成新的事件和服务列表
|
|
|
- List<IotProductThinkModelDO> newFunctionList = new ArrayList<>();
|
|
|
+ List<IotProductThingModelDO> newThingModelList = new ArrayList<>();
|
|
|
// 生成属性上报事件
|
|
|
- ThinkModelEvent propertyPostEvent = generatePropertyPostEvent(propertyList);
|
|
|
+ ThingModelEvent propertyPostEvent = generatePropertyPostEvent(propertyList);
|
|
|
if (propertyPostEvent != null) {
|
|
|
- IotProductThinkModelDO eventFunction = buildEventFunctionDO(productId, productKey, propertyPostEvent);
|
|
|
- newFunctionList.add(eventFunction);
|
|
|
+ IotProductThingModelDO eventThingModel = buildEventThingModelDO(productId, productKey, propertyPostEvent);
|
|
|
+ newThingModelList.add(eventThingModel);
|
|
|
}
|
|
|
// 生成属性设置服务
|
|
|
- ThinkModelService propertySetService = generatePropertySetService(propertyList);
|
|
|
+ ThingModelService propertySetService = generatePropertySetService(propertyList);
|
|
|
if (propertySetService != null) {
|
|
|
- IotProductThinkModelDO setServiceFunction = buildServiceFunctionDO(productId, productKey, propertySetService);
|
|
|
- newFunctionList.add(setServiceFunction);
|
|
|
+ IotProductThingModelDO setServiceThingModel = buildServiceThingModelDO(productId, productKey, propertySetService);
|
|
|
+ newThingModelList.add(setServiceThingModel);
|
|
|
}
|
|
|
// 生成属性获取服务
|
|
|
- ThinkModelService propertyGetService = generatePropertyGetService(propertyList);
|
|
|
+ ThingModelService propertyGetService = generatePropertyGetService(propertyList);
|
|
|
if (propertyGetService != null) {
|
|
|
- IotProductThinkModelDO getServiceFunction = buildServiceFunctionDO(productId, productKey, propertyGetService);
|
|
|
- newFunctionList.add(getServiceFunction);
|
|
|
+ IotProductThingModelDO getServiceThingModel = buildServiceThingModelDO(productId, productKey, propertyGetService);
|
|
|
+ newThingModelList.add(getServiceThingModel);
|
|
|
}
|
|
|
|
|
|
// 3. 获取数据库中的默认的旧事件和服务列表
|
|
|
- List<IotProductThinkModelDO> oldFunctionList = productThinkModelMapper.selectListByProductIdAndIdentifiersAndTypes(
|
|
|
+ List<IotProductThingModelDO> oldThingModelList = productThingModelMapper.selectListByProductIdAndIdentifiersAndTypes(
|
|
|
productId,
|
|
|
Arrays.asList("post", "set", "get"),
|
|
|
- Arrays.asList(IotProductThinkModelTypeEnum.EVENT.getType(), IotProductThinkModelTypeEnum.SERVICE.getType())
|
|
|
+ Arrays.asList(IotProductThingModelTypeEnum.EVENT.getType(), IotProductThingModelTypeEnum.SERVICE.getType())
|
|
|
);
|
|
|
|
|
|
// 3.1 使用 diffList 方法比较新旧列表
|
|
|
- List<List<IotProductThinkModelDO>> diffResult = diffList(oldFunctionList, newFunctionList,
|
|
|
+ List<List<IotProductThingModelDO>> diffResult = diffList(oldThingModelList, newThingModelList,
|
|
|
// 继续使用 identifier 和 type 进行比较:这样可以准确地匹配对应的功能对象。
|
|
|
(oldFunc, newFunc) -> Objects.equals(oldFunc.getIdentifier(), newFunc.getIdentifier())
|
|
|
&& Objects.equals(oldFunc.getType(), newFunc.getType()));
|
|
|
- List<IotProductThinkModelDO> createList = diffResult.get(0); // 需要新增的
|
|
|
- List<IotProductThinkModelDO> updateList = diffResult.get(1); // 需要更新的
|
|
|
- List<IotProductThinkModelDO> deleteList = diffResult.get(2); // 需要删除的
|
|
|
+ List<IotProductThingModelDO> createList = diffResult.get(0); // 需要新增的
|
|
|
+ List<IotProductThingModelDO> updateList = diffResult.get(1); // 需要更新的
|
|
|
+ List<IotProductThingModelDO> deleteList = diffResult.get(2); // 需要删除的
|
|
|
|
|
|
// 3.2 批量执行数据库操作
|
|
|
// 新增数据库中的新事件和服务列表
|
|
|
if (CollUtil.isNotEmpty(createList)) {
|
|
|
- productThinkModelMapper.insertBatch(createList);
|
|
|
+ productThingModelMapper.insertBatch(createList);
|
|
|
}
|
|
|
// 更新数据库中的事件和服务列表
|
|
|
if (CollUtil.isNotEmpty(updateList)) {
|
|
|
// 首先,为每个需要更新的对象设置其对应的 ID
|
|
|
updateList.forEach(updateFunc -> {
|
|
|
- IotProductThinkModelDO oldFunc = findFunctionByIdentifierAndType(
|
|
|
- oldFunctionList, updateFunc.getIdentifier(), updateFunc.getType());
|
|
|
+ IotProductThingModelDO oldFunc = findThingModelByIdentifierAndType(
|
|
|
+ oldThingModelList, updateFunc.getIdentifier(), updateFunc.getType());
|
|
|
if (oldFunc != null) {
|
|
|
updateFunc.setId(oldFunc.getId());
|
|
|
}
|
|
|
});
|
|
|
// 过滤掉没有设置 ID 的对象
|
|
|
- List<IotProductThinkModelDO> validUpdateList = updateList.stream()
|
|
|
+ List<IotProductThingModelDO> validUpdateList = updateList.stream()
|
|
|
.filter(func -> func.getId() != null)
|
|
|
.collect(Collectors.toList());
|
|
|
// 执行批量更新
|
|
|
if (CollUtil.isNotEmpty(validUpdateList)) {
|
|
|
- productThinkModelMapper.updateBatch(validUpdateList);
|
|
|
+ productThingModelMapper.updateBatch(validUpdateList);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 删除数据库中的旧事件和服务列表
|
|
|
if (CollUtil.isNotEmpty(deleteList)) {
|
|
|
- Set<Long> idsToDelete = CollectionUtils.convertSet(deleteList, IotProductThinkModelDO::getId);
|
|
|
- productThinkModelMapper.deleteByIds(idsToDelete);
|
|
|
+ Set<Long> idsToDelete = CollectionUtils.convertSet(deleteList, IotProductThingModelDO::getId);
|
|
|
+ productThingModelMapper.deleteByIds(idsToDelete);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据标识符和类型查找功能对象
|
|
|
*/
|
|
|
- private IotProductThinkModelDO findFunctionByIdentifierAndType(List<IotProductThinkModelDO> functionList,
|
|
|
- String identifier, Integer type) {
|
|
|
- return CollUtil.findOne(functionList, func ->
|
|
|
+ private IotProductThingModelDO findThingModelByIdentifierAndType(List<IotProductThingModelDO> thingModelList,
|
|
|
+ String identifier, Integer type) {
|
|
|
+ return CollUtil.findOne(thingModelList, func ->
|
|
|
Objects.equals(func.getIdentifier(), identifier) && Objects.equals(func.getType(), type));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 构建事件功能对象
|
|
|
*/
|
|
|
- private IotProductThinkModelDO buildEventFunctionDO(Long productId, String productKey, ThinkModelEvent event) {
|
|
|
- return new IotProductThinkModelDO()
|
|
|
+ private IotProductThingModelDO buildEventThingModelDO(Long productId, String productKey, ThingModelEvent event) {
|
|
|
+ return new IotProductThingModelDO()
|
|
|
.setProductId(productId)
|
|
|
.setProductKey(productKey)
|
|
|
.setIdentifier(event.getIdentifier())
|
|
|
.setName(event.getName())
|
|
|
.setDescription(event.getDescription())
|
|
|
- .setType(IotProductThinkModelTypeEnum.EVENT.getType())
|
|
|
+ .setType(IotProductThingModelTypeEnum.EVENT.getType())
|
|
|
.setEvent(event);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 构建服务功能对象
|
|
|
*/
|
|
|
- private IotProductThinkModelDO buildServiceFunctionDO(Long productId, String productKey, ThinkModelService service) {
|
|
|
- return new IotProductThinkModelDO()
|
|
|
+ private IotProductThingModelDO buildServiceThingModelDO(Long productId, String productKey, ThingModelService service) {
|
|
|
+ return new IotProductThingModelDO()
|
|
|
.setProductId(productId)
|
|
|
.setProductKey(productKey)
|
|
|
.setIdentifier(service.getIdentifier())
|
|
|
.setName(service.getName())
|
|
|
.setDescription(service.getDescription())
|
|
|
- .setType(IotProductThinkModelTypeEnum.SERVICE.getType())
|
|
|
+ .setType(IotProductThingModelTypeEnum.SERVICE.getType())
|
|
|
.setService(service);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 生成属性上报事件
|
|
|
*/
|
|
|
- private ThinkModelEvent generatePropertyPostEvent(List<IotProductThinkModelDO> propertyList) {
|
|
|
+ private ThingModelEvent generatePropertyPostEvent(List<IotProductThingModelDO> propertyList) {
|
|
|
if (CollUtil.isEmpty(propertyList)) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- ThinkModelEvent event = new ThinkModelEvent()
|
|
|
+ ThingModelEvent event = new ThingModelEvent()
|
|
|
.setIdentifier("post")
|
|
|
.setName("属性上报")
|
|
|
.setType("info")
|
|
@@ -333,13 +330,13 @@ public class IotProductThinkModelServiceImpl implements IotProductThinkModelServ
|
|
|
.setMethod("thing.event.property.post");
|
|
|
|
|
|
// 将属性列表转换为事件的输出参数
|
|
|
- List<ThinkModelArgument> outputData = new ArrayList<>();
|
|
|
- for (IotProductThinkModelDO thinkModel : propertyList) {
|
|
|
- ThinkModelArgument arg = new ThinkModelArgument()
|
|
|
- .setIdentifier(thinkModel.getIdentifier())
|
|
|
- .setName(thinkModel.getName())
|
|
|
- .setProperty(thinkModel.getProperty())
|
|
|
- .setDescription(thinkModel.getDescription())
|
|
|
+ List<ThingModelArgument> outputData = new ArrayList<>();
|
|
|
+ for (IotProductThingModelDO thingModel : propertyList) {
|
|
|
+ ThingModelArgument arg = new ThingModelArgument()
|
|
|
+ .setIdentifier(thingModel.getIdentifier())
|
|
|
+ .setName(thingModel.getName())
|
|
|
+ .setProperty(thingModel.getProperty())
|
|
|
+ .setDescription(thingModel.getDescription())
|
|
|
.setDirection("output"); // 设置为输出参数
|
|
|
outputData.add(arg);
|
|
|
}
|
|
@@ -350,16 +347,16 @@ public class IotProductThinkModelServiceImpl implements IotProductThinkModelServ
|
|
|
/**
|
|
|
* 生成属性设置服务
|
|
|
*/
|
|
|
- private ThinkModelService generatePropertySetService(List<IotProductThinkModelDO> propertyList) {
|
|
|
+ private ThingModelService generatePropertySetService(List<IotProductThingModelDO> propertyList) {
|
|
|
if (propertyList == null || propertyList.isEmpty()) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- List<ThinkModelArgument> inputData = new ArrayList<>();
|
|
|
- for (IotProductThinkModelDO thinkModel : propertyList) {
|
|
|
- ThinkModelProperty property = thinkModel.getProperty();
|
|
|
- if (IotProductThinkModelAccessModeEnum.READ_WRITE.getMode().equals(property.getAccessMode())) {
|
|
|
- ThinkModelArgument arg = new ThinkModelArgument()
|
|
|
+ List<ThingModelArgument> inputData = new ArrayList<>();
|
|
|
+ for (IotProductThingModelDO thingModel : propertyList) {
|
|
|
+ ThingModelProperty property = thingModel.getProperty();
|
|
|
+ if (IotProductThingModelAccessModeEnum.READ_WRITE.getMode().equals(property.getAccessMode())) {
|
|
|
+ ThingModelArgument arg = new ThingModelArgument()
|
|
|
.setIdentifier(property.getIdentifier())
|
|
|
.setName(property.getName())
|
|
|
.setProperty(property)
|
|
@@ -374,7 +371,7 @@ public class IotProductThinkModelServiceImpl implements IotProductThinkModelServ
|
|
|
}
|
|
|
|
|
|
// 属性设置服务一般不需要输出参数
|
|
|
- return new ThinkModelService()
|
|
|
+ return new ThingModelService()
|
|
|
.setIdentifier("set")
|
|
|
.setName("属性设置")
|
|
|
.setCallType("async")
|
|
@@ -388,17 +385,17 @@ public class IotProductThinkModelServiceImpl implements IotProductThinkModelServ
|
|
|
/**
|
|
|
* 生成属性获取服务
|
|
|
*/
|
|
|
- private ThinkModelService generatePropertyGetService(List<IotProductThinkModelDO> propertyList) {
|
|
|
+ private ThingModelService generatePropertyGetService(List<IotProductThingModelDO> propertyList) {
|
|
|
if (propertyList == null || propertyList.isEmpty()) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- List<ThinkModelArgument> outputData = new ArrayList<>();
|
|
|
- for (IotProductThinkModelDO functionDO : propertyList) {
|
|
|
- ThinkModelProperty property = functionDO.getProperty();
|
|
|
+ List<ThingModelArgument> outputData = new ArrayList<>();
|
|
|
+ for (IotProductThingModelDO thingModelDO : propertyList) {
|
|
|
+ ThingModelProperty property = thingModelDO.getProperty();
|
|
|
if (ObjectUtils.equalsAny(property.getAccessMode(),
|
|
|
- IotProductThinkModelAccessModeEnum.READ_ONLY.getMode(), IotProductThinkModelAccessModeEnum.READ_WRITE.getMode())) {
|
|
|
- ThinkModelArgument arg = new ThinkModelArgument()
|
|
|
+ IotProductThingModelAccessModeEnum.READ_ONLY.getMode(), IotProductThingModelAccessModeEnum.READ_WRITE.getMode())) {
|
|
|
+ ThingModelArgument arg = new ThingModelArgument()
|
|
|
.setIdentifier(property.getIdentifier())
|
|
|
.setName(property.getName())
|
|
|
.setProperty(property)
|
|
@@ -412,7 +409,7 @@ public class IotProductThinkModelServiceImpl implements IotProductThinkModelServ
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- ThinkModelService service = new ThinkModelService()
|
|
|
+ ThingModelService service = new ThingModelService()
|
|
|
.setIdentifier("get")
|
|
|
.setName("属性获取")
|
|
|
.setCallType("async")
|
|
@@ -420,21 +417,21 @@ public class IotProductThinkModelServiceImpl implements IotProductThinkModelServ
|
|
|
.setMethod("thing.service.property.get");
|
|
|
|
|
|
// 定义输入参数:属性标识符列表
|
|
|
- ThinkModelArgument inputArg = new ThinkModelArgument()
|
|
|
+ ThingModelArgument inputArg = new ThingModelArgument()
|
|
|
.setIdentifier("properties")
|
|
|
.setName("属性标识符列表")
|
|
|
.setDescription("需要获取的属性标识符列表")
|
|
|
.setDirection("input"); // 设置为输入参数
|
|
|
|
|
|
// 创建数组类型,元素类型为文本类型(字符串)TODO @puhui999: 还得研究研究
|
|
|
- ThinkModelArrayDataSpecs arrayType = new ThinkModelArrayDataSpecs();
|
|
|
+ ThingModelArrayDataSpecs arrayType = new ThingModelArrayDataSpecs();
|
|
|
arrayType.setDataType("array");
|
|
|
- inputArg.setProperty(new ThinkModelProperty().setIdentifier(inputArg.getIdentifier()).setName(inputArg.getName())
|
|
|
+ inputArg.setProperty(new ThingModelProperty().setIdentifier(inputArg.getIdentifier()).setName(inputArg.getName())
|
|
|
.setDescription(inputArg.getDescription()).setDataSpecs(arrayType));
|
|
|
|
|
|
- ThinkModelDateOrTextDataSpecs textType = new ThinkModelDateOrTextDataSpecs();
|
|
|
+ ThingModelDateOrTextDataSpecs textType = new ThingModelDateOrTextDataSpecs();
|
|
|
textType.setDataType("text");
|
|
|
- inputArg.setProperty(new ThinkModelProperty().setIdentifier(inputArg.getIdentifier()).setName(inputArg.getName())
|
|
|
+ inputArg.setProperty(new ThingModelProperty().setIdentifier(inputArg.getIdentifier()).setName(inputArg.getName())
|
|
|
.setDescription(inputArg.getDescription()).setDataSpecs(textType));
|
|
|
|
|
|
service.setInputData(Collections.singletonList(inputArg));
|