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.SmartMeterMapper;
import com.template.model.pojo.SmartMeter;
import com.template.mapper.SmartMeterMapper;
import com.template.model.pojo.SmartMeter;
import com.template.model.result.PageUtils;
import com.template.services.SmartMeterService;
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 SmartMeterServiceImpl extends ServiceImpl<SmartMeterMapper, SmartMeter> implements SmartMeterService {
    @Autowired
    private SmartMeterMapper smartMeterMapper;

    @Override
    public int insertSmartMeter(SmartMeter sa) {
        int result = smartMeterMapper.insert(sa);
        return result;
    }

    @Override
    public int updateSmartMeter(SmartMeter sa) {
        int result = smartMeterMapper.updateById(sa);
        return result;
    }

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

    @Override
    public int deleteSmartMeterById(int id) {
        int result = smartMeterMapper.deleteById(id);
        return result;
    }

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