package com.bonus.sgzb.system.controller;

import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.system.service.ISysSmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Description: 短信控制器
 *
 * @Author 阮世耀
 * @Create 2023/12/11 15:46
 * @Version 1.0
 */

@RestController
@RequestMapping("/sms")
public class SysSmsController extends BaseController {

    @Resource
    private ISysSmsService smsService;

    /**
     * 登录短信验证码
     * @param phone
     * @return
     */
    @PostMapping("codeLogin")
    public AjaxResult codeLogin(@RequestParam(value = "phone") String phone){
        try {
            return smsService.codeLogin(phone);
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 短信验证码校验
     * @param phone
     * @param code
     * @return
     */
    @PostMapping("checkCode")
    public AjaxResult codeLogin(@RequestParam(value = "phone") String phone, @RequestParam(value = "code") String code){
        try {
            return toAjax(smsService.checkCode(phone, code));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 验收通知短信
     * @param phone
     * @param msg
     * @return
     */
    @PostMapping("send")
    public AjaxResult send(@RequestParam(value = "phone") String phone, @RequestParam(value = "msg",required = false) String msg){
        try {
            return smsService.sendSms(phone, msg);
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }


}
