package com.whyc.controller;
|
|
import com.whyc.dto.Response;
|
import com.whyc.pojo.UserInf;
|
import com.whyc.service.AlarmDataService;
|
import com.whyc.service.MSTTSSpeechService;
|
import com.whyc.util.ActionUtil;
|
import com.whyc.util.CommonUtil;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.io.File;
|
import java.util.LinkedList;
|
import java.util.List;
|
|
@Api(tags = "语音")
|
@RestController
|
@RequestMapping("voice")
|
public class VoiceController {
|
|
@Autowired
|
private AlarmDataService alarmDataService;
|
|
/**
|
* 用户的语音文件路径层级
|
* /fg_file/wav/alarm/uId/unread/
|
* /fg_file/wav/alarm/uId/read/
|
* @return
|
*/
|
@ApiOperation("查询用户未读的wav语音文件列表")
|
@GetMapping
|
public Response getWavUnread(){
|
UserInf user = ActionUtil.getUser();
|
//获取绝对文件夹路径
|
String unreadSuffixPath = "wav" + File.separator + "alarm" + File.separator + user.getUId() + File.separator + "unread";
|
String unreadDirPath = CommonUtil.getRootFile() + unreadSuffixPath;
|
File unreadDir = new File(unreadDirPath);
|
//保存用户的告警语音文件
|
alarmDataService.saveToWav(unreadDirPath);
|
if(!unreadDir.exists()){
|
return new Response().set(1,false,"无未读告警语音");
|
}else{
|
String[] arr = unreadDir.list();
|
if(arr.length==0){
|
return new Response().set(1,false,"无未读告警语音");
|
}
|
List<String> fileNameList = new LinkedList<>();
|
for (String fileName : arr) {
|
fileName="fg_doc"+File.separator+unreadSuffixPath+File.separator+fileName;
|
fileNameList.add(fileName);
|
}
|
return new Response().setII(1,true,fileNameList,null);
|
}
|
}
|
|
@ApiOperation("删除用户wav语音文件")
|
@DeleteMapping
|
public void deleteWavRead(@RequestParam(required = false) String fileFullName){
|
UserInf user = ActionUtil.getUser();
|
//获取绝对文件夹路径
|
String unreadSuffixPath = "wav" + File.separator + "alarm" + File.separator + user.getUId() + File.separator + "unread";
|
if(fileFullName!=null) { //删除用户下指定的语音
|
String deletedFilePath = CommonUtil.getRootFile() + unreadSuffixPath + File.separator + fileFullName;
|
File deletedFile = new File(deletedFilePath);
|
deletedFile.delete();
|
}else{ //清空用户下的所有语音
|
String deletedDirPath = CommonUtil.getRootFile() + unreadSuffixPath;
|
File deletedDir = new File(deletedDirPath);
|
File[] files = deletedDir.listFiles();
|
for (File file:files) {
|
file.delete();
|
}
|
}
|
}
|
|
}
|