package com.ruoyi.web.controller.back;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SmsLog;
import com.ruoyi.system.service.ISmsLogService;
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 mingxue
 * @date 2022-09-24
 */
@RestController
@RequestMapping("/system/mxjbSmsLog")
public class BackSmsLogController extends BaseController
{
    @Autowired
    private ISmsLogService mxjbSmsLogService;

    /**
     * 查询短信发送记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:mxjbSmsLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsLog mxjbSmsLog)
    {
        startPage();
        List<SmsLog> list = mxjbSmsLogService.selectSmsLogList(mxjbSmsLog);
        return getDataTable(list);
    }

    /**
     * 导出短信发送记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:mxjbSmsLog:export')")
    @Log(title = "短信发送记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SmsLog mxjbSmsLog)
    {
        List<SmsLog> list = mxjbSmsLogService.selectSmsLogList(mxjbSmsLog);
        ExcelUtil<SmsLog> util = new ExcelUtil<SmsLog>(SmsLog.class);
        return util.exportExcel(list, "短信发送记录数据");
    }

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

    /**
     * 新增短信发送记录
     */
    @PreAuthorize("@ss.hasPermi('system:mxjbSmsLog:add')")
    @Log(title = "短信发送记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmsLog mxjbSmsLog)
    {
        return toAjax(mxjbSmsLogService.insertSmsLog(mxjbSmsLog));
    }

    /**
     * 修改短信发送记录
     */
    @PreAuthorize("@ss.hasPermi('system:mxjbSmsLog:edit')")
    @Log(title = "短信发送记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmsLog mxjbSmsLog)
    {
        return toAjax(mxjbSmsLogService.updateSmsLog(mxjbSmsLog));
    }

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