@ -1,6 +1,7 @@
package com.baiye.modules.platform.service.impl ;
import cn.hutool.core.date.DateUtil ;
import cn.hutool.core.util.RandomUtil ;
import cn.hutool.core.util.StrUtil ;
import cn.hutool.core.util.URLUtil ;
import com.baiye.config.properties.FileProperties ;
@ -14,7 +15,6 @@ import com.baiye.util.QueryHelp;
import com.baiye.util.SecurityUtils ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.data.domain.Page ;
import org.springframework.data.domain.PageRequest ;
import org.springframework.data.domain.Pageable ;
@ -37,24 +37,19 @@ public class ExcellentCasesServiceImpl implements ExcellentCasesService {
private final FileProperties fileProperties ;
@Value ( "${ocean.engine.welcomeUrl}" )
private String sysPath ;
@Override
public void addExcellentCases ( ExcellentCases excellentCases ) {
excellentCases . setCreateBy ( SecurityUtils . getCurrentUserId ( ) ) ;
excellentCases . setCreateTime ( DateUtil . date ( ) ) ;
URL url1 = URLUtil . url ( excellentCases . getUrl ( ) ) ;
BufferedInputStream inputStream = null ;
String url = null ;
BufferedInputStream inputStream ;
String url ;
try {
inputStream = new BufferedInputStream ( url1 . openStream ( ) ) ;
String s = url1 . getPath ( ) ;
String substring = s . substring ( s . lastIndexOf ( "/" ) + 1 ) ;
String substring = DateUtil . format ( DateUtil . date ( ) , "MMdd" ) + RandomUtil . randomString ( 6 ) + ".wav" ;
File file = inputStreamToFile ( inputStream , substring ) ;
log . info ( "地址=={}" , file . getPath ( ) ) ;
url = sysPath + file . getPath ( ) ;
url = "cases" + File . separator + substring ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
throw new BadRequestException ( "保存错误,获取录音错误" ) ;
@ -68,7 +63,7 @@ public class ExcellentCasesServiceImpl implements ExcellentCasesService {
public File inputStreamToFile ( InputStream ins , String name ) throws Exception {
String path = fileProperties . getPath ( ) . getPath ( ) ;
File file = new File ( path + File . separator + " re cord" + name ) ;
File file = new File ( path + File . separator + " cases" + File . separat or + name ) ;
if ( file . exists ( ) ) {
return file ;
}