package com.cf.imes.module.manage.controller.admin.voice;


import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.module.manage.controller.admin.voice.vo.VoiceReqVO;
import com.cf.imes.module.manage.service.voice.VoiceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.web.bind.annotation.RestController;



@Tag(name = "管理后台 - 语音播报")
@RestController
@RequestMapping("/manage/voice")
@Validated
public class VoiceController {


    @Resource
    private VoiceService voiceService;


    @PostMapping()
    @Operation(summary = "语音播报")
    @PreAuthorize("@ss.hasPermission('manage:voice:insert')")
    public CommonResult<String> voiceAnnouncements(@Valid @RequestBody VoiceReqVO reqVO ) throws Exception {

        String sourceFile  = voiceService.voiceAnnouncements(reqVO.getData());

        String gzipFile = sourceFile+".zip";

        // 压缩语音文件
        voiceService.zipFiles(sourceFile, gzipFile);

        // 删除生成的 mp3 文件
        voiceService.deleteFiles(sourceFile);

        return CommonResult.success(gzipFile);

    }


}




