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

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.NAME,
		f.PERIOD,
		f.TYPE,
		f.CORPINFO_ID,
		f.CREATOR,
		f.CREATTIME,
		f.OPERATOR,
		f.OPERATTIME,
		f.ISDELETE,
		f.LISTMANAGER_ID,
		f.DEPARTMENT_ID,
		f.POST_ID,
		f.USER_ID,
		f.ACOUNT,
		f.BCOUNT,
		f.CCOUNT,
		f.DCOUNT,
		f.START_DATE,
		f.END_DATE,
		f.SCREENTYPE,
		f.BAO_BAO_DEPARTMENT_ID,
	  	f.BAO_BAO_USER_ID,
	  	f.BAO_BAO_TYPE,
	  	f.TASK_TYPE,
		f.ATTRIBUTE
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		NAME,
		PERIOD,
		TYPE,
		CORPINFO_ID,
		CREATOR,
		CREATTIME,
		OPERATOR,
		OPERATTIME,
		ISDELETE,
		LISTMANAGER_ID,
		DEPARTMENT_ID,
		POST_ID,
		USER_ID,
		ACOUNT,
		BCOUNT,
		CCOUNT,
		DCOUNT,
		START_DATE,
		END_DATE,
		SCREENTYPE,
		BAO_BAO_DEPARTMENT_ID,
	  	BAO_BAO_USER_ID,
	  	BAO_BAO_TYPE,
	  	TASK_TYPE,
		ATTRIBUTE
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{NAME},
		#{PERIOD},
		#{TYPE},
		#{CORPINFO_ID},
		#{CREATOR},
		#{CREATTIME},
		#{OPERATOR},
		#{OPERATTIME},
		#{ISDELETE},
		#{LISTMANAGER_ID},
		#{DEPARTMENT_ID},
		#{POST_ID},
		#{USER_ID},
		#{ACOUNT},
		#{BCOUNT},
		#{CCOUNT},
		#{DCOUNT},
		#{START_DATE},
		#{END_DATE},
		#{SCREENTYPE},
		#{BAO_BAO_DEPARTMENT_ID},
		#{BAO_BAO_USER_ID},
		#{BAO_BAO_TYPE},
		#{TASK_TYPE},
		#{ATTRIBUTE}
	</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'
		<if test="OPERATTIME != null or OPERATTIME != ''">
			,OPERATTIME =#{OPERATTIME}
		</if>
		<if test="OPERATOR != null or OPERATOR != ''">
			,OPERATOR =#{OPERATOR}
		</if>
		where
		LISTMANAGER_ID = #{LISTMANAGER_ID}
	</delete>

	<!-- 删除 -->
	<delete id="remove" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
		ISDELETE = '2'
		<if test="OPERATTIME != null or OPERATTIME != ''">
			,OPERATTIME =#{OPERATTIME}
		</if>
		<if test="OPERATOR != null or OPERATOR != ''">
			,OPERATOR =#{OPERATOR}
		</if>
		where
		LISTMANAGER_ID = #{LISTMANAGER_ID}
	</delete>

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

	<!-- 删除 -->
	<delete id="deletedThorough" parameterType="pd">
		delete FROM
		<include refid="tableName"></include>
		where
		LISTMANAGER_ID = #{LISTMANAGER_ID}
	</delete>
	<!-- 启用 -->
	<update id="enable" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
		ISDELETE = '0'
		<if test="OPERATTIME != null or OPERATTIME != ''">
			,OPERATTIME =#{OPERATTIME}
		</if>
		<if test="OPERATOR != null or OPERATOR != ''">
			,OPERATOR =#{OPERATOR}
		</if>
		where
		LISTMANAGER_ID = #{LISTMANAGER_ID}
	</update>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
		NAME = #{NAME},
		PERIOD = #{PERIOD},
		TYPE = #{TYPE},
		ACOUNT = #{ACOUNT},
		BCOUNT = #{BCOUNT},
		CCOUNT = #{CCOUNT},
		DCOUNT = #{DCOUNT},
		ATTRIBUTE = #{ATTRIBUTE},
		<if test="BAO_BAO_DEPARTMENT_ID != null or BAO_BAO_DEPARTMENT_ID != ''">
			BAO_BAO_DEPARTMENT_ID = #{BAO_BAO_DEPARTMENT_ID},
		</if>
		<if test="ISDELETE != null or ISDELETE != ''">
			ISDELETE = #{ISDELETE},
		</if>
		<if test="BAO_BAO_USER_ID != null or BAO_BAO_USER_ID != ''">
			BAO_BAO_USER_ID = #{BAO_BAO_USER_ID},
		</if>
		<if test="BAO_BAO_TYPE != null or BAO_BAO_TYPE != ''">
			BAO_BAO_TYPE = #{BAO_BAO_TYPE},
		</if>
		<if test="TASK_TYPE != null or TASK_TYPE != ''">
			TASK_TYPE = #{TASK_TYPE},
		</if>
		<if test="DEPARTMENT_ID != null or DEPARTMENT_ID != ''">
			DEPARTMENT_ID= #{DEPARTMENT_ID},
		</if>
		<if test="POST_ID != null or POST_ID != ''">
			POST_ID =#{POST_ID},
		</if>
		<if test="SCREENTYPE != null or SCREENTYPE != ''">
			SCREENTYPE =#{SCREENTYPE},
		</if>
		<if test="START_DATE != null or START_DATE != ''">
			START_DATE =#{START_DATE},
		</if>
		<if test="END_DATE != null or END_DATE != ''">
			END_DATE =#{END_DATE},
		</if>
		<if test="OVERTIMENUM != null or OVERTIMENUM != ''">
			OVERTIMENUM =#{OVERTIMENUM},
		</if>
		<if test="USER_ID != null or USER_ID!= ''">
			USER_ID =#{USER_ID},
		</if>
		LISTMANAGER_ID = LISTMANAGER_ID
		where
		LISTMANAGER_ID = #{LISTMANAGER_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,
		tt.NAME as TASK_TYPE_NAME,
		sp.NAME
		AS POST_NAME,
		s.NAME AS SCREENTYPENAME,
		u.NAME AS USER_NAME,
		bb.NAME as BAO_BAO_USER_NAME,
		bbd.NAME as BAO_BAO_DEPARTMENT_NAME
		from
		<include refid="tableName"></include>
		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 tt on f.TASK_TYPE = tt.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
		LEFT JOIN SYS_USER bb on bb.USER_ID = f.BAO_BAO_USER_ID
		left join OA_DEPARTMENT bbd on bbd.DEPARTMENT_ID=f.DEPARTMENT_ID
		where
		f.LISTMANAGER_ID = #{LISTMANAGER_ID}
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
		<include refid="Field"></include>
		,
		p.NAME PERIODNAME,
		t.NAME TYPENAME,
		d.NAME as DEPARTMENT_NAME,
		getFullName(d.DEPARTMENT_ID) as DEPARTMENT_NAME_ALL,
		sp.NAME
		AS POST_NAME,
		u.NAME USER_NAME,
		bb.NAME as TASK_TYPE_NAME,
		s.NAME AS SCREENTYPENAME,
		(select count(1) from BUS_LIST_CHECKITEM ch where
		ch.LISTMANAGER_ID=f.LISTMANAGER_ID and ch.ISDELETE = '0') as count ,
		(SELECT count(1) FROM BUS_CHECKRECORD ch WHERE ch.LISTMANAGER_ID =
		f.LISTMANAGER_ID AND ch.FINISHED = '1' AND ch.ISDELETE = 0 ) as
		cdcount
		from
		<include refid="tableName"></include>
		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 = #{pd.CORPINFO_ID}

		and f.ISDELETE != '2'  and f.ISDELETE !='-1'
		<!-- 是否隐藏禁用清单，当HIDFORBIDDEN为空时，隐藏已禁用清单 -->
		<!-- <if test="pd.HIDFORBIDDEN == null or pd.HIDFORBIDDEN == ''">
			and f.ISDELETE = '0'
		</if> -->
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and
			(
			f.NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
			)
		</if>
		<if test="pd.POST_ID != null and pd.POST_ID != ''"><!-- 关键词检索 -->
			and
			(
			f.POST_ID = #{pd.POST_ID}
			)
		</if>
		<if test="pd.PERIOD != null and pd.PERIOD != ''"><!-- 关键词检索 -->
			and f.PERIOD = #{pd.PERIOD}
		</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
					f.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"'>
								<choose>
									<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
										and
										f.DEPARTMENT_ID in
										<foreach item="item" index="index"
												 collection="pd.DEPT_IDS" open="(" separator="," close=")">
											'${item}'
										</foreach>
									</when>
									<otherwise>
										and
										((f.DEPARTMENT_ID in (
										select
										SUB_DEPARTMENT_ID
										from
										oa_supervision_department osd
										where
										osd.SUP_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
										and osd.ISDELETE = '0'
										and osd.CORPINFO_ID  = #{pd.CORPINFO_ID}
										)) or (
										f.DEPARTMENT_ID in
										<foreach item="item" index="index"
												 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
											'${item}'
										</foreach>
										))
									</otherwise>
								</choose>
							</when>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<otherwise>

								and
								(f.DEPARTMENT_ID in (
								select
								SUB_DEPARTMENT_ID
								from
								oa_supervision_department osd
								where
								osd.SUP_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
								and osd.ISDELETE = '0'
								and osd.CORPINFO_ID  = #{pd.CORPINFO_ID})
								or f.USER_ID = #{pd.USER_ID})
							</otherwise>
						</choose>
					</when>

					<when test='pd.ISLEADER != null and pd.ISLEADER != "" and pd.ISLEADER == "1"'>
						<choose>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<otherwise>
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</otherwise>
						</choose>
					</when>
					<when test="pd.DEPARTMENT_ID != null and pd.DEPARTMENT_ID != ''">
						and f.USER_ID = #{pd.USER_ID}
						and f.DEPARTMENT_ID=#{pd.DEPARTMENT_ID}
					</when>
					<otherwise>
					</otherwise>
				</choose>
			</otherwise>
		</choose>
		<if test="pd.USERNAME != null and pd.USERNAME != ''"><!-- 关键词检索 -->
			and u.NAME LIKE CONCAT(CONCAT('%', #{pd.USERNAME}),'%')
		</if>
		<if test="pd.TYPE != null and pd.TYPE != ''"><!-- 关键词检索 -->
			and f.TYPE = #{pd.TYPE}
		</if>
		<if test="pd.LISTINGLEVEL != null and pd.LISTINGLEVEL != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.LISTINGLEVEL == "1"'>
					and d.LEVEL = ''
				</when>
				<otherwise>
					and d.LEVEL = #{pd.LISTINGLEVEL}
				</otherwise>
			</choose>
		</if>
		<if
				test="pd.RISKCHECKLISTTYPE != null and pd.RISKCHECKLISTTYPE != ''"><!-- 关键词检索 -->
			and f.SCREENTYPE = #{pd.RISKCHECKLISTTYPE}
		</if>
		order by f.ISDELETE,f.OPERATTIME desc
	</select>

	<!-- 列表 -->
	<select id="stopdatalistPage" parameterType="page" resultType="pd">
		select
		<include refid="Field"></include>
		,
		p.NAME PERIODNAME,
		t.NAME TYPENAME,
		d.NAME as DEPARTMENT_NAME,
		getFullName(d.DEPARTMENT_ID) as DEPARTMENT_NAME_ALL,
		sp.NAME
		AS POST_NAME,
		u.NAME USER_NAME,
		bb.NAME as TASK_TYPE_NAME,
		s.NAME AS SCREENTYPENAME,
		(select count(1) from BUS_LIST_CHECKITEM ch where
		ch.LISTMANAGER_ID=f.LISTMANAGER_ID and ch.ISDELETE = '0') as count ,
		(SELECT count(1) FROM BUS_CHECKRECORD ch WHERE ch.LISTMANAGER_ID =
		f.LISTMANAGER_ID AND ch.FINISHED = '1' AND ch.ISDELETE = 0 ) as
		cdcount
		from
		<include refid="tableName"></include>
		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 = #{pd.CORPINFO_ID}
		and f.ISDELETE = '2'

		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and
			(
			f.NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
			)
		</if>
		<if test="pd.POST_ID != null and pd.POST_ID != ''"><!-- 关键词检索 -->
			and
			(
			f.POST_ID = #{pd.POST_ID}
			)
		</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
					f.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.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<otherwise>
								and
								(f.DEPARTMENT_ID in (
								select
								SUB_DEPARTMENT_ID
								from
								oa_supervision_department osd
								where
								osd.SUP_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
								and osd.ISDELETE = '0'
								and osd.CORPINFO_ID  = #{pd.CORPINFO_ID}
								)or f.USER_ID = #{pd.USER_ID})
							</otherwise>
						</choose>
					</when>
					<when test='pd.ISLEADER != null and pd.ISLEADER != "" and pd.ISLEADER == "1"'>
						<choose>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<otherwise>
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</otherwise>
						</choose>
					</when>
					<when test="pd.DEPARTMENT_ID != null and pd.DEPARTMENT_ID != ''">
						and f.DEPARTMENT_ID=#{pd.DEPARTMENT_ID}
					</when>
					<otherwise>
					</otherwise>
				</choose>
			</otherwise>
		</choose>
		<if test="pd.USERNAME != null and pd.USERNAME != ''"><!-- 关键词检索 -->
			and u.NAME LIKE CONCAT(CONCAT('%', #{pd.USERNAME}),'%')
		</if>
		<if test="pd.TYPE != null and pd.TYPE != ''"><!-- 关键词检索 -->
			and f.TYPE = #{pd.TYPE}
		</if>
		<if test="pd.LISTINGLEVEL != null and pd.LISTINGLEVEL != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.LISTINGLEVEL == "1"'>
					and d.LEVEL = ''
				</when>
				<otherwise>
					and d.LEVEL = #{pd.LISTINGLEVEL}
				</otherwise>
			</choose>
		</if>
		<if
				test="pd.RISKCHECKLISTTYPE != null and pd.RISKCHECKLISTTYPE != ''"><!-- 关键词检索 -->
			and f.SCREENTYPE = #{pd.RISKCHECKLISTTYPE}
		</if>
		order by f.ISDELETE,f.OPERATTIME,f.DEPARTMENT_ID desc
	</select>


	<!-- 部门清单列表 -->
	<select id="recordlistPage" parameterType="page" resultType="pd">
		select * from
		(
		select
		<include refid="Field"></include>
		,
		u.WORKSTATUS,
		a.STARTTIME,
		a.ENDTIME ,
		p.NAME PERIODNAME,
		t.NAME TYPENAME,
		m.NAME SCREENTYPENAME,
		d.NAME as DEPARTMENT_NAME,
		getFullName(d.DEPARTMENT_ID) as DEPARTMENT_NAME_ALL,
		sp.NAME
		AS POST_NAME,
		u.NAME as USER_NAME,
		(
		select count(1) from BUS_CHECKRECORD ch
		where ch.LISTMANAGER_ID=f.LISTMANAGER_ID AND ch.type = '1'
		and ch.FINISHED='1' and ch.ISDELETE =0
		) as count ,
		(
		select
		count(1)
		from BUS_CHECKRECORD ch
		left join bus_hidden h on h.CHECKRECORD_ID = ch.CHECKRECORD_ID
		where ch.LISTMANAGER_ID=f.LISTMANAGER_ID
		and ch.FINISHED='1'
		and ch.ISDELETE =0
		and h.ISDELETE =0
		and h.HIDDEN_ID is not null
		) as hiddenCount,

		(
		CASE
		WHEN f.TYPE = 'listType0005' THEN
		CONCAT( f.START_DATE, " 00:00:00" )
		WHEN f.PERIOD = 'checkPeriod0001' THEN
		(select sd.DAY_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0002' THEN
		(select sd.WEEK_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0003' THEN
		(select sd.XUN_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0004' THEN
		(select sd.MONTH_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0005' THEN
		(select sd.QUARTER_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0006' THEN
		(select sd.YEAR_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0007' THEN
		(select sd.HALFYEAR_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		END
		) DATESTART,
		bb.NAME AS TASK_TYPE_NAME,
		(
		CASE
		WHEN f.TYPE = 'listType0005' THEN
		CONCAT( f.END_DATE, " 23:59:59" )
		WHEN f.PERIOD = 'checkPeriod0001' THEN
		(select sd.DAY_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0002' THEN
		(select sd.WEEK_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0003' THEN
		(select sd.XUN_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0004' THEN
		(select sd.MONTH_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0005' THEN
		(select sd.QUARTER_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0006' THEN
		(select sd.YEAR_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0007' THEN
		(select sd.HALFYEAR_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		END
		) DATEEND,
		getCheckedNum(f.LISTMANAGER_ID) checkCount,
		(select count(1) from bus_checkrecord cc where cc.LISTMANAGER_ID = f.LISTMANAGER_ID  and cc.FINISHED ='1' and type ='2') overTimeCount
		from
		<include refid="tableName"></include>
		f
		LEFT JOIN BUS_OFFDUTY a on f.USER_ID = a.USER_ID and a.isdelete = '0' and a.STARTTIME &lt;= date_format(now(),'%Y-%m-%d') and a.ENDTIME &gt;= date_format(now(),'%Y-%m-%d')
		left join sys_dictionaries p on f.PERIOD = p.BIANMA
		left join sys_dictionaries t on f.TYPE = t.BIANMA
		left join sys_dictionaries m on f.SCREENTYPE = m.BIANMA
		left join OA_DEPARTMENT d on d.DEPARTMENT_ID = f.DEPARTMENT_ID
		LEFT JOIN sys_dictionaries bb ON f.TASK_TYPE = bb.DICTIONARIES_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 = #{pd.CORPINFO_ID} and f.ISDELETE != '-99'
		<if test="pd.RISKCHECKLISTTYPE != null and pd.RISKCHECKLISTTYPE != ''"><!-- 状态 -->
			and f.SCREENTYPE = #{pd.RISKCHECKLISTTYPE}
		</if>
		<if test="pd.statusIds != null and pd.statusIds != ''">
			and
			(
			f.LISTMANAGER_ID in
			<foreach item="item" index="index" collection="pd.statusIds"
					 open="(" separator="," close=")">
				'${item}'
			</foreach>
			)
		</if>
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and
			(
			f.NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
			)
		</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
					f.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"'>
								<choose>
									<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
										and
										f.DEPARTMENT_ID in
										<foreach item="item" index="index"
												 collection="pd.DEPT_IDS" open="(" separator="," close=")">
											'${item}'
										</foreach>
									</when>
									<when test="pd.DEPT_ID != null and pd.DEPT_ID != ''"><!-- 关键词检索 -->
										and f.DEPARTMENT_ID = #{pd.DEPT_ID}
									</when>
									<otherwise>
										and
										((f.DEPARTMENT_ID in (
										select
										SUB_DEPARTMENT_ID
										from
										oa_supervision_department osd
										where
										osd.SUP_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
										and osd.ISDELETE = '0'
										and osd.CORPINFO_ID  = #{pd.CORPINFO_ID}
										)) or (
										f.DEPARTMENT_ID in
										<foreach item="item" index="index"
												 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
											'${item}'
										</foreach>
										))
									</otherwise>
								</choose>
							</when>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<when test="pd.DEPT_ID != null and pd.DEPT_ID != ''">
								and
								f.DEPARTMENT_ID = #{pd.DEPT_ID}
							</when>
							<otherwise>

								and
								(f.DEPARTMENT_ID in (
								select
								SUB_DEPARTMENT_ID
								from
								oa_supervision_department osd
								where
								osd.SUP_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
								and osd.ISDELETE = '0'
								and osd.CORPINFO_ID  = #{pd.CORPINFO_ID})
								or f.USER_ID = #{pd.USER_ID})
							</otherwise>
						</choose>
					</when>

					<when test='pd.ISLEADER != null and pd.ISLEADER != "" and pd.ISLEADER == "1"'>
						<choose>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<when test="pd.DEPT_ID != null and pd.DEPT_ID != ''">
								and
								f.DEPARTMENT_ID = #{pd.DEPT_ID}
							</when>
							<otherwise>
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</otherwise>
						</choose>
					</when>
					<when test="pd.DEPT_ID != null and pd.DEPT_ID != ''">
						and
						f.DEPARTMENT_ID = #{pd.DEPT_ID}
					</when>
					<when test="pd.DEPARTMENT_ID != null and pd.DEPARTMENT_ID != ''">
						and f.USER_ID = #{pd.USER_ID}
						and f.DEPARTMENT_ID=#{pd.DEPARTMENT_ID}
					</when>
					<otherwise>
					</otherwise>
				</choose>
			</otherwise>
		</choose>
		<if test="pd.USERNAME != null and pd.USERNAME != ''"><!-- 关键词检索 -->
			and u.NAME LIKE CONCAT(CONCAT('%', #{pd.USERNAME}),'%')
		</if>

		<if test="pd.ISDELETE != null and pd.ISDELETE != ''"><!-- 状态 -->
			and f.ISDELETE = #{pd.ISDELETE}
		</if>

		<if test="pd.STATUS != null and pd.STATUS != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.STATUS=="1"'>
					AND getCheckedNum(f.LISTMANAGER_ID) &gt; 0
				</when>
				<when test='pd.STATUS=="0"'>
					AND getCheckedNum(f.LISTMANAGER_ID) = 0
				</when>
				<otherwise>
				</otherwise>
			</choose>
		</if>
		<if test="pd.OVERTIME != null and pd.OVERTIME != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.OVERTIME=="1"'>
					AND (select count(1) from bus_checkrecord cc where cc.LISTMANAGER_ID = f.LISTMANAGER_ID  and cc.FINISHED ='1' and type ='2') &gt; 0
				</when>
				<when test='pd.OVERTIME=="0"'>
					AND (select count(1) from bus_checkrecord cc where cc.LISTMANAGER_ID = f.LISTMANAGER_ID  and cc.FINISHED ='1' and type ='2') = 0
				</when>
				<otherwise>
				</otherwise>
			</choose>
		</if>
		<if test="pd.PERIOD != null and pd.PERIOD != ''"><!-- 关键词检索 -->
			and f.PERIOD = #{pd.PERIOD}
		</if>
		<if test="pd.TYPE != null and pd.TYPE != ''"><!-- 关键词检索 -->
			and f.TYPE = #{pd.TYPE}
		</if>
		<if test='pd.WORKSTATUS == "0"'>
			and (
			(a.STARTTIME is null or a.ENDTIME is null)
			or (to_days(a.STARTTIME) &lt; to_days(NOW()) and to_days(a.ENDTIME) &gt; to_days(NOW()))
			AND u.WORKSTATUS != '2'
			)
		</if>
		<if test='pd.WORKSTATUS == "1"'>
			and !(
			(a.STARTTIME is null or a.ENDTIME is null)
			or (to_days(a.STARTTIME) &lt; to_days(NOW()) and to_days(a.ENDTIME) &gt; to_days(NOW()))
			or u.WORKSTATUS = '2'
			)
		</if>
		<if test="pd.LISTINGLEVEL != null and pd.LISTINGLEVEL != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.LISTINGLEVEL == "1"'>
					and d.LEVEL = ''
				</when>
				<otherwise>
					and d.LEVEL = #{pd.LISTINGLEVEL}
				</otherwise>
			</choose>
		</if>
		<if test="(pd.STARTTIME != null and pd.STARTTIME != '') or (pd.ENDTIME != null and pd.ENDTIME != '')"><!-- 关键词检索 -->
			<choose>
				<when
						test="pd.STARTTIME != null and pd.STARTTIME != '' and pd.ENDTIME != null and pd.ENDTIME != ''">
					and f.LISTMANAGER_ID in
					(
					SELECT LISTMANAGER_ID
					FROM BUS_CHECKRECORD
					WHERE FINISHED = '1'
					AND ISDELETE = 0
					and DATE_FORMAT(CHECK_TIME,'%Y-%m-%d %H:%i:%s') &gt;= #{pd.STARTTIME}
					and DATE_FORMAT(CHECK_TIME,'%Y-%m-%d %H:%i:%s') &lt;= #{pd.ENDTIME}
					)
				</when>
				<when test="pd.STARTTIME != null and pd.STARTTIME != ''">
					and f.LISTMANAGER_ID in
					(
					SELECT LISTMANAGER_ID
					FROM BUS_CHECKRECORD
					WHERE FINISHED = '1'
					AND ISDELETE = 0
					and DATE_FORMAT(CHECK_TIME,'%Y-%m-%d %H:%i:%s') &gt;= #{pd.STARTTIME}
					)
				</when>
				<when test="pd.ENDTIME != null and pd.ENDTIME != ''">
					and f.LISTMANAGER_ID in
					(
					SELECT LISTMANAGER_ID
					FROM BUS_CHECKRECORD
					WHERE FINISHED = '1'
					AND ISDELETE = 0
					and DATE_FORMAT(CHECK_TIME,'%Y-%m-%d %H:%i:%s') &lt;= #{pd.ENDTIME}
					)
				</when>
			</choose>

		</if>
		) f
		where 1= 1
		<if test="pd.HASHIDDEN != null and pd.HASHIDDEN != ''"><!-- 关键词检索 -->
			<choose>
				<when test="pd.HASHIDDEN == 0">
					and f.hiddenCount = 0
				</when>
				<when test="pd.HASHIDDEN == 1">
					and f.hiddenCount > 0
				</when>
			</choose>
		</if>
		group by f.LISTMANAGER_ID
		order by field(f.ISDELETE,'0','1','2','-1')	,f.OPERATTIME desc
	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		,
		p.NAME PERIODNAME,
		t.NAME TYPENAME,
		d.NAME as DEPARTMENT_NAME,
		d.LEVEL as DEPARTMENT_LEVEL,
		sp.NAME
		AS POST_NAME,
		u.NAME USER_NAME,
		(select count(1) from BUS_LIST_CHECKITEM
		ch where ch.LISTMANAGER_ID=f.LISTMANAGER_ID and ch.ISDELETE =0) as
		count,
		getCheckedNum(f.LISTMANAGER_ID) checkCount,
		f.BAO_BAO_TYPE
		from
		<include refid="tableName"></include>
		f
		left join sys_dictionaries p on f.PERIOD = p.BIANMA
		left join sys_dictionaries t on f.TYPE = t.BIANMA
		left join OA_DEPARTMENT d on d.DEPARTMENT_ID=f.DEPARTMENT_ID
		left join
		sys_user u on u.USER_ID = f.USER_ID
		left join SYS_POST sp on
		sp.POST_ID=f.POST_ID
		where  (f.TYPE != 'listType0005'
		or (f.START_DATE &lt;= DATE_FORMAT(NOW(),'%Y-%m-%d') and f.END_DATE
		&gt;= DATE_FORMAT(NOW(),'%Y-%m-%d') ))

		<!-- <if test="POST_ID != null and POST_ID != ''">关键词检索 -->
		<!-- and -->
		<!-- ( -->
		<!-- f.POST_ID = #{POST_ID} -->
		<!-- ) -->
		<!-- </if> -->
		<if test="CORPINFO_ID != null and CORPINFO_ID != ''">
			and
			f.CORPINFO_ID = #{CORPINFO_ID}
		</if>
		<!--		<if test="USER_ID != null and USER_ID != ''">&lt;!&ndash; 部门查询条件 &ndash;&gt;-->
		<!--			and f.USER_ID = #{USER_ID}-->
		<!--		</if>-->
		<choose>
			<when test='ISSUPERVISE != null and ISSUPERVISE != "" and ISSUPERVISE == "1"'>
				<choose>
					<when test='ISLEADER != null and ISLEADER != "" and ISLEADER == "1"'>
						and
						((f.DEPARTMENT_ID in (
						select
						SUB_DEPARTMENT_ID
						from
						oa_supervision_department osd
						where
						osd.SUP_DEPARTMENT_ID = #{SUP_DEPARTMENT_ID}
						and osd.ISDELETE = '0'
						and osd.CORPINFO_ID  = #{CORPINFO_ID}
						)) or (
						f.DEPARTMENT_ID in
						<foreach item="item" index="index"
								 collection="DEPARTMENT_IDS" open="(" separator="," close=")">
							'${item}'
						</foreach>
						))
					</when>
					<otherwise>
						and
						(f.DEPARTMENT_ID in (
						select
						SUB_DEPARTMENT_ID
						from
						oa_supervision_department osd
						where
						osd.SUP_DEPARTMENT_ID = #{SUP_DEPARTMENT_ID}
						and osd.ISDELETE = '0'
						and osd.CORPINFO_ID  = #{CORPINFO_ID}
						) or f.USER_ID = #{USER_ID})
					</otherwise>
				</choose>
			</when>

			<when test='ISLEADER != null and ISLEADER != "" and ISLEADER == "1"'>
				and
				f.DEPARTMENT_ID in
				<foreach item="item" index="index"
						 collection="DEPARTMENT_IDS" open="(" separator="," close=")">
					'${item}'
				</foreach>
			</when>
			<when test="DEPARTMENT_ID != null and DEPARTMENT_ID != ''">
				and
				f.DEPARTMENT_ID = #{DEPARTMENT_ID}
				and f.USER_ID = #{USER_ID}
			</when>
			<otherwise>
			</otherwise>
		</choose>
		<if test="SUB_DEPARTMENT_IDS != null and SUB_DEPARTMENT_IDS != ''">
			and f.DEPARTMENT_ID = #{SUB_DEPARTMENT_IDS}
		</if>
		<if test="USERNAME != null and USERNAME != ''">
			and u.NAME LIKE CONCAT(CONCAT('%', #{USERNAME}),'%')
		</if>
		<if test="KEYWORDS != null and KEYWORDS != ''">
			and f.NAME LIKE CONCAT(CONCAT('%', #{KEYWORDS}),'%')
		</if>
		<if test="STATUS != null and STATUS != ''"><!-- 关键词检索 -->
			<choose>
				<when test='STATUS=="1"'>
					AND getCheckedNum(f.LISTMANAGER_ID) &gt; 0
				</when>
				<when test='STATUS=="0"'>
					AND getCheckedNum(f.LISTMANAGER_ID) = 0
				</when>
				<otherwise>
				</otherwise>
			</choose>
		</if>
		<if test="LISTINGLEVEL != null and LISTINGLEVEL != ''"><!-- 关键词检索 -->
			<choose>
				<when test='LISTINGLEVEL == "1"'>
					and d.LEVEL = ''
				</when>
				<otherwise>
					and d.LEVEL = #{LISTINGLEVEL}
				</otherwise>
			</choose>
		</if>
		AND f.ISDELETE = '0'
		order by f.USER_ID= #{orderUserId} desc ,f.CREATTIME desc ,f.DEPARTMENT_ID asc
	</select>

	<!-- 列表(全部) -->
	<select id="listAllForApp" parameterType="pd" resultType="pd">
		( SELECT
		f.LISTMANAGER_ID,
		f.NAME,
		f.DEPARTMENT_ID,
		f.USER_ID,
		f.OPERATTIME,
		p.NAME PERIODNAME,
		t.NAME TYPENAME,
		d.NAME AS DEPARTMENT_NAME,
		getFullName ( d.DEPARTMENT_ID ) AS DEPARTMENT_NAME_ALL,
		sp.NAME AS POST_NAME,
		u.NAME USER_NAME,
		f.TYPE,
		( SELECT count( 1 ) FROM BUS_LIST_CHECKITEM ch WHERE ch.LISTMANAGER_ID = f.LISTMANAGER_ID AND ch.ISDELETE = 0 ) AS count,
		getCheckedNum ( f.LISTMANAGER_ID ) checkCount,
		"1" AS list_type
		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 OA_DEPARTMENT d ON d.DEPARTMENT_ID = f.DEPARTMENT_ID
		LEFT JOIN sys_user u ON u.USER_ID = f.USER_ID
		LEFT JOIN SYS_POST sp ON sp.POST_ID = f.POST_ID
		WHERE
		f.ISDELETE = '0'
		AND (
		f.TYPE != 'listType0005'
		OR ( f.START_DATE &lt;= DATE_FORMAT( NOW(), '%Y-%m-%d' ) AND f.END_DATE &gt;= DATE_FORMAT( NOW(), '%Y-%m-%d' ) ))
		<if test="CORPINFO_ID != null and CORPINFO_ID != ''">
			AND f.CORPINFO_ID = #{CORPINFO_ID}
		</if>
		<if test="DEPARTMENT_ID != null and DEPARTMENT_ID != ''">
			AND f.DEPARTMENT_ID = #{DEPARTMENT_ID}
		</if>
		<if test="USER_ID != null and USER_ID != ''">
			AND f.USER_ID = #{USER_ID}
		</if>
		ORDER BY
		f.USER_ID = #{USER_ID} DESC,
		f.DEPARTMENT_ID ASC,
		f.OPERATTIME DESC
		) UNION
		(
		SELECT
		f.CUSTOM_ID,
		f.NAME,
		f.DEPARTMENT_ID,
		f.USER_ID,
		f.OPERATTIME,
		p.NAME PERIODNAME,
		t.NAME TYPENAME,
		d.NAME AS DEPARTMENT_NAME,
		getFullName ( d.DEPARTMENT_ID ) AS DEPARTMENT_NAME_ALL,
		sp.NAME AS POST_NAME,
		u.NAME USER_NAME,
		f.TYPE,
		( SELECT count( 1 ) FROM bus_hiddendangercheckstandard_custom_item ch WHERE ch.CUSTOM_ID = f.CUSTOM_ID AND ch.ISDELETE = 0 ) AS count,
		getStandardCheckedNum ( f.CUSTOM_ID ) checkCount,
		"2" AS list_type
		FROM bus_hiddendangercheckstandard_custom f
		LEFT JOIN sys_dictionaries p ON f.PERIOD = p.BIANMA
		LEFT JOIN sys_dictionaries t ON f.TYPE = t.BIANMA
		LEFT JOIN OA_DEPARTMENT d ON d.DEPARTMENT_ID = f.DEPARTMENT_ID
		LEFT JOIN sys_user u ON u.USER_ID = f.USER_ID
		LEFT JOIN SYS_POST sp ON sp.POST_ID = f.POST_ID
		WHERE
		f.ISDELETE = '0'
		AND (
		f.TYPE != 'listType0005'
		OR ( f.START_DATE &lt;= DATE_FORMAT( NOW(), '%Y-%m-%d' ) AND f.END_DATE &gt;= DATE_FORMAT( NOW(), '%Y-%m-%d' ) ))
		<if test="CORPINFO_ID != null and CORPINFO_ID != ''">
			AND f.CORPINFO_ID = #{CORPINFO_ID}
		</if>
		<if test="DEPARTMENT_ID != null and DEPARTMENT_ID != ''">
			AND f.DEPARTMENT_ID = #{DEPARTMENT_ID}
		</if>
		<if test="USER_ID != null and USER_ID != ''">
			AND f.USER_ID = #{USER_ID}
		</if>
		ORDER BY
		f.USER_ID = #{USER_ID} DESC,
		f.DEPARTMENT_ID ASC,
		f.OPERATTIME DESC
		)
	</select>

	<!-- 列表(全部) -->
	<select id="appListAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		,
		p.NAME PERIODNAME,
		t.NAME TYPENAME,
		d.NAME as DEPARTMENT_NAME,
		d.LEVEL as DEPARTMENT_LEVEL,
		sp.NAME
		AS POST_NAME,
		u.NAME USER_NAME,
		(select count(1) from BUS_LIST_CHECKITEM
		ch where ch.LISTMANAGER_ID=f.LISTMANAGER_ID and ch.ISDELETE =0) as
		count,
		getCheckedNum(f.LISTMANAGER_ID) checkCount
		from
		<include refid="tableName"></include>
		f
		left join sys_dictionaries p on f.PERIOD = p.BIANMA
		left join sys_dictionaries t on f.TYPE = t.BIANMA
		left join OA_DEPARTMENT d on d.DEPARTMENT_ID=f.DEPARTMENT_ID
		left join
		sys_user u on u.USER_ID = f.USER_ID
		left join SYS_POST sp on
		sp.POST_ID=f.POST_ID
		where f.ISDELETE = '0' and (f.TYPE != 'listType0005'
		or (f.START_DATE &lt;= DATE_FORMAT(NOW(),'%Y-%m-%d') and f.END_DATE
		&gt;= DATE_FORMAT(NOW(),'%Y-%m-%d') ))
		<!-- <if test="POST_ID != null and POST_ID != ''">关键词检索 -->
		<!-- and -->
		<!-- ( -->
		<!-- f.POST_ID = #{POST_ID} -->
		<!-- ) -->
		<!-- </if> -->
		<if test="CORPINFO_ID != null and CORPINFO_ID != ''">
			and
			f.CORPINFO_ID = #{CORPINFO_ID}
		</if>
		<choose>
			<when test='ISMAIN != null and ISMAIN != "" and ISMAIN == "1"'>
				<if test="DEPT_IDS != null and DEPT_IDS != ''">
					and
					f.DEPARTMENT_ID in
					<foreach item="item" index="index"
							 collection="DEPT_IDS" open="(" separator="," close=")">
						'${item}'
					</foreach>
				</if>
			</when>
			<otherwise>
				<choose>
					<when test='ISSUPERVISE != null and ISSUPERVISE != "" and ISSUPERVISE == "1"'>
						<choose>
							<when test="DEPT_IDS != null and DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<otherwise>
								and
								f.DEPARTMENT_ID in (
								select
								SUB_DEPARTMENT_ID
								from
								oa_supervision_department osd
								where
								osd.SUP_DEPARTMENT_ID = #{DEPARTMENT_ID}
								and osd.ISDELETE = '0'
								and osd.CORPINFO_ID  = #{CORPINFO_ID}
								)
							</otherwise>
						</choose>
					</when>
					<when test="DEPARTMENT_ID != null and DEPARTMENT_ID != ''">
						and f.DEPARTMENT_ID=#{DEPARTMENT_ID}
					</when>
					<otherwise>
					</otherwise>
				</choose>
			</otherwise>
		</choose>
		<if test="USERNAME != null and USERNAME != ''">
			and u.NAME LIKE CONCAT(CONCAT('%', #{USERNAME}),'%')
		</if>
		<if test="KEYWORDS != null and KEYWORDS != ''">
			and f.NAME LIKE CONCAT(CONCAT('%', #{KEYWORDS}),'%')
		</if>
		<if test="STATUS != null and STATUS != ''"><!-- 关键词检索 -->
			<choose>
				<when test='STATUS=="1"'>
					AND getCheckedNum(f.LISTMANAGER_ID) &gt; 0
				</when>
				<when test='STATUS=="0"'>
					AND getCheckedNum(f.LISTMANAGER_ID) = 0
				</when>
				<otherwise>
				</otherwise>
			</choose>
		</if>
		<if test="LISTINGLEVEL != null and LISTINGLEVEL != ''"><!-- 关键词检索 -->
			<choose>
				<when test='LISTINGLEVEL == "1"'>
					and d.LEVEL = ''
				</when>
				<otherwise>
					and d.LEVEL = #{LISTINGLEVEL}
				</otherwise>
			</choose>
		</if>
		order by f.USER_ID= #{orderUserId} desc ,f.DEPARTMENT_ID asc
	</select>

	<!-- 清单检查分页 -->
	<select id="checklistPage" parameterType="page" resultType="pd">
		select
		<include refid="Field"></include>
		,
		p.NAME PERIODNAME,
		t.NAME TYPENAME,
		d.NAME as DEPARTMENT_NAME,
		getFullName(d.DEPARTMENT_ID) as DEPARTMENT_NAME_ALL,
		sp.NAME
		AS POST_NAME,
		u.NAME USER_NAME,
		(select count(1) from BUS_LIST_CHECKITEM
		ch where ch.LISTMANAGER_ID=f.LISTMANAGER_ID and ch.ISDELETE =0) as	count,
		getCheckedNum(f.LISTMANAGER_ID) checkCount
		from
		<include refid="tableName"></include>
		f
		left join sys_dictionaries p on f.PERIOD = p.BIANMA
		left join sys_dictionaries t on f.TYPE = t.BIANMA
		left join OA_DEPARTMENT d on d.DEPARTMENT_ID=f.DEPARTMENT_ID
		left join
		sys_user u on u.USER_ID = f.USER_ID
		left join SYS_POST sp on
		sp.POST_ID=f.POST_ID
		where f.ISDELETE = '0' and (f.TYPE != 'listType0005'
		or (f.START_DATE &lt;= DATE_FORMAT(NOW(),'%Y-%m-%d') and f.END_DATE
		&gt;= DATE_FORMAT(NOW(),'%Y-%m-%d') ))
		<!-- <if test="POST_ID != null and POST_ID != ''">关键词检索 -->
		<!-- and -->
		<!-- ( -->
		<!-- f.POST_ID = #{POST_ID} -->
		<!-- ) -->
		<!-- </if> -->
		<if test="pd.CORPINFO_ID != null and pd.CORPINFO_ID != ''">
			and
			f.CORPINFO_ID = #{pd.CORPINFO_ID}
		</if>
		<!-- 		<if test="pd.DEPARTMENT_IDS != null and pd.DEPARTMENT_IDS != ''">关键词检索
                    and
                    (
                    f.DEPARTMENT_ID in
                    <foreach item="item" index="index"
                        collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
                        #{pd.DEPARTMENT_IDS[${index}]}
                    </foreach>
                    or f.USER_ID = #{pd.USER_ID}
                    )
                </if>
                <if test="pd.DEPARTMENT_ID != null and pd.DEPARTMENT_ID != ''">
                    and
                    f.DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
                    and f.USER_ID = #{pd.USER_ID}
                </if>
                <if test="pd.DTID != null and pd.DTID != ''">部门查询条件
                    and f.DEPARTMENT_ID = #{pd.DTID}
                </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
					f.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"'>
								<choose>
									<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
										and
										f.DEPARTMENT_ID in
										<foreach item="item" index="index"
												 collection="pd.DEPT_IDS" open="(" separator="," close=")">
											'${item}'
										</foreach>
									</when>
									<otherwise>
										and
										((f.DEPARTMENT_ID in (
										select
										SUB_DEPARTMENT_ID
										from
										oa_supervision_department osd
										where
										osd.SUP_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
										and osd.ISDELETE = '0'
										and osd.CORPINFO_ID  = #{pd.CORPINFO_ID}
										)) or (
										f.DEPARTMENT_ID in
										<foreach item="item" index="index"
												 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
											'${item}'
										</foreach>
										))
									</otherwise>
								</choose>
							</when>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<otherwise>

								and
								(f.DEPARTMENT_ID in (
								select
								SUB_DEPARTMENT_ID
								from
								oa_supervision_department osd
								where
								osd.SUP_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
								and osd.ISDELETE = '0'
								and osd.CORPINFO_ID  = #{pd.CORPINFO_ID})
								or f.USER_ID = #{pd.USER_ID})
							</otherwise>
						</choose>
					</when>

					<when test='pd.ISLEADER != null and pd.ISLEADER != "" and pd.ISLEADER == "1"'>
						<choose>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<otherwise>
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</otherwise>
						</choose>
					</when>
					<when test="pd.DEPARTMENT_ID != null and pd.DEPARTMENT_ID != ''">
						and f.USER_ID = #{pd.USER_ID}
						and f.DEPARTMENT_ID=#{pd.DEPARTMENT_ID}
					</when>
					<otherwise>
					</otherwise>
				</choose>
			</otherwise>
		</choose>
		<if test="pd.USERNAME != null and pd.USERNAME != ''">
			and u.NAME LIKE CONCAT(CONCAT('%', #{pd.USERNAME}),'%')
		</if>
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''">
			and f.NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
		</if>
		<if test="pd.PERIOD != null and pd.PERIOD != ''">
			and f.PERIOD = #{pd.PERIOD}
		</if>
		<if test="pd.STATUS != null and pd.STATUS != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.STATUS=="1"'>
					AND getCheckedNum(f.LISTMANAGER_ID) &gt; 0
				</when>
				<when test='pd.STATUS=="0"'>
					AND getCheckedNum(f.LISTMANAGER_ID) = 0
				</when>
				<otherwise>
				</otherwise>
			</choose>
		</if>
		<if test="pd.LISTINGLEVEL != null and pd.LISTINGLEVEL != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.LISTINGLEVEL == "1"'>
					and d.LEVEL = ''
				</when>
				<otherwise>
					and d.LEVEL = #{pd.LISTINGLEVEL}
				</otherwise>
			</choose>
		</if>
		order by f.USER_ID= #{pd.orderUserId} desc ,f.DEPARTMENT_ID asc,f.OPERATTIME desc
	</select>

	<!-- 风险管控和检查标准清单检查分页 -->
	<select id="riskStandardChecklistPage" parameterType="page" resultType="pd">
	  (	select
		f.LISTMANAGER_ID,
		f.NAME,
		f.DEPARTMENT_ID,
		f.USER_ID,
		f.OPERATTIME,
		p.NAME PERIODNAME,
		t.NAME TYPENAME,
		d.NAME as DEPARTMENT_NAME,
		getFullName(d.DEPARTMENT_ID) as DEPARTMENT_NAME_ALL,
		sp.NAME
		AS POST_NAME,
		u.NAME USER_NAME,
		(select count(1) from BUS_LIST_CHECKITEM
		ch where ch.LISTMANAGER_ID=f.LISTMANAGER_ID and ch.ISDELETE =0) as	count,
		getCheckedNum(f.LISTMANAGER_ID) checkCount,
		"1" as list_type
		from
		<include refid="tableName"></include>
		f
		left join sys_dictionaries p on f.PERIOD = p.BIANMA
		left join sys_dictionaries t on f.TYPE = t.BIANMA
		left join OA_DEPARTMENT d on d.DEPARTMENT_ID=f.DEPARTMENT_ID
		left join
		sys_user u on u.USER_ID = f.USER_ID
		left join SYS_POST sp on
		sp.POST_ID=f.POST_ID
		where f.ISDELETE = '0' and (f.TYPE != 'listType0005'
		or (f.START_DATE &lt;= DATE_FORMAT(NOW(),'%Y-%m-%d') and f.END_DATE
		&gt;= DATE_FORMAT(NOW(),'%Y-%m-%d') ))
		<if test="pd.CORPINFO_ID != null and pd.CORPINFO_ID != ''">
			and
			f.CORPINFO_ID = #{pd.CORPINFO_ID}
		</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
					f.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"'>
								<choose>
									<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
										and
										f.DEPARTMENT_ID in
										<foreach item="item" index="index"
												 collection="pd.DEPT_IDS" open="(" separator="," close=")">
											'${item}'
										</foreach>
									</when>
									<otherwise>
										and
										((f.DEPARTMENT_ID in (
										select
										SUB_DEPARTMENT_ID
										from
										oa_supervision_department osd
										where
										osd.SUP_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
										and osd.ISDELETE = '0'
										and osd.CORPINFO_ID  = #{pd.CORPINFO_ID}
										)) or (
										f.DEPARTMENT_ID in
										<foreach item="item" index="index"
												 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
											'${item}'
										</foreach>
										))
									</otherwise>
								</choose>
							</when>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<otherwise>

								and
								(f.DEPARTMENT_ID in (
								select
								SUB_DEPARTMENT_ID
								from
								oa_supervision_department osd
								where
								osd.SUP_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
								and osd.ISDELETE = '0'
								and osd.CORPINFO_ID  = #{pd.CORPINFO_ID})
								or f.USER_ID = #{pd.USER_ID})
							</otherwise>
						</choose>
					</when>

					<when test='pd.ISLEADER != null and pd.ISLEADER != "" and pd.ISLEADER == "1"'>
						<choose>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<otherwise>
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</otherwise>
						</choose>
					</when>
					<when test="pd.DEPARTMENT_ID != null and pd.DEPARTMENT_ID != ''">
						and f.USER_ID = #{pd.USER_ID}
						and f.DEPARTMENT_ID=#{pd.DEPARTMENT_ID}
					</when>
					<otherwise>
					</otherwise>
				</choose>
			</otherwise>
		</choose>
		<if test="pd.USERNAME != null and pd.USERNAME != ''">
			and u.NAME LIKE CONCAT(CONCAT('%', #{pd.USERNAME}),'%')
		</if>
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''">
			and f.NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
		</if>
		<if test="pd.PERIOD != null and pd.PERIOD != ''">
			and f.PERIOD = #{pd.PERIOD}
		</if>
		<if test="pd.STATUS != null and pd.STATUS != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.STATUS=="1"'>
					AND getCheckedNum(f.LISTMANAGER_ID) &gt; 0
				</when>
				<when test='pd.STATUS=="0"'>
					AND getCheckedNum(f.LISTMANAGER_ID) = 0
				</when>
				<otherwise>
				</otherwise>
			</choose>
		</if>
		<if test="pd.LISTINGLEVEL != null and pd.LISTINGLEVEL != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.LISTINGLEVEL == "1"'>
					and d.LEVEL = ''
				</when>
				<otherwise>
					and d.LEVEL = #{pd.LISTINGLEVEL}
				</otherwise>
			</choose>
		</if>
		<if test="pd.LIST_TYPE != null and pd.LIST_TYPE != ''">
			and "1" = #{pd.LIST_TYPE}
		</if>
		order by f.USER_ID= #{pd.orderUserId} desc ,f.DEPARTMENT_ID asc,f.OPERATTIME desc )
	  union
		(select
		f.CUSTOM_ID,
		f.NAME,
		f.DEPARTMENT_ID,
		f.USER_ID,
		f.OPERATTIME,
		p.NAME PERIODNAME,
		t.NAME TYPENAME,
		d.NAME as DEPARTMENT_NAME,
		getFullName(d.DEPARTMENT_ID) as DEPARTMENT_NAME_ALL,
		sp.NAME
		AS POST_NAME,
		u.NAME USER_NAME,
		(select count(1) from bus_hiddendangercheckstandard_custom_item
		ch where ch.CUSTOM_ID = f.CUSTOM_ID and ch.ISDELETE =0) as	count,
		getStandardCheckedNum(f.CUSTOM_ID) checkCount,
		 "2" as list_type
		from
		bus_hiddendangercheckstandard_custom
		f
		left join sys_dictionaries p on f.PERIOD = p.BIANMA
		left join sys_dictionaries t on f.TYPE = t.BIANMA
		left join OA_DEPARTMENT d on d.DEPARTMENT_ID=f.DEPARTMENT_ID
		left join
		sys_user u on u.USER_ID = f.USER_ID
		left join SYS_POST sp on
		sp.POST_ID=f.POST_ID
		where f.ISDELETE = '0' and (f.TYPE != 'listType0005'
		or (f.START_DATE &lt;= DATE_FORMAT(NOW(),'%Y-%m-%d') and f.END_DATE
		&gt;= DATE_FORMAT(NOW(),'%Y-%m-%d') ))
		<if test="pd.CORPINFO_ID != null and pd.CORPINFO_ID != ''">
			and
			f.CORPINFO_ID = #{pd.CORPINFO_ID}
		</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
					f.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"'>
								<choose>
									<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
										and
										f.DEPARTMENT_ID in
										<foreach item="item" index="index"
												 collection="pd.DEPT_IDS" open="(" separator="," close=")">
											'${item}'
										</foreach>
									</when>
									<otherwise>
										and
										((f.DEPARTMENT_ID in (
										select
										SUB_DEPARTMENT_ID
										from
										oa_supervision_department osd
										where
										osd.SUP_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
										and osd.ISDELETE = '0'
										and osd.CORPINFO_ID  = #{pd.CORPINFO_ID}
										)) or (
										f.DEPARTMENT_ID in
										<foreach item="item" index="index"
												 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
											'${item}'
										</foreach>
										))
									</otherwise>
								</choose>
							</when>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<otherwise>

								and
								(f.DEPARTMENT_ID in (
								select
								SUB_DEPARTMENT_ID
								from
								oa_supervision_department osd
								where
								osd.SUP_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
								and osd.ISDELETE = '0'
								and osd.CORPINFO_ID  = #{pd.CORPINFO_ID})
								or f.USER_ID = #{pd.USER_ID})
							</otherwise>
						</choose>
					</when>

					<when test='pd.ISLEADER != null and pd.ISLEADER != "" and pd.ISLEADER == "1"'>
						<choose>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<otherwise>
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</otherwise>
						</choose>
					</when>
					<when test="pd.DEPARTMENT_ID != null and pd.DEPARTMENT_ID != ''">
						and f.USER_ID = #{pd.USER_ID}
						and f.DEPARTMENT_ID=#{pd.DEPARTMENT_ID}
					</when>
					<otherwise>
					</otherwise>
				</choose>
			</otherwise>
		</choose>
		<if test="pd.USERNAME != null and pd.USERNAME != ''">
			and u.NAME LIKE CONCAT(CONCAT('%', #{pd.USERNAME}),'%')
		</if>
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''">
			and f.NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
		</if>
		<if test="pd.PERIOD != null and pd.PERIOD != ''">
			and f.PERIOD = #{pd.PERIOD}
		</if>
		<if test="pd.STATUS != null and pd.STATUS != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.STATUS=="1"'>
					AND getStandardCheckedNum(f.CUSTOM_ID) &gt; 0
				</when>
				<when test='pd.STATUS=="0"'>
					AND getStandardCheckedNum(f.CUSTOM_ID) = 0
				</when>
				<otherwise>
				</otherwise>
			</choose>
		</if>
		<if test="pd.LISTINGLEVEL != null and pd.LISTINGLEVEL != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.LISTINGLEVEL == "1"'>
					and d.LEVEL = ''
				</when>
				<otherwise>
					and d.LEVEL = #{pd.LISTINGLEVEL}
				</otherwise>
			</choose>
		</if>
		<if test="pd.LIST_TYPE != null and pd.LIST_TYPE != ''">
			and "2" = #{pd.LIST_TYPE}
		</if>
		order by f.USER_ID= #{pd.orderUserId} desc ,f.DEPARTMENT_ID asc,f.OPERATTIME desc )
	</select>

	<!-- 列表(全部) -->
	<select id="listRecordAll" parameterType="pd" resultType="pd">
		select * from (
		select
		f.TYPE,
		f.START_DATE,
		f.END_DATE,
		f.CREATTIME,
		f.LISTMANAGER_ID,
		p.NAME PERIODNAME,
		f.OPERATTIME,
		(
		select
		count(1)
		from BUS_CHECKRECORD ch
		left join bus_hidden h on h.CHECKRECORD_ID = ch.CHECKRECORD_ID
		where ch.LISTMANAGER_ID=f.LISTMANAGER_ID
		and ch.FINISHED='1'
		and ch.ISDELETE =0
		and h.ISDELETE =0
		and h.HIDDEN_ID is not null
		) as hiddenCount
		from
		<include refid="tableName"></include>
		f
		left join sys_dictionaries p on f.PERIOD = p.BIANMA
		left join sys_dictionaries t on f.TYPE = t.BIANMA
		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 = #{pd.CORPINFO_ID}
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and
			(
			f.NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
			)
		</if>
		<if test="pd.DEPARTMENT_IDS != null and pd.DEPARTMENT_IDS != ''"><!-- 关键词检索 -->
			and
			(
			f.DEPARTMENT_ID in
			<foreach item="item" index="index"
					 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
				'${item}'
			</foreach>
			or f.USER_ID = #{pd.USER_ID}
			)
		</if>
		<if test="pd.USERNAME != null and pd.USERNAME != ''"><!-- 关键词检索 -->
			and u.NAME LIKE CONCAT(CONCAT('%', #{pd.USERNAME}),'%')
		</if>
		<if test="pd.DEPARTMENT_ID != null and pd.DEPARTMENT_ID != ''"><!-- 关键词检索 -->
			and f.DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
		</if>
		<if test="pd.PERIOD != null and pd.PERIOD != ''"><!-- 关键词检索 -->
			and f.PERIOD = #{pd.PERIOD}
		</if>
		<if test="pd.TYPE != null and pd.TYPE != ''"><!-- 关键词检索 -->
			and f.TYPE = #{pd.TYPE}
		</if>
		<if test="pd.LISTINGLEVEL != null and pd.LISTINGLEVEL != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.LISTINGLEVEL == "1"'>
					and d.LEVEL = ''
				</when>
				<otherwise>
					and d.LEVEL = #{pd.LISTINGLEVEL}
				</otherwise>
			</choose>
		</if>
		<if
				test="(pd.STARTTIME != null and pd.STARTTIME != '') or (pd.ENDTIME != null and pd.ENDTIME != '')"><!-- 关键词检索 -->
			<choose>
				<when
						test="pd.STARTTIME != null and pd.STARTTIME != '' and pd.ENDTIME != null and pd.ENDTIME != ''">
					and f.LISTMANAGER_ID in
					(
					SELECT LISTMANAGER_ID
					FROM BUS_CHECKRECORD
					WHERE FINISHED = '1'
					AND ISDELETE = 0
					and CHECK_TIME &gt;= #{pd.STARTTIME}
					and CHECK_TIME &lt;= #{pd.ENDTIME}
					)
				</when>
				<when test="pd.STARTTIME != null and pd.STARTTIME != ''">
					and f.LISTMANAGER_ID in
					(
					SELECT LISTMANAGER_ID
					FROM BUS_CHECKRECORD
					WHERE FINISHED = '1'
					AND ISDELETE = 0
					and CHECK_TIME &gt;= #{pd.STARTTIME}
					)
				</when>
				<when test="pd.ENDTIME != null and pd.ENDTIME != ''">
					and f.LISTMANAGER_ID in
					(
					SELECT LISTMANAGER_ID
					FROM BUS_CHECKRECORD
					WHERE FINISHED = '1'
					AND ISDELETE = 0
					and CHECK_TIME &lt;= #{pd.ENDTIME}
					)
				</when>
			</choose>
		</if>
		) f
		where 1= 1
		<if test="pd.HASHIDDEN != null and pd.HASHIDDEN != ''"><!-- 关键词检索 -->
			<choose>
				<when test="pd.HASHIDDEN == 0">
					and f.hiddenCount = 0
				</when>
				<when test="pd.HASHIDDEN == 1">
					and f.hiddenCount > 0
				</when>
			</choose>
		</if>
		order by f.OPERATTIME desc
	</select>

	<!-- 列表(不包含节假日) -->
	<select id="listExaminedNum" parameterType="pd" resultType="pd">
		SELECT
			COUNT( 1 ) NOTEXAMINEDNUM,
			l.PERIOD,
			l.TYPE,
			l.CORPINFO_ID,
			l.USER_ID
		FROM
			BUS_LISTMANAGER l
			LEFT JOIN SYS_USER u on u.USER_ID = l.USER_ID
		WHERE
			l.ISDELETE = 0
			AND l.TYPE != 'listType0005'
			AND (
					u.WORKSTATUS = '1'
					or u.WORKSTATUS IS NULL
					or u.WORKSTATUS = ''
				)
		GROUP BY
			l.PERIOD,
			l.TYPE,
			l.CORPINFO_ID,
			l.USER_ID
	</select>

	<select id="listExaminedNumJjr" parameterType="pd"
			resultType="pd">
		SELECT
		count(1)*2 NOTEXAMINEDNUM,TYPE,CORPINFO_ID,START_DATE,END_DATE,USER_ID
		FROM
		BUS_LISTMANAGER
		where
		ISDELETE = 0
		and TYPE = 'listType0005'
		and START_DATE is not null
		and END_DATE is
		not null
		AND START_DATE != ''
		AND END_DATE != ''
		GROUP BY TYPE,CORPINFO_ID,START_DATE,END_DATE,USER_ID
	</select>
	<!--清单全部风险 -->
	<select id="listAllRisk" parameterType="pd" resultType="pd">
		select
		id.PARTSNAME,
		id.IDENTIFICATIONPARTS_ID,
		id.ELECTRONIC_FENCE_ID,
		id.ELECTRONIC_FENCE_NAME,
		un.RISKUNITNAME,
		de.NAME DEPT_NAME,
		count(r.RISKPOINT_ID) as RISK_COUNT
		from
		BUS_LIST_CHECKITEM f
		left join BUS_RISKPOINT r on r.RISKPOINT_ID=f.RISKPOINT_ID
		left join bus_identificationparts id on id.IDENTIFICATIONPARTS_ID =
		r.IDENTIFICATION_ID
		left join BUS_RISKUNIT un on id.RISK_UNIT_ID = un.RISKUNIT_ID
		left join OA_DEPARTMENT de on de.DEPARTMENT_ID = un.DEPARTMENT_ID
		where
		f.LISTMANAGER_ID = #{LISTMANAGER_ID}
		and
		f.ISDELETE = '0'
		group by id.IDENTIFICATIONPARTS_ID,id.PARTSNAME
		order by (select o.ORDERBY from BUS_CHECKROUTE o where o.LISTMANAGER_ID = f.LISTMANAGER_ID and o.IDENTIFICATIONPARTS_ID = id.IDENTIFICATIONPARTS_ID)
	</select>

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

	<!--查询部门清单 -->
	<select id="listListByDep" parameterType="pd" resultType="pd">
		SELECT
		f.LISTMANAGER_ID
		FROM
		bus_listmanager f
		WHERE
		f.ISDELETE = '0'
		and f.DEPARTMENT_ID = #{DEPARTMENT_ID}
	</select>

	<!--人员负责清单数 -->
	<select id="countListByUser" parameterType="pd" resultType="pd">
		SELECT
		count(1) NUM,
		f.USER_ID
		FROM
		vi_list_all f
		LEFT JOIN SYS_USER u ON u.USER_ID = f.USER_ID
		WHERE
		f.ISDELETE = '0'
		and f.CORPINFO_ID = #{CORPINFO_ID}
		GROUP BY
		f.USER_ID
	</select>
	<!-- 查询所有可发送短信的企业的清单 -->
	<select id="listAllByCorpMsm" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		,
		u.NAME USER_NAME,
		u.USERNAME PHONE,
		c.SMS_COUNT,
		getCheckedNum(f.LISTMANAGER_ID) checkCount
		from
		<include refid="tableName"></include>
		f
		left join sys_user u on u.USER_ID = f.USER_ID
		left join bus_corp_info
		c on c.CORPINFO_ID = f.CORPINFO_ID
		where f.ISDELETE = '0' and (f.TYPE
		!= 'listType0005' or (f.START_DATE &lt;= DATE_FORMAT(NOW(),'%Y-%m-%d')
		and f.END_DATE &gt;= DATE_FORMAT(NOW(),'%Y-%m-%d') ))
		and u.USERNAME is
		not null
		and u.USERNAME != ''
		and u.ISMAIN = '0' <!-- 非主账号 -->
		and f.CORPINFO_ID in (select CORPINFO_ID from bus_corp_info where
		ISRECEIVE='1' and ISDELETE = '0' )
		<if test="USERNAME != null and USERNAME != ''">
			and u.NAME LIKE CONCAT(CONCAT('%', #{USERNAME}),'%')
		</if>
		<if test="KEYWORDS != null and KEYWORDS != ''">
			and f.NAME LIKE CONCAT(CONCAT('%', #{KEYWORDS}),'%')
		</if>
		order by f.CORPINFO_ID
	</select>

	<!--查询人员清单 -->
	<select id="listListByUser" parameterType="pd" resultType="pd">
		SELECT
			f.LISTMANAGER_ID
		FROM
			bus_listmanager f
		WHERE
			f.ISDELETE = '0'
		  and f.USER_ID = #{USER_ID}
	</select>

	<!--查询人员清单 -->
	<select id="getListByCorplistPage" parameterType="page" resultType="pd">
		SELECT
		f.LIST_TYPE,
		f.LISTMANAGER_ID,
		f.NAME,
		f.CREATTIME,
		p.NAME AS PERIOD_NAME,
		t.NAME AS TYPE_NAME,
		u.NAME  USER_NAME,
		getFullName(d.DEPARTMENT_ID)  DEPARTMENT_NAME,
		po.NAME  POST_NAME
		FROM
		vi_list_all f
		left join sys_dictionaries p on p.BIANMA = f.PERIOD
		left join sys_dictionaries t on t.BIANMA = f.TYPE
		left join sys_user u on u.USER_ID = f.USER_ID
		left join oa_department d on u.DEPARTMENT_ID = d.DEPARTMENT_ID
		left join sys_post po on u.POST_ID = po.POST_ID
		WHERE
		f.ISDELETE = '0'
		and f.CORPINFO_ID = #{pd.CORPINFO_ID}
		<if test="pd.USERNAME != null and pd.USERNAME != ''">
			and u.NAME LIKE CONCAT(CONCAT('%', #{pd.USERNAME}),'%')
		</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
					d.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"'>
								<choose>
									<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
										and
										d.DEPARTMENT_ID in
										<foreach item="item" index="index"
												 collection="pd.DEPT_IDS" open="(" separator="," close=")">
											'${item}'
										</foreach>
									</when>
									<otherwise>
										and
										((d.DEPARTMENT_ID in (
										select
										SUB_DEPARTMENT_ID
										from
										oa_supervision_department osd
										where
										osd.SUP_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
										and osd.ISDELETE = '0'
										and osd.CORPINFO_ID  = #{pd.CORPINFO_ID}
										)) or (
										d.DEPARTMENT_ID in
										<foreach item="item" index="index"
												 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
											'${item}'
										</foreach>
										))
									</otherwise>
								</choose>
							</when>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								or f.USER_ID = #{pd.USER_ID}
								and
								d.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<otherwise>

								and
								d.DEPARTMENT_ID in (
								select
								SUB_DEPARTMENT_ID
								from
								oa_supervision_department osd
								where
								osd.SUP_DEPARTMENT_ID = #{pd.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"'>
						<choose>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								d.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<otherwise>
								and
								d.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</otherwise>
						</choose>
					</when>
					<when test="pd.DEPARTMENT_ID != null and pd.DEPARTMENT_ID != ''">
						and d.DEPARTMENT_ID=#{pd.DEPARTMENT_ID}
						and f.USER_ID = #{pd.USER_ID}
					</when>
					<otherwise>
					</otherwise>
				</choose>
			</otherwise>
		</choose>

		ORDER BY d.DEP_ORDER,po.POST_ID,f.USER_ID,f.PERIOD
	</select>

	<!--查询所有清单清单 -->
	<select id="getAllList" parameterType="pd" resultType="pd">
		SELECT
		f.*,
		getCheckedNum(f.LISTMANAGER_ID) checkCount
		FROM
		bus_listmanager f
		WHERE
		f.ISDELETE = '0'
	</select>

	<select id="goIndexCount" parameterType="pd" resultType="pd">
		SELECT
		   lis.SCREENTYPE SCREENTYPE,
		   COUNT(*) as COUNT,
		   DATE_FORMAT( f.CHECK_TIME, '%Y-%m' ) TIME
		  FROM
		   BUS_CHECKRECORD f
		  LEFT JOIN bus_LISTMANAGER lis ON lis.LISTMANAGER_ID = f.LISTMANAGER_ID
		  WHERE
		   f.CORPINFO_ID = #{CORPINFO_ID}
		   and f.CHECK_TIME is not null
		   and lis.screenType is not null
		   and f.ISSTATISTICS = '1'
		   and f.isdelete = '0'
		   and lis.isdelete = '0'
		   AND f.FINISHED = '1'
		   and f.TYPE = '1'
		   AND DATE_FORMAT( f.CHECK_TIME, '%Y-%m' ) &gt;= #{TIME}
		   AND DATE_FORMAT( f.CHECK_TIME, '%Y-%m' ) &lt;= DATE_FORMAT( NOW(), '%Y-%m' )
		  GROUP BY
		   lis.screenType,
		   DATE_FORMAT( f.CHECK_TIME, '%Y-%m' )
		  ORDER BY
		   lis.screenType,
			  DATE_FORMAT( f.CHECK_TIME, '%Y-%m' )
	</select>

	<!-- 查询公司清单总数 -->
	<select id="getListCount" parameterType="pd" resultType="int" >
		SELECT
			count( 1 )
		FROM
			vi_list_all
		WHERE
			CORPINFO_ID = #{CORPINFO_ID}
			and ISDELETE  = '0'
	</select>

	<!-- 查询公司检查过清单的总数 -->
	<select id="getWorkedListCount" parameterType="pd" resultType="int" >
		SELECT
			COUNT(DISTINCT S.LISTMANAGER_ID )
		FROM
			VI_LIST_CHECKRECORD_ALL S
		WHERE
			S.CORPINFO_ID = #{CORPINFO_ID}
		  AND S.FINISHED = '1'
		  AND S.ISDELETE = '0'
		  AND S.TYPE = '1'
		  AND S.CHECKRECORD_ID IS NOT NULL
	</select>

	<!-- 根据分类统计清单 -->
	<select id="countListByType" parameterType="pd" resultType="pd" >
		SELECT
			COUNT( f.TYPE ) NUM,
			d.NAME NAME
		FROM
			bus_listmanager f
			LEFT JOIN sys_dictionaries d ON f.TYPE = d.BIANMA
			AND d.YNDEL = 'no'
		WHERE
			f.ISDELETE = '0'
			AND f.CORPINFO_ID = #{CORPINFO_ID}
		GROUP BY
			f.TYPE
	</select>

	<!-- 上期超期未检查的清单 -->
	<select id="overTimeRecord" parameterType="pd" resultType="pd">
		SELECT
			f.NAME,f.LISTMANAGER_ID,f.CORPINFO_ID
		FROM
			bus_listmanager f
			LEFT JOIN bus_offduty o ON o.USER_ID = f.USER_ID
			AND concat( o.STARTTIME, ' 00:00:00' ) &lt;= #{STARTTIME} AND concat( o.ENDTIME, ' 23:59:59' ) &gt;= #{ENDTIME}
			left join bus_listdisabletime ld on ld.LISTMANAGER_ID = f.LISTMANAGER_ID and ld.ENDTIME is not null
			and ld.STARTTIME &lt;= #{STARTTIME} and ld.ENDTIME &gt;= #{ENDTIME}
		WHERE
			f.LISTMANAGER_ID NOT IN (
			SELECT
				l.LISTMANAGER_ID
			FROM
				bus_listmanager l
				LEFT JOIN bus_checkrecord c ON c.LISTMANAGER_ID = l.LISTMANAGER_ID
			WHERE
				l.isdelete = '0'
				AND l.PERIOD = #{PERIOD}
				AND l.TYPE != 'listType0005'
				AND (

					c.CHECK_TIME BETWEEN #{STARTTIME} AND #{ENDTIME}
					or
					(
						c.periodstart =#{STARTTIME} and c.periodend = #{ENDTIME}
					)
				)

			)
			AND f.isdelete = '0'
			AND f.TYPE != 'listType0005'
			AND f.PERIOD = #{PERIOD}
			AND o.OFFDUTY_ID IS NULL
			AND ld.LISTDISABLETIME_ID IS NULL
	</select>

	<!-- 上期超期未检查的清单（每日使用） -->
	<select id="overTimeRecordDay" parameterType="pd" resultType="pd">
		SELECT
			f.NAME,f.LISTMANAGER_ID,f.CORPINFO_ID
		FROM
			bus_listmanager f
			LEFT JOIN bus_offduty o ON o.USER_ID = f.USER_ID
			AND concat( o.STARTTIME, ' 00:00:00' ) &lt;= #{STARTTIME} AND concat( o.ENDTIME, ' 23:59:59' ) &gt;= #{ENDTIME}
			left join bus_listdisabletime ld on ld.LISTMANAGER_ID = f.LISTMANAGER_ID and ld.ENDTIME is not null
			and ld.STARTTIME &lt;= #{STARTTIME} and ld.ENDTIME &gt;= #{ENDTIME}
			LEFT JOIN SYS_USER u on u.USER_ID = f.USER_ID
			LEFT JOIN BUS_SHIFTWORKRULES swr ON u.SHIFTDUTYTWO = swr.SHIFTWORKRULES_ID
		WHERE
			f.LISTMANAGER_ID NOT IN (
			SELECT
				l.LISTMANAGER_ID
			FROM
				bus_listmanager l
				LEFT JOIN bus_checkrecord c ON c.LISTMANAGER_ID = l.LISTMANAGER_ID
			WHERE
				l.isdelete = '0'
				AND l.PERIOD = #{PERIOD}
				AND l.TYPE != 'listType0005'
				AND (

					c.CHECK_TIME BETWEEN #{STARTTIME} AND #{ENDTIME}
					or
					(
						c.periodstart =#{STARTTIME} and c.periodend = #{ENDTIME}
					)
				)

			)
			AND f.isdelete = '0'
			AND f.TYPE != 'listType0005'
			AND f.PERIOD = #{PERIOD}
			AND o.OFFDUTY_ID IS NULL
			AND ld.LISTDISABLETIME_ID IS NULL
			AND (
					(
						swr.ISDELETE = '0'
						AND (
							swr.ISCUSTOM = '0'
							OR ( u.WORKSTATUS = '1' AND u.DURATION > 1 )
							OR ( u.WORKSTATUS = '2' AND u.DURATION = '1' )
						)
					)
					OR u.SHIFTDUTYONE IS NULL
					OR u.SHIFTDUTYONE = ''
				)
	</select>

	<!-- 节假日超期未检查的清单 -->
	<select id="overTimeRecordJjr" parameterType="pd" resultType="pd">
		SELECT
			f.NAME,
			f.LISTMANAGER_ID,
			f.CORPINFO_ID,
			IFNULL( h.num, 0 ) COUNT,
			f.START_DATE,
			f.END_DATE
		FROM
			bus_listmanager f
			LEFT JOIN bus_offduty o ON o.USER_ID = f.USER_ID
			AND concat( o.STARTTIME, ' 00:00:00' ) &lt;= concat( f.START_DATE, ' 00:00:00' ) AND concat( o.ENDTIME, ' 23:59:59' ) &gt;= concat( f.End_DATE, ' 23:59:59' )
			LEFT JOIN bus_listdisabletime ld ON ld.LISTMANAGER_ID = f.LISTMANAGER_ID
			AND ld.ENDTIME IS NOT NULL
			AND ld.STARTTIME &lt;= concat( f.START_DATE, ' 00:00:00' ) AND ld.ENDTIME &gt;= concat( f.End_DATE, ' 23:59:59' )
			LEFT JOIN (
			SELECT
				l.LISTMANAGER_ID,
				count( 1 ) NUM
			FROM
				bus_listmanager l
				LEFT JOIN bus_checkrecord c ON c.LISTMANAGER_ID = l.LISTMANAGER_ID
			WHERE
				l.isdelete = '0'
				AND l.TYPE = 'listType0005'
				AND (
					c.CHECK_TIME BETWEEN concat( l.START_DATE, ' 00:00:00' )
					AND concat( l.END_DATE, ' 23:59:59' )
					OR (
						c.periodstart = concat( l.START_DATE, ' 00:00:00' )
					AND c.periodend = concat( l.END_DATE, ' 23:59:59' ))
				)
			GROUP BY
				l.LISTMANAGER_ID
			) h ON h.LISTMANAGER_ID = f.LISTMANAGER_ID
		WHERE
			f.isdelete = '0'
		  	AND now() > f.END_DATE
			AND f.TYPE = 'listType0005'
			AND ( h.NUM &lt; 1 OR h.NUM IS NULL )
			AND o.OFFDUTY_ID IS NULL
			AND f.START_DATE IS NOT NULL
			AND f.END_DATE IS NOT NULL
			AND ld.LISTDISABLETIME_ID IS NULL
	</select>

	<!-- 查询今日待处理清单数 -->
	<select id="getListToday" parameterType="pd" resultType="pd">
		SELECT
			COUNT( u.USER_ID ) NUM,
			u.USER_ID,
			u.USERNAME,
			u.CORPINFO_ID
		FROM
			SYS_USER u
			LEFT JOIN BUS_LISTMANAGER f ON u.USER_ID = f.USER_ID
			LEFT JOIN VIEW_EXAMINE w ON f.LISTMANAGER_ID = w.LISTMANAGER_ID
			LEFT JOIN BUS_CORP_INFO c on c.CORPINFO_ID = u.CORPINFO_ID
			left join bus_smsmanagement m on m.CORPINFO_ID = c.CORPINFO_ID
		WHERE
			f.ISDELETE = '0'
			and c.ISRECEIVE = '1'
			AND u.ISMAIN = '0'
			AND w.numCount &lt; 1
			and m.SMSCODE = #{SMSCODE}
			and m.ISENABLE = '1'
		GROUP BY
			u.USER_ID,
			u.USERNAME,
			u.CORPINFO_ID
	</select>

	<select id="listAllForDiagnosis" parameterType="pd" resultType="pd">
		select
			f.*,
			u.NAME AS USER_NAME
		from
			BUS_LISTMANAGER f
		LEFT JOIN
			SYS_USER u on u.USER_ID = f.USER_ID
		where
			DATE_FORMAT(f.CREATTIME,'%Y-%m') <![CDATA[ <= ]]> #{MONTH}
		  and DATE_FORMAT(f.CREATTIME,'%Y-%m') <![CDATA[ >= ]]> #{CORPCREATTIME}
		  and f.ISDELETE ='0'
		  and f.CORPINFO_ID = #{CORPINFO_ID}
		order by f.OPERATTIME desc
	</select>

	<!--当前月份的清单数据	-->
	<select id="thisMonthListmanager" parameterType="pd" resultType="pd">
		select
			f.*,
			u.NAME AS USER_NAME
		from
			BUS_LISTMANAGER f
				LEFT JOIN
			SYS_USER u on u.USER_ID = f.USER_ID
		where
			DATE_FORMAT(f.CREATTIME,'%Y-%m') = #{MONTH}  and f.ISDELETE ='0' and f.CORPINFO_ID = #{CORPINFO_ID}
	</select>

	<select id="listAllPlan" parameterType="pd" resultType="pd">
		select type.BIANMA type_bianma,type.NAME type_name,
			   level.BIANMA level_bianma,level.NAME level_name,
			   period.BIANMA period_bianma,period.NAME period_name,
		       0 as list_count,0 as check_count,0 as dept_count,0 as display_count
		from sys_dictionaries type
				 LEFT JOIN sys_dictionaries period on period.PARENT_ID = 'f60cf0e8315b4993b6d6049dd29f2ba5'
				 LEFT JOIN sys_dictionaries level on level.PARENT_ID = '4a661fa8aedc4d158c9cddaa9d2ec47e'
		where type.PARENT_ID = '4a3d0d99b0ea4e268c11dd0b18866917' and type.bianma != 'listType0006'
		order by type.BIANMA,level.BIANMA,period.BIANMA
	</select>

	<select id="listAllForPlan" parameterType="pd" resultType="pd">
		select f.*,d.LEVEL level_bianma
		from BUS_LISTMANAGER f
		left join OA_DEPARTMENT d on d.DEPARTMENT_ID = f.DEPARTMENT_ID
		where f.ISDELETE = '0' and f.TYPE != 'listType0006'
		<if test="CORPINFO_ID != null and CORPINFO_ID != ''"><!-- 关键词检索 -->
			and f.CORPINFO_ID = #{CORPINFO_ID}
		</if>
	</select>

	<select id="mergeListAllForPlan" parameterType="pd" resultType="pd">
		select * from (select f.NAME,
		f.PERIOD,
		f.TYPE,
		f.CORPINFO_ID,
		f.CREATOR,
		f.CREATTIME,
		f.OPERATOR,
		f.OPERATTIME,
		f.ISDELETE,
		f.LISTMANAGER_ID as ID,
		f.DEPARTMENT_ID,
		f.POST_ID,
		f.USER_ID,
		f.START_DATE,
		f.END_DATE,
		f.SCREENTYPE,
		f.BAO_BAO_DEPARTMENT_ID,
		f.BAO_BAO_USER_ID,
		f.BAO_BAO_TYPE,
		f.TASK_TYPE,d.LEVEL level_bianma,
		getCheckedNum(f.LISTMANAGER_ID) checkCount
		from BUS_LISTMANAGER f
		left join OA_DEPARTMENT d on d.DEPARTMENT_ID = f.DEPARTMENT_ID
		where f.ISDELETE = '0' and f.TYPE != 'listType0006'
		<if test="CORPINFO_ID != null and CORPINFO_ID != ''"><!-- 关键词检索 -->
			and f.CORPINFO_ID = #{CORPINFO_ID}
		</if>
		union
		select f.NAME,
		f.PERIOD,
		f.TYPE,
		f.CORPINFO_ID,
		f.CREATOR,
		f.CREATTIME,
		f.OPERATOR,
		f.OPERATTIME,
		f.ISDELETE,
		f.CUSTOM_ID as ID,
		f.DEPARTMENT_ID,
		f.POST_ID,
		f.USER_ID,
		f.START_DATE,
		f.END_DATE,
		f.SCREENTYPE,
		f.BAO_BAO_DEPARTMENT_ID,
		f.BAO_BAO_USER_ID,
		f.BAO_BAO_TYPE,
		f.TASK_TYPE,d.LEVEL level_bianma,
		getStandardCheckedNum(f.CUSTOM_ID) checkCount
		from bus_hiddendangercheckstandard_custom f
		left join OA_DEPARTMENT d on d.DEPARTMENT_ID = f.DEPARTMENT_ID
		where f.ISDELETE = '0' and f.TYPE != 'listType0006'
		<if test="CORPINFO_ID != null and CORPINFO_ID != ''"><!-- 关键词检索 -->
			and f.CORPINFO_ID = #{CORPINFO_ID}
		</if>
		) z
	</select>

	<select id="getCountNumBi" parameterType="pd" resultType="pd">
		select count(1) count,d.NAME
		from vi_list_all f
		left join sys_dictionaries d on d.BIANMA = f.SCREENTYPE
		where f.ISDELETE = '0'
		<if test="CORPINFO_ID != null and CORPINFO_ID != ''"><!-- 关键词检索 -->
			and f.CORPINFO_ID = #{CORPINFO_ID}
		</if>
		<!--		<if test="YEAR != null and YEAR != ''">&lt;!&ndash; 年度 &ndash;&gt;-->
		<!--			and DATE_FORMAT( f.CREATTIME, '%Y' ) = #{YEAR}-->
		<!--		</if>-->
		group by d.NAME
	</select>

	<!-- 查询未对接数据 -->
	<select id="listForDocking" parameterType="pd" resultType="pd" >
		SELECT
			l.*,
			re.CHECK_TIME
		FROM
			BUS_LISTMANAGER l
		LEFT JOIN
		(select r.LISTMANAGER_ID,min(r.CHECK_TIME) as CHECK_TIME from bus_checkrecord r group by r.LISTMANAGER_ID) re on re.LISTMANAGER_ID = l.LISTMANAGER_ID
		WHERE
			l.CORPINFO_ID = #{CORPINFO_ID}
		  and l.IS_DOCKING is null
		  and l.ISDELETE = 0
	</select>
	<select id="findByCondition" resultType="com.zcloud.entity.PageData">
		select * from bus_listmanager a where a.ISDELETE = '0'
		<if test="BAO_BAO_TYPE != '' and BAO_BAO_TYPE != null">
			and a.BAO_BAO_TYPE = #{BAO_BAO_TYPE}
		</if>
		<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>
	</select>
	<select id="analysis" resultType="com.zcloud.entity.PageData">
		select count(1),a.TASK_TYPE,sd.NAME as TASK_TYPE_NAME
		from bus_listmanager a
		left join sys_dictionaries sd on a.TASK_TYPE = sd.DICTIONARIES_ID
		where a.ISDELETE = '0'
		<if test="ids != null and ids.length != 0">
			and a.LISTMANAGER_ID in
			<foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
				'${item}'
			</foreach>
		</if>
		group by a.TASK_TYPE;
	</select>

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

	<!-- 部门清单列表 -->
	<select id="riskStandardRecordlistPage" parameterType="page" resultType="pd">
	( select * from
		(
		select
		f.LISTMANAGER_ID,
		f.NAME,
		f.OPERATTIME,
		f.ISDELETE,
		f.DEPARTMENT_ID,
		f.POST_ID,
		f.USER_ID,
		"1" as list_type,
		u.WORKSTATUS,
		a.STARTTIME,
		a.ENDTIME ,
		p.NAME PERIODNAME,
		t.NAME TYPENAME,
		m.NAME SCREENTYPENAME,
		d.NAME as DEPARTMENT_NAME,
		getFullName(d.DEPARTMENT_ID) as DEPARTMENT_NAME_ALL,
		sp.NAME
		AS POST_NAME,
		u.NAME as USER_NAME,
		(
		select count(1) from BUS_CHECKRECORD ch
		where ch.LISTMANAGER_ID=f.LISTMANAGER_ID AND ch.type = '1'
		and ch.FINISHED='1' and ch.ISDELETE =0
		) as count ,
		(
		select
		count(1)
		from BUS_CHECKRECORD ch
		left join bus_hidden h on h.CHECKRECORD_ID = ch.CHECKRECORD_ID
		where ch.LISTMANAGER_ID=f.LISTMANAGER_ID
		and ch.FINISHED='1'
		and ch.ISDELETE =0
		and h.ISDELETE =0
		and h.HIDDEN_ID is not null
		) as hiddenCount,

		(
		CASE
		WHEN f.TYPE = 'listType0005' THEN
		CONCAT( f.START_DATE, " 00:00:00" )
		WHEN f.PERIOD = 'checkPeriod0001' THEN
		(select sd.DAY_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0002' THEN
		(select sd.WEEK_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0003' THEN
		(select sd.XUN_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0004' THEN
		(select sd.MONTH_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0005' THEN
		(select sd.QUARTER_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0006' THEN
		(select sd.YEAR_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0007' THEN
		(select sd.HALFYEAR_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		END
		) DATESTART,
		bb.NAME AS TASK_TYPE_NAME,
		(
		CASE
		WHEN f.TYPE = 'listType0005' THEN
		CONCAT( f.END_DATE, " 23:59:59" )
		WHEN f.PERIOD = 'checkPeriod0001' THEN
		(select sd.DAY_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0002' THEN
		(select sd.WEEK_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0003' THEN
		(select sd.XUN_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0004' THEN
		(select sd.MONTH_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0005' THEN
		(select sd.QUARTER_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0006' THEN
		(select sd.YEAR_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0007' THEN
		(select sd.HALFYEAR_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		END
		) DATEEND,
		getCheckedNum(f.LISTMANAGER_ID) checkCount,
		(select count(1) from bus_checkrecord cc where cc.LISTMANAGER_ID = f.LISTMANAGER_ID  and cc.FINISHED ='1' and type ='2') overTimeCount
		from
		<include refid="tableName"></include>
		f
		LEFT JOIN BUS_OFFDUTY a on f.USER_ID = a.USER_ID and a.isdelete = '0' and a.STARTTIME &lt;= date_format(now(),'%Y-%m-%d') and a.ENDTIME &gt;= date_format(now(),'%Y-%m-%d')
		left join sys_dictionaries p on f.PERIOD = p.BIANMA
		left join sys_dictionaries t on f.TYPE = t.BIANMA
		left join sys_dictionaries m on f.SCREENTYPE = m.BIANMA
		left join OA_DEPARTMENT d on d.DEPARTMENT_ID = f.DEPARTMENT_ID
		LEFT JOIN sys_dictionaries bb ON f.TASK_TYPE = bb.DICTIONARIES_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 = #{pd.CORPINFO_ID} and f.ISDELETE != '-99'
		<if test="pd.RISKCHECKLISTTYPE != null and pd.RISKCHECKLISTTYPE != ''"><!-- 状态 -->
			and f.SCREENTYPE = #{pd.RISKCHECKLISTTYPE}
		</if>
		<if test="pd.statusIds != null and pd.statusIds != ''">
			and
			(
			f.LISTMANAGER_ID in
			<foreach item="item" index="index" collection="pd.statusIds"
					 open="(" separator="," close=")">
				'${item}'
			</foreach>
			)
		</if>
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and
			(
			f.NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
			)
		</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
					f.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"'>
								<choose>
									<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
										and
										f.DEPARTMENT_ID in
										<foreach item="item" index="index"
												 collection="pd.DEPT_IDS" open="(" separator="," close=")">
											'${item}'
										</foreach>
									</when>
									<when test="pd.DEPT_ID != null and pd.DEPT_ID != ''"><!-- 关键词检索 -->
										and f.DEPARTMENT_ID = #{pd.DEPT_ID}
									</when>
									<otherwise>
										and
										((f.DEPARTMENT_ID in (
										select
										SUB_DEPARTMENT_ID
										from
										oa_supervision_department osd
										where
										osd.SUP_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
										and osd.ISDELETE = '0'
										and osd.CORPINFO_ID  = #{pd.CORPINFO_ID}
										)) or (
										f.DEPARTMENT_ID in
										<foreach item="item" index="index"
												 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
											'${item}'
										</foreach>
										))
									</otherwise>
								</choose>
							</when>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<when test="pd.DEPT_ID != null and pd.DEPT_ID != ''">
								and
								f.DEPARTMENT_ID = #{pd.DEPT_ID}
							</when>
							<otherwise>

								and
								(f.DEPARTMENT_ID in (
								select
								SUB_DEPARTMENT_ID
								from
								oa_supervision_department osd
								where
								osd.SUP_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
								and osd.ISDELETE = '0'
								and osd.CORPINFO_ID  = #{pd.CORPINFO_ID})
								or f.USER_ID = #{pd.USER_ID})
							</otherwise>
						</choose>
					</when>

					<when test='pd.ISLEADER != null and pd.ISLEADER != "" and pd.ISLEADER == "1"'>
						<choose>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<when test="pd.DEPT_ID != null and pd.DEPT_ID != ''">
								and
								f.DEPARTMENT_ID = #{pd.DEPT_ID}
							</when>
							<otherwise>
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</otherwise>
						</choose>
					</when>
					<when test="pd.DEPT_ID != null and pd.DEPT_ID != ''">
						and
						f.DEPARTMENT_ID = #{pd.DEPT_ID}
					</when>
					<when test="pd.DEPARTMENT_ID != null and pd.DEPARTMENT_ID != ''">
						and f.USER_ID = #{pd.USER_ID}
						and f.DEPARTMENT_ID=#{pd.DEPARTMENT_ID}
					</when>
					<otherwise>
					</otherwise>
				</choose>
			</otherwise>
		</choose>
		<if test="pd.USERNAME != null and pd.USERNAME != ''"><!-- 关键词检索 -->
			and u.NAME LIKE CONCAT(CONCAT('%', #{pd.USERNAME}),'%')
		</if>

		<if test="pd.ISDELETE != null and pd.ISDELETE != ''"><!-- 状态 -->
			and f.ISDELETE = #{pd.ISDELETE}
		</if>

		<if test="pd.STATUS != null and pd.STATUS != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.STATUS=="1"'>
					AND getCheckedNum(f.LISTMANAGER_ID) &gt; 0
				</when>
				<when test='pd.STATUS=="0"'>
					AND getCheckedNum(f.LISTMANAGER_ID) = 0
				</when>
				<otherwise>
				</otherwise>
			</choose>
		</if>
		<if test="pd.OVERTIME != null and pd.OVERTIME != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.OVERTIME=="1"'>
					AND (select count(1) from bus_checkrecord cc where cc.LISTMANAGER_ID = f.LISTMANAGER_ID  and cc.FINISHED ='1' and type ='2') &gt; 0
				</when>
				<when test='pd.OVERTIME=="0"'>
					AND (select count(1) from bus_checkrecord cc where cc.LISTMANAGER_ID = f.LISTMANAGER_ID  and cc.FINISHED ='1' and type ='2') = 0
				</when>
				<otherwise>
				</otherwise>
			</choose>
		</if>
		<if test="pd.PERIOD != null and pd.PERIOD != ''"><!-- 关键词检索 -->
			and f.PERIOD = #{pd.PERIOD}
		</if>
		<if test="pd.TYPE != null and pd.TYPE != ''"><!-- 关键词检索 -->
			and f.TYPE = #{pd.TYPE}
		</if>
		<if test='pd.WORKSTATUS == "0"'>
			and (
			(a.STARTTIME is null or a.ENDTIME is null)
			or (to_days(a.STARTTIME) &lt; to_days(NOW()) and to_days(a.ENDTIME) &gt; to_days(NOW()))
			AND u.WORKSTATUS != '2'
			)
		</if>
		<if test='pd.WORKSTATUS == "1"'>
			and !(
			(a.STARTTIME is null or a.ENDTIME is null)
			or (to_days(a.STARTTIME) &lt; to_days(NOW()) and to_days(a.ENDTIME) &gt; to_days(NOW()))
			or u.WORKSTATUS = '2'
			)
		</if>
		<if test="pd.LISTINGLEVEL != null and pd.LISTINGLEVEL != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.LISTINGLEVEL == "1"'>
					and d.LEVEL = ''
				</when>
				<otherwise>
					and d.LEVEL = #{pd.LISTINGLEVEL}
				</otherwise>
			</choose>
		</if>
		<if test="(pd.STARTTIME != null and pd.STARTTIME != '') or (pd.ENDTIME != null and pd.ENDTIME != '')"><!-- 关键词检索 -->
			<choose>
				<when
						test="pd.STARTTIME != null and pd.STARTTIME != '' and pd.ENDTIME != null and pd.ENDTIME != ''">
					and f.LISTMANAGER_ID in
					(
					SELECT LISTMANAGER_ID
					FROM BUS_CHECKRECORD
					WHERE FINISHED = '1'
					AND ISDELETE = 0
					and DATE_FORMAT(CHECK_TIME,'%Y-%m-%d %H:%i:%s') &gt;= #{pd.STARTTIME}
					and DATE_FORMAT(CHECK_TIME,'%Y-%m-%d %H:%i:%s') &lt;= #{pd.ENDTIME}
					)
				</when>
				<when test="pd.STARTTIME != null and pd.STARTTIME != ''">
					and f.LISTMANAGER_ID in
					(
					SELECT LISTMANAGER_ID
					FROM BUS_CHECKRECORD
					WHERE FINISHED = '1'
					AND ISDELETE = 0
					and DATE_FORMAT(CHECK_TIME,'%Y-%m-%d %H:%i:%s') &gt;= #{pd.STARTTIME}
					)
				</when>
				<when test="pd.ENDTIME != null and pd.ENDTIME != ''">
					and f.LISTMANAGER_ID in
					(
					SELECT LISTMANAGER_ID
					FROM BUS_CHECKRECORD
					WHERE FINISHED = '1'
					AND ISDELETE = 0
					and DATE_FORMAT(CHECK_TIME,'%Y-%m-%d %H:%i:%s') &lt;= #{pd.ENDTIME}
					)
				</when>
			</choose>

		</if>
		) f
		where 1= 1

		<if test="pd.HASHIDDEN != null and pd.HASHIDDEN != ''"><!-- 关键词检索 -->
			<choose>
				<when test="pd.HASHIDDEN == 0">
					and f.hiddenCount = 0
				</when>
				<when test="pd.HASHIDDEN == 1">
					and f.hiddenCount > 0
				</when>
			</choose>
		</if>
		group by f.LISTMANAGER_ID
		order by field(f.ISDELETE,'0','1','2','-1')	,f.OPERATTIME desc )
	union
		(select * from
		(
		select
		f.CUSTOM_ID,
		f.NAME,
		f.OPERATTIME,
		f.ISDELETE,
		f.DEPARTMENT_ID,
		f.POST_ID,
		f.USER_ID,
		"2" as list_type,
		u.WORKSTATUS,
		a.STARTTIME,
		a.ENDTIME ,
		p.NAME PERIODNAME,
		t.NAME TYPENAME,
		m.NAME SCREENTYPENAME,
		d.NAME as DEPARTMENT_NAME,
		getFullName(d.DEPARTMENT_ID) as DEPARTMENT_NAME_ALL,
		sp.NAME
		AS POST_NAME,
		u.NAME as USER_NAME,
		(
		select count(1) from bus_hiddendangercheckstandard_checkrecord ch
		where ch.CUSTOM_ID=f.CUSTOM_ID AND ch.type = '1'
		and ch.FINISHED='1' and ch.ISDELETE =0
		) as count ,
		(
		select
		count(1)
		from bus_hiddendangercheckstandard_checkrecord ch
		left join bus_hiddendangercheckstandard_hidden h on h.CHECKRECORD_ID = ch.CHECKRECORD_ID
		where ch.CUSTOM_ID=f.CUSTOM_ID
		and ch.FINISHED='1'
		and ch.ISDELETE =0
		and h.ISDELETE =0
		and h.HIDDEN_ID is not null
		) as hiddenCount,

		(
		CASE
		WHEN f.TYPE = 'listType0005' THEN
		CONCAT( f.START_DATE, " 00:00:00" )
		WHEN f.PERIOD = 'checkPeriod0001' THEN
		(select sd.DAY_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0002' THEN
		(select sd.WEEK_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0003' THEN
		(select sd.XUN_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0004' THEN
		(select sd.MONTH_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0005' THEN
		(select sd.QUARTER_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0006' THEN
		(select sd.YEAR_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0007' THEN
		(select sd.HALFYEAR_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		END
		) DATESTART,
		bb.NAME AS TASK_TYPE_NAME,
		(
		CASE
		WHEN f.TYPE = 'listType0005' THEN
		CONCAT( f.END_DATE, " 23:59:59" )
		WHEN f.PERIOD = 'checkPeriod0001' THEN
		(select sd.DAY_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0002' THEN
		(select sd.WEEK_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0003' THEN
		(select sd.XUN_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0004' THEN
		(select sd.MONTH_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0005' THEN
		(select sd.QUARTER_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0006' THEN
		(select sd.YEAR_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0007' THEN
		(select sd.HALFYEAR_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		END
		) DATEEND,
		getStandardCheckedNum(f.CUSTOM_ID) checkCount,
		(select count(1) from bus_hiddendangercheckstandard_checkrecord cc where cc.CUSTOM_ID = f.CUSTOM_ID  and cc.FINISHED ='1' and type ='2') overTimeCount
		from
		bus_hiddendangercheckstandard_custom
		f
		LEFT JOIN BUS_OFFDUTY a on f.USER_ID = a.USER_ID and a.isdelete = '0' and a.STARTTIME &lt;= date_format(now(),'%Y-%m-%d') and a.ENDTIME &gt;= date_format(now(),'%Y-%m-%d')
		left join sys_dictionaries p on f.PERIOD = p.BIANMA
		left join sys_dictionaries t on f.TYPE = t.BIANMA
		left join sys_dictionaries m on f.SCREENTYPE = m.BIANMA
		left join OA_DEPARTMENT d on d.DEPARTMENT_ID = f.DEPARTMENT_ID
		LEFT JOIN sys_dictionaries bb ON f.TASK_TYPE = bb.DICTIONARIES_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 = #{pd.CORPINFO_ID} and f.ISDELETE != '-99'
		<if test="pd.statusIds != null and pd.statusIds != ''">
			and
			(
			f.CUSTOM_ID in
			<foreach item="item" index="index" collection="pd.statusIds"
					 open="(" separator="," close=")">
				'${item}'
			</foreach>
			)
		</if>
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and
			(
			f.NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
			)
		</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
					f.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"'>
								<choose>
									<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
										and
										f.DEPARTMENT_ID in
										<foreach item="item" index="index"
												 collection="pd.DEPT_IDS" open="(" separator="," close=")">
											'${item}'
										</foreach>
									</when>
									<when test="pd.DEPT_ID != null and pd.DEPT_ID != ''"><!-- 关键词检索 -->
										and f.DEPARTMENT_ID = #{pd.DEPT_ID}
									</when>
									<otherwise>
										and
										((f.DEPARTMENT_ID in (
										select
										SUB_DEPARTMENT_ID
										from
										oa_supervision_department osd
										where
										osd.SUP_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
										and osd.ISDELETE = '0'
										and osd.CORPINFO_ID  = #{pd.CORPINFO_ID}
										)) or (
										f.DEPARTMENT_ID in
										<foreach item="item" index="index"
												 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
											'${item}'
										</foreach>
										))
									</otherwise>
								</choose>
							</when>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<when test="pd.DEPT_ID != null and pd.DEPT_ID != ''">
								and
								f.DEPARTMENT_ID = #{pd.DEPT_ID}
							</when>
							<otherwise>

								and
								(f.DEPARTMENT_ID in (
								select
								SUB_DEPARTMENT_ID
								from
								oa_supervision_department osd
								where
								osd.SUP_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
								and osd.ISDELETE = '0'
								and osd.CORPINFO_ID  = #{pd.CORPINFO_ID})
								or f.USER_ID = #{pd.USER_ID})
							</otherwise>
						</choose>
					</when>

					<when test='pd.ISLEADER != null and pd.ISLEADER != "" and pd.ISLEADER == "1"'>
						<choose>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<when test="pd.DEPT_ID != null and pd.DEPT_ID != ''">
								and
								f.DEPARTMENT_ID = #{pd.DEPT_ID}
							</when>
							<otherwise>
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</otherwise>
						</choose>
					</when>
					<when test="pd.DEPT_ID != null and pd.DEPT_ID != ''">
						and
						f.DEPARTMENT_ID = #{pd.DEPT_ID}
					</when>
					<when test="pd.DEPARTMENT_ID != null and pd.DEPARTMENT_ID != ''">
						and f.USER_ID = #{pd.USER_ID}
						and f.DEPARTMENT_ID=#{pd.DEPARTMENT_ID}
					</when>
					<otherwise>
					</otherwise>
				</choose>
			</otherwise>
		</choose>
		<if test="pd.USERNAME != null and pd.USERNAME != ''"><!-- 关键词检索 -->
			and u.NAME LIKE CONCAT(CONCAT('%', #{pd.USERNAME}),'%')
		</if>

		<if test="pd.ISDELETE != null and pd.ISDELETE != ''"><!-- 状态 -->
			and f.ISDELETE = #{pd.ISDELETE}
		</if>

		<if test="pd.STATUS != null and pd.STATUS != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.STATUS=="1"'>
					AND getStandardCheckedNum(f.CUSTOM_ID) &gt; 0
				</when>
				<when test='pd.STATUS=="0"'>
					AND getStandardCheckedNum(f.CUSTOM_ID) = 0
				</when>
				<otherwise>
				</otherwise>
			</choose>
		</if>
		<if test="pd.OVERTIME != null and pd.OVERTIME != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.OVERTIME=="1"'>
					AND (select count(1) from bus_hiddendangercheckstandard_checkrecord cc where cc.CUSTOM_ID = f.CUSTOM_ID  and cc.FINISHED ='1' and type ='2') &gt; 0
				</when>
				<when test='pd.OVERTIME=="0"'>
					AND (select count(1) from bus_hiddendangercheckstandard_checkrecord cc where cc.CUSTOM_ID = f.CUSTOM_ID  and cc.FINISHED ='1' and type ='2') = 0
				</when>
				<otherwise>
				</otherwise>
			</choose>
		</if>
		<if test="pd.PERIOD != null and pd.PERIOD != ''"><!-- 关键词检索 -->
			and f.PERIOD = #{pd.PERIOD}
		</if>
		<if test="pd.TYPE != null and pd.TYPE != ''"><!-- 关键词检索 -->
			and f.TYPE = #{pd.TYPE}
		</if>
		<if test='pd.WORKSTATUS == "0"'>
			and (
			(a.STARTTIME is null or a.ENDTIME is null)
			or (to_days(a.STARTTIME) &lt; to_days(NOW()) and to_days(a.ENDTIME) &gt; to_days(NOW()))
			AND u.WORKSTATUS != '2'
			)
		</if>
		<if test='pd.WORKSTATUS == "1"'>
			and !(
			(a.STARTTIME is null or a.ENDTIME is null)
			or (to_days(a.STARTTIME) &lt; to_days(NOW()) and to_days(a.ENDTIME) &gt; to_days(NOW()))
			or u.WORKSTATUS = '2'
			)
		</if>
		<if test="pd.LISTINGLEVEL != null and pd.LISTINGLEVEL != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.LISTINGLEVEL == "1"'>
					and d.LEVEL = ''
				</when>
				<otherwise>
					and d.LEVEL = #{pd.LISTINGLEVEL}
				</otherwise>
			</choose>
		</if>
		<if test="(pd.STARTTIME != null and pd.STARTTIME != '') or (pd.ENDTIME != null and pd.ENDTIME != '')"><!-- 关键词检索 -->
			<choose>
				<when
						test="pd.STARTTIME != null and pd.STARTTIME != '' and pd.ENDTIME != null and pd.ENDTIME != ''">
					and f.CUSTOM_ID in
					(
					SELECT CUSTOM_ID
					FROM bus_hiddendangercheckstandard_checkrecord
					WHERE FINISHED = '1'
					AND ISDELETE = 0
					and DATE_FORMAT(CHECK_TIME,'%Y-%m-%d %H:%i:%s') &gt;= #{pd.STARTTIME}
					and DATE_FORMAT(CHECK_TIME,'%Y-%m-%d %H:%i:%s') &lt;= #{pd.ENDTIME}
					)
				</when>
				<when test="pd.STARTTIME != null and pd.STARTTIME != ''">
					and f.CUSTOM_ID in
					(
					SELECT CUSTOM_ID
					FROM bus_hiddendangercheckstandard_checkrecord
					WHERE FINISHED = '1'
					AND ISDELETE = 0
					and DATE_FORMAT(CHECK_TIME,'%Y-%m-%d %H:%i:%s') &gt;= #{pd.STARTTIME}
					)
				</when>
				<when test="pd.ENDTIME != null and pd.ENDTIME != ''">
					and f.LISTMANAGER_ID in
					(
					SELECT CUSTOM_ID
					FROM bus_hiddendangercheckstandard_checkrecord
					WHERE FINISHED = '1'
					AND ISDELETE = 0
					and DATE_FORMAT(CHECK_TIME,'%Y-%m-%d %H:%i:%s') &lt;= #{pd.ENDTIME}
					)
				</when>
			</choose>

		</if>
		) f
		where 1= 1
		<if test="pd.LIST_TYPE != null and pd.LIST_TYPE != ''">
			and list_type = #{pd.LIST_TYPE}
		</if>
		<if test="pd.HASHIDDEN != null and pd.HASHIDDEN != ''"><!-- 关键词检索 -->
			<choose>
				<when test="pd.HASHIDDEN == 0">
					and f.hiddenCount = 0
				</when>
				<when test="pd.HASHIDDEN == 1">
					and f.hiddenCount > 0
				</when>
			</choose>
		</if>
		group by f.CUSTOM_ID
		order by field(f.ISDELETE,'0','1','2','-1')	,f.OPERATTIME desc )
	</select>

	<!-- 列表(全部) -->
	<select id="listAllRiskStandard" parameterType="pd" resultType="pd">
		select * from
		(
			select
			f.LISTMANAGER_ID, f.NAME, f.PERIOD, f.TYPE, f.CORPINFO_ID,
			f.CREATOR, f.CREATTIME, f.OPERATOR, f.OPERATTIME, f.ISDELETE,
			f.DEPARTMENT_ID, f.POST_ID, f.USER_ID,
<!-- 		f.ACOUNT, f.BCOUNT, f.CCOUNT, f.DCOUNT, -->
			f.START_DATE, f.END_DATE, f.SCREENTYPE,
			f.BAO_BAO_DEPARTMENT_ID, f.BAO_BAO_USER_ID, f.BAO_BAO_TYPE, f.TASK_TYPE,
			p.NAME PERIODNAME,
			t.NAME TYPENAME,
			d.NAME as DEPARTMENT_NAME,
			d.LEVEL as DEPARTMENT_LEVEL,
			sp.NAME
			AS POST_NAME,
			u.NAME USER_NAME,
			(select count(1) from BUS_LIST_CHECKITEM
			ch where ch.LISTMANAGER_ID=f.LISTMANAGER_ID and ch.ISDELETE =0) as
			count,
			getCheckedNum(f.LISTMANAGER_ID) checkCount
			from
			<include refid="tableName"></include>
			f
			left join sys_dictionaries p on f.PERIOD = p.BIANMA
			left join sys_dictionaries t on f.TYPE = t.BIANMA
			left join OA_DEPARTMENT d on d.DEPARTMENT_ID=f.DEPARTMENT_ID
			left join
			sys_user u on u.USER_ID = f.USER_ID
			left join SYS_POST sp on
			sp.POST_ID=f.POST_ID
			where  (f.TYPE != 'listType0005'
			or (f.START_DATE &lt;= DATE_FORMAT(NOW(),'%Y-%m-%d') and f.END_DATE
			&gt;= DATE_FORMAT(NOW(),'%Y-%m-%d') ))

			<!-- <if test="POST_ID != null and POST_ID != ''">关键词检索 -->
			<!-- and -->
			<!-- ( -->
			<!-- f.POST_ID = #{POST_ID} -->
			<!-- ) -->
			<!-- </if> -->
			<if test="CORPINFO_ID != null and CORPINFO_ID != ''">
				and
				f.CORPINFO_ID = #{CORPINFO_ID}
			</if>
					<if test="USER_ID != null and USER_ID != ''"><!-- 部门查询条件 -->
						and f.USER_ID = #{USER_ID}
					</if>
			<choose>
				<when test='ISSUPERVISE != null and ISSUPERVISE != "" and ISSUPERVISE == "1"'>
					<choose>
						<when test='ISLEADER != null and ISLEADER != "" and ISLEADER == "1"'>
							and
							((f.DEPARTMENT_ID in (
							select
							SUB_DEPARTMENT_ID
							from
							oa_supervision_department osd
							where
							osd.SUP_DEPARTMENT_ID = #{SUP_DEPARTMENT_ID}
							and osd.ISDELETE = '0'
							and osd.CORPINFO_ID  = #{CORPINFO_ID}
							)) or (
							f.DEPARTMENT_ID in
							<foreach item="item" index="index"
									 collection="DEPARTMENT_IDS" open="(" separator="," close=")">
								'${item}'
							</foreach>
							))
						</when>
						<otherwise>
							and
							(f.DEPARTMENT_ID in (
							select
							SUB_DEPARTMENT_ID
							from
							oa_supervision_department osd
							where
							osd.SUP_DEPARTMENT_ID = #{SUP_DEPARTMENT_ID}
							and osd.ISDELETE = '0'
							and osd.CORPINFO_ID  = #{CORPINFO_ID}
							) or f.USER_ID = #{USER_ID})
						</otherwise>
					</choose>
				</when>

				<when test='ISLEADER != null and ISLEADER != "" and ISLEADER == "1"'>
					and
					f.DEPARTMENT_ID in
					<foreach item="item" index="index"
							 collection="DEPARTMENT_IDS" open="(" separator="," close=")">
						'${item}'
					</foreach>
				</when>
				<when test="DEPARTMENT_ID != null and DEPARTMENT_ID != ''">
					and
					f.DEPARTMENT_ID = #{DEPARTMENT_ID}
					and f.USER_ID = #{USER_ID}
				</when>
				<otherwise>
				</otherwise>
			</choose>
			<if test="SUB_DEPARTMENT_IDS != null and SUB_DEPARTMENT_IDS != ''">
				and f.DEPARTMENT_ID = #{SUB_DEPARTMENT_IDS}
			</if>
			<if test="USERNAME != null and USERNAME != ''">
				and u.NAME LIKE CONCAT(CONCAT('%', #{USERNAME}),'%')
			</if>
			<if test="KEYWORDS != null and KEYWORDS != ''">
				and f.NAME LIKE CONCAT(CONCAT('%', #{KEYWORDS}),'%')
			</if>
			<if test="STATUS != null and STATUS != ''"><!-- 关键词检索 -->
				<choose>
					<when test='STATUS=="1"'>
						AND getCheckedNum(f.LISTMANAGER_ID) &gt; 0
					</when>
					<when test='STATUS=="0"'>
						AND getCheckedNum(f.LISTMANAGER_ID) = 0
					</when>
					<otherwise>
					</otherwise>
				</choose>
			</if>
			<if test="LISTINGLEVEL != null and LISTINGLEVEL != ''"><!-- 关键词检索 -->
				<choose>
					<when test='LISTINGLEVEL == "1"'>
						and d.LEVEL = ''
					</when>
					<otherwise>
						and d.LEVEL = #{LISTINGLEVEL}
					</otherwise>
				</choose>
			</if>
			AND f.ISDELETE = '0'

			union all

			select
			f.CUSTOM_ID, f.NAME, f.PERIOD, f.TYPE, f.CORPINFO_ID,
			f.CREATOR, f.CREATTIME, f.OPERATOR, f.OPERATTIME, f.ISDELETE,
			f.DEPARTMENT_ID, f.POST_ID, f.USER_ID,
			f.START_DATE, f.END_DATE, f.SCREENTYPE,
			f.BAO_BAO_DEPARTMENT_ID, f.BAO_BAO_USER_ID, f.BAO_BAO_TYPE, f.TASK_TYPE,
			p.NAME PERIODNAME,
			t.NAME TYPENAME,
			d.NAME as DEPARTMENT_NAME,
			d.LEVEL as DEPARTMENT_LEVEL,
			sp.NAME
			AS POST_NAME,
			u.NAME USER_NAME,
			(select count(1) from BUS_HIDDENDANGERCHECKSTANDARD_CUSTOM_ITEM
			ch where ch.CUSTOM_ID=f.CUSTOM_ID and ch.ISDELETE =0) as
			count,
			getStandardCheckedNum(f.CUSTOM_ID) checkCount
			from
			BUS_HIDDENDANGERCHECKSTANDARD_CUSTOM f
			left join sys_dictionaries p on f.PERIOD = p.BIANMA
			left join sys_dictionaries t on f.TYPE = t.BIANMA
			left join OA_DEPARTMENT d on d.DEPARTMENT_ID=f.DEPARTMENT_ID
			left join sys_user u on u.USER_ID = f.USER_ID
			left join SYS_POST sp on sp.POST_ID=f.POST_ID
			where  (f.TYPE != 'listType0005'
			or (f.START_DATE &lt;= DATE_FORMAT(NOW(),'%Y-%m-%d') and f.END_DATE
			&gt;= DATE_FORMAT(NOW(),'%Y-%m-%d') ))

			<!-- <if test="POST_ID != null and POST_ID != ''">关键词检索 -->
			<!-- and -->
			<!-- ( -->
			<!-- f.POST_ID = #{POST_ID} -->
			<!-- ) -->
			<!-- </if> -->
			<if test="CORPINFO_ID != null and CORPINFO_ID != ''">
				and f.CORPINFO_ID = #{CORPINFO_ID}
			</if>
			<if test="USER_ID != null and USER_ID != ''"><!-- 部门查询条件 -->
				and f.USER_ID = #{USER_ID}
			</if>
			<choose>
				<when test='ISSUPERVISE != null and ISSUPERVISE != "" and ISSUPERVISE == "1"'>
					<choose>
						<when test='ISLEADER != null and ISLEADER != "" and ISLEADER == "1"'>
							and
							((f.DEPARTMENT_ID in (
							select
							SUB_DEPARTMENT_ID
							from
							oa_supervision_department osd
							where
							osd.SUP_DEPARTMENT_ID = #{SUP_DEPARTMENT_ID}
							and osd.ISDELETE = '0'
							and osd.CORPINFO_ID  = #{CORPINFO_ID}
							)) or (
							f.DEPARTMENT_ID in
							<foreach item="item" index="index"
									 collection="DEPARTMENT_IDS" open="(" separator="," close=")">
								'${item}'
							</foreach>
							))
						</when>
						<otherwise>
							and
							(f.DEPARTMENT_ID in (
							select
							SUB_DEPARTMENT_ID
							from
							oa_supervision_department osd
							where
							osd.SUP_DEPARTMENT_ID = #{SUP_DEPARTMENT_ID}
							and osd.ISDELETE = '0'
							and osd.CORPINFO_ID  = #{CORPINFO_ID}
							) or f.USER_ID = #{USER_ID})
						</otherwise>
					</choose>
				</when>

				<when test='ISLEADER != null and ISLEADER != "" and ISLEADER == "1"'>
					and
					f.DEPARTMENT_ID in
					<foreach item="item" index="index"
							 collection="DEPARTMENT_IDS" open="(" separator="," close=")">
						'${item}'
					</foreach>
				</when>
				<when test="DEPARTMENT_ID != null and DEPARTMENT_ID != ''">
					and
					f.DEPARTMENT_ID = #{DEPARTMENT_ID}
					and f.USER_ID = #{USER_ID}
				</when>
				<otherwise>
				</otherwise>
			</choose>
			<if test="SUB_DEPARTMENT_IDS != null and SUB_DEPARTMENT_IDS != ''">
				and f.DEPARTMENT_ID = #{SUB_DEPARTMENT_IDS}
			</if>
			<if test="USERNAME != null and USERNAME != ''">
				and u.NAME LIKE CONCAT(CONCAT('%', #{USERNAME}),'%')
			</if>
			<if test="KEYWORDS != null and KEYWORDS != ''">
				and f.NAME LIKE CONCAT(CONCAT('%', #{KEYWORDS}),'%')
			</if>
			<if test="STATUS != null and STATUS != ''"><!-- 关键词检索 -->
				<choose>
					<when test='STATUS=="1"'>
						AND getStandardCheckedNum(f.CUSTOM_ID) &gt; 0
					</when>
					<when test='STATUS=="0"'>
						AND getStandardCheckedNum(f.CUSTOM_ID) = 0
					</when>
					<otherwise>
					</otherwise>
				</choose>
			</if>
			<if test="LISTINGLEVEL != null and LISTINGLEVEL != ''"><!-- 关键词检索 -->
				<choose>
					<when test='LISTINGLEVEL == "1"'>
						and d.LEVEL = ''
					</when>
					<otherwise>
						and d.LEVEL = #{LISTINGLEVEL}
					</otherwise>
				</choose>
			</if>
			AND f.ISDELETE = '0'
		) z
		order by z.USER_ID= #{orderUserId} desc ,z.CREATTIME desc ,z.DEPARTMENT_ID asc
	</select>


	<!-- 部门清单列表 -->
	<select id="recordAlllistPage" parameterType="page" resultType="pd">
		select * from
		(
		select
		f.*,
		u.WORKSTATUS,
		a.STARTTIME,
		a.ENDTIME ,
		p.NAME PERIODNAME,
		t.NAME TYPENAME,
		m.NAME SCREENTYPENAME,
		d.NAME as DEPARTMENT_NAME,
		getFullName(d.DEPARTMENT_ID) as DEPARTMENT_NAME_ALL,
		sp.NAME
		AS POST_NAME,
		u.NAME as USER_NAME,
		(
		select count(1) from vi_list_checkrecord_all ch
		where ch.LISTMANAGER_ID=f.LISTMANAGER_ID AND ch.type = '1'
		and ch.FINISHED='1' and ch.ISDELETE =0
		) as count ,
		(
		select
		count(1)
		from VI_LIST_CHECKRECORD_ALL ch
		left join VI_HIDDEN_ALL h on h.CHECKRECORD_ID = ch.CHECKRECORD_ID
		where ch.LISTMANAGER_ID=f.LISTMANAGER_ID
		and ch.FINISHED='1'
		and ch.ISDELETE =0
		and h.ISDELETE =0
		and h.HIDDEN_ID is not null
		) as hiddenCount,

		(
		CASE
		WHEN f.TYPE = 'listType0005' THEN
		CONCAT( f.START_DATE, " 00:00:00" )
		WHEN f.PERIOD = 'checkPeriod0001' THEN
		(select sd.DAY_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0002' THEN
		(select sd.WEEK_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0003' THEN
		(select sd.XUN_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0004' THEN
		(select sd.MONTH_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0005' THEN
		(select sd.QUARTER_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0006' THEN
		(select sd.YEAR_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0007' THEN
		(select sd.HALFYEAR_START from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		END
		) DATESTART,
		bb.NAME AS TASK_TYPE_NAME,
		(
		CASE
		WHEN f.TYPE = 'listType0005' THEN
		CONCAT( f.END_DATE, " 23:59:59" )
		WHEN f.PERIOD = 'checkPeriod0001' THEN
		(select sd.DAY_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0002' THEN
		(select sd.WEEK_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0003' THEN
		(select sd.XUN_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0004' THEN
		(select sd.MONTH_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0005' THEN
		(select sd.QUARTER_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0006' THEN
		(select sd.YEAR_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		WHEN f.PERIOD = 'checkPeriod0007' THEN
		(select sd.HALFYEAR_END from v_sysdate sd where DATE_FORMAT( sd.`date`,'%Y-%m-%d' ) = DATE_FORMAT(now(),'%Y-%m-%d') )
		END
		) DATEEND,
		getCheckedNum(f.LISTMANAGER_ID) checkCount,
		(select count(1) from VI_LIST_CHECKRECORD_ALL cc where cc.LISTMANAGER_ID = f.LISTMANAGER_ID  and cc.FINISHED ='1' and type ='2') overTimeCount
		from
		VI_LIST_ALL f
		LEFT JOIN BUS_OFFDUTY a on f.USER_ID = a.USER_ID and a.isdelete = '0' and a.STARTTIME &lt;= date_format(now(),'%Y-%m-%d') and a.ENDTIME &gt;= date_format(now(),'%Y-%m-%d')
		left join sys_dictionaries p on f.PERIOD = p.BIANMA
		left join sys_dictionaries t on f.TYPE = t.BIANMA
		left join sys_dictionaries m on f.SCREENTYPE = m.BIANMA
		left join OA_DEPARTMENT d on d.DEPARTMENT_ID = f.DEPARTMENT_ID
		LEFT JOIN sys_dictionaries bb ON f.TASK_TYPE = bb.DICTIONARIES_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 = #{pd.CORPINFO_ID} and f.ISDELETE != '-99'
		<if test="pd.RISKCHECKLISTTYPE != null and pd.RISKCHECKLISTTYPE != ''"><!-- 状态 -->
			and f.SCREENTYPE = #{pd.RISKCHECKLISTTYPE}
		</if>
		<if test="pd.statusIds != null and pd.statusIds != ''">
			and
			(
			f.LISTMANAGER_ID in
			<foreach item="item" index="index" collection="pd.statusIds"
					 open="(" separator="," close=")">
				'${item}'
			</foreach>
			)
		</if>
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and
			(
			f.NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
			)
		</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
					f.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"'>
								<choose>
									<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
										and
										f.DEPARTMENT_ID in
										<foreach item="item" index="index"
												 collection="pd.DEPT_IDS" open="(" separator="," close=")">
											'${item}'
										</foreach>
									</when>
									<when test="pd.DEPT_ID != null and pd.DEPT_ID != ''"><!-- 关键词检索 -->
										and f.DEPARTMENT_ID = #{pd.DEPT_ID}
									</when>
									<otherwise>
										and
										((f.DEPARTMENT_ID in (
										select
										SUB_DEPARTMENT_ID
										from
										oa_supervision_department osd
										where
										osd.SUP_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
										and osd.ISDELETE = '0'
										and osd.CORPINFO_ID  = #{pd.CORPINFO_ID}
										)) or (
										f.DEPARTMENT_ID in
										<foreach item="item" index="index"
												 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
											'${item}'
										</foreach>
										))
									</otherwise>
								</choose>
							</when>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<when test="pd.DEPT_ID != null and pd.DEPT_ID != ''">
								and
								f.DEPARTMENT_ID = #{pd.DEPT_ID}
							</when>
							<otherwise>

								and
								(f.DEPARTMENT_ID in (
								select
								SUB_DEPARTMENT_ID
								from
								oa_supervision_department osd
								where
								osd.SUP_DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
								and osd.ISDELETE = '0'
								and osd.CORPINFO_ID  = #{pd.CORPINFO_ID})
								or f.USER_ID = #{pd.USER_ID})
							</otherwise>
						</choose>
					</when>

					<when test='pd.ISLEADER != null and pd.ISLEADER != "" and pd.ISLEADER == "1"'>
						<choose>
							<when test="pd.DEPT_IDS != null and pd.DEPT_IDS != ''">
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</when>
							<when test="pd.DEPT_ID != null and pd.DEPT_ID != ''">
								and
								f.DEPARTMENT_ID = #{pd.DEPT_ID}
							</when>
							<otherwise>
								and
								f.DEPARTMENT_ID in
								<foreach item="item" index="index"
										 collection="pd.DEPARTMENT_IDS" open="(" separator="," close=")">
									'${item}'
								</foreach>
							</otherwise>
						</choose>
					</when>
					<when test="pd.DEPT_ID != null and pd.DEPT_ID != ''">
						and
						f.DEPARTMENT_ID = #{pd.DEPT_ID}
					</when>
					<when test="pd.DEPARTMENT_ID != null and pd.DEPARTMENT_ID != ''">
						and f.USER_ID = #{pd.USER_ID}
						and f.DEPARTMENT_ID=#{pd.DEPARTMENT_ID}
					</when>
					<otherwise>
					</otherwise>
				</choose>
			</otherwise>
		</choose>
		<if test="pd.USERNAME != null and pd.USERNAME != ''"><!-- 关键词检索 -->
			and u.NAME LIKE CONCAT(CONCAT('%', #{pd.USERNAME}),'%')
		</if>

		<if test="pd.ISDELETE != null and pd.ISDELETE != ''"><!-- 状态 -->
			and f.ISDELETE = #{pd.ISDELETE}
		</if>

		<if test="pd.STATUS != null and pd.STATUS != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.STATUS=="1"'>
					AND getCheckedNum(f.LISTMANAGER_ID) &gt; 0
				</when>
				<when test='pd.STATUS=="0"'>
					AND getCheckedNum(f.LISTMANAGER_ID) = 0
				</when>
				<otherwise>
				</otherwise>
			</choose>
		</if>
		<if test="pd.OVERTIME != null and pd.OVERTIME != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.OVERTIME=="1"'>
					AND (select count(1) from vi_list_checkrecord_all cc where cc.LISTMANAGER_ID = f.LISTMANAGER_ID  and cc.FINISHED ='1' and type ='2') &gt; 0
				</when>
				<when test='pd.OVERTIME=="0"'>
					AND (select count(1) from vi_list_checkrecord_all cc where cc.LISTMANAGER_ID = f.LISTMANAGER_ID  and cc.FINISHED ='1' and type ='2') = 0
				</when>
				<otherwise>
				</otherwise>
			</choose>
		</if>
		<if test="pd.PERIOD != null and pd.PERIOD != ''"><!-- 关键词检索 -->
			and f.PERIOD = #{pd.PERIOD}
		</if>
		<if test="pd.TYPE != null and pd.TYPE != ''"><!-- 关键词检索 -->
			and f.TYPE = #{pd.TYPE}
		</if>
		<if test='pd.WORKSTATUS == "0"'>
			and (
			(a.STARTTIME is null or a.ENDTIME is null)
			or (to_days(a.STARTTIME) &lt; to_days(NOW()) and to_days(a.ENDTIME) &gt; to_days(NOW()))
			AND u.WORKSTATUS != '2'
			)
		</if>
		<if test='pd.WORKSTATUS == "1"'>
			and !(
			(a.STARTTIME is null or a.ENDTIME is null)
			or (to_days(a.STARTTIME) &lt; to_days(NOW()) and to_days(a.ENDTIME) &gt; to_days(NOW()))
			or u.WORKSTATUS = '2'
			)
		</if>
		<if test="pd.LISTINGLEVEL != null and pd.LISTINGLEVEL != ''"><!-- 关键词检索 -->
			<choose>
				<when test='pd.LISTINGLEVEL == "1"'>
					and d.LEVEL = ''
				</when>
				<otherwise>
					and d.LEVEL = #{pd.LISTINGLEVEL}
				</otherwise>
			</choose>
		</if>
		<if test="(pd.STARTTIME != null and pd.STARTTIME != '') or (pd.ENDTIME != null and pd.ENDTIME != '')"><!-- 关键词检索 -->
			<choose>
				<when
						test="pd.STARTTIME != null and pd.STARTTIME != '' and pd.ENDTIME != null and pd.ENDTIME != ''">
					and f.LISTMANAGER_ID in
					(
					SELECT LISTMANAGER_ID
					FROM VI_LIST_CHECKRECORD_ALL
					WHERE FINISHED = '1'
					AND ISDELETE = 0
					and DATE_FORMAT(CHECK_TIME,'%Y-%m-%d %H:%i:%s') &gt;= #{pd.STARTTIME}
					and DATE_FORMAT(CHECK_TIME,'%Y-%m-%d %H:%i:%s') &lt;= #{pd.ENDTIME}
					)
				</when>
				<when test="pd.STARTTIME != null and pd.STARTTIME != ''">
					and f.LISTMANAGER_ID in
					(
					SELECT LISTMANAGER_ID
					FROM VI_LIST_CHECKRECORD_ALL
					WHERE FINISHED = '1'
					AND ISDELETE = 0
					and DATE_FORMAT(CHECK_TIME,'%Y-%m-%d %H:%i:%s') &gt;= #{pd.STARTTIME}
					)
				</when>
				<when test="pd.ENDTIME != null and pd.ENDTIME != ''">
					and f.LISTMANAGER_ID in
					(
					SELECT LISTMANAGER_ID
					FROM VI_LIST_CHECKRECORD_ALL
					WHERE FINISHED = '1'
					AND ISDELETE = 0
					and DATE_FORMAT(CHECK_TIME,'%Y-%m-%d %H:%i:%s') &lt;= #{pd.ENDTIME}
					)
				</when>
			</choose>

		</if>
		) f
		where 1= 1
		<if test="pd.HASHIDDEN != null and pd.HASHIDDEN != ''"><!-- 关键词检索 -->
			<choose>
				<when test="pd.HASHIDDEN == 0">
					and f.hiddenCount = 0
				</when>
				<when test="pd.HASHIDDEN == 1">
					and f.hiddenCount > 0
				</when>
			</choose>
		</if>
		<if test="pd.LIST_TYPE != null and pd.LIST_TYPE != ''"><!-- 关键词检索 -->
			and f.LIST_TYPE = #{pd.LIST_TYPE}
		</if>
		group by f.LISTMANAGER_ID
		order by field(f.ISDELETE,'0','1','2','-1')	,f.OPERATTIME desc
	</select>

	<!-- 获取日常检查列表 -->
	<select id="getDailyInspectionList" parameterType="pd" resultType="pd">
		( SELECT
		*
		FROM
		(
		SELECT
		f.LISTMANAGER_ID,
		f.NAME,
		f.OPERATTIME,
		f.ISDELETE,
		f.DEPARTMENT_ID,
		f.POST_ID,
		f.USER_ID,
		"1" AS list_type,
		getCheckedNum ( f.LISTMANAGER_ID ) checkCount
		FROM
		BUS_LISTMANAGER f
		LEFT JOIN BUS_OFFDUTY a ON f.USER_ID = a.USER_ID
		AND a.isdelete = '0'
		AND a.STARTTIME &lt;= date_format( now(), '%Y-%m-%d' ) AND a.ENDTIME &gt;= date_format( now(), '%Y-%m-%d' )
		LEFT JOIN sys_dictionaries p ON f.PERIOD = p.BIANMA
		LEFT JOIN sys_dictionaries t ON f.TYPE = t.BIANMA
		LEFT JOIN sys_dictionaries m ON f.SCREENTYPE = m.BIANMA
		LEFT JOIN OA_DEPARTMENT d ON d.DEPARTMENT_ID = f.DEPARTMENT_ID
		LEFT JOIN sys_dictionaries bb ON f.TASK_TYPE = bb.DICTIONARIES_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 != '-99'
		and f.PERIOD = #{PERIOD}
		) f
		GROUP BY
		f.LISTMANAGER_ID
		ORDER BY
		field( f.ISDELETE, '0', '1', '2', '-1' ),
		f.OPERATTIME DESC
		) UNION
		(
		SELECT
		*
		FROM
		(
		SELECT
		f.CUSTOM_ID,
		f.NAME,
		f.OPERATTIME,
		f.ISDELETE,
		f.DEPARTMENT_ID,
		f.POST_ID,
		f.USER_ID,
		"2" AS list_type,
		getStandardCheckedNum ( f.CUSTOM_ID ) checkCount
		FROM
		bus_hiddendangercheckstandard_custom f
		LEFT JOIN BUS_OFFDUTY a ON f.USER_ID = a.USER_ID
		AND a.isdelete = '0'
		AND a.STARTTIME &lt;= date_format( now(), '%Y-%m-%d' ) AND a.ENDTIME &gt;= date_format( now(), '%Y-%m-%d' )
		LEFT JOIN sys_dictionaries p ON f.PERIOD = p.BIANMA
		LEFT JOIN sys_dictionaries t ON f.TYPE = t.BIANMA
		LEFT JOIN sys_dictionaries m ON f.SCREENTYPE = m.BIANMA
		LEFT JOIN OA_DEPARTMENT d ON d.DEPARTMENT_ID = f.DEPARTMENT_ID
		LEFT JOIN sys_dictionaries bb ON f.TASK_TYPE = bb.DICTIONARIES_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 != '-99'
		and f.PERIOD = #{PERIOD}
		) f
		GROUP BY
		f.CUSTOM_ID
		ORDER BY
		field( f.ISDELETE, '0', '1', '2', '-1' ),
		f.OPERATTIME DESC )
	</select>
    <select id="checkListCount" resultType="com.zcloud.entity.PageData">
		SELECT
			COUNT( 1 ) listCount,
			( SELECT COUNT( 1 ) customCount FROM BUS_HIDDENDANGERCHECKSTANDARD_CUSTOM f WHERE f.CORPINFO_ID = #{CORPINFO_ID} AND f.ISDELETE = 0 ) customCount,
			(
				SELECT
					COUNT( f.CHECKRECORD_ID ) listCheckCount
				FROM
				bus_listmanager l
				LEFT JOIN bus_checkrecord f ON l.LISTMANAGER_ID = f.LISTMANAGER_ID
				WHERE f.CORPINFO_ID = #{CORPINFO_ID} AND f.FINISHED = 1 AND f.TYPE = 1 AND f.ISDELETE = 0 and l.ISDELETE = 0
			) listCheckCount,
			(
				SELECT
					COUNT( 1 )
				FROM
					BUS_HIDDENDANGERCHECKSTANDARD_CUSTOM c LEFT JOIN
					bus_hiddendangercheckstandard_checkrecord f on c.CUSTOM_ID = f.CUSTOM_ID
				WHERE
					f.CORPINFO_ID = #{CORPINFO_ID}
				  AND f.FINISHED = 1
				  AND f.TYPE = 1
				  AND f.ISDELETE = 0
				  AND c.ISDELETE = 0
			) customCheckCount
		FROM
			bus_listmanager f
		WHERE
			f.CORPINFO_ID = #{CORPINFO_ID}
		  AND f.ISDELETE = 0
	</select>
    <select id="checkListCountByPeriod" resultType="com.zcloud.entity.PageData">
		SELECT
			GROUP_CONCAT( NAME ORDER BY px ) nameTypeList,
			GROUP_CONCAT( PERIOD_COUNT ORDER BY px ) periodList
		FROM
			(
				SELECT
					d.`NAME`,
					d.ORDER_BY as px,
					d.PARENT_ID,
					IFNULL( L.PERIOD_COUNT, 0 ) + IFNULL( c.c_PERIOD_COUNT, 0 ) PERIOD_COUNT
				FROM
					sys_dictionaries d
						LEFT JOIN (
						SELECT
							count( 1 ) PERIOD_COUNT,
							l.PERIOD
						FROM
							bus_listmanager l
						WHERE
							l.ISDELETE = 0
						  AND l.CORPINFO_ID = #{CORPINFO_ID}
						GROUP BY
							l.`PERIOD`
					) l ON l.PERIOD = d.`BIANMA`
						LEFT JOIN (
						SELECT
							COUNT( 1 ) C_PERIOD_COUNT,
							PERIOD
						FROM
							bus_hiddendangercheckstandard_custom c
						WHERE
							c.ISDELETE = 0
						  AND c.CORPINFO_ID = #{CORPINFO_ID}
						GROUP BY
							c.PERIOD
					) c ON c.PERIOD = d.BIANMA
				WHERE
					d.PARENT_ID = 'f60cf0e8315b4993b6d6049dd29f2ba5'
				ORDER BY
					d.ORDER_BY
			) t
		GROUP BY
			t.PARENT_ID
	</select>
	<select id="goIndexCount2" resultType="com.zcloud.entity.PageData">
		SELECT
			d.`NAME`,
			d.DEPARTMENT_ID,
			GROUP_CONCAT( DISTINCT l.LISTMANAGER_ID ) LISTMANAGER_IDS,
			GROUP_CONCAT( DISTINCT c.CUSTOM_ID ) CUSTOM_IDS,
			getCheckedNumByIds (
					GROUP_CONCAT( DISTINCT l.LISTMANAGER_ID )) LISTMANAGER_CHECKCOUNT,
			getStandardCheckedNumByids (
					GROUP_CONCAT( DISTINCT c.CUSTOM_ID )) CUSTOM_CHECKCOUNT,
			COUNT( DISTINCT l.LISTMANAGER_ID ) LCOUNT,
			COUNT( DISTINCT c.CUSTOM_ID ) CCOUNT,
			getCheckedListNumByIds (
					GROUP_CONCAT( DISTINCT l.LISTMANAGER_ID ))+ getStandardCheckedListNumByids (
					GROUP_CONCAT( DISTINCT c.CUSTOM_ID )) CHECK_COUNT,
			COUNT( DISTINCT l.LISTMANAGER_ID ) + COUNT( DISTINCT c.CUSTOM_ID ) LIST_CUSTOM_COUNT
		FROM
			oa_department d
				LEFT JOIN bus_listmanager l ON d.DEPARTMENT_ID = l.DEPARTMENT_ID
				AND l.ISDELETE = 0
				AND l.PERIOD = #{type}
				LEFT JOIN bus_hiddendangercheckstandard_custom c ON d.DEPARTMENT_ID = c.DEPARTMENT_ID
				AND c.ISDELETE = 0
				AND c.PERIOD = #{type}
		WHERE
			d.CORPINFO_ID = #{CORPINFO_ID}
		GROUP BY
			d.DEPARTMENT_ID
	</select>
</mapper>
