<?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.OutsidersMapper">

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

	<!-- 字段 -->
	<sql id="Field">
		f.OUTSIDERS_ID,
		f.SOURCE_UNIT,
		f.NAME,
		f.PHONO_NUMBER,
		f.ADMISSION_NUMBER,
		f.SUBJECT_MATTER,
		f.DEPARTMENT_ID,
		f.ISDELETE,
		f.APPLY_SOURCE,
		f.CREATOR,
		f.CREATTIME,
		f.OPERATOR,
		f.OPERATTIME,
		f.EXAMINE_DEPARTMENT_ID,
		f.EXAMINE_PEOPLE,
		f.APPROVE_DEPARTMENT_ID,
		f.APPROVE_PEOPLE,
		f.CONFIRM_DEPARTMENT_ID,
		f.CONFIRM_PEOPLE,
		f.REJECTOPINION,
		f.APPLICATION_TIME,
		f.STARTTIME,
		f.ENDTIME,
		f.APPLYTIME,
		f.STATE,
		f.CORPINFO_ID
	</sql>

	<!-- 字段 -->
	<sql id="Field2">
		OUTSIDERS_ID,
		SOURCE_UNIT,
		NAME,
		PHONO_NUMBER,
		ADMISSION_NUMBER,
		SUBJECT_MATTER,
		DEPARTMENT_ID,
		ISDELETE,
		APPLY_SOURCE,
		CREATOR,
		CREATTIME,
		OPERATOR,
		OPERATTIME,
		EXAMINE_DEPARTMENT_ID,
		EXAMINE_PEOPLE,
		APPROVE_DEPARTMENT_ID,
		APPROVE_PEOPLE,
		CONFIRM_DEPARTMENT_ID,
		CONFIRM_PEOPLE,
		REJECTOPINION,
		APPLICATION_TIME,
		STARTTIME,
		ENDTIME,
		APPLYTIME,
		STATE,
		CORPINFO_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{OUTSIDERS_ID},
		#{SOURCE_UNIT},
		#{NAME},
		#{PHONO_NUMBER},
		#{ADMISSION_NUMBER},
		#{SUBJECT_MATTER},
		#{DEPARTMENT_ID},
		#{ISDELETE},
		#{APPLY_SOURCE},
		#{CREATOR},
		#{CREATTIME},
		#{OPERATOR},
		#{OPERATTIME},
		#{EXAMINE_DEPARTMENT_ID},
		#{EXAMINE_PEOPLE},
		#{APPROVE_DEPARTMENT_ID},
		#{APPROVE_PEOPLE},
		#{CONFIRM_DEPARTMENT_ID},
		#{CONFIRM_PEOPLE},
		#{REJECTOPINION},
		#{APPLICATION_TIME},
		#{STARTTIME},
		#{ENDTIME},
		#{APPLYTIME},
		#{STATE},
		#{CORPINFO_ID}
	</sql>

	<!-- 新增-->
	<insert id="save" parameterType="pd">
		insert into
	<include refid="tableName"></include>
		(
	<include refid="Field2"></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
			OUTSIDERS_ID = #{OUTSIDERS_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
			OUTSIDERS_ID = #{OUTSIDERS_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
		OUTSIDERS_ID = #{OUTSIDERS_ID}
	</update>

<!--	&lt;!&ndash; 通过ID获取数据 &ndash;&gt;-->
<!--	<select id="findById" parameterType="pd" resultType="pd">-->
<!--		select-->
<!--		<include refid="Field1"></include>-->
<!--		from -->
<!--		<include refid="tableName"></include>-->
<!--		where-->
<!--		OUTSIDERS_ID = #{OUTSIDERS_ID}-->
<!--	</select>-->

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
		CONCAT_WS('', od.NAME, ':', u.NAME, ' ', f.APPLY_SOURCE) APPLY_NAME,
		<include refid="Field"></include>
		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
		<if test="pd.EXAMINE_USER != null and pd.EXAMINE_USER != ''">
			LEFT JOIN sys_user_examine e ON e.DEPARTMENT_ID = f.EXAMINE_DEPARTMENT_ID
		</if>
		where f.ISDELETE = '0'
		<if test="pd.EXAMINE_USER != null and pd.EXAMINE_USER != ''">
			and f.EXAMINE_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
			and e.USER_ID = #{pd.EXAMINE_USER}
			and e.IS_TO_EXAMINE = '1'
		</if>
		<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.STARTTIME != null and pd.STARTTIME != ''">-->
<!--			and f.STARTTIME <![CDATA[ >= ]]> #{pd.STARTTIME}-->
<!--		</if>-->
<!--		<if test="pd.ENDTIME != null and pd.ENDTIME != ''">-->
<!--			and f.ENDTIME <![CDATA[ <= ]]> #{pd.ENDTIME}-->
<!--		</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.STATE != null and pd.STATE != ''">
			and f.STATE LIKE CONCAT(CONCAT('%', #{pd.STATE}),'%')
		</if>
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''">
			and f.SOURCE_UNIT LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
		</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>
		GROUP BY f.OUTSIDERS_ID
		ORDER BY f.OPERATTIME desc, f.APPLYTIME desc

	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></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>
		<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="Field"></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="findById" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>,
		od.name as deptname,
		u.NAME as USERNAME,
		CONCAT_WS('', od.NAME, ':', u.NAME, ' ', f.APPLY_SOURCE) APPLY_NAME
		from
		<include refid="tableName"></include> f
		left join OA_DEPARTMENT od on f.DEPARTMENT_ID = od.DEPARTMENT_ID
		LEFT JOIN SYS_USER u ON u.USER_ID = f.CREATOR
		where
		f.OUTSIDERS_ID = #{OUTSIDERS_ID}
		and f.ISDELETE = '0'
		order by f.OPERATTIME desc

	</select>

	<!-- 部门审核列表 -->
	<select id="examinelistPage" parameterType="page" resultType="pd">
		select
		bf.OUTSIDERS_ID,
		bf.SOURCE_UNIT,
		bf.LICENSE_PLATE,
		bf.APPLICATION_TIME,
		bf.MODEL,
		bf.STATE,
		bf.NUMBER_PEOPLE_CAR,
		od.NAME
		from
		<include refid="tableName"></include> bf,
		OA_DEPARTMENT od
		where bf.DEPARTMENT_ID = od.DEPARTMENT_ID
		and	bf.ISDELETE = '0'
		and bf.DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
		and bf.STATE >= 1
		<if test="pd.SOURCE_UNIT != null and pd.SOURCE_UNIT != ''">
			and bf.SOURCE_UNIT LIKE CONCAT(CONCAT('%', #{pd.SOURCE_UNIT}),'%')
		</if>
		<if test="pd.STATE != null and pd.STATE != ''">
			and bf.STATE LIKE CONCAT(CONCAT('%', #{pd.STATE}),'%')
		</if>
		<if test="pd.STATE != null and pd.STATE != ''">
			and bf.STATE LIKE CONCAT(CONCAT('%', #{pd.STATE}),'%')
		</if>
		order by bf.OPERATTIME desc

	</select>

	<!-- 安监部审批列表 -->
	<select id="approvallistPage" parameterType="page" resultType="pd">
		select
		f.OUTSIDERS_ID,
		f.SOURCE_UNIT,
		f.ADMISSION_NUMBER,
		f.APPLICATION_TIME,
		f.SUBJECT_MATTER,
		f.EXAMINE_DEPARTMENT_ID,
		f.STATE,
		f.CREATOR,
		f.STARTTIME,
		f.ENDTIME,
		od.name,
		u.NAME as USERNAME,
		CONCAT_WS('', od.NAME, ':', u.NAME, ' ', f.APPLY_SOURCE) APPLY_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
		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.STATE != null and pd.STATE != ''">
			and f.STATE LIKE CONCAT(CONCAT('%', #{pd.STATE}),'%')
		</if>
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''">
			and SOURCE_UNIT LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
		</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>
		order by f.OPERATTIME desc

	</select>

	<!-- 现场确认列表 -->
	<select id="confirmlistPage" parameterType="page" resultType="pd">
		select
		f.OUTSIDERS_ID,
		f.SOURCE_UNIT,
		f.ADMISSION_NUMBER,
		f.APPLICATION_TIME,
		f.SUBJECT_MATTER,
		f.EXAMINE_DEPARTMENT_ID,
		f.STATE,
		f.CREATOR,
		f.STARTTIME,
		f.ENDTIME,
		f.APPROVE_PEOPLE,
		f.CONFIRM_PEOPLE,
		od.name,
		u.NAME as USERNAME,
		CONCAT_WS('', od.NAME, ':', u.NAME, ' ', f.APPLY_SOURCE) APPLY_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
		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.STATE != null and pd.STATE != ''">
			and f.STATE LIKE CONCAT(CONCAT('%', #{pd.STATE}),'%')
		</if>
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''">
			and SOURCE_UNIT LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
		</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>



		order by f.OPERATTIME desc

	</select>

	<!-- 统计今日临时人员检测
	 * 		提交申请数[COUNTAPPLY]，门卫确认进入数[COUNTIN]，现场车辆数[COUNTSITE]，
	 * 		审核通过数[COUNPASS]，门卫确认离开数[COUNTOUT]，入场车辆比例[INRATIO]
	 * 	 	审核未通过数[COUNREFUSE] -->
	<select id="statisticsOutsiderCount" 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.OUTSIDERS_ID END) COUNTAPPLY,
				COUNT(case when f.TIME_IN IS NOT NULL then f.OUTSIDERS_ID END) COUNTIN,
				COUNT(case when f.TIME_OUT IS NOT NULL then f.OUTSIDERS_ID END) COUNTOUT,
				COUNT(case when f.STATE IN ('3', '4', '5', '7', '8') then f.OUTSIDERS_ID END) COUNPASS,
				COUNT(case when f.STATE = '6' then f.OUTSIDERS_ID END) COUNREFUSE
			FROM bus_outsiders f
			 WHERE f.ISDELETE = 0
			 AND f.CREATTIME >= CONCAT_WS(" ", DATE_FORMAT(CURDATE(),'%Y-%m-%d'), '00:00:00')
		) f
	</select>

	<!-- 统计今日临时人员检测
	 * 	车辆	职能部门审核[COUNT_CAR_EXAMINE]，安监部门审批[COUNT_CAR_APPROVE]，现场确认[COUNT_CAR_CONFIRM]，
	 * 	人员	职能部门审核[COUNT_PEOPLE_EXAMINE]，安监部门审批[COUNT_PEOPLE_APPROVE]，现场确认[COUNT_PEOPLE_CONFIRM]
	 -->
	<select id="countCheck" parameterType="pd" resultType="pd">
		SELECT
			(select COUNT(f.FOREIGNCAR_ID) from bus_foreigncar f
				LEFT JOIN sys_user_examine e ON e.DEPARTMENT_ID = f.EXAMINE_DEPARTMENT_ID
				where f.ISDELETE = '0' AND f.STATE = '1' AND f.CORPINFO_ID = #{CORPINFO_ID}
			 	AND TRIM(f.ENDTIME) >= DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i')
				 AND e.IS_TO_EXAMINE = '1' and e.USER_ID = #{USER_ID}) as COUNT_CAR_EXAMINE,
			(select COUNT(f.FOREIGNCAR_ID) from bus_foreigncar f
				LEFT JOIN sys_user_examine e ON e.DEPARTMENT_ID = f.APPROVE_DEPARTMENT_ID
				where f.ISDELETE = '0' AND f.STATE = '2' AND f.CORPINFO_ID = #{CORPINFO_ID}
			 	AND TRIM(f.ENDTIME) >= DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i')
				 and e.IS_EXAMINE_AND_APPROVE = '1' and e.USER_ID = #{USER_ID}) as COUNT_CAR_APPROVE,
			(select COUNT(f.FOREIGNCAR_ID) from bus_foreigncar f
				LEFT JOIN sys_user_examine e ON e.DEPARTMENT_ID = f.CONFIRM_DEPARTMENT_ID
				where f.ISDELETE = '0' AND f.STATE in ('3','4') AND f.CORPINFO_ID = #{CORPINFO_ID}
			 	 AND TRIM(f.STARTTIME) &lt;= DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i') AND TRIM(f.ENDTIME) >= DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i')
				 and e.IS_DEPT_CONFIRM = '1' and e.USER_ID = #{USER_ID}) as COUNT_CAR_CONFIRM,

			(select COUNT(f.OUTSIDERS_ID) from bus_outsiders f
				LEFT JOIN sys_user_examine e ON e.DEPARTMENT_ID = f.EXAMINE_DEPARTMENT_ID
				where f.ISDELETE = '0' AND f.STATE = '1' AND f.CORPINFO_ID = #{CORPINFO_ID}
			 	AND TRIM(f.ENDTIME) >= DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i')
				 and e.IS_TO_EXAMINE = '1' and e.USER_ID = #{USER_ID}) as COUNT_PEOPLE_EXAMINE,
			(select COUNT(f.OUTSIDERS_ID) from bus_outsiders f
				LEFT JOIN sys_user_examine e ON e.DEPARTMENT_ID = f.APPROVE_DEPARTMENT_ID
				where f.ISDELETE = '0' AND f.STATE = '2' AND f.CORPINFO_ID = #{CORPINFO_ID}
			 	AND TRIM(f.ENDTIME) >= DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i')
				 and e.IS_EXAMINE_AND_APPROVE = '1' and e.USER_ID = #{USER_ID}) as COUNT_PEOPLE_APPROVE,
			(select COUNT(f.OUTSIDERS_ID) from bus_outsiders f
				LEFT JOIN sys_user_examine e ON e.DEPARTMENT_ID = f.CONFIRM_DEPARTMENT_ID
				where f.ISDELETE = '0' AND f.STATE in ('3','4') AND f.CORPINFO_ID = #{CORPINFO_ID}
			 	 AND TRIM(f.STARTTIME) &lt;= DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i') AND TRIM(f.ENDTIME) >= DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i')
				 and e.IS_DEPT_CONFIRM = '1' and e.USER_ID = #{USER_ID}) as COUNT_PEOPLE_CONFIRM
	</select>
</mapper>
