package com.template.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.template.model.pojo.SmartAccess;
import com.template.mapper.SmartAccessMapper;
import com.template.model.pojo.SmartFaceDiscern;
import com.template.model.result.PageUtils;
import com.template.model.vo.SmartAccessVo;
import com.template.model.vo.VisitorPageVo;
import com.template.services.SmartAccessService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2024-05-31
 */
@Service
public class SmartAccessServiceImpl extends ServiceImpl<SmartAccessMapper, SmartAccess> implements SmartAccessService {

    @Autowired
    SmartAccessMapper smartAccessMapper;

    @Override
    public List<SmartAccess> track(String stateTime, String endTime, Integer id) {
        LambdaQueryWrapper<SmartAccess> wrapper = new LambdaQueryWrapper<>();
        wrapper.between(SmartAccess::getDateTime, stateTime, endTime)
                .eq(SmartAccess::getUserId, id)
                .orderByDesc(SmartAccess::getDateTime);
        List<SmartAccess> list = this.list(wrapper);
        return list;
    }

    @Override
    public PageUtils<SmartAccessVo> getPage(Integer currentPage, Integer pageCount,String keyWord,Integer gradeId, Integer classId, Integer departmentId, String openType,String resultStatus,String startTime,String endTime) {
        Page<SmartAccessVo> page = new Page<>();
        page.setCurrent(currentPage);
        page.setSize(pageCount);
        IPage<SmartAccessVo> datas = smartAccessMapper.getPage(page,keyWord,gradeId,classId,departmentId,openType,resultStatus,startTime,endTime);
        return new PageUtils(datas);
    }

    @Override
    public List<SmartAccessVo> getPageExport(String keyWord, Integer gradeId, Integer classId, Integer departmentId, String openType,String resultStatus, String startTime, String endTime) {
        List<SmartAccessVo> vos = smartAccessMapper.getPageExport(keyWord,gradeId,classId,departmentId,openType,resultStatus,startTime,endTime);
        return vos;
    }

    @Override
    public PageUtils<SmartAccessVo> getAccessPage(Integer currentPage, Integer pageCount, String keyWord, Integer gradeId, Integer classId, String resultStatus, String inOut, String startTime, String endTime) {
        Page<SmartAccessVo> page = new Page<>();
        page.setCurrent(currentPage);
        page.setSize(pageCount);
        IPage<SmartAccessVo> datas = smartAccessMapper.getAccessPage(page,keyWord,gradeId,classId,resultStatus,inOut,startTime,endTime);
        return new PageUtils(datas);
    }

    @Override
    public List<SmartAccess> toDatelist(LocalDateTime start, LocalDateTime end) {
        List<SmartAccess> list = smartAccessMapper.toDatelist(start,end);
        return list;
    }

    @Override
    public List<SmartAccess> toDateAndPlacelist(LocalDateTime startTime, LocalDateTime endTime, String type) {
        List<SmartAccess> list = smartAccessMapper.toDateAndPlacelist(startTime,endTime,type);
        return list;
    }
}
