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.SmartAuthorityMapper;
import com.template.model.pojo.SmartAuthorGroup;
import com.template.model.pojo.SmartAuthority;
import com.template.model.pojo.SmartAuthority;
import com.template.mapper.SmartAuthorityMapper;
import com.template.model.result.PageUtils;
import com.template.services.SmartAuthorityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2023-12-04
 */
@Service
public class SmartAuthorityServiceImpl extends ServiceImpl<SmartAuthorityMapper, SmartAuthority> implements SmartAuthorityService {
    @Autowired
    private SmartAuthorityMapper smartAuthorityMapper;

    @Override
    public int insertSmartAuthority(SmartAuthority sa) {
        int result = smartAuthorityMapper.insert(sa);
        return result;
    }

    @Override
    public int updateSmartAuthority(SmartAuthority sa) {
        int result = smartAuthorityMapper.updateById(sa);
        return result;
    }

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

    @Override
    public int deleteSmartAuthorityById(int id) {
        int result = smartAuthorityMapper.deleteById(id);
        return result;
    }

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

    @Override
    public List<SmartAuthority> getAuthorByKey(QueryWrapper<SmartAuthority> queryWrapper) {
        List<SmartAuthority> result = smartAuthorityMapper.selectList(queryWrapper);
        return result;
    }

}
