| | |
| | | package com.whyc.controller; |
| | | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.pojo.AlarmVoiceSet; |
| | | import com.whyc.pojo.UserInf; |
| | | import com.whyc.service.AlarmDataService; |
| | | import com.whyc.service.AlarmVoiceSetService; |
| | | import com.whyc.service.MSTTSSpeechService; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.CommonUtil; |
| | |
| | | @Autowired |
| | | private AlarmDataService alarmDataService; |
| | | |
| | | @Autowired |
| | | private AlarmVoiceSetService alarmVoiceSetService; |
| | | |
| | | /** |
| | | * 用户的语音文件路径层级 |
| | | * /fg_file/wav/alarm/uId/unread/ |
| | |
| | | * @return |
| | | */ |
| | | @ApiOperation("查询用户未读的wav语音文件列表") |
| | | @GetMapping |
| | | @GetMapping("wavUnread") |
| | | public Response getWavUnread(){ |
| | | UserInf user = ActionUtil.getUser(); |
| | | //获取绝对文件夹路径 |
| | |
| | | } |
| | | List<String> fileNameList = new LinkedList<>(); |
| | | for (String fileName : arr) { |
| | | fileName="fg_doc"+File.separator+unreadSuffixPath+File.separator+fileName; |
| | | fileName="fg_file"+File.separator+unreadSuffixPath+File.separator+fileName; |
| | | fileNameList.add(fileName); |
| | | } |
| | | return new Response().setII(1,true,fileNameList,null); |
| | |
| | | } |
| | | |
| | | @ApiOperation("删除用户wav语音文件") |
| | | @DeleteMapping |
| | | @DeleteMapping("wavRead") |
| | | public void deleteWavRead(@RequestParam(required = false) String fileFullName){ |
| | | UserInf user = ActionUtil.getUser(); |
| | | //获取绝对文件夹路径 |
| | |
| | | } |
| | | } |
| | | |
| | | @ApiOperation("用户wav语音文件播放完毕") |
| | | @PutMapping("wavRead") |
| | | public void updateWavRead(@RequestParam(required = false) String fileFullName){ |
| | | UserInf user = ActionUtil.getUser(); |
| | | long currentTimeMillis = System.currentTimeMillis(); |
| | | Long specialId = null; |
| | | int type = 0; |
| | | int alarmType = 0; |
| | | //获取绝对文件夹路径 |
| | | String readSuffixPath = "wav" + File.separator + "alarm" + File.separator + user.getUId() + File.separator; |
| | | String fromFilePath = CommonUtil.getRootFile() + readSuffixPath + fileFullName; |
| | | //语音文件,命名规则 {alarmStartTime}_device_{num}_{deviceId}_{almType}_{readableVoiceTime}.wav |
| | | //更新下次播放时间:如果set表没有对应的时间间隔,则默认5分钟后,有则按照表中的时间间隔(单位:分钟). |
| | | if(fileFullName.contains("batt")){ |
| | | type=1; |
| | | }else if(fileFullName.contains("device")){ |
| | | type=2; |
| | | }else{ |
| | | type=3; |
| | | } |
| | | String[] nameSplit = fileFullName.split("_"); |
| | | specialId = Long.parseLong(nameSplit[3]); |
| | | alarmType = Integer.parseInt(nameSplit[4]); |
| | | String readableVoiceTimeWithWav = nameSplit[5]; |
| | | AlarmVoiceSet nextTimeIntervalSet = alarmVoiceSetService.getNextTimeInterval(user.getUId(), type, specialId, alarmType); |
| | | int addedTimeMillis = 0; |
| | | if(nextTimeIntervalSet !=null){ |
| | | //间隔时间(单位分钟)失效,删除 |
| | | Integer nextTimeInterval = nextTimeIntervalSet.getNextTimeInterval(); |
| | | addedTimeMillis = nextTimeInterval*60*1000; |
| | | |
| | | alarmVoiceSetService.delete(nextTimeIntervalSet.getId()); |
| | | }else{ //默认5分钟 |
| | | addedTimeMillis = 5*60*1000; |
| | | //addedTimeMillis = 1*60*1000; |
| | | } |
| | | String readableVoiceTimeWithWavNew = currentTimeMillis+addedTimeMillis+".wav"; |
| | | //文件下次播放时间确定新的文件名 |
| | | String renameToFileFullName = fileFullName.replace(readableVoiceTimeWithWav,readableVoiceTimeWithWavNew); |
| | | String renameToFilePath = CommonUtil.getRootFile() + readSuffixPath + renameToFileFullName; |
| | | //播报完毕后,将播报时间更新到文件名上 |
| | | File fromFile = new File(fromFilePath); |
| | | File renameToFile = new File(renameToFilePath); |
| | | fromFile.renameTo(renameToFile); |
| | | } |
| | | |
| | | /** |
| | | * 用户的语音文件路径层级 |
| | | * /fg_file/wav/alarm/uId/ |
| | | * @return |
| | | */ |
| | | @ApiOperation("查询用户目前可读的wav语音文件列表") |
| | | @GetMapping("wavRead") |
| | | public Response getWavRead(){ |
| | | return alarmDataService.getWavRead(); |
| | | } |
| | | |
| | | } |