From 0237c530005be606b101fbd465316d61685e2519 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Fri, 30 Apr 2021 18:29:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=BA=E6=99=AF=E8=AF=AD=E9=9F=B3=E5=BD=95?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CompetitionPracticalController.java | 31 +- .../controller/voice/VoiceController.java | 17 +- .../rtss/dao/CompetitionVoiceRecordDAO.java | 12 + .../rtss/entity/CompetitionVoiceRecord.java | 108 ++++ .../entity/CompetitionVoiceRecordExample.java | 542 ++++++++++++++++++ .../joylink/rtss/services/IVoiceService.java | 10 +- .../CompetitionPracticalService.java | 87 +++ .../ICompetitionPracticalService.java | 15 +- .../services/voice/IVoiceTrainingService.java | 17 + .../services/voice/VoiceTrainingService.java | 49 ++ .../voice/huawei/HuaweiVoiceServiceImpl.java | 7 +- .../CompetitionVoiceRecordCheckVO.java | 19 + .../client/competition/VoiceErrorSetVO.java | 46 ++ .../mapper/CompetitionVoiceRecordDAO.xml | 213 +++++++ 14 files changed, 1153 insertions(+), 20 deletions(-) create mode 100644 src/main/java/club/joylink/rtss/dao/CompetitionVoiceRecordDAO.java create mode 100644 src/main/java/club/joylink/rtss/entity/CompetitionVoiceRecord.java create mode 100644 src/main/java/club/joylink/rtss/entity/CompetitionVoiceRecordExample.java create mode 100644 src/main/java/club/joylink/rtss/services/voice/IVoiceTrainingService.java create mode 100644 src/main/java/club/joylink/rtss/services/voice/VoiceTrainingService.java create mode 100644 src/main/java/club/joylink/rtss/vo/client/competition/CompetitionVoiceRecordCheckVO.java create mode 100644 src/main/java/club/joylink/rtss/vo/client/competition/VoiceErrorSetVO.java create mode 100644 src/main/resources/mybatis/mapper/CompetitionVoiceRecordDAO.xml diff --git a/src/main/java/club/joylink/rtss/controller/competition/CompetitionPracticalController.java b/src/main/java/club/joylink/rtss/controller/competition/CompetitionPracticalController.java index 944cca986..a0bba31bc 100644 --- a/src/main/java/club/joylink/rtss/controller/competition/CompetitionPracticalController.java +++ b/src/main/java/club/joylink/rtss/controller/competition/CompetitionPracticalController.java @@ -1,16 +1,14 @@ package club.joylink.rtss.controller.competition; import club.joylink.rtss.controller.advice.AuthenticateInterceptor; +import club.joylink.rtss.entity.CompetitionVoiceRecord; import club.joylink.rtss.entity.CompetitionWithBLOBs; import club.joylink.rtss.services.completition.ICompetitionPracticalService; import club.joylink.rtss.simulation.cbtc.script.ScriptBO; import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.client.PageVO; -import club.joylink.rtss.vo.client.competition.CompetitionPagedQueryVO; -import club.joylink.rtss.vo.client.competition.CompetitionResult; -import club.joylink.rtss.vo.client.competition.CompetitionVO; -import club.joylink.rtss.vo.client.competition.OperationStatisticVO; +import club.joylink.rtss.vo.client.competition.*; import club.joylink.rtss.vo.client.pay.WxPayUnifiedOrderResultVO; import club.joylink.rtss.vo.client.userPermission.UserPermissionVO; import club.joylink.rtss.vo.client.validGroup.competition.CompetitionUpdateCheck; @@ -21,6 +19,7 @@ import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import springfox.documentation.annotations.ApiIgnore; import java.util.List; @@ -102,6 +101,30 @@ public class CompetitionPracticalController { return iCompetitionPracticalService.purchasePermission(mapId, monthAmount, user); } + @ApiOperation("查询语音录制") + @GetMapping("/voice/record/query/{userId}/{competitionId}") + public List queryVoiceRecords(@PathVariable Long userId, @PathVariable Long competitionId) { + return iCompetitionPracticalService.queryVoiceRecords(userId, competitionId); + } + + @ApiOperation("新增语音录制") + @PostMapping("/voice/record/{competitionId}/{actionId}") + public CompetitionVoiceRecord voiceRecord(@PathVariable Long competitionId, @PathVariable String actionId, MultipartFile file, @RequestAttribute UserVO user) { + return iCompetitionPracticalService.voiceRecord(competitionId, actionId, file, user); + } + + @ApiOperation("更新语音录制") + @PutMapping("/voice/record/{recordId}") + public CompetitionVoiceRecord updateVoiceRecord(@PathVariable Long recordId, MultipartFile file, @RequestAttribute UserVO user) { + return iCompetitionPracticalService.updateVoiceRecord(recordId, file, user); + } + + @ApiOperation("语音录制校验") + @GetMapping("/voice/record/check/{recordId}") + public VoiceErrorSetVO voiceRecordCheck(@PathVariable Long recordId) { + return iCompetitionPracticalService.voiceRecordCheck(recordId); + } + /* ------------------------- 竞赛运行相关 ------------------------- */ @ApiOperation("加载竞赛场景") @PutMapping("/load/{group}/{id}") diff --git a/src/main/java/club/joylink/rtss/controller/voice/VoiceController.java b/src/main/java/club/joylink/rtss/controller/voice/VoiceController.java index 2472bdd05..2cb79bd3c 100644 --- a/src/main/java/club/joylink/rtss/controller/voice/VoiceController.java +++ b/src/main/java/club/joylink/rtss/controller/voice/VoiceController.java @@ -1,12 +1,17 @@ package club.joylink.rtss.controller.voice; import club.joylink.rtss.services.IVoiceService; +import club.joylink.rtss.services.voice.IVoiceTrainingService; import club.joylink.rtss.simulation.cbtc.conversation.SimulationVoiceHandler; +import club.joylink.rtss.vo.client.PageQueryVO; +import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.VoiceRecognitionResult; +import club.joylink.rtss.vo.client.competition.VoiceErrorSetVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -25,13 +30,19 @@ public class VoiceController { @Autowired private SimulationVoiceHandler simulationVoiceHandler; + @Autowired + private IVoiceTrainingService iVoiceTrainingService; + @ApiOperation("语音识别") @PostMapping("recognition") public VoiceRecognitionResult voiceRecognition(MultipartFile file) { - VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(file, ""); - result.setResult(simulationVoiceHandler.handle(result.getResult())); - return result; + return iVoiceTrainingService.voiceRecognition(file); + } + @ApiOperation("查询语音识别错误集") + @GetMapping("/errorSet/paged") + public PageVO pagedQueryErrorSet(PageQueryVO queryVO) { + return iVoiceTrainingService.pagedQueryErrorSet(queryVO); } } diff --git a/src/main/java/club/joylink/rtss/dao/CompetitionVoiceRecordDAO.java b/src/main/java/club/joylink/rtss/dao/CompetitionVoiceRecordDAO.java new file mode 100644 index 000000000..5c2ee9861 --- /dev/null +++ b/src/main/java/club/joylink/rtss/dao/CompetitionVoiceRecordDAO.java @@ -0,0 +1,12 @@ +package club.joylink.rtss.dao; + +import club.joylink.rtss.entity.CompetitionVoiceRecord; +import club.joylink.rtss.entity.CompetitionVoiceRecordExample; +import org.springframework.stereotype.Repository; + +/** + * CompetitionVoiceRecordDAO继承基类 + */ +@Repository +public interface CompetitionVoiceRecordDAO extends MyBatisBaseDao { +} \ No newline at end of file diff --git a/src/main/java/club/joylink/rtss/entity/CompetitionVoiceRecord.java b/src/main/java/club/joylink/rtss/entity/CompetitionVoiceRecord.java new file mode 100644 index 000000000..e01f96c22 --- /dev/null +++ b/src/main/java/club/joylink/rtss/entity/CompetitionVoiceRecord.java @@ -0,0 +1,108 @@ +package club.joylink.rtss.entity; + +import java.io.Serializable; + +/** + * @author + * + */ +public class CompetitionVoiceRecord implements Serializable { + private Long id; + + private Long userId; + + private Long competitionId; + + private String actionId; + + private String filepath; + + private static final long serialVersionUID = 1L; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public Long getCompetitionId() { + return competitionId; + } + + public void setCompetitionId(Long competitionId) { + this.competitionId = competitionId; + } + + public String getActionId() { + return actionId; + } + + public void setActionId(String actionId) { + this.actionId = actionId; + } + + public String getFilepath() { + return filepath; + } + + public void setFilepath(String filepath) { + this.filepath = filepath; + } + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + CompetitionVoiceRecord other = (CompetitionVoiceRecord) that; + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId())) + && (this.getCompetitionId() == null ? other.getCompetitionId() == null : this.getCompetitionId().equals(other.getCompetitionId())) + && (this.getActionId() == null ? other.getActionId() == null : this.getActionId().equals(other.getActionId())) + && (this.getFilepath() == null ? other.getFilepath() == null : this.getFilepath().equals(other.getFilepath())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode()); + result = prime * result + ((getCompetitionId() == null) ? 0 : getCompetitionId().hashCode()); + result = prime * result + ((getActionId() == null) ? 0 : getActionId().hashCode()); + result = prime * result + ((getFilepath() == null) ? 0 : getFilepath().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", userId=").append(userId); + sb.append(", competitionId=").append(competitionId); + sb.append(", actionId=").append(actionId); + sb.append(", filepath=").append(filepath); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/club/joylink/rtss/entity/CompetitionVoiceRecordExample.java b/src/main/java/club/joylink/rtss/entity/CompetitionVoiceRecordExample.java new file mode 100644 index 000000000..d22e1f8ec --- /dev/null +++ b/src/main/java/club/joylink/rtss/entity/CompetitionVoiceRecordExample.java @@ -0,0 +1,542 @@ +package club.joylink.rtss.entity; + +import java.util.ArrayList; +import java.util.List; + +public class CompetitionVoiceRecordExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + private Integer limit; + + private Long offset; + + public CompetitionVoiceRecordExample() { + 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 andUserIdIsNull() { + addCriterion("user_id is null"); + return (Criteria) this; + } + + public Criteria andUserIdIsNotNull() { + addCriterion("user_id is not null"); + return (Criteria) this; + } + + public Criteria andUserIdEqualTo(Long value) { + addCriterion("user_id =", value, "userId"); + return (Criteria) this; + } + + public Criteria andUserIdNotEqualTo(Long value) { + addCriterion("user_id <>", value, "userId"); + return (Criteria) this; + } + + public Criteria andUserIdGreaterThan(Long value) { + addCriterion("user_id >", value, "userId"); + return (Criteria) this; + } + + public Criteria andUserIdGreaterThanOrEqualTo(Long value) { + addCriterion("user_id >=", value, "userId"); + return (Criteria) this; + } + + public Criteria andUserIdLessThan(Long value) { + addCriterion("user_id <", value, "userId"); + return (Criteria) this; + } + + public Criteria andUserIdLessThanOrEqualTo(Long value) { + addCriterion("user_id <=", value, "userId"); + return (Criteria) this; + } + + public Criteria andUserIdIn(List values) { + addCriterion("user_id in", values, "userId"); + return (Criteria) this; + } + + public Criteria andUserIdNotIn(List values) { + addCriterion("user_id not in", values, "userId"); + return (Criteria) this; + } + + public Criteria andUserIdBetween(Long value1, Long value2) { + addCriterion("user_id between", value1, value2, "userId"); + return (Criteria) this; + } + + public Criteria andUserIdNotBetween(Long value1, Long value2) { + addCriterion("user_id not between", value1, value2, "userId"); + return (Criteria) this; + } + + public Criteria andCompetitionIdIsNull() { + addCriterion("competition_id is null"); + return (Criteria) this; + } + + public Criteria andCompetitionIdIsNotNull() { + addCriterion("competition_id is not null"); + return (Criteria) this; + } + + public Criteria andCompetitionIdEqualTo(Long value) { + addCriterion("competition_id =", value, "competitionId"); + return (Criteria) this; + } + + public Criteria andCompetitionIdNotEqualTo(Long value) { + addCriterion("competition_id <>", value, "competitionId"); + return (Criteria) this; + } + + public Criteria andCompetitionIdGreaterThan(Long value) { + addCriterion("competition_id >", value, "competitionId"); + return (Criteria) this; + } + + public Criteria andCompetitionIdGreaterThanOrEqualTo(Long value) { + addCriterion("competition_id >=", value, "competitionId"); + return (Criteria) this; + } + + public Criteria andCompetitionIdLessThan(Long value) { + addCriterion("competition_id <", value, "competitionId"); + return (Criteria) this; + } + + public Criteria andCompetitionIdLessThanOrEqualTo(Long value) { + addCriterion("competition_id <=", value, "competitionId"); + return (Criteria) this; + } + + public Criteria andCompetitionIdIn(List values) { + addCriterion("competition_id in", values, "competitionId"); + return (Criteria) this; + } + + public Criteria andCompetitionIdNotIn(List values) { + addCriterion("competition_id not in", values, "competitionId"); + return (Criteria) this; + } + + public Criteria andCompetitionIdBetween(Long value1, Long value2) { + addCriterion("competition_id between", value1, value2, "competitionId"); + return (Criteria) this; + } + + public Criteria andCompetitionIdNotBetween(Long value1, Long value2) { + addCriterion("competition_id not between", value1, value2, "competitionId"); + return (Criteria) this; + } + + public Criteria andActionIdIsNull() { + addCriterion("action_id is null"); + return (Criteria) this; + } + + public Criteria andActionIdIsNotNull() { + addCriterion("action_id is not null"); + return (Criteria) this; + } + + public Criteria andActionIdEqualTo(String value) { + addCriterion("action_id =", value, "actionId"); + return (Criteria) this; + } + + public Criteria andActionIdNotEqualTo(String value) { + addCriterion("action_id <>", value, "actionId"); + return (Criteria) this; + } + + public Criteria andActionIdGreaterThan(String value) { + addCriterion("action_id >", value, "actionId"); + return (Criteria) this; + } + + public Criteria andActionIdGreaterThanOrEqualTo(String value) { + addCriterion("action_id >=", value, "actionId"); + return (Criteria) this; + } + + public Criteria andActionIdLessThan(String value) { + addCriterion("action_id <", value, "actionId"); + return (Criteria) this; + } + + public Criteria andActionIdLessThanOrEqualTo(String value) { + addCriterion("action_id <=", value, "actionId"); + return (Criteria) this; + } + + public Criteria andActionIdLike(String value) { + addCriterion("action_id like", value, "actionId"); + return (Criteria) this; + } + + public Criteria andActionIdNotLike(String value) { + addCriterion("action_id not like", value, "actionId"); + return (Criteria) this; + } + + public Criteria andActionIdIn(List values) { + addCriterion("action_id in", values, "actionId"); + return (Criteria) this; + } + + public Criteria andActionIdNotIn(List values) { + addCriterion("action_id not in", values, "actionId"); + return (Criteria) this; + } + + public Criteria andActionIdBetween(String value1, String value2) { + addCriterion("action_id between", value1, value2, "actionId"); + return (Criteria) this; + } + + public Criteria andActionIdNotBetween(String value1, String value2) { + addCriterion("action_id not between", value1, value2, "actionId"); + return (Criteria) this; + } + + public Criteria andFilepathIsNull() { + addCriterion("filePath is null"); + return (Criteria) this; + } + + public Criteria andFilepathIsNotNull() { + addCriterion("filePath is not null"); + return (Criteria) this; + } + + public Criteria andFilepathEqualTo(String value) { + addCriterion("filePath =", value, "filepath"); + return (Criteria) this; + } + + public Criteria andFilepathNotEqualTo(String value) { + addCriterion("filePath <>", value, "filepath"); + return (Criteria) this; + } + + public Criteria andFilepathGreaterThan(String value) { + addCriterion("filePath >", value, "filepath"); + return (Criteria) this; + } + + public Criteria andFilepathGreaterThanOrEqualTo(String value) { + addCriterion("filePath >=", value, "filepath"); + return (Criteria) this; + } + + public Criteria andFilepathLessThan(String value) { + addCriterion("filePath <", value, "filepath"); + return (Criteria) this; + } + + public Criteria andFilepathLessThanOrEqualTo(String value) { + addCriterion("filePath <=", value, "filepath"); + return (Criteria) this; + } + + public Criteria andFilepathLike(String value) { + addCriterion("filePath like", value, "filepath"); + return (Criteria) this; + } + + public Criteria andFilepathNotLike(String value) { + addCriterion("filePath not like", value, "filepath"); + return (Criteria) this; + } + + public Criteria andFilepathIn(List values) { + addCriterion("filePath in", values, "filepath"); + return (Criteria) this; + } + + public Criteria andFilepathNotIn(List values) { + addCriterion("filePath not in", values, "filepath"); + return (Criteria) this; + } + + public Criteria andFilepathBetween(String value1, String value2) { + addCriterion("filePath between", value1, value2, "filepath"); + return (Criteria) this; + } + + public Criteria andFilepathNotBetween(String value1, String value2) { + addCriterion("filePath not between", value1, value2, "filepath"); + 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/services/IVoiceService.java b/src/main/java/club/joylink/rtss/services/IVoiceService.java index 2c6f27cd4..8fd1a9b88 100644 --- a/src/main/java/club/joylink/rtss/services/IVoiceService.java +++ b/src/main/java/club/joylink/rtss/services/IVoiceService.java @@ -85,13 +85,17 @@ public interface IVoiceService { } } - static String handleAndSaveFile(MultipartFile file) throws IOException { + static String handleAndSaveFile(MultipartFile file) { String contentType = file.getContentType(); BusinessExceptionAssertEnum.UNSUPPORTED_FILE_FORMAT.assertTrue( "audio/wave".equals(contentType) || "audio/wav".equals(contentType) || "audio/x-wav".equals(contentType), String.format("不支持的文件格式[%s]", contentType)); - InputStream inputStream = file.getInputStream(); - return saveFile(inputStream); + try { + InputStream inputStream = file.getInputStream(); + return saveFile(inputStream); + } catch (IOException e) { + throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("语音文件上传失败", e); + } } /** diff --git a/src/main/java/club/joylink/rtss/services/completition/CompetitionPracticalService.java b/src/main/java/club/joylink/rtss/services/completition/CompetitionPracticalService.java index e8e2583f6..bc7a41962 100644 --- a/src/main/java/club/joylink/rtss/services/completition/CompetitionPracticalService.java +++ b/src/main/java/club/joylink/rtss/services/completition/CompetitionPracticalService.java @@ -3,12 +3,15 @@ package club.joylink.rtss.services.completition; import club.joylink.rtss.constants.*; import club.joylink.rtss.dao.CompetitionDAO; import club.joylink.rtss.dao.CompetitionRecordDAO; +import club.joylink.rtss.dao.CompetitionVoiceRecordDAO; import club.joylink.rtss.entity.*; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.services.*; import club.joylink.rtss.services.script.IScriptService; import club.joylink.rtss.services.script.IScriptSimulationService; import club.joylink.rtss.services.simulation.ProjectSimulationService; +import club.joylink.rtss.services.voice.IVoiceTrainingService; +import club.joylink.rtss.services.voice.baidu.ConnUtil; import club.joylink.rtss.simulation.cbtc.ATS.ATSMessageCollectAndDispatcher; import club.joylink.rtss.simulation.cbtc.GroupSimulationCache; import club.joylink.rtss.simulation.cbtc.GroupSimulationService; @@ -37,10 +40,21 @@ import club.joylink.rtss.vo.client.userPermission.UserPermissionVO; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import lombok.extern.slf4j.Slf4j; +import org.apache.http.client.methods.HttpPost; +import org.apache.tomcat.jni.OS; +import org.apache.tomcat.util.http.fileupload.FileItem; +import org.apache.tomcat.util.http.fileupload.FileItemFactory; +import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import org.springframework.web.multipart.MultipartFile; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.*; import java.time.LocalDateTime; import java.util.List; import java.util.Map; @@ -95,6 +109,12 @@ public class CompetitionPracticalService implements ICompetitionPracticalService @Autowired private IMapService iMapService; + @Autowired + private CompetitionVoiceRecordDAO competitionVoiceRecordDAO; + + @Autowired + private IVoiceTrainingService iVoiceTrainingService; + @Override public PageVO pagedQueryCompetition(CompetitionPagedQueryVO queryVO) { PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); @@ -451,6 +471,73 @@ public class CompetitionPracticalService implements ICompetitionPracticalService return iOrderService.pay(order.getId(), null, "调度大赛权限"); } + @Override + public CompetitionVoiceRecord voiceRecord(Long competitionId, String actionId, MultipartFile file, UserVO user) { + String filePath = IVoiceService.handleAndSaveFile(file); + CompetitionVoiceRecord voiceRecord = new CompetitionVoiceRecord(); + voiceRecord.setUserId(user.getId()); + voiceRecord.setCompetitionId(competitionId); + voiceRecord.setActionId(actionId); + voiceRecord.setFilepath(filePath); + competitionVoiceRecordDAO.insert(voiceRecord); + return voiceRecord; + } + + @Override + public CompetitionVoiceRecord updateVoiceRecord(Long recordId, MultipartFile file, UserVO user) { + CompetitionVoiceRecord record = getVoiceRecordEntity(recordId); + BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertEquals(record.getUserId(), user.getId()); + String filePath = IVoiceService.handleAndSaveFile(file); + record.setFilepath(filePath); + competitionVoiceRecordDAO.updateByPrimaryKey(record); + return record; + } + + @Override + public VoiceErrorSetVO voiceRecordCheck(Long recordId) { + return new VoiceErrorSetVO(); +// CompetitionVoiceRecord record = getVoiceRecordEntity(recordId); +// String totalFilePath = "https://oss.joylink.club/oss/joylink" + record.getFilepath(); +// File file = new File(totalFilePath); +//// FileInputStream fileInputStream = new FileInputStream(file); +// FileItemFactory factory = new DiskFileItemFactory(16, null); +// FileItem item = factory.createItem(file.getName(), "text/plain", true, file.getName()); +//// MultipartFile multipartFile = new CommonsMultipartFile(item); +// MultipartFile multipartFile = null; +// return null; + } + + public static void main(String[] args) { + try { + HttpURLConnection conn = (HttpURLConnection) new URL("https://oss.joylink.club/oss/joylink/AUDIO/2021-04-30/2036-47816.wav").openConnection(); + conn.setConnectTimeout(10000); + conn.setRequestMethod("GET"); + conn.setRequestProperty("Content-Type", "application/json; charset=utf-8"); + conn.setDoOutput(true); + conn.setDoInput(true); + OutputStream os = conn.getOutputStream(); + File file = new File("C:\\Users\\wangxj\\Desktop\\voice.wav"); + } catch (Exception e) { + e.printStackTrace(); + } finally { + + } + + } + + @Override + public List queryVoiceRecords(Long userId, Long competitionId) { + CompetitionVoiceRecordExample example = new CompetitionVoiceRecordExample(); + example.createCriteria().andUserIdEqualTo(userId).andCompetitionIdEqualTo(competitionId); + return competitionVoiceRecordDAO.selectByExample(example); + } + + private CompetitionVoiceRecord getVoiceRecordEntity(Long id) { + CompetitionVoiceRecord record = competitionVoiceRecordDAO.selectByPrimaryKey(id); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(record, String.format("id为[%s]的记录不存在", id)); + return record; + } + /** * 保存结果 */ diff --git a/src/main/java/club/joylink/rtss/services/completition/ICompetitionPracticalService.java b/src/main/java/club/joylink/rtss/services/completition/ICompetitionPracticalService.java index cd8108da2..9c4370a0a 100644 --- a/src/main/java/club/joylink/rtss/services/completition/ICompetitionPracticalService.java +++ b/src/main/java/club/joylink/rtss/services/completition/ICompetitionPracticalService.java @@ -1,16 +1,15 @@ package club.joylink.rtss.services.completition; +import club.joylink.rtss.entity.CompetitionVoiceRecord; import club.joylink.rtss.entity.CompetitionWithBLOBs; import club.joylink.rtss.simulation.cbtc.script.ScriptBO; import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.client.PageVO; -import club.joylink.rtss.vo.client.competition.CompetitionPagedQueryVO; -import club.joylink.rtss.vo.client.competition.CompetitionResult; -import club.joylink.rtss.vo.client.competition.CompetitionVO; -import club.joylink.rtss.vo.client.competition.OperationStatisticVO; +import club.joylink.rtss.vo.client.competition.*; import club.joylink.rtss.vo.client.pay.WxPayUnifiedOrderResultVO; import club.joylink.rtss.vo.client.userPermission.UserPermissionVO; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -123,4 +122,12 @@ public interface ICompetitionPracticalService { * @return */ WxPayUnifiedOrderResultVO purchasePermission(Long mapId, Integer amount, UserVO user); + + CompetitionVoiceRecord voiceRecord(Long competitionId, String actionId, MultipartFile file, UserVO user); + + CompetitionVoiceRecord updateVoiceRecord(Long recordId, MultipartFile file, UserVO user); + + VoiceErrorSetVO voiceRecordCheck(Long recordId); + + List queryVoiceRecords(Long userId, Long competitionId); } diff --git a/src/main/java/club/joylink/rtss/services/voice/IVoiceTrainingService.java b/src/main/java/club/joylink/rtss/services/voice/IVoiceTrainingService.java new file mode 100644 index 000000000..d84a3ca95 --- /dev/null +++ b/src/main/java/club/joylink/rtss/services/voice/IVoiceTrainingService.java @@ -0,0 +1,17 @@ +package club.joylink.rtss.services.voice; + +import club.joylink.rtss.vo.client.PageQueryVO; +import club.joylink.rtss.vo.client.PageVO; +import club.joylink.rtss.vo.client.VoiceRecognitionResult; +import club.joylink.rtss.vo.client.competition.VoiceErrorSetVO; +import org.springframework.web.multipart.MultipartFile; + +/** + * 语音训练 + */ +public interface IVoiceTrainingService { + + PageVO pagedQueryErrorSet(PageQueryVO queryVO); + + VoiceRecognitionResult voiceRecognition(MultipartFile file); +} diff --git a/src/main/java/club/joylink/rtss/services/voice/VoiceTrainingService.java b/src/main/java/club/joylink/rtss/services/voice/VoiceTrainingService.java new file mode 100644 index 000000000..6da9c5034 --- /dev/null +++ b/src/main/java/club/joylink/rtss/services/voice/VoiceTrainingService.java @@ -0,0 +1,49 @@ +package club.joylink.rtss.services.voice; + +import club.joylink.rtss.dao.CompetitionErrorSetDAO; +import club.joylink.rtss.entity.CompetitionErrorSet; +import club.joylink.rtss.services.IVoiceService; +import club.joylink.rtss.simulation.cbtc.conversation.SimulationVoiceHandler; +import club.joylink.rtss.vo.client.PageQueryVO; +import club.joylink.rtss.vo.client.PageVO; +import club.joylink.rtss.vo.client.VoiceRecognitionResult; +import club.joylink.rtss.vo.client.competition.VoiceErrorSetVO; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class VoiceTrainingService implements IVoiceTrainingService { + + @Autowired + private CompetitionErrorSetDAO competitionErrorSetDAO; + + @Autowired + @Qualifier("HuaWeiVoiceService") + private IVoiceService iVoiceService; + + @Autowired + private SimulationVoiceHandler simulationVoiceHandler; + + + @Override + public PageVO pagedQueryErrorSet(PageQueryVO queryVO) { + Page page = PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); + List sets = competitionErrorSetDAO.selectByExample(null); + List list = sets.stream().map(VoiceErrorSetVO::new).collect(Collectors.toList()); + return PageVO.convert(page, list); + } + + @Override + public VoiceRecognitionResult voiceRecognition(MultipartFile file) { + VoiceRecognitionResult result = this.iVoiceService.voiceRecognition(file, ""); + result.setResult(simulationVoiceHandler.handle(result.getResult())); + return result; + } +} diff --git a/src/main/java/club/joylink/rtss/services/voice/huawei/HuaweiVoiceServiceImpl.java b/src/main/java/club/joylink/rtss/services/voice/huawei/HuaweiVoiceServiceImpl.java index 492d9c404..d1ad209a6 100644 --- a/src/main/java/club/joylink/rtss/services/voice/huawei/HuaweiVoiceServiceImpl.java +++ b/src/main/java/club/joylink/rtss/services/voice/huawei/HuaweiVoiceServiceImpl.java @@ -36,12 +36,7 @@ public class HuaweiVoiceServiceImpl implements IVoiceService { @Override public VoiceRecognitionResult voiceRecognition(MultipartFile file, String lang) { - String filePath; - try { - filePath = IVoiceService.handleAndSaveFile(file); - } catch (IOException e) { - throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("语音文件上传失败", e); - } + String filePath = IVoiceService.handleAndSaveFile(file); AuthInfo authInfo = new AuthInfo(ak, sk, region, projectId); SisConfig sisConfig = new SisConfig(); AsrCustomizationClient client = new AsrCustomizationClient(authInfo, sisConfig); diff --git a/src/main/java/club/joylink/rtss/vo/client/competition/CompetitionVoiceRecordCheckVO.java b/src/main/java/club/joylink/rtss/vo/client/competition/CompetitionVoiceRecordCheckVO.java new file mode 100644 index 000000000..2438dd182 --- /dev/null +++ b/src/main/java/club/joylink/rtss/vo/client/competition/CompetitionVoiceRecordCheckVO.java @@ -0,0 +1,19 @@ +package club.joylink.rtss.vo.client.competition; + +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +@Getter +@Setter +public class CompetitionVoiceRecordCheckVO { + private Long competitionId; + + private Long actionId; + + + private List keyWords; + + +} diff --git a/src/main/java/club/joylink/rtss/vo/client/competition/VoiceErrorSetVO.java b/src/main/java/club/joylink/rtss/vo/client/competition/VoiceErrorSetVO.java new file mode 100644 index 000000000..de301d5cb --- /dev/null +++ b/src/main/java/club/joylink/rtss/vo/client/competition/VoiceErrorSetVO.java @@ -0,0 +1,46 @@ +package club.joylink.rtss.vo.client.competition; + +import club.joylink.rtss.entity.CompetitionErrorSet; +import club.joylink.rtss.util.JsonUtils; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.springframework.util.StringUtils; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@NoArgsConstructor +public class VoiceErrorSetVO { + private Long id; + + private Long competitionId; + + private Long userId; + + private String actionId; + + private String right = "道岔试验"; + + private String wrong = "刀叉试验"; + + private List keyWords = List.of("道岔"); + + private List tripNumbers = List.of("2027"); + + private String filePath; + + public VoiceErrorSetVO(CompetitionErrorSet set) { + this.id = set.getId(); + this.competitionId = set.getId(); + this.userId = set.getUserId(); + this.actionId = set.getActionId(); + this.right = set.getRight(); + this.wrong = set.getWrong(); + if (StringUtils.hasText(set.getKeyWords())) + this.keyWords = JsonUtils.readCollection(set.getKeyWords(), ArrayList.class, String.class); + if (StringUtils.hasText(set.getTripNumber())) + this.tripNumbers = JsonUtils.readCollection(set.getTripNumber(), ArrayList.class, String.class); + this.filePath = set.getFilePath(); + } +} diff --git a/src/main/resources/mybatis/mapper/CompetitionVoiceRecordDAO.xml b/src/main/resources/mybatis/mapper/CompetitionVoiceRecordDAO.xml new file mode 100644 index 000000000..df76ff810 --- /dev/null +++ b/src/main/resources/mybatis/mapper/CompetitionVoiceRecordDAO.xml @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + 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, user_id, competition_id, action_id, filePath + + + + + delete from competition_voice_record + where id = #{id,jdbcType=BIGINT} + + + delete from competition_voice_record + + + + + + insert into competition_voice_record (user_id, competition_id, action_id, + filePath) + values (#{userId,jdbcType=BIGINT}, #{competitionId,jdbcType=BIGINT}, #{actionId,jdbcType=VARCHAR}, + #{filepath,jdbcType=VARCHAR}) + + + insert into competition_voice_record + + + user_id, + + + competition_id, + + + action_id, + + + filePath, + + + + + #{userId,jdbcType=BIGINT}, + + + #{competitionId,jdbcType=BIGINT}, + + + #{actionId,jdbcType=VARCHAR}, + + + #{filepath,jdbcType=VARCHAR}, + + + + + + update competition_voice_record + + + id = #{record.id,jdbcType=BIGINT}, + + + user_id = #{record.userId,jdbcType=BIGINT}, + + + competition_id = #{record.competitionId,jdbcType=BIGINT}, + + + action_id = #{record.actionId,jdbcType=VARCHAR}, + + + filePath = #{record.filepath,jdbcType=VARCHAR}, + + + + + + + + update competition_voice_record + set id = #{record.id,jdbcType=BIGINT}, + user_id = #{record.userId,jdbcType=BIGINT}, + competition_id = #{record.competitionId,jdbcType=BIGINT}, + action_id = #{record.actionId,jdbcType=VARCHAR}, + filePath = #{record.filepath,jdbcType=VARCHAR} + + + + + + update competition_voice_record + + + user_id = #{userId,jdbcType=BIGINT}, + + + competition_id = #{competitionId,jdbcType=BIGINT}, + + + action_id = #{actionId,jdbcType=VARCHAR}, + + + filePath = #{filepath,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=BIGINT} + + + update competition_voice_record + set user_id = #{userId,jdbcType=BIGINT}, + competition_id = #{competitionId,jdbcType=BIGINT}, + action_id = #{actionId,jdbcType=VARCHAR}, + filePath = #{filepath,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} + + \ No newline at end of file