package com.fs.crm.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.crm.domain.CrmMsg;
import com.fs.crm.service.ICrmMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  消息Controller
 *
 * @author fs
 * @date 2022-12-21
 */
@RestController
@RequestMapping("/crm/msg")
public class CrmMsgController extends BaseController
{
    @Autowired
    private ICrmMsgService crmMsgService;

    /**
     * 查询 消息列表
     */
    @PreAuthorize("@ss.hasPermi('crm:msg:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmMsg crmMsg)
    {
        startPage();
        List<CrmMsg> list = crmMsgService.selectCrmMsgList(crmMsg);
        return getDataTable(list);
    }

    /**
     * 导出 消息列表
     */
    @PreAuthorize("@ss.hasPermi('crm:msg:export')")
    @Log(title = " 消息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmMsg crmMsg)
    {
        List<CrmMsg> list = crmMsgService.selectCrmMsgList(crmMsg);
        ExcelUtil<CrmMsg> util = new ExcelUtil<CrmMsg>(CrmMsg.class);
        return util.exportExcel(list, "msg");
    }

    /**
     * 获取 消息详细信息
     */
    @PreAuthorize("@ss.hasPermi('crm:msg:query')")
    @GetMapping(value = "/{msgId}")
    public AjaxResult getInfo(@PathVariable("msgId") Long msgId)
    {
        return AjaxResult.success(crmMsgService.selectCrmMsgById(msgId));
    }

    /**
     * 新增 消息
     */
    @PreAuthorize("@ss.hasPermi('crm:msg:add')")
    @Log(title = " 消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmMsg crmMsg)
    {
        return toAjax(crmMsgService.insertCrmMsg(crmMsg));
    }

    /**
     * 修改 消息
     */
    @PreAuthorize("@ss.hasPermi('crm:msg:edit')")
    @Log(title = " 消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmMsg crmMsg)
    {
        return toAjax(crmMsgService.updateCrmMsg(crmMsg));
    }

    /**
     * 删除 消息
     */
    @PreAuthorize("@ss.hasPermi('crm:msg:remove')")
    @Log(title = " 消息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{msgIds}")
    public AjaxResult remove(@PathVariable Long[] msgIds)
    {
        return toAjax(crmMsgService.deleteCrmMsgByIds(msgIds));
    }
}
