语音指令

This commit is contained in:
tiger_zhou 2023-03-28 15:43:03 +08:00
parent 246bfbe92c
commit 2445287f8c
35 changed files with 2613 additions and 3 deletions

33
pom.xml
View File

@ -146,6 +146,39 @@
<artifactId>protobuf-java</artifactId>
<version>3.19.3</version>
</dependency>
<!-- <dependency>
<groupId>com.chenlb.mmseg4j</groupId>
<artifactId>mmseg4j-core</artifactId>
<version>1.10.0</version>
</dependency>-->
<dependency>
<groupId>org.ansj</groupId>
<artifactId>ansj_seg</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.11</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<!-- <dependency>
<groupId>info.debatty</groupId>
<artifactId>java-string-similarity</artifactId>
<version>2.0.0</version>
</dependency>-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.10.0</version>
</dependency>
</dependencies>
<build>

View File

@ -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;
}
}

View File

@ -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;
/**
* 验证码有效期: 单位 分钟

View File

@ -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<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,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;
}

View File

@ -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<Criteria> oredCriteria;
private Integer limit;
private Long offset;
public VoiceDeviceConfigExample() {
oredCriteria = new ArrayList<Criteria>();
}
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<Criteria> 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<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> 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<Long> values) {
addCriterion("id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<Long> 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<String> values) {
addCriterion("`describe` in", values, "describe");
return (Criteria) this;
}
public Criteria andDescribeNotIn(List<String> 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<Long> values) {
addCriterion("map_id in", values, "mapId");
return (Criteria) this;
}
public Criteria andMapIdNotIn(List<Long> 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<Long> values) {
addCriterion("create_id in", values, "createId");
return (Criteria) this;
}
public Criteria andCreateIdNotIn(List<Long> 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<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;
}
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<Date> values) {
addCriterion("create_time in", values, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotIn(List<Date> 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<Date> values) {
addCriterion("update_time in", values, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeNotIn(List<Date> 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<String> values) {
addCriterion("device_type in", values, "deviceType");
return (Criteria) this;
}
public Criteria andDeviceTypeNotIn(List<String> 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<Integer> values) {
addCriterion("`status` in", values, "status");
return (Criteria) this;
}
public Criteria andStatusNotIn(List<Integer> 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);
}
}
}

View File

@ -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")

View File

@ -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("缓存地图数据结束");
}

View File

@ -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<VoiceConfigVO> findData(Long mapId);
}

View File

@ -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<VoiceConfigVO> query(VoiceQueryVO query);
void changeStatus(Long id,Integer status);
}

View File

@ -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<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().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<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

@ -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<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

@ -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<DeviceVoiceCommand> matcher(List<VoiceConfigVO> configVOList, String msg){
List<DeviceVoiceCommand> findParseDataList = Lists.newArrayList();
for (VoiceConfigVO configVO : configVOList) {
Optional<List<DeviceVoiceCommand>> optional = commandMatcher.matchCommand(configVO,msg);
optional.ifPresent(findParseDataList::addAll);
}
return findParseDataList;
}
}

View File

@ -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<String> parseCommandDescribe(DeviceVoiceCommand command) {
this.initDic(command);
String pinyinStr = PinYinUtil.toPinYinSplitBlankSpace(command.getSourceDescrbe());
Result reslut = DicAnalysis.parse(pinyinStr);
List<String> 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);
}
}
}

View File

@ -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<String> parseCommandDescribe(DeviceVoiceCommand Command);
}

View File

@ -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<List<DeviceVoiceCommand>> matchCommand(VoiceConfigVO configVOList, String msg);
// HandleType handleType();
}

View File

@ -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<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())
&& ArrayUtils.isNotEmpty(d.getMatchCommandKW())
&& ArrayUtils.isNotEmpty(d.getTranslateWakeUpKW())
).collect(Collectors.toList());
if(CollectionUtils.isEmpty(commandList)){
return Optional.empty();
}
return Optional.of(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().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;
}
}

View File

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

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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();
}
}

View File

@ -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<MapNamedElement> findDevice(Simulation simulation, List<String> matchCommandDescribe);
WorkResult work(Simulation simulation, DeviceVoiceCommand command, MapElement device);
MapElement.DeviceType deviceType();
}

View File

@ -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<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;
}
public Optional<MapNamedElement> analyse(Simulation simulation, DeviceVoiceCommand command) {
IDeviceWork deviceWork = this.findDeviceWork(command.getDeviceType());
List<String> findDeviceNames = this.commandAnalyse.parseCommandDescribe(command);
command.setMatchCommandDescribe(Joiner.on(",").join(findDeviceNames));
Optional<MapNamedElement> 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;
}
}

View File

@ -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<MapNamedElement> findDevice(Simulation simulation, List<String> matchCommandDescribe) {
JaroWinklerSimilarity similarity = new JaroWinklerSimilarity();
Map<Double,String> 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;
}
}

View File

@ -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_NUMBER1-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();
}
}

View File

@ -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<OperateConfigData> 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<OperateConfigData> configList = JsonUtils.readCollection(vc.getConfig(), ArrayList.class,OperateConfigData.class);
configVO.setConfig(configList);
}
return configVO;
}
}

View File

@ -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;
}
}

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.voice.VoiceDeviceConfigDAO">
<resultMap id="BaseResultMap" type="club.joylink.rtss.entity.voice.VoiceDeviceConfig">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="describe" jdbcType="VARCHAR" property="describe" />
<result column="map_id" jdbcType="BIGINT" property="mapId" />
<result column="create_id" jdbcType="BIGINT" property="createId" />
<result column="handle_type" jdbcType="VARCHAR" property="handleType" />
<result column="wake_up_kw" jdbcType="VARCHAR" property="wakeUpKw" />
<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="status" jdbcType="INTEGER" property="status" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="club.joylink.rtss.entity.voice.VoiceDeviceConfig">
<result column="config" jdbcType="LONGVARCHAR" property="config" />
</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`, map_id, create_id, handle_type, wake_up_kw, create_time, update_time,
device_type, `status`
</sql>
<sql id="Blob_Column_List">
config
</sql>
<select id="selectByExampleWithBLOBs" parameterType="club.joylink.rtss.entity.voice.VoiceDeviceConfigExample" 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.voice.VoiceDeviceConfigExample" 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.voice.VoiceDeviceConfigExample">
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.voice.VoiceDeviceConfig" useGeneratedKeys="true">
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>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="club.joylink.rtss.entity.voice.VoiceDeviceConfig" useGeneratedKeys="true">
insert into rts_voice_device_config
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="describe != null">
`describe`,
</if>
<if test="mapId != null">
map_id,
</if>
<if test="createId != null">
create_id,
</if>
<if test="handleType != null">
handle_type,
</if>
<if test="wakeUpKw != null">
wake_up_kw,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="deviceType != null">
device_type,
</if>
<if test="status != null">
`status`,
</if>
<if test="config != null">
config,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="describe != null">
#{describe,jdbcType=VARCHAR},
</if>
<if test="mapId != null">
#{mapId,jdbcType=BIGINT},
</if>
<if test="createId != null">
#{createId,jdbcType=BIGINT},
</if>
<if test="handleType != null">
#{handleType,jdbcType=VARCHAR},
</if>
<if test="wakeUpKw != null">
#{wakeUpKw,jdbcType=VARCHAR},
</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="status != null">
#{status,jdbcType=INTEGER},
</if>
<if test="config != null">
#{config,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="club.joylink.rtss.entity.voice.VoiceDeviceConfigExample" 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.mapId != null">
map_id = #{record.mapId,jdbcType=BIGINT},
</if>
<if test="record.createId != null">
create_id = #{record.createId,jdbcType=BIGINT},
</if>
<if test="record.handleType != null">
handle_type = #{record.handleType,jdbcType=VARCHAR},
</if>
<if test="record.wakeUpKw != null">
wake_up_kw = #{record.wakeUpKw,jdbcType=VARCHAR},
</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.status != null">
`status` = #{record.status,jdbcType=INTEGER},
</if>
<if test="record.config != null">
config = #{record.config,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},
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}
<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},
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}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="club.joylink.rtss.entity.voice.VoiceDeviceConfig">
update rts_voice_device_config
<set>
<if test="describe != null">
`describe` = #{describe,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="handleType != null">
handle_type = #{handleType,jdbcType=VARCHAR},
</if>
<if test="wakeUpKw != null">
wake_up_kw = #{wakeUpKw,jdbcType=VARCHAR},
</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="status != null">
`status` = #{status,jdbcType=INTEGER},
</if>
<if test="config != null">
config = #{config,jdbcType=LONGVARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="club.joylink.rtss.entity.voice.VoiceDeviceConfig">
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>
<update id="updateByPrimaryKey" parameterType="club.joylink.rtss.entity.voice.VoiceDeviceConfig">
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}
</update>
</mapper>

View File

@ -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);
}
}
}

View File

@ -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"));;
}
}

View File

@ -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<WorkResult> 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<WorkResult> results = this.commandService.voiceCommand(simulation,"道岔帮你p07017道岔定位");
for (WorkResult result : results) {
System.out.println(result);
}
}
}

View File

@ -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<OperateConfigData> 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<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);
}
}