<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="SapCheckReportMapper">
	<select id="selectReportDayList" resultType="java.util.LinkedHashMap">
		SELECT c.firstDepartName,c.secondDepartName, a.userId, a.name, ${reportDaySql}
		from sap_check_report a, wx_user c
		where a.userId = c.userId and a.checkinDay >= #{startDate} and a.checkinDay &lt;= #{endDate}
		<if test="name != null and name != ''">
			and a.name like CONCAT(CONCAT('%', #{name}),'%')
		</if>
		<if test="departId != null and departId != ''">
			and (c.firstDepartId=#{departId} or c.secondDepartId=#{departId})
		</if>
		group by c.firstDepartName,c.secondDepartName, a.userId, a.name
		order by a.userId
	</select>
	
	<select id="findUserReports" resultType="java.util.LinkedHashMap">
		SELECT c.firstDepartName,c.secondDepartName,a.userId,groupName,workTime,offWorkTime,a.name,a.checkinDay,
			checkinDate,checkinException,checkoffDate,checkoffException,checkoutDate1,checkoutDate2,leaveCreatedTime,
			leaveStartDate,leaveEndDate,leaveDay,leaveComment,bukaDay,result
		from sap_check_report a, sap_checkdate b, wx_user c 
		where a.checkinDay=b.checkinDay and a.userId = c.userId
		<if test="departId != null and departId != ''">
			and (c.firstDepartId=#{departId} or c.secondDepartId=#{departId})
		</if>
		<if test="startDate != null and startDate != ''">
			and a.checkinDay >= #{startDate} 
		</if>
		<if test="endDate != null and endDate != ''">
			and a.checkinDay &lt;= #{endDate} 
		</if>
		<if test="name != null and name != ''">
			and a.name like CONCAT(CONCAT('%', #{name}),'%')
		</if>
		<if test="state != null and state != ''">
			and a.result = #{state} 
		</if>
		order by a.userId, a.checkinDay 
		<if test="pageCurrent != null and pageCurrent != ''">
			limit ${pageCurrent},${pageSize}
		</if>
	</select>
	
	<select id="findUserReportTotal" resultType="Long">
		SELECT count(1) 
		from sap_check_report a, sap_checkdate b, wx_user c 
		where a.checkinDay=b.checkinDay and a.userId = c.userId
		<if test="departId != null and departId != ''">
			and (c.firstDepartId=#{departId} or c.secondDepartId=#{departId})
		</if>
		<if test="startDate != null and startDate != ''">
			and a.checkinDay >= #{startDate} 
		</if>
		<if test="endDate != null and endDate != ''">
			and a.checkinDay &lt;= #{endDate} 
		</if>
		<if test="name != null and name != ''">
			and a.name like CONCAT(CONCAT('%', #{name}),'%')
		</if>
		<if test="state != null and state != ''">
			and a.result = #{state} 
		</if>
	</select>
</mapper>