package com.template.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.template.mapper.SmartUserMapper;
import com.template.model.pojo.SmartFamilyIndex;
import com.template.mapper.SmartFamilyIndexMapper;
import com.template.services.SmartFamilyIndexService;
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-23
 */
@Service
public class SmartFamilyIndexServiceImpl extends ServiceImpl<SmartFamilyIndexMapper, SmartFamilyIndex> implements SmartFamilyIndexService {

    @Autowired
    private SmartFamilyIndexMapper smartFamilyIndexMapper;

    @Override
    public SmartFamilyIndex queryFamilyByPhoneCardNo(String phone, String cardNo) {
        QueryWrapper<SmartFamilyIndex> queryWrapper = new QueryWrapper();
        queryWrapper.eq(StringUtils.hasText(phone), "parent_phone", phone);
        queryWrapper.eq(StringUtils.hasText(cardNo), "student_no", cardNo);
        SmartFamilyIndex result = smartFamilyIndexMapper.selectOne(queryWrapper);
        return result;
    }

    @Override
    public List<SmartFamilyIndex> querySmartFamilyByCardNo(String cardNo) {
        QueryWrapper<SmartFamilyIndex> queryWrapper = new QueryWrapper();
        queryWrapper.eq(StringUtils.hasText(cardNo), "student_no", cardNo);
        queryWrapper.orderByAsc("index_data");
        List<SmartFamilyIndex> indexs = smartFamilyIndexMapper.selectList(queryWrapper);
        return indexs;
    }

    @Override
    public int deleteSmartFamilyByPhone(String phone) {
        QueryWrapper<SmartFamilyIndex> queryWrapper = new QueryWrapper();
        queryWrapper.eq(StringUtils.hasText(phone), "parent_phone", phone);
        int result = smartFamilyIndexMapper.delete(queryWrapper);
        return result;
    }

    @Override
    public int deleteSmartFamilyByCardNo(String cardNo) {
        QueryWrapper<SmartFamilyIndex> queryWrapper = new QueryWrapper();
        queryWrapper.eq(StringUtils.hasText(cardNo), "student_no", cardNo);
        int result = smartFamilyIndexMapper.delete(queryWrapper);
        return result;
    }

    @Override
    public int updateSmartFamily(SmartFamilyIndex sfi) {
        int result = smartFamilyIndexMapper.updateById(sfi);
        return result;
    }

    @Override
    public int deleteSmartFamilyByIds(List<Integer> ids) {
        int result = smartFamilyIndexMapper.deleteBatchIds(ids);
        return result;
    }
}
