<?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="com.zcloud.mapper.datasource.bus.ForeignCarMapper">

	<!--外来车辆表名 -->
	<sql id="tableName">
		BUS_FOREIGNCAR
	</sql>

	<!--数据字典表名 -->
	<sql id="dicTableName">
		SYS_DICTIONARIES
	</sql>

	<!-- 字段 -->
	<sql id="Field">
		FOREIGNCAR_ID,
		SOURCE_UNIT,
		LICENSE_PLATE,
		APPLICATION_TIME,
		MODEL,
		COMING_REASON,
		STATE,
		NUMBER_PEOPLE_CAR,
		ISDELETE,
		CREATOR,
		CREATTIME,
		OPERATOR,
		OPERATTIME,
		DEPARTMENT_ID,
		APPLY_SOURCE,
		APPLYTIME,
		EXAMINE_DEPARTMENT_ID,
		EXAMINE_PEOPLE,
		APPROVE_DEPARTMENT_ID,
		APPROVE_PEOPLE,
		CONFIRM_DEPARTMENT_ID,
		CONFIRM_PEOPLE,
		CORPINFO_ID,
		STARTTIME,
		ENDTIME,
		REJECTOPINION
	</sql>

	<!-- 字段 -->
	<sql id="Field1">
		f.FOREIGNCAR_ID,
		f.SOURCE_UNIT,
		f.LICENSE_PLATE,
		f.APPLICATION_TIME,
		f.MODEL,
		f.COMING_REASON,
		f.STATE,
		f.NUMBER_PEOPLE_CAR,
		f.ISDELETE,
		f.CREATOR,
		f.CREATTIME,
		f.OPERATOR,
		f.OPERATTIME,
		f.DEPARTMENT_ID,
		f.APPLY_SOURCE,
		f.APPLYTIME,
		f.EXAMINE_DEPARTMENT_ID,
		f.EXAMINE_PEOPLE,
		f.APPROVE_DEPARTMENT_ID,
		f.APPROVE_PEOPLE,
		f.CONFIRM_DEPARTMENT_ID,
		f.CONFIRM_PEOPLE,
		f.CORPINFO_ID,
		f.STARTTIME,
		f.ENDTIME,
		f.REJECTOPINION
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{FOREIGNCAR_ID},
		#{SOURCE_UNIT},
		#{LICENSE_PLATE},
		#{APPLICATION_TIME},
		#{MODEL},
		#{COMING_REASON},
		#{STATE},
		#{NUMBER_PEOPLE_CAR},
		#{ISDELETE},
		#{CREATOR},
		#{CREATTIME},
		#{OPERATOR},
		#{OPERATTIME},
		#{DEPARTMENT_ID},
		#{APPLY_SOURCE},
		#{APPLYTIME},
		#{EXAMINE_DEPARTMENT_ID},
		#{EXAMINE_PEOPLE},
		#{APPROVE_DEPARTMENT_ID},
		#{APPROVE_PEOPLE},
		#{CONFIRM_DEPARTMENT_ID},
		#{CONFIRM_PEOPLE},
		#{CORPINFO_ID},
		#{STARTTIME},
		#{ENDTIME},
		#{REJECTOPINION}
	</sql>

	<!-- 新增-->
	<insert id="save" parameterType="pd">
		insert into
	<include refid="tableName"></include>
		(
	<include refid="Field"></include>
		) values (
	<include refid="FieldValue"></include>
		)
	</insert>

	<!-- 删除-->
	<delete id="delete" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			ISDELETE = '1',
			OPERATOR = #{OPERATOR},
			OPERATTIME = #{OPERATTIME}
		where
			FOREIGNCAR_ID = #{FOREIGNCAR_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			SOURCE_UNIT        = #{SOURCE_UNIT},
			LICENSE_PLATE      = #{LICENSE_PLATE},
			APPLICATION_TIME   = #{APPLICATION_TIME},
			MODEL              = #{MODEL},
			NUMBER_PEOPLE_CAR  = #{NUMBER_PEOPLE_CAR}
			<if test="STATE != null and STATE != ''">
			,STATE = #{STATE}
			</if>		where
			FOREIGNCAR_ID = #{FOREIGNCAR_ID}
	</update>

	<!-- 修改 -->
	<update id="editState" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			STATE = #{STATE}
		<if test="EXAMINE_PEOPLE != null and EXAMINE_PEOPLE != ''">
			,EXAMINE_PEOPLE = #{EXAMINE_PEOPLE}
		</if>
		<if test="APPROVE_DEPARTMENT_ID != null and APPROVE_DEPARTMENT_ID != ''">
			,APPROVE_DEPARTMENT_ID = #{APPROVE_DEPARTMENT_ID}
		</if>
		<if test="APPROVE_PEOPLE != null and APPROVE_PEOPLE != ''">
			,APPROVE_PEOPLE = #{APPROVE_PEOPLE}
		</if>
		<if test="CONFIRM_DEPARTMENT_ID != null and CONFIRM_DEPARTMENT_ID != ''">
			,CONFIRM_DEPARTMENT_ID = #{CONFIRM_DEPARTMENT_ID}
		</if>
		<if test="CONFIRM_PEOPLE != null and CONFIRM_PEOPLE != ''">
			,CONFIRM_PEOPLE = #{CONFIRM_PEOPLE}
		</if>
		<if test="REJECTOPINION != null and REJECTOPINION != ''">
			,REJECTOPINION = #{REJECTOPINION}
		</if>
		<if test="TIME_IN != null and TIME_IN != ''">
			,TIME_IN = #{TIME_IN}
		</if>
		<if test="TIME_OUT != null and TIME_OUT != ''">
			,TIME_OUT = #{TIME_OUT}
		</if>
		where
		FOREIGNCAR_ID = #{FOREIGNCAR_ID}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		<include refid="Field1"></include>
		,CONCAT_WS('', od.NAME, ':', u.NAME, ' ', f.APPLY_SOURCE) NAME
		,d1.NAME MODEL_NAME
		,f.TIME_IN,f.TIME_OUT
		from
		<include refid="tableName"></include> f
		LEFT JOIN OA_DEPARTMENT od ON od.DEPARTMENT_ID = f.DEPARTMENT_ID
		LEFT JOIN SYS_USER u ON u.USER_ID = f.CREATOR
		left join <include refid="dicTableName"></include> d1 on d1.BIANMA = f.MODEL and d1.PARENT_ID = 'c1d7ddc73eea4219952f28814d33b845'
		where
		f.FOREIGNCAR_ID = #{FOREIGNCAR_ID}
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
		<include refid="Field1"></include>
		,CONCAT_WS('', od.NAME, ':', u.NAME, ' ', f.APPLY_SOURCE) NAME
		,d1.NAME MODEL_NAME
		from
		<include refid="tableName"></include> f
		LEFT JOIN OA_DEPARTMENT od ON od.DEPARTMENT_ID = f.DEPARTMENT_ID
		LEFT JOIN SYS_USER u ON u.USER_ID = f.CREATOR
		LEFT JOIN <include refid="dicTableName"></include> d1 on d1.BIANMA = f.MODEL and d1.PARENT_ID = 'c1d7ddc73eea4219952f28814d33b845'
		where f.ISDELETE = '0'
		<if test="pd.CREATOR != null and pd.CREATOR != ''">
			and f.CREATOR = #{pd.CREATOR}
		</if>
		<if test="pd.CORPINFO_ID != null and pd.CORPINFO_ID != ''">
			and f.CORPINFO_ID = #{pd.CORPINFO_ID}
		</if>
		<if test="pd.SOURCE_UNIT != null and pd.SOURCE_UNIT != ''">
			and f.SOURCE_UNIT LIKE CONCAT(CONCAT('%', #{pd.SOURCE_UNIT}),'%')
		</if>
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''">
			and f.SOURCE_UNIT LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
		</if>
		<if test="pd.STATE != null and pd.STATE != ''">
			and f.STATE = #{pd.STATE}
		</if>
		<if test="pd.STARTTIME != null and pd.STARTTIME != ''">
			and f.STARTTIME <![CDATA[ >= ]]> CONCAT_WS(' ', #{pd.STARTTIME}, '00:00')
		</if>
		<if test="pd.ENDTIME != null and pd.ENDTIME != ''">
			and f.STARTTIME <![CDATA[ <= ]]> CONCAT_WS(' ', #{pd.ENDTIME}, '23:59')
		</if>
		group by f.FOREIGNCAR_ID
		order by f.OPERATTIME desc ,f.APPLYTIME desc

	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field1"></include>
		,c.CORP_NAME
		,de.NAME as DEPT_NAME
		,d1.NAME MODEL_NAME
		from
		<include refid="tableName"></include> f
		left join BUS_CORP_INFO c on c.CORPINFO_ID = f.CORPINFO_ID
		left join OA_DEPARTMENT de on de.DEPARTMENT_ID = f.DEPARTMENT_ID
		LEFT JOIN <include refid="dicTableName"></include> d1 on d1.BIANMA = f.MODEL and d1.PARENT_ID = 'c1d7ddc73eea4219952f28814d33b845'
		where f.ISDELETE = '0'
		<if test="CORPINFO_ID != null and CORPINFO_ID != ''"><!-- 关键词检索 -->
			and f.CORPINFO_ID = #{CORPINFO_ID}
		</if>
		<if test="CHECK_NAME != null and CHECK_NAME != ''"><!-- 重名验证专用 -->
			AND
				f.RISKUNITNAME = #{CHECK_NAME}
		</if>
		<if test="DEPARTMENT_ID != null and DEPARTMENT_ID != ''"><!-- 重名验证专用 -->
			AND
				f.DEPARTMENT_ID = #{DEPARTMENT_ID}
		</if>
		order by f.OPERATTIME desc
	</select>

	<!-- 列表(首页) -->
	<select id="listIndexAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field1"></include>,
		c.CORP_NAME,
		de.NAME as DEPT_NAME
		from
		<include refid="tableName"></include> f
		left join BUS_CORP_INFO c on c.CORPINFO_ID = f.CORPINFO_ID
		left join OA_DEPARTMENT de on de.DEPARTMENT_ID = f.DEPARTMENT_ID
		where f.ISDELETE = '0'
		<if test="CORPINFO_ID != null and CORPINFO_ID != ''"><!-- 关键词检索 -->
			and f.CORPINFO_ID = #{CORPINFO_ID}
		</if>
		group by f.RISKUNITNAME
		order by f.OPERATTIME desc
	</select>

	<!-- 批量删除 -->
	<delete id="deleteAll" parameterType="String">
		update
		<include refid="tableName"></include>
		set
			ISDELETE = '1'
		where
			RISKUNIT_ID in
		<foreach item="item" index="index" collection="ArrayDATA_IDS" open="(" separator="," close=")">
                 #{item}
		</foreach>
	</delete>
  <!--  根据外来车辆ID查询 -->
	<select id="getForeignCarById" parameterType="page" resultType="pd">
		select
			<include refid="Field1"></include>
			,f.TIME_IN,f.TIME_OUT
		FROM
			<include refid="tableName"></include> f
		WHERE
			f.FOREIGNCAR_ID = #{pd.FOREIGNCAR_ID}
		and f.ISDELETE = '0'
		order by f.OPERATTIME desc

	</select>

	<!-- 部门审核列表 -->
	<select id="examinelistPage" parameterType="page" resultType="pd">
		select
		f.FOREIGNCAR_ID,
		f.SOURCE_UNIT,
		f.LICENSE_PLATE,
		f.APPLICATION_TIME,
		f.MODEL,
		f.STATE,
		f.NUMBER_PEOPLE_CAR,
		f.EXAMINE_DEPARTMENT_ID,
		f.STARTTIME,
		f.ENDTIME,
		d1.NAME MODEL_NAME,
		CONCAT_WS('', od.NAME, ':', u.NAME, ' ', f.APPLY_SOURCE) NAME
		from
		<include refid="tableName"></include> f
			LEFT JOIN OA_DEPARTMENT od ON od.DEPARTMENT_ID = f.DEPARTMENT_ID
			LEFT JOIN SYS_USER u ON u.USER_ID = f.CREATOR
			LEFT JOIN sys_user_examine e ON e.DEPARTMENT_ID = f.EXAMINE_DEPARTMENT_ID
			LEFT JOIN <include refid="dicTableName"></include> d1 on d1.BIANMA = f.MODEL and d1.PARENT_ID = 'c1d7ddc73eea4219952f28814d33b845'
		where f.ISDELETE = '0' and f.EXAMINE_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
		and f.STATE >= 1 and e.USER_ID = #{pd.USER_ID} and e.IS_TO_EXAMINE = '1'
		<if test="pd.CORPINFO_ID != null and pd.CORPINFO_ID != ''">
			and f.CORPINFO_ID = #{pd.CORPINFO_ID}
		</if>
		<if test="pd.STARTTIME != null and pd.STARTTIME != ''">
			and f.STARTTIME <![CDATA[ >= ]]> CONCAT_WS(' ', #{pd.STARTTIME}, '00:00')
		</if>
		<if test="pd.ENDTIME != null and pd.ENDTIME != ''">
			and f.STARTTIME <![CDATA[ <= ]]> CONCAT_WS(' ', #{pd.ENDTIME}, '23:59')
		</if>
<!--		<if test="pd.STARTTIME != null and pd.STARTTIME != ''">-->
<!--			and date (SUBSTR(f.STARTTIME, 1, POSITION(',' IN f.STARTTIME) - 1)) &gt;= date(CONCAT_WS(' ', #{pd.STARTTIME}, '00:00'))-->
<!--		</if>-->
<!--		<if test="pd.ENDTIME != null and pd.ENDTIME != ''">-->
<!--			and date(SUBSTR(f.STARTTIME, POSITION(',' IN f.STARTTIME)+1,LENGTH(f.STARTTIME)-1)) &lt;= date (CONCAT_WS(' ', #{pd.ENDTIME}, '23:59'))-->
<!--		</if>-->
		<if test="pd.SOURCE_UNIT != null and pd.SOURCE_UNIT != ''">
			and f.SOURCE_UNIT LIKE CONCAT(CONCAT('%', #{pd.SOURCE_UNIT}),'%')
		</if>
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''">
			and f.SOURCE_UNIT LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
		</if>
		<if test="pd.STATE != null and pd.STATE != ''">
			and f.STATE = #{pd.STATE}
		</if>
		order by f.OPERATTIME desc

	</select>

	<!-- 安监部审批列表 -->
	<select id="approvallistPage" parameterType="page" resultType="pd">
		select
		f.FOREIGNCAR_ID,
		f.SOURCE_UNIT,
		f.LICENSE_PLATE,
		f.APPLICATION_TIME,
		f.MODEL,
		f.STATE,
		f.NUMBER_PEOPLE_CAR,
		f.EXAMINE_DEPARTMENT_ID,
		f.STARTTIME,
		f.ENDTIME,
		d1.NAME MODEL_NAME,
		CONCAT_WS('', od.NAME, ':', u.NAME, ' ', f.APPLY_SOURCE) NAME
		from
		<include refid="tableName"></include> f
			LEFT JOIN OA_DEPARTMENT od ON od.DEPARTMENT_ID = f.DEPARTMENT_ID
			LEFT JOIN SYS_USER u ON u.USER_ID = f.CREATOR
			LEFT JOIN sys_user_examine e ON e.DEPARTMENT_ID = f.APPROVE_DEPARTMENT_ID
			LEFT JOIN <include refid="dicTableName"></include> d1 on d1.BIANMA = f.MODEL and d1.PARENT_ID = 'c1d7ddc73eea4219952f28814d33b845'
		where f.ISDELETE = '0' and f.APPROVE_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
		and f.STATE >= 2 and e.USER_ID = #{pd.USER_ID} and e.IS_EXAMINE_AND_APPROVE = '1'
		<if test="pd.CORPINFO_ID != null and pd.CORPINFO_ID != ''">
			and f.CORPINFO_ID = #{pd.CORPINFO_ID}
		</if>
		<if test="pd.SOURCE_UNIT != null and pd.SOURCE_UNIT != ''">
			and f.SOURCE_UNIT LIKE CONCAT(CONCAT('%', #{pd.SOURCE_UNIT}),'%')
		</if>
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''">
			and f.SOURCE_UNIT LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
		</if>
		<if test="pd.STATE != null and pd.STATE != ''">
			and f.STATE LIKE CONCAT(CONCAT('%', #{pd.STATE}),'%')
		</if>
		<if test="pd.STATE != null and pd.STATE != ''">
			and f.STATE LIKE CONCAT(CONCAT('%', #{pd.STATE}),'%')
		</if>
<!--		<if test="pd.STATE != null and pd.STATE != ''">-->
<!--			and f.STATE = #{pd.STATE}-->
<!--		</if>-->
<!--		<if test="pd.STARTTIME != null and pd.STARTTIME != ''">-->
<!--			and date (SUBSTR(f.APPLICATION_TIME, 1, POSITION(',' IN f.APPLICATION_TIME) - 1)) &gt;= date(CONCAT_WS(' ', #{pd.STARTTIME}, '00:00'))-->
<!--		</if>-->
<!--		<if test="pd.ENDTIME != null and pd.ENDTIME != ''">-->
<!--			and date(SUBSTR(f.APPLICATION_TIME, POSITION(',' IN f.APPLICATION_TIME)+1,LENGTH(f.APPLICATION_TIME)-1)) &lt;= date (CONCAT_WS(' ', #{pd.ENDTIME}, '23:59'))-->
<!--		</if>-->
		<if test="pd.STARTTIME != null and pd.STARTTIME != ''">
			and f.STARTTIME <![CDATA[ >= ]]> CONCAT_WS(' ', #{pd.STARTTIME}, '00:00')
		</if>
		<if test="pd.ENDTIME != null and pd.ENDTIME != ''">
			and f.STARTTIME <![CDATA[ <= ]]> CONCAT_WS(' ', #{pd.ENDTIME}, '23:59')
		</if>
		order by f.OPERATTIME desc

	</select>

	<!-- 现场确认列表 -->
	<select id="confirmlistPage" parameterType="page" resultType="pd">
		select
		f.FOREIGNCAR_ID,
		f.SOURCE_UNIT,
		f.LICENSE_PLATE,
		f.APPLICATION_TIME,
		f.MODEL,
		f.STATE,
		f.NUMBER_PEOPLE_CAR,
		f.EXAMINE_DEPARTMENT_ID,
		f.STARTTIME,
		f.ENDTIME,
		d1.NAME MODEL_NAME,
		CONCAT_WS('', od.NAME, ':', u.NAME, ' ', f.APPLY_SOURCE) NAME
		from
		<include refid="tableName"></include> f
			LEFT JOIN OA_DEPARTMENT od ON od.DEPARTMENT_ID = f.DEPARTMENT_ID
			LEFT JOIN SYS_USER u ON u.USER_ID = f.CREATOR
			LEFT JOIN sys_user_examine e ON e.DEPARTMENT_ID = f.CONFIRM_DEPARTMENT_ID
			LEFT JOIN <include refid="dicTableName"></include> d1 on d1.BIANMA = f.MODEL and d1.PARENT_ID = 'c1d7ddc73eea4219952f28814d33b845'
		where f.ISDELETE = '0' and f.CONFIRM_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
		and f.STATE >= 3 and e.USER_ID = #{pd.USER_ID} and e.IS_DEPT_CONFIRM = '1'
		<if test="pd.CORPINFO_ID != null and pd.CORPINFO_ID != ''">
			and f.CORPINFO_ID = #{pd.CORPINFO_ID}
		</if>
		<if test="pd.SOURCE_UNIT != null and pd.SOURCE_UNIT != ''">
			and f.SOURCE_UNIT LIKE CONCAT(CONCAT('%', #{pd.SOURCE_UNIT}),'%')
		</if>
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''">
			and f.SOURCE_UNIT LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
		</if>
		<if test="pd.STATE != null and pd.STATE != ''">
			and f.STATE LIKE CONCAT(CONCAT('%', #{pd.STATE}),'%')
		</if>
		<if test="pd.STATE != null and pd.STATE != ''">
			and f.STATE LIKE CONCAT(CONCAT('%', #{pd.STATE}),'%')
		</if>
<!--		<if test="pd.STARTTIME != null and pd.STARTTIME != ''">-->
<!--			and date (SUBSTR(f.APPLICATION_TIME, 1, POSITION(',' IN f.APPLICATION_TIME) - 1)) &gt;= date(CONCAT_WS(' ', #{pd.STARTTIME}, '00:00'))-->
<!--		</if>-->
<!--		<if test="pd.ENDTIME != null and pd.ENDTIME != ''">-->
<!--			and date(SUBSTR(f.APPLICATION_TIME, POSITION(',' IN f.APPLICATION_TIME)+1,LENGTH(f.APPLICATION_TIME)-1)) &lt;= date (CONCAT_WS(' ', #{pd.ENDTIME}, '23:59'))-->
<!--		</if>-->
		<if test="pd.STARTTIME != null and pd.STARTTIME != ''">
			and f.STARTTIME <![CDATA[ >= ]]> CONCAT_WS(' ', #{pd.STARTTIME}, '00:00')
		</if>
		<if test="pd.ENDTIME != null and pd.ENDTIME != ''">
			and f.STARTTIME <![CDATA[ <= ]]> CONCAT_WS(' ', #{pd.ENDTIME}, '23:59')
		</if>
		order by f.OPERATTIME desc

	</select>

	<!-- 统计今日现场车辆情况
	 * 		提交申请数[COUNTAPPLY]，门卫确认进入数[COUNTIN]，现场车辆数[COUNTSITE]，
	 * 		审核通过数[COUNPASS]，门卫确认离开数[COUNTOUT]，入场车辆比例[INRATIO]
	 * 		审核未通过数[COUNREFUSE] -->
	<select id="statisticsCarCount" parameterType="pd" resultType="pd">
		SELECT
			F.*
			, (f.COUNTIN-f.COUNTOUT) COUNTSITE
			, IF(ISNULL(f.COUNTIN / f.COUNTAPPLY), 0, ROUND(f.COUNTIN / f.COUNTAPPLY * 100, 2)) INRATIO
		FROM
		(SELECT
				COUNT(case when f.STATE != '0' then f.FOREIGNCAR_ID END) COUNTAPPLY,
				COUNT(case when f.TIME_IN IS NOT NULL then f.FOREIGNCAR_ID END) COUNTIN,
				COUNT(case when f.TIME_OUT IS NOT NULL then f.FOREIGNCAR_ID END) COUNTOUT,
				COUNT(case when f.STATE IN ('3', '4', '5', '7', '8') then f.FOREIGNCAR_ID END) COUNPASS,
				COUNT(case when f.STATE = '6' then f.FOREIGNCAR_ID END) COUNREFUSE
			FROM bus_foreigncar f
			 WHERE f.ISDELETE = 0
			 AND f.CREATTIME >= CONCAT_WS(" ", DATE_FORMAT(CURDATE(),'%Y-%m-%d'), '00:00:00')
		) f

	</select>

	<!-- 统计今日现场车辆情况
	 * 		提交申请数[COUNTAPPLY]，门卫确认进入数[COUNTIN]，现场车辆数[COUNTSITE]，
	 * 		审核通过数[COUNPASS]，门卫确认离开数[COUNTOUT]，入场车辆比例[INRATIO]
	 * 		审核未通过数[COUNREFUSE] -->
	<select id="statisticsGroupDay" parameterType="pd" resultType="pd">
		<choose>
			<when test="STATUSNAME == '进入'">
				SELECT 'IN' STATUS, f.TIME_IN DAYS, COUNT(f.FOREIGNCAR_ID) COUNT FROM
				(SELECT
				SUBSTR(f.TIME_IN, 1, 10) TIME_IN,f.FOREIGNCAR_ID
				FROM bus_foreigncar f
				WHERE f.TIME_IN >= CONCAT_WS("", date_format(now(),'%Y-%m'), '-01 00:00:00')
				) f GROUP BY f.TIME_IN ORDER BY f.TIME_IN ASC
			</when>
			<otherwise>
				SELECT 'OUT' STATUS, f.TIME_OUT DAYS, COUNT(f.FOREIGNCAR_ID) COUNT FROM
				(SELECT
				SUBSTR(f.TIME_OUT, 1, 10) TIME_OUT,f.FOREIGNCAR_ID
				FROM bus_foreigncar f
				WHERE f.TIME_OUT >= CONCAT_WS("", date_format(now(),'%Y-%m'), '-01 00:00:00')
				) f GROUP BY f.TIME_OUT ORDER BY f.TIME_OUT ASC
			</otherwise>
		</choose>
	</select>
</mapper>
