package com.srs.web.controller.stureg;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.srs.common.annotation.Anonymous;
import com.srs.stureg.domain.SrsMsgQueue;
import com.srs.stureg.service.ISrsMsgQueueService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.srs.common.annotation.Log;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.enums.BusinessType;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.core.page.TableDataInfo;

/**
 * 短信队列Controller
 *
 * @author srs
 * @date 2023-07-24
 */
@RestController
@RequestMapping("/system/queue")
public class SrsMsgQueueController extends BaseController
{
    @Autowired
    private ISrsMsgQueueService srsMsgQueueService;

    /**
     * 查询短信队列列表
     */
//    @PreAuthorize("@ss.hasPermi('system:queue:list')")
    @GetMapping("/list")
    public TableDataInfo list(SrsMsgQueue srsMsgQueue)
    {
        startPage();
        List<SrsMsgQueue> list = srsMsgQueueService.selectSrsMsgQueueList(srsMsgQueue);
        return getDataTable(list);
    }

    //发送验证码短信短信
    //@Anonymous
    @PostMapping("/sendSms")
    public AjaxResult sendSms(@RequestBody Map<String,Object> msgMap) {
        try
        {
            boolean b = srsMsgQueueService.sendSms(msgMap);
            if (b){
                return success("发送成功");
            }
        }catch (Exception e){
            return  error(e.getMessage());
        }
        return error("发送失败");
    }

    //发送验证码短信短信
    //@Anonymous
    @PostMapping("/sendSmsUpdatePhone")
    public AjaxResult sendSmsUpdatePhone(@RequestBody Map<String,Object> msgMap) {
        try
        {
            boolean b = srsMsgQueueService.sendSmsUpdatePhone(msgMap);
            if (b){
                return success("发送成功");
            }
        }catch (Exception e){
            return  error(e.getMessage());
        }
        return error("发送失败");
    }
    @PostMapping("/sendSmsUpdatePwd")
    public AjaxResult sendSmsUpdatePwd(@RequestBody Map<String,Object> msgMap) {
        try
        {
            boolean b = srsMsgQueueService.sendSmsUpdatePwd(msgMap);
            if (b){
                return success("发送成功");
            }
        }catch (Exception e){
            return  error(e.getMessage());
        }
        return error("发送失败");
    }
    //发送所有通知短信
    //@Anonymous
    @PostMapping("/sendSmsAll")
    public AjaxResult sendSmsAll(String notice) throws Exception {
        srsMsgQueueService.sendSmsAll(notice);
        return success("发送成功");
    }

    /**
     * 导出短信队列列表
     */
//    @PreAuthorize("@ss.hasPermi('system:queue:export')")
    @Log(title = "短信队列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrsMsgQueue srsMsgQueue)
    {
        List<SrsMsgQueue> list = srsMsgQueueService.selectSrsMsgQueueList(srsMsgQueue);
        ExcelUtil<SrsMsgQueue> util = new ExcelUtil<SrsMsgQueue>(SrsMsgQueue.class);
        util.exportExcel(response, list, "短信队列数据");
    }

    /**
     * 获取短信队列详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:queue:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(srsMsgQueueService.selectSrsMsgQueueById(id));
    }

    /**
     * 新增短信队列
     */
//    @PreAuthorize("@ss.hasPermi('system:queue:add')")
    @Log(title = "短信队列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrsMsgQueue srsMsgQueue)
    {
        return toAjax(srsMsgQueueService.insertSrsMsgQueue(srsMsgQueue));
    }

    /**
     * 修改短信队列
     */
//    @PreAuthorize("@ss.hasPermi('system:queue:edit')")
    @Log(title = "短信队列", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody SrsMsgQueue srsMsgQueue)
    {
        return toAjax(srsMsgQueueService.updateSrsMsgQueue(srsMsgQueue));
    }

    /**
     * 删除短信队列
     */
//    @PreAuthorize("@ss.hasPermi('system:queue:remove')")
    @Log(title = "短信队列", businessType = BusinessType.DELETE)
	@PostMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(srsMsgQueueService.deleteSrsMsgQueueByIds(ids));
    }
}
