package com.ruoyi.cai.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.cai.domain.SmsVerify;
import com.ruoyi.cai.enums.CodeEnum;
import com.ruoyi.cai.manager.CodeManager;
import com.ruoyi.cai.mapper.SmsVerifyMapper;
import com.ruoyi.cai.service.SmsVerifyService;
import com.ruoyi.common.utils.ServletUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

/**
 * 短信验证码Service业务层处理
 *
 * @author 77
 * @date 2024-01-01
 */
@Service
public class SmsVerifyServiceImpl extends ServiceImpl<SmsVerifyMapper,SmsVerify> implements SmsVerifyService {

    @Autowired
    private CodeManager codeManager;

    @Override
    public void put(CodeEnum codeEnum,String mobile){
        String code = codeManager.put(codeEnum, mobile);
        SmsVerify smsVerify = new SmsVerify();
        smsVerify.setType(codeEnum.name());
        smsVerify.setType(codeEnum.getName());
        smsVerify.setReceivePhone(mobile);
        smsVerify.setVerifyCode(code);
        smsVerify.setSendInterface("阿里云");
        smsVerify.setOperateIp(ServletUtils.getClientIP());
        smsVerify.setOverTime(LocalDateTime.now().plus(3, ChronoUnit.MINUTES));
        this.save(smsVerify);
    }

}
