package thyyxxk.webserver.dao.his.reports;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.clockin.Clockin;

import java.util.Date;
import java.util.List;

@Mapper
public interface ClockinDao {

    @Select("select ltrim(rtrim(code_rs)) from a_employee_mi with(nolock) " +
            "where isnull(del_flag, 0)=0 and isnull(dept_code,'')!='3100000'")
    List<String> getAllEmployeeExceptItDept();

    @Select("select ltrim(rtrim(code_rs)) from a_employee_mi with(nolock) where " +
            "isnull(del_flag, 0)=0 and dept_code='3100000' and code_rs!='0000'")
    List<String> getAllEmployeeInItDept();

    @Insert("<script>" +
            "insert into clock_in (groupname, checkin_type, exception_type, checkin_time, " +
            "location_title, location_detail, userid, checkin_date, checkin_hour, notes) values " +
            "<foreach collection='list' item='dk' open='' separator=',' close=''>" +
            "(#{dk.groupname}, #{dk.checkinType}, #{dk.exceptionType}, #{dk.checkinTime}, " +
            "#{dk.locationTitle}, #{dk.locationDetail}, #{dk.userid}, #{dk.checkinDate}, " +
            "#{dk.checkinHour}, #{dk.notes})" +
            "</foreach>" +
            "</script>")
    void insertIntoTable(List<Clockin> list);

    @Select("select a.*, rtrim(b.name) name, rtrim(c.name) dept " +
            "from clock_in a with(nolock), a_employee_mi b with(nolock), zd_unit_code c with(nolock) " +
            "where a.checkin_time>#{start} and a.checkin_time<#{end} " +
            "and a.userid = b.code_rs and isnull(b.del_flag, 0)!=1 " +
            "and c.code=b.dept_code order by checkin_date,userid")
    IPage<Clockin> getAllClockInDataFromDb(IPage<Clockin> iPage, @Param("start") Date start, @Param("end") Date end);
}
