package com.flossom.system.controller;

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

import com.flossom.common.core.domain.entity.WxScriptMessage;
import com.flossom.common.core.utils.poi.ExcelUtil;
import com.flossom.common.core.web.controller.BaseController;
import com.flossom.common.core.web.domain.AjaxResult;
import com.flossom.common.core.web.page.TableDataInfo;
import com.flossom.common.log.annotation.Log;
import com.flossom.common.log.enums.BusinessType;
import com.flossom.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.flossom.system.service.IWxScriptMessageService;

/**
 * 消息模版Controller
 *
 * @author flossom
 * @date 2023-12-22
 */
@RestController
@RequestMapping("/scriptMessage")
public class WxScriptMessageController extends BaseController
{
    @Autowired
    private IWxScriptMessageService wxScriptMessageService;

    /**
     * 查询消息模版列表
     */
    @RequiresPermissions("system:scriptMessage:list")
    @GetMapping("/list")
    public TableDataInfo list(WxScriptMessage wxScriptMessage)
    {
        startPage();
        List<WxScriptMessage> list = wxScriptMessageService.selectWxScriptMessageList(wxScriptMessage);
        return getDataTable(list);
    }

    /**
     * 导出消息模版列表
     */
    @RequiresPermissions("system:scriptMessage:export")
    @Log(title = "消息模版", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxScriptMessage wxScriptMessage)
    {
        List<WxScriptMessage> list = wxScriptMessageService.selectWxScriptMessageList(wxScriptMessage);
        ExcelUtil<WxScriptMessage> util = new ExcelUtil<WxScriptMessage>(WxScriptMessage.class);
        util.exportExcel(response, list, "消息模版数据");
    }

    /**
     * 获取消息模版详细信息
     */
    @RequiresPermissions("system:scriptMessage:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wxScriptMessageService.selectWxScriptMessageById(id));
    }

    /**
     * 新增消息模版
     */
    @RequiresPermissions("system:scriptMessage:add")
    @Log(title = "消息模版", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxScriptMessage wxScriptMessage)
    {
        return toAjax(wxScriptMessageService.insertWxScriptMessage(wxScriptMessage));
    }

    /**
     * 修改消息模版
     */
    @RequiresPermissions("system:scriptMessage:edit")
    @Log(title = "消息模版", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxScriptMessage wxScriptMessage)
    {
        return toAjax(wxScriptMessageService.updateWxScriptMessage(wxScriptMessage));
    }

    /**
     * 删除消息模版
     */
    @RequiresPermissions("system:scriptMessage:remove")
    @Log(title = "消息模版", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wxScriptMessageService.deleteWxScriptMessageByIds(ids));
    }
}
