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.SmartMeterDetailMapper;
import com.template.model.pojo.SmartMeterDetail;
import com.template.model.pojo.SmartMeterDetail;
import com.template.mapper.SmartMeterDetailMapper;
import com.template.model.result.PageUtils;
import com.template.services.SmartMeterDetailService;
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;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2023-12-04
 */
@Service
public class SmartMeterDetailServiceImpl extends ServiceImpl<SmartMeterDetailMapper, SmartMeterDetail> implements SmartMeterDetailService {
    @Autowired
    private SmartMeterDetailMapper smartMeterDetailMapper;

    @Override
    public int insertSmartMeterDetail(SmartMeterDetail sa) {
        int result = smartMeterDetailMapper.insert(sa);
        return result;
    }

    @Override
    public int updateSmartMeterDetail(SmartMeterDetail sa) {
        int result = smartMeterDetailMapper.updateById(sa);
        return result;
    }

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

    @Override
    public int deleteSmartMeterDetailById(int id) {
        int result = smartMeterDetailMapper.deleteById(id);
        return result;
    }

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