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.SmartVisitorMapper;
import com.template.model.pojo.SmartVisitor;
import com.template.model.pojo.SmartVisitor;
import com.template.mapper.SmartVisitorMapper;
import com.template.model.result.PageUtils;
import com.template.model.vo.VisitorPageVo;
import com.template.services.SmartVisitorService;
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 2023-12-04
 */
@Service
public class SmartVisitorServiceImpl extends ServiceImpl<SmartVisitorMapper, SmartVisitor> implements SmartVisitorService {
    @Autowired
    private SmartVisitorMapper smartVisitorMapper;

    @Override
    public int insertSmartVisitor(SmartVisitor sa) {
        int result = smartVisitorMapper.insert(sa);
        return result;
    }

    @Override
    public int updateSmartVisitor(SmartVisitor sa) {
        int result = smartVisitorMapper.updateById(sa);
        return result;
    }

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

    @Override
    public int deleteSmartVisitorById(int id) {
        int result = smartVisitorMapper.deleteById(id);
        return result;
    }

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

    @Override
    public boolean insertVisitorBatch(List<SmartVisitor> visitors) {
        boolean result = this.saveBatch(visitors);
        return result;
    }

    @Override
    public PageUtils<VisitorPageVo> smartVisitorPageByUserId(int currentPage, int pageCount, Integer userId, Integer statu, String createStartTime, String createEndTime, String keyWord, String visitorStartTime, String visitorEndTime) {
        Page<VisitorPageVo> page = new Page<>();
        page.setCurrent(currentPage);
        page.setSize(pageCount);
        IPage<VisitorPageVo> datas = smartVisitorMapper.queryVisitorPage(page, userId, statu, createStartTime, createEndTime, keyWord, visitorStartTime, visitorEndTime);
        return new PageUtils(datas);
    }

    @Override
    public Integer queryVisitorCount(String cardNo, String startTime, String endTime) {
        Integer result = smartVisitorMapper.queryVisitorCount(cardNo, startTime, endTime);
        return result;
    }

    @Override
    public PageUtils<SmartVisitor> queryVisitorPageDatas(int currentPage, int pageCount, Integer type, List<Integer> studentIds, String isAdmin) {
        Page<SmartVisitor> page = new Page<>();
        page.setCurrent(currentPage);
        page.setSize(pageCount);
        IPage<SmartVisitor> datas = smartVisitorMapper.queryVisitorPageDatas(page, type, studentIds, isAdmin);
        return new PageUtils(datas);
    }
}
