From d5ff5dc681c4b05140e2d62f2cbc2d63ae302296 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Thu, 8 Dec 2022 15:33:02 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=AE=9E=E8=AE=AD=E7=94=9F=E6=88=90?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=AD=9B=E9=80=89=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/advice/CommonResponseBody.java | 8 ++ .../training2/TrainingRuleController.java | 17 ++- .../controller/IscsModelDataController.java | 120 ------------------ .../controller/ManageModelDataController.java | 94 ++++++++++++++ .../iscs/convert/PageDataModelConvertor.java | 23 ++++ .../rtss/iscs/memory/MemoryManager.java | 57 +++++++++ .../proto => memory}/model/ModelMemory.java | 17 ++- .../rtss/iscs/memory/model/ModelMemoryId.java | 41 ++++++ .../model/ModelMemoryImpl.java | 11 +- .../model => }/IscsModelDataService.java | 34 ++++- .../proto/model/IscsModelMemoryService.java | 114 ----------------- .../iscs/services/soe/IscsSoeService.java | 4 - .../training2/Training2RuleService.java | 11 ++ .../vo/training2/rule/BgSceneStatusRule.java | 8 +- .../rtss/vo/training2/rule/MapDeviceRule.java | 45 +++++-- 15 files changed, 334 insertions(+), 270 deletions(-) delete mode 100644 src/main/java/club/joylink/rtss/iscs/controller/IscsModelDataController.java create mode 100644 src/main/java/club/joylink/rtss/iscs/controller/ManageModelDataController.java create mode 100644 src/main/java/club/joylink/rtss/iscs/convert/PageDataModelConvertor.java create mode 100644 src/main/java/club/joylink/rtss/iscs/memory/MemoryManager.java rename src/main/java/club/joylink/rtss/iscs/{services/proto => memory}/model/ModelMemory.java (85%) create mode 100644 src/main/java/club/joylink/rtss/iscs/memory/model/ModelMemoryId.java rename src/main/java/club/joylink/rtss/iscs/{services/proto => memory}/model/ModelMemoryImpl.java (97%) rename src/main/java/club/joylink/rtss/iscs/services/{proto/model => }/IscsModelDataService.java (84%) delete mode 100644 src/main/java/club/joylink/rtss/iscs/services/proto/model/IscsModelMemoryService.java delete mode 100644 src/main/java/club/joylink/rtss/iscs/services/soe/IscsSoeService.java diff --git a/src/main/java/club/joylink/rtss/controller/advice/CommonResponseBody.java b/src/main/java/club/joylink/rtss/controller/advice/CommonResponseBody.java index 7254fd4b2..6b96a844e 100644 --- a/src/main/java/club/joylink/rtss/controller/advice/CommonResponseBody.java +++ b/src/main/java/club/joylink/rtss/controller/advice/CommonResponseBody.java @@ -5,6 +5,7 @@ import club.joylink.rtss.exception.PayException; import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.vo.CommonJsonResponse; import club.joylink.rtss.vo.ResponseConsts; +import com.google.protobuf.AbstractMessageLite; import lombok.extern.slf4j.Slf4j; import org.springframework.core.MethodParameter; import org.springframework.http.MediaType; @@ -33,10 +34,17 @@ public class CommonResponseBody implements ResponseBodyAdvice { @Override public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) { + //byte[] if(body instanceof byte[]){ response.getHeaders().setContentType(MediaType.APPLICATION_OCTET_STREAM); return body; } + //byte[] + if(body instanceof AbstractMessageLite){ + response.getHeaders().setContentType(MediaType.APPLICATION_OCTET_STREAM); + final AbstractMessageLite proto = (AbstractMessageLite) body; + return proto.toByteArray(); + } if(body instanceof CommonJsonResponse) { return body; } diff --git a/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java b/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java index fa6d2e5cb..983176afa 100644 --- a/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java +++ b/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java @@ -4,10 +4,7 @@ import club.joylink.rtss.services.training2.Training2RuleService; import lombok.extern.slf4j.Slf4j; import org.checkerframework.checker.units.qual.A; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -24,15 +21,21 @@ public class TrainingRuleController { /** - * 根据地图生成 - * @param groupId - * @return + * 根据仿真生成 */ @PostMapping("{groupId}/generate") public List generateTraining(@PathVariable String groupId){ return training2RuleService.generateTrainingByRule(groupId); } + /** + * 根据地图与功能生成 + */ + @PostMapping("{mapId}/function/{functionId}") + public List generateTrainingByMapIdAndFunId(@PathVariable Long mapId, @PathVariable Long functionId) { + return training2RuleService.generateTrainingByMapIdAndFunId(mapId, functionId); + } + @PostMapping("{groupId}/test") public void test(@PathVariable String groupId){ training2RuleService.test(groupId); diff --git a/src/main/java/club/joylink/rtss/iscs/controller/IscsModelDataController.java b/src/main/java/club/joylink/rtss/iscs/controller/IscsModelDataController.java deleted file mode 100644 index 955cd6c0a..000000000 --- a/src/main/java/club/joylink/rtss/iscs/controller/IscsModelDataController.java +++ /dev/null @@ -1,120 +0,0 @@ -package club.joylink.rtss.iscs.controller; - -import club.joylink.rtss.exception.BusinessExceptionAssertEnum; -import club.joylink.rtss.iscs.entity.IscsModelData; -import club.joylink.rtss.iscs.services.proto.model.IscsModelDataService; -import club.joylink.rtss.iscs.vo.FindIscsModelDataBasicInfoByPageReqVo; -import club.joylink.rtss.iscs.vo.IscsModelDataBasicInfo; -import club.joylink.rtss.vo.client.PageVO; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import javax.validation.constraints.NotNull; - -/** - * iscs 模型数据处理接口 - *

- * [ - * "Plan-设备运行图: Plan/DeviceRunning",
- * "Plan-站厅布局图: Plan/HallLayout",
- * "Plan-站台布局图: Plan/PlatformLayout",
- * "Plan-出入口布局图: Plan/EntranceLayout",
- * "PSCADA-一次图: PSCADA/OneTimeGraph",
- * "PSCADA-自动化系统图: PSCADA/AutoSysGraph",
- * "PSCADA-定值召唤: PSCADA/SettingCall",
- * "PSCADA-实时SOE: PSCADA/RealTimeSOE",
- * "PSCADA-历史SOE: PSCADA/HistoricalSOE",
- * "PSCADA-光字屏: PSCADA/Screen",
- * "BAS-大系统: BAS/BigSys",
- * "BAS-小系统: BAS/SmallSys",
- * "BAS-隧道通风系统: BAS/TunnelVentilationSys",
- * "BAS-水系统: BAS/WaterSys",
- * "BAS-给排水: BAS/DrainageSys",
- * "BAS-电扶梯: BAS/Escalator",
- * "BAS-照明系统: BAS/LightingSys",
- * "BAS-传感器: BAS/Sensor",
- * "BAS-导向标识/广告: BAS/WayfindingNAds",
- * "BAS-人防门: BAS/CivilDefense",
- * "BAS-BAS系统图: BAS/BASSys",
- * "BAS-模式控制: BAS/ModeControl",
- * "BAS-时间表: BAS/TimeTable",
- * "FAS-设备分区图: FAS/DevicePartition",
- * "FAS-火灾报警平面图: FAS/FireAlarmLayout",
- * "FAS-FAS气灭系统图: FAS/GaseousFireSuppressionSys",
- * "TFDS-感温光纤状态监视图: TFDS/TFDSState",
- * "AFC-自动售检票系统监视图: AFC/AFCState",
- * "CCTV-监控布局图: CCTV/MonitorLayout",
- * "CCTV-CCTV设备布局图: CCTV/CCTVEquipLayout",
- * "PIS-PIS监控: PIS/PIS",
- * "PSD-屏蔽门系统图: PSD/PSDSys",
- * "ACS-门禁总览图: ACS/ACSOverview",
- * "ACS-门禁监视布局图-站厅: ACS/ACSLayoutHall",
- * "ACS-门禁监视布局图-站台: ACS/ACSLayoutStation",
- * "FG-防淹门状态监视图: FG/FGState",
- * "PA-PA监控: PA/PA",
- * "NMS-网络状态监视图: NMS/NMS"
- * ] - */ -@Slf4j -@RestController -@RequestMapping("/api/v2/iscs/model") -public class IscsModelDataController { - @Autowired - private IscsModelDataService modelDataService; - - /** - * 初始化模型数据 - * - * @param data 模型proto数据DataModelMap - */ - @PostMapping("/{system}/{view}/{place}/init") - public IscsModelDataBasicInfo storeModelData(@PathVariable("system") @NotNull String system, @PathVariable("view") @NotNull String view, @PathVariable("place") @NotNull String place, @RequestBody @NotNull byte[] data) { - log.debug("==>>初始化模型数据 system = {} view = {} place = {}", system, view, place); - final IscsModelData param = new IscsModelData(); - param.setSystem(system); - param.setView(view); - param.setPlace(place); - param.setData(data); - return modelDataService.storeModelData(param); - } - - /** - * 获取模型数据 - * - * @return 模型proto数据DataModelMap - */ - @GetMapping("/{system}/{view}/{place}") - @ResponseBody - public byte[] findModelDataByBasicInfo(@PathVariable("system") @NotNull String system, @PathVariable("view") @NotNull String view, @PathVariable("place") @NotNull String place) { - log.debug("==>>获取模型数据 system = {} view = {} place = {}", system, view, place); - final IscsModelDataBasicInfo param = new IscsModelDataBasicInfo(); - param.setSystem(system); - param.setView(view); - param.setPlace(place); - final IscsModelData rt = modelDataService.findModelData(param); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(null != rt && null != rt.getData(), "模型数据不存在"); - return rt.getData(); - } - /** - * 获取模型数据 - * - * @return 模型proto数据DataModelMap - */ - @GetMapping("/{id}") - @ResponseBody - public byte[] findModelDataById(@PathVariable("id") @NotNull Long id) { - log.debug("==>>获取模型数据 id = {}", id); - final IscsModelData rt = modelDataService.findModelData(id); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(null != rt && null != rt.getData(), "模型数据不存在"); - return rt.getData(); - } - /** - * 分页查询ISCS模型数据基本信息 - */ - @PostMapping("/find/page") - public PageVO findModelDataByPage(@RequestBody FindIscsModelDataBasicInfoByPageReqVo req) { - log.debug("==>>分页查询ISCS模型数据基本信息 : {}", req.toString()); - return modelDataService.findModelDataByPage(req); - } -} diff --git a/src/main/java/club/joylink/rtss/iscs/controller/ManageModelDataController.java b/src/main/java/club/joylink/rtss/iscs/controller/ManageModelDataController.java new file mode 100644 index 000000000..038bd56b8 --- /dev/null +++ b/src/main/java/club/joylink/rtss/iscs/controller/ManageModelDataController.java @@ -0,0 +1,94 @@ +package club.joylink.rtss.iscs.controller; + +import club.joylink.iscs.model.data.PageDataModelProto; +import club.joylink.rtss.exception.BusinessExceptionAssertEnum; +import club.joylink.rtss.iscs.convert.PageDataModelConvertor; +import club.joylink.rtss.iscs.entity.IscsModelData; +import club.joylink.rtss.iscs.services.IscsModelDataService; +import club.joylink.rtss.iscs.vo.FindIscsModelDataBasicInfoByPageReqVo; +import club.joylink.rtss.iscs.vo.IscsModelDataBasicInfo; +import club.joylink.rtss.vo.client.PageVO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.validation.constraints.NotNull; + +/** + * ISCS 模型数据管理接口 + */ +@Slf4j +@RestController +@RequestMapping("/api/v2/iscs/model/manage") +public class ManageModelDataController { + @Autowired + private IscsModelDataService modelDataService; + + /** + * 持久化模型数据 + * + * @param data 模型proto数据DataModelMap + */ + @PostMapping("/{system}/{view}/{place}/store") + public IscsModelDataBasicInfo storeModelData(@PathVariable("system") @NotNull String system, @PathVariable("view") @NotNull String view, @PathVariable("place") @NotNull String place, @RequestBody @NotNull byte[] data) { + log.debug("==>>存储模型数据 system = {} view = {} place = {}", system, view, place); + final IscsModelData param = new IscsModelData(); + param.setSystem(system); + param.setView(view); + param.setPlace(place); + param.setData(data); + return modelDataService.storeModelData(param); + } + + /** + * 持久化模型数据 + * + * @param data 模型proto数据DataModelMap + */ + @PostMapping("/{id}/store") + public IscsModelDataBasicInfo storeModelData(@PathVariable("id") @NotNull Long id, @RequestBody @NotNull byte[] data) { + log.debug("==>>存储模型数据 id = {}", id); + return modelDataService.updateModelData(id, data); + } + + /** + * 获取模型数据 + * + * @return PageDataModelProto.PageDataModel + */ + @GetMapping("/{system}/{view}/{place}") + @ResponseBody + public PageDataModelProto.PageDataModel findModelDataByBasicInfo(@PathVariable("system") @NotNull String system, @PathVariable("view") @NotNull String view, @PathVariable("place") @NotNull String place) { + log.debug("==>>获取模型数据 system = {} view = {} place = {}", system, view, place); + final IscsModelDataBasicInfo param = new IscsModelDataBasicInfo(); + param.setSystem(system); + param.setView(view); + param.setPlace(place); + final IscsModelData rt = modelDataService.findModelData(param); + BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(null != rt && null != rt.getData(), "模型数据不存在"); + return PageDataModelConvertor.convertFrom(rt).build(); + } + + /** + * 获取模型数据 + * + * @return 模型proto数据DataModelMap + */ + @GetMapping("/{id}") + @ResponseBody + public PageDataModelProto.PageDataModel findModelDataById(@PathVariable("id") @NotNull Long id) { + log.debug("==>>获取模型数据 id = {}", id); + final IscsModelData rt = modelDataService.findModelData(id); + BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(null != rt && null != rt.getData(), "模型数据不存在"); + return PageDataModelConvertor.convertFrom(rt).build(); + } + + /** + * 分页查询ISCS模型数据基本信息 + */ + @PostMapping("/find/page") + public PageVO findModelDataByPage(@RequestBody FindIscsModelDataBasicInfoByPageReqVo req) { + log.debug("==>>分页查询ISCS模型数据基本信息 : {}", req.toString()); + return modelDataService.findModelDataByPage(req); + } +} diff --git a/src/main/java/club/joylink/rtss/iscs/convert/PageDataModelConvertor.java b/src/main/java/club/joylink/rtss/iscs/convert/PageDataModelConvertor.java new file mode 100644 index 000000000..f2dc7aff9 --- /dev/null +++ b/src/main/java/club/joylink/rtss/iscs/convert/PageDataModelConvertor.java @@ -0,0 +1,23 @@ +package club.joylink.rtss.iscs.convert; + +import club.joylink.iscs.model.data.DataModelMapProto; +import club.joylink.iscs.model.data.PageDataModelProto; +import club.joylink.rtss.iscs.entity.IscsModelData; +import com.google.protobuf.InvalidProtocolBufferException; + +public class PageDataModelConvertor { + + public static PageDataModelProto.PageDataModel.Builder convertFrom(IscsModelData from){ + final PageDataModelProto.PageDataModel.Builder rt = PageDataModelProto.PageDataModel.newBuilder(); + rt.setId(from.getId()); + rt.setSystem(from.getSystem()); + rt.setView(from.getView()); + rt.setPlace(from.getPlace()); + try { + rt.setContent(DataModelMapProto.DataModelMap.parseFrom(from.getData())); + } catch (InvalidProtocolBufferException e) { + throw new RuntimeException(e); + } + return rt; + } +} diff --git a/src/main/java/club/joylink/rtss/iscs/memory/MemoryManager.java b/src/main/java/club/joylink/rtss/iscs/memory/MemoryManager.java new file mode 100644 index 000000000..ffae16469 --- /dev/null +++ b/src/main/java/club/joylink/rtss/iscs/memory/MemoryManager.java @@ -0,0 +1,57 @@ +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; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; + +/** + * ISCS运行时存储管理 + */ +public class MemoryManager { + /** + * ISCS的页面对应的模型数据 + */ + private Map modelMemories = new HashMap<>(); + /** + * ISCS的设备产生的动作事件 + */ + private LinkedList actionEvents = new LinkedList<>(); + /** + * ISCS的设备报警事件 + */ + private LinkedList 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; + } + /////////////////////////////////////////////////////////////////////////////////////////////////////// +} diff --git a/src/main/java/club/joylink/rtss/iscs/services/proto/model/ModelMemory.java b/src/main/java/club/joylink/rtss/iscs/memory/model/ModelMemory.java similarity index 85% rename from src/main/java/club/joylink/rtss/iscs/services/proto/model/ModelMemory.java rename to src/main/java/club/joylink/rtss/iscs/memory/model/ModelMemory.java index 47e723e86..fc2d3b37c 100644 --- a/src/main/java/club/joylink/rtss/iscs/services/proto/model/ModelMemory.java +++ b/src/main/java/club/joylink/rtss/iscs/memory/model/ModelMemory.java @@ -1,13 +1,17 @@ -package club.joylink.rtss.iscs.services.proto.model; +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; import java.lang.reflect.Method; import java.util.Map; +/** + * ISCS模型数据(页面地图数据) + */ public interface ModelMemory { /** @@ -40,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; } diff --git a/src/main/java/club/joylink/rtss/iscs/memory/model/ModelMemoryId.java b/src/main/java/club/joylink/rtss/iscs/memory/model/ModelMemoryId.java new file mode 100644 index 000000000..2ebb9ead9 --- /dev/null +++ b/src/main/java/club/joylink/rtss/iscs/memory/model/ModelMemoryId.java @@ -0,0 +1,41 @@ +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; + this.place = place; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ModelMemoryId that = (ModelMemoryId) o; + return system.equals(that.system) && view.equals(that.view) && place.equals(that.place); + } + + @Override + public int hashCode() { + return Objects.hash(system, view, place); + } +} diff --git a/src/main/java/club/joylink/rtss/iscs/services/proto/model/ModelMemoryImpl.java b/src/main/java/club/joylink/rtss/iscs/memory/model/ModelMemoryImpl.java similarity index 97% rename from src/main/java/club/joylink/rtss/iscs/services/proto/model/ModelMemoryImpl.java rename to src/main/java/club/joylink/rtss/iscs/memory/model/ModelMemoryImpl.java index 41a7352c2..81b7372b3 100644 --- a/src/main/java/club/joylink/rtss/iscs/services/proto/model/ModelMemoryImpl.java +++ b/src/main/java/club/joylink/rtss/iscs/memory/model/ModelMemoryImpl.java @@ -1,4 +1,4 @@ -package club.joylink.rtss.iscs.services.proto.model; +package club.joylink.rtss.iscs.memory.model; import club.joylink.iscs.model.data.DataModelMapProto; import club.joylink.iscs.model.data.DataModelProto; @@ -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, Method> modelMap = new HashMap<>(); - public ModelMemoryImpl() { + ModelMemoryImpl() { } - + @Override + public ModelMemoryId mmId() { + return this.mmId; + } /** * 获取模型数据的引用 */ diff --git a/src/main/java/club/joylink/rtss/iscs/services/proto/model/IscsModelDataService.java b/src/main/java/club/joylink/rtss/iscs/services/IscsModelDataService.java similarity index 84% rename from src/main/java/club/joylink/rtss/iscs/services/proto/model/IscsModelDataService.java rename to src/main/java/club/joylink/rtss/iscs/services/IscsModelDataService.java index 2e050cba9..f1e4f7a10 100644 --- a/src/main/java/club/joylink/rtss/iscs/services/proto/model/IscsModelDataService.java +++ b/src/main/java/club/joylink/rtss/iscs/services/IscsModelDataService.java @@ -1,4 +1,4 @@ -package club.joylink.rtss.iscs.services.proto.model; +package club.joylink.rtss.iscs.services; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.iscs.dao.IscsModelDataDAO; @@ -56,6 +56,31 @@ public class IscsModelDataService { return rt; } + /** + * 存储模型数据 + */ + @Transactional(readOnly = false, rollbackFor = Exception.class) + public IscsModelDataBasicInfo updateModelData(final Long id, final byte[] data) { + //参数校验 + BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(null != id && null != data, "参数校验失败"); + // + final IscsModelData has = this.findBasicById(id); + BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(null != has, "模型数据基本信息不存在"); + // + final IscsModelData md = new IscsModelData(); + md.setId(id); + md.setData(data); + md.setUpdateTime(LocalDateTime.now()); + modelDataDao.updateByPrimaryKeySelective(md); + // + IscsModelDataBasicInfo rt = new IscsModelDataBasicInfo(); + rt.setId(has.getId()); + rt.setSystem(has.getSystem()); + rt.setView(has.getView()); + rt.setPlace(has.getPlace()); + return rt; + } + /** * 根据完整基本模型信息获取模型数据(包括大字段信息) */ @@ -158,6 +183,13 @@ public class IscsModelDataService { return null != list && list.size() > 0 ? list.get(0) : null; } + private IscsModelData findBasicById(Long id) { + IscsModelDataExample example = new IscsModelDataExample(); + example.createCriteria().andIdEqualTo(id); + List list = modelDataDao.selectByExample(example); + return null != list && list.size() > 0 ? list.get(0) : null; + } + /** * 根据基本信息查询模型(包括大字段信息) */ diff --git a/src/main/java/club/joylink/rtss/iscs/services/proto/model/IscsModelMemoryService.java b/src/main/java/club/joylink/rtss/iscs/services/proto/model/IscsModelMemoryService.java deleted file mode 100644 index 63c4408ba..000000000 --- a/src/main/java/club/joylink/rtss/iscs/services/proto/model/IscsModelMemoryService.java +++ /dev/null @@ -1,114 +0,0 @@ -package club.joylink.rtss.iscs.services.proto.model; - -import club.joylink.rtss.iscs.dao.IscsModelDataDAO; -import club.joylink.rtss.iscs.entity.IscsModelData; -import club.joylink.rtss.iscs.entity.IscsModelDataExample; -import club.joylink.rtss.iscs.services.proto.model.ModelMemory; -import lombok.Getter; -import lombok.Setter; -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; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; - -/** - * iscs的所有页面的模型数据 - */ -@Service -public class IscsModelMemoryService { - @Autowired - private IscsModelDataDAO modelDataDao; - /** - * key : iscs的类型
- * value : iscs的所有页面的模型数据
- */ - private final Map> modelMemoryMap = new ConcurrentHashMap<>(); - - /** - * iscs启动时加载模型数据 - */ - @Transactional(readOnly = true) - public void loadModelData() throws Exception { - final List mmiList = this.findAllModelMemoryIndex(ISCS_DEFAULT_TYPE); - for (ModelMemoryIndex mmi : mmiList) { - final Map map = getIscsModelMap(mmi.type); - map.put(mmi, this.loadModelMemory(mmi)); - } - } - - //////////////////////////////////////////////////////////////////////////////////////////////////// - private synchronized Map getIscsModelMap(String iscsType) { - Map map = modelMemoryMap.get(iscsType); - if (null == map) { - map = new ConcurrentHashMap<>(); - modelMemoryMap.put(iscsType, map); - } - return map; - } - - private List findAllModelMemoryIndex(String iscsType) { - final List rt = new ArrayList<>(); - // - final IscsModelDataExample example = new IscsModelDataExample(); - final List list = modelDataDao.selectByExample(example); - if (null != list) { - list.forEach(md -> { - rt.add(new ModelMemoryIndex(md.getSystem(), md.getView(), md.getPlace())); - }); - } - return rt; - } - - private ModelMemory loadModelMemory(ModelMemoryIndex mmi) throws Exception { - IscsModelDataExample example = new IscsModelDataExample(); - example.createCriteria().andSystemEqualTo(mmi.system).andViewEqualTo(mmi.view).andPlaceEqualTo(mmi.place); - List list = modelDataDao.selectByExampleWithBLOBs(example); - return ModelMemory.create(list.get(0).getData()); - } - /////////////////////////////////////////////////////////////////////////////////////////////// - - /** - * 模型数据的索引(页面id) - */ - @Getter - @Setter - public static class ModelMemoryIndex { - //iscs 类型(扩展用,暂时默认值) - private String type = ISCS_DEFAULT_TYPE; - //iscs 系统(一级菜单) - private String system; - //iscs 视图(二级菜单) - private String view; - //iscs 场所(车站、变电所,等)(三级菜单) - private String place; - - public ModelMemoryIndex() { - } - - public ModelMemoryIndex(String system, String view, String place) { - this.system = system; - this.view = view; - this.place = place; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ModelMemoryIndex that = (ModelMemoryIndex) o; - return type.equals(that.type) && system.equals(that.system) && view.equals(that.view) && place.equals(that.place); - } - - @Override - public int hashCode() { - return Objects.hash(type, system, view, place); - } - } - - public static final String ISCS_DEFAULT_TYPE = "FAST_TRAIN"; -} diff --git a/src/main/java/club/joylink/rtss/iscs/services/soe/IscsSoeService.java b/src/main/java/club/joylink/rtss/iscs/services/soe/IscsSoeService.java deleted file mode 100644 index 8de47cf7a..000000000 --- a/src/main/java/club/joylink/rtss/iscs/services/soe/IscsSoeService.java +++ /dev/null @@ -1,4 +0,0 @@ -package club.joylink.rtss.iscs.services.soe; - -public class IscsSoeService { -} diff --git a/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java b/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java index 4752ced6b..54a95fe9c 100644 --- a/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java +++ b/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java @@ -98,6 +98,17 @@ public class Training2RuleService { return Arrays.asList("生成完成!"); } + /** + * + * @param mapId + * @param functionId + * @return + */ + public List generateTrainingByMapIdAndFunId(Long mapId, Long functionId) { + String groupId = simulationService.querySimulationByMapIdAndMapFunction(mapId, functionId); + return generateTrainingByRule(groupId); + } + public void test(String groupId) { Simulation simulation = simulationManager.getById(groupId , Simulation.class); Switch aSwitch = simulation.getRepository().getByCode("W32728", Switch.class); diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/BgSceneStatusRule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/BgSceneStatusRule.java index a9f560a63..f3d064fdd 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/rule/BgSceneStatusRule.java +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/BgSceneStatusRule.java @@ -263,11 +263,9 @@ public enum BgSceneStatusRule { @Override public String doHandle(Simulation simulation, MapElement mapElement) { Signal signal = (Signal) mapElement; - List fltRouteList = signal.getRouteList().stream().filter(Route::isFlt).collect(Collectors.toList()); - fltRouteList.forEach(route -> { - openRouteDirect(simulation, route); - route.setFleetMode(true); - }); + Route route = signal.getRouteList().get(0); + openRouteDirect(simulation, route); + route.setFleetMode(true); return getBgScene(simulation); } }, diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java index 124113fb8..c90c187d1 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java @@ -22,9 +22,8 @@ public enum MapDeviceRule { List stationList = simulation.getBuildParams().getMap().getGraphDataNew().getStationList() .stream().filter(s -> s.isVisible() && s.isCentralized() && s.isCiStation() && !s.isDepot()) .sorted(Comparator.comparing(MapStationNewVO::getSn)) - .map(MapStationNewVO::getCode) - .map(code -> simulation.getRepository().getByCode(code, Station.class)) - .collect(Collectors.toList()); + .map(MapStationNewVO::getCode).map(code -> simulation.getRepository().getByCode(code, Station.class)) + .filter(Station::isInterlock).collect(Collectors.toList()); return generateRandomElement(stationList, NUMBER); } }, @@ -38,7 +37,7 @@ public enum MapDeviceRule { Station firstStation = stationList.get(0); Station lastStation = stationList.get(stationList.size() - 1); List standList = simulation.getRepository().getStandList().stream().filter(stand -> { - if (stand.getStation() != null && stand.getStation().isDepot()) + if (stand.getStation() != null && (stand.getStation().isDepot() || !stand.getStation().isInterlock())) return false; // 去除第一个与最后一个站的站台 if (firstStation.equals(stand.getStation()) || lastStation.equals(stand.getStation())) { @@ -47,7 +46,6 @@ public enum MapDeviceRule { if (!stand.isVisible() || !stand.hasDoor() || stand.isSmall()) { // 特殊站台 return false; } - return true; }).sorted(Comparator.comparingInt(stand -> stand.getStation().getSn())).collect(Collectors.toList()); return MapDeviceRule.generateRandomElement(standList, NUMBER); @@ -63,7 +61,7 @@ public enum MapDeviceRule { Station firstStation = stationList.get(0); Station lastStation = stationList.get(stationList.size() - 1); List standList = simulation.getRepository().getStandList().stream().filter(stand -> { - if (stand.getStation() != null && stand.getStation().isDepot()) + if (stand.getStation() != null && (stand.getStation().isDepot() || !stand.getStation().isInterlock())) return false; // 去除第一个与最后一个站的站台 if (firstStation.equals(stand.getStation()) || lastStation.equals(stand.getStation())) { @@ -88,10 +86,12 @@ public enum MapDeviceRule { if (route.getStart() == null || route.getStart().isVirtual()) { return false; } - if (route.getStart().getStation()!= null && route.getStart().getStation().isDepot()) { + if (route.getStart().getStation() != null + && (route.getStart().getStation().isDepot() || !route.getStart().getStation().isInterlock())) { return false; } - if (route.getStart().getDeviceStation()!= null && route.getStart().getDeviceStation().isDepot()) { + if (route.getStart().getDeviceStation() != null + && (route.getStart().getDeviceStation().isDepot() || !route.getStart().getDeviceStation().isInterlock())) { return false; } if (route.getSectionList().size() < 2) { @@ -122,6 +122,9 @@ public enum MapDeviceRule { .filter(aSwitch -> { if (aSwitch.getDeviceStation() != null && aSwitch.getDeviceStation().isDepot()) return false; + if (!aSwitch.getDeviceStation().isInterlock()) { + return false; + } if (aSwitch.isSingleLock()) { return false; } @@ -137,7 +140,7 @@ public enum MapDeviceRule { .filter(aSwitch -> { if (aSwitch.getDeviceStation() != null && aSwitch.getDeviceStation().isDepot()) return false; - if (!aSwitch.getDeviceStation().isHasControlMode()) { + if (!aSwitch.getDeviceStation().isHasControlMode() || !aSwitch.getDeviceStation().isInterlock()) { return false; } if (aSwitch.isSingleLock()) { @@ -169,14 +172,20 @@ public enum MapDeviceRule { if (route.getStart().getStation() != null && route.getStart().getStation().isDepot()) { return false; } + if (route.getStart().getStation() != null && !route.getStart().getStation().isInterlock()) { + return false; + } if (route.getStart().getDeviceStation() != null && route.getStart().getDeviceStation().isDepot()) { return false; } - if (route.isArs() || route.isGuide()) { + if (route.getStart().getDeviceStation() != null && !route.getStart().getDeviceStation().isInterlock()) { + return false; + } + if ((!route.isArs()) || route.isGuide()) { return false; } return true; - }).map(route -> route.getStart()).distinct().collect(Collectors.toList()); + }).map(Route::getStart).distinct().collect(Collectors.toList()); return MapDeviceRule.generateRandomElement(signalList, NUMBER); } }, @@ -214,7 +223,16 @@ public enum MapDeviceRule { public List filterMapDeviceList(Simulation simulation) { //找到所有有控制模式的车站 List stationList = simulation.getRepository().getStationList().stream() - .filter(Station::isHasControlMode).collect(Collectors.toList()); + .filter(s -> s.isHasControlMode() && s.isInterlock()).collect(Collectors.toList()); + return MapDeviceRule.generateRandomElement(stationList, NUMBER); + } + }, + INTERLOCK_STATION_LIST("联锁车站列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + //找到所有有控制模式的车站 + List stationList = simulation.getRepository().getStationList().stream() + .filter(Station::isInterlock).collect(Collectors.toList()); return MapDeviceRule.generateRandomElement(stationList, NUMBER); } } @@ -262,6 +280,9 @@ public enum MapDeviceRule { if (deviceStation != null && deviceStation.isDepot()) { return false; } + if (deviceStation != null && !deviceStation.isInterlock()) { + return false; + } Section axleCounterSection = section.findAxleCounterSection(); if (axleCounterSection != null) { Station axleDeviceStation = axleCounterSection.getDeviceStation();