package com.sky.ioc.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sky.ioc.entity.domain.security.SecurityPerson;
import com.sky.ioc.entity.params.security.PersonParam;
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 SecurityPersonMapper extends BaseMapper<SecurityPerson> {
  @Select("<script>" +
          " SELECT name,work_number,phone,type,duty.scope,duty_start_time,duty_end_time,photo " +
          "from security_person_duty duty LEFT JOIN security_person person on duty.security_person_id = person.id " +
          "where 1=1 " +
          "<if test='personParam!=null and personParam.type!=null'>" +
          " and person.type = #{personParam.type} " +
          "</if>" +
          "<if test='personParam!=null and personParam.name!=null and personParam.name!=\"\" '>" +
          " and person.name like #{personParam.name} " +
          "</if>" +
          "<if test='personParam!=null and personParam.startTime!= null'>" +
          " and duty_start_time between  #{personParam.startTime} and #{personParam.endTime} " +
          " and duty_end_time between  #{personParam.startTime} and #{personParam.endTime} " +
          "</if>" +
          " order by person.id limit #{personParam.pageSize} offset #{personParam.pageStart} " +
          "</script>")
  List<Map<String,Object>> getListByTimeAndName(@Param("personParam")PersonParam personParam);

}
