Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
commit
215a6bafd0
5
pom.xml
5
pom.xml
@ -98,11 +98,6 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>5.2.2.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
@Insert(value = "<script>" +
|
||||
"insert into iscs (id, line_code, station_code, total_system, `system`, user_interface, graph_data) " +
|
||||
" values " +
|
||||
" <foreach collection=\"list\" item=\"entity\" separator=\",\"> " +
|
||||
" (#{entity.id,jdbcType=INTEGER}, #{entity.lineCode,jdbcType=VARCHAR}, #{entity.stationCode,jdbcType=VARCHAR}," +
|
||||
" #{entity.totalSystem,jdbcType=VARCHAR}, " +
|
||||
" #{entity.system,jdbcType=VARCHAR}, #{entity.userInterface,jdbcType=VARCHAR}, #{entity.graphData,jdbcType=LONGVARCHAR})"+
|
||||
" </foreach>" +
|
||||
"</script>")
|
||||
void batchInsertWithId(@Param("list") List<Iscs> iscsList);
|
||||
}
|
||||
|
@ -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<OperatePlaceholder, Long, OperatePlaceholderExample> {
|
||||
}
|
||||
|
||||
@Insert(value = "<script>" +
|
||||
"insert into operate_placeholder (id, code, training_type, `type`, `name`, val, val_new) " +
|
||||
" values " +
|
||||
" <foreach collection=\"list\" item=\"entity\" separator=\",\"> " +
|
||||
" (#{entity.code,jdbcType=BIGINT}, #{entity.trainingType,jdbcType=VARCHAR}, #{entity.type,jdbcType=VARCHAR}, " +
|
||||
" #{entity.name,jdbcType=VARCHAR}, #{entity.val,jdbcType=VARCHAR}, #{entity.valNew,jdbcType=VARCHAR})"+
|
||||
" </foreach>" +
|
||||
"</script>")
|
||||
void batchInsertWithId(@Param("list") List<OperatePlaceholder> operatePlaceholderList);
|
||||
}
|
||||
|
@ -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<String, Object> map = new LinkedMultiValueMap<>();
|
||||
map.add("file", new FileSystemResource(saveFile));
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
ResponseEntity<String> 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<String, Object> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<Long> 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<MapDataWithBLOBs> mapDatas = this.mapDataDAO.selectByExampleWithBLOBs(mapDataExample);
|
||||
localDataVO.setMapDataList(mapDatas);
|
||||
// 地图三维数据
|
||||
@ -252,6 +259,13 @@ public class LocalDataServiceImpl implements LocalDataService {
|
||||
SysDictionaryDetailExample dicDetailExample = new SysDictionaryDetailExample();
|
||||
List<SysDictionaryDetail> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<String, Object> 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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -61,4 +61,8 @@ public class LocalDataVO {
|
||||
|
||||
List<SysDictionaryDetail> dicDetailList;
|
||||
|
||||
List<Iscs> iscsList;
|
||||
|
||||
List<OperatePlaceholder> operatePlaceholderList;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user