package com.sptg.permissions.biz.service.impl;

import com.baomidou.mybatisplus.enums.SqlLike;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.permissions.api.entity.SmsRecords;
import com.sptg.permissions.biz.mapper.SmsMapper;
import com.sptg.permissions.biz.service.SmsServiceInterface;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * title: SmsServiceImpl
 * package: com.sptg.permissions.biz.service.impl
 * description: 短信 服务层实现类
 *
 */
@Service
@RequiredArgsConstructor
public class SmsServiceImpl extends ServiceImpl<SmsMapper, SmsRecords> implements SmsServiceInterface {

    @Override
    public ResultBean<Page<SmsRecords>> pagingByCondition(SmsRecords smsRecords) {
        Wrapper<SmsRecords> wrapper = new EntityWrapper<>();
        if (StringUtils.isNotBlank(smsRecords.getTel())){
            wrapper.like("s_tel", smsRecords.getTel(), SqlLike.DEFAULT);
        }
        return new ResultBean<>(ResultEnum.SUCCESS,this.selectPage(smsRecords.getPage(),wrapper));
    }

    @Override
    public ResultBean<Boolean> insertSms(SmsRecords smsRecords){
        return new ResultBean<>(ResultEnum.SUCCESS,this.insert(smsRecords));
    }
}
