diff --git a/pom.xml b/pom.xml
index f79c30e01..4625083e1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -98,11 +98,6 @@
-
- org.springframework
- spring-test
- 5.2.2.RELEASE
-
diff --git a/src/main/java/club/joylink/rtss/dao/IscsDAO.java b/src/main/java/club/joylink/rtss/dao/IscsDAO.java
index d85878ac8..c725273c0 100644
--- a/src/main/java/club/joylink/rtss/dao/IscsDAO.java
+++ b/src/main/java/club/joylink/rtss/dao/IscsDAO.java
@@ -2,6 +2,7 @@ package club.joylink.rtss.dao;
import club.joylink.rtss.entity.Iscs;
import club.joylink.rtss.entity.IscsExample;
+import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@@ -36,4 +37,15 @@ public interface IscsDAO {
int updateByPrimaryKeyWithBLOBs(Iscs record);
int updateByPrimaryKey(Iscs record);
-}
\ No newline at end of file
+
+ @Insert(value = "")
+ void batchInsertWithId(@Param("list") List iscsList);
+}
diff --git a/src/main/java/club/joylink/rtss/dao/OperatePlaceholderDAO.java b/src/main/java/club/joylink/rtss/dao/OperatePlaceholderDAO.java
index 768b1050c..aef901872 100644
--- a/src/main/java/club/joylink/rtss/dao/OperatePlaceholderDAO.java
+++ b/src/main/java/club/joylink/rtss/dao/OperatePlaceholderDAO.java
@@ -2,11 +2,25 @@ package club.joylink.rtss.dao;
import club.joylink.rtss.entity.OperatePlaceholder;
import club.joylink.rtss.entity.OperatePlaceholderExample;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
+import java.util.List;
+
/**
* OperatePlaceholderDAO继承基类
*/
@Repository
public interface OperatePlaceholderDAO extends MyBatisBaseDao {
-}
\ No newline at end of file
+
+ @Insert(value = "")
+ void batchInsertWithId(@Param("list") List operatePlaceholderList);
+}
diff --git a/src/main/java/club/joylink/rtss/services/IVoiceService.java b/src/main/java/club/joylink/rtss/services/IVoiceService.java
index 260f03578..853535e6e 100644
--- a/src/main/java/club/joylink/rtss/services/IVoiceService.java
+++ b/src/main/java/club/joylink/rtss/services/IVoiceService.java
@@ -44,18 +44,34 @@ public interface IVoiceService {
* @return
* @throws IOException
*/
- static VoiceFile saveFile(InputStream inputStream) throws IOException {
- String filePath = getFilePath();
+ static String saveFile(InputStream inputStream) throws IOException {
+ String localFilePath = getFilePath();
OutputStream os = null;
File saveFile = null;
try {
+ //创建本地文件
byte[] bs = new byte[4096];
int len;
- os = new FileOutputStream(filePath);
+ os = new FileOutputStream(localFilePath);
while ((len = inputStream.read(bs)) != -1) {
os.write(bs, 0, len);
}
- saveFile = new File(filePath);
+ saveFile = new File(localFilePath);
+ //上传文件
+ String url = "https://joylink.club/jlfile/api/upload/AUDIO?appId=00001&appSecret=joylink00001";
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.MULTIPART_FORM_DATA);
+ MultiValueMap map = new LinkedMultiValueMap<>();
+ map.add("file", new FileSystemResource(saveFile));
+ RestTemplate restTemplate = new RestTemplate();
+ ResponseEntity responseEntity = restTemplate.postForEntity(url, map, String.class);
+ String body = responseEntity.getBody();
+// body = body.replaceAll("\\\\", "/");
+ CommonJsonResponse response = JsonUtils.read(body, CommonJsonResponse.class);
+ BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertEquals(200, response.getCode());
+ return (String) response.getData();
+ } catch (Exception e) {
+ throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception(e);
} finally {
if (Objects.nonNull(inputStream)) {
inputStream.close();
@@ -63,8 +79,10 @@ public interface IVoiceService {
if (os != null) {
os.close();
}
+ if (saveFile != null) {
+ saveFile.delete();
+ }
}
- return new VoiceFile(filePath.replace(AudioFileBasePath, ""), saveFile);
}
static VoiceFile saveFile(MultipartFile multipartFile) {
@@ -72,11 +90,9 @@ public interface IVoiceService {
String url = "https://joylink.club/jlfile/api/upload/AUDIO?appId=00001&appSecret=joylink00001";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
- String fileName = multipartFile.getName();
- String prefix = fileName.substring(fileName.lastIndexOf("."));
File tempFile = null;
try {
- tempFile = File.createTempFile("fileName", prefix);
+ tempFile = File.createTempFile("fileName", ".wav");
multipartFile.transferTo(tempFile);
MultiValueMap map = new LinkedMultiValueMap<>();
map.add("file", new FileSystemResource(tempFile));
@@ -87,23 +103,22 @@ public interface IVoiceService {
CommonJsonResponse response = JsonUtils.read(body, CommonJsonResponse.class);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertEquals(200, response.getCode());
String path = (String) response.getData();
- File file = new File("https://joylink.club/oss/joylink" + path);
- return new VoiceFile(path, file);
- } catch (IOException e) {
- throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("创建文件报错");
+ return new VoiceFile(path, null);
+ } catch (Exception e) {
+ throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception(e);
} finally {
if (tempFile != null)
tempFile.delete();
}
}
- static VoiceFile handleAndSaveFile(MultipartFile file) throws IOException {
+ static String handleAndSaveFile(MultipartFile file) throws IOException {
String contentType = file.getContentType();
BusinessExceptionAssertEnum.UNSUPPORTED_FILE_FORMAT.assertTrue(
"audio/wave".equals(contentType) || "audio/wav".equals(contentType),
String.format("不支持的文件格式[%s]", contentType));
-// InputStream inputStream = file.getInputStream();
- return saveFile(file);
+ InputStream inputStream = file.getInputStream();
+ return saveFile(inputStream);
}
/**
diff --git a/src/main/java/club/joylink/rtss/services/local/LocalDataServiceImpl.java b/src/main/java/club/joylink/rtss/services/local/LocalDataServiceImpl.java
index 75fdbc61d..89eda8e63 100644
--- a/src/main/java/club/joylink/rtss/services/local/LocalDataServiceImpl.java
+++ b/src/main/java/club/joylink/rtss/services/local/LocalDataServiceImpl.java
@@ -88,6 +88,12 @@ public class LocalDataServiceImpl implements LocalDataService {
@Autowired
private TrainingDAO trainingDAO;
+ @Autowired
+ private IscsDAO iscsDAO;
+
+ @Autowired
+ private OperatePlaceholderDAO operatePlaceholderDAO;
+
@Override
public LocalDataVO exportLocalMapData(List mapIdList, UserVO user) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertCollectionNotEmpty(mapIdList, "没有指定需要导出的地图");
@@ -122,8 +128,9 @@ public class LocalDataServiceImpl implements LocalDataService {
localDataVO.setRealLineList(realLines);
// 地图数据
MapDataExample mapDataExample = new MapDataExample();
- mapDataExample.createCriteria()
- .andMapIdIn(mapIdList);
+ for (MapInfo mapInfo : mapInfos) {
+ mapDataExample.or().andMapIdEqualTo(mapInfo.getId()).andVersionEqualTo(mapInfo.getVersion());
+ }
List mapDatas = this.mapDataDAO.selectByExampleWithBLOBs(mapDataExample);
localDataVO.setMapDataList(mapDatas);
// 地图三维数据
@@ -252,6 +259,13 @@ public class LocalDataServiceImpl implements LocalDataService {
SysDictionaryDetailExample dicDetailExample = new SysDictionaryDetailExample();
List dicDetailList = this.sysDictionaryDetailMapper.selectByExample(dicDetailExample);
localDataVO.setDicDetailList(dicDetailList);
+ // iscs
+ IscsExample iscsExample = new IscsExample();
+ iscsExample.createCriteria().andLineCodeIn(lineCodeList);
+ localDataVO.setIscsList(iscsDAO.selectByExampleWithBLOBs(iscsExample));
+ // operate_placeholder
+ OperatePlaceholderExample operatePlaceholderExample = new OperatePlaceholderExample();
+ localDataVO.setOperatePlaceholderList(operatePlaceholderDAO.selectByExample(operatePlaceholderExample));
return localDataVO;
}
@@ -344,5 +358,13 @@ public class LocalDataServiceImpl implements LocalDataService {
if (!CollectionUtils.isEmpty(localDataVO.getDicDetailList())) {
this.sysDictionaryDetailMapper.batchInsertWithId(localDataVO.getDicDetailList());
}
+ // iscs
+ if (!CollectionUtils.isEmpty(localDataVO.getIscsList())) {
+ this.iscsDAO.batchInsertWithId(localDataVO.getIscsList());
+ }
+ // operate_placeholder
+ if (!CollectionUtils.isEmpty(localDataVO.getOperatePlaceholderList())) {
+ this.operatePlaceholderDAO.batchInsertWithId(localDataVO.getOperatePlaceholderList());
+ }
}
}
diff --git a/src/main/java/club/joylink/rtss/services/voice/baidu/AsrService.java b/src/main/java/club/joylink/rtss/services/voice/baidu/AsrService.java
index bcdab4723..381be55dc 100644
--- a/src/main/java/club/joylink/rtss/services/voice/baidu/AsrService.java
+++ b/src/main/java/club/joylink/rtss/services/voice/baidu/AsrService.java
@@ -6,6 +6,7 @@ import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;
@@ -71,6 +72,39 @@ public class AsrService {
return result;
}
+ public String runJsonPostMethod(InputStream is, String token) throws IOException {
+ byte[] content = getContent(is);
+ String speech = base64Encode(content);
+
+ Map params = new HashMap<>();
+ params.put("dev_pid", DEV_PID);
+ params.put("format", FORMAT);
+ params.put("rate", RATE);
+ params.put("token", token);
+ params.put("cuid", TokenHolder.APP_ID);
+ params.put("channel", "1");
+ params.put("len", content.length);
+ params.put("speech", speech);
+ String json = JsonUtils.writeValueAsString(params);
+
+ HttpURLConnection conn = (HttpURLConnection) new URL(ASR_URL).openConnection();
+ conn.setConnectTimeout(10000);
+ conn.setRequestMethod("POST");
+ conn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
+ conn.setDoOutput(true);
+ conn.getOutputStream().write(json.getBytes());
+ conn.getOutputStream().close();
+ String result = ConnUtil.getResponseString(conn);
+
+
+ params.put("speech", "base64Encode(getFileContent(FILENAME))");
+ System.out.println("url is : " + ASR_URL);
+ System.out.println("params is :" + params.toString());
+
+
+ return result;
+ }
+
private byte[] getFileContent(File file) throws IOException {
if (!file.canRead()) {
System.err.println("文件不存在或者不可读: " + file.getAbsolutePath());
@@ -92,6 +126,20 @@ public class AsrService {
}
+ private byte[] getContent(InputStream is) throws IOException {
+ try {
+ return ConnUtil.getInputStreamContent(is);
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
private String base64Encode(byte[] content) {
Base64.Encoder encoder = Base64.getEncoder(); // JDK 1.8 推荐方法
String str = encoder.encodeToString(content);
diff --git a/src/main/java/club/joylink/rtss/services/voice/baidu/VoiceServiceImpl.java b/src/main/java/club/joylink/rtss/services/voice/baidu/VoiceServiceImpl.java
index 671914098..ff6f30577 100644
--- a/src/main/java/club/joylink/rtss/services/voice/baidu/VoiceServiceImpl.java
+++ b/src/main/java/club/joylink/rtss/services/voice/baidu/VoiceServiceImpl.java
@@ -5,13 +5,11 @@ import club.joylink.rtss.services.IVoiceService;
import club.joylink.rtss.vo.client.VoiceRecognitionResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -31,14 +29,13 @@ public class VoiceServiceImpl implements IVoiceService {
@Override
public VoiceRecognitionResult voiceRecognition(MultipartFile multipartFile, String lang) {
try {
- VoiceFile voiceFile = IVoiceService.handleAndSaveFile(multipartFile);
- File file = voiceFile.getFile();
- String json = this.asrService.runJsonPostMethod(file, TokenHolder.getInstance().getToken());
+ String filePath = IVoiceService.handleAndSaveFile(multipartFile);
+ String json = this.asrService.runJsonPostMethod(multipartFile.getInputStream(), TokenHolder.getInstance().getToken());
log.info(String.format("百度语音识别结果:[%s]", json));
VoiceAsrResult result = VoiceAsrResult.fromJson(json);
- return new VoiceRecognitionResult(voiceFile.getPath(), result.getResult().get(0));
+ return new VoiceRecognitionResult(filePath, result.getResult().get(0));
} catch (Exception e) {
- throw BusinessExceptionAssertEnum.THIRD_SERVICE_CALL_EXCEPTION.exception();
+ throw BusinessExceptionAssertEnum.THIRD_SERVICE_CALL_EXCEPTION.exception(e);
}
}
@@ -47,9 +44,7 @@ public class VoiceServiceImpl implements IVoiceService {
try {
byte[] data = this.ttsService.run(message, per, TokenHolder.getInstance().getToken());
InputStream inputStream = new ByteArrayInputStream(data);
- MultipartFile file = new MockMultipartFile("语音文件.wav", inputStream);
- VoiceFile voiceFile = IVoiceService.saveFile(file);//生成的音频数据
- return voiceFile.getPath();
+ return IVoiceService.saveFile(inputStream);//生成的音频数据
} catch (IOException e) {
throw BusinessExceptionAssertEnum.THIRD_SERVICE_CALL_EXCEPTION.exception();
}
diff --git a/src/main/java/club/joylink/rtss/vo/client/local/LocalDataVO.java b/src/main/java/club/joylink/rtss/vo/client/local/LocalDataVO.java
index 1f68b8720..40522e3f4 100644
--- a/src/main/java/club/joylink/rtss/vo/client/local/LocalDataVO.java
+++ b/src/main/java/club/joylink/rtss/vo/client/local/LocalDataVO.java
@@ -61,4 +61,8 @@ public class LocalDataVO {
List dicDetailList;
+ List iscsList;
+
+ List operatePlaceholderList;
+
}