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.SmartBuildMeterMapper;
import com.template.model.pojo.SmartBuildMeter;
import com.template.model.pojo.SmartBuildMeter;
import com.template.mapper.SmartBuildMeterMapper;
import com.template.model.result.PageUtils;
import com.template.services.SmartBuildMeterService;
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 SmartBuildMeterServiceImpl extends ServiceImpl<SmartBuildMeterMapper, SmartBuildMeter> implements SmartBuildMeterService {
    @Autowired
    private SmartBuildMeterMapper smartBuildMeterMapper;

    @Override
    public int insertSmartBuildMeter(SmartBuildMeter sa) {
        int result = smartBuildMeterMapper.insert(sa);
        return result;
    }

    @Override
    public int updateSmartBuildMeter(SmartBuildMeter sa) {
        int result = smartBuildMeterMapper.updateById(sa);
        return result;
    }

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

    @Override
    public int deleteSmartBuildMeterById(int id) {
        int result = smartBuildMeterMapper.deleteById(id);
        return result;
    }

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