This commit is contained in:
xzb 2022-12-08 15:02:36 +08:00
parent 3bfa4472b3
commit 02d7e7522d
5 changed files with 55 additions and 5 deletions

Binary file not shown.

View File

@ -1,6 +1,8 @@
package club.joylink.rtss.iscs.memory;
import club.joylink.iscs.model.data.PageDataModelProto.PageDataModel;
import club.joylink.iscs.model.status.soe.SoeProto;
import club.joylink.rtss.iscs.entity.IscsModelData;
import club.joylink.rtss.iscs.memory.model.ModelMemory;
import club.joylink.rtss.iscs.memory.model.ModelMemoryId;
@ -25,4 +27,30 @@ public class MemoryManager {
*/
private LinkedList<SoeProto.AlarmEvent.Builder> alarmEvents = new LinkedList<>();
/**
* 添加从数据库加载的页面模型数据
*/
public void addModelData(IscsModelData md) {
final ModelMemory mm = ModelMemory.create(md);
modelMemories.put(mm.mmId(), mm);
}
/**
* 根据页面坐标获取页面模型数据
*/
public PageDataModel.Builder getModelData(String system, String view, String place) {
final ModelMemory modelMemory = modelMemories.get(new ModelMemoryId(system, view, place));
if (null != modelMemory) {
final PageDataModel.Builder rt = PageDataModel.newBuilder();
final ModelMemoryId mmId = modelMemory.mmId();
rt.setId(mmId.getId());
rt.setSystem(mmId.getSystem());
rt.setView(mmId.getView());
rt.setPlace(mmId.getPlace());
rt.setContent(modelMemory.allDataModels());
return rt;
}
return null;
}
}

View File

@ -2,6 +2,7 @@ package club.joylink.rtss.iscs.memory.model;
import club.joylink.iscs.model.data.DataModelMapProto;
import club.joylink.iscs.model.data.DataModelProto;
import club.joylink.rtss.iscs.entity.IscsModelData;
import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.InvalidProtocolBufferException;
@ -43,9 +44,16 @@ public interface ModelMemory {
*/
void recoverFrom(byte[] modelsData) throws InvalidProtocolBufferException;
public static ModelMemory create(byte[] modelsData) throws InvalidProtocolBufferException {
ModelMemoryId mmId();
public static ModelMemory create(IscsModelData md) {
ModelMemoryImpl impl = new ModelMemoryImpl();
impl.recoverFrom(modelsData);
try {
impl.mmId = new ModelMemoryId(md.getId(), md.getSystem(), md.getView(), md.getPlace());
impl.recoverFrom(md.getData());
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
return impl;
}

View File

@ -1,14 +1,25 @@
package club.joylink.rtss.iscs.memory.model;
import lombok.Getter;
import java.util.Objects;
/**
* 页模型数据的id
*/
@Getter
public class ModelMemoryId {
private Long id;//数据库记录id
private String system;
private String view;
private String place;
public ModelMemoryId(Long id, String system, String view, String place) {
this.id = id;
this.system = system;
this.view = view;
this.place = place;
}
public ModelMemoryId(String system, String view, String place) {
this.system = system;
this.view = view;

View File

@ -15,7 +15,7 @@ import java.util.Map;
*/
@Slf4j
public class ModelMemoryImpl implements ModelMemory {
ModelMemoryId mmId;
/**
* 模型数据存储空间
*/
@ -33,10 +33,13 @@ public class ModelMemoryImpl implements ModelMemory {
*/
private final Map<Class<? extends GeneratedMessageV3>, Method> modelMap = new HashMap<>();
public ModelMemoryImpl() {
ModelMemoryImpl() {
}
@Override
public ModelMemoryId mmId() {
return this.mmId;
}
/**
* 获取模型数据的引用
*/