pa/pis系统消息类型作为操作参数

This commit is contained in:
thesai 2022-01-19 14:36:13 +08:00
parent 2e06dd9031
commit 4e07a65b6a
5 changed files with 37 additions and 56 deletions

View File

@ -1,6 +1,5 @@
package club.joylink.rtss.services.iscs.interactive; package club.joylink.rtss.services.iscs.interactive;
import club.joylink.rtss.constants.IscsSystem;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.audio.AudioResourcesService; import club.joylink.rtss.services.audio.AudioResourcesService;
import club.joylink.rtss.services.voice.IVoiceService; import club.joylink.rtss.services.voice.IVoiceService;
@ -11,7 +10,6 @@ import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityAudio; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityAudio;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import club.joylink.rtss.vo.client.audio.AudioResourcesVO; import club.joylink.rtss.vo.client.audio.AudioResourcesVO;
import club.joylink.rtss.vo.client.iscs.IscsAudioResourceVO;
import club.joylink.rtss.vo.client.iscs.PlayParamVO; import club.joylink.rtss.vo.client.iscs.PlayParamVO;
import club.joylink.rtss.vo.client.iscs.systemRes.IscsSystemResourcesVO; import club.joylink.rtss.vo.client.iscs.systemRes.IscsSystemResourcesVO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -33,17 +31,17 @@ public class IscsInteractiveService {
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(member != null && (member.isDispatcher() || member.isStationSupervisor()), BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(member != null && (member.isDispatcher() || member.isStationSupervisor()),
"仅行调和行值可操作"); "仅行调和行值可操作");
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(param.getResourceId(), "资源id不能为null"); BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(param.getResourceId(), "资源id不能为null");
IscsAudioResourceVO resourceVO = simulation.getIscsRepository().getIscsAudioResource(param.getResourceId()); AudioResourcesVO resourceVO = simulation.getIscsRepository().getAudioResource(param.getResourceId());
SimulationDataRepository repository = simulation.getRepository(); SimulationDataRepository repository = simulation.getRepository();
for (String code : param.getIscsDeviceCodes()) { for (String code : param.getIscsDeviceCodes()) {
MapElement element = repository.getByCode(code); MapElement element = repository.getByCode(code);
if (element instanceof Audio) { if (element instanceof Audio) {
Audio audio = (Audio) element; Audio audio = (Audio) element;
audio.updateResource(resourceVO); audio.updateResource(resourceVO);
audio.updateState(getPaState(resourceVO, member)); audio.updateState(getPaState(param.getType(), member));
audio.updateRemain(Audio.DEFAULT_REMAIN); audio.updateRemain(Audio.DEFAULT_REMAIN);
VirtualRealityAudio vrAudio = audio.getVrAudio(); VirtualRealityAudio vrAudio = audio.getVrAudio();
vrAudio.updateUrl(resourceVO.getAudioResourcesVO().getUrl()); vrAudio.updateUrl(resourceVO.getUrl());
vrAudio.control(VirtualRealityAudio.Command.PLAY); vrAudio.control(VirtualRealityAudio.Command.PLAY);
} }
} }
@ -66,15 +64,14 @@ public class IscsInteractiveService {
public String pisPlay(Simulation simulation, PlayParamVO param, SimulationMember member) { public String pisPlay(Simulation simulation, PlayParamVO param, SimulationMember member) {
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(member != null && (member.isDispatcher() || member.isStationSupervisor()), BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(member != null && (member.isDispatcher() || member.isStationSupervisor()),
"仅行调和行值可操作"); "仅行调和行值可操作");
IscsAudioResourceVO resourceVO; AudioResourcesVO resourceVO;
if (param.getResourceId() != null) { if (!IscsSystemResourcesVO.Type.REAL_TIME.equals(param.getType())) {
resourceVO = simulation.getIscsRepository().getIscsAudioResource(param.getResourceId()); resourceVO = simulation.getIscsRepository().getAudioResource(param.getResourceId());
} else { } else {
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertHasText(param.getName(), "实时消息名称不能为空"); BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertHasText(param.getName(), "实时消息名称不能为空");
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertHasText(param.getContent(), "实时消息内容不能为空"); BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertHasText(param.getContent(), "实时消息内容不能为空");
String url = iVoiceService.synthesis(param.getContent(), "0"); String url = iVoiceService.synthesis(param.getContent(), "0");
AudioResourcesVO audioResourcesVO = new AudioResourcesVO(param.getName(), param.getContent(), url); resourceVO = new AudioResourcesVO(param.getName(), param.getContent(), url);
resourceVO = new IscsAudioResourceVO(audioResourcesVO, IscsSystem.PIS, IscsSystemResourcesVO.Type.REAL_TIME);
} }
SimulationDataRepository repository = simulation.getRepository(); SimulationDataRepository repository = simulation.getRepository();
boolean play = false; boolean play = false;
@ -84,13 +81,13 @@ public class IscsInteractiveService {
Audio audio = (Audio) element; Audio audio = (Audio) element;
audio.updateResource(resourceVO); audio.updateResource(resourceVO);
VirtualRealityAudio vrAudio = audio.getVrAudio(); VirtualRealityAudio vrAudio = audio.getVrAudio();
vrAudio.updateUrl(resourceVO.getAudioResourcesVO().getUrl()); vrAudio.updateUrl(resourceVO.getUrl());
vrAudio.control(VirtualRealityAudio.Command.PLAY); vrAudio.control(VirtualRealityAudio.Command.PLAY);
play = true; play = true;
} }
} }
if (play) { if (play) {
return resourceVO.getAudioResourcesVO().getUrl(); return resourceVO.getUrl();
} }
return null; return null;
} }
@ -107,24 +104,25 @@ public class IscsInteractiveService {
} }
} }
private String getPaState(IscsAudioResourceVO resourcesVO, SimulationMember member) { private String getPaState(IscsSystemResourcesVO.Type resourceType, SimulationMember member) {
boolean dispatcher = member.isDispatcher(); boolean dispatcher = member.isDispatcher();
if (IscsSystemResourcesVO.Type.BGM.equals(resourcesVO.getType())) { switch (resourceType) {
return Audio.State.BGM; case RECORDING:
}
if (dispatcher) { if (dispatcher) {
if (IscsSystemResourcesVO.Type.RECORDING.equals(resourcesVO.getType())) {
return Audio.State.CENTER_NORMAL; return Audio.State.CENTER_NORMAL;
} else if (IscsSystemResourcesVO.Type.EMERGENCY_RECORDING.equals(resourcesVO.getType())) {
return Audio.State.CENTER_EMERGENCY;
}
} else { } else {
if (IscsSystemResourcesVO.Type.RECORDING.equals(resourcesVO.getType())) {
return Audio.State.STATION_NORMAL; return Audio.State.STATION_NORMAL;
} else if (IscsSystemResourcesVO.Type.EMERGENCY_RECORDING.equals(resourcesVO.getType())) { }
case EMERGENCY_RECORDING:
if (dispatcher) {
return Audio.State.CENTER_EMERGENCY;
} else {
return Audio.State.STATION_EMERGENCY; return Audio.State.STATION_EMERGENCY;
} }
case BGM:
return Audio.State.BGM;
default:
throw new IllegalStateException("Unexpected value: " + resourceType);
} }
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("消息类型异常");
} }
} }

View File

@ -4,7 +4,6 @@ import club.joylink.rtss.constants.IscsSystem;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.cbtc.data.vo.iscs.IscsStatusVO; import club.joylink.rtss.simulation.cbtc.data.vo.iscs.IscsStatusVO;
import club.joylink.rtss.vo.client.audio.AudioResourcesVO; import club.joylink.rtss.vo.client.audio.AudioResourcesVO;
import club.joylink.rtss.vo.client.iscs.IscsAudioResourceVO;
import club.joylink.rtss.vo.client.iscs.systemRes.IscsSystemResourcesVO; import club.joylink.rtss.vo.client.iscs.systemRes.IscsSystemResourcesVO;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
@ -57,12 +56,12 @@ public class SimulationIscsDataRepository {
return stream.collect(Collectors.toList()); return stream.collect(Collectors.toList());
} }
public IscsAudioResourceVO getIscsAudioResource(long resourceId) { public AudioResourcesVO getAudioResource(long resourceId) {
for (IscsSystemResourcesVO systemResource : systemResources) { for (IscsSystemResourcesVO systemResource : systemResources) {
if (!CollectionUtils.isEmpty(systemResource.getResources())) { if (!CollectionUtils.isEmpty(systemResource.getResources())) {
for (AudioResourcesVO resource : systemResource.getResources()) { for (AudioResourcesVO resource : systemResource.getResources()) {
if (Objects.equals(resourceId, resource.getId())) { if (Objects.equals(resourceId, resource.getId())) {
return new IscsAudioResourceVO(resource, systemResource.getSystem(), systemResource.getType()); return resource;
} }
} }
} }

View File

@ -2,7 +2,7 @@ package club.joylink.rtss.simulation.cbtc.data.map;
import club.joylink.rtss.constants.IscsSystem; import club.joylink.rtss.constants.IscsSystem;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityAudio; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityAudio;
import club.joylink.rtss.vo.client.iscs.IscsAudioResourceVO; import club.joylink.rtss.vo.client.audio.AudioResourcesVO;
import club.joylink.rtss.vo.client.iscs.device.IscsDeviceVO; import club.joylink.rtss.vo.client.iscs.device.IscsDeviceVO;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter; import lombok.Getter;
@ -24,7 +24,7 @@ public class Audio extends MapElement{
private String state; private String state;
private IscsAudioResourceVO resource; private AudioResourcesVO resource;
/** /**
* 剩余播放时长/ms * 剩余播放时长/ms
@ -50,7 +50,7 @@ public class Audio extends MapElement{
} }
} }
public void updateResource(IscsAudioResourceVO resource) { public void updateResource(AudioResourcesVO resource) {
this.resource = resource; this.resource = resource;
} }

View File

@ -1,21 +0,0 @@
package club.joylink.rtss.vo.client.iscs;
import club.joylink.rtss.constants.IscsSystem;
import club.joylink.rtss.vo.client.audio.AudioResourcesVO;
import club.joylink.rtss.vo.client.iscs.systemRes.IscsSystemResourcesVO;
import lombok.Getter;
@Getter
public class IscsAudioResourceVO {
private AudioResourcesVO audioResourcesVO;
private IscsSystem system;
private IscsSystemResourcesVO.Type type;
public IscsAudioResourceVO(AudioResourcesVO resource, IscsSystem system, IscsSystemResourcesVO.Type type) {
this.audioResourcesVO = resource;
this.system = system;
this.type = type;
}
}

View File

@ -1,10 +1,12 @@
package club.joylink.rtss.vo.client.iscs; package club.joylink.rtss.vo.client.iscs;
import club.joylink.rtss.vo.client.iscs.systemRes.IscsSystemResourcesVO;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
/** /**
@ -14,6 +16,9 @@ import java.util.List;
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor
public class PlayParamVO { public class PlayParamVO {
@NotNull(message = "类型不能为null")
private IscsSystemResourcesVO.Type type;
private Long resourceId; private Long resourceId;
@NotEmpty(message = "设备编号不能为空") @NotEmpty(message = "设备编号不能为空")