From 2445287f8cd9be357fa08c11cec1fc6de4c64d46 Mon Sep 17 00:00:00 2001 From: tiger_zhou <123456> Date: Tue, 28 Mar 2023 15:43:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=AD=E9=9F=B3=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 35 +- .../configuration/VoiceCommandConfig.java | 32 + .../rtss/constants/BusinessConsts.java | 2 + .../rtss/dao/voice/VoiceDeviceConfigDAO.java | 40 + .../rtss/entity/voice/VoiceDeviceConfig.java | 69 ++ .../voice/VoiceDeviceConfigExample.java | 863 ++++++++++++++++++ .../BusinessExceptionAssertEnum.java | 4 + .../joylink/rtss/services/MapService.java | 4 +- .../voice/IVoiceCommandDataService.java | 11 + .../services/voice/IVoiceDataService.java | 15 + .../services/voice/impl/VoiceDataService.java | 180 ++++ .../voice/DeviceVoiceCommandService.java | 76 ++ .../voice/VoiceCommandMatchHandler.java | 27 + .../voice/analyse/PinYinSplitWordAnalyse.java | 54 ++ .../voice/analyse/VoiceCommandAnalyse.java | 16 + .../voice/match/IVoiceCommandMatcher.java | 15 + .../match/PinYinViolenceMatchHandler.java | 51 ++ .../command/voice/operate/HandleType.java | 10 + .../voice/operate/OperateDeviceEnum.java | 12 + .../command/voice/operate/OperateEnum.java | 38 + .../command/voice/vo/DeviceVoiceCommand.java | 47 + .../command/voice/vo/OperateConfigData.java | 15 + .../command/voice/vo/VoiceConfigData.java | 10 + .../cbtc/command/voice/vo/WorkResult.java | 31 + .../cbtc/command/voice/work/IDeviceWork.java | 18 + .../voice/work/VoiceCommandAnalyseWork.java | 48 + .../command/voice/work/device/SwitchWork.java | 57 ++ .../club/joylink/rtss/util/PinYinUtil.java | 57 ++ .../joylink/rtss/vo/voice/VoiceConfigVO.java | 113 +++ .../joylink/rtss/vo/voice/VoiceQueryVO.java | 59 ++ .../mapper/voice/VoiceDeviceConfigDAO.xml | 368 ++++++++ .../rtss/services/util/SplitWordTest.java | 36 + .../services/util/StringSimilarityTest.java | 17 + .../services/voice/SimulationVoiceTest.java | 98 ++ .../services/voice/VoiceDataManageTest.java | 88 ++ 35 files changed, 2613 insertions(+), 3 deletions(-) create mode 100644 src/main/java/club/joylink/rtss/configuration/VoiceCommandConfig.java create mode 100644 src/main/java/club/joylink/rtss/dao/voice/VoiceDeviceConfigDAO.java create mode 100644 src/main/java/club/joylink/rtss/entity/voice/VoiceDeviceConfig.java create mode 100644 src/main/java/club/joylink/rtss/entity/voice/VoiceDeviceConfigExample.java create mode 100644 src/main/java/club/joylink/rtss/services/voice/IVoiceCommandDataService.java create mode 100644 src/main/java/club/joylink/rtss/services/voice/IVoiceDataService.java create mode 100644 src/main/java/club/joylink/rtss/services/voice/impl/VoiceDataService.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/DeviceVoiceCommandService.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/VoiceCommandMatchHandler.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/analyse/PinYinSplitWordAnalyse.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/analyse/VoiceCommandAnalyse.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/match/IVoiceCommandMatcher.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/match/PinYinViolenceMatchHandler.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/operate/HandleType.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/operate/OperateDeviceEnum.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/operate/OperateEnum.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/vo/DeviceVoiceCommand.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/vo/OperateConfigData.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/vo/VoiceConfigData.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/vo/WorkResult.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/work/IDeviceWork.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/work/VoiceCommandAnalyseWork.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/work/device/SwitchWork.java create mode 100644 src/main/java/club/joylink/rtss/util/PinYinUtil.java create mode 100644 src/main/java/club/joylink/rtss/vo/voice/VoiceConfigVO.java create mode 100644 src/main/java/club/joylink/rtss/vo/voice/VoiceQueryVO.java create mode 100644 src/main/resources/mybatis/mapper/voice/VoiceDeviceConfigDAO.xml create mode 100644 src/test/java/club/joylink/rtss/services/util/SplitWordTest.java create mode 100644 src/test/java/club/joylink/rtss/services/util/StringSimilarityTest.java create mode 100644 src/test/java/club/joylink/rtss/services/voice/SimulationVoiceTest.java create mode 100644 src/test/java/club/joylink/rtss/services/voice/VoiceDataManageTest.java diff --git a/pom.xml b/pom.xml index 4352e1135..209843ee2 100644 --- a/pom.xml +++ b/pom.xml @@ -146,7 +146,40 @@ protobuf-java 3.19.3 - + + + + org.ansj + ansj_seg + 5.1.6 + + + org.reflections + reflections + 0.9.11 + + + org.apache.commons + commons-lang3 + 3.12.0 + + + + + org.apache.commons + commons-text + 1.10.0 + + + diff --git a/src/main/java/club/joylink/rtss/configuration/VoiceCommandConfig.java b/src/main/java/club/joylink/rtss/configuration/VoiceCommandConfig.java new file mode 100644 index 000000000..510e3571a --- /dev/null +++ b/src/main/java/club/joylink/rtss/configuration/VoiceCommandConfig.java @@ -0,0 +1,32 @@ +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 org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class VoiceCommandConfig { + + /** + * VoiceCommandAnalyse 注入 一种类型只能被注入一次,类型查看handleType方法 + * @return + */ + @Bean + public VoiceCommandAnalyse voiceCommandAnalyse(){ + PinYinSplitWordAnalyse sw = new PinYinSplitWordAnalyse(); + return sw; + } + + /** + * 只能注入一次 + * @return + */ + @Bean + public IVoiceCommandMatcher matchHandler(){ + PinYinViolenceMatchHandler matchHandler = new PinYinViolenceMatchHandler(); + return matchHandler; + } +} diff --git a/src/main/java/club/joylink/rtss/constants/BusinessConsts.java b/src/main/java/club/joylink/rtss/constants/BusinessConsts.java index a116c1166..639aa45b3 100644 --- a/src/main/java/club/joylink/rtss/constants/BusinessConsts.java +++ b/src/main/java/club/joylink/rtss/constants/BusinessConsts.java @@ -8,11 +8,13 @@ public interface BusinessConsts { * 状态 1-启用/有效 */ String STATUS_USE = "1"; + int STATUS_USE_INT = 1; /** * 状态 0-禁用/无效 */ String STATUS_NOT_USE = "0"; + int STATUS_NOT_USE_INT = 0; /** * 验证码有效期: 单位 分钟 diff --git a/src/main/java/club/joylink/rtss/dao/voice/VoiceDeviceConfigDAO.java b/src/main/java/club/joylink/rtss/dao/voice/VoiceDeviceConfigDAO.java new file mode 100644 index 000000000..8ecc02810 --- /dev/null +++ b/src/main/java/club/joylink/rtss/dao/voice/VoiceDeviceConfigDAO.java @@ -0,0 +1,40 @@ +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 selectByExampleWithBLOBs(VoiceDeviceConfigExample example); + + List 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); +} \ No newline at end of file diff --git a/src/main/java/club/joylink/rtss/entity/voice/VoiceDeviceConfig.java b/src/main/java/club/joylink/rtss/entity/voice/VoiceDeviceConfig.java new file mode 100644 index 000000000..401a499ee --- /dev/null +++ b/src/main/java/club/joylink/rtss/entity/voice/VoiceDeviceConfig.java @@ -0,0 +1,69 @@ +package club.joylink.rtss.entity.voice; + +import java.io.Serializable; +import java.time.LocalDateTime; + +import club.joylink.rtss.simulation.cbtc.command.voice.operate.HandleType; +import club.joylink.rtss.simulation.cbtc.data.map.MapElement; +import lombok.Data; + +/** + * @author + * + */ +@Data +public class VoiceDeviceConfig implements Serializable { + private Long id; + + /** + * 描述 + */ + private String describe; + + /** + * 线路 + */ + private Long mapId; + + /** + * 编辑创建者 + */ + private Long createId; + + /** + * 处理方式,目前只支持拼音 + */ + private HandleType handleType; + + /** + * 命令类型匹配关键字 + */ + private String wakeUpKw; + + /** + * 开始时间 + */ + private LocalDateTime createTime; + + /** + * 修改时间 + */ + private LocalDateTime updateTime; + + /** + * 支持的设备类型 + */ + private MapElement.DeviceType deviceType; + + /** + * 是否启用0=未启用,1=启用 + */ + private Integer status; + + /** + * 配置 + */ + private String config; + + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/club/joylink/rtss/entity/voice/VoiceDeviceConfigExample.java b/src/main/java/club/joylink/rtss/entity/voice/VoiceDeviceConfigExample.java new file mode 100644 index 000000000..31a6d91b3 --- /dev/null +++ b/src/main/java/club/joylink/rtss/entity/voice/VoiceDeviceConfigExample.java @@ -0,0 +1,863 @@ +package club.joylink.rtss.entity.voice; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class VoiceDeviceConfigExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + private Integer limit; + + private Long offset; + + public VoiceDeviceConfigExample() { + oredCriteria = new ArrayList(); + } + + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + public String getOrderByClause() { + return orderByClause; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + public boolean isDistinct() { + return distinct; + } + + public List getOredCriteria() { + return oredCriteria; + } + + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + public void setLimit(Integer limit) { + this.limit = limit; + } + + public Integer getLimit() { + return limit; + } + + public void setOffset(Long offset) { + this.offset = offset; + } + + public Long getOffset() { + return offset; + } + + protected abstract static class GeneratedCriteria { + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(Long value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(Long value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(Long value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(Long value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(Long value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(Long value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(Long value1, Long value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(Long value1, Long value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andDescribeIsNull() { + addCriterion("`describe` is null"); + return (Criteria) this; + } + + public Criteria andDescribeIsNotNull() { + addCriterion("`describe` is not null"); + return (Criteria) this; + } + + public Criteria andDescribeEqualTo(String value) { + addCriterion("`describe` =", value, "describe"); + return (Criteria) this; + } + + public Criteria andDescribeNotEqualTo(String value) { + addCriterion("`describe` <>", value, "describe"); + return (Criteria) this; + } + + public Criteria andDescribeGreaterThan(String value) { + addCriterion("`describe` >", value, "describe"); + return (Criteria) this; + } + + public Criteria andDescribeGreaterThanOrEqualTo(String value) { + addCriterion("`describe` >=", value, "describe"); + return (Criteria) this; + } + + public Criteria andDescribeLessThan(String value) { + addCriterion("`describe` <", value, "describe"); + return (Criteria) this; + } + + public Criteria andDescribeLessThanOrEqualTo(String value) { + addCriterion("`describe` <=", value, "describe"); + return (Criteria) this; + } + + public Criteria andDescribeLike(String value) { + addCriterion("`describe` like", value, "describe"); + return (Criteria) this; + } + + public Criteria andDescribeNotLike(String value) { + addCriterion("`describe` not like", value, "describe"); + return (Criteria) this; + } + + public Criteria andDescribeIn(List values) { + addCriterion("`describe` in", values, "describe"); + return (Criteria) this; + } + + public Criteria andDescribeNotIn(List values) { + addCriterion("`describe` not in", values, "describe"); + return (Criteria) this; + } + + public Criteria andDescribeBetween(String value1, String value2) { + addCriterion("`describe` between", value1, value2, "describe"); + return (Criteria) this; + } + + public Criteria andDescribeNotBetween(String value1, String value2) { + addCriterion("`describe` not between", value1, value2, "describe"); + return (Criteria) this; + } + + public Criteria andMapIdIsNull() { + addCriterion("map_id is null"); + return (Criteria) this; + } + + public Criteria andMapIdIsNotNull() { + addCriterion("map_id is not null"); + return (Criteria) this; + } + + public Criteria andMapIdEqualTo(Long value) { + addCriterion("map_id =", value, "mapId"); + return (Criteria) this; + } + + public Criteria andMapIdNotEqualTo(Long value) { + addCriterion("map_id <>", value, "mapId"); + return (Criteria) this; + } + + public Criteria andMapIdGreaterThan(Long value) { + addCriterion("map_id >", value, "mapId"); + return (Criteria) this; + } + + public Criteria andMapIdGreaterThanOrEqualTo(Long value) { + addCriterion("map_id >=", value, "mapId"); + return (Criteria) this; + } + + public Criteria andMapIdLessThan(Long value) { + addCriterion("map_id <", value, "mapId"); + return (Criteria) this; + } + + public Criteria andMapIdLessThanOrEqualTo(Long value) { + addCriterion("map_id <=", value, "mapId"); + return (Criteria) this; + } + + public Criteria andMapIdIn(List values) { + addCriterion("map_id in", values, "mapId"); + return (Criteria) this; + } + + public Criteria andMapIdNotIn(List values) { + addCriterion("map_id not in", values, "mapId"); + return (Criteria) this; + } + + public Criteria andMapIdBetween(Long value1, Long value2) { + addCriterion("map_id between", value1, value2, "mapId"); + return (Criteria) this; + } + + public Criteria andMapIdNotBetween(Long value1, Long value2) { + addCriterion("map_id not between", value1, value2, "mapId"); + return (Criteria) this; + } + + public Criteria andCreateIdIsNull() { + addCriterion("create_id is null"); + return (Criteria) this; + } + + public Criteria andCreateIdIsNotNull() { + addCriterion("create_id is not null"); + return (Criteria) this; + } + + public Criteria andCreateIdEqualTo(Long value) { + addCriterion("create_id =", value, "createId"); + return (Criteria) this; + } + + public Criteria andCreateIdNotEqualTo(Long value) { + addCriterion("create_id <>", value, "createId"); + return (Criteria) this; + } + + public Criteria andCreateIdGreaterThan(Long value) { + addCriterion("create_id >", value, "createId"); + return (Criteria) this; + } + + public Criteria andCreateIdGreaterThanOrEqualTo(Long value) { + addCriterion("create_id >=", value, "createId"); + return (Criteria) this; + } + + public Criteria andCreateIdLessThan(Long value) { + addCriterion("create_id <", value, "createId"); + return (Criteria) this; + } + + public Criteria andCreateIdLessThanOrEqualTo(Long value) { + addCriterion("create_id <=", value, "createId"); + return (Criteria) this; + } + + public Criteria andCreateIdIn(List values) { + addCriterion("create_id in", values, "createId"); + return (Criteria) this; + } + + public Criteria andCreateIdNotIn(List values) { + addCriterion("create_id not in", values, "createId"); + return (Criteria) this; + } + + public Criteria andCreateIdBetween(Long value1, Long value2) { + addCriterion("create_id between", value1, value2, "createId"); + return (Criteria) this; + } + + public Criteria andCreateIdNotBetween(Long value1, Long value2) { + addCriterion("create_id not between", value1, value2, "createId"); + 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 values) { + addCriterion("handle_type in", values, "handleType"); + return (Criteria) this; + } + + public Criteria andHandleTypeNotIn(List 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 values) { + addCriterion("wake_up_kw in", values, "wakeUpKw"); + return (Criteria) this; + } + + public Criteria andWakeUpKwNotIn(List 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; + } + + public Criteria andCreateTimeIsNotNull() { + addCriterion("create_time is not null"); + return (Criteria) this; + } + + public Criteria andCreateTimeEqualTo(Date value) { + addCriterion("create_time =", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotEqualTo(Date value) { + addCriterion("create_time <>", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThan(Date value) { + addCriterion("create_time >", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThanOrEqualTo(Date value) { + addCriterion("create_time >=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThan(Date value) { + addCriterion("create_time <", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThanOrEqualTo(Date value) { + addCriterion("create_time <=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeIn(List values) { + addCriterion("create_time in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotIn(List values) { + addCriterion("create_time not in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeBetween(Date value1, Date value2) { + addCriterion("create_time between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotBetween(Date value1, Date value2) { + addCriterion("create_time not between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIsNull() { + addCriterion("update_time is null"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIsNotNull() { + addCriterion("update_time is not null"); + return (Criteria) this; + } + + public Criteria andUpdateTimeEqualTo(Date value) { + addCriterion("update_time =", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotEqualTo(Date value) { + addCriterion("update_time <>", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeGreaterThan(Date value) { + addCriterion("update_time >", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeGreaterThanOrEqualTo(Date value) { + addCriterion("update_time >=", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeLessThan(Date value) { + addCriterion("update_time <", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeLessThanOrEqualTo(Date value) { + addCriterion("update_time <=", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIn(List values) { + addCriterion("update_time in", values, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotIn(List values) { + addCriterion("update_time not in", values, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeBetween(Date value1, Date value2) { + addCriterion("update_time between", value1, value2, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotBetween(Date value1, Date value2) { + addCriterion("update_time not between", value1, value2, "updateTime"); + return (Criteria) this; + } + + public Criteria andDeviceTypeIsNull() { + addCriterion("device_type is null"); + return (Criteria) this; + } + + public Criteria andDeviceTypeIsNotNull() { + addCriterion("device_type is not null"); + return (Criteria) this; + } + + public Criteria andDeviceTypeEqualTo(String value) { + addCriterion("device_type =", value, "deviceType"); + return (Criteria) this; + } + + public Criteria andDeviceTypeNotEqualTo(String value) { + addCriterion("device_type <>", value, "deviceType"); + return (Criteria) this; + } + + public Criteria andDeviceTypeGreaterThan(String value) { + addCriterion("device_type >", value, "deviceType"); + return (Criteria) this; + } + + public Criteria andDeviceTypeGreaterThanOrEqualTo(String value) { + addCriterion("device_type >=", value, "deviceType"); + return (Criteria) this; + } + + public Criteria andDeviceTypeLessThan(String value) { + addCriterion("device_type <", value, "deviceType"); + return (Criteria) this; + } + + public Criteria andDeviceTypeLessThanOrEqualTo(String value) { + addCriterion("device_type <=", value, "deviceType"); + return (Criteria) this; + } + + public Criteria andDeviceTypeLike(String value) { + addCriterion("device_type like", value, "deviceType"); + return (Criteria) this; + } + + public Criteria andDeviceTypeNotLike(String value) { + addCriterion("device_type not like", value, "deviceType"); + return (Criteria) this; + } + + public Criteria andDeviceTypeIn(List values) { + addCriterion("device_type in", values, "deviceType"); + return (Criteria) this; + } + + public Criteria andDeviceTypeNotIn(List values) { + addCriterion("device_type not in", values, "deviceType"); + return (Criteria) this; + } + + public Criteria andDeviceTypeBetween(String value1, String value2) { + addCriterion("device_type between", value1, value2, "deviceType"); + return (Criteria) this; + } + + public Criteria andDeviceTypeNotBetween(String value1, String value2) { + addCriterion("device_type not between", value1, value2, "deviceType"); + return (Criteria) this; + } + + public Criteria andStatusIsNull() { + addCriterion("`status` is null"); + return (Criteria) this; + } + + public Criteria andStatusIsNotNull() { + addCriterion("`status` is not null"); + return (Criteria) this; + } + + public Criteria andStatusEqualTo(Integer value) { + addCriterion("`status` =", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusNotEqualTo(Integer value) { + addCriterion("`status` <>", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusGreaterThan(Integer value) { + addCriterion("`status` >", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusGreaterThanOrEqualTo(Integer value) { + addCriterion("`status` >=", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusLessThan(Integer value) { + addCriterion("`status` <", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusLessThanOrEqualTo(Integer value) { + addCriterion("`status` <=", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusIn(List values) { + addCriterion("`status` in", values, "status"); + return (Criteria) this; + } + + public Criteria andStatusNotIn(List values) { + addCriterion("`status` not in", values, "status"); + return (Criteria) this; + } + + public Criteria andStatusBetween(Integer value1, Integer value2) { + addCriterion("`status` between", value1, value2, "status"); + return (Criteria) this; + } + + public Criteria andStatusNotBetween(Integer value1, Integer value2) { + addCriterion("`status` not between", value1, value2, "status"); + return (Criteria) this; + } + } + + /** + */ + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} \ No newline at end of file diff --git a/src/main/java/club/joylink/rtss/exception/BusinessExceptionAssertEnum.java b/src/main/java/club/joylink/rtss/exception/BusinessExceptionAssertEnum.java index f7d9ddb69..80c4c2af3 100644 --- a/src/main/java/club/joylink/rtss/exception/BusinessExceptionAssertEnum.java +++ b/src/main/java/club/joylink/rtss/exception/BusinessExceptionAssertEnum.java @@ -59,6 +59,10 @@ public enum BusinessExceptionAssertEnum implements BusinessExceptionAssert { INCORRECT_VERIFICATION_CODE(40051, "incorrect verification code"), THIRD_SERVICE_CALL_EXCEPTION(40071, "the third service call exception"), VOICE_COMMAND_PARSE_ERROR(40061,"voice command parse error"), + VOICE_COMMAND_CONFIG_NULL(40062,"voice command config is null"), + VOICE_COMMAND_DEVICE_UNDEFINED(40063,"device undefined"), + VOICE_COMMAND_WORK_UNDEFINED(40064,"device work undefined"), + //支付异常 PAY_ERROR(50000, "pay error"), WECHAT_NOTIFY_ERROR(401, "wechat notify error") diff --git a/src/main/java/club/joylink/rtss/services/MapService.java b/src/main/java/club/joylink/rtss/services/MapService.java index 6d307a9fe..278fe9b22 100644 --- a/src/main/java/club/joylink/rtss/services/MapService.java +++ b/src/main/java/club/joylink/rtss/services/MapService.java @@ -117,13 +117,13 @@ public class MapService implements IMapService, ApplicationRunner { public void run(ApplicationArguments args) throws Exception { //缓存所有地图数据 log.info("开始缓存地图数据"); - for (MapVO mapVO : listOnline()) { +/* for (MapVO mapVO : listOnline()) { try { getMapDetail(mapVO.getId()); } catch (Exception e) { log.error(String.format("[id:%s]的地图缓存失败", mapVO.getId()), e); } - } + }*/ log.info("缓存地图数据结束"); } diff --git a/src/main/java/club/joylink/rtss/services/voice/IVoiceCommandDataService.java b/src/main/java/club/joylink/rtss/services/voice/IVoiceCommandDataService.java new file mode 100644 index 000000000..2935c294e --- /dev/null +++ b/src/main/java/club/joylink/rtss/services/voice/IVoiceCommandDataService.java @@ -0,0 +1,11 @@ +package club.joylink.rtss.services.voice; + +import club.joylink.rtss.vo.voice.VoiceConfigVO; + +import java.util.List; + +public interface IVoiceCommandDataService { + + List findData(Long mapId); + +} diff --git a/src/main/java/club/joylink/rtss/services/voice/IVoiceDataService.java b/src/main/java/club/joylink/rtss/services/voice/IVoiceDataService.java new file mode 100644 index 000000000..932a7fe64 --- /dev/null +++ b/src/main/java/club/joylink/rtss/services/voice/IVoiceDataService.java @@ -0,0 +1,15 @@ +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 query(VoiceQueryVO query); + + void changeStatus(Long id,Integer status); + +} diff --git a/src/main/java/club/joylink/rtss/services/voice/impl/VoiceDataService.java b/src/main/java/club/joylink/rtss/services/voice/impl/VoiceDataService.java new file mode 100644 index 000000000..6d7c6374d --- /dev/null +++ b/src/main/java/club/joylink/rtss/services/voice/impl/VoiceDataService.java @@ -0,0 +1,180 @@ +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.simulation.cbtc.command.voice.vo.VoiceConfigData; +import club.joylink.rtss.util.JsonUtils; +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> VOICE_CACHE = CacheBuilder.newBuilder().expireAfterWrite(3, TimeUnit.MINUTES).build(); + + private Optional 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().getSourceMatch()),String.format("类型匹配需要关键字")); + OperateConfigData configData = dataVO.getConfig().stream().filter(d->ArrayUtils.isEmpty(d.getSourceMatch())).findFirst().orElse(null); + BusinessExceptionAssertEnum.DATA_INVALID.assertNotTrue(Objects.nonNull(configData),String.format("操作数据关键字不能为空")); + Map> mapList = dataVO.getConfig().stream().collect(Collectors.groupingBy(OperateConfigData::getOperate)); + for (List 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 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 optional = this.findById(id); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(optional.isPresent(),"未找到对应的数据"); + return club.joylink.rtss.vo.voice.VoiceConfigVO.converVO(optional.get()); + + } + + @Override + public PageVO query(VoiceQueryVO query) { + PageHelper.startPage(query.getPageNum(),query.getPageSize()); + Page sqlPage = (Page) this.configDAO.selectByExampleWithBLOBs(query.createQuery()); + List result = Lists.newArrayList(); + for (VoiceDeviceConfig vc : sqlPage.getResult()) { + result.add(club.joylink.rtss.vo.voice.VoiceConfigVO.converVO(vc)); + } + PageVO 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 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 findData(Long mapId) { + try { + return VOICE_CACHE.get(mapId,()->{ + VoiceQueryVO query = VoiceQueryVO.builder().mapId(mapId).status(BusinessConsts.STATUS_USE_INT).build(); + List tmpList = this.configDAO.selectByExampleWithBLOBs(query.createQuery()); + List 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 pinYinList(List content){ +// List pyList = Lists.newArrayList(); +// for (String s : content) { +// String pinyinStr = PinYinUtil.toPinYinSplitBlankSpace(s); +// pyList.add(pinyinStr); +// } +// return pyList; +// } + +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/DeviceVoiceCommandService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/DeviceVoiceCommandService.java new file mode 100644 index 000000000..5ce889200 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/DeviceVoiceCommandService.java @@ -0,0 +1,76 @@ +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.vo.client.voice.VoiceRecognitionResult; +import club.joylink.rtss.vo.voice.VoiceConfigVO; +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.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 findVoiceConfig(Simulation simulation){ + Long mapId = simulation.getBuildParams().getMap().getId(); + List configVOList = this.commandDataService.findData(mapId); + BusinessExceptionAssertEnum.VOICE_COMMAND_CONFIG_NULL.assertTrue(!CollectionUtils.isEmpty(configVOList),"未找到语音配置的相关信息"); + return configVOList; + } + + public List voiceCommand(Simulation simulation, String source){ + List 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 handle(List configVOList,Simulation simulation,String result){ + List commandList = this.matchHandler.matcher(configVOList,result); + BusinessExceptionAssertEnum.VOICE_COMMAND_PARSE_ERROR.assertTrue(!CollectionUtils.isEmpty(commandList),"语音指令未识别输入内容"); + List workResultList = Lists.newArrayList(); + for (DeviceVoiceCommand command : commandList) { + Optional 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; + } + +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/VoiceCommandMatchHandler.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/VoiceCommandMatchHandler.java new file mode 100644 index 000000000..fff58eeb2 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/VoiceCommandMatchHandler.java @@ -0,0 +1,27 @@ +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 java.util.*; + +@Component +@Slf4j +public class VoiceCommandMatchHandler { + + @Autowired + private IVoiceCommandMatcher commandMatcher; + public List matcher(List configVOList, String msg){ + List findParseDataList = Lists.newArrayList(); + for (VoiceConfigVO configVO : configVOList) { + Optional> optional = commandMatcher.matchCommand(configVO,msg); + optional.ifPresent(findParseDataList::addAll); + } + return findParseDataList; + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/analyse/PinYinSplitWordAnalyse.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/analyse/PinYinSplitWordAnalyse.java new file mode 100644 index 000000000..74cffe9e0 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/analyse/PinYinSplitWordAnalyse.java @@ -0,0 +1,54 @@ +package club.joylink.rtss.simulation.cbtc.command.voice.analyse; + +import club.joylink.rtss.simulation.cbtc.command.voice.operate.HandleType; +import club.joylink.rtss.simulation.cbtc.command.voice.vo.DeviceVoiceCommand; +import club.joylink.rtss.util.PinYinUtil; +import com.google.common.collect.Lists; +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.StringUtils; + +import java.util.List; +import java.util.Objects; + +public class PinYinSplitWordAnalyse implements VoiceCommandAnalyse { + @Override + public synchronized List parseCommandDescribe(DeviceVoiceCommand command) { + this.initDic(command); + String pinyinStr = PinYinUtil.toPinYinSplitBlankSpace(command.getSourceDescrbe()); + + Result reslut = DicAnalysis.parse(pinyinStr); + List resultList = Lists.newArrayList(); + for (Term term : reslut) { + String name = term.getName().toUpperCase(); + String nature = term.getNatureStr(); + if(Objects.nonNull(nature) && !StringUtils.startsWith(nature,"w")){ + if(!StringUtils.equalsIgnoreCase(nature,"userDefine")){ +// command.appendCommandDescribe(name); + resultList.add(name); + }/*else{ + command.appendCommandDescribe(name); + }*/ + } +// commandList.add(command); + } + return resultList; + } + +/* @Override + public HandleType handleType() { + return HandleType.PINYIN; + }*/ + + private void initDic(DeviceVoiceCommand command){ + DicLibrary.clear(DicLibrary.DEFAULT); + for (String s : command.getTranslateWakeUpKW()) { + DicLibrary.insert(DicLibrary.DEFAULT,s,DicLibrary.DEFAULT_NATURE,DicLibrary.DEFAULT_FREQ); + } + for (String s : command.getMatchCommandKW()) { + DicLibrary.insert(DicLibrary.DEFAULT,s,DicLibrary.DEFAULT_NATURE,DicLibrary.DEFAULT_FREQ); + } + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/analyse/VoiceCommandAnalyse.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/analyse/VoiceCommandAnalyse.java new file mode 100644 index 000000000..d7527a441 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/analyse/VoiceCommandAnalyse.java @@ -0,0 +1,16 @@ +package club.joylink.rtss.simulation.cbtc.command.voice.analyse; + +import club.joylink.rtss.simulation.cbtc.command.voice.vo.DeviceVoiceCommand; + +import java.util.List; + +public interface VoiceCommandAnalyse { + + /** + * 解析命令 + * @param Command 命令原文 + * @return 解析后的数据 + */ + List parseCommandDescribe(DeviceVoiceCommand Command); + +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/match/IVoiceCommandMatcher.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/match/IVoiceCommandMatcher.java new file mode 100644 index 000000000..73b134b37 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/match/IVoiceCommandMatcher.java @@ -0,0 +1,15 @@ +package club.joylink.rtss.simulation.cbtc.command.voice.match; + +import club.joylink.rtss.simulation.cbtc.command.voice.operate.HandleType; +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 IVoiceCommandMatcher { + + + Optional> matchCommand(VoiceConfigVO configVOList, String msg); +// HandleType handleType(); +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/match/PinYinViolenceMatchHandler.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/match/PinYinViolenceMatchHandler.java new file mode 100644 index 000000000..845c01fcf --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/match/PinYinViolenceMatchHandler.java @@ -0,0 +1,51 @@ +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 org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; + + +public class PinYinViolenceMatchHandler implements IVoiceCommandMatcher { + @Override + public Optional> matchCommand(VoiceConfigVO configVO, String sourceMsg) { + String tmpPinYinContent = PinYinUtil.toPinYinSplitBlankSpace(sourceMsg); + List commandList = this.match(configVO,sourceMsg,tmpPinYinContent); + commandList = commandList.stream().filter(d->Objects.nonNull(d.getDeviceType()) + && ArrayUtils.isNotEmpty(d.getMatchCommandKW()) + && ArrayUtils.isNotEmpty(d.getTranslateWakeUpKW()) + ).collect(Collectors.toList()); + if(CollectionUtils.isEmpty(commandList)){ + return Optional.empty(); + } + return Optional.of(commandList); + } + + private List match(VoiceConfigVO configVO,String sourceMsg, String pinyinStr){ + List commandList = new ArrayList<>(); + for (OperateConfigData configData : configVO.getConfig()) { + DeviceVoiceCommand command = new DeviceVoiceCommand(configVO.getHandleType()); + if(StringUtils.containsAny(pinyinStr,configVO.getWakeUpKw().getTranslateMatch())){ + command.setDeviceType(configVO.getDeviceType()); + command.setTranslateWakeUpKW(configVO.getWakeUpKw().getTranslateMatch()); + } + if(StringUtils.containsAny(pinyinStr,configData.getTranslateMatch())){ + command.setOperateConfigData(configData); + command.setMatchCommandKW(configData.getTranslateMatch()); + } + command.setSourceDescrbe(sourceMsg); + commandList.add(command); + } + return commandList; + } + +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/operate/HandleType.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/operate/HandleType.java new file mode 100644 index 000000000..9e2a55aee --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/operate/HandleType.java @@ -0,0 +1,10 @@ +package club.joylink.rtss.simulation.cbtc.command.voice.operate; + +import lombok.Getter; + +public enum HandleType { + PINYIN; + @Getter + String name; + +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/operate/OperateDeviceEnum.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/operate/OperateDeviceEnum.java new file mode 100644 index 000000000..d279e898f --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/operate/OperateDeviceEnum.java @@ -0,0 +1,12 @@ +package club.joylink.rtss.simulation.cbtc.command.voice.operate; + +import java.util.List; + +public enum OperateDeviceEnum { + SWITCH(); + private OperateEnum[] operates; + + OperateDeviceEnum(OperateEnum... operates) { + this.operates = operates; + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/operate/OperateEnum.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/operate/OperateEnum.java new file mode 100644 index 000000000..36097b96e --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/operate/OperateEnum.java @@ -0,0 +1,38 @@ +package club.joylink.rtss.simulation.cbtc.command.voice.operate; + +import club.joylink.rtss.simulation.cbtc.CI.device.CiSwitchControlService; +import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.data.map.MapElement; +import club.joylink.rtss.simulation.cbtc.data.map.Switch; +import lombok.Getter; + + + +public enum OperateEnum { + SWITCH_DINGWEI(MapElement.DeviceType.SWITCH,"定位"){ + @Override + public void handle(Simulation simulation,CiSwitchControlService service, MapElement device) { + Switch aswitch = (Switch)device; + service.turn2NormalPosition(simulation,aswitch); + } + }, + SWITCH_FANWEI(MapElement.DeviceType.SWITCH,"反位"){ + @Override + public void handle(Simulation simulation, CiSwitchControlService service, MapElement device) { + Switch aswitch = (Switch)device; + service.turn2ReversePosition(simulation,aswitch); + } + } + ; + private MapElement.DeviceType deviceType; + @Getter + private String describe; + + public abstract void handle(Simulation simulation,CiSwitchControlService service, MapElement device); + + OperateEnum(MapElement.DeviceType deviceType, String describe) { + this.deviceType = deviceType; + this.describe = describe; + + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/vo/DeviceVoiceCommand.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/vo/DeviceVoiceCommand.java new file mode 100644 index 000000000..c665d0754 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/vo/DeviceVoiceCommand.java @@ -0,0 +1,47 @@ +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; + + public void appendCommandDescribe(String d){ + if(Objects.isNull(this.matchCommandDescribe)){ + this.matchCommandDescribe = d; + }else{ + this.matchCommandDescribe = this.matchCommandDescribe.concat(d); + } + + } + + @Override + public String toString(){ + StringBuilder sb = new StringBuilder(); + return sb.toString(); + } + +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/vo/OperateConfigData.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/vo/OperateConfigData.java new file mode 100644 index 000000000..478c0efe6 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/vo/OperateConfigData.java @@ -0,0 +1,15 @@ +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; + + public OperateConfigData(OperateEnum operate) { + this.operate = operate; + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/vo/VoiceConfigData.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/vo/VoiceConfigData.java new file mode 100644 index 000000000..3f326ae90 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/vo/VoiceConfigData.java @@ -0,0 +1,10 @@ +package club.joylink.rtss.simulation.cbtc.command.voice.vo; + +import lombok.Data; + +@Data +public class VoiceConfigData { + private String[] sourceMatch; + private String[] translateMatch; + +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/vo/WorkResult.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/vo/WorkResult.java new file mode 100644 index 000000000..3b8e05e87 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/vo/WorkResult.java @@ -0,0 +1,31 @@ +package club.joylink.rtss.simulation.cbtc.command.voice.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.data.map.MapNamedElement; +import lombok.Data; + +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; + this.device = device; + this.operate = operate; + } + + @Override + 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())); + return sb.toString(); + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/work/IDeviceWork.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/work/IDeviceWork.java new file mode 100644 index 000000000..a90a4a804 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/work/IDeviceWork.java @@ -0,0 +1,18 @@ +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.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 java.util.List; +import java.util.Optional; + +public interface IDeviceWork { + + Optional findDevice(Simulation simulation, List matchCommandDescribe); + WorkResult work(Simulation simulation, DeviceVoiceCommand command, MapElement device); + MapElement.DeviceType deviceType(); + +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/work/VoiceCommandAnalyseWork.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/work/VoiceCommandAnalyseWork.java new file mode 100644 index 000000000..6c3e3a04a --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/work/VoiceCommandAnalyseWork.java @@ -0,0 +1,48 @@ +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.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 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; + } + + public Optional analyse(Simulation simulation, DeviceVoiceCommand command) { + IDeviceWork deviceWork = this.findDeviceWork(command.getDeviceType()); + List findDeviceNames = this.commandAnalyse.parseCommandDescribe(command); + command.setMatchCommandDescribe(Joiner.on(",").join(findDeviceNames)); + Optional optional = deviceWork.findDevice(simulation,findDeviceNames); + return 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; + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/work/device/SwitchWork.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/work/device/SwitchWork.java new file mode 100644 index 000000000..82684efe3 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/voice/work/device/SwitchWork.java @@ -0,0 +1,57 @@ +package club.joylink.rtss.simulation.cbtc.command.voice.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.WorkResult; +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.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 { + @Autowired + private CiSwitchControlService ciSwitchControlService; + + @Override + public Optional findDevice(Simulation simulation, List matchCommandDescribe) { + JaroWinklerSimilarity similarity = new JaroWinklerSimilarity(); + Map similarityMaper = new HashMap<>(); + for (Switch aSwitch : simulation.getRepository().getSwitchList()) { + String switchName = aSwitch.getName(); + for (String findDeviceName : matchCommandDescribe) { + double scope = similarity.apply(switchName.toUpperCase(),findDeviceName); + similarityMaper.put(scope,aSwitch.getCode()); + } + } + if(similarityMaper.isEmpty()){ + return Optional.empty(); + } + + double max = similarityMaper.keySet().stream().mapToDouble(d->d).max().getAsDouble(); + String deviceCode = similarityMaper.get(max); + MapElement device = simulation.getRepository().getByCode(deviceCode); + return Optional.of((MapNamedElement)device); + } + + @Override + public WorkResult work(Simulation simulation, DeviceVoiceCommand command, MapElement device) { + command.getOperateConfigData().getOperate().handle(simulation,this.ciSwitchControlService,device); + return null; + } + + @Override + public MapElement.DeviceType deviceType() { + return MapElement.DeviceType.SWITCH; + } +} diff --git a/src/main/java/club/joylink/rtss/util/PinYinUtil.java b/src/main/java/club/joylink/rtss/util/PinYinUtil.java new file mode 100644 index 000000000..f406f8e4d --- /dev/null +++ b/src/main/java/club/joylink/rtss/util/PinYinUtil.java @@ -0,0 +1,57 @@ +package club.joylink.rtss.util; + +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; + +public class PinYinUtil { + + private final static HanyuPinyinOutputFormat PIN_YIN_FORMAT = new HanyuPinyinOutputFormat(); + static{ + /** + * 输出大小写设置 + * + * LOWERCASE:输出小写 + * UPPERCASE:输出大写 + */ + PIN_YIN_FORMAT.setCaseType(HanyuPinyinCaseType.UPPERCASE); + /** + * 输出音标设置 + * + * WITH_TONE_MARK:直接用音标符(必须设置WITH_U_UNICODE,否则会抛出异常) + * WITH_TONE_NUMBER:1-4数字表示音标 + * WITHOUT_TONE:没有音标 + */ + PIN_YIN_FORMAT.setToneType(HanyuPinyinToneType.WITHOUT_TONE); + + } + + public static String[] toPinYins(String[] source){ + String[] result = new String[source.length]; + for (int i = 0; i < source.length; i++) { + String s = source[i]; + String t = toPinYinSplitBlankSpace(s); + result[i] = t; + } + return result; + } + public static String toPinYinSplitBlankSpace(String sourceMsg){ + StringBuilder sb = new StringBuilder(); + for(char c : sourceMsg.toCharArray()){ + if(Character.toString(c).matches("[\\u4E00-\\u9FA5]+")) { + try { + String[] ss = PinyinHelper.toHanyuPinyinStringArray(c,PIN_YIN_FORMAT); + sb.append(" ").append(ss[0]).append("|"); + } catch (BadHanyuPinyinOutputFormatCombination e) { + e.printStackTrace(); + } + }else{ + sb.append(c); + } + } + return sb.toString().replaceAll("\\|"," ") + .replaceAll("\\s{2,}"," ").trim(); + } +} diff --git a/src/main/java/club/joylink/rtss/vo/voice/VoiceConfigVO.java b/src/main/java/club/joylink/rtss/vo/voice/VoiceConfigVO.java new file mode 100644 index 000000000..7d41d2516 --- /dev/null +++ b/src/main/java/club/joylink/rtss/vo/voice/VoiceConfigVO.java @@ -0,0 +1,113 @@ +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.Arrays; +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 config; + + + public VoiceDeviceConfig converBean(){ + VoiceDeviceConfig vc = new VoiceDeviceConfig(); + if(Objects.nonNull(this.wakeUpKw)){ + if(this.handleType == HandleType.PINYIN){ + this.wakeUpKw.setTranslateMatch(PinYinUtil.toPinYins(this.wakeUpKw.getSourceMatch())); + } + vc.setWakeUpKw(JsonUtils.writeValueAsString(this.wakeUpKw)); + } + if(!CollectionUtils.isEmpty(this.config)){ + for (OperateConfigData configData : this.config) { + if(this.handleType == HandleType.PINYIN){ + configData.setTranslateMatch(PinYinUtil.toPinYins(configData.getSourceMatch())); + } + } + 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 configList = JsonUtils.readCollection(vc.getConfig(), ArrayList.class,OperateConfigData.class); + configVO.setConfig(configList); + } + return configVO; + } + + +} diff --git a/src/main/java/club/joylink/rtss/vo/voice/VoiceQueryVO.java b/src/main/java/club/joylink/rtss/vo/voice/VoiceQueryVO.java new file mode 100644 index 000000000..ac7d7054c --- /dev/null +++ b/src/main/java/club/joylink/rtss/vo/voice/VoiceQueryVO.java @@ -0,0 +1,59 @@ +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.simulation.cbtc.data.map.MapElement; +import club.joylink.rtss.vo.client.PageQueryVO; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.StringUtils; + +import java.util.Objects; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder + +public class VoiceQueryVO extends PageQueryVO { + private Long id; + private String describe; + private Long mapId; + /** + * 处理方式,目前只支持拼音 + */ + private HandleType handleType; + /** + * 支持的设备类型 + */ + private MapElement.DeviceType deviceType; + + /** + * 是否启用0=未启用,1=启用 + */ + private Integer status; + + + public VoiceDeviceConfigExample createQuery(){ + VoiceDeviceConfigExample example = new VoiceDeviceConfigExample(); + VoiceDeviceConfigExample.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.deviceType)){ + criteria.andDeviceTypeEqualTo(this.deviceType.name()); + } + if(Objects.nonNull(this.status)){ + criteria.andStatusEqualTo(this.status); + } + return example; + } +} diff --git a/src/main/resources/mybatis/mapper/voice/VoiceDeviceConfigDAO.xml b/src/main/resources/mybatis/mapper/voice/VoiceDeviceConfigDAO.xml new file mode 100644 index 000000000..5f74c5824 --- /dev/null +++ b/src/main/resources/mybatis/mapper/voice/VoiceDeviceConfigDAO.xml @@ -0,0 +1,368 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + id, `describe`, map_id, create_id, handle_type, wake_up_kw, create_time, update_time, + device_type, `status` + + + config + + + + + + delete from rts_voice_device_config + where id = #{id,jdbcType=BIGINT} + + + delete from rts_voice_device_config + + + + + + insert into rts_voice_device_config (`describe`, map_id, create_id, + handle_type, wake_up_kw, create_time, + update_time, device_type, `status`, + config) + values (#{describe,jdbcType=VARCHAR}, #{mapId,jdbcType=BIGINT}, #{createId,jdbcType=BIGINT}, + #{handleType,jdbcType=VARCHAR}, #{wakeUpKw,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, + #{updateTime,jdbcType=TIMESTAMP}, #{deviceType,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, + #{config,jdbcType=LONGVARCHAR}) + + + insert into rts_voice_device_config + + + `describe`, + + + map_id, + + + create_id, + + + handle_type, + + + wake_up_kw, + + + create_time, + + + update_time, + + + device_type, + + + `status`, + + + config, + + + + + #{describe,jdbcType=VARCHAR}, + + + #{mapId,jdbcType=BIGINT}, + + + #{createId,jdbcType=BIGINT}, + + + #{handleType,jdbcType=VARCHAR}, + + + #{wakeUpKw,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + #{deviceType,jdbcType=VARCHAR}, + + + #{status,jdbcType=INTEGER}, + + + #{config,jdbcType=LONGVARCHAR}, + + + + + + update rts_voice_device_config + + + id = #{record.id,jdbcType=BIGINT}, + + + `describe` = #{record.describe,jdbcType=VARCHAR}, + + + map_id = #{record.mapId,jdbcType=BIGINT}, + + + create_id = #{record.createId,jdbcType=BIGINT}, + + + handle_type = #{record.handleType,jdbcType=VARCHAR}, + + + wake_up_kw = #{record.wakeUpKw,jdbcType=VARCHAR}, + + + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + + + update_time = #{record.updateTime,jdbcType=TIMESTAMP}, + + + device_type = #{record.deviceType,jdbcType=VARCHAR}, + + + `status` = #{record.status,jdbcType=INTEGER}, + + + config = #{record.config,jdbcType=LONGVARCHAR}, + + + + + + + + update rts_voice_device_config + set id = #{record.id,jdbcType=BIGINT}, + `describe` = #{record.describe,jdbcType=VARCHAR}, + map_id = #{record.mapId,jdbcType=BIGINT}, + create_id = #{record.createId,jdbcType=BIGINT}, + handle_type = #{record.handleType,jdbcType=VARCHAR}, + wake_up_kw = #{record.wakeUpKw,jdbcType=VARCHAR}, + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + update_time = #{record.updateTime,jdbcType=TIMESTAMP}, + device_type = #{record.deviceType,jdbcType=VARCHAR}, + `status` = #{record.status,jdbcType=INTEGER}, + config = #{record.config,jdbcType=LONGVARCHAR} + + + + + + update rts_voice_device_config + set id = #{record.id,jdbcType=BIGINT}, + `describe` = #{record.describe,jdbcType=VARCHAR}, + map_id = #{record.mapId,jdbcType=BIGINT}, + create_id = #{record.createId,jdbcType=BIGINT}, + handle_type = #{record.handleType,jdbcType=VARCHAR}, + wake_up_kw = #{record.wakeUpKw,jdbcType=VARCHAR}, + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + update_time = #{record.updateTime,jdbcType=TIMESTAMP}, + device_type = #{record.deviceType,jdbcType=VARCHAR}, + `status` = #{record.status,jdbcType=INTEGER} + + + + + + update rts_voice_device_config + + + `describe` = #{describe,jdbcType=VARCHAR}, + + + map_id = #{mapId,jdbcType=BIGINT}, + + + create_id = #{createId,jdbcType=BIGINT}, + + + handle_type = #{handleType,jdbcType=VARCHAR}, + + + wake_up_kw = #{wakeUpKw,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + device_type = #{deviceType,jdbcType=VARCHAR}, + + + `status` = #{status,jdbcType=INTEGER}, + + + config = #{config,jdbcType=LONGVARCHAR}, + + + where id = #{id,jdbcType=BIGINT} + + + update rts_voice_device_config + set `describe` = #{describe,jdbcType=VARCHAR}, + map_id = #{mapId,jdbcType=BIGINT}, + create_id = #{createId,jdbcType=BIGINT}, + handle_type = #{handleType,jdbcType=VARCHAR}, + wake_up_kw = #{wakeUpKw,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP}, + device_type = #{deviceType,jdbcType=VARCHAR}, + `status` = #{status,jdbcType=INTEGER}, + config = #{config,jdbcType=LONGVARCHAR} + where id = #{id,jdbcType=BIGINT} + + + update rts_voice_device_config + set `describe` = #{describe,jdbcType=VARCHAR}, + map_id = #{mapId,jdbcType=BIGINT}, + create_id = #{createId,jdbcType=BIGINT}, + handle_type = #{handleType,jdbcType=VARCHAR}, + wake_up_kw = #{wakeUpKw,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP}, + device_type = #{deviceType,jdbcType=VARCHAR}, + `status` = #{status,jdbcType=INTEGER} + where id = #{id,jdbcType=BIGINT} + + \ No newline at end of file diff --git a/src/test/java/club/joylink/rtss/services/util/SplitWordTest.java b/src/test/java/club/joylink/rtss/services/util/SplitWordTest.java new file mode 100644 index 000000000..92688af1f --- /dev/null +++ b/src/test/java/club/joylink/rtss/services/util/SplitWordTest.java @@ -0,0 +1,36 @@ +package club.joylink.rtss.services.util; + +import org.ansj.domain.Result; +import org.ansj.domain.Term; +import org.ansj.library.DicLibrary; +import org.ansj.splitWord.analysis.DicAnalysis; + +public class SplitWordTest { + public static void main(String[] args) throws Exception { + + DicLibrary.insert(DicLibrary.DEFAULT, "dao cha", DicLibrary.DEFAULT_NATURE, 1); + DicLibrary.insert(DicLibrary.DEFAULT, "ding wei", DicLibrary.DEFAULT_NATURE, 1); + DicLibrary.insert(DicLibrary.DEFAULT, "fan wei", DicLibrary.DEFAULT_NATURE, 1); + DicLibrary.insert(DicLibrary.DEFAULT, "ban li", DicLibrary.DEFAULT_NATURE, 1); + +// print("1234asdfa"); +// print("BAN LI|p0707|daochadingwei|"); + print("BAN LI p0707 dao cha ding wei"); + } + private static void print(String s) throws Exception { +// print(BaseAnalysis.parse(s)); +// print(ToAnalysis.parse(s)); +// print(IndexAnalysis.parse(s)); + print(DicAnalysis.parse(s)); +// print(NlpAnalysis.parse(s)); +// print(DicAnalysis.parse(s)); + } + private static void print(Result result){ + System.out.println("------------------------------"); + for (Term term : result) { + String d = String.format("%s->%s->%s->%s--->%s" + ,term.getName(),term.getNatureStr(),term.getOffe(),term.getSynonyms(),term.getSubTerm()); + System.out.println(d); + } + } +} diff --git a/src/test/java/club/joylink/rtss/services/util/StringSimilarityTest.java b/src/test/java/club/joylink/rtss/services/util/StringSimilarityTest.java new file mode 100644 index 000000000..828de7e40 --- /dev/null +++ b/src/test/java/club/joylink/rtss/services/util/StringSimilarityTest.java @@ -0,0 +1,17 @@ +package club.joylink.rtss.services.util; + +import org.apache.commons.text.similarity.JaroWinklerSimilarity; + +public class StringSimilarityTest { + public static void main(String[] args) { + String d = "道岔p0202范围"; + System.out.println(d.substring(0,2)); + System.out.println(d.substring(d.length()-2)); + System.out.println(d.substring(2,d.length()-2)); + JaroWinklerSimilarity similarity = new JaroWinklerSimilarity(); + System.out.println(similarity.apply("p020301","p0202"));; + System.out.println(similarity.apply("p02021","啊0202"));; + System.out.println(similarity.apply("p0202","是0202"));; + System.out.println(similarity.apply("P0202","P0202"));; + } +} diff --git a/src/test/java/club/joylink/rtss/services/voice/SimulationVoiceTest.java b/src/test/java/club/joylink/rtss/services/voice/SimulationVoiceTest.java new file mode 100644 index 000000000..87024e563 --- /dev/null +++ b/src/test/java/club/joylink/rtss/services/voice/SimulationVoiceTest.java @@ -0,0 +1,98 @@ +package club.joylink.rtss.services.voice; + +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.util.JsonUtils; +import club.joylink.rtss.vo.LoginUserInfoVO; +import club.joylink.rtss.vo.project.ProjectVO; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.util.FileCopyUtils; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.List; + +@SpringBootTest +public class SimulationVoiceTest { + @Autowired + private DeviceVoiceCommandService commandService; + @Autowired + private SimulationService simulationService; + @Autowired + private SimulationManager simulationManager; + + 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"; + LoginUserInfoVO infoVO = JsonUtils.read(testJsonData,LoginUserInfoVO.class); + Project project = new Project(); + project.setName("默认项目"); + project.setCode("DEFAULT"); + ProjectVO projectVO = new ProjectVO(project); + infoVO.setProjectInfo(projectVO); + return infoVO; + } + + private String findLocalVoiceFileData(String filePath) throws IOException { + File file = new File(filePath); + String fileBase64 = FileCopyUtils.copyToString(new FileReader(file)); + return fileBase64; + } + + @Test + public void test() throws IOException { + LoginUserInfoVO userInfoVO = this.getInfo(); + String simKey = simulationService.createSimulation(10601L,userInfoVO); + Simulation simulation = (Simulation)this.simulationManager.getById(simKey); + String fileData = this.findLocalVoiceFileData("C:\\Users\\joylink\\Desktop\\voice\\5.txt"); +// ParseData result = this.commandService.voiceCommand(simulation,fileData); +// System.out.println(result); + } + @Test + public void testSource3(){ + LoginUserInfoVO userInfoVO = this.getInfo(); + String simKey = simulationService.createSimulation(10601L,userInfoVO); + Simulation simulation = (Simulation)this.simulationManager.getById(simKey); +// String fileData = this.findLocalVoiceFileData("C:\\Users\\joylink\\Desktop\\voice\\5.txt"); +// ParseData result = this.commandService.voiceCommand(simulation,"道岔p0707定位"); +// System.out.println(result); + } + @Test + public void testSource(){ + LoginUserInfoVO userInfoVO = this.getInfo(); + String simKey = simulationService.createSimulation(10601L,userInfoVO); + Simulation simulation = (Simulation)this.simulationManager.getById(simKey); +// String fileData = this.findLocalVoiceFileData("C:\\Users\\joylink\\Desktop\\voice\\5.txt"); +// ParseData result = this.commandService.voiceCommand(simulation,"办理p0707道岔定位"); +// System.out.println(result); + } + + @Test + public void testSource2() throws IOException { + LoginUserInfoVO userInfoVO = this.getInfo(); + String simKey = simulationService.createSimulation(10601L,userInfoVO); + Simulation simulation = (Simulation)this.simulationManager.getById(simKey); + String fileData = this.findLocalVoiceFileData("C:\\Users\\joylink\\Desktop\\voice\\5.txt"); + List results = this.commandService.voiceCommand(simulation,fileData); + for (WorkResult result : results) { + System.out.println(result); + } + } + + @Test + public void newTest(){ + LoginUserInfoVO userInfoVO = this.getInfo(); + String simKey = simulationService.createSimulation(10601L,userInfoVO); + Simulation simulation = (Simulation)this.simulationManager.getById(simKey); + List results = this.commandService.voiceCommand(simulation,"道岔帮你p07017道岔定位"); + for (WorkResult result : results) { + System.out.println(result); + } + } +} diff --git a/src/test/java/club/joylink/rtss/services/voice/VoiceDataManageTest.java b/src/test/java/club/joylink/rtss/services/voice/VoiceDataManageTest.java new file mode 100644 index 000000000..09bf677e7 --- /dev/null +++ b/src/test/java/club/joylink/rtss/services/voice/VoiceDataManageTest.java @@ -0,0 +1,88 @@ +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.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 org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.List; + +@SpringBootTest +//@Transactional +public class VoiceDataManageTest { + @Autowired + private VoiceDataService dataService; + + @Autowired + private IVoiceCommandDataService commandDataService; + + 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"; + LoginUserInfoVO infoVO = JsonUtils.read(testJsonData,LoginUserInfoVO.class); + Project project = new Project(); + project.setName("默认项目"); + project.setCode("DEFAULT"); + ProjectVO projectVO = new ProjectVO(project); + infoVO.setProjectInfo(projectVO); + return infoVO; + } + + + @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.setSourceMatch(new String[]{"道岔"}); + configVO.setWakeUpKw(config); + List configDataList = Lists.newArrayList(); + OperateConfigData configData = new OperateConfigData(OperateEnum.SWITCH_DINGWEI); + configData.setSourceMatch(new String[]{"定位"}); + configDataList.add(configData); + configData = new OperateConfigData(OperateEnum.SWITCH_FANWEI); + configData.setSourceMatch(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); + } + + @Test + public void changeStatus(){ + this.dataService.changeStatus(3L,1); + } + + @Test + public void findConfigData(){ + List list = this.commandDataService.findData(50L); + System.out.println(list); + } + @Test + public void changeStatusAndFindConfig(){ + this.dataService.changeStatus(3L,0); + List list = this.commandDataService.findData(50L); + System.out.println(list); + } +}