package com.lz.modules.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lz.common.utils.PageUtils;
import com.lz.common.utils.Query;
import com.lz.modules.app.dao.CodeRecordDao;
import com.lz.modules.app.entity.CodeRecordEntity;
import com.lz.modules.app.enums.SmsTypeEnum;
import com.lz.modules.app.service.CodeRecordService;
import com.lz.modules.sys.entity.SysUserEntity;
import org.springframework.stereotype.Service;

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


@Service("codeRecordService")
public class CodeRecordServiceImpl extends ServiceImpl<CodeRecordDao, CodeRecordEntity> implements CodeRecordService {

    @Resource
    CodeRecordDao codeRecordDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CodeRecordEntity> page = this.page(
                new Query<CodeRecordEntity>().getPage(params),
                new QueryWrapper<CodeRecordEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public CodeRecordEntity getNoCerifyCode(String mobile, Integer type) {
        return codeRecordDao.getNoCerifyCode(mobile, type);
    }

    @Override
    public void addCodeRecord(String verifyCode, SysUserEntity user, String result) {
        CodeRecordEntity codeRecordEntity = new CodeRecordEntity();
        codeRecordEntity.setType(SmsTypeEnum.LZ_LOGIN_VERIFICATION.getCode());
        codeRecordEntity.setUserId(user.getUserId());
        codeRecordEntity.setSendAccount(user.getMobile());
        codeRecordEntity.setVerifyCode(verifyCode);
        codeRecordEntity.setResult(result);
        codeRecordEntity.setIsCheck(0);
        this.save(codeRecordEntity);
    }


}
