rasa 初始化文件保存功能
parent
5273e79278
commit
cd895db85f
@ -1,44 +0,0 @@
|
||||
package com.superversion.rasa.controller;
|
||||
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
@Api(tags = "辅助检查")
|
||||
@RestController
|
||||
@RequestMapping("askAncillary")
|
||||
@RequiredArgsConstructor
|
||||
public class AskAncillaryController {
|
||||
|
||||
|
||||
@ApiOperation("接收页面的语音消息(暂时不用这个接口,主要使用websocket进行通信)")
|
||||
@PostMapping("/receiveVoiceFile")
|
||||
public String receiveVoiceFile(@RequestParam("file") MultipartFile file) throws IOException {
|
||||
//return askService.receiveVoiceFile(file);
|
||||
|
||||
if (file != null && !file.isEmpty()) {
|
||||
String fileName1 = file.getOriginalFilename(); //获取保存文件名
|
||||
String suffixName=fileName1.substring(fileName1.lastIndexOf(".")); //文件格式
|
||||
String fileName= UUID.randomUUID()+suffixName;//重命名a.jpg
|
||||
//保存文件到对应位置
|
||||
File dir = new File("F:\\tmp\\"+fileName);
|
||||
if (!dir.getParentFile().exists()) {
|
||||
dir.getParentFile().mkdirs();
|
||||
}
|
||||
try {
|
||||
file.transferTo(dir);
|
||||
} catch (IOException e) {
|
||||
//抛出异常
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.superversion.rasa.controller;
|
||||
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class RasaCmdController {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.superversion.rasa.controller;
|
||||
|
||||
|
||||
import com.superversion.rasa.service.RasaFileService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
@Api(tags = "辅助检查")
|
||||
@RestController
|
||||
@RequestMapping("rasaFile")
|
||||
@RequiredArgsConstructor
|
||||
public class RasaFileController {
|
||||
|
||||
@Autowired
|
||||
private RasaFileService rasaFileService;
|
||||
|
||||
@ApiOperation("接受并保存rasa文件")
|
||||
@PostMapping("/saveRasaFile")
|
||||
public String saveRasaFile(@RequestParam("file") MultipartFile file) throws Exception {
|
||||
|
||||
if (file == null || file.isEmpty()) {
|
||||
return "file is empty";
|
||||
}
|
||||
|
||||
rasaFileService.saveRasaFile(file);
|
||||
return "ok";
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package com.superversion.rasa.service;
|
||||
|
||||
public interface RasaCmdService {
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.superversion.rasa.service;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public interface RasaFileService {
|
||||
|
||||
void saveRasaFile(MultipartFile file) throws Exception;
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.superversion.rasa.service.impl;
|
||||
|
||||
import com.superversion.rasa.service.RasaCmdService;
|
||||
|
||||
public class RasaCmdServiceImpl implements RasaCmdService {
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.superversion.rasa.service.impl;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import com.superversion.rasa.service.RasaFileService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class RasaFileServiceImpl implements RasaFileService {
|
||||
|
||||
|
||||
@Value("${rasa.file-path:/home/rasa}")
|
||||
private String rasaFilePath;
|
||||
|
||||
@Value("${rasa.file-name:rasa.zip}")
|
||||
private String rasaFileName;
|
||||
|
||||
@Override
|
||||
public void saveRasaFile(MultipartFile file) throws Exception {
|
||||
|
||||
//初始化目录
|
||||
File dir = new File(rasaFilePath);
|
||||
if (!dir.exists()){
|
||||
FileUtil.mkdir(dir);
|
||||
}
|
||||
|
||||
String suffix = "_back";
|
||||
String rasaFullPath = String.join(File.separator, rasaFilePath, rasaFileName);
|
||||
String rasaBackFullPath = String.join(File.separator, rasaFilePath, rasaFileName + suffix);
|
||||
|
||||
//1.检查路径下是否存在文件
|
||||
File oldFile = new File(rasaFullPath);
|
||||
if (oldFile.exists()){
|
||||
//1.1 如果存在文件,先备份文件
|
||||
FileUtil.rename(oldFile,rasaBackFullPath,true);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
//2.把流文件保存到本地
|
||||
file.transferTo(new File(rasaFullPath));
|
||||
|
||||
//3.解压文件
|
||||
ZipUtil.unzip(rasaFullPath);
|
||||
|
||||
//4.删除备份文件
|
||||
FileUtil.del(rasaBackFullPath);
|
||||
} catch (IOException e) {
|
||||
// 恢复文件
|
||||
File backFile = new File(rasaBackFullPath);
|
||||
if (backFile.exists()){ //恢复文件
|
||||
FileUtil.rename(oldFile,rasaFullPath,true);
|
||||
}
|
||||
throw new Exception(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1 +0,0 @@
|
||||
|
@ -0,0 +1,7 @@
|
||||
server:
|
||||
port: 8081
|
||||
servlet:
|
||||
context-path: /
|
||||
|
||||
rasa:
|
||||
file-path: F:\tmp
|
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<include resource="org/springframework/boot/logging/logback/base.xml"/>
|
||||
<logger name="org.springframework.web" level="INFO"/>
|
||||
<logger name="org.springboot.sample" level="TRACE"/>
|
||||
|
||||
<!-- 开发、测试环境 -->
|
||||
<springProfile name="dev,test,local">
|
||||
<logger name="org.springframework.web" level="DEBUG"/>
|
||||
<logger name="org.springboot.sample" level="DEBUG"/>
|
||||
<logger name="com.supervision" level="DEBUG"/>
|
||||
<logger name="org.springframework.scheduling" level="DEBUG"/>
|
||||
</springProfile>
|
||||
|
||||
<!-- 生产环境 -->
|
||||
<springProfile name="prod">
|
||||
<logger name="org.springframework.web" level="ERROR"/>
|
||||
<logger name="org.springboot.sample" level="ERROR"/>
|
||||
<logger name="com.supervision" level="INFO"/>
|
||||
</springProfile>
|
||||
|
||||
</configuration>
|
Loading…
Reference in New Issue