语音指令

This commit is contained in:
tiger_zhou 2023-03-31 10:13:07 +08:00
parent a23bf72997
commit d5a43c0af9
49 changed files with 1349 additions and 1099 deletions

View File

@ -1,23 +1,25 @@
package club.joylink.rtss.configuration;
import club.joylink.rtss.simulation.cbtc.command.voice.match.IVoiceCommandMatcher;
import club.joylink.rtss.simulation.cbtc.command.voice.analyse.PinYinSplitWordAnalyse;
import club.joylink.rtss.simulation.cbtc.command.voice.analyse.VoiceCommandAnalyse;
import club.joylink.rtss.simulation.cbtc.command.voice.match.PinYinViolenceMatchHandler;
import club.joylink.rtss.simulation.cbtc.command.voice2.analyse.DefaultPinYinSplitWordAnalyse;
import club.joylink.rtss.simulation.cbtc.command.voice2.match.IVoiceCommandMatcher;
import club.joylink.rtss.simulation.cbtc.command.voice2.match.DefaultPinYinViolenceMatch;
import club.joylink.rtss.simulation.cbtc.command.voice2.work.IDeviceWorkHandle;
import club.joylink.rtss.simulation.cbtc.command.voice2.work.VoiceCommandAnalyseWork;
import club.joylink.rtss.simulation.cbtc.command.voice2.work.device.StandWork;
import club.joylink.rtss.simulation.cbtc.command.voice2.work.device.SwitchWork;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
@Configuration
public class VoiceCommandConfig {
/**
* VoiceCommandAnalyse 注入 一种类型只能被注入一次,类型查看handleType方法
* @return
*/
@Bean
public VoiceCommandAnalyse voiceCommandAnalyse(){
PinYinSplitWordAnalyse sw = new PinYinSplitWordAnalyse();
return sw;
@PostConstruct
private void initAnalyse(){
//加入指令分析
VoiceCommandAnalyseWork.addAnalyse(new DefaultPinYinSplitWordAnalyse());
}
/**
@ -26,7 +28,17 @@ public class VoiceCommandConfig {
*/
@Bean
public IVoiceCommandMatcher matchHandler(){
PinYinViolenceMatchHandler matchHandler = new PinYinViolenceMatchHandler();
DefaultPinYinViolenceMatch matchHandler = new DefaultPinYinViolenceMatch();
return matchHandler;
}
@Bean
public IDeviceWorkHandle switchWork(){
return new SwitchWork();
}
@Bean
public IDeviceWorkHandle standWork(){
return new StandWork();
}
}

View File

@ -0,0 +1,56 @@
package club.joylink.rtss.controller.voice;
import club.joylink.rtss.controller.advice.AuthenticateInterceptor;
import club.joylink.rtss.services.voice.IVoiceConfigDataService;
import club.joylink.rtss.services.voice.IVoiceTrainingService;
import club.joylink.rtss.services.voice.baidu.TokenHolder;
import club.joylink.rtss.simulation.cbtc.command.voice2.operate.OperateEnum;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.PageQueryVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.competition.VoiceErrorVO;
import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult;
import club.joylink.rtss.vo.voice.VoiceConfigDataVO;
import club.joylink.rtss.vo.voice.VoiceQueryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
/**
* 语音AI接口
*/
@RestController
@RequestMapping("/api/voice/cmds/manage")
public class VoiceCommandManageController {
@Autowired
private IVoiceConfigDataService configDataService;
@GetMapping("{id}")
public VoiceConfigDataVO voiceRecognition(@PathVariable(name = "id") Long id) {
return this.configDataService.findById(id);
}
@PostMapping("saveOrUpdate")
public void pagedQueryErrorSet(@RequestBody VoiceConfigDataVO configDataVO, @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO userInfoVO) {
this.configDataService.saveOrUpdate(configDataVO,userInfoVO);
}
@GetMapping("query")
public PageVO<VoiceConfigDataVO> query(@ModelAttribute VoiceQueryVO query){
return this.configDataService.query(query);
}
@GetMapping("change/{id}/{status}")
public void changeStatus(@PathVariable(name="id") Long id, @PathVariable(name = "status") Integer status){
this.configDataService.changeStatus(id,status);
}
@GetMapping("type")
public Map<String, List<OperateEnum>> findType(){
return this.configDataService.findDeviceType();
}
}

View File

@ -1,40 +0,0 @@
package club.joylink.rtss.dao.voice;
import club.joylink.rtss.entity.voice.VoiceDeviceConfig;
import club.joylink.rtss.entity.voice.VoiceDeviceConfigExample;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@Mapper
@Repository
public interface VoiceDeviceConfigDAO {
long countByExample(VoiceDeviceConfigExample example);
int deleteByExample(VoiceDeviceConfigExample example);
int deleteByPrimaryKey(Long id);
int insert(VoiceDeviceConfig record);
int insertSelective(VoiceDeviceConfig record);
List<VoiceDeviceConfig> selectByExampleWithBLOBs(VoiceDeviceConfigExample example);
List<VoiceDeviceConfig> selectByExample(VoiceDeviceConfigExample example);
VoiceDeviceConfig selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") VoiceDeviceConfig record, @Param("example") VoiceDeviceConfigExample example);
int updateByExampleWithBLOBs(@Param("record") VoiceDeviceConfig record, @Param("example") VoiceDeviceConfigExample example);
int updateByExample(@Param("record") VoiceDeviceConfig record, @Param("example") VoiceDeviceConfigExample example);
int updateByPrimaryKeySelective(VoiceDeviceConfig record);
int updateByPrimaryKeyWithBLOBs(VoiceDeviceConfig record);
int updateByPrimaryKey(VoiceDeviceConfig record);
}

View File

@ -0,0 +1,40 @@
package club.joylink.rtss.dao.voice2;
import club.joylink.rtss.entity.voice2.VoiceDeviceConfig2;
import club.joylink.rtss.entity.voice2.VoiceDeviceConfig2Example;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@Mapper
@Repository
public interface VoiceDeviceConfig2DAO {
long countByExample(VoiceDeviceConfig2Example example);
int deleteByExample(VoiceDeviceConfig2Example example);
int deleteByPrimaryKey(Long id);
int insert(VoiceDeviceConfig2 record);
int insertSelective(VoiceDeviceConfig2 record);
List<VoiceDeviceConfig2> selectByExampleWithBLOBs(VoiceDeviceConfig2Example example);
List<VoiceDeviceConfig2> selectByExample(VoiceDeviceConfig2Example example);
VoiceDeviceConfig2 selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") VoiceDeviceConfig2 record, @Param("example") VoiceDeviceConfig2Example example);
int updateByExampleWithBLOBs(@Param("record") VoiceDeviceConfig2 record, @Param("example") VoiceDeviceConfig2Example example);
int updateByExample(@Param("record") VoiceDeviceConfig2 record, @Param("example") VoiceDeviceConfig2Example example);
int updateByPrimaryKeySelective(VoiceDeviceConfig2 record);
int updateByPrimaryKeyWithBLOBs(VoiceDeviceConfig2 record);
int updateByPrimaryKey(VoiceDeviceConfig2 record);
}

View File

@ -1,9 +1,10 @@
package club.joylink.rtss.entity.voice;
package club.joylink.rtss.entity.voice2;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;
import club.joylink.rtss.simulation.cbtc.command.voice.operate.HandleType;
import club.joylink.rtss.simulation.cbtc.command.voice2.operate.OperateEnum;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import lombok.Data;
@ -12,7 +13,7 @@ import lombok.Data;
*
*/
@Data
public class VoiceDeviceConfig implements Serializable {
public class VoiceDeviceConfig2 implements Serializable {
private Long id;
/**
@ -20,6 +21,11 @@ public class VoiceDeviceConfig implements Serializable {
*/
private String describe;
/**
* 匹配类型唤醒参数
*/
private String wakeUpParmas;
/**
* 线路
*/
@ -30,16 +36,6 @@ public class VoiceDeviceConfig implements Serializable {
*/
private Long createId;
/**
* 处理方式目前只支持拼音
*/
private HandleType handleType;
/**
* 命令类型匹配关键字
*/
private String wakeUpKw;
/**
* 开始时间
*/
@ -55,15 +51,20 @@ public class VoiceDeviceConfig implements Serializable {
*/
private MapElement.DeviceType deviceType;
/**
* 操作类型
*/
private OperateEnum operateType;
/**
* 是否启用0=未启用1=启用
*/
private Integer status;
/**
* 配置
* 操作匹配参数
*/
private String config;
private String paramConfig;
private static final long serialVersionUID = 1L;
}

View File

@ -1,10 +1,10 @@
package club.joylink.rtss.entity.voice;
package club.joylink.rtss.entity.voice2;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class VoiceDeviceConfigExample {
public class VoiceDeviceConfig2Example {
protected String orderByClause;
protected boolean distinct;
@ -15,7 +15,7 @@ public class VoiceDeviceConfigExample {
private Long offset;
public VoiceDeviceConfigExample() {
public VoiceDeviceConfig2Example() {
oredCriteria = new ArrayList<Criteria>();
}
@ -255,6 +255,76 @@ public class VoiceDeviceConfigExample {
return (Criteria) this;
}
public Criteria andWakeUpParmasIsNull() {
addCriterion("wake_up_parmas is null");
return (Criteria) this;
}
public Criteria andWakeUpParmasIsNotNull() {
addCriterion("wake_up_parmas is not null");
return (Criteria) this;
}
public Criteria andWakeUpParmasEqualTo(String value) {
addCriterion("wake_up_parmas =", value, "wakeUpParmas");
return (Criteria) this;
}
public Criteria andWakeUpParmasNotEqualTo(String value) {
addCriterion("wake_up_parmas <>", value, "wakeUpParmas");
return (Criteria) this;
}
public Criteria andWakeUpParmasGreaterThan(String value) {
addCriterion("wake_up_parmas >", value, "wakeUpParmas");
return (Criteria) this;
}
public Criteria andWakeUpParmasGreaterThanOrEqualTo(String value) {
addCriterion("wake_up_parmas >=", value, "wakeUpParmas");
return (Criteria) this;
}
public Criteria andWakeUpParmasLessThan(String value) {
addCriterion("wake_up_parmas <", value, "wakeUpParmas");
return (Criteria) this;
}
public Criteria andWakeUpParmasLessThanOrEqualTo(String value) {
addCriterion("wake_up_parmas <=", value, "wakeUpParmas");
return (Criteria) this;
}
public Criteria andWakeUpParmasLike(String value) {
addCriterion("wake_up_parmas like", value, "wakeUpParmas");
return (Criteria) this;
}
public Criteria andWakeUpParmasNotLike(String value) {
addCriterion("wake_up_parmas not like", value, "wakeUpParmas");
return (Criteria) this;
}
public Criteria andWakeUpParmasIn(List<String> values) {
addCriterion("wake_up_parmas in", values, "wakeUpParmas");
return (Criteria) this;
}
public Criteria andWakeUpParmasNotIn(List<String> values) {
addCriterion("wake_up_parmas not in", values, "wakeUpParmas");
return (Criteria) this;
}
public Criteria andWakeUpParmasBetween(String value1, String value2) {
addCriterion("wake_up_parmas between", value1, value2, "wakeUpParmas");
return (Criteria) this;
}
public Criteria andWakeUpParmasNotBetween(String value1, String value2) {
addCriterion("wake_up_parmas not between", value1, value2, "wakeUpParmas");
return (Criteria) this;
}
public Criteria andMapIdIsNull() {
addCriterion("map_id is null");
return (Criteria) this;
@ -375,146 +445,6 @@ public class VoiceDeviceConfigExample {
return (Criteria) this;
}
public Criteria andHandleTypeIsNull() {
addCriterion("handle_type is null");
return (Criteria) this;
}
public Criteria andHandleTypeIsNotNull() {
addCriterion("handle_type is not null");
return (Criteria) this;
}
public Criteria andHandleTypeEqualTo(String value) {
addCriterion("handle_type =", value, "handleType");
return (Criteria) this;
}
public Criteria andHandleTypeNotEqualTo(String value) {
addCriterion("handle_type <>", value, "handleType");
return (Criteria) this;
}
public Criteria andHandleTypeGreaterThan(String value) {
addCriterion("handle_type >", value, "handleType");
return (Criteria) this;
}
public Criteria andHandleTypeGreaterThanOrEqualTo(String value) {
addCriterion("handle_type >=", value, "handleType");
return (Criteria) this;
}
public Criteria andHandleTypeLessThan(String value) {
addCriterion("handle_type <", value, "handleType");
return (Criteria) this;
}
public Criteria andHandleTypeLessThanOrEqualTo(String value) {
addCriterion("handle_type <=", value, "handleType");
return (Criteria) this;
}
public Criteria andHandleTypeLike(String value) {
addCriterion("handle_type like", value, "handleType");
return (Criteria) this;
}
public Criteria andHandleTypeNotLike(String value) {
addCriterion("handle_type not like", value, "handleType");
return (Criteria) this;
}
public Criteria andHandleTypeIn(List<String> values) {
addCriterion("handle_type in", values, "handleType");
return (Criteria) this;
}
public Criteria andHandleTypeNotIn(List<String> values) {
addCriterion("handle_type not in", values, "handleType");
return (Criteria) this;
}
public Criteria andHandleTypeBetween(String value1, String value2) {
addCriterion("handle_type between", value1, value2, "handleType");
return (Criteria) this;
}
public Criteria andHandleTypeNotBetween(String value1, String value2) {
addCriterion("handle_type not between", value1, value2, "handleType");
return (Criteria) this;
}
public Criteria andWakeUpKwIsNull() {
addCriterion("wake_up_kw is null");
return (Criteria) this;
}
public Criteria andWakeUpKwIsNotNull() {
addCriterion("wake_up_kw is not null");
return (Criteria) this;
}
public Criteria andWakeUpKwEqualTo(String value) {
addCriterion("wake_up_kw =", value, "wakeUpKw");
return (Criteria) this;
}
public Criteria andWakeUpKwNotEqualTo(String value) {
addCriterion("wake_up_kw <>", value, "wakeUpKw");
return (Criteria) this;
}
public Criteria andWakeUpKwGreaterThan(String value) {
addCriterion("wake_up_kw >", value, "wakeUpKw");
return (Criteria) this;
}
public Criteria andWakeUpKwGreaterThanOrEqualTo(String value) {
addCriterion("wake_up_kw >=", value, "wakeUpKw");
return (Criteria) this;
}
public Criteria andWakeUpKwLessThan(String value) {
addCriterion("wake_up_kw <", value, "wakeUpKw");
return (Criteria) this;
}
public Criteria andWakeUpKwLessThanOrEqualTo(String value) {
addCriterion("wake_up_kw <=", value, "wakeUpKw");
return (Criteria) this;
}
public Criteria andWakeUpKwLike(String value) {
addCriterion("wake_up_kw like", value, "wakeUpKw");
return (Criteria) this;
}
public Criteria andWakeUpKwNotLike(String value) {
addCriterion("wake_up_kw not like", value, "wakeUpKw");
return (Criteria) this;
}
public Criteria andWakeUpKwIn(List<String> values) {
addCriterion("wake_up_kw in", values, "wakeUpKw");
return (Criteria) this;
}
public Criteria andWakeUpKwNotIn(List<String> values) {
addCriterion("wake_up_kw not in", values, "wakeUpKw");
return (Criteria) this;
}
public Criteria andWakeUpKwBetween(String value1, String value2) {
addCriterion("wake_up_kw between", value1, value2, "wakeUpKw");
return (Criteria) this;
}
public Criteria andWakeUpKwNotBetween(String value1, String value2) {
addCriterion("wake_up_kw not between", value1, value2, "wakeUpKw");
return (Criteria) this;
}
public Criteria andCreateTimeIsNull() {
addCriterion("create_time is null");
return (Criteria) this;
@ -705,6 +635,76 @@ public class VoiceDeviceConfigExample {
return (Criteria) this;
}
public Criteria andOperateTypeIsNull() {
addCriterion("operate_type is null");
return (Criteria) this;
}
public Criteria andOperateTypeIsNotNull() {
addCriterion("operate_type is not null");
return (Criteria) this;
}
public Criteria andOperateTypeEqualTo(String value) {
addCriterion("operate_type =", value, "operateType");
return (Criteria) this;
}
public Criteria andOperateTypeNotEqualTo(String value) {
addCriterion("operate_type <>", value, "operateType");
return (Criteria) this;
}
public Criteria andOperateTypeGreaterThan(String value) {
addCriterion("operate_type >", value, "operateType");
return (Criteria) this;
}
public Criteria andOperateTypeGreaterThanOrEqualTo(String value) {
addCriterion("operate_type >=", value, "operateType");
return (Criteria) this;
}
public Criteria andOperateTypeLessThan(String value) {
addCriterion("operate_type <", value, "operateType");
return (Criteria) this;
}
public Criteria andOperateTypeLessThanOrEqualTo(String value) {
addCriterion("operate_type <=", value, "operateType");
return (Criteria) this;
}
public Criteria andOperateTypeLike(String value) {
addCriterion("operate_type like", value, "operateType");
return (Criteria) this;
}
public Criteria andOperateTypeNotLike(String value) {
addCriterion("operate_type not like", value, "operateType");
return (Criteria) this;
}
public Criteria andOperateTypeIn(List<String> values) {
addCriterion("operate_type in", values, "operateType");
return (Criteria) this;
}
public Criteria andOperateTypeNotIn(List<String> values) {
addCriterion("operate_type not in", values, "operateType");
return (Criteria) this;
}
public Criteria andOperateTypeBetween(String value1, String value2) {
addCriterion("operate_type between", value1, value2, "operateType");
return (Criteria) this;
}
public Criteria andOperateTypeNotBetween(String value1, String value2) {
addCriterion("operate_type not between", value1, value2, "operateType");
return (Criteria) this;
}
public Criteria andStatusIsNull() {
addCriterion("`status` is null");
return (Criteria) this;

View File

@ -1,11 +0,0 @@
package club.joylink.rtss.services.voice;
import club.joylink.rtss.vo.voice.VoiceConfigVO;
import java.util.List;
public interface IVoiceCommandDataService {
List<VoiceConfigVO> findData(Long mapId);
}

View File

@ -0,0 +1,21 @@
package club.joylink.rtss.services.voice;
import club.joylink.rtss.simulation.cbtc.command.voice2.operate.OperateEnum;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.voice.VoiceConfigDataVO;
import club.joylink.rtss.vo.voice.VoiceQueryVO;
import java.util.List;
import java.util.Map;
public interface IVoiceConfigDataService {
VoiceConfigDataVO findById(Long id);
void saveOrUpdate(VoiceConfigDataVO dataVO, LoginUserInfoVO userInfoVO);
void changeStatus(Long id,Integer status);
PageVO<VoiceConfigDataVO> query(VoiceQueryVO query);
Map<String, List<OperateEnum>> findDeviceType();
}

View File

@ -1,15 +0,0 @@
package club.joylink.rtss.services.voice;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.voice.VoiceConfigVO;
import club.joylink.rtss.vo.voice.VoiceQueryVO;
public interface IVoiceDataService {
void saveOrUpdate(VoiceConfigVO dataVO, LoginUserInfoVO userInfoVO);
VoiceConfigVO byId(Long id);
PageVO<VoiceConfigVO> query(VoiceQueryVO query);
void changeStatus(Long id,Integer status);
}

View File

@ -0,0 +1,127 @@
package club.joylink.rtss.services.voice.impl;
import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.dao.voice2.VoiceDeviceConfig2DAO;
import club.joylink.rtss.entity.voice2.VoiceDeviceConfig2;
import club.joylink.rtss.entity.voice2.VoiceDeviceConfig2Example;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.voice.IVoiceConfigDataService;
import club.joylink.rtss.simulation.cbtc.command.voice2.IVoiceCommandDataService;
import club.joylink.rtss.simulation.cbtc.command.voice2.operate.OperateEnum;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.ConfigData;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.voice.VoiceConfigDataVO;
import club.joylink.rtss.vo.voice.VoiceQueryVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@Service
@Slf4j
public class VoiceConfigDataService implements IVoiceConfigDataService, IVoiceCommandDataService {
@Resource
private VoiceDeviceConfig2DAO config2DAO;
private Optional<VoiceDeviceConfig2> byId(Long id){
VoiceDeviceConfig2 configData = this.config2DAO.selectByPrimaryKey(id);
if(Objects.nonNull(configData)){
return Optional.of(configData);
}
return Optional.empty();
}
@Override
public VoiceConfigDataVO findById(Long id) {
Optional<VoiceDeviceConfig2> optional = this.byId(id);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(optional.isPresent(),"未找到对应的数据");
return VoiceConfigDataVO.converVO(optional.get());
}
@Override
public void saveOrUpdate(VoiceConfigDataVO dataVO, LoginUserInfoVO userInfoVO) {
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(Objects.nonNull(dataVO.getMapId()),"请选择对应的线路");
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(Objects.nonNull(dataVO.getDeviceType()),"请选择操控的设备类型");
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(Objects.nonNull(dataVO.getOperateType()),"请选择设备对应的操作");
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(dataVO.getOperateType().getDeviceType() == dataVO.getDeviceType(),"设备的操作与设备类型不匹配");
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(!CollectionUtils.isEmpty(dataVO.getWakeUpParmas()),"设备唤醒匹配关键字不能为空");
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(Objects.nonNull(dataVO.getParamConfig()),"操作参数不能为空");
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(ArrayUtils.isNotEmpty(dataVO.getParamConfig().getActionKW()),"操作关键字不能为空");
VoiceDeviceConfig2 vc = dataVO.converBean();
vc.setCreateId(userInfoVO.getAccountVO().getId());
vc.setStatus(BusinessConsts.STATUS_NOT_USE_INT);
LocalDateTime dateTime = LocalDateTime.now();
vc.setCreateTime(dateTime);
vc.setUpdateTime(dateTime);
if(Objects.isNull(dataVO.getId())){
this.config2DAO.insert(vc);
}else{
Optional<VoiceDeviceConfig2> optional = this.byId(vc.getId());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(optional.isPresent(),"未找到对应的数据");
VoiceDeviceConfig2 db = optional.get();
BusinessExceptionAssertEnum.DATA_BEEN_USED.assertTrue(db.getStatus() != BusinessConsts.STATUS_USE_INT,"已上架的不能编辑");
this.config2DAO.updateByPrimaryKeySelective(vc);
}
}
@Override
public void changeStatus(Long id, Integer status) {
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(Objects.nonNull(id),"数据信息不能为空");
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(Objects.nonNull(status),"状态不能为空");
Optional<VoiceDeviceConfig2> optional = this.byId(id);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(optional.isPresent(),"未找到对应的数据");
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(status == BusinessConsts.STATUS_USE_INT || status == BusinessConsts.STATUS_NOT_USE_INT,"不确定的状态");
if(status == BusinessConsts.STATUS_USE_INT){
VoiceDeviceConfig2 db = optional.get();
VoiceDeviceConfig2Example example = new VoiceDeviceConfig2Example();
example.createCriteria().andMapIdEqualTo(db.getMapId()).andDeviceTypeEqualTo(db.getDeviceType().name())
.andOperateTypeEqualTo(db.getOperateType().name()).andStatusEqualTo(BusinessConsts.STATUS_USE_INT);
Long count = this.config2DAO.countByExample(example);
BusinessExceptionAssertEnum.DATA_BEEN_USED.assertTrue(count <= 0 ,"已经有上架类型的配置数据");
}
VoiceDeviceConfig2 configData = new VoiceDeviceConfig2();
configData.setId(id);
configData.setStatus(status);
this.config2DAO.updateByPrimaryKeySelective(configData);
}
@Override
public PageVO<VoiceConfigDataVO> query(VoiceQueryVO query) {
PageHelper.startPage(query.getPageNum(),query.getPageSize());
VoiceDeviceConfig2Example example = new VoiceDeviceConfig2Example();
Page<VoiceDeviceConfig2> sqlPage = (Page<VoiceDeviceConfig2>) this.config2DAO.selectByExampleWithBLOBs(query.createQuery(example));
List<VoiceConfigDataVO> dataVoList = sqlPage.getResult().stream().map(VoiceConfigDataVO::converVO).collect(Collectors.toList());
PageVO<VoiceConfigDataVO> page = PageVO.convert(sqlPage,dataVoList);
return page;
}
@Override
public Map<String,List<OperateEnum>> findDeviceType() {
Map<String,List<OperateEnum>> operateMapList = Arrays.stream(OperateEnum.values()).collect(Collectors.groupingBy(d->d.getDeviceType().name()));
return operateMapList;
}
@Override
public List<ConfigData> findConfigData(Long mapId) {
VoiceDeviceConfig2Example example = new VoiceDeviceConfig2Example();
VoiceQueryVO query = VoiceQueryVO.builder().mapId(mapId).status(BusinessConsts.STATUS_USE_INT).build();
List<VoiceDeviceConfig2> tmpList = this.config2DAO.selectByExampleWithBLOBs(query.createQuery(example));
List<ConfigData> voList = tmpList.stream().map(ConfigData::converVO).collect(Collectors.toList());
return voList;
}
}

View File

@ -1,178 +0,0 @@
package club.joylink.rtss.services.voice.impl;
import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.dao.voice.VoiceDeviceConfigDAO;
import club.joylink.rtss.entity.voice.VoiceDeviceConfig;
import club.joylink.rtss.entity.voice.VoiceDeviceConfigExample;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.voice.IVoiceCommandDataService;
import club.joylink.rtss.services.voice.IVoiceDataService;
import club.joylink.rtss.simulation.cbtc.command.voice.operate.HandleType;
import club.joylink.rtss.simulation.cbtc.command.voice.operate.OperateEnum;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.OperateConfigData;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.voice.VoiceConfigVO;
import club.joylink.rtss.vo.voice.VoiceQueryVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Service
@Slf4j
public class VoiceDataService implements IVoiceDataService, IVoiceCommandDataService {
@Resource
private VoiceDeviceConfigDAO configDAO;
private Cache<Long,List<club.joylink.rtss.vo.voice.VoiceConfigVO>> VOICE_CACHE = CacheBuilder.newBuilder().expireAfterWrite(3, TimeUnit.MINUTES).build();
private Optional<VoiceDeviceConfig> findById(Long id){
VoiceDeviceConfig vc = this.configDAO.selectByPrimaryKey(id);
if(Objects.nonNull(vc)){
return Optional.of(vc);
}
return Optional.empty();
}
private void checkData(VoiceConfigVO dataVO){
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(Objects.nonNull(dataVO.getWakeUpKw()),String.format("缺少类型匹配"));
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(ArrayUtils.isNotEmpty(dataVO.getWakeUpKw().getActionMatch()),String.format("类型匹配需要关键字"));
OperateConfigData configData = dataVO.getConfig().stream().filter(d->ArrayUtils.isEmpty(d.getActionMatch())).findFirst().orElse(null);
BusinessExceptionAssertEnum.DATA_INVALID.assertNotTrue(Objects.nonNull(configData),String.format("操作数据关键字不能为空"));
Map<OperateEnum,List<OperateConfigData>> mapList = dataVO.getConfig().stream().collect(Collectors.groupingBy(OperateConfigData::getOperate));
for (List<OperateConfigData> value : mapList.values()) {
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(value.size() >= 1,String.format("重复操作数据[%s]",value.get(0).getOperate().getDescribe()));
}
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(Objects.nonNull(dataVO.getMapId()),"请关联对应的线路");
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(Objects.nonNull(dataVO.getDeviceType()),"请关联对应的类型");
}
@Override
public void saveOrUpdate(VoiceConfigVO dataVO, LoginUserInfoVO userInfoVO){
this.checkData(dataVO);
VoiceDeviceConfig vc = dataVO.converBean();
vc.setCreateId(userInfoVO.getAccountVO().getId());
vc.setStatus(BusinessConsts.STATUS_NOT_USE_INT);
LocalDateTime dateTime = LocalDateTime.now();
vc.setUpdateTime(dateTime);
if(Objects.isNull(vc.getHandleType())){
vc.setHandleType(HandleType.PINYIN);
}
if(Objects.isNull(vc.getId())){
vc.setCreateTime(dateTime);
this.configDAO.insert(vc);
}else{
Optional<VoiceDeviceConfig> optional = this.findById(vc.getId());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(optional.isPresent(),"未找到对应的数据");
VoiceDeviceConfig db = optional.get();
BusinessExceptionAssertEnum.DATA_BEEN_USED.assertTrue(db.getStatus() != BusinessConsts.STATUS_USE_INT,"已上架的不能编辑");
this.configDAO.updateByPrimaryKeySelective(vc);
}
}
@Override
public club.joylink.rtss.vo.voice.VoiceConfigVO byId(Long id) {
Optional<VoiceDeviceConfig> optional = this.findById(id);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(optional.isPresent(),"未找到对应的数据");
return club.joylink.rtss.vo.voice.VoiceConfigVO.converVO(optional.get());
}
@Override
public PageVO<club.joylink.rtss.vo.voice.VoiceConfigVO> query(VoiceQueryVO query) {
PageHelper.startPage(query.getPageNum(),query.getPageSize());
Page<VoiceDeviceConfig> sqlPage = (Page<VoiceDeviceConfig>) this.configDAO.selectByExampleWithBLOBs(query.createQuery());
List<club.joylink.rtss.vo.voice.VoiceConfigVO> result = Lists.newArrayList();
for (VoiceDeviceConfig vc : sqlPage.getResult()) {
result.add(club.joylink.rtss.vo.voice.VoiceConfigVO.converVO(vc));
}
PageVO<club.joylink.rtss.vo.voice.VoiceConfigVO> page = PageVO.convert(sqlPage,result);
return page;
}
@Override
public void changeStatus(Long id, Integer status) {
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(Objects.nonNull(id),"数据信息不能为空");
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue( status == BusinessConsts.STATUS_NOT_USE_INT || status == BusinessConsts.STATUS_USE_INT,String.format("状态变更只能为%s,%s",BusinessConsts.STATUS_USE_INT,BusinessConsts.STATUS_NOT_USE_INT));
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(id),"数据信息不能为空");
Optional<VoiceDeviceConfig> optional = this.findById(id);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(optional.isPresent(),"未找到对应的数据");
VoiceDeviceConfig vc = optional.get();
BusinessExceptionAssertEnum.DATA_INVALID.assertNotTrue( status == BusinessConsts.STATUS_NOT_USE_INT && vc.getStatus() == BusinessConsts.STATUS_NOT_USE_INT,"已经是下架的数据");
if(status == BusinessConsts.STATUS_USE_INT){
BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(StringUtils.isNotEmpty(vc.getConfig()),"缺少语音指令配置信息");
// VoiceConfigData config = JsonUtils.read(vc.getWakeUpKw(), VoiceConfigData.class);
// BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(ArrayUtils.isNotEmpty(config.getSourceMatch()),String.format("%s-配置信息缺少唤醒关键字",vc.getDescribe()));
// BusinessExceptionAssertEnum.DATA_INVALID.assertTrue(ArrayUtils.isNotEmpty(config.getTranslateMatch()),String.format("%s-配置信息缺少操作关键字",vc.getDescribe()));
VoiceDeviceConfigExample voiceConfigExample = new VoiceDeviceConfigExample();
VoiceDeviceConfigExample.Criteria criteria = voiceConfigExample.createCriteria();
criteria.andStatusEqualTo(BusinessConsts.STATUS_USE_INT);
criteria.andMapIdEqualTo(vc.getMapId());
criteria.andDeviceTypeEqualTo(vc.getDeviceType().name());
long count = this.configDAO.countByExample(voiceConfigExample);
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertTrue(count <= 0L,"已经存在上架的数据");
}
VoiceDeviceConfig statConfig = new VoiceDeviceConfig();
statConfig.setId(id);
statConfig.setStatus(status);
this.configDAO.updateByPrimaryKeySelective(statConfig);
VOICE_CACHE.invalidate(vc.getMapId());
}
@Override
public List<club.joylink.rtss.vo.voice.VoiceConfigVO> findData(Long mapId) {
try {
return VOICE_CACHE.get(mapId,()->{
VoiceQueryVO query = VoiceQueryVO.builder().mapId(mapId).status(BusinessConsts.STATUS_USE_INT).build();
List<VoiceDeviceConfig> tmpList = this.configDAO.selectByExampleWithBLOBs(query.createQuery());
List<club.joylink.rtss.vo.voice.VoiceConfigVO> voList = tmpList.stream().map(club.joylink.rtss.vo.voice.VoiceConfigVO::converVO).collect(Collectors.toList());
for (club.joylink.rtss.vo.voice.VoiceConfigVO configVO : voList) {
if(configVO.getHandleType() == HandleType.PINYIN){
// VoiceConfig config = configVO.getConfig();
// pinYinList(config.getSourceMatch());
}
}
return voList;
});
} catch (ExecutionException e) {
log.error("获取对应的缓存数据失败 msg:" + e.getMessage(),e);
return Collections.emptyList();
}
}
// private void pinYinList(String[] content){
//// ArrayUtils.
// for (int i = 0; i < content.length; i++) {
// String c = content[i];
// String pinyinStr = PinYinUtil.toPinYinSplitBlankSpace(c);
// content[i] = pinyinStr;
// }
// }
// private List<String> pinYinList(List<String> content){
// List<String> pyList = Lists.newArrayList();
// for (String s : content) {
// String pinyinStr = PinYinUtil.toPinYinSplitBlankSpace(s);
// pyList.add(pinyinStr);
// }
// return pyList;
// }
}

View File

@ -8,6 +8,7 @@ import club.joylink.rtss.simulation.cbtc.CTC.data.CtcRepository;
import club.joylink.rtss.simulation.cbtc.build.SimulationBuildParams;
import club.joylink.rtss.simulation.cbtc.command.VoiceCommandBO;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.ConfigData;
import club.joylink.rtss.simulation.cbtc.competition.CompetitionBO;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.conversation.Conversation;
@ -33,6 +34,7 @@ import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.fault.FaultRuleVO;
import club.joylink.rtss.vo.permission.PermissionSubjectTypeEnum;
import club.joylink.rtss.vo.project.ProjectVO;
import club.joylink.rtss.vo.voice.VoiceConfigDataVO;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@ -126,6 +128,11 @@ public class Simulation extends club.joylink.rtss.simulation.Simulation<Simulati
// */
// private Map<Long, SimulationUser> simulationUserMap = new ConcurrentHashMap<>();
/**
* 语音设备指令配置数据
*/
private List<ConfigData> voiceConfigDataList;
/**
* 真实设备列表
*/

View File

@ -5,7 +5,10 @@ import club.joylink.rtss.services.ISysUserService;
import club.joylink.rtss.services.RunPlanDraftService;
import club.joylink.rtss.services.mapFunction.RtsMapFunctionService;
import club.joylink.rtss.services.permission.PermissionSubjectService;
import club.joylink.rtss.simulation.SimulationManager;
import club.joylink.rtss.simulation.cbtc.command.voice2.IVoiceCommandDataService;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.ConfigData;
import club.joylink.rtss.simulation.cbtc.event.SimulationCreateSuccessEvent;
import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
@ -24,6 +27,7 @@ import club.joylink.rtss.vo.client.simulationv1.RunAsPlanParam;
import club.joylink.rtss.vo.permission.PermissionSubjectTypeEnum;
import club.joylink.rtss.vo.permission.PermissionSystemAbilityVO;
import club.joylink.rtss.vo.permission.subject.PermissionSubjectVO;
import club.joylink.rtss.vo.voice.VoiceConfigDataVO;
import club.joylink.rtss.websocket.StompMessageService;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@ -66,6 +70,10 @@ public class SimulationServiceImpl implements SimulationService {
@Autowired
private ISysUserService iSysUserService;
@Autowired
private IVoiceCommandDataService commandDataService;
@Override
public String createSimulation(long mapId, Long mapFunctionId, SimulationWorkParamVO workParamVO, @NonNull LoginUserInfoVO loginUserInfoVO,Map<String,Boolean> createUserType) {
return createSimulationPojo(mapId, mapFunctionId, workParamVO, loginUserInfoVO, createUserType).getId();
@ -289,9 +297,14 @@ public class SimulationServiceImpl implements SimulationService {
public Simulation createSimulationPojo(long mapId, Long mapFunctionId, SimulationWorkParamVO workParamVO, @NonNull LoginUserInfoVO loginUserInfoVO, Map<String,Boolean> createUserType) {
//获取仿真工作服务
SimulationWorkService initService = simulationWorkServiceManager.getWorkService(workParamVO.getType());
//创建仿真
String simulationId = SimulationIdGenerator.generateGroup(loginUserInfoVO.getAccountVO().getId(), mapId);
Simulation simulation = initService.create(mapId, workParamVO, loginUserInfoVO, simulationId);
//加载语音指令配置数据
List<ConfigData> voiceConfigDataList = commandDataService.findConfigData(mapId);
simulation.setVoiceConfigDataList(voiceConfigDataList);
simulation.setMapFunctionId(mapFunctionId);
simulation.setCreateUserType(createUserType);
LoginUserInfoVO loginUserInfo = simulation.getBuildParams().getLoginUserInfo();

View File

@ -1,80 +0,0 @@
package club.joylink.rtss.simulation.cbtc.command.voice;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.voice.IVoiceCommandDataService;
import club.joylink.rtss.services.voice.IVoiceService;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.DeviceVoiceCommand;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.WorkResult;
import club.joylink.rtss.simulation.cbtc.command.voice.work.VoiceCommandAnalyseWork;
import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement;
import club.joylink.rtss.simulation.cbtc.data.map.Station;
import club.joylink.rtss.util.PinYinUtil;
import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult;
import club.joylink.rtss.vo.voice.VoiceConfigVO;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.ansj.library.DicLibrary;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Optional;
@Service
@Slf4j
public class DeviceVoiceCommandService{
@Autowired
@Qualifier("baiDuVoiceService")
private IVoiceService iVoiceService;
@Autowired
private IVoiceCommandDataService commandDataService;
@Autowired
private VoiceCommandMatchHandler matchHandler;
@Autowired
private VoiceCommandAnalyseWork analyseWork;
private List<VoiceConfigVO> findVoiceConfig(Simulation simulation){
Long mapId = simulation.getBuildParams().getMap().getId();
List<VoiceConfigVO> configVOList = this.commandDataService.findData(mapId);
BusinessExceptionAssertEnum.VOICE_COMMAND_CONFIG_NULL.assertTrue(!CollectionUtils.isEmpty(configVOList),"未找到语音配置的相关信息");
return configVOList;
}
public List<WorkResult> voiceCommand(Simulation simulation, String source){
List<VoiceConfigVO> configVOList = this.findVoiceConfig(simulation);
String tmpSource = source;
if(StringUtils.indexOf(source,"base64,") >= 0){
VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(tmpSource);
tmpSource = result.getResult();
}
BusinessExceptionAssertEnum.VOICE_COMMAND_PARSE_ERROR.assertTrue(StringUtils.isNotEmpty(tmpSource),"语音指令未识别输入内容");
log.info("获取语音识别指令原文:[{}]",tmpSource);
return this.handle(configVOList,simulation,tmpSource);
}
private List<WorkResult> handle(List<VoiceConfigVO> configVOList,Simulation simulation,String result){
List<DeviceVoiceCommand> commandList = this.matchHandler.matcher(configVOList,result);
BusinessExceptionAssertEnum.VOICE_COMMAND_PARSE_ERROR.assertTrue(!CollectionUtils.isEmpty(commandList),"语音指令未识别输入内容");
List<WorkResult> workResultList = Lists.newArrayList();
for (DeviceVoiceCommand command : commandList) {
Optional<MapNamedElement> deviceOptional = analyseWork.analyse(simulation,command);
if(deviceOptional.isEmpty()){
log.error("未找到对应的设备 类型[{}] 语音指令[{}]",command.getDeviceType(),result);
}else{
WorkResult workResult = analyseWork.work(simulation,command,deviceOptional.get());
workResultList.add(workResult);
}
}
return workResultList;
}
}

View File

@ -1,30 +0,0 @@
package club.joylink.rtss.simulation.cbtc.command.voice;
import club.joylink.rtss.simulation.cbtc.command.voice.match.IVoiceCommandMatcher;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.DeviceVoiceCommand;
import club.joylink.rtss.vo.voice.VoiceConfigVO;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.*;
@Component
@Slf4j
public class VoiceCommandMatchHandler {
@Autowired
private IVoiceCommandMatcher commandMatcher;
public List<DeviceVoiceCommand> matcher(List<VoiceConfigVO> configVOList, String msg){
List<DeviceVoiceCommand> findParseDataList = Lists.newArrayList();
for (VoiceConfigVO configVO : configVOList) {
List<DeviceVoiceCommand> commandList = commandMatcher.matchCommand(configVO,msg);
if(!CollectionUtils.isEmpty(commandList)){
findParseDataList.addAll(commandList);
}
}
return findParseDataList;
}
}

View File

@ -1,16 +0,0 @@
package club.joylink.rtss.simulation.cbtc.command.voice.analyse;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.CommandParse;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.DeviceVoiceCommand;
public interface VoiceCommandAnalyse {
String DESCRIBE_NATURE = "nature";
/**
* 解析命令
* @param Command 命令原文
* @return 解析后的数据
*/
CommandParse parseCommandDescribe(Simulation simulation, DeviceVoiceCommand Command);
}

View File

@ -1,14 +0,0 @@
package club.joylink.rtss.simulation.cbtc.command.voice.match;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.DeviceVoiceCommand;
import club.joylink.rtss.vo.voice.VoiceConfigVO;
import java.util.List;
import java.util.Optional;
public interface IMatchFilter {
List<DeviceVoiceCommand> filter();
Optional<List<DeviceVoiceCommand>> matchCommand(VoiceConfigVO configVOList, String msg);
}

View File

@ -1,13 +0,0 @@
package club.joylink.rtss.simulation.cbtc.command.voice.match;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.DeviceVoiceCommand;
import club.joylink.rtss.vo.voice.VoiceConfigVO;
import java.util.List;
public interface IVoiceCommandMatcher {
List<DeviceVoiceCommand> matchCommand(VoiceConfigVO configVOList, String msg);
// HandleType handleType();
}

View File

@ -1,56 +0,0 @@
package club.joylink.rtss.simulation.cbtc.command.voice.match;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.DeviceVoiceCommand;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.OperateConfigData;
import club.joylink.rtss.util.PinYinUtil;
import club.joylink.rtss.vo.voice.VoiceConfigVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Slf4j
public class PinYinViolenceMatchHandler implements IVoiceCommandMatcher {
@Override
public List<DeviceVoiceCommand> matchCommand(VoiceConfigVO configVO, String sourceMsg) {
String tmpPinYinContent = PinYinUtil.toPinYinSplitBlankSpace(sourceMsg);
List<DeviceVoiceCommand> commandList = this.match(configVO,sourceMsg,tmpPinYinContent);
commandList = commandList.stream().filter(d->Objects.nonNull(d.getDeviceType())
&& Objects.nonNull(d.getOperateConfigData())
&& ArrayUtils.isNotEmpty(d.getTranslateWakeUpKW())
).collect(Collectors.toList());
return commandList;
}
private List<DeviceVoiceCommand> match(VoiceConfigVO configVO,String sourceMsg, String pinyinStr){
List<DeviceVoiceCommand> commandList = new ArrayList<>();
for (OperateConfigData configData : configVO.getConfig()) {
DeviceVoiceCommand command = new DeviceVoiceCommand(configVO.getHandleType());
if(StringUtils.containsAny(pinyinStr,configVO.getWakeUpKw().getTranslateActionMatch())){
command.setDeviceType(configVO.getDeviceType());
command.setTranslateWakeUpKW(configVO.getWakeUpKw().getTranslateActionMatch());
}
if(StringUtils.containsAny(pinyinStr,configData.getTranslateActionMatch())){
if(configData.isForceMatchNature()){
if(ArrayUtils.isEmpty(configData.getTranslateNatureKW())){
log.error("强制匹配属性,但是属性为空 config id[{}]",configVO.getId());
return Collections.emptyList();
}else if(StringUtils.containsAny(pinyinStr,configData.getTranslateNatureKW())){
command.setOperateConfigData(configData);
}
}else{
command.setOperateConfigData(configData);
}
}
command.setSourceDescrbe(sourceMsg);
commandList.add(command);
}
return commandList;
}
}

View File

@ -1,10 +0,0 @@
package club.joylink.rtss.simulation.cbtc.command.voice.operate;
import lombok.Getter;
public enum HandleType {
PINYIN;
@Getter
String name;
}

View File

@ -1,40 +0,0 @@
package club.joylink.rtss.simulation.cbtc.command.voice.vo;
import club.joylink.rtss.simulation.cbtc.command.voice.operate.HandleType;
import club.joylink.rtss.simulation.cbtc.command.voice.operate.OperateEnum;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Objects;
@Data
@NoArgsConstructor
public class DeviceVoiceCommand {
public DeviceVoiceCommand(HandleType handleType) {
this.handleType = handleType;
}
private MapElement.DeviceType deviceType;
private HandleType handleType;
private OperateConfigData operateConfigData;
/**
* 匹配的类型关键字
*/
private String[] translateWakeUpKW;
private String sourceDescrbe;
/**
* 匹配的命令关键字
*/
// private String[] matchCommandKW;
// private String matchCommandDescribe;
@Override
public String toString(){
StringBuilder sb = new StringBuilder();
return sb.toString();
}
}

View File

@ -1,31 +0,0 @@
package club.joylink.rtss.simulation.cbtc.command.voice.vo;
import club.joylink.rtss.simulation.cbtc.command.voice.operate.OperateEnum;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
public class OperateConfigData extends VoiceConfigData {
private OperateEnum operate;
/**
* 描述
*/
// private String[] describeKW;
// private String[] translateDescribeKW;
/**
* 属性关键字
*/
private String[] natureKW;
private String[] translateNatureKW;
/**
* 是否强制匹配属性关键字
*/
private boolean forceMatchNature;
public OperateConfigData(OperateEnum operate) {
this.operate = operate;
}
}

View File

@ -1,13 +0,0 @@
package club.joylink.rtss.simulation.cbtc.command.voice.vo;
import lombok.Data;
@Data
public class VoiceConfigData {
/**
* 激活匹配关键字
*/
private String[] actionMatch;
private String[] translateActionMatch;
}

View File

@ -1,34 +0,0 @@
package club.joylink.rtss.simulation.cbtc.command.voice.work;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.CommandParse;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.ParseDetail;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.OperateConfigData;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.DeviceVoiceCommand;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement;
import java.util.List;
import java.util.Optional;
public interface IDeviceWork {
/**
* 根据分析出的数据查找对应的设备
* @param simulation
* @param matchCommandDescribe
* @return
*/
Optional<? extends MapNamedElement> findDevice(Simulation simulation, CommandParse commandParse, OperateConfigData configData);
/**
* 执行对应的操作
* @param simulation
* @param command
* @param device
* @return
*/
void work(Simulation simulation, DeviceVoiceCommand command, MapElement device);
MapElement.DeviceType deviceType();
}

View File

@ -1,56 +0,0 @@
package club.joylink.rtss.simulation.cbtc.command.voice.work;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.command.voice.analyse.VoiceCommandAnalyse;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.CommandParse;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.ParseDetail;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.WorkResult;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.DeviceVoiceCommand;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement;
import com.google.common.base.Joiner;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@Component
@Slf4j
public class VoiceCommandAnalyseWork {
@Resource
private VoiceCommandAnalyse commandAnalyse;
@Resource
private List<IDeviceWork> deviceWorks;
private IDeviceWork findDeviceWork(MapElement.DeviceType deviceType){
IDeviceWork deviceWork = this.deviceWorks.stream().filter(d->d.deviceType() == deviceType).findFirst().orElse(null);
BusinessExceptionAssertEnum.VOICE_COMMAND_WORK_UNDEFINED.assertTrue(Objects.nonNull(deviceWork),String.format("未找到对应的工作处理 类型:[%s]",deviceType));
return deviceWork;
}
/**
* 分析语音指令的描述并返回查找对应的设备
* @param simulation
* @param command
* @return
*/
public Optional<MapNamedElement> analyse(Simulation simulation, DeviceVoiceCommand command) {
IDeviceWork deviceWork = this.findDeviceWork(command.getDeviceType());
CommandParse commandParse = this.commandAnalyse.parseCommandDescribe(simulation,command);
// command.setMatchCommandDescribe(Joiner.on(",").join(findDeviceNames));
Optional<? extends MapNamedElement> optional = deviceWork.findDevice(simulation,commandParse,command.getOperateConfigData());
return (Optional<MapNamedElement>) optional;
}
public WorkResult work(Simulation simulation, DeviceVoiceCommand command, MapNamedElement device){
IDeviceWork deviceWork = this.findDeviceWork(command.getDeviceType());
deviceWork.work(simulation,command,device);
WorkResult result = new WorkResult(command.getDeviceType(),device,command.getOperateConfigData().getOperate());
return result;
}
}

View File

@ -0,0 +1,12 @@
package club.joylink.rtss.simulation.cbtc.command.voice2;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.ConfigData;
import club.joylink.rtss.vo.voice.VoiceConfigDataVO;
import java.util.List;
public interface IVoiceCommandDataService {
List<ConfigData> findConfigData(Long mapId);
}

View File

@ -0,0 +1,67 @@
package club.joylink.rtss.simulation.cbtc.command.voice2;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.voice.IVoiceService;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.command.voice2.match.IVoiceCommandMatcher;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.CommandParse;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.ConfigData;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.VoiceCommand;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.WorkResult;
import club.joylink.rtss.simulation.cbtc.command.voice2.work.VoiceCommandAnalyseWork;
import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Objects;
@Component
@Slf4j
public class VoiceCommandHandle {
@Autowired
@Qualifier("baiDuVoiceService")
private IVoiceService iVoiceService;
@Autowired
private IVoiceCommandMatcher commandMatcher;
@Autowired
private VoiceCommandAnalyseWork analyseWork;
public List<WorkResult> voiceCommand(Simulation simulation, String source){
List<ConfigData> configDataList = simulation.getVoiceConfigDataList();
BusinessExceptionAssertEnum.VOICE_COMMAND_CONFIG_NULL.assertTrue(!CollectionUtils.isEmpty(configDataList),"未找到语音配置的相关信息");
String tmpSource = source;
if(StringUtils.indexOf(source,"base64,") >= 0){
VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(tmpSource);
tmpSource = result.getResult();
}
BusinessExceptionAssertEnum.VOICE_COMMAND_PARSE_ERROR.assertTrue(StringUtils.isNotEmpty(tmpSource),"语音指令未识别输入内容");
log.info("获取语音识别指令原文:[{}]",tmpSource);
return this.handle(configDataList,simulation,tmpSource);
}
private List<WorkResult> handle(List<ConfigData> configDataList,Simulation simulation,String result){
List<VoiceCommand> commandList = this.commandMatcher.matcher(configDataList,result);
BusinessExceptionAssertEnum.VOICE_COMMAND_PARSE_ERROR.assertTrue(!CollectionUtils.isEmpty(commandList),"语音指令未识别匹配的内容");
List<WorkResult> workResultList = Lists.newArrayList();
for (VoiceCommand command : commandList) {
CommandParse commandParse = analyseWork.analyse(simulation,command,result);
if(Objects.isNull(commandParse)){
log.error("数据结失败 类型[{}] 动作[{}] 语音指令[{}]",command.getOperate().getDeviceType(),command.getOperate(),result);
}else{
WorkResult workResult = this.analyseWork.work(simulation,commandParse,command.getOperate());
if(Objects.isNull(workResult)){
log.error("未找到对应的设备 类型[{}] 动作[{}] 语音指令[{}]",command.getOperate().getDeviceType(),command.getOperate(),result);
}else{
workResultList.add(workResult);
}
}
}
return workResultList;
}
}

View File

@ -1,9 +1,9 @@
package club.joylink.rtss.simulation.cbtc.command.voice.analyse;
package club.joylink.rtss.simulation.cbtc.command.voice2.analyse;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.CommandParse;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.ParseDetail;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.DeviceVoiceCommand;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.CommandParse;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.ParseDetail;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.VoiceCommand;
import club.joylink.rtss.simulation.cbtc.data.map.Station;
import club.joylink.rtss.util.PinYinUtil;
import com.google.common.base.Joiner;
@ -13,21 +13,20 @@ import org.ansj.domain.Result;
import org.ansj.domain.Term;
import org.ansj.library.DicLibrary;
import org.ansj.splitWord.analysis.DicAnalysis;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
import java.util.Objects;
public class PinYinSplitWordAnalyse implements VoiceCommandAnalyse {
public class DefaultPinYinSplitWordAnalyse implements VoiceCommandAnalyse {
@Override
public synchronized CommandParse parseCommandDescribe(Simulation simulation, DeviceVoiceCommand command) {
public synchronized CommandParse parseCommandDescribe(Simulation simulation, VoiceCommand command, String sourceCommand) {
this.initDic(simulation,command);
String pinyinStr = PinYinUtil.toPinYinSplitBlankSpace(command.getSourceDescrbe());
String pinyinStr = PinYinUtil.toPinYinSplitBlankSpace(sourceCommand);
Result reslut = DicAnalysis.parse(pinyinStr);
List<ParseDetail> resultList = Lists.newArrayList();
CommandParse commandParse = new CommandParse(command.getSourceDescrbe(),pinyinStr);
CommandParse commandParse = new CommandParse();
commandParse.setDetail(resultList);
for (Term term : reslut) {
String name = term.getName().toUpperCase();
@ -43,44 +42,37 @@ public class PinYinSplitWordAnalyse implements VoiceCommandAnalyse {
private void initDic(Simulation simulation,DeviceVoiceCommand command){
private void initDic(Simulation simulation,VoiceCommand command){
DicLibrary.clear(DicLibrary.DEFAULT);
for (Station station : simulation.getRepository().getStationList()) {
String pinYinTmp = PinYinUtil.toPinYinSplitBlankSpace(station.getName()).toLowerCase();
List<String> pinyin = Splitter.onPattern("\\s").omitEmptyStrings().splitToList(pinYinTmp);
DicLibrary.insert(DicLibrary.DEFAULT,pinYinTmp,VoiceCommandAnalyse.DESCRIBE_NATURE,DicLibrary.DEFAULT_FREQ);
DicLibrary.insert(DicLibrary.DEFAULT,pinYinTmp, VoiceCommandAnalyse.DESCRIBE_NATURE,DicLibrary.DEFAULT_FREQ);
List<List<String>> subPinYinList = Lists.partition(pinyin,2);
for (List<String> strings : subPinYinList) {
String t = Joiner.on(" ").skipNulls().join(strings);
DicLibrary.insert(DicLibrary.DEFAULT,t,VoiceCommandAnalyse.DESCRIBE_NATURE,DicLibrary.DEFAULT_FREQ);
DicLibrary.insert(DicLibrary.DEFAULT,t, VoiceCommandAnalyse.DESCRIBE_NATURE,DicLibrary.DEFAULT_FREQ);
}
subPinYinList = Lists.partition(pinyin,3);
for (List<String> strings : subPinYinList) {
String t = Joiner.on(" ").skipNulls().join(strings);
DicLibrary.insert(DicLibrary.DEFAULT,t,VoiceCommandAnalyse.DESCRIBE_NATURE,DicLibrary.DEFAULT_FREQ);
DicLibrary.insert(DicLibrary.DEFAULT,t, VoiceCommandAnalyse.DESCRIBE_NATURE,DicLibrary.DEFAULT_FREQ);
}
}
for (String s : command.getTranslateWakeUpKW()) {
String[] pinYinWakeUp = PinYinUtil.toPinYins(command.getWakeUpKW());
for (String s : pinYinWakeUp) {
DicLibrary.insert(DicLibrary.DEFAULT,s.toLowerCase(),DicLibrary.DEFAULT_NATURE,DicLibrary.DEFAULT_FREQ);
}
for (String s : command.getOperateConfigData().getTranslateActionMatch()) {
String[] pinYinAction = PinYinUtil.toPinYins(command.getOperateConfigData().getActionKW());
for (String s : pinYinAction) {
DicLibrary.insert(DicLibrary.DEFAULT,s.toLowerCase(),DicLibrary.DEFAULT_NATURE,DicLibrary.DEFAULT_FREQ);
}
String[] pinYinNature = PinYinUtil.toPinYins(command.getOperateConfigData().getNatureKW());
if(ArrayUtils.isNotEmpty(command.getOperateConfigData().getTranslateNatureKW())){
for (String s : command.getOperateConfigData().getTranslateNatureKW()) {
DicLibrary.insert(DicLibrary.DEFAULT,s.toLowerCase(),VoiceCommandAnalyse.DESCRIBE_NATURE,DicLibrary.DEFAULT_FREQ);
}
for (String s : pinYinNature) {
DicLibrary.insert(DicLibrary.DEFAULT,s.toLowerCase(), VoiceCommandAnalyse.DESCRIBE_NATURE,DicLibrary.DEFAULT_FREQ);
}
/* if(ArrayUtils.isNotEmpty(command.getOperateConfigData().getTranslateDescribeKW())){
for (String s : command.getOperateConfigData().getTranslateDescribeKW()) {
DicLibrary.insert(DicLibrary.DEFAULT,s.toLowerCase(),DicLibrary.DEFAULT_NATURE,DicLibrary.DEFAULT_FREQ);
}
}*/
}
}

View File

@ -0,0 +1,16 @@
package club.joylink.rtss.simulation.cbtc.command.voice2.analyse;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.CommandParse;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.VoiceCommand;
public interface VoiceCommandAnalyse {
String DESCRIBE_NATURE = "nature";
/**
* 解析命令
* @param Command 命令原文
* @return 解析后的数据
*/
CommandParse parseCommandDescribe(Simulation simulation, VoiceCommand Command, String sourceCommandStr);
}

View File

@ -0,0 +1,44 @@
package club.joylink.rtss.simulation.cbtc.command.voice2.match;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.ConfigData;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.VoiceCommand;
import club.joylink.rtss.util.PinYinUtil;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
import java.util.Objects;
@Slf4j
public class DefaultPinYinViolenceMatch implements IVoiceCommandMatcher {
@Override
public List<VoiceCommand> matcher(List<ConfigData> configVOList, String sourceMsg) {
List<VoiceCommand> commandList = Lists.newArrayList();
for (ConfigData configData : configVOList) {
VoiceCommand command = this.matching(configData,sourceMsg);
if(Objects.nonNull(command.getOperate())){
commandList.add(command);
}
}
return commandList;
}
private VoiceCommand matching(ConfigData configData,String sourceMsg){
String pinYinSource = PinYinUtil.toPinYinSplitBlankSpace(sourceMsg);
String[] pinYinWakeUp = PinYinUtil.toPinYins(configData.getWakeUpKW());
VoiceCommand command = new VoiceCommand();
if(StringUtils.containsAnyIgnoreCase(pinYinSource,pinYinWakeUp)){
command.setWakeUpKW(configData.getWakeUpKW());
// command.setSourceDescrbe(sourceMsg);
}
String[] pinYinAction = PinYinUtil.toPinYins(configData.getOperateConfigData().getActionKW());
if(StringUtils.containsAnyIgnoreCase(pinYinSource,pinYinAction)){
command.setOperate(configData.getOperateType());
command.setOperateConfigData(configData.getOperateConfigData());
}
return command;
}
}

View File

@ -0,0 +1,12 @@
package club.joylink.rtss.simulation.cbtc.command.voice2.match;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.ConfigData;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.VoiceCommand;
import java.util.List;
public interface IVoiceCommandMatcher {
List<VoiceCommand> matcher(List<ConfigData> configVOList, String msg);
}

View File

@ -1,4 +1,4 @@
package club.joylink.rtss.simulation.cbtc.command.voice.operate;
package club.joylink.rtss.simulation.cbtc.command.voice2.operate;
import club.joylink.rtss.simulation.cbtc.ATS.service.AtsStandService;
import club.joylink.rtss.simulation.cbtc.CI.device.CiSwitchControlService;
@ -8,7 +8,6 @@ import club.joylink.rtss.simulation.cbtc.data.map.Switch;
import lombok.Getter;
public enum OperateEnum {
SWITCH_DINGWEI(MapElement.DeviceType.SWITCH,"定位"){
@Override
@ -26,7 +25,7 @@ public enum OperateEnum {
controlService.turn2ReversePosition(simulation,aswitch);
}
},
STAND_HOLD_TRAIN(MapElement.DeviceType.STAND,"扣车"){
/* STAND_HOLD_TRAIN(MapElement.DeviceType.STAND,"扣车"){
@Override
public void handle(Simulation simulation, Object objectService, MapElement device) {
AtsStandService standService = (AtsStandService) objectService;
@ -39,7 +38,7 @@ public enum OperateEnum {
AtsStandService standService = (AtsStandService) objectService;
standService.cancelHoldTrain(simulation,device.getCode());
}
},
},*/
STAND_UP_HOLD_TRAIN(MapElement.DeviceType.STAND,"上行扣车"){
@Override
public void handle(Simulation simulation, Object objectService, MapElement device) {
@ -70,6 +69,7 @@ public enum OperateEnum {
},
;
@Getter
private MapElement.DeviceType deviceType;
@Getter
private String describe;

View File

@ -1,4 +1,4 @@
package club.joylink.rtss.simulation.cbtc.command.voice.vo;
package club.joylink.rtss.simulation.cbtc.command.voice2.vo;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -10,15 +10,12 @@ import java.util.stream.Collectors;
@Data
@NoArgsConstructor
public class CommandParse {
private String descrbeCommand;
private String translateDescrbeCommand;
// private String descrbeCommand;
// private String translateDescrbeCommand;
// private OperateEnum operate;
private List<ParseDetail> detail;
public CommandParse(String descrbeCommand, String translateDescrbeCommand) {
this.descrbeCommand = descrbeCommand;
this.translateDescrbeCommand = translateDescrbeCommand;
}
public List<ParseDetail> findNatureDetail(String nature){
return this.detail.stream().filter(d-> StringUtils.equalsIgnoreCase(d.getNature(), nature)).collect(Collectors.toList());

View File

@ -0,0 +1,37 @@
package club.joylink.rtss.simulation.cbtc.command.voice2.vo;
import club.joylink.rtss.entity.voice2.VoiceDeviceConfig2;
import club.joylink.rtss.simulation.cbtc.command.voice2.operate.OperateEnum;
import club.joylink.rtss.util.JsonUtils;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Data
public class ConfigData {
// private MapElement.DeviceType deviceType;
private String[] wakeUpKW;
private OperateConfigData operateConfigData;
private OperateEnum operateType;
public static ConfigData converVO(VoiceDeviceConfig2 vc){
ConfigData configVO = new ConfigData();
configVO.setOperateType(vc.getOperateType());
// configVO.setDeviceType(vc.getDeviceType());
if(StringUtils.isNotEmpty(vc.getWakeUpParmas())){
List<String> wakeUps = JsonUtils.readCollection(vc.getWakeUpParmas(), ArrayList.class,String.class);
String[] ss = new String[wakeUps.size()];
wakeUps.toArray(ss);
configVO.setWakeUpKW(ss);
}
if(Objects.nonNull(vc.getParamConfig())){
OperateConfigData cd = JsonUtils.read(vc.getParamConfig(), OperateConfigData.class);
configVO.setOperateConfigData(cd);
}
return configVO;
}
}

View File

@ -0,0 +1,16 @@
package club.joylink.rtss.simulation.cbtc.command.voice2.vo;
import lombok.Data;
@Data
public class OperateConfigData {
// private OperateEnum operate;
/**
* 动作关键字 定位(道岔)反位(道岔),跳站(站台)扣车(站台),办理进路
*/
private String[] actionKW;
/**
* 属性关键字 上行(站台)
*/
private String[] natureKW;
}

View File

@ -1,4 +1,4 @@
package club.joylink.rtss.simulation.cbtc.command.voice.vo;
package club.joylink.rtss.simulation.cbtc.command.voice2.vo;
import lombok.Data;
import lombok.NoArgsConstructor;

View File

@ -0,0 +1,24 @@
package club.joylink.rtss.simulation.cbtc.command.voice2.vo;
import club.joylink.rtss.simulation.cbtc.command.voice2.operate.OperateEnum;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
public class VoiceCommand {
private OperateEnum operate;
private OperateConfigData operateConfigData;
/**
* 匹配的类型关键字
*/
private String[] wakeUpKW;
@Override
public String toString(){
StringBuilder sb = new StringBuilder();
return sb.toString();
}
}

View File

@ -1,7 +1,6 @@
package club.joylink.rtss.simulation.cbtc.command.voice.vo;
package club.joylink.rtss.simulation.cbtc.command.voice2.vo;
import club.joylink.rtss.simulation.cbtc.command.voice.operate.OperateEnum;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.command.voice2.operate.OperateEnum;
import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement;
import lombok.Data;
@ -9,14 +8,13 @@ import javax.validation.constraints.NotNull;
@Data
public class WorkResult {
private MapElement.DeviceType deviceType;
@NotNull
private MapNamedElement device;
@NotNull
private OperateEnum operate;
public WorkResult(MapElement.DeviceType deviceType, MapNamedElement device, OperateEnum operate) {
this.deviceType = deviceType;
public WorkResult(MapNamedElement device, OperateEnum operate) {
this.device = device;
this.operate = operate;
}
@ -25,7 +23,7 @@ public class WorkResult {
public String toString(){
StringBuilder sb = new StringBuilder();
sb.append("语音指令解析结果:\n");
sb.append(String.format("[%s] %s(%s) %s",deviceType,device.getCode(),device.getName(),operate.getDescribe()));
sb.append(String.format("[%s] %s(%s) %s",operate.getDeviceType(),device.getCode(),device.getName(),operate.getDescribe()));
return sb.toString();
}
}

View File

@ -0,0 +1,31 @@
package club.joylink.rtss.simulation.cbtc.command.voice2.work;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.command.voice2.operate.OperateEnum;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.CommandParse;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement;
import java.util.Optional;
public interface IDeviceWorkHandle {
/**
* 根据分析出的数据查找对应的设备
* @param simulation
* @param
* @return
*/
Optional<? extends MapNamedElement> findDevice(Simulation simulation, CommandParse commandParse,OperateEnum operate);
/**
* 执行对应的操作
* @param simulation
* @param
* @param device
* @return
*/
void work(Simulation simulation, OperateEnum operate, MapElement device);
MapElement.DeviceType deviceType();
}

View File

@ -0,0 +1,74 @@
package club.joylink.rtss.simulation.cbtc.command.voice2.work;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.command.voice2.analyse.VoiceCommandAnalyse;
import club.joylink.rtss.simulation.cbtc.command.voice2.operate.OperateEnum;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.CommandParse;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.VoiceCommand;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.WorkResult;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@Component
@Slf4j
public class VoiceCommandAnalyseWork {
@Resource
private List<IDeviceWorkHandle> deviceWorks;
private final static List<VoiceCommandAnalyse> ANALYSE_LIST = new ArrayList<>();
/**
* 添加分析
* @param analyse
*/
public static void addAnalyse(VoiceCommandAnalyse analyse){
ANALYSE_LIST.add(analyse);
}
private IDeviceWorkHandle findDeviceWorkHandle(MapElement.DeviceType deviceType){
IDeviceWorkHandle deviceWork = this.deviceWorks.stream().filter(d->d.deviceType() == deviceType).findFirst().orElse(null);
BusinessExceptionAssertEnum.VOICE_COMMAND_WORK_UNDEFINED.assertTrue(Objects.nonNull(deviceWork),String.format("未找到对应的工作处理 类型:[%s]",deviceType));
return deviceWork;
}
/**
* 分析语音指令的描述并返回查找对应的设备
* @param simulation
* @param command
* @return
*/
public CommandParse analyse(Simulation simulation, VoiceCommand command, String sourceCommandStr) {
for (VoiceCommandAnalyse commandAnalyse : ANALYSE_LIST) {
CommandParse commandParse = commandAnalyse.parseCommandDescribe(simulation,command, sourceCommandStr);
if(Objects.nonNull(commandParse)){
return commandParse;
}
}
return null;
}
public WorkResult work(Simulation simulation, CommandParse commandParse,OperateEnum operate){
IDeviceWorkHandle deviceWork = this.findDeviceWorkHandle(operate.getDeviceType());
Optional<? extends MapNamedElement> optional = deviceWork.findDevice(simulation,commandParse,operate);
if(optional.isEmpty()){
return null;
}else{
MapNamedElement device = optional.get();
deviceWork.work(simulation,operate,optional.get());
WorkResult result = new WorkResult(device,operate);
return result;
}
}
}

View File

@ -1,29 +1,28 @@
package club.joylink.rtss.simulation.cbtc.command.voice.work.device;
package club.joylink.rtss.simulation.cbtc.command.voice2.work.device;
import club.joylink.rtss.simulation.cbtc.ATS.service.AtsStandService;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.command.voice.analyse.VoiceCommandAnalyse;
import club.joylink.rtss.simulation.cbtc.command.voice.operate.OperateEnum;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.CommandParse;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.ParseDetail;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.DeviceVoiceCommand;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.OperateConfigData;
import club.joylink.rtss.simulation.cbtc.command.voice.work.IDeviceWork;
import club.joylink.rtss.simulation.cbtc.data.map.*;
import club.joylink.rtss.simulation.cbtc.command.voice2.analyse.VoiceCommandAnalyse;
import club.joylink.rtss.simulation.cbtc.command.voice2.operate.OperateEnum;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.CommandParse;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.ParseDetail;
import club.joylink.rtss.simulation.cbtc.command.voice2.work.IDeviceWorkHandle;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement;
import club.joylink.rtss.simulation.cbtc.data.map.Stand;
import club.joylink.rtss.simulation.cbtc.data.map.Station;
import club.joylink.rtss.util.PinYinUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.similarity.JaroWinklerSimilarity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@Component
public class StandWork implements IDeviceWork {
//@Component
public class StandWork implements IDeviceWorkHandle {
@Autowired
private AtsStandService atsStandService;
@ -48,20 +47,20 @@ public class StandWork implements IDeviceWork {
}
@Override
public Optional<? extends MapNamedElement> findDevice(Simulation simulation, CommandParse commandParse, OperateConfigData configData) {
public Optional<? extends MapNamedElement> findDevice(Simulation simulation, CommandParse commandParse,OperateEnum operate) {
String stationCode = this.findStationCode(simulation,commandParse);
if(StringUtils.isEmpty(stationCode)){
return Optional.empty();
}
OperateEnum configOperateEnum = configData.getOperate();
final boolean isRight = (configOperateEnum == OperateEnum.STAND_DOWN_HOLD_TRAIN || configOperateEnum == OperateEnum.STAND_CANCEL_DOWN_HOLD_TRAIN) ? false : true;
// OperateEnum configOperateEnum = commandParse.getOperate();
final boolean isRight = (operate == OperateEnum.STAND_DOWN_HOLD_TRAIN || operate == OperateEnum.STAND_CANCEL_DOWN_HOLD_TRAIN) ? false : true;
Optional<Stand> stand = simulation.getRepository().getStandList().stream().filter(d->d.isRight() == isRight && StringUtils.equalsIgnoreCase(d.getStation().getCode(),stationCode)).findFirst();
return stand;
}
@Override
public void work(Simulation simulation, DeviceVoiceCommand command, MapElement device) {
command.getOperateConfigData().getOperate().handle(simulation,this.atsStandService,device);
public void work(Simulation simulation, OperateEnum operate, MapElement device) {
operate.handle(simulation,this.atsStandService,device);
}
@Override

View File

@ -1,32 +1,27 @@
package club.joylink.rtss.simulation.cbtc.command.voice.work.device;
package club.joylink.rtss.simulation.cbtc.command.voice2.work.device;
import club.joylink.rtss.simulation.cbtc.CI.device.CiSwitchControlService;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.CommandParse;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.ParseDetail;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.OperateConfigData;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.DeviceVoiceCommand;
import club.joylink.rtss.simulation.cbtc.command.voice.work.IDeviceWork;
import club.joylink.rtss.simulation.cbtc.command.voice2.operate.OperateEnum;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.CommandParse;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.ParseDetail;
import club.joylink.rtss.simulation.cbtc.command.voice2.work.IDeviceWorkHandle;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement;
import club.joylink.rtss.simulation.cbtc.data.map.Switch;
import org.apache.commons.text.similarity.JaroWinklerSimilarity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@Component
public class SwitchWork implements IDeviceWork {
public class SwitchWork implements IDeviceWorkHandle {
@Autowired
private CiSwitchControlService ciSwitchControlService;
@Override
public Optional<MapNamedElement> findDevice(Simulation simulation, CommandParse commandParse, OperateConfigData configData) {
public Optional<MapNamedElement> findDevice(Simulation simulation, CommandParse commandParse,OperateEnum operate) {
JaroWinklerSimilarity similarity = new JaroWinklerSimilarity();
Map<Double,String> similarityMaper = new HashMap<>();
for (Switch aSwitch : simulation.getRepository().getSwitchList()) {
@ -45,11 +40,9 @@ public class SwitchWork implements IDeviceWork {
MapElement device = simulation.getRepository().getByCode(deviceCode);
return Optional.of((MapNamedElement)device);
}
@Override
public void work(Simulation simulation, DeviceVoiceCommand command, MapElement device) {
command.getOperateConfigData().getOperate().handle(simulation,this.ciSwitchControlService,device);
public void work(Simulation simulation, OperateEnum operate, MapElement device) {
operate.handle(simulation,this.ciSwitchControlService,device);
}
@Override

View File

@ -1,11 +1,14 @@
package club.joylink.rtss.util;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
@ -32,6 +35,9 @@ public class PinYinUtil {
}
public static String[] toPinYins(String[] source){
if(ArrayUtils.isEmpty(source)){
return ArrayUtils.EMPTY_STRING_ARRAY;
}
String[] result = new String[source.length];
for (int i = 0; i < source.length; i++) {
String s = source[i];
@ -41,11 +47,11 @@ public class PinYinUtil {
return result;
}
public static List<String> toPinyinList(String sourceMsg){
String tmpPinyinStr = toPinYinSplitBlankSpace(sourceMsg);
return Splitter.onPattern("\\s").omitEmptyStrings().splitToList(tmpPinyinStr);
}
public static String toPinYinSplitBlankSpace(String sourceMsg){
if(StringUtils.isEmpty(sourceMsg)){
return StringUtils.EMPTY;
}
StringBuilder sb = new StringBuilder();
for(char c : sourceMsg.toCharArray()){
if(Character.toString(c).matches("[\\u4E00-\\u9FA5]+")) {

View File

@ -0,0 +1,102 @@
package club.joylink.rtss.vo.voice;
import club.joylink.rtss.entity.voice2.VoiceDeviceConfig2;
import club.joylink.rtss.simulation.cbtc.command.voice2.operate.OperateEnum;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.OperateConfigData;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.util.JsonUtils;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Data
public class VoiceConfigDataVO implements Serializable {
private Long id;
/**
* 描述
*/
private String describe;
/**
* 匹配类型唤醒参数
*/
private List<String> wakeUpParmas;
/**
* 线路
*/
private Long mapId;
/**
* 编辑创建者
*/
private Long createId;
/**
* 开始时间
*/
private LocalDateTime createTime;
/**
* 修改时间
*/
private LocalDateTime updateTime;
/**
* 支持的设备类型
*/
private MapElement.DeviceType deviceType;
/**
* 操作类型
*/
private OperateEnum operateType;
/**
* 操作匹配参数
*/
private OperateConfigData paramConfig;
public VoiceDeviceConfig2 converBean(){
VoiceDeviceConfig2 vc = new VoiceDeviceConfig2();
BeanUtils.copyProperties(this, vc);
if(!CollectionUtils.isEmpty(this.wakeUpParmas)){
vc.setWakeUpParmas(JsonUtils.writeValueAsString(this.wakeUpParmas));
}
if(Objects.nonNull(this.paramConfig)){
vc.setParamConfig(JsonUtils.writeValueAsString(this.paramConfig));
}
return vc;
}
public static VoiceConfigDataVO converVO(VoiceDeviceConfig2 vc){
VoiceConfigDataVO configVO = new VoiceConfigDataVO();
configVO.setId(vc.getId());
configVO.setDescribe(vc.getDescribe());
configVO.setMapId(vc.getMapId());
configVO.setCreateId(vc.getCreateId());
configVO.setCreateTime(vc.getCreateTime());
configVO.setUpdateTime(vc.getUpdateTime());
configVO.setDeviceType(vc.getDeviceType());
configVO.setOperateType(vc.getOperateType());
if(StringUtils.isNotEmpty(vc.getWakeUpParmas())){
List<String> wakeUps = JsonUtils.readCollection(vc.getWakeUpParmas(),ArrayList.class,String.class);
configVO.setWakeUpParmas(wakeUps);
}
if(Objects.nonNull(vc.getWakeUpParmas())){
OperateConfigData cd = JsonUtils.read(vc.getWakeUpParmas(),OperateConfigData.class);
configVO.setParamConfig(cd);
}
return configVO;
}
}

View File

@ -1,118 +0,0 @@
package club.joylink.rtss.vo.voice;
import club.joylink.rtss.entity.voice.VoiceDeviceConfig;
import club.joylink.rtss.simulation.cbtc.command.voice.operate.HandleType;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.OperateConfigData;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.VoiceConfigData;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.util.PinYinUtil;
import lombok.Data;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Data
public class VoiceConfigVO implements Serializable {
private Long id;
/**
* 描述
*/
private String describe;
/**
* 线路
*/
private Long mapId;
/**
* 命令类型匹配关键字
*/
private VoiceConfigData wakeUpKw;
/**
* 处理方式目前只支持拼音
*/
private HandleType handleType;
/**
* 开始时间
*/
private LocalDateTime createTime;
/**
* 修改时间
*/
private LocalDateTime updateTime;
/**
* 支持的设备类型
*/
private MapElement.DeviceType deviceType;
/**
* 是否启用0=未启用1=启用
*/
private Integer status;
/**
* 配置
*/
private List<OperateConfigData> config;
public VoiceDeviceConfig converBean(){
VoiceDeviceConfig vc = new VoiceDeviceConfig();
if(Objects.nonNull(this.wakeUpKw)){
if(this.handleType == HandleType.PINYIN){
this.wakeUpKw.setTranslateActionMatch(PinYinUtil.toPinYins(this.wakeUpKw.getActionMatch()));
}
vc.setWakeUpKw(JsonUtils.writeValueAsString(this.wakeUpKw));
}
if(!CollectionUtils.isEmpty(this.config)){
for (OperateConfigData configData : this.config) {
if(this.handleType == HandleType.PINYIN){
configData.setTranslateActionMatch(PinYinUtil.toPinYins(configData.getActionMatch()));
if(ArrayUtils.isNotEmpty(configData.getDescribeKW())){
configData.setTranslateDescribeKW(PinYinUtil.toPinYins(configData.getDescribeKW()));
}
if(ArrayUtils.isNotEmpty(configData.getNatureKW())){
configData.setTranslateNatureKW(PinYinUtil.toPinYins(configData.getNatureKW()));
}
}
}
vc.setConfig(JsonUtils.writeValueAsString(this.config));
}
BeanUtils.copyProperties(this, vc);
return vc;
}
public static VoiceConfigVO converVO(VoiceDeviceConfig vc){
VoiceConfigVO configVO = new VoiceConfigVO();
configVO.setId(vc.getId());
configVO.setDescribe(vc.getDescribe());
configVO.setMapId(vc.getMapId());
configVO.setHandleType(vc.getHandleType());
configVO.setDeviceType(vc.getDeviceType());
configVO.setCreateTime(vc.getCreateTime());
configVO.setUpdateTime(vc.getCreateTime());
if(StringUtils.hasText(vc.getWakeUpKw())){
VoiceConfigData config = JsonUtils.read(vc.getWakeUpKw(), VoiceConfigData.class);
configVO.setWakeUpKw(config);
}
if(StringUtils.hasText(vc.getConfig())){
List<OperateConfigData> configList = JsonUtils.readCollection(vc.getConfig(), ArrayList.class,OperateConfigData.class);
configVO.setConfig(configList);
}
return configVO;
}
}

View File

@ -1,7 +1,6 @@
package club.joylink.rtss.vo.voice;
import club.joylink.rtss.entity.voice.VoiceDeviceConfigExample;
import club.joylink.rtss.simulation.cbtc.command.voice.operate.HandleType;
import club.joylink.rtss.entity.voice2.VoiceDeviceConfig2Example;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.vo.client.PageQueryVO;
import lombok.AllArgsConstructor;
@ -24,7 +23,7 @@ public class VoiceQueryVO extends PageQueryVO {
/**
* 处理方式目前只支持拼音
*/
private HandleType handleType;
// private HandleType handleType;
/**
* 支持的设备类型
*/
@ -35,19 +34,18 @@ public class VoiceQueryVO extends PageQueryVO {
*/
private Integer status;
public VoiceDeviceConfig2Example createQuery(VoiceDeviceConfig2Example example){
public VoiceDeviceConfigExample createQuery(){
VoiceDeviceConfigExample example = new VoiceDeviceConfigExample();
VoiceDeviceConfigExample.Criteria criteria = example.createCriteria();
VoiceDeviceConfig2Example.Criteria criteria = example.createCriteria();
if(StringUtils.isNotEmpty(this.getDescribe())){
criteria.andDescribeLike(String.format("%%%s%%", this.describe));
}
if(Objects.nonNull(this.mapId)){
criteria.andMapIdEqualTo(this.mapId);
}
if(Objects.nonNull(this.handleType)){
criteria.andHandleTypeEqualTo(this.handleType.name());
}
// if(Objects.nonNull(this.handleType)){
// criteria.andHandleTypeEqualTo(this.handleType.name());
// }
if(Objects.nonNull(this.deviceType)){
criteria.andDeviceTypeEqualTo(this.deviceType.name());
}
@ -56,4 +54,5 @@ public class VoiceQueryVO extends PageQueryVO {
}
return example;
}
}

View File

@ -0,0 +1,368 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="club.joylink.rtss.dao.voice2.VoiceDeviceConfig2DAO">
<resultMap id="BaseResultMap" type="club.joylink.rtss.entity.voice2.VoiceDeviceConfig2">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="describe" jdbcType="VARCHAR" property="describe" />
<result column="wake_up_parmas" jdbcType="VARCHAR" property="wakeUpParmas" />
<result column="map_id" jdbcType="BIGINT" property="mapId" />
<result column="create_id" jdbcType="BIGINT" property="createId" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="device_type" jdbcType="VARCHAR" property="deviceType" />
<result column="operate_type" jdbcType="VARCHAR" property="operateType" />
<result column="status" jdbcType="INTEGER" property="status" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="club.joylink.rtss.entity.voice2.VoiceDeviceConfig2">
<result column="param_config" jdbcType="LONGVARCHAR" property="paramConfig" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, `describe`, wake_up_parmas, map_id, create_id, create_time, update_time, device_type,
operate_type, `status`
</sql>
<sql id="Blob_Column_List">
param_config
</sql>
<select id="selectByExampleWithBLOBs" parameterType="club.joylink.rtss.entity.voice2.VoiceDeviceConfig2Example" resultMap="ResultMapWithBLOBs">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from rts_voice_device_config
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
<if test="limit != null">
<if test="offset != null">
limit ${offset}, ${limit}
</if>
<if test="offset == null">
limit ${limit}
</if>
</if>
</select>
<select id="selectByExample" parameterType="club.joylink.rtss.entity.voice2.VoiceDeviceConfig2Example" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from rts_voice_device_config
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
<if test="limit != null">
<if test="offset != null">
limit ${offset}, ${limit}
</if>
<if test="offset == null">
limit ${limit}
</if>
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="ResultMapWithBLOBs">
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from rts_voice_device_config
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from rts_voice_device_config
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="club.joylink.rtss.entity.voice2.VoiceDeviceConfig2Example">
delete from rts_voice_device_config
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="club.joylink.rtss.entity.voice2.VoiceDeviceConfig2" useGeneratedKeys="true">
insert into rts_voice_device_config (`describe`, wake_up_parmas, map_id,
create_id, create_time, update_time,
device_type, operate_type, `status`,
param_config)
values (#{describe,jdbcType=VARCHAR}, #{wakeUpParmas,jdbcType=VARCHAR}, #{mapId,jdbcType=BIGINT},
#{createId,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
#{deviceType,jdbcType=VARCHAR}, #{operateType,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},
#{paramConfig,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="club.joylink.rtss.entity.voice2.VoiceDeviceConfig2" useGeneratedKeys="true">
insert into rts_voice_device_config
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="describe != null">
`describe`,
</if>
<if test="wakeUpParmas != null">
wake_up_parmas,
</if>
<if test="mapId != null">
map_id,
</if>
<if test="createId != null">
create_id,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="deviceType != null">
device_type,
</if>
<if test="operateType != null">
operate_type,
</if>
<if test="status != null">
`status`,
</if>
<if test="paramConfig != null">
param_config,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="describe != null">
#{describe,jdbcType=VARCHAR},
</if>
<if test="wakeUpParmas != null">
#{wakeUpParmas,jdbcType=VARCHAR},
</if>
<if test="mapId != null">
#{mapId,jdbcType=BIGINT},
</if>
<if test="createId != null">
#{createId,jdbcType=BIGINT},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="deviceType != null">
#{deviceType,jdbcType=VARCHAR},
</if>
<if test="operateType != null">
#{operateType,jdbcType=VARCHAR},
</if>
<if test="status != null">
#{status,jdbcType=INTEGER},
</if>
<if test="paramConfig != null">
#{paramConfig,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="club.joylink.rtss.entity.voice2.VoiceDeviceConfig2Example" resultType="java.lang.Long">
select count(*) from rts_voice_device_config
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update rts_voice_device_config
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.describe != null">
`describe` = #{record.describe,jdbcType=VARCHAR},
</if>
<if test="record.wakeUpParmas != null">
wake_up_parmas = #{record.wakeUpParmas,jdbcType=VARCHAR},
</if>
<if test="record.mapId != null">
map_id = #{record.mapId,jdbcType=BIGINT},
</if>
<if test="record.createId != null">
create_id = #{record.createId,jdbcType=BIGINT},
</if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=TIMESTAMP},
</if>
<if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
</if>
<if test="record.deviceType != null">
device_type = #{record.deviceType,jdbcType=VARCHAR},
</if>
<if test="record.operateType != null">
operate_type = #{record.operateType,jdbcType=VARCHAR},
</if>
<if test="record.status != null">
`status` = #{record.status,jdbcType=INTEGER},
</if>
<if test="record.paramConfig != null">
param_config = #{record.paramConfig,jdbcType=LONGVARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExampleWithBLOBs" parameterType="map">
update rts_voice_device_config
set id = #{record.id,jdbcType=BIGINT},
`describe` = #{record.describe,jdbcType=VARCHAR},
wake_up_parmas = #{record.wakeUpParmas,jdbcType=VARCHAR},
map_id = #{record.mapId,jdbcType=BIGINT},
create_id = #{record.createId,jdbcType=BIGINT},
create_time = #{record.createTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
device_type = #{record.deviceType,jdbcType=VARCHAR},
operate_type = #{record.operateType,jdbcType=VARCHAR},
`status` = #{record.status,jdbcType=INTEGER},
param_config = #{record.paramConfig,jdbcType=LONGVARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update rts_voice_device_config
set id = #{record.id,jdbcType=BIGINT},
`describe` = #{record.describe,jdbcType=VARCHAR},
wake_up_parmas = #{record.wakeUpParmas,jdbcType=VARCHAR},
map_id = #{record.mapId,jdbcType=BIGINT},
create_id = #{record.createId,jdbcType=BIGINT},
create_time = #{record.createTime,jdbcType=TIMESTAMP},
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
device_type = #{record.deviceType,jdbcType=VARCHAR},
operate_type = #{record.operateType,jdbcType=VARCHAR},
`status` = #{record.status,jdbcType=INTEGER}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="club.joylink.rtss.entity.voice2.VoiceDeviceConfig2">
update rts_voice_device_config
<set>
<if test="describe != null">
`describe` = #{describe,jdbcType=VARCHAR},
</if>
<if test="wakeUpParmas != null">
wake_up_parmas = #{wakeUpParmas,jdbcType=VARCHAR},
</if>
<if test="mapId != null">
map_id = #{mapId,jdbcType=BIGINT},
</if>
<if test="createId != null">
create_id = #{createId,jdbcType=BIGINT},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="deviceType != null">
device_type = #{deviceType,jdbcType=VARCHAR},
</if>
<if test="operateType != null">
operate_type = #{operateType,jdbcType=VARCHAR},
</if>
<if test="status != null">
`status` = #{status,jdbcType=INTEGER},
</if>
<if test="paramConfig != null">
param_config = #{paramConfig,jdbcType=LONGVARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="club.joylink.rtss.entity.voice2.VoiceDeviceConfig2">
update rts_voice_device_config
set `describe` = #{describe,jdbcType=VARCHAR},
wake_up_parmas = #{wakeUpParmas,jdbcType=VARCHAR},
map_id = #{mapId,jdbcType=BIGINT},
create_id = #{createId,jdbcType=BIGINT},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP},
device_type = #{deviceType,jdbcType=VARCHAR},
operate_type = #{operateType,jdbcType=VARCHAR},
`status` = #{status,jdbcType=INTEGER},
param_config = #{paramConfig,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="club.joylink.rtss.entity.voice2.VoiceDeviceConfig2">
update rts_voice_device_config
set `describe` = #{describe,jdbcType=VARCHAR},
wake_up_parmas = #{wakeUpParmas,jdbcType=VARCHAR},
map_id = #{mapId,jdbcType=BIGINT},
create_id = #{createId,jdbcType=BIGINT},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP},
device_type = #{deviceType,jdbcType=VARCHAR},
operate_type = #{operateType,jdbcType=VARCHAR},
`status` = #{status,jdbcType=INTEGER}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>

View File

@ -4,8 +4,8 @@ import club.joylink.rtss.entity.project.Project;
import club.joylink.rtss.simulation.SimulationManager;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.SimulationService;
import club.joylink.rtss.simulation.cbtc.command.voice.DeviceVoiceCommandService;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.WorkResult;
import club.joylink.rtss.simulation.cbtc.command.voice2.VoiceCommandHandle;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.WorkResult;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.project.ProjectVO;
@ -22,7 +22,7 @@ import java.util.List;
@SpringBootTest
public class SimulationVoiceTest {
@Autowired
private DeviceVoiceCommandService commandService;
private VoiceCommandHandle commandService;
@Autowired
private SimulationService simulationService;
@Autowired

View File

@ -1,17 +1,14 @@
package club.joylink.rtss.services.voice;
import club.joylink.rtss.entity.project.Project;
import club.joylink.rtss.services.voice.impl.VoiceDataService;
import club.joylink.rtss.simulation.cbtc.command.voice.operate.HandleType;
import club.joylink.rtss.simulation.cbtc.command.voice.operate.OperateEnum;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.OperateConfigData;
import club.joylink.rtss.simulation.cbtc.command.voice.vo.VoiceConfigData;
import club.joylink.rtss.services.voice.impl.VoiceConfigDataService;
import club.joylink.rtss.simulation.cbtc.command.voice2.operate.OperateEnum;
import club.joylink.rtss.simulation.cbtc.command.voice2.vo.OperateConfigData;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.project.ProjectVO;
import club.joylink.rtss.vo.voice.VoiceConfigVO;
import com.google.common.collect.Lists;
import club.joylink.rtss.vo.voice.VoiceConfigDataVO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@ -22,10 +19,7 @@ import java.util.List;
//@Transactional
public class VoiceDataManageTest {
@Autowired
private VoiceDataService dataService;
@Autowired
private IVoiceCommandDataService commandDataService;
private VoiceConfigDataService dataService;
private LoginUserInfoVO getInfo(){
String testJsonData = "{\"accountVO\":{\"id\":\"8146\",\"account\":\"13992867352\",\"type\":\"2\",\"nickname\":\"13992867352\",\"mobile\":\"13992867352\",\"password\":\"e10adc3949ba59abbe56e057f20f883e\",\"roles\":[\"01\",\"05\"],\"email\":\"\",\"status\":\"1\",\"companyId\":124,\"companyName\":\"默认组织\",\"companyAdmin\":false,\"projectCodes\":[\"BJD\",\"CGY\",\"DEFAULT\",\"DRTS\",\"HEB\",\"HYD_RAILWAY\",\"JJJLM\",\"JXGM\",\"NOLOGO\",\"RICHOR\",\"RICHOR_CXJS\",\"RICHOR_HHCJ\",\"RICHOR_JOINT\",\"RICHOR_YGY\",\"SR_SANDBOX\",\"THAILAND_SANDBOX\",\"WJLS\",\"YJDDZH\",\"ZZWW\",\"ZZWWTEST\"]},\"client\":\"Joylink\",\"project\":\"DEFAULT\",\"token\":\"34a5b6916e60eea26a53c820c644c4e8\",\"projectDeviceLogin\":false,\"wechatLogin\":false,\"topOrgId\":124,\"dispatcherRaceTrainingLogin\":false}\n";
@ -40,75 +34,22 @@ public class VoiceDataManageTest {
@Test
// @Rollback
public void insertData(){
LoginUserInfoVO userInfoVO = this.getInfo();
VoiceConfigVO configVO = new VoiceConfigVO();
configVO.setId(7L);
configVO.setHandleType(HandleType.PINYIN);
configVO.setDescribe("测试");
configVO.setDeviceType(MapElement.DeviceType.SWITCH);
configVO.setMapId(50L);
VoiceConfigData config = new VoiceConfigData();
config.setActionMatch(new String[]{"道岔"});
configVO.setWakeUpKw(config);
List<OperateConfigData> configDataList = Lists.newArrayList();
OperateConfigData configData = new OperateConfigData(OperateEnum.SWITCH_DINGWEI);
configData.setActionMatch(new String[]{"定位"});
configDataList.add(configData);
configData = new OperateConfigData(OperateEnum.SWITCH_FANWEI);
configData.setActionMatch(new String[]{"反位"});
configDataList.add(configData);
configVO.setConfig(configDataList);
this.dataService.saveOrUpdate(configVO,userInfoVO);
}
@Test
// @Rollback
public void insertDataStand(){
LoginUserInfoVO userInfoVO = this.getInfo();
VoiceConfigVO configVO = new VoiceConfigVO();
configVO.setId(11L);
configVO.setHandleType(HandleType.PINYIN);
configVO.setDescribe("测试站台");
configVO.setDeviceType(MapElement.DeviceType.STAND);
configVO.setMapId(63L);
VoiceConfigData config = new VoiceConfigData();
config.setActionMatch(new String[]{"站台"});
configVO.setWakeUpKw(config);
List<OperateConfigData> configDataList = Lists.newArrayList();
OperateConfigData configData = new OperateConfigData(OperateEnum.STAND_UP_HOLD_TRAIN);
configData.setActionMatch(new String[]{"扣车"});
configData.setNatureKW(new String[]{"上行",""});
// configData.setDescribeKW(new String[]{""});
configDataList.add(configData);
configData = new OperateConfigData(OperateEnum.STAND_CANCEL_UP_HOLD_TRAIN);
configData.setActionMatch(new String[]{"取消扣车","取消"});
configData.setNatureKW(new String[]{"上行",""});
// configData.setDescribeKW(new String[]{""});
configDataList.add(configData);
configVO.setConfig(configDataList);
this.dataService.saveOrUpdate(configVO,userInfoVO);
}
@Test
public void findData(){
VoiceConfigVO vo1 = this.dataService.byId(7L);
System.out.println(vo1);
public void insert(){
VoiceConfigDataVO dataVO = new VoiceConfigDataVO();
dataVO.setDescribe("测试");
dataVO.setMapId(63L);
dataVO.setWakeUpParmas(List.of("道岔"));
dataVO.setDeviceType(MapElement.DeviceType.SWITCH);
dataVO.setOperateType(OperateEnum.SWITCH_DINGWEI);
OperateConfigData configData = new OperateConfigData();
// configData.setOperate(OperateEnum.SWITCH_DINGWEI);
configData.setActionKW(new String[]{"定位"});
dataVO.setParamConfig(configData);
dataService.saveOrUpdate(dataVO,this.getInfo());
}
@Test
public void changeStatus(){
this.dataService.changeStatus(3L,1);
}
@Test
public void findConfigData(){
List<club.joylink.rtss.vo.voice.VoiceConfigVO> list = this.commandDataService.findData(50L);
System.out.println(list);
}
@Test
public void changeStatusAndFindConfig(){
this.dataService.changeStatus(3L,0);
List<club.joylink.rtss.vo.voice.VoiceConfigVO> list = this.commandDataService.findData(50L);
System.out.println(list);
dataService.changeStatus(1L,2);
}
}