package com.template.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.template.mapper.SmartIdentityMapper;
import com.template.model.pojo.SmartIdentity;
import com.template.model.result.PageUtils;
import com.template.services.SmartIdentityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2023-12-04
 */
@Service
public class SmartIdentityServiceImpl extends ServiceImpl<SmartIdentityMapper, SmartIdentity> implements SmartIdentityService {
    @Autowired
    private SmartIdentityMapper smartIdentityMapper;

    @Override
    public int insertSmartIdentity(SmartIdentity sa) {
        int result = smartIdentityMapper.insert(sa);
        return result;
    }

    @Override
    public int updateSmartIdentity(SmartIdentity sa) {
        int result = smartIdentityMapper.updateById(sa);
        return result;
    }

    @Override
    public SmartIdentity queryIdentityByName(String name){
        QueryWrapper<SmartIdentity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name);
        SmartIdentity result = smartIdentityMapper.selectOne(queryWrapper);
        return result;
    }

    @Override
    public PageUtils<SmartIdentity> queryPageSmartIdentitys(int currentPage, int pageCount, String name) {
        Page<SmartIdentity> page = new Page<>(currentPage, pageCount);
        QueryWrapper<SmartIdentity> queryWrapper = new QueryWrapper<>();
        //queryWrapper.like(StringUtils.hasText(name), "name", name);
        IPage<SmartIdentity> result = smartIdentityMapper.selectPage(page,queryWrapper);
        return new PageUtils<>(result);
    }

    @Override
    public int deleteSmartIdentityById(int id) {
        int result = smartIdentityMapper.deleteById(id);
        return result;
    }

    @Override
    public SmartIdentity getSmartById(int id) {
        SmartIdentity result = smartIdentityMapper.selectById(id);
        return result;
    }

    @Override
    public List<SmartIdentity> querySmartIdentityDatas(int id){
        List<SmartIdentity> result = smartIdentityMapper.querySmartIdentityDatas(id);
        return result;
    }

}
