package com.sqx.modules.message.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sqx.common.utils.Result;
import com.sqx.modules.message.entity.MessageInfoAudio;
import com.sqx.modules.message.service.MessageAudioService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author fang
 * @date 2020/7/13
 */
@RestController
@Api(value = "消息管理", tags = {"消息管理"})
@RequestMapping(value = "/messageAudio")
public class MessageAudioController {

    @Autowired
    private MessageAudioService service;

    @GetMapping("/batchList")
    @ApiOperation("按批次获取音频列表")
    public Result batchList(Integer page,Integer limit,String batch){
        QueryWrapper<MessageInfoAudio> qw = new QueryWrapper<>();
        qw.eq(StringUtils.isNotBlank(batch),"batch",batch);
        qw.eq(StringUtils.isBlank(batch),"batch","-1");
        qw.orderByAsc("sort");
        IPage<MessageInfoAudio> pageList = service.page(new Page<>(page,limit),qw);
        return Result.success().put("data",pageList);
    }

    @PostMapping(value = "/add")
    @ApiOperation("新增音频列表")
    @ResponseBody
    public Result add(@RequestBody MessageInfoAudio messageInfoAudio){
        return Result.success().put("data",service.save(messageInfoAudio));
    }

    @PostMapping(value = "/update")
    @ApiOperation("修改音频列表")
    @ResponseBody
    public Result update(@RequestBody MessageInfoAudio messageInfoAudio){
        return Result.success().put("data",service.updateById(messageInfoAudio));
    }

    @GetMapping(value = "/deleteById")
    @ApiOperation("删除音频列表")
    @ResponseBody
    public Result deleteById(Long id){
        return Result.success().put("data",service.removeById(id));
    }

    @GetMapping(value = "/mergeAllAudio")
    @ApiOperation("合并全部音频")
    @ResponseBody
    public Result mergeAllAudio(String batch){
        return Result.success().put("data",service.mergeAllAudio(batch));
    }


}