package com.sky.ioc.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sky.ioc.entity.domain.parking.Parking;
import com.sky.ioc.entity.params.IocParam;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ParkingMapper extends BaseMapper<Parking> {

    @Select("<script>" +
            "SELECT count(1) FROM parking where 1=1 " +
            "<if test='iocParam!=null and iocParam.companyId != null '>" +
            " and company_id=#{iocParam.companyId} " +
            "</if>"+
            "</script>")
    Integer getTotalParkingByCompanyIdAndDeptId(@Param("iocParam") IocParam iocParam);

    @Select("<script>" +
            "SELECT * FROM parking where 1=1 " +
            "<if test='iocParam!=null and iocParam.companyId != null '>" +
            " and company_id=#{iocParam.companyId} " +
            "</if>"+
            " order by parking_numbers limit 100 OFFSET 0 </script>")
    List<Parking> getListByCompanyIdAndDeptId(@Param("iocParam") IocParam iocParam);

    @Select("<script>" +
            "SELECT parking.*, COUNT(park.id) AS tcount " +
            "FROM parking LEFT JOIN park ON parking.parking_numbers = park.parking_numbers " +
            "GROUP BY parking.ID HAVING COUNT(park.id)>0 ORDER BY tcount" +
            "</script>")
    List<Parking> getVacancyList(@Param("iocParam") IocParam iocParam);
}
