<?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.check.CheckRecordMapper">

	<!--表名 -->
	<sql id="tableName">
		BUS_CHECKRECORD
	</sql>

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

	<!-- 字段 -->
	<sql id="Field">
		f.LISTMANAGER_ID,
		f.LIST_NAME,
		f.CORPINFO_ID,
		f.CREATOR,
		f.CREATTIME,
		f.OPERATOR,
		f.OPERATTIME,
		f.ISDELETE,
		f.LONGITUDE,
		f.LATITUDE,
		f.CHECKRECORD_ID,
		f.CHECK_TIME,
		f.REASON,
		f.DESCR,
		f.FINISHED,
		f.TYPE,
		f.PERIODSTART,
		f.PERIODEND,
		f.ISSTATISTICS
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		LISTMANAGER_ID,
		LIST_NAME,
		CORPINFO_ID,
		CREATOR,
		CREATTIME,
		OPERATOR,
		OPERATTIME,
		ISDELETE,
		LONGITUDE,
		LATITUDE,
		CHECKRECORD_ID,
		CHECK_TIME,
		REASON,
		DESCR,
		FINISHED,
		TYPE,
		PERIODSTART,
		PERIODEND,
		ISSTATISTICS
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{LISTMANAGER_ID},
		#{LIST_NAME},
		#{CORPINFO_ID},
		#{CREATOR},
		#{CREATTIME},
		#{OPERATOR},
		#{OPERATTIME},
		#{ISDELETE},
		#{LONGITUDE},
		#{LATITUDE},
		#{CHECKRECORD_ID},
		#{CHECK_TIME},
		#{REASON},
		#{DESCR},
		#{FINISHED},
		#{TYPE},
		#{PERIODSTART},
		#{PERIODEND},
		#{ISSTATISTICS}
	</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'
		where
			CHECKRECORD_ID = #{CHECKRECORD_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			FINISHED=#{FINISHED},
			CHECK_TIME=#{CHECK_TIME},
			<if test="PERIODSTART != null and PERIODSTART != ''">
				PERIODSTART=#{PERIODSTART},
			</if>
			<if test="PERIODEND != null and PERIODEND != ''">
				PERIODEND=#{PERIODEND},
			</if>
			DESCR=#{DESCR},
			CHECKRECORD_ID = CHECKRECORD_ID
		where
			CHECKRECORD_ID = #{CHECKRECORD_ID}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>,
		p.NAME PERIODNAME,
		t.NAME TYPENAME,
		d.NAME as DEPARTMENT_NAME,
		sp.NAME AS POST_NAME,
		s.NAME AS SCREENTYPENAME,
		l.TYPE as LISTTYPE,
		l.START_DATE,
		l.END_DATE
		from
		<include refid="tableName"></include> f
		left join BUS_LISTMANAGER l on f.LISTMANAGER_ID = l.LISTMANAGER_ID
		left join sys_dictionaries p on l.PERIOD = p.BIANMA
		left join sys_dictionaries t on l.TYPE = t.BIANMA
		left join sys_dictionaries s on l.SCREENTYPE = s.BIANMA
		left join OA_DEPARTMENT d on d.DEPARTMENT_ID=l.DEPARTMENT_ID
		left join SYS_POST sp on sp.POST_ID=l.POST_ID
		where
			f.CHECKRECORD_ID = #{CHECKRECORD_ID}
	</select>
	<!-- 通过清单ID获取风险点数据 -->
	<select id="findRiskPointByLId" parameterType="pd" resultType="pd">
		select * from bus_riskpoint t where t.RISKPOINT_ID in (select RISKPOINT_ID from bus_list_checkitem where LISTMANAGER_ID=#{LISTMANAGER_ID})
	</select>

	<!-- 列表 -->
	<select id="appdatalist" parameterType="pd" resultType="pd">
		select
			f.LISTMANAGER_ID,
			f.LIST_NAME,
			f.CORPINFO_ID,
			f.CREATOR,
			f.CREATTIME,
			f.OPERATOR,
			f.OPERATTIME,
			f.ISDELETE,
			f.LONGITUDE,
			f.LATITUDE,
			f.CHECKRECORD_ID,
			f.CHECK_TIME,
			f.DESCR,
			f.FINISHED,
			f.TYPE,
			f.PERIODSTART DATESTART,
			f.PERIODEND DATEEND,
			u.NAME AS USER_NAME,
			su.NAME AS PRINCIPALNAME,
			(select group_concat(IFNULL(bh.USER_NAME,chr.NAME)) from BUS_CHECKUSER bh left join sys_user chr on chr.USER_ID=bh.USER_ID where bh.CHECKRECORD_ID=f.CHECKRECORD_ID) CHECK_USERS
		from
		<include refid="tableName"></include> f
		left join SYS_USER u on u.USERNAME=f.CREATOR
		LEFT JOIN BUS_LISTMANAGER l ON l.LISTMANAGER_ID = f.LISTMANAGER_ID
		LEFT JOIN SYS_USER su ON su.USER_ID = l.USER_ID
		where f.ISDELETE = '0' and f.CORPINFO_ID = #{CORPINFO_ID} and f.FINISHED='1'
		<if test="KEYWORDS != null and KEYWORDS != ''">
			and
				(
					f.LIST_NAME LIKE CONCAT(CONCAT('%', #{KEYWORDS}),'%')
				)
		</if>
		<if test="LISTMANAGER_ID != null and LISTMANAGER_ID != ''">
			and
				(
					f.LISTMANAGER_ID = #{LISTMANAGER_ID}
				)
		</if>
		<if test="STARTTIME != null and STARTTIME != ''">
			and DATE_FORMAT(f.CHECK_TIME,'%Y-%m-%d %H:%i:%s') &gt;= CONCAT(#{STARTTIME},':00')
		</if>
		<if test="ENDTIME != null and ENDTIME != ''">
			and DATE_FORMAT(f.CHECK_TIME,'%Y-%m-%d %H:%i:%s') &lt;= CONCAT(#{ENDTIME},':59')
		</if>
		<if test="TYPE != null and TYPE != ''">
			and f.TYPE= #{TYPE}
			<!-- <choose>
				<when test='TYPE=="1"'>
					order by IFNULL( f.CHECK_TIME, f.PERIODEND ) desc
				</when>
				<when test='TYPE=="2"'>
					order by IFNULL( f.CHECK_TIME, f.PERIODEND ) desc
				</when>
			</choose> -->
		</if>
		order by IFNULL( f.CHECK_TIME, f.PERIODEND ) desc
	</select>
	<select id="datalistPage" parameterType="page" resultType="pd">

		select
			'1' LIST_TYPE,
			f.LISTMANAGER_ID LIST_ID,
			f.LIST_NAME,
			f.CORPINFO_ID,
			f.CREATOR,
			f.CREATTIME,
			f.OPERATOR,
			f.OPERATTIME,
			f.ISDELETE,
			f.LONGITUDE,
			f.LATITUDE,
			f.CHECKRECORD_ID,
			f.CHECK_TIME,
			f.DESCR,
			f.FINISHED,
			f.TYPE,
			f.PERIODSTART DATESTART,
			f.PERIODEND DATEEND,
			u.NAME AS USER_NAME,
			su.NAME AS PRINCIPALNAME,
			(select group_concat(IFNULL(bh.USER_NAME,chr.NAME)) from BUS_CHECKUSER bh left join sys_user chr on chr.USER_ID=bh.USER_ID where bh.CHECKRECORD_ID=f.CHECKRECORD_ID) CHECK_USERS
		from
		<include refid="tableName"></include> f
		left join SYS_USER u on u.USERNAME=f.CREATOR
		LEFT JOIN BUS_LISTMANAGER l ON l.LISTMANAGER_ID = f.LISTMANAGER_ID
		LEFT JOIN SYS_USER su ON su.USER_ID = l.USER_ID
		where f.ISDELETE = '0' and f.CORPINFO_ID = #{pd.CORPINFO_ID} and f.FINISHED='1'

		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''">
			and
				(
				l.NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
				)
		</if>
		<if test="pd.LISTMANAGER_ID != null and pd.LISTMANAGER_ID != ''">
			and
				(
					f.LISTMANAGER_ID = #{pd.LISTMANAGER_ID}
				)
		</if>
		<if test="pd.CUSTOM_ID != null and pd.CUSTOM_ID != ''">
			and
			(
			f.LISTMANAGER_ID = #{pd.CUSTOM_ID}
			)
		</if>
		<if test="pd.DEPARTMENT_ID != null and pd.DEPARTMENT_ID != ''">
			and
				(
					l.DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
				)
		</if>
		<!-- <if test="pd.STARTTIME != null and pd.STARTTIME != ''">
			and DATE_FORMAT(f.CHECK_TIME,'%Y-%m-%d %H:%i:%s') &gt;= CONCAT(#{pd.STARTTIME},':00')
		</if>
		<if test="pd.ENDTIME != null and pd.ENDTIME != ''">
			and DATE_FORMAT(f.CHECK_TIME,'%Y-%m-%d %H:%i:%s') &lt;= CONCAT(#{pd.ENDTIME},':59')
		</if> -->
		<choose>
			<when test="pd.STARTTIME != null and pd.STARTTIME != '' and pd.ENDTIME != null and pd.ENDTIME != ''">
				and DATE_FORMAT(CONCAT(#{pd.STARTTIME},' 00:00:00'),'%Y-%m-%d %H:%i:%s') &lt;= DATE_FORMAT(f.CREATTIME,'%Y-%m-%d %H:%i:%s')
				and DATE_FORMAT(CONCAT(#{pd.ENDTIME},' 23:59:59'),'%Y-%m-%d %H:%i:%s') &gt;= DATE_FORMAT(f.CREATTIME,'%Y-%m-%d %H:%i:%s')
			</when>
			<otherwise>
				<if test="pd.STARTINSPECTTIME != null and pd.STARTINSPECTTIME != ''">
					and DATE_FORMAT(CONCAT(#{pd.STARTINSPECTTIME},' 00:00:00'),'%Y-%m-%d %H:%i:%s') &lt;= DATE_FORMAT(f.PERIODEND,'%Y-%m-%d %H:%i:%s')
				</if>
				<if test="pd.ENDINSPECTTIME != null and pd.ENDINSPECTTIME != ''">
					and DATE_FORMAT(CONCAT(#{pd.ENDINSPECTTIME},' 23:59:59'),'%Y-%m-%d %H:%i:%s') &gt;= DATE_FORMAT(f.PERIODSTART,'%Y-%m-%d %H:%i:%s')
				</if>
			</otherwise>
		</choose>
		<if test="pd.TYPE != null and pd.TYPE != ''">
			and f.TYPE= #{pd.TYPE}
			<!-- <choose>
				<when test='pd.TYPE=="1"'>
					order by IFNULL( f.CHECK_TIME, f.PERIODEND ) desc
				</when>
				<when test='pd.TYPE=="2"'>
					order by IFNULL( f.CHECK_TIME, f.PERIODEND ) desc
				</when>
			</choose> -->
		</if>
		<choose>
			<when test='pd.ISMAIN != null and pd.ISMAIN != "" and pd.ISMAIN == "1"'>
				<if test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
					and
					u.DEPARTMENT_ID in
					<foreach item="item" index="index"
							 collection="pd.DEPT_IDS" open="(" separator="," close=")">
						'${item}'
					</foreach>
				</if>
			</when>
			<otherwise>
				<choose>
					<when test='pd.ISSUPERVISE != null and pd.ISSUPERVISE != "" and pd.ISSUPERVISE == "1"'>
						<choose>
							 <when test='pd.ISLEADER != null and pd.ISLEADER != "" and pd.ISLEADER == "1"'>
								 and
								 EXISTS (
								 SELECT
								 1
								 FROM
								 BUS_CHECKUSER bh
								 LEFT JOIN SYS_USER chr ON chr.USER_ID = bh.USER_ID
								 WHERE
								 bh.CHECKRECORD_ID = f.CHECKRECORD_ID
								 AND ((chr.DEPARTMENT_ID IN ( SELECT SUB_DEPARTMENT_ID FROM oa_supervision_department
								 osd WHERE osd.SUP_DEPARTMENT_ID = #{pd.SELF_DEPARTMENT_ID} AND osd.ISDELETE = '0' AND
								 osd.CORPINFO_ID = #{pd.CORPINFO_ID} ) )
								 or (chr.DEPARTMENT_ID IN
								 <foreach item="item" index="index"
										  collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
									 '${item}'
								 </foreach>) )
								 )
							 </when>
							 <otherwise>
								 and
								 EXISTS (
								 SELECT
								 1
								 FROM
								 BUS_CHECKUSER bh
								 LEFT JOIN SYS_USER chr ON chr.USER_ID = bh.USER_ID
								 WHERE
								 (bh.CHECKRECORD_ID = f.CHECKRECORD_ID
								 or chr.USER_ID = #{pd.USER_ID})
								 AND chr.DEPARTMENT_ID IN ( SELECT SUB_DEPARTMENT_ID FROM oa_supervision_department osd WHERE osd.SUP_DEPARTMENT_ID = #{pd.SELF_DEPARTMENT_ID} AND osd.ISDELETE = '0' AND osd.CORPINFO_ID = #{pd.CORPINFO_ID} ) )

							 </otherwise>
						</choose>

					</when>
					<when test='pd.ISLEADER != null and pd.ISLEADER != "" and pd.ISLEADER == "1"'>
						and
						EXISTS (
						SELECT
						1
						FROM
						BUS_CHECKUSER bh
						LEFT JOIN SYS_USER chr ON chr.USER_ID = bh.USER_ID
						WHERE
						bh.CHECKRECORD_ID = f.CHECKRECORD_ID
						AND chr.DEPARTMENT_ID IN
						<foreach item="item" index="index"
								 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
							'${item}'
						</foreach> )

					</when>
					<when test="pd.SELF_DEPARTMENT_ID != null and pd.SELF_DEPARTMENT_ID != ''">
						and l.DEPARTMENT_ID=#{pd.SELF_DEPARTMENT_ID}
						and l.USER_ID = #{pd.USER_ID}
					</when>
					<otherwise>
					</otherwise>
				</choose>
			</otherwise>
		</choose>

		UNION
		SELECT
		'2' LIST_TYPE,
		f.CUSTOM_ID LIST_ID,
		l.NAME LIST_NAME,
		f.CORPINFO_ID,
		f.CREATOR,
		f.CREATTIME,
		f.OPERATOR,
		f.OPERATTIME,
		f.ISDELETE,
		f.LONGITUDE,
		f.LATITUDE,
		f.CHECKRECORD_ID,
		f.CHECK_TIME,
		f.DESCR,
		f.FINISHED,
		f.TYPE,
		f.PERIODSTART DATESTART,
		f.PERIODEND DATEEND,
		u.NAME AS USER_NAME,
		su.NAME AS PRINCIPALNAME,
		(
		SELECT
		group_concat(
		IFNULL( bh.USER_NAME, chr.NAME ))
		FROM
		bus_hiddendangercheckstandard_checkuser bh
		LEFT JOIN sys_user chr ON chr.USER_ID = bh.USER_ID
		WHERE
		bh.CHECKRECORD_ID = f.CHECKRECORD_ID
		) CHECK_USERS
		FROM
		bus_hiddendangercheckstandard_checkrecord f
		LEFT JOIN SYS_USER u ON u.USERNAME = f.CREATOR
		LEFT JOIN bus_hiddendangercheckstandard_custom l ON l.CUSTOM_ID = f.CUSTOM_ID
		LEFT JOIN SYS_USER su ON su.USER_ID = l.USER_ID
		WHERE
		f.ISDELETE = '0'
		and f.CORPINFO_ID = #{pd.CORPINFO_ID} and f.FINISHED='1'

		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''">
			and
			(
			l.NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
			)
		</if>
		<if test="pd.CUSTOM_ID != null and pd.CUSTOM_ID != ''">
			and
			(
			f.CUSTOM_ID = #{pd.CUSTOM_ID}
			)
		</if>
		<if test="pd.LISTMANAGER_ID != null and pd.LISTMANAGER_ID != ''">
			and
			(
			f.CUSTOM_ID = #{pd.LISTMANAGER_ID}
			)
		</if>
		<if test="pd.DEPARTMENT_ID != null and pd.DEPARTMENT_ID != ''">
			and
			(
			l.DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
			)
		</if>
		<!-- <if test="pd.STARTTIME != null and pd.STARTTIME != ''">
			and DATE_FORMAT(f.CHECK_TIME,'%Y-%m-%d %H:%i:%s') &gt;= CONCAT(#{pd.STARTTIME},':00')
		</if>
		<if test="pd.ENDTIME != null and pd.ENDTIME != ''">
			and DATE_FORMAT(f.CHECK_TIME,'%Y-%m-%d %H:%i:%s') &lt;= CONCAT(#{pd.ENDTIME},':59')
		</if> -->
		<choose>
			<when test="pd.STARTTIME != null and pd.STARTTIME != '' and pd.ENDTIME != null and pd.ENDTIME != ''">
				and DATE_FORMAT(CONCAT(#{pd.STARTTIME},' 00:00:00'),'%Y-%m-%d %H:%i:%s') &lt;= DATE_FORMAT(f.CREATTIME,'%Y-%m-%d %H:%i:%s')
				and DATE_FORMAT(CONCAT(#{pd.ENDTIME},' 23:59:59'),'%Y-%m-%d %H:%i:%s') &gt;= DATE_FORMAT(f.CREATTIME,'%Y-%m-%d %H:%i:%s')
			</when>
			<otherwise>
				<if test="pd.STARTINSPECTTIME != null and pd.STARTINSPECTTIME != ''">
					and DATE_FORMAT(CONCAT(#{pd.STARTINSPECTTIME},' 00:00:00'),'%Y-%m-%d %H:%i:%s') &lt;= DATE_FORMAT(f.PERIODEND,'%Y-%m-%d %H:%i:%s')
				</if>
				<if test="pd.ENDINSPECTTIME != null and pd.ENDINSPECTTIME != ''">
					and DATE_FORMAT(CONCAT(#{pd.ENDINSPECTTIME},' 23:59:59'),'%Y-%m-%d %H:%i:%s') &gt;= DATE_FORMAT(f.PERIODSTART,'%Y-%m-%d %H:%i:%s')
				</if>
			</otherwise>
		</choose>
		<if test="pd.TYPE != null and pd.TYPE != ''">
			and f.TYPE= #{pd.TYPE}
			<!-- <choose>
				<when test='pd.TYPE=="1"'>
					order by IFNULL( f.CHECK_TIME, f.PERIODEND ) desc
				</when>
				<when test='pd.TYPE=="2"'>
					order by IFNULL( f.CHECK_TIME, f.PERIODEND ) desc
				</when>
			</choose> -->
		</if>
		<choose>
			<when test='pd.ISMAIN != null and pd.ISMAIN != "" and pd.ISMAIN == "1"'>
				<if test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
					and
					u.DEPARTMENT_ID in
					<foreach item="item" index="index"
							 collection="pd.DEPT_IDS" open="(" separator="," close=")">
						'${item}'
					</foreach>
				</if>
			</when>
			<otherwise>
				<choose>
					<when test='pd.ISSUPERVISE != null and pd.ISSUPERVISE != "" and pd.ISSUPERVISE == "1"'>
						<choose>
							<when test='pd.ISLEADER != null and pd.ISLEADER != "" and pd.ISLEADER == "1"'>
								and
								EXISTS (
								SELECT
								1
								FROM
								BUS_CHECKUSER bh
								LEFT JOIN SYS_USER chr ON chr.USER_ID = bh.USER_ID
								WHERE
								bh.CHECKRECORD_ID = f.CHECKRECORD_ID
								AND ((chr.DEPARTMENT_ID IN ( SELECT SUB_DEPARTMENT_ID FROM oa_supervision_department
								osd WHERE osd.SUP_DEPARTMENT_ID = #{pd.SELF_DEPARTMENT_ID} AND osd.ISDELETE = '0' AND
								osd.CORPINFO_ID = #{pd.CORPINFO_ID} ) )
								or (chr.DEPARTMENT_ID IN
								<foreach item="item" index="index"
										 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>) )
								)
							</when>
							<otherwise>
								and
								EXISTS (
								SELECT
								1
								FROM
								BUS_CHECKUSER bh
								LEFT JOIN SYS_USER chr ON chr.USER_ID = bh.USER_ID
								WHERE
								(bh.CHECKRECORD_ID = f.CHECKRECORD_ID
								or chr.USER_ID = #{pd.USER_ID})
								AND chr.DEPARTMENT_ID IN ( SELECT SUB_DEPARTMENT_ID FROM oa_supervision_department osd WHERE osd.SUP_DEPARTMENT_ID = #{pd.SELF_DEPARTMENT_ID} AND osd.ISDELETE = '0' AND osd.CORPINFO_ID = #{pd.CORPINFO_ID} ) )

							</otherwise>
						</choose>

					</when>
					<when test='pd.ISLEADER != null and pd.ISLEADER != "" and pd.ISLEADER == "1"'>
						and
						EXISTS (
						SELECT
						1
						FROM
						BUS_CHECKUSER bh
						LEFT JOIN SYS_USER chr ON chr.USER_ID = bh.USER_ID
						WHERE
						bh.CHECKRECORD_ID = f.CHECKRECORD_ID
						AND chr.DEPARTMENT_ID IN
						<foreach item="item" index="index"
								 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
							'${item}'
						</foreach> )

					</when>
					<when test="pd.SELF_DEPARTMENT_ID != null and pd.SELF_DEPARTMENT_ID != ''">
						and l.DEPARTMENT_ID=#{pd.SELF_DEPARTMENT_ID}
						and l.USER_ID = #{pd.USER_ID}
					</when>
					<otherwise>
					</otherwise>
				</choose>
			</otherwise>
		</choose>
		ORDER BY IFNULL( CHECK_TIME,DATEEND) desc
	</select>


	<!-- <select id="datalistPage" parameterType="page" resultType="pd">
		SELECT
			a.*
		FROM
			(
			SELECT
				'' LISTMANAGER_ID,
				'' LIST_NAME,
				'' CORPINFO_ID,
				'' CREATOR,
				'' CREATTIME,
				'' OPERATOR,
				'' OPERATTIME,
				'' ISDELETE,
				'' LONGITUDE,
				'' LATITUDE,
				'' CHECKRECORD_ID,
				'' CHECK_TIME,
				'' DESCR,
				'' FINISHED,
				'' CHECK_USERS,
				q.DATESTART,
				q.DATEEND,
				'' USER_NAME,
				'' PRINCIPALNAME,
				q.DATE
			FROM
				(
				SELECT
					MAX(f.CHECKRECORD_ID) CHECKRECORD_ID,
					<if test="pd.LISTTYPE != null and pd.LISTTYPE != ''">关键词检索
		                <choose>
		                    <when test='pd.LISTTYPE=="checkPeriod0001"'>
		                        w.DAY_START DATESTART,
		                        w.DAY_END DATEEND,
		                    </when>
		                    <when test='pd.LISTTYPE=="checkPeriod0002"'>
		                        w.WEEK_START DATESTART,
		                        w.WEEK_END DATEEND,
		                    </when>
		                    <when test='pd.LISTTYPE=="checkPeriod0003"'>
		                        w.XUN_START DATESTART,
		                        w.XUN_END DATEEND,
		                    </when>
		                    <when test='pd.LISTTYPE=="checkPeriod0004"'>
		                        w.MONTH_START DATESTART,
		                        w.MONTH_END DATEEND,
		                    </when>
		                    <when test='pd.LISTTYPE=="checkPeriod0005"'>
		                        w.QUARTER_START DATESTART,
		                        w.QUARTER_END DATEEND,
		                    </when>
		                    <when test='pd.LISTTYPE=="checkPeriod0007"'>
		                        w.HALFYEAR_START DATESTART,
		                        w.HALFYEAR_END DATEEND,
		                    </when>
		                    <when test='pd.LISTTYPE=="checkPeriod0006"'>
		                        w.YEAR_START DATESTART,
		                        w.YEAR_END DATEEND,
		                    </when>
		                </choose>
		            </if>
					w.DATE
				FROM
					(
						SELECT * from BUS_SYSDATE
						${pd.SQL}
					) w
					LEFT JOIN BUS_CHECKRECORD f ON w.DATE = DATE_FORMAT( f.CHECK_TIME, '%Y-%m-%d' )
					AND f.ISDELETE = '0'
					AND f.CORPINFO_ID = #{pd.CORPINFO_ID}
					AND f.FINISHED = '1'
					<if test="pd.LISTMANAGER_ID != null and pd.LISTMANAGER_ID != ''">关键词检索
		                and
		                    (
		                        f.LISTMANAGER_ID = #{pd.LISTMANAGER_ID}
		                    )
		            </if>
				WHERE
					DATE_FORMAT( #{pd.LISTDATE}, '%Y-%m-%d' ) &lt;= w.DATE
		            <if test='pd.ISDELETE != null and pd.ISDELETE != "" and pd.ISDELETE != "0"'>关键词检索
		                and w.DATE &lt;= DATE_FORMAT(#{pd.DELETEDATE},'%Y-%m-%d')
		            </if>
				GROUP BY
				<if test="pd.LISTTYPE != null and pd.LISTTYPE != ''">关键词检索
					<choose>
						<when test='pd.LISTTYPE=="checkPeriod0001"'>
							w.DAY_START,
							w.DAY_END
						</when>
						<when test='pd.LISTTYPE=="checkPeriod0002"'>
							w.WEEK_START,
							w.WEEK_END
						</when>
						<when test='pd.LISTTYPE=="checkPeriod0003"'>
							w.XUN_START,
							w.XUN_END
						</when>
						<when test='pd.LISTTYPE=="checkPeriod0004"'>
							w.MONTH_START,
							w.MONTH_END
						</when>
						<when test='pd.LISTTYPE=="checkPeriod0005"'>
							w.QUARTER_START,
							w.QUARTER_END
						</when>
						<when test='pd.LISTTYPE=="checkPeriod0007"'>
							w.HALFYEAR_START,
							w.HALFYEAR_END
						</when>
						<when test='pd.LISTTYPE=="checkPeriod0006"'>
							w.YEAR_START,
							w.YEAR_END
						</when>
					</choose>
				</if>
				) q
			WHERE
				q.CHECKRECORD_ID IS NULL

				UNION ALL
			SELECT
				f.LISTMANAGER_ID,
				f.LIST_NAME,
				f.CORPINFO_ID,
				f.CREATOR,
				f.CREATTIME,
				f.OPERATOR,
				f.OPERATTIME,
				f.ISDELETE,
				f.LONGITUDE,
				f.LATITUDE,
				f.CHECKRECORD_ID,
				f.CHECK_TIME,
				f.DESCR,
				f.FINISHED,
				(
				SELECT
					group_concat( chr.NAME )
				FROM
					BUS_CHECKUSER bh
					LEFT JOIN sys_user chr ON chr.USER_ID = bh.USER_ID
				WHERE
					bh.CHECKRECORD_ID = f.CHECKRECORD_ID
				) CHECK_USERS,
				<if test="pd.LISTTYPE != null and pd.LISTTYPE != ''">关键词检索
					<choose>
						<when test='pd.LISTTYPE=="checkPeriod0001"'>
							w.DAY_START DATESTART,
							w.DAY_END DATEEND,
						</when>
						<when test='pd.LISTTYPE=="checkPeriod0002"'>
							w.WEEK_START DATESTART,
							w.WEEK_END DATEEND,
						</when>
						<when test='pd.LISTTYPE=="checkPeriod0003"'>
							w.XUN_START DATESTART,
							w.XUN_END DATEEND,
						</when>
						<when test='pd.LISTTYPE=="checkPeriod0004"'>
							w.MONTH_START DATESTART,
							w.MONTH_END DATEEND,
						</when>
						<when test='pd.LISTTYPE=="checkPeriod0005"'>
							w.QUARTER_START DATESTART,
							w.QUARTER_END DATEEND,
						</when>
						<when test='pd.LISTTYPE=="checkPeriod0007"'>
							w.HALFYEAR_START DATESTART,
							w.HALFYEAR_END DATEEND,
						</when>
						<when test='pd.LISTTYPE=="checkPeriod0006"'>
							w.YEAR_START DATESTART,
							w.YEAR_END DATEEND,
						</when>
					</choose>
				</if>
				u.NAME AS USER_NAME,
				su.NAME AS PRINCIPALNAME,
				w.DATE
			FROM
				BUS_SYSDATE w
				LEFT JOIN BUS_CHECKRECORD f ON w.DATE = DATE_FORMAT( f.CHECK_TIME, '%Y-%m-%d' )
				AND f.ISDELETE = '0'
				AND f.CORPINFO_ID = #{pd.CORPINFO_ID}
				AND f.FINISHED = '1'
				<if test="pd.LISTMANAGER_ID != null and pd.LISTMANAGER_ID != ''">关键词检索
					and
						(
							f.LISTMANAGER_ID = #{pd.LISTMANAGER_ID}
						)
				</if>
				LEFT JOIN SYS_USER u ON u.USERNAME = f.CREATOR
				LEFT JOIN BUS_LISTMANAGER l ON l.LISTMANAGER_ID = f.LISTMANAGER_ID
				LEFT JOIN SYS_USER su ON su.USER_ID = l.USER_ID
			WHERE
				DATE_FORMAT( #{pd.LISTDATE}, '%Y-%m-%d' ) &lt;= w.DATE
				AND f.CHECKRECORD_ID IS NOT NULL
		        <if test='pd.ISDELETE != null and pd.ISDELETE != "" and pd.ISDELETE != "0"'>关键词检索
					and w.DATE &lt;= DATE_FORMAT(#{pd.DELETEDATE},'%Y-%m-%d')
				</if>
				<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''">关键词检索
					and
						(
							f.LIST_NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
						)
				</if>

				<if test="pd.STARTTIME != null and pd.STARTTIME != ''">关键词检索
					and f.CHECK_TIME &gt;= #{pd.STARTTIME}
				</if>
				<if test="pd.ENDTIME != null and pd.ENDTIME != ''">关键词检索
					and f.CHECK_TIME &lt;= #{pd.ENDTIME}
				</if>
				<if test="pd.STATUS != null and pd.STATUS != ''">关键词检索
					<choose>
						<when test='pd.STATUS =="1"'>

							and f.CHECKRECORD_ID is not null
						</when>
						<when test='pd.STATUS =="0"'>

							and f.CHECKRECORD_ID is null
						</when>
					</choose>
				</if>
			GROUP BY
				<if test="pd.LISTTYPE != null and pd.LISTTYPE != ''">关键词检索
					<choose>
						<when test='pd.LISTTYPE=="checkPeriod0001"'>
							w.DAY_START,
							w.DAY_END,
						</when>
						<when test='pd.LISTTYPE=="checkPeriod0002"'>
							w.WEEK_START,
							w.WEEK_END,
						</when>
						<when test='pd.LISTTYPE=="checkPeriod0003"'>
							w.XUN_START,
							w.XUN_END,
						</when>
						<when test='pd.LISTTYPE=="checkPeriod0004"'>
							w.MONTH_START,
							w.MONTH_END,
						</when>
						<when test='pd.LISTTYPE=="checkPeriod0005"'>
							w.QUARTER_START,
							w.QUARTER_END,
						</when>
						<when test='pd.LISTTYPE=="checkPeriod0007"'>
							w.HALFYEAR_START,
							w.HALFYEAR_END,
						</when>
						<when test='pd.LISTTYPE=="checkPeriod0006"'>
							w.YEAR_START,
							w.YEAR_END,
						</when>
					</choose>
				</if>
				f.CHECK_TIME,
				f.CHECKRECORD_ID
			) a
		ORDER BY
			a.date desc


	</select> -->

		<!-- 查询节假日分页 -->
	<select id="listlistPage" parameterType="page" resultType="pd">
		select
		<include refid="Field"></include>,
		CONCAT(l.START_DATE," 00:00:00") DATESTART,
		CONCAT(l.END_DATE," 00:00:00") DATEEND,
		(select group_concat(IFNULL(bh.USER_NAME,chr.NAME)) from BUS_CHECKUSER bh left join sys_user chr on chr.USER_ID=bh.USER_ID where bh.CHECKRECORD_ID=f.CHECKRECORD_ID) CHECK_USERS
		from
		<include refid="tableName"></include> f
		left join bus_listmanager l on l.LISTMANAGER_ID = f.LISTMANAGER_ID
		where 1=1 and  f.ISDELETE =0
		<if test="pd.FINISHED != null and pd.FINISHED != ''"><!-- 关键词检索 -->
			and
				f.FINISHED=#{pd.FINISHED}
		</if>
		<if test="pd.USER_ID != null and pd.USER_ID != ''"><!-- 关键词检索 -->
			and
				f.CREATOR=#{pd.USER_ID}
		</if>
		<if test="pd.LISTMANAGER_ID != null and pd.LISTMANAGER_ID != ''"><!-- 关键词检索 -->
			and
				f.LISTMANAGER_ID = #{pd.LISTMANAGER_ID}
		</if>
		<if test="pd.IS_DAY != null and pd.IS_DAY != ''"><!-- 关键词检索 -->
			and
				TO_DAYS(f.CHECK_TIME) = TO_DAYS(NOW())
		</if>
		<if test="pd.IS_WEEK != null and pd.IS_WEEK != ''"><!-- 关键词检索 -->
			and
				YEARWEEK(DATE_FORMAT(f.CHECK_TIME,'%Y-%m-%d')) = YEARWEEK(NOW())
		</if>
		<if test="pd.IS_XUN != null and pd.IS_XUN != ''"><!-- 关键词检索 -->
				<if test="pd.BEGINTIME != null and pd.BEGINTIME != ''"><!-- 关键词检索 -->
					and f.CHECK_TIME &gt;= #{pd.BEGINTIME}
				</if>
				<if test="pd.ENDTIME != null and pd.ENDTIME != ''">
					and f.CHECK_TIME &lt;= #{pd.ENDTIME}
				</if>
		</if>

		<if test="pd.IS_MONTH != null and pd.IS_MONTH != ''"><!-- 关键词检索 -->
			and
				DATE_FORMAT(f.CHECK_TIME,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')
		</if>
		<if test="pd.IS_QUARTER != null and pd.IS_QUARTER != ''"><!-- 关键词检索 -->
			and
				QUARTER(f.CHECK_TIME) = QUARTER(NOW());
		</if>

		<if test="pd.IS_HALFYEAR != null and pd.IS_HALFYEAR != ''">
			AND
			CONVERT(concat(DATE_FORMAT(f.CHECK_TIME, '%Y'), INTERVAL(CONVERT(MONTH(f.CHECK_TIME),SIGNED),7,13) ),SIGNED) =
			CONVERT(concat(DATE_FORMAT(NOW(), '%Y'), INTERVAL(CONVERT(MONTH(NOW()),SIGNED),7,13) ),SIGNED)
		</if>
		<if test="pd.IS_YEAR != null and pd.IS_YEAR != ''"><!-- 关键词检索 -->
			and
				YEAR(f.CHECK_TIME)=YEAR(NOW())
		</if>
	</select>

	<!-- 清单逾期检查记录数 -->
	<select id="countOverTime" parameterType="pd" resultType="int">

		select count(1) NUM from (
			select
			<include refid="Field"></include>,

			(select group_concat(IFNULL(bh.USER_NAME,chr.NAME)) from BUS_CHECKUSER bh left join sys_user chr on chr.USER_ID=bh.USER_ID where bh.CHECKRECORD_ID=f.CHECKRECORD_ID) CHECK_USERS,


			<if test="LISTTYPE != null and LISTTYPE != ''"><!-- 关键词检索 -->
				<choose>
					<when test='LISTTYPE=="checkPeriod0001"'>
						w.DAY_START DATESTART,
						w.DAY_END DATEEND,
					</when>
					<when test='LISTTYPE=="checkPeriod0002"'>
						w.WEEK_START DATESTART,
						w.WEEK_END DATEEND,
					</when>
					<when test='LISTTYPE=="checkPeriod0003"'>
						w.XUN_START DATESTART,
						w.XUN_END DATEEND,
					</when>
					<when test='LISTTYPE=="checkPeriod0004"'>
						w.MONTH_START DATESTART,
						w.MONTH_END DATEEND,
					</when>
					<when test='LISTTYPE=="checkPeriod0005"'>
						w.QUARTER_START DATESTART,
						w.QUARTER_END DATEEND,
					</when>
					<when test='LISTTYPE=="checkPeriod0007"'>
						w.HALFYEAR_START DATESTART,
						w.HALFYEAR_END DATEEND,
					</when>
					<when test='LISTTYPE=="checkPeriod0006"'>
						w.YEAR_START DATESTART,
						w.YEAR_END DATEEND,
					</when>
				</choose>
			</if>
			u.NAME AS USER_NAME,
			su.NAME AS PRINCIPALNAME
			FROM
			V_SYSDATE w
			left join <include refid="tableName"></include> f
			on w.DATE = DATE_FORMAT(f.CHECK_TIME,'%Y-%m-%d') and f.ISDELETE = '0'
			and f.CORPINFO_ID = #{CORPINFO_ID} and f.FINISHED='1'
			<if test="LISTMANAGER_ID != null and LISTMANAGER_ID != ''"><!-- 关键词检索 -->
				and
					(
						f.LISTMANAGER_ID = #{LISTMANAGER_ID}
					)
			</if>

			LEFT JOIN SYS_USER u on u.USERNAME=f.CREATOR
			LEFT JOIN BUS_LISTMANAGER l on l.LISTMANAGER_ID = f.LISTMANAGER_ID

			LEFT JOIN SYS_USER su on su.USER_ID = l.USER_ID
			WHERE
			DATE_FORMAT(#{LISTDATE},'%Y-%m-%d') &lt;= w.DATE
			<if test="KEYWORDS != null and KEYWORDS != ''"><!-- 关键词检索 -->
				and
					(
						f.LIST_NAME LIKE CONCAT(CONCAT('%', #{KEYWORDS}),'%')
					)
			</if>

			<if test="STARTTIME != null and STARTTIME != ''"><!-- 关键词检索 -->
				and f.CHECK_TIME &gt;= #{STARTTIME}
			</if>
			<if test="ENDTIME != null and ENDTIME != ''"><!-- 关键词检索 -->
				and f.CHECK_TIME &lt;= #{ENDTIME}
			</if>
			<if test="STATUS != null and STATUS != ''"><!-- 关键词检索 -->
				<choose>
					<when test='STATUS =="1"'>

						and f.CHECKRECORD_ID is not null
					</when>
					<when test='STATUS =="0"'>

						and f.CHECKRECORD_ID is null
					</when>
				</choose>
			</if>
			GROUP BY
			<if test="LISTTYPE != null and LISTTYPE != ''"><!-- 关键词检索 -->
				<choose>
					<when test='LISTTYPE=="checkPeriod0001"'>
						w.DAY_START,
						w.DAY_END,
					</when>
					<when test='LISTTYPE=="checkPeriod0002"'>
						w.WEEK_START,
						w.WEEK_END,
					</when>
					<when test='LISTTYPE=="checkPeriod0003"'>
						w.XUN_START,
						w.XUN_END,
					</when>
					<when test='LISTTYPE=="checkPeriod0004"'>
						w.MONTH_START,
						w.MONTH_END,
					</when>
					<when test='LISTTYPE=="checkPeriod0005"'>
						w.QUARTER_START,
						w.QUARTER_END,
					</when>
					<when test='LISTTYPE=="checkPeriod0007"'>
						w.HALFYEAR_START,
						w.HALFYEAR_END,
					</when>
					<when test='LISTTYPE=="checkPeriod0006"'>
						w.YEAR_START,
						w.YEAR_END,
					</when>
				</choose>
			</if>
			f.CHECK_TIME, f.CHECKRECORD_ID
			order by w.DATE desc
		) h
	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		where 1=1 and  f.ISDELETE =0
		<if test="FINISHED != null and FINISHED != ''"><!-- 关键词检索 -->
			and
				f.FINISHED=#{FINISHED}
		</if>
		<if test="USER_ID != null and USER_ID != ''"><!-- 关键词检索 -->
			and
				f.CREATOR=#{USER_ID}
		</if>
		<if test="LISTMANAGER_ID != null and LISTMANAGER_ID != ''"><!-- 关键词检索 -->
			and
				f.LISTMANAGER_ID = #{LISTMANAGER_ID}
		</if>
		<if test="IS_DAY != null and IS_DAY != ''"><!-- 关键词检索 -->
			and
				TO_DAYS(f.CHECK_TIME) = TO_DAYS(NOW())
		</if>
		<if test="IS_WEEK != null and IS_WEEK != ''"><!-- 关键词检索 -->
			and
				YEARWEEK(DATE_FORMAT(f.CHECK_TIME,'%Y-%m-%d')) = YEARWEEK(NOW())
		</if>
		<if test="IS_XUN != null and IS_XUN != ''"><!-- 关键词检索 -->
				<if test="BEGINTIME != null and BEGINTIME != ''"><!-- 关键词检索 -->
					and f.CHECK_TIME &gt;= #{BEGINTIME}
				</if>
				<if test="ENDTIME != null and ENDTIME != ''">
					and f.CHECK_TIME &lt;= #{ENDTIME}
				</if>
		</if>

		<if test="IS_MONTH != null and IS_MONTH != ''"><!-- 关键词检索 -->
			and
				DATE_FORMAT(f.CHECK_TIME,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')
		</if>
		<if test="IS_QUARTER != null and IS_QUARTER != ''"><!-- 关键词检索 -->
			and
				QUARTER(f.CHECK_TIME) = QUARTER(NOW());
		</if>

		<if test="IS_HALFYEAR != null and IS_HALFYEAR != ''">
			AND
			CONVERT(concat(DATE_FORMAT(f.CHECK_TIME, '%Y'), INTERVAL(CONVERT(MONTH(f.CHECK_TIME),SIGNED),7,13) ),SIGNED) =
			CONVERT(concat(DATE_FORMAT(NOW(), '%Y'), INTERVAL(CONVERT(MONTH(NOW()),SIGNED),7,13) ),SIGNED)
		</if>
		<if test="IS_YEAR != null and IS_YEAR != ''"><!-- 关键词检索 -->
			and
				YEAR(f.CHECK_TIME)=YEAR(NOW())
		</if>
	</select>

	<!-- 列表(全部) -->
	<select id="listAllUnfinished" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		where 1=1
		<if test="FINISHED != null and FINISHED != ''"><!-- 关键词检索 -->
			and
				f.FINISHED=#{FINISHED}
		</if>
		<if test="USER_ID != null and USER_ID != ''"><!-- 关键词检索 -->
			and
				f.CREATOR=#{USER_ID}
		</if>
		<if test="LISTMANAGER_ID != null and LISTMANAGER_ID != ''"><!-- 关键词检索 -->
			and
				f.LISTMANAGER_ID = #{LISTMANAGER_ID}
		</if>
		<if test="IS_DAY != null and IS_DAY != ''"><!-- 关键词检索 -->
			and
				TO_DAYS(f.CREATTIME) = TO_DAYS(NOW())
		</if>
		<if test="IS_WEEK != null and IS_WEEK != ''"><!-- 关键词检索 -->
			and
				YEARWEEK(DATE_FORMAT(f.CREATTIME,'%Y-%m-%d')) = YEARWEEK(NOW())
		</if>
		<if test="IS_XUN != null and IS_XUN != ''"><!-- 关键词检索 -->
				<if test="BEGINTIME != null and BEGINTIME != ''"><!-- 关键词检索 -->
					and f.CREATTIME &gt;= #{BEGINTIME}
				</if>
				<if test="ENDTIME != null and ENDTIME != ''">
					and f.CREATTIME &lt;= #{ENDTIME}
				</if>
		</if>

		<if test="IS_MONTH != null and IS_MONTH != ''"><!-- 关键词检索 -->
			and
				DATE_FORMAT(f.CREATTIME,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')
		</if>
		<if test="IS_QUARTER != null and IS_QUARTER != ''"><!-- 关键词检索 -->
			and
				QUARTER(f.CREATTIME) = QUARTER(NOW())
		</if>
		<if test="IS_HALFYEAR != null and IS_HALFYEAR != ''">
			AND
			CONVERT(concat(DATE_FORMAT(f.CREATTIME, '%Y'), INTERVAL(CONVERT(MONTH(f.CREATTIME),SIGNED),7,13) ),SIGNED) =
			CONVERT(concat(DATE_FORMAT(NOW(), '%Y'), INTERVAL(CONVERT(MONTH(NOW()),SIGNED),7,13) ),SIGNED)
		</if>
		<if test="IS_YEAR != null and IS_YEAR != ''"><!-- 关键词检索 -->
			and
				YEAR(f.CREATTIME)=YEAR(NOW())
		</if>
		ORDER BY f.CREATTIME DESC
	</select>

	<!-- 批量删除 -->
	<delete id="deleteAll" parameterType="String">
		update
		<include refid="tableName"></include>
		set
			ISDELETE = '1'
		where
			CHECKRECORD_ID in
		<foreach item="item" index="index" collection="ArrayDATA_IDS" open="(" separator="," close=")">
                 #{item}
		</foreach>
	</delete>


	<!-- 统计日 -->
	<select id="listCountDay" parameterType="pd" resultType="pd">
		SELECT
			COUNT(1) NUM,
			s.TYPE
		FROM
			(
			SELECT
				f.LISTMANAGER_ID,
				l.TYPE,
				l.PERIOD,
				DATE_FORMAT( f.CHECK_TIME, '%Y-%m-%d' ) CHECK_TIME
			FROM
				vi_list_checkrecord_all f
				LEFT JOIN vi_list_all l ON l.LISTMANAGER_ID = f.LISTMANAGER_ID and l.LIST_TYPE = f.LIST_TYPE
			WHERE
				f.FINISHED = '1'
				AND f.ISSTATISTICS = '1'
				AND f.ISDELETE = '0'
				AND l.PERIOD = 'checkPeriod0001'
				AND l.TYPE != 'listType0005'
				AND l.TYPE != 'listType0006'
				AND DATE_FORMAT( f.CHECK_TIME, '%Y-%m-%d' ) BETWEEN DATE_FORMAT( #{STARTTIME}, '%Y-%m-%d' ) and DATE_FORMAT( #{ENDTIME}, '%Y-%m-%d' )
				AND f.CORPINFO_ID = #{CORPINFO_ID}
			GROUP BY
				f.LISTMANAGER_ID,
				l.type,
				l.PERIOD,
				DATE_FORMAT( f.CHECK_TIME, '%Y-%m-%d' )
			) s
		GROUP BY s.TYPE
	</select>

	<!-- 统计周 -->
	<select id="listCountWeek" parameterType="pd" resultType="pd">
		SELECT
			TYPE,
			COUNT(1) NUM
		FROM (
			SELECT
				f.LISTMANAGER_ID,
				l.TYPE,
				l.PERIOD,
				YEARWEEK(DATE_FORMAT(f.CHECK_TIME,'%Y-%m-%d'),1) WEEKNUM
			FROM
				vi_list_checkrecord_all f
				LEFT JOIN vi_list_all l ON l.LISTMANAGER_ID = f.LISTMANAGER_ID and l.LIST_TYPE = f.LIST_TYPE
			WHERE
				f.FINISHED = '1'
				AND f.ISDELETE = '0'
				AND f.ISSTATISTICS = '1'
				AND l.PERIOD = 'checkPeriod0002'
				AND l.TYPE != 'listType0005'
				AND l.TYPE != 'listType0006'
				AND YEARWEEK( DATE_FORMAT( f.CHECK_TIME, '%Y-%m-%d' ), 1 ) &gt;= YEARWEEK( DATE_FORMAT( #{STARTTIME}, '%Y-%m-%d' ), 1 )
				AND YEARWEEK( DATE_FORMAT( f.CHECK_TIME, '%Y-%m-%d' ), 1 ) &lt;= YEARWEEK( DATE_FORMAT( #{ENDTIME}, '%Y-%m-%d' ), 1 )
				AND f.CORPINFO_ID = #{CORPINFO_ID}
			GROUP BY
				f.LISTMANAGER_ID,
				l.TYPE,
				l.PERIOD,
				WEEKNUM
			) s
		GROUP BY s.TYPE
	</select>

	<!-- 统计旬 -->
	<select id="listCountTenDays" parameterType="pd" resultType="pd">
		SELECT
			COUNT(1) NUM,
			s.TYPE
		FROM
			(
			SELECT
				f.LISTMANAGER_ID,
				l.TYPE,
				l.PERIOD
			FROM
				vi_list_checkrecord_all f
				LEFT JOIN vi_list_all l ON l.LISTMANAGER_ID = f.LISTMANAGER_ID and l.LIST_TYPE = f.LIST_TYPE
			WHERE
				f.FINISHED = '1'
				AND f.ISSTATISTICS = '1'
				AND f.ISDELETE = '0'
				AND l.PERIOD = 'checkPeriod0003'
				AND l.TYPE != 'listType0005'
				AND DATE_FORMAT( f.CHECK_TIME, '%Y-%m-%d' ) BETWEEN DATE_FORMAT( #{STARTTIME}, '%Y-%m-%d' ) and DATE_FORMAT( #{ENDTIME}, '%Y-%m-%d' ) <!-- 处理后的时间 -->
				AND f.CORPINFO_ID = #{CORPINFO_ID}
			GROUP BY
				f.LISTMANAGER_ID,
				l.type,
				l.PERIOD
			) s
		GROUP BY s.TYPE
	</select>

	<!-- 统计月 -->
	<select id="listCountMonth" parameterType="pd" resultType="pd">
		SELECT
			COUNT( 1 ) NUM,
			s.TYPE
		FROM
			(
			SELECT
				f.LISTMANAGER_ID,
				l.TYPE,
				l.PERIOD,
				DATE_FORMAT( f.CHECK_TIME, '%Y-%m' ) CHECK_TIME
			FROM
				vi_list_checkrecord_all f
				LEFT JOIN vi_list_all l ON l.LISTMANAGER_ID = f.LISTMANAGER_ID and l.LIST_TYPE = f.LIST_TYPE
			WHERE
				f.FINISHED = '1'
				AND f.ISDELETE = '0'
				AND f.ISSTATISTICS = '1'
				AND l.PERIOD = 'checkPeriod0004'
				AND l.TYPE != 'listType0005'
				AND l.TYPE != 'listType0006'
				AND DATE_FORMAT( f.CHECK_TIME, '%Y-%m' ) BETWEEN DATE_FORMAT( #{STARTTIME}, '%Y-%m' )
					AND DATE_FORMAT( #{ENDTIME}, '%Y-%m' )
				AND f.CORPINFO_ID = #{CORPINFO_ID}
			GROUP BY
				f.LISTMANAGER_ID,
				l.type,
				l.PERIOD,
				DATE_FORMAT( f.CHECK_TIME, '%Y-%m' )
			) s
		GROUP BY
			s.TYPE
	</select>

	<!-- 统计季 -->
	<select id="listCountQuarter" parameterType="pd" resultType="pd">
		SELECT
			COUNT( 1 ) NUM,
			s.TYPE
		FROM
			(
			SELECT
				f.LISTMANAGER_ID,
				l.TYPE,
				l.PERIOD,
				concat(
					DATE_FORMAT( f.CHECK_TIME, '%Y' ),
				QUARTER ( f.CHECK_TIME )) CHECK_TIME_quarter
			FROM
				vi_list_checkrecord_all f
				LEFT JOIN vi_list_all l ON l.LISTMANAGER_ID = f.LISTMANAGER_ID and l.LIST_TYPE = f.LIST_TYPE
			WHERE
				f.FINISHED = '1'
				AND f.ISDELETE = '0'
				AND f.ISSTATISTICS = '1'
				AND l.PERIOD = 'checkPeriod0005'
				AND l.TYPE != 'listType0005'
				AND l.TYPE != 'listType0006'
				AND
				CONVERT(concat(DATE_FORMAT(f.CHECK_TIME, '%Y'), QUARTER (f.CHECK_TIME)),SIGNED) &gt;=
				CONVERT(concat(DATE_FORMAT(#{STARTTIME}, '%Y'), QUARTER (#{STARTTIME})),SIGNED)
				AND
				CONVERT(concat(DATE_FORMAT(f.CHECK_TIME, '%Y'), QUARTER (f.CHECK_TIME)),SIGNED) &lt;=
				CONVERT(concat(DATE_FORMAT(#{ENDTIME}, '%Y'), QUARTER (#{ENDTIME})),SIGNED)
				AND f.CORPINFO_ID = #{CORPINFO_ID}
			GROUP BY
				f.LISTMANAGER_ID,
				l.type,
				l.PERIOD,
				concat(
					DATE_FORMAT( f.CHECK_TIME, '%Y' ),
				QUARTER ( f.CHECK_TIME ))
			) s
		GROUP BY
			s.TYPE
	</select>


		<!-- 统计半年 -->
	<select id="listCountHalfYear" parameterType="pd" resultType="pd">
		SELECT
			COUNT( 1 ) NUM,
			s.TYPE
		FROM
			(
			SELECT
				f.LISTMANAGER_ID,
				l.TYPE,
				l.PERIOD,
				concat(DATE_FORMAT(f.CHECK_TIME, '%Y'), INTERVAL(CONVERT(MONTH(f.CHECK_TIME),SIGNED),7,13) )
			FROM
				vi_list_checkrecord_all f
				LEFT JOIN vi_list_all l ON l.LISTMANAGER_ID = f.LISTMANAGER_ID and l.LIST_TYPE = f.LIST_TYPE
			WHERE
				f.FINISHED = '1'
				AND f.ISSTATISTICS = '1'
				AND f.ISDELETE = '0'
				AND l.PERIOD = 'checkPeriod0007'
				AND l.TYPE != 'listType0005'
				AND l.TYPE != 'listType0006'
				AND
				CONVERT(concat(DATE_FORMAT(f.CHECK_TIME, '%Y'), INTERVAL(CONVERT(MONTH(f.CHECK_TIME),SIGNED),7,13) ),SIGNED) &gt;=
				CONVERT(concat(DATE_FORMAT(#{STARTTIME}, '%Y'), INTERVAL(CONVERT(MONTH(#{STARTTIME}),SIGNED),7,13) ),SIGNED)
				AND
				CONVERT(concat(DATE_FORMAT(f.CHECK_TIME, '%Y'), INTERVAL(CONVERT(MONTH(f.CHECK_TIME),SIGNED),7,13) ),SIGNED) &lt;=
				CONVERT(concat(DATE_FORMAT(#{ENDTIME}, '%Y'), INTERVAL(CONVERT(MONTH(#{ENDTIME}),SIGNED),7,13)),SIGNED)
				AND f.CORPINFO_ID = #{CORPINFO_ID}
			GROUP BY
				f.LISTMANAGER_ID,
				l.type,
				l.PERIOD,
				concat(DATE_FORMAT(f.CHECK_TIME, '%Y'), INTERVAL(CONVERT(MONTH(f.CHECK_TIME),SIGNED),7,13) )
			) s
		GROUP BY
			s.TYPE
	</select>


	<!-- 统计年 -->
	<select id="listCountYear" parameterType="pd" resultType="pd">
		SELECT
			COUNT( 1 ) NUM,
			s.TYPE
		FROM
			(
			SELECT
				f.LISTMANAGER_ID,
				l.TYPE,
				l.PERIOD,
				DATE_FORMAT( f.CHECK_TIME, '%Y' ) CHECK_TIME
			FROM
				vi_list_checkrecord_all f
				LEFT JOIN vi_list_all l ON l.LISTMANAGER_ID = f.LISTMANAGER_ID and l.LIST_TYPE = f.LIST_TYPE
			WHERE
				f.FINISHED = '1'
				AND f.ISSTATISTICS = '1'
				AND f.ISDELETE = '0'
				AND l.PERIOD = 'checkPeriod0006'
				AND l.TYPE != 'listType0005'
				AND l.TYPE != 'listType0006'
				AND DATE_FORMAT( f.CHECK_TIME, '%Y' ) BETWEEN DATE_FORMAT(#{STARTTIME}, '%Y' )
					AND DATE_FORMAT(#{ENDTIME}, '%Y' )
				AND f.CORPINFO_ID = #{CORPINFO_ID}
			GROUP BY
				f.LISTMANAGER_ID,
				l.type,
				l.PERIOD,
				DATE_FORMAT( f.CHECK_TIME, '%Y' )
			) s
		GROUP BY
			s.TYPE
	</select>

		<!-- 统计节假日 -->
	<select id="listCountJjr" parameterType="pd" resultType="Integer">
		SELECT
			sum( s.num ) NUM
		FROM
			(
			SELECT
				f.LISTMANAGER_ID,
				l.TYPE,
				l.PERIOD,
				DATE_FORMAT( f.CHECK_TIME, '%Y' ) CHECK_TIME,
			IF
				(
					count( 1 )> 1,
					1,
				count( 1 )) num
			FROM
				vi_list_checkrecord_all f
				LEFT JOIN vi_list_all l ON l.LISTMANAGER_ID = f.LISTMANAGER_ID and l.LIST_TYPE = f.LIST_TYPE
			WHERE
				f.FINISHED = '1'
				AND f.ISSTATISTICS = '1'
				AND l.TYPE = 'listType0005'
				AND f.ISDELETE = '0'
				AND (
					l.START_DATE BETWEEN #{STARTTIME}
					AND #{ENDTIME}
					OR l.END_DATE BETWEEN #{STARTTIME}
					AND #{ENDTIME}
					OR ( l.START_DATE &lt;= #{STARTTIME} AND l.END_DATE &gt;= #{ENDTIME} )
				)
				AND f.CORPINFO_ID = #{CORPINFO_ID}
			GROUP BY
				f.LISTMANAGER_ID,
				l.type,
				l.PERIOD,
			DATE_FORMAT( f.CHECK_TIME, '%Y' )
		) s
	</select>


		<!-- 查询辨识部位检查记录 -->
	<select id="listLogByIde" parameterType="pd" resultType="pd">
		SELECT DISTINCT
			f.CHECKRECORD_ID,
			IFNULL(cu.USER_NAME, u.NAME) NAME,
			r.PARTSNAME,
			l.NAME as LISTNAME,
			DATE_FORMAT( f.CHECK_TIME, '%Y-%m-%d %H:%i' ) CHECK_TIME
		FROM
			bus_checkrecord f
			LEFT JOIN bus_checkuser cu ON cu.CHECKRECORD_ID = f.CHECKRECORD_ID
			LEFT JOIN sys_user u ON cu.USER_ID = u.USER_ID
			LEFT JOIN bus_listmanager l ON f.LISTMANAGER_ID = l.LISTMANAGER_ID
			LEFT JOIN bus_recorditem r ON r.CHECKRECORD_ID = f.CHECKRECORD_ID
		WHERE
			f.CORPINFO_ID = #{CORPINFO_ID}
			AND f.ISDELETE = '0'
			AND f.FINISHED = '1'
			AND l.ISDELETE = '0'
			AND TO_DAYS( f.CHECK_TIME ) = TO_DAYS(NOW())
		ORDER BY
			f.CHECK_TIME DESC
	</select>

	<!-- 指定辨识部位检查记录 -->
	<select id="recordByIde" parameterType="pd" resultType="pd">
		SELECT
			DISTINCT
			f.CHECKRECORD_ID,
			l.LISTMANAGER_ID,
			l.NAME LISTMANAGERNAME,
			IFNULL(cu.USER_NAME, u.NAME) USERNAME,
			id.PARTSNAME PARTSNAME,
			DATE_FORMAT( f.CHECK_TIME, '%Y-%m-%d %H:%i' ) CHECK_TIME
		FROM
			bus_checkrecord f
			LEFT JOIN bus_checkuser cu ON cu.CHECKRECORD_ID = f.CHECKRECORD_ID
			LEFT JOIN sys_user u ON cu.USER_ID = u.USER_ID
			LEFT JOIN bus_listmanager l ON f.LISTMANAGER_ID = l.LISTMANAGER_ID
			LEFT JOIN bus_recorditem r ON r.CHECKRECORD_ID = f.CHECKRECORD_ID
			left join bus_list_checkitem lc on lc.LISTCHECKITEM_ID = r.LISTCHECKITEM_ID
			left join bus_riskpoint rp on rp.RISKPOINT_ID = lc.RISKPOINT_ID
			left join bus_identificationparts id on id.IDENTIFICATIONPARTS_ID = rp.IDENTIFICATION_ID
		WHERE
			id.IDENTIFICATIONPARTS_ID = #{IDENTIFICATIONPARTS_ID}
			and  f.ISDELETE = '0'
			AND f.FINISHED = '1'
			AND l.ISDELETE = '0'
			AND lc.ISDELETE = '0'
			AND rp.ISDELETE = '0'
			AND id.ISDELETE = '0'
			<if test="KEYWORDS != null and KEYWORDS != ''">
				and
				(
					l.NAME LIKE CONCAT(CONCAT('%', #{KEYWORDS}),'%')
				)
			</if>
		ORDER BY
			f.CHECK_TIME DESC
	</select>

		<!-- 修改统计状态 -->
	<update id="editStatistics" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			ISSTATISTICS= #{ISSTATISTICS}
		where
			LISTMANAGER_ID = #{LISTMANAGER_ID}
			AND
			DATE_FORMAT( CHECK_TIME, '%Y-%m-%d ' ) between DATE_FORMAT( #{STARTTIME}, '%Y-%m-%d' ) AND DATE_FORMAT( #{ENDTIME}, '%Y-%m-%d' )
			AND
			CORPINFO_ID = #{CORPINFO_ID}
	</update>

	<!-- 补录 -->
	<update id="recording" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			<if test="CREATOR != null and CREATOR != ''">
				CREATOR = #{CREATOR},
			</if>
			<if test="OPERATOR != null and OPERATOR != ''">
				OPERATOR = #{OPERATOR},
			</if>
			<if test="DESCR != null and DESCR != ''">
				DESCR = #{DESCR},
			</if>
			<if test="LONGITUDE != null and LONGITUDE != ''">
				LONGITUDE = #{LONGITUDE},
			</if>
			<if test="LATITUDE != null and LATITUDE != ''">
				LATITUDE = #{LATITUDE},
			</if>
			<if test="CHECK_TIME != null and CHECK_TIME != ''">
				CHECK_TIME = #{CHECK_TIME},
			</if>
			<if test="ISSTATISTICS != null and ISSTATISTICS != ''">
				ISSTATISTICS = #{ISSTATISTICS},
			</if>
			<if test="REASON != null and REASON != ''">
				REASON = #{REASON},
			</if>
			<if test="TYPE != null and TYPE != ''">
				TYPE = #{TYPE},
			</if>
			CHECKRECORD_ID = CHECKRECORD_ID
		where
			CHECKRECORD_ID = #{CHECKRECORD_ID}
	</update>
	<!-- 统计各用户各类型检查数据 -->
	<select id="countByPeriodUser" parameterType="pd" resultType="pd">
		SELECT
			l.USER_ID,
			COUNT( DISTINCT CASE l.PERIOD WHEN 'checkPeriod0001' THEN l.LISTMANAGER_ID END ) CHECKPERIOD1,
			COUNT( DISTINCT CASE l.PERIOD WHEN 'checkPeriod0002' THEN l.LISTMANAGER_ID END ) CHECKPERIOD2,
			COUNT( DISTINCT CASE l.PERIOD WHEN 'checkPeriod0003' THEN l.LISTMANAGER_ID END ) CHECKPERIOD3,
			COUNT( DISTINCT CASE l.PERIOD WHEN 'checkPeriod0004' THEN l.LISTMANAGER_ID END ) CHECKPERIOD4,
			COUNT( DISTINCT CASE l.PERIOD WHEN 'checkPeriod0005' THEN l.LISTMANAGER_ID END ) CHECKPERIOD5,
			COUNT( DISTINCT CASE l.PERIOD WHEN 'checkPeriod0006' THEN l.LISTMANAGER_ID END ) CHECKPERIOD6,
			COUNT( DISTINCT CASE l.PERIOD WHEN 'checkPeriod0007' THEN l.LISTMANAGER_ID END ) CHECKPERIOD7
		FROM
			BUS_CHECKRECORD f
			LEFT JOIN BUS_LISTMANAGER l ON l.LISTMANAGER_ID = f.LISTMANAGER_ID
		WHERE
			f.ISDELETE = '0'
			AND f.FINISHED = '1'
			AND f.ISSTATISTICS = '1'
			AND f.TYPE = '1'
			AND l.USER_ID IS NOT NULL
			AND l.TYPE != 'listType0005'
			AND l.ISDELETE = '0'
			AND f.CORPINFO_ID = #{CORPINFO_ID}
			AND DATE_FORMAT(#{TIME},"%Y-%m-%d %H:%i:%S") BETWEEN f.PERIODSTART AND f.PERIODEND
		GROUP BY
			l.USER_ID
	</select>

	<!-- 查询公司检查过清单的员工总数 -->
	<select id="getWorkedUserCount" parameterType="pd" resultType="int" >
		SELECT
			COUNT( DISTINCT U.USER_ID )
		FROM
			BUS_LISTMANAGER F
				LEFT JOIN SYS_DICTIONARIES P ON F.PERIOD = P.BIANMA
				LEFT JOIN SYS_DICTIONARIES T ON F.TYPE = T.BIANMA
				LEFT JOIN SYS_DICTIONARIES S ON F.SCREENTYPE = S.BIANMA
				LEFT JOIN SYS_DICTIONARIES BB ON F.TASK_TYPE = BB.DICTIONARIES_ID
				LEFT JOIN OA_DEPARTMENT D ON D.DEPARTMENT_ID = F.DEPARTMENT_ID
				LEFT JOIN SYS_POST SP ON SP.POST_ID = F.POST_ID
				LEFT JOIN SYS_USER U ON U.USER_ID = F.USER_ID
		WHERE
			F.CORPINFO_ID = #{CORPINFO_ID}
		  AND F.ISDELETE = '0'
		ORDER BY
			F.ISDELETE,
			F.OPERATTIME DESC
	</select>

	<!-- 查询公司检查过清单的部门总数 -->
	<select id="getWorkedDepCount" parameterType="pd" resultType="int" >
		SELECT
			COUNT( DISTINCT F.DEPARTMENT_ID )
		FROM
			BUS_LISTMANAGER F
				LEFT JOIN SYS_DICTIONARIES P ON F.PERIOD = P.BIANMA
				LEFT JOIN SYS_DICTIONARIES T ON F.TYPE = T.BIANMA
				LEFT JOIN SYS_DICTIONARIES S ON F.SCREENTYPE = S.BIANMA
				LEFT JOIN SYS_DICTIONARIES BB ON F.TASK_TYPE = BB.DICTIONARIES_ID
				LEFT JOIN OA_DEPARTMENT D ON D.DEPARTMENT_ID = F.DEPARTMENT_ID
				LEFT JOIN SYS_POST SP ON SP.POST_ID = F.POST_ID
				LEFT JOIN SYS_USER U ON U.USER_ID = F.USER_ID
		WHERE
			F.CORPINFO_ID = #{CORPINFO_ID}
		  AND F.ISDELETE = '0'
		ORDER BY
			F.ISDELETE,
			F.OPERATTIME DESC
	</select>

	<select id="listTypeBi" parameterType="pd" resultType="pd">
		select count(1) count,d.NAME
		from vi_list_checkrecord_all f
		left join vi_list_all l on f.LISTMANAGER_ID = l.LISTMANAGER_ID and f.LIST_TYPE = l.LIST_TYPE
		left join sys_dictionaries d on d.BIANMA = l.SCREENTYPE
		where f.ISDELETE = '0'
		AND f.FINISHED = '1'
		AND f.TYPE='1'
		AND f.CHECKRECORD_ID IS NOT NULL
		AND DATE_FORMAT( f.CREATTIME, '%Y' ) = DATE_FORMAT( NOW(), '%Y' )
		<if test="CORPINFO_ID != null and CORPINFO_ID != ''"><!-- 关键词检索 -->
			and f.CORPINFO_ID = #{CORPINFO_ID}
		</if>

		group by d.NAME
	</select>

	<!-- 查询未对接数据 -->
	<select id="listForDocking" parameterType="pd" resultType="pd" >
		SELECT
			c.CHECKRECORD_ID,
			c.LISTMANAGER_ID,
			c.CHECK_TIME,
			c.CREATTIME,
			c.OPERATTIME,
			l.NAME,
			l.TYPE,
			l.PERIOD,
			l.DEPARTMENT_ID,
			l.USER_ID,
		   (select count(1) from BUS_HIDDEN  h where h.CHECKRECORD_ID = c.CHECKRECORD_ID and h.ISDELETE = 0) as hdc
		FROM
			BUS_CHECKRECORD c
			left join BUS_LISTMANAGER l on l.LISTMANAGER_ID = c.LISTMANAGER_ID
		WHERE
			c.CORPINFO_ID = #{CORPINFO_ID}
			and c.IS_DOCKING is null
			and c.ISDELETE = 0
			and c.FINISHED = 1
			and c.TYPE = 1
	</select>

	<update id="updateDocking" parameterType="pd" >
		update
			BUS_CHECKRECORD
		set
			IS_DOCKING = 1
		where
			CHECKRECORD_ID = #{CHECKRECORD_ID}
	</update>

	<!-- 查询检查记录(按ids) -->
	<select id="listForIdsAndMonth" parameterType="pd" resultType="pd" >
		SELECT
			c.LISTMANAGER_ID,
			c.CREATTIME,
			c.TYPE,
			c.PERIODSTART,
			c.PERIODEND,
			COUNT(h.HIDDEN_ID) HIDDEN_COUNT
		FROM
			vi_list_checkrecord_all c
			left join vi_hidden_all h on h.CHECKRECORD_ID = c.CHECKRECORD_ID and h.LIST_TYPE = c.LIST_TYPE and h.ISDELETE = '0'
		WHERE
			c.FINISHED = 1
		  	and (#{MONTH} &gt;= DATE_FORMAT(c.PERIODSTART,'%Y-%m') and #{MONTH} &lt;=DATE_FORMAT(c.PERIODEND,'%Y-%m'))
			and c.LISTMANAGER_ID in
			<foreach item="item" index="index"
					 collection="LIST_IDS" open="(" separator="," close=")">
				'${item}'
			</foreach>
		GROUP BY c.CHECKRECORD_ID
		order by PERIODSTART
	</select>

	<select id="anaysis" resultType="com.zcloud.entity.PageData">
		select count(1) as num,bl.TASK_TYPE,sd.NAME as TASK_TYPE_NAME
		from bus_checkrecord a
		left join bus_listmanager bl on bl.LISTMANAGER_ID = a.LISTMANAGER_ID
		left join sys_dictionaries sd on bl.TASK_TYPE = sd.DICTIONARIES_ID
		where a.ISDELETE = '0'
		<if test="ids != null and ids.size != 0">
			and a.LISTMANAGER_ID in
			<foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
				'${item}'
			</foreach>
		</if>
		<if test="FINISHED != null and FINISHED != ''">
			and a.FINISHED = #{FINISHED}
		</if>
		group by bl.TASK_TYPE;
	</select>

	<select id="findByNumber" resultType="com.zcloud.entity.PageData">
		select count(1) as num from bus_checkrecord a
			left join bus_listmanager b on b.LISTMANAGER_ID = a.LISTMANAGER_ID where a.ISDELETE = '0'
		<if test="ids != null and ids.size != 0">
			and a.LISTMANAGER_ID in
			<foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
				'${item}'
			</foreach>
		</if>
		<if test="date != null and date != ''">
			and DATE_FORMAT(a.CREATTIME,'%Y') = #{date}
		</if>
		<if test="BAO_BAO_TYPE != null and BAO_BAO_TYPE != ''">
			and b.BAO_BAO_TYPE = #{BAO_BAO_TYPE}
		</if>
		<if test="TASK_TYPE != null and TASK_TYPE != ''">
			and b.TASK_TYPE = #{TASK_TYPE}
		</if>
	</select>

	<!-- 清单检查记录（日检）统计(按清单ID统计指定年内检查情况) -->
	<select id="listAllYearForDay" parameterType="pd" resultType="pd" >
		SELECT
		c.LISTMANAGER_ID,
		c.CREATTIME,
		c.TYPE,
		c.PERIODSTART,
		c.PERIODEND,
		COUNT(h.HIDDEN_ID) HIDDEN_COUNT,
		GROUP_CONCAT(
		    CONCAT(h.CREATTIME,'  ',h.HIDDENDESCR
<!-- 		        (IF(h.RECTIFYDESCR IS NULL OR h.RECTIFYDESCR = '','',CONCAT('【整改情况：',h.RECTIFYDESCR,'】')))-->
			)
		SEPARATOR '$') HIDDEN_DESC
		FROM
		BUS_CHECKRECORD c
		left join bus_hidden h on h.CHECKRECORD_ID = c.CHECKRECORD_ID and h.ISDELETE = '0'
		WHERE
		c.FINISHED = 1
		and (#{YEAR} &gt;= DATE_FORMAT(c.PERIODSTART,'%Y') and #{YEAR} &lt;=DATE_FORMAT(c.PERIODEND,'%Y'))
		and c.LISTMANAGER_ID = #{LISTMANAGER_ID}
		GROUP BY c.CHECKRECORD_ID
		order by PERIODSTART
	</select>

	<!-- 清单检查记录（周检）统计(按清单ID统计指定年内检查情况) -->
	<select id="listAllYearForWeek" parameterType="pd" resultType="pd" >
		SELECT
			c.LISTMANAGER_ID,
			c.CREATTIME,
			c.TYPE,
			c.PERIODSTART,
			c.PERIODEND,
			COUNT(h.HIDDEN_ID) HIDDEN_COUNT,
			GROUP_CONCAT( CONCAT(h.CREATTIME,'  ',h.HIDDENDESCR) SEPARATOR '$') HIDDENDESCR,
			GROUP_CONCAT(h.RECTIFYDESCR SEPARATOR '$') RECTIFYDESCR
		FROM
			BUS_CHECKRECORD c
				left join bus_hidden h on h.CHECKRECORD_ID = c.CHECKRECORD_ID and h.ISDELETE = '0'
		WHERE
			c.FINISHED = 1
		  and (#{YEAR} &gt;= DATE_FORMAT(c.PERIODSTART,'%Y') and #{YEAR} &lt;=DATE_FORMAT(c.PERIODEND,'%Y'))
		  and c.LISTMANAGER_ID = #{LISTMANAGER_ID}
		GROUP BY c.CHECKRECORD_ID
		order by PERIODSTART
	</select>

	<!-- 清单检查记录（旬检）统计(按清单ID统计指定年内检查情况) -->
	<select id="listAllYearForTenday" parameterType="pd" resultType="pd" >
		SELECT
			c.LISTMANAGER_ID,
			c.CREATTIME,
			c.TYPE,
			c.PERIODSTART,
			c.PERIODEND,
			COUNT(h.HIDDEN_ID) HIDDEN_COUNT,
			GROUP_CONCAT(CONCAT(h.CREATTIME,'  ',h.HIDDENDESCR) SEPARATOR '$') HIDDENDESCR,
			GROUP_CONCAT(h.RECTIFYDESCR SEPARATOR '$') RECTIFYDESCR
		FROM
			BUS_CHECKRECORD c
				left join bus_hidden h on h.CHECKRECORD_ID = c.CHECKRECORD_ID and h.ISDELETE = '0'
		WHERE
			c.FINISHED = 1
		  and (#{YEAR} &gt;= DATE_FORMAT(c.PERIODSTART,'%Y') and #{YEAR} &lt;=DATE_FORMAT(c.PERIODEND,'%Y'))
		  and c.LISTMANAGER_ID = #{LISTMANAGER_ID}
		GROUP BY c.CHECKRECORD_ID
		order by PERIODSTART
	</select>
</mapper>
