package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TextMessageLog;
import com.ruoyi.system.service.ITextMessageLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 短信记录Controller
 * 
 * @author ruoyi
 * @date 2021-07-20
 */
@RestController
@RequestMapping("/system/messageLog")
public class TextMessageLogController extends BaseController
{
    @Autowired
    private ITextMessageLogService textMessageLogService;

    /**
     * 查询短信记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:messageLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(TextMessageLog textMessageLog)
    {
        startPage();
        List<TextMessageLog> list = textMessageLogService.selectTextMessageLogList(textMessageLog);
        return getDataTable(list);
    }

    /**
     * 导出短信记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:messageLog:export')")
    @Log(title = "短信记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TextMessageLog textMessageLog)
    {
        List<TextMessageLog> list = textMessageLogService.selectTextMessageLogList(textMessageLog);
        ExcelUtil<TextMessageLog> util = new ExcelUtil<TextMessageLog>(TextMessageLog.class);
        return util.exportExcel(list, "messageLog");
    }

    /**
     * 获取短信记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:messageLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(textMessageLogService.selectTextMessageLogById(id));
    }

    /**
     * 新增短信记录
     */
    @PreAuthorize("@ss.hasPermi('system:messageLog:add')")
    @Log(title = "短信记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TextMessageLog textMessageLog)
    {
        return toAjax(textMessageLogService.insertTextMessageLog(textMessageLog));
    }

    /**
     * 修改短信记录
     */
    @PreAuthorize("@ss.hasPermi('system:messageLog:edit')")
    @Log(title = "短信记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TextMessageLog textMessageLog)
    {
        return toAjax(textMessageLogService.updateTextMessageLog(textMessageLog));
    }

    /**
     * 删除短信记录
     */
    @PreAuthorize("@ss.hasPermi('system:messageLog:remove')")
    @Log(title = "短信记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(textMessageLogService.deleteTextMessageLogByIds(ids));
    }
}
