Commit c54b9127 authored by huangcb's avatar huangcb

新增/删除模型实例时,新增/删除模型实例Topic

parent b35e36bd
......@@ -12,5 +12,23 @@ import com.esv.datacenter.iot.module.omodel.entity.InstanceTopicEntity;
*/
public interface InstanceTopicService extends IService<InstanceTopicEntity> {
/**
* @description 新增模型实例Topic
* @param modelId:
* @param instanceId:
* @return void
* @author huangChaobin@esvtek.com
* @createTime 2020/08/04 11:22
**/
void insertTopic(Long modelId, Long instanceId);
/**
* @description 删除模型实例Topic
* @param instanceId:
* @return void
* @author huangChaobin@esvtek.com
* @createTime 2020/08/04 11:22
**/
void deleteTopic(Long instanceId);
}
package com.esv.datacenter.iot.module.omodel.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.esv.datacenter.iot.module.omodel.dao.InstanceTopicDao;
import com.esv.datacenter.iot.module.omodel.entity.InstanceTopicEntity;
import com.esv.datacenter.iot.module.omodel.service.InstanceTopicService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
@Service("instanceTopicService")
@RefreshScope
public class InstanceTopicServiceImpl extends ServiceImpl<InstanceTopicDao, InstanceTopicEntity> implements InstanceTopicService {
@Value("${mqtt.topic.instance.data-upload}")
private String instanceDataUploadTopic;
@Override
public void insertTopic(Long modelId, Long instanceId) {
String topic = instanceDataUploadTopic.replaceFirst("[model_id]", String.valueOf(modelId))
.replaceFirst("[instance_id]", String.valueOf(instanceId));
InstanceTopicEntity entity = new InstanceTopicEntity();
entity.setModelId(modelId);
entity.setInstanceId(instanceId);
entity.setTopic(topic);
this.getBaseMapper().insert(entity);
}
@Override
public void deleteTopic(Long instanceId) {
this.getBaseMapper().delete(new LambdaQueryWrapper<InstanceTopicEntity>().eq(InstanceTopicEntity::getInstanceId, instanceId));
}
}
\ No newline at end of file
......@@ -12,6 +12,7 @@ import com.esv.datacenter.iot.module.omodel.dao.ObjectModelInstanceDao;
import com.esv.datacenter.iot.module.omodel.entity.ObjectModelEntity;
import com.esv.datacenter.iot.module.omodel.entity.ObjectModelInstanceEntity;
import com.esv.datacenter.iot.module.omodel.form.ModelInstanceForm;
import com.esv.datacenter.iot.module.omodel.service.InstanceTopicService;
import com.esv.datacenter.iot.module.omodel.service.ObjectModelInstanceService;
import com.esv.datacenter.iot.module.omodel.service.ObjectModelService;
import com.esv.datacenter.iot.module.omodel.vo.ModelInstanceDetailVO;
......@@ -19,6 +20,7 @@ import com.esv.datacenter.iot.module.omodel.vo.ModelInstanceVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
......@@ -29,6 +31,8 @@ public class ObjectModelInstanceServiceImpl extends ServiceImpl<ObjectModelInsta
@Autowired
ObjectModelService objectModelService;
@Autowired
InstanceTopicService instanceTopicService;
@Override
public List<ModelInstanceVO> getModelInstanceList(Long modelId) {
......@@ -67,6 +71,7 @@ public class ObjectModelInstanceServiceImpl extends ServiceImpl<ObjectModelInsta
}
@Override
@Transactional(rollbackFor = Exception.class)
public Long createModelInstance(ModelInstanceForm form) {
// 模型实例名称校验
int instanceCount = this.getBaseMapper().selectCount(new LambdaQueryWrapper<ObjectModelInstanceEntity>()
......@@ -81,8 +86,12 @@ public class ObjectModelInstanceServiceImpl extends ServiceImpl<ObjectModelInsta
ObjectModelInstanceEntity entity = new ObjectModelInstanceEntity();
BeanUtils.copyProperties(form, entity);
this.getBaseMapper().insert(entity);
Long instanceId = entity.getId();
// 新增模型实例Topic
this.instanceTopicService.insertTopic(form.getModelId(), instanceId);
return entity.getId();
return instanceId;
}
@Override
......@@ -110,7 +119,8 @@ public class ObjectModelInstanceServiceImpl extends ServiceImpl<ObjectModelInsta
public void deleteModelInstance(Long id) {
this.getBaseMapper().deleteById(id);
// TODO,删除时序数据
// 删除模型实例Topic
this.instanceTopicService.deleteTopic(id);
}
@Override
......
......@@ -202,8 +202,7 @@ public class ObjectModelServiceImpl extends ServiceImpl<ObjectModelDao, ObjectMo
@Override
public Boolean isModelExits(Long modelId) {
int count = this.getBaseMapper().selectCount(new LambdaQueryWrapper<ObjectModelEntity>()
.eq(ObjectModelEntity::getId, modelId)
.eq(ObjectModelEntity::getDeleted, DbDeletedEnum.NO.getCode()));
.eq(ObjectModelEntity::getId, modelId));
if (0 == count) {
return false;
} else {
......
......@@ -85,4 +85,8 @@ timescale:
max-lifetime: 0
table-field:
map: string-text,number-numeric,boolean-bit(1)
table-prefix: iot_model_
\ No newline at end of file
table-prefix: iot_model_
mqtt:
topic:
instance:
data-upload: $esv/iot/[model_id]/[instance_id]/data/upload
\ No newline at end of file
......@@ -85,4 +85,8 @@ timescale:
max-lifetime: 0
table-field:
map: string-text,number-numeric,boolean-bit(1)
table-prefix: iot_model_
\ No newline at end of file
table-prefix: iot_model_
mqtt:
topic:
instance:
data-upload: $esv/iot/[model_id]/[instance_id]/data/upload
\ No newline at end of file
......@@ -85,4 +85,8 @@ timescale:
max-lifetime: 0
table-field:
map: string-text,number-numeric,boolean-bit(1)
table-prefix: iot_model_
\ No newline at end of file
table-prefix: iot_model_
mqtt:
topic:
instance:
data-upload: $esv/iot/[model_id]/[instance_id]/data/upload
\ No newline at end of file
......@@ -85,4 +85,8 @@ timescale:
max-lifetime: 0
table-field:
map: string-text,number-numeric,boolean-bit(1)
table-prefix: iot_model_
\ No newline at end of file
table-prefix: iot_model_
mqtt:
topic:
instance:
data-upload: $esv/iot/[model_id]/[instance_id]/data/upload
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment