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.SmartBuildMapper;
import com.template.model.pojo.SmartBuild;
import com.template.mapper.SmartBuildMapper;
import com.template.model.pojo.SmartBuild;
import com.template.model.result.PageUtils;
import com.template.services.SmartBuildService;
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 SmartBuildServiceImpl extends ServiceImpl<SmartBuildMapper, SmartBuild> implements SmartBuildService {
    @Autowired
    private SmartBuildMapper smartBuildMapper;

    @Override
    public int insertSmartBuild(SmartBuild sa) {
        int result = smartBuildMapper.insert(sa);
        return result;
    }

    @Override
    public int updateSmartBuild(SmartBuild sa) {
        int result = smartBuildMapper.updateById(sa);
        return result;
    }

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

    @Override
    public int deleteSmartBuildById(int id) {
        int result = smartBuildMapper.deleteById(id);
        return result;
    }

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