package com.template.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.template.mapper.SmartBuildMapper;
import com.template.model.pojo.SmartApply;
import com.template.model.pojo.SmartBuild;
import com.template.model.pojo.SmartTimeGroup;
import com.template.mapper.SmartTimeGroupMapper;
import com.template.services.SmartTimeGroupService;
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 2024-04-12
 */
@Service
public class SmartTimeGroupServiceImpl extends ServiceImpl<SmartTimeGroupMapper, SmartTimeGroup> implements SmartTimeGroupService {

    @Autowired
    private SmartTimeGroupMapper smartTimeGroupMapper;

    @Override
    public boolean insertSmartTimeGroups(List<SmartTimeGroup> stgs) {
        boolean result = this.saveBatch(stgs);
        return result;
    }

    @Override
    public boolean updateSmartTimeGroups(List<SmartTimeGroup> stgs) {
        boolean result = this.updateBatchById(stgs);
        return result;
    }

    @Override
    public List<SmartTimeGroup> queryTimeGroups() {
        List<SmartTimeGroup> result = smartTimeGroupMapper.selectList(null);
        return result;
    }

    @Override
    public SmartTimeGroup queryTimeGroupById(Integer id) {
        SmartTimeGroup result = smartTimeGroupMapper.selectById(id);
        return result;
    }

    @Override
    public SmartTimeGroup queryTimeGroupByName(String name) {
        QueryWrapper<SmartTimeGroup> queryWrapper = new QueryWrapper();
        queryWrapper.eq(StringUtils.hasText(name),"name",name);
        SmartTimeGroup result = smartTimeGroupMapper.selectOne(queryWrapper);
        return result;
    }

    @Override
    public int deletedTimeGroupByIds(List<Integer> ids) {
        QueryWrapper<SmartTimeGroup> queryWrapper = new QueryWrapper();
        queryWrapper.in("id", ids);
        int result = smartTimeGroupMapper.delete(queryWrapper);
        return result;
    }
}
