package com.ruoyi.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
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.cs.domain.CsMessageRecord;
import com.ruoyi.cs.service.ICsMessageRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 短信通知记录Controller
 *
 * @author ruoyi
 * @date 2024-05-29
 */
@RestController
@RequestMapping("/cs/csMessageRecord")
public class CsMessageRecordController extends BaseController
{
    @Resource
    private ICsMessageRecordService csMessageRecordService;

    /**
     * 查询短信通知记录列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csMessageRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsMessageRecord csMessageRecord)
    {
        startPage();
        csMessageRecord.setDelFlag("0");
        List<CsMessageRecord> list = csMessageRecordService.selectCsMessageRecordList(csMessageRecord);
        return getDataTable(list);
    }

    /**
     * 导出短信通知记录列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csMessageRecord:export')")
    @Log(title = "短信通知记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsMessageRecord csMessageRecord)
    {
        List<CsMessageRecord> list = csMessageRecordService.selectCsMessageRecordList(csMessageRecord);
        ExcelUtil<CsMessageRecord> util = new ExcelUtil<CsMessageRecord>(CsMessageRecord.class);
        util.exportExcel(response, list, "短信通知记录数据");
    }

    /**
     * 获取短信通知记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('cs:csMessageRecord:query')")
    @GetMapping(value = "/{messageRecordId}")
    public AjaxResult getInfo(@PathVariable("messageRecordId") String messageRecordId)
    {
        return AjaxResult.success(csMessageRecordService.selectCsMessageRecordByMessageRecordId(messageRecordId));
    }

    /**
     * 新增短信通知记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csMessageRecord:add')")
    @Log(title = "短信通知记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsMessageRecord csMessageRecord)
    {
        return toAjax(csMessageRecordService.insertCsMessageRecord(csMessageRecord));
    }

    /**
     * 修改短信通知记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csMessageRecord:edit')")
    @Log(title = "短信通知记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsMessageRecord csMessageRecord)
    {
        return toAjax(csMessageRecordService.updateCsMessageRecord(csMessageRecord));
    }

    /**
     * 删除短信通知记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csMessageRecord:remove')")
    @Log(title = "短信通知记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{messageRecordIds}")
    public AjaxResult remove(@PathVariable String[] messageRecordIds)
    {
        return toAjax(csMessageRecordService.deleteCsMessageRecordByMessageRecordIds(messageRecordIds));
    }

    /**
     * 批量发送短信
     */
    @Log(title = "批量发送短信", businessType = BusinessType.INSERT)
    @PostMapping("/bachSendMessage")
    public AjaxResult bachSendMessage(@RequestBody CsMessageRecord csMessageRecord)
    {
        if (csMessageRecord.getPhones() == null) {
            return AjaxResult.error("请输入手机号");
        }
        return csMessageRecordService.bachSendMessage(csMessageRecord);
    }
}
