package com.yiqi.crm.controller;

import com.yiqi.common.annotation.Log;
import com.yiqi.common.core.controller.BaseController;
import com.yiqi.common.core.domain.AjaxResult;
import com.yiqi.common.core.page.TableDataInfo;
import com.yiqi.common.enums.BusinessType;
import com.yiqi.common.utils.poi.ExcelUtil;
import com.yiqi.crm.domain.WxReply;
import com.yiqi.crm.service.IWxReplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;



/**
 * 微信内容管理Controller
 *
 * @author ruoyi
 * @date 2023-07-27
 */
@Api("微信回复内容管理")
@RestController
@RequestMapping("/wxManage/wxreply")
public class WxReplyController extends BaseController {
    @Autowired
    private IWxReplyService wxReplyService;

    /**
     * 查询微信关键字回复列表
     */
    @ApiOperation("查询微信关键字回复列表")
//    @PreAuthorize("@ss.hasPermi('wxManage:keyWordsReply:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxReply wxReply) {
        startPage();
        List<WxReply> list = wxReplyService.selectWxReplyList(wxReply);
        return getDataTable(list);
    }

    /**
     * 导出微信内容管理列表
     */
    @ApiOperation("导出微信关键字回复列表")
//    @PreAuthorize("@ss.hasPermi('wxManage:keyWordsReply:export')")
    @Log(title = "微信内容管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxReply wxReply) {
        List<WxReply> list = wxReplyService.selectWxReplyList(wxReply);
        ExcelUtil<WxReply> util = new ExcelUtil<WxReply>(WxReply. class);
        util.exportExcel(response, list, "微信内容管理数据");
    }

    /**
     * 获取微信内容管理详细信息
     */
    @ApiOperation("获取微信内容管理详细信息")
//    @PreAuthorize("@ss.hasPermi('wxManage:keyWordsReply:query')")
    @GetMapping(value = "/{replyId}")
    public AjaxResult getInfo(@PathVariable("replyId") Long replyId) {
        return success(wxReplyService.selectWxReplyByReplyId(replyId));
    }

    /**
     * 新增微信内容管理
     */
    @ApiOperation("新增微信内容管理")
//    @PreAuthorize("@ss.hasPermi('wxManage:keyWordsReply:add')")
    @Log(title = "微信内容管理", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody WxReply wxReply) throws Exception {
        return toAjax(wxReplyService.insertWxReply(wxReply));
    }

    /**
     * 修改微信内容管理
     */
    @ApiOperation("修改微信内容管理")
//    @PreAuthorize("@ss.hasPermi('wxManage:keyWordsReply:edit')")
    @Log(title = "微信内容管理", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/edit")
    public AjaxResult edit(@RequestBody WxReply wxReply) throws Exception {
        return toAjax(wxReplyService.updateWxReply(wxReply));
    }

    /**
     * 删除微信内容管理
     */
    @ApiOperation("删除微信内容管理")
//    @PreAuthorize("@ss.hasPermi('wxManage:keyWordsReply:remove')")
    @Log(title = "微信内容管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{replyIds}")
    public AjaxResult remove(@PathVariable Long[] replyIds) {
        return toAjax(wxReplyService.deleteWxReplyByReplyIds(replyIds));
    }

    /**
     * 通过回复类型查询回复详细信息
     */
    @ApiOperation("通过回复类型查询回复详细信息")
//    @PreAuthorize("@ss.hasPermi('wxManage:keyWordsReply:query')")
    @GetMapping(value = "/getInfoByReplyType")
    public AjaxResult getInfoByReplyType(@RequestParam String replyType) {
        return success(wxReplyService.selectWxReplyByReplyType(replyType));
    }


    /**
     * 查询图文回复列表
     */
    @ApiOperation("查询图文回复列表")
//    @PreAuthorize("@ss.hasPermi('wxManage:keyWordsReply:query')")
    @GetMapping(value = "/getPicTextReplyList")
    public AjaxResult getPicTextReplyList() {
        return success(wxReplyService.getPicTextReplyList());
    }
}

