package com.ruoyi.web.controller.system;

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.ss.msgLog.domain.MsgLog;
import com.ruoyi.ss.msgLog.service.IMsgLogService;
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 qiuzhenzhen
 * @date 2024-07-24
 */
@RestController
@RequestMapping("/system/msgLog")
public class MsgLogController extends BaseController
{
    @Autowired
    private IMsgLogService etMsgLogService;

    /**
     * 查询短信日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:msgLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(MsgLog eMsgLog)
    {
        startPage();
        List<MsgLog> list = etMsgLogService.selectEtMsgLogList(eMsgLog);
        return getDataTable(list);
    }

    /**
     * 导出短信日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:msgLog:export')")
    @Log(title = "短信日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MsgLog eMsgLog)
    {
        List<MsgLog> list = etMsgLogService.selectEtMsgLogList(eMsgLog);
        ExcelUtil<MsgLog> util = new ExcelUtil<>(MsgLog.class);
        util.exportExcel(response, list, "短信日志数据");
    }

    /**
     * 获取短信日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:msgLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(etMsgLogService.selectEtMsgLogById(id));
    }

    /**
     * 新增短信日志
     */
    @PreAuthorize("@ss.hasPermi('system:msgLog:add')")
    @Log(title = "短信日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MsgLog eMsgLog)
    {
        return toAjax(etMsgLogService.insertEtMsgLog(eMsgLog));
    }

    /**
     * 修改短信日志
     */
    @PreAuthorize("@ss.hasPermi('system:msgLog:edit')")
    @Log(title = "短信日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MsgLog eMsgLog)
    {
        return toAjax(etMsgLogService.updateEtMsgLog(eMsgLog));
    }

    /**
     * 删除短信日志
     */
    @PreAuthorize("@ss.hasPermi('system:msgLog:remove')")
    @Log(title = "短信日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(etMsgLogService.deleteEtMsgLogByIds(ids));
    }
}
