package com.ruoyi.web.controller.projectV2.common;

import java.util.List;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.projectV2.common.SendSms;
import com.ruoyi.system.service.projectV2.common.ISendSmsService;
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.common.core.page.TableDataInfo;

/**
 * 短信日志Controller
 * 
 * @author ruoyi
 * @date 2023-02-24
 */
@RestController
@RequestMapping("/projectV2/sms")
public class SendSmsController extends BaseController
{
    @Autowired
    private ISendSmsService sendSmsService;

    /**
     * 查询短信日志列表
     */
    @PreAuthorize("@ss.hasPermi('projectV2:sms:list')")
    @GetMapping("/list")
    public TableDataInfo list(SendSms sendSms)
    {
        startPage();
        List<SendSms> list = sendSmsService.selectSendSmsList(sendSms);
        return getDataTable(list);
    }

    /**
     * 导出短信日志列表
     */
    @PreAuthorize("@ss.hasPermi('projectV2:sms:export')")
    @Log(title = "短信日志", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SendSms sendSms)
    {
        List<SendSms> list = sendSmsService.selectSendSmsList(sendSms);
        ExcelUtil<SendSms> util = new ExcelUtil<SendSms>(SendSms.class);
        return util.exportExcel(list, "sms");
    }

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

    /**
     * 新增短信日志
     */
    @PreAuthorize("@ss.hasPermi('projectV2:sms:add')")
    @Log(title = "短信日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SendSms sendSms)
    {
        return toAjax(sendSmsService.insertSendSms(sendSms));
    }

    /**
     * 修改短信日志
     */
    @PreAuthorize("@ss.hasPermi('projectV2:sms:edit')")
    @Log(title = "短信日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SendSms sendSms)
    {
        return toAjax(sendSmsService.updateSendSms(sendSms));
    }

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