package com.sky.ioc.mapper.security;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sky.ioc.entity.domain.security.SecurityDoorRecord;
import com.sky.ioc.entity.params.scene.DoorAccessParam;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface SecurityDoorRecordMapper extends BaseMapper<SecurityDoorRecord> {

    @Select("<script>" +
            "SELECT record.id, record.name,record.time,door.name as doorName,record.dept_id as deptId " +
            "from  security_door_record record " +
            "LEFT JOIN security_door door on record.door_id = door.id " +
            "where 1=1 " +
            "<if test='doorAccessParam!=null and doorAccessParam.startTime!=null'>" +
            " and record.time BETWEEN  #{doorAccessParam.startTime} AND #{doorAccessParam.endTime}" +
            "</if>" +
            "<if test='doorAccessParam!=null and doorAccessParam.name!=\"\" and doorAccessParam.name!=null'>" +
            " and record.name like #{doorAccessParam.name} " +
            "</if>" +
            "<if test='doorAccessParam!=null and doorAccessParam.equipment!=\"\" and doorAccessParam.equipment!=null'>" +
            " and door.name like #{doorAccessParam.equipment} " +
            "</if>" +
            "<if test='doorAccessParam!=null and doorAccessParam.deptId!=null'>" +
            " and record.dept_id = #{doorAccessParam.deptId} " +
            "</if>" +
            "ORDER BY record.id " +
            "limit #{doorAccessParam.pageSize} OFFSET  #{doorAccessParam.pageStart}" +
            "</script>")
    List<Map<String,Object>> pageList(@Param("doorAccessParam")DoorAccessParam doorAccessParam);

    @Select("<script>" +
            "SELECT count(1) " +
            "from  security_door_record record " +
            "LEFT JOIN security_door door on record.door_id = door.id " +
            "where 1=1 " +
            "<if test='doorAccessParam!=null and doorAccessParam.startTime!=null'>" +
            " and record.time between #{doorAccessParam.startTime} and #{doorAccessParam.endTime}" +
            "</if>" +
            "<if test='doorAccessParam!=null and doorAccessParam.name!=\"\" and doorAccessParam.name!=null'>" +
            " and record.name like #{doorAccessParam.name} " +
            "</if>" +
            "<if test='doorAccessParam!=null and doorAccessParam.equipment!=\"\" and doorAccessParam.equipment!=null'>" +
            " and door.name like #{doorAccessParam.equipment} " +
            "</if>" +
            "<if test='doorAccessParam!=null and doorAccessParam.deptId!=null'>" +
            " and record.dept_id = #{doorAccessParam.deptId} " +
            "</if>" +
            "</script>")
    Long  pageCount(@Param("doorAccessParam")DoorAccessParam doorAccessParam);
}
