Merge branch 'test'

This commit is contained in:
tiger_zhou 2024-03-12 10:36:14 +08:00
commit bf87b46662
17 changed files with 2209 additions and 1093 deletions

@ -1 +1 @@
Subproject commit 2aedc24640de82379bc4ebb48e428fd57cfc5e77
Subproject commit 5dd7fdb3d568c829356fa59b746b559d17da49b8

View File

@ -6,6 +6,7 @@ import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.race.RaceSceneOuterClass.RaceSceneListVO;
import club.joylink.rtss.vo.race.RaceSceneOuterClass.RaceScenePublishVO;
import club.joylink.rtss.vo.race.RaceSceneOuterClass.RaceSceneVO;
import club.joylink.rtss.vo.race.RaceSceneOuterClass.SceneCustomCreateVO;
import club.joylink.rtss.vo.race.RaceSceneQueryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
@ -27,6 +28,16 @@ public class RaceSceneController {
@Autowired
private RaceSceneService sceneService;
@PostMapping("/custom/edit")
public void customSave(@RequestBody SceneCustomCreateVO vo, @RequestAttribute AccountVO user) {
this.sceneService.customSave(vo, user);
}
@PostMapping("/custom/{id}/edit")
public void customUpdate(@PathVariable("id") Long id, @RequestBody SceneCustomCreateVO vo, @RequestAttribute AccountVO user) {
this.sceneService.customUpdate(id, vo, user);
}
/**
* 草稿实训发布到场景
*

View File

@ -29,7 +29,7 @@ public interface RacetrSceneDAO extends MyBatisBaseDao<RacetrScene, Long, Racetr
+ " and A.name like CONCAT('%',#{vo.name},'%') "
+ "</if> "
+ "<if test='vo.type!= null and vo.type!= \"\"'> "
+ " and A.type = ${vo.type}"
+ " and A.type = #{vo.type}"
+ "</if> "
+ "</script>")
List<RaceScenePageVO> pages(@Param("vo") RaceSceneQueryVO vo);

View File

@ -17,7 +17,7 @@ import org.springframework.stereotype.Repository;
public interface RacetrTaskDAO extends MyBatisBaseDao<RacetrTask, Long, RacetrTaskExample> {
@Select("<script>"
+ "select A.id,A.name,A.desc,A.content,A.standards,A.scene_id,B.name as sceneName, "
+ "select A.id,A.name,A.desc,A.content,A.standards,B.id as scene_id,B.name as sceneName, "
+ "A.score_rule_id as rule_id,C.name as ruleName,A.parent_id,"
+ "A.creator_id,A.create_time,A.updater_id,A.update_time,D.nickname as creatorName,E.nickname as updaterName "
+ " from racetr_task A left join racetr_scene B on A.scene_id = B.id "

View File

@ -256,7 +256,9 @@ public class MapService implements IMapService, ApplicationRunner {
@Override
public MapVO getMapDetail(Long id) {
Objects.requireNonNull(id, "id不能为空");
if (id < 0) return null;
if (id < 0) {
return null;
}
MapVO mapVO = (MapVO) this.iCacheService.get(BusinessConsts.CachePrefix.Map + id);
if (Objects.isNull(mapVO)) { // 缓存不存在查询数据库
synchronized (this) {
@ -437,8 +439,9 @@ public class MapService implements IMapService, ApplicationRunner {
/**
* 创建地图信息
*
* <p>
* 所有参数的正确性需调用方保证这里不做任何校验
*
* @return 创建的实体
*/
private MapInfo createMapInfo(String name, String cityCode, String lineCode) {

View File

@ -277,6 +277,7 @@ public class RacePaperService {
RaceTaskChildVO.Builder childVOB = RaceTaskChildVO.newBuilder();
childVOB.setName(group.getName());
childVOB.setNodeType(ChildNodeType.MODULE_GROUP);
for (Long taskId : group.getTaskIdsList()) {
RaceTaskChildVO taskVO = this.findTask(taskId, allTaskMapList);
childVOB.addChildren(taskVO);
@ -333,16 +334,16 @@ public class RacePaperService {
cb.setContent(dto.getContent());
cb.setStandards(dto.getStandards());
cb.setParentId(dto.getParentId());
}
if (Objects.nonNull(dto.getRuleId())) {
cb.setRuleId(dto.getRuleId());
}
if (StringUtils.isNotEmpty(dto.getSceneType())) {
cb.setSceneType(Type.valueOf(dto.getSceneType()));
}
if (Objects.nonNull(dto.getSceneId())) {
cb.setSceneId(dto.getSceneId());
}
if (Objects.nonNull(dto.getRuleId())) {
cb.setRuleId(dto.getRuleId());
}
}
cb.setNodeType(nodeType);
cb.setName(dto.getName());

View File

@ -10,22 +10,26 @@ import club.joylink.rtss.entity.training2.DraftTraining2WithBLOBs;
import club.joylink.rtss.exception.BusinessExceptionAssert;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.exception.RacetrExceptionAssert;
import club.joylink.rtss.services.MinioService;
import club.joylink.rtss.simulation.cbtc.training2.Training2;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.common.ModifyInfo.ModifyInfoVO;
import club.joylink.rtss.vo.race.RaceSceneOuterClass.RaceScene;
import club.joylink.rtss.vo.race.RaceSceneOuterClass.RaceScene.Type;
import club.joylink.rtss.vo.race.RaceSceneOuterClass.RaceSceneListVO;
import club.joylink.rtss.vo.race.RaceSceneOuterClass.RaceScenePublishVO;
import club.joylink.rtss.vo.race.RaceSceneOuterClass.RaceSceneVO;
import club.joylink.rtss.vo.race.RaceSceneOuterClass.Scene;
import club.joylink.rtss.vo.race.RaceSceneOuterClass.SceneCustomCreateVO;
import club.joylink.rtss.vo.race.RaceSceneOuterClass.StorageSimulation;
import club.joylink.rtss.vo.race.RaceScenePageVO;
import club.joylink.rtss.vo.race.RaceSceneQueryVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import com.google.protobuf.InvalidProtocolBufferException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
@ -33,10 +37,12 @@ import java.util.List;
import java.util.Objects;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestAttribute;
@Service
@Slf4j
@ -48,7 +54,8 @@ public class RaceSceneService {
private RacetrTaskDAO taskDAO;
@Autowired
private DraftTraining2DAO trainingDao;
@Autowired
private MinioService minioService;
public RacetrScene findById(Long id) {
RacetrScene rs = this.sceneDAO.selectByPrimaryKey(id);
@ -56,6 +63,47 @@ public class RaceSceneService {
return rs;
}
public void customSave(SceneCustomCreateVO vo, AccountVO user) {
LocalDateTime now = LocalDateTime.now();
RacetrScene rs = new RacetrScene();
rs.setName(vo.getName());
rs.setType(vo.getType().name());
rs.setProto(vo.getScene().toByteArray());
rs.setCreatorId(user.getId());
rs.setUpdaterId(user.getId());
rs.setCreateTime(now);
rs.setUpdateTime(now);
this.sceneDAO.insert(rs);
}
public void customUpdate(Long id, SceneCustomCreateVO vo, AccountVO user) {
RacetrScene rs = this.findById(id);
this.removeObj(rs);
rs.setName(vo.getName());
rs.setType(vo.getType().name());
rs.setProto(vo.getScene().toByteArray());
rs.setUpdaterId(user.getId());
rs.setUpdateTime(LocalDateTime.now());
this.sceneDAO.updateByPrimaryKeySelective(rs);
}
private void removeObj(RacetrScene rs) {
byte[] protoData = rs.getProto();
if (ArrayUtils.isEmpty(protoData)) {
log.error("自定义删除场景附件proto数据不能为空 id:[{}]", rs.getId());
return;
}
try {
if (!Objects.equals(rs.getType(), Type.Video.name())) {
return;
}
Scene sceneProto = Scene.parseFrom(protoData);
this.minioService.removeMinioObject(rs.getType(), sceneProto.getFileName());
} catch (Exception e) {
log.error("场景附件处理失败 id:[{}] msg:[{}]", rs.getId(), e.getMessage(), e);
}
}
public PageVO<RaceSceneListVO> page(RaceSceneQueryVO query) {
PageHelper.startPage(query.getPageNum(), query.getPageSize());
Page<RaceScenePageVO> page = (Page<RaceScenePageVO>) this.sceneDAO.pages(query);
@ -70,8 +118,10 @@ public class RaceSceneService {
ModifyInfoVO modifyInfoVO = RaceServiceUtil.createModifyInfo(rs.getCreatorId(), rs.getCreatorName(), rs.getUpdaterId(), rs.getUpdaterName(), rs.getCreateTime(), rs.getUpdateTime());
vo.setModifyInfo(modifyInfoVO);
vo.setType(Type.valueOf(rs.getType()));
if (Objects.nonNull(rs.getMapId())) {
vo.setMapId(rs.getMapId());
vo.setMapName(rs.getMapName());
}
return vo.build();
}
@ -89,10 +139,13 @@ public class RaceSceneService {
}
public void delete(Long id) {
RacetrTaskExample taskExample = new RacetrTaskExample();
taskExample.createCriteria().andSceneIdEqualTo(id);
long bindTaskCount = this.taskDAO.countByExample(taskExample);
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(bindTaskCount <= 0, "此场景已被任务绑定不能删除");
RacetrScene rs = this.findById(id);
this.removeObj(rs);
this.sceneDAO.deleteByPrimaryKey(id);
}

View File

@ -972,6 +972,8 @@ public class Training2Service {
if (!simulation.getTraining2().isJumpStep(step) && !step.getSimulationMember().isRobot()) {
applicationContext.publishEvent(
new SimulationTrainingAudioEvent(this, simulation, step, simOperation2, doCompletion));
/*
取消 发送请重试语音
if (!doCompletion) {
Operation.Type operationType;
HashMap<String, Object> params = new HashMap<>(event.getParams());
@ -997,7 +999,7 @@ public class Training2Service {
params.put("content", compose.getMessage());
atsOperationDispatcher.execute(simulation, member, operationType.name(), params);
}
}
}*/
}
}

View File

@ -28,55 +28,59 @@ public class VoiceService {
@Qualifier(value = "baiDuVoiceService2")
private IVoiceService2 voiceService;
public VoiceService(MinioClientConfig minioClientConfig){
this.voiceSynthesisUtil = MinioClientUtil.getInstance(minioClientConfig,SYNTHESIS_FOLDER);
this.voiceRecognitionUtil = MinioClientUtil.getInstance(minioClientConfig,RECOGNITION_FOLDER);
public VoiceService(MinioClientConfig minioClientConfig) {
this.voiceSynthesisUtil = MinioClientUtil.getInstance(minioClientConfig, SYNTHESIS_FOLDER);
this.voiceRecognitionUtil = MinioClientUtil.getInstance(minioClientConfig, RECOGNITION_FOLDER);
}
/**
* 语音识别
*
* @param vo
* @return
*/
public VoiceRecognitionResult voiceRecognition(VoiceRecognitionVO vo){
String fileName = String.format("%s.wav",System.currentTimeMillis());
this.uploadFile(voiceRecognitionUtil,vo.getData(),fileName,RECOGNITION_FOLDER);
public VoiceRecognitionResult voiceRecognition(VoiceRecognitionVO vo) {
String fileName = String.format("%s.wav", System.currentTimeMillis());
this.uploadFile(voiceRecognitionUtil, vo.getData(), fileName, RECOGNITION_FOLDER);
String filePath = this.voiceRecognitionUtil.getDownLoadPath(fileName);
VoiceAsrResult voiceResult = voiceService.recognition(vo);
return new VoiceRecognitionResult(filePath,voiceResult.getResult().get(0));
return new VoiceRecognitionResult(filePath, voiceResult.getResult().get(0));
}
/**
* 语音合成
*
* @param vo
* @return
*/
public VoiceCompose synthesis(BaseVoiceSynthesisVO vo){
public VoiceCompose synthesis(BaseVoiceSynthesisVO vo) {
String md5Code = vo.md5Code();
String fileName = String.format("%s.wav",md5Code);
if(Objects.equals(false,this.voiceSynthesisUtil.checkFileIsExist(fileName))){
byte[] data = voiceService.voiceSynthesis(vo);
this.uploadFile(voiceSynthesisUtil,data,fileName,SYNTHESIS_FOLDER);
String fileName = String.format("%s.wav", md5Code);
if (Objects.equals(false, this.voiceSynthesisUtil.checkFileIsExist(fileName))) {
byte[] bytes = voiceService.voiceSynthesis(vo);
byte[] data = bytes;
this.uploadFile(voiceSynthesisUtil, data, fileName, SYNTHESIS_FOLDER);
}
String filePath = this.voiceSynthesisUtil.getDownLoadPath(fileName);
return new VoiceCompose(filePath,md5Code,vo.getMessage());
return new VoiceCompose(filePath, md5Code, vo.getMessage());
}
/**
* 语音合成返回原数据
*
* @param vo
* @return
*/
public byte[] synthesisSource(BaseVoiceSynthesisVO vo){
public byte[] synthesisSource(BaseVoiceSynthesisVO vo) {
byte[] data = voiceService.voiceSynthesis(vo);
return data;
}
private void uploadFile(MinioClientUtil minioClient ,byte[] data,String fileName,String folder){
try{
minioClient.uploadBytes(data,fileName);
}catch (SimulationException e){
log.error("文件上传失败 folder:{},文件名:{} errmsg:{}",folder,fileName,e.getMessage(),e);
private void uploadFile(MinioClientUtil minioClient, byte[] data, String fileName, String folder) {
try {
minioClient.uploadBytes(data, fileName);
} catch (SimulationException e) {
log.error("文件上传失败 folder:{},文件名:{} errmsg:{}", folder, fileName, e.getMessage(), e);
throw e;
}
}

View File

@ -18,7 +18,7 @@ public class SimulationVoiceHandler {
static Map<String, String> regexReplaceMap = new HashMap<>();
// static {
// static {
// regexReplaceMap.put("", "1");
// }
static List<Replacement> numReplacementList;
@ -147,6 +147,7 @@ public class SimulationVoiceHandler {
* 匹配替换对象
*/
public static class Replacement {
String match;
String replace;
@ -163,12 +164,13 @@ public class SimulationVoiceHandler {
}
}
public String numHandle(String content){
public String numHandle(String content) {
for (Replacement replacement : numReplacementList) {
content = replacement.matchAndReplace(content);
}
return regexReplace(content);
}
/**
* 对语音识别内容进行仿真用词处理
*
@ -183,7 +185,7 @@ public class SimulationVoiceHandler {
}
private String regexReplace(String s) {
log.info("正则替换");
log.info("正则替换 字符[{}]", s);
//编号替换
Pattern pattern = Pattern.compile("([一二三四五六七八九十]+)(号)");
Matcher matcher = pattern.matcher(s);

View File

@ -7,6 +7,9 @@ import club.joylink.rtss.simulation.cbtc.training2.Step2;
import club.joylink.rtss.simulation.cbtc.training2.Training2;
import lombok.Getter;
/**
* 发送实训当前阶段完成情况
*/
@Getter
public class SimulationTrainingAudioEvent extends AbstractSimulationEvent {
@ -14,9 +17,12 @@ public class SimulationTrainingAudioEvent extends AbstractSimulationEvent {
private Operation2.SimCommand2 operation2;
/**
* 结果是否匹配
*/
private boolean matchResult;
public SimulationTrainingAudioEvent(Object source, Simulation simulation,Step2 step, Operation2.SimCommand2 operation2, boolean matchResult) {
public SimulationTrainingAudioEvent(Object source, Simulation simulation, Step2 step, Operation2.SimCommand2 operation2, boolean matchResult) {
super(source, simulation);
this.step = step;
this.operation2 = operation2;

View File

@ -8,5 +8,5 @@ import lombok.Data;
public class RaceSceneQueryVO extends PageQueryVO {
private String name;
private Type type;
private String type;
}

View File

@ -106,11 +106,11 @@ logging:
club.joylink.rtss: DEBUG
minio:
endpoint: http://192.168.3.233
endpoint: http://192.168.33.233
accessKey: jladmin
secretKey: Joylink@0503
bucket: oss-rtss
replaceHttps: true
replaceHttps: false
common:
env: dev
@ -167,11 +167,11 @@ logging:
club.joylink.rtss: INFO
minio:
endpoint: http://192.168.3.233
endpoint: http://192.168.33.233
accessKey: jladmin
secretKey: Joylink@0503
bucket: oss-rtss
replaceHttps: true
replaceHttps: false
common:

View File

@ -330,6 +330,6 @@
</foreach>
UNION all
select A.id,A.name,A.desc,A.content,A.standards,A.scene_id,A.score_rule_id as ruleId,A.parent_id from racetr_task A, task B where A.parent_id = B.id)
select A.*,B.type as sceneType from task A left join racetr_scene B on A.scene_id = B.id
select A.id,A.name,A.desc,A.content,A.standards,A.ruleId ,A.parent_id,B.id as scene_id,B.type as sceneType from task A left join racetr_scene B on A.scene_id = B.id
</select>
</mapper>

View File

@ -2,6 +2,7 @@ package club.joylink.rtss.services.race;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.race.RaceSceneOuterClass.RaceScene.Type;
import club.joylink.rtss.vo.race.RaceSceneOuterClass.RaceSceneListVO;
import club.joylink.rtss.vo.race.RaceSceneOuterClass.RaceScenePublishVO;
import club.joylink.rtss.vo.race.RaceSceneOuterClass.RaceSceneVO;
@ -29,6 +30,7 @@ public class SceneServiceTest {
RaceSceneQueryVO query = new RaceSceneQueryVO();
query.setPageNum(1);
query.setPageSize(10);
query.setType(Type.Video.name());
PageVO<RaceSceneListVO> page = this.sceneService.page(query);
System.out.println(JsonUtils.writeValueAsString(page));
@ -36,7 +38,7 @@ public class SceneServiceTest {
@Test
public void detailTest() {
RaceSceneVO vo = this.sceneService.detail(2L);
RaceSceneVO vo = this.sceneService.detail(5L);
System.out.println(JsonUtils.writeValueAsString(vo));
}
}

View File

@ -66,7 +66,7 @@ public class TaskServiceTest {
@Test
public void detailTest() {
RaceTaskDetailVO vo = this.taskService.detail(1L);
RaceTaskDetailVO vo = this.taskService.detail(44L);
System.out.println(JsonUtils.writeValueAsString(vo));
}