whycxzp
2022-11-17 f04cdce04b9e44a4dea870ba2721415be7eb085e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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_file"+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();
            }
        }
    }
 
}