<?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.risk.RiskPointAnalysisMapper">

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.RISKPOINT_ID,
		f.HIDDEN_ID,
		f.RISK_UNIT_ID,
		f.CORPINFO_ID,
		f.IDENTIFICATION_ID,
		f.RISK_DESCR,
		f.RISK_POSITION_ID,
		f.LEVELID,
		f.MEASURES,
		f.ACCIDENTS,
		f.ACCIDENTS_NAME,
		f.EME_MEASURES,
		f.DEPARTMENT_ID,
		f.USER_ID,
		f.ISDELETE,
		f.CREATOR,
		f.CREATTIME,
		f.OPERATOR,
		f.OPERATTIME,
		f.LONGITUDE,
		f.LATITUDE,
		f.RISKPOINT_ANALYSIS_ID,
		f.SORT,
		f.LIKELIHOOD,
		f.EXPOSURE,
		f.CONSEQUENCE,
		f.DANGER,
		f.STATUS,
		f.IS_NEW
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		RISKPOINT_ID,
		HIDDEN_ID,
		RISK_UNIT_ID,
		CORPINFO_ID,
		IDENTIFICATION_ID,
		RISK_DESCR,
		RISK_POSITION_ID,
		LEVELID,
		MEASURES,
		ACCIDENTS,
		ACCIDENTS_NAME,
		EME_MEASURES,
		DEPARTMENT_ID,
		USER_ID,
		ISDELETE,
		CREATOR,
		CREATTIME,
		OPERATOR,
		OPERATTIME,
		LONGITUDE,
		LATITUDE,
		RISKPOINT_ANALYSIS_ID,
		SORT,
		LIKELIHOOD,
		EXPOSURE,
		CONSEQUENCE,
		DANGER,
		STATUS,
		IS_NEW
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{RISKPOINT_ID},
		#{HIDDEN_ID},
		#{RISK_UNIT_ID},
		#{CORPINFO_ID},
		#{IDENTIFICATION_ID},
		#{RISK_DESCR},
		#{RISK_POSITION_ID},
		#{LEVELID},
		#{MEASURES},
		#{ACCIDENTS},
		#{ACCIDENTS_NAME},
		#{EME_MEASURES},
		#{DEPARTMENT_ID},
		#{USER_ID},
		#{ISDELETE},
		#{CREATOR},
		#{CREATTIME},
		#{OPERATOR},
		#{OPERATTIME},
		#{LONGITUDE},
		#{LATITUDE},
		#{RISKPOINT_ANALYSIS_ID},
		#{SORT},
		#{LIKELIHOOD},
		#{EXPOSURE},
		#{CONSEQUENCE},
		#{DANGER},
		#{STATUS},
		#{IS_NEW}
	</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">
		delete from
		<include refid="tableName"></include>
		where
			RISKPOINT_ANALYSIS_ID = #{RISKPOINT_ANALYSIS_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			RISKPOINT_ID = #{RISKPOINT_ID},
			HIDDEN_ID = #{HIDDEN_ID},
			RISK_UNIT_ID = #{RISK_UNIT_ID},
			IDENTIFICATION_ID = #{IDENTIFICATION_ID},
			RISK_DESCR = #{RISK_DESCR},
			RISK_POSITION_ID = #{RISK_POSITION_ID},
			LEVELID = #{LEVELID},
			MEASURES = #{MEASURES},
			ACCIDENTS = #{ACCIDENTS},
			ACCIDENTS_NAME=#{ACCIDENTS_NAME},
			EME_MEASURES = #{EME_MEASURES},
			DEPARTMENT_ID = #{DEPARTMENT_ID},
			USER_ID = #{USER_ID},
			LONGITUDE = #{LONGITUDE},
			LATITUDE = #{LATITUDE},
			LIKELIHOOD = #{LIKELIHOOD},
			EXPOSURE = #{EXPOSURE},
			CONSEQUENCE = #{CONSEQUENCE},
			DANGER = #{DANGER},
			STATUS = #{STATUS},
			RISKPOINT_ANALYSIS_ID = RISKPOINT_ANALYSIS_ID
		where
			RISKPOINT_ANALYSIS_ID = #{RISKPOINT_ANALYSIS_ID}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
			d5.BIANMA BIANMA5,
			d5.NAME DNAME5,
		<include refid="Field"></include>,
			un.RISKUNITNAME,
			po.POSITIONNAME,
			id.PARTSNAME,
			de.NAME as DEPT_NAME,
			u.NAME as USER_NAME
		from
		<include refid="tableName"></include> f
			left join
			<include refid="dicTableName"></include> d5
			on f.LEVELID = d5.BIANMA
			left join bus_riskunit un on un.RISKUNIT_ID = f.RISK_UNIT_ID and un.ISDELETE = '0'
			left join bus_riskpointposition po on po.RISKPOINTPOSITION_ID = f.RISK_POSITION_ID and po.ISDELETE = '0'
			left join bus_identificationparts id on id.IDENTIFICATIONPARTS_ID = f.IDENTIFICATION_ID and id.ISDELETE = '0'
			left join OA_DEPARTMENT de on de.DEPARTMENT_ID = f.DEPARTMENT_ID
			left join SYS_USER u on u.USER_ID = f.USER_ID
		where
			f.RISKPOINT_ANALYSIS_ID = #{RISKPOINT_ANALYSIS_ID}
	</select>

	<!-- 通过ID获取数据 -->
	<select id="findRiskById" parameterType="pd" resultType="pd">
		select
			d5.BIANMA BIANMA5,
			d5.NAME DNAME5,
		<include refid="Field"></include>,
			un.RISKUNITNAME,
			po.POSITIONNAME,
			id.PARTSNAME,
			de.NAME as DEPT_NAME,
			u.NAME as USER_NAME
		from
		<include refid="tableName"></include> f
			left join
			<include refid="dicTableName"></include> d5
			on f.LEVELID = d5.BIANMA
			left join bus_riskunit un on un.RISKUNIT_ID = f.RISK_UNIT_ID and un.ISDELETE = '0'
			left join bus_riskpointposition po on po.RISKPOINTPOSITION_ID = f.RISK_POSITION_ID and po.ISDELETE = '0'
			left join bus_identificationparts id on id.IDENTIFICATIONPARTS_ID = f.IDENTIFICATION_ID and id.ISDELETE = '0'
			left join OA_DEPARTMENT de on de.DEPARTMENT_ID = f.DEPARTMENT_ID
			left join SYS_USER u on u.USER_ID = f.USER_ID
		where
			f.RISKPOINT_ANALYSIS_ID = #{RISKPOINT_ANALYSIS_ID}
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
			d5.BIANMA BIANMA5,
			d5.NAME DNAME5,
		<include refid="Field"></include>,
		un.RISKUNITNAME,
		po.POSITIONNAME,
		id.PARTSNAME,
		de.NAME as DEPT_NAME,
		getFullName(de.DEPARTMENT_ID) as DEPT_NAME_ALL,
		u.NAME as USER_NAME
		from
		<include refid="tableName"></include> f
			left join
			<include refid="dicTableName"></include> d5
			on f.LEVELID = d5.BIANMA
			left join bus_riskunit un on un.RISKUNIT_ID = f.RISK_UNIT_ID and un.ISDELETE = '0'
			left join bus_riskpointposition po on po.RISKPOINTPOSITION_ID = f.RISK_POSITION_ID and po.ISDELETE = '0'
			left join bus_identificationparts id on id.IDENTIFICATIONPARTS_ID = f.IDENTIFICATION_ID and id.ISDELETE = '0'
			left join OA_DEPARTMENT de on de.DEPARTMENT_ID = f.DEPARTMENT_ID
			left join SYS_USER u on u.USER_ID = f.USER_ID
		where f.ISDELETE = '0' and f.CORPINFO_ID = #{pd.CORPINFO_ID}
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and
				(
					un.RISKUNITNAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
					 or
					id.PARTSNAME 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.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}
								)
				            </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.LEVELID != null and pd.LEVELID != ''">
			and
					f.LEVELID=#{pd.LEVELID}
		</if>
		<if test="pd.FIND_USER_ID != null and pd.FIND_USER_ID != ''">
			and
					f.USER_ID=#{pd.FIND_USER_ID}
		</if>
<!-- 		<if test="pd.DEPARTMENT_ID != null and pd.DEPARTMENT_ID != ''">
			and
					f.DEPARTMENT_ID=#{pd.DEPARTMENT_ID}
		</if> -->
		<if test="pd.RISK_UNIT_ID != null and pd.RISK_UNIT_ID != ''">
			and
					f.RISK_UNIT_ID=#{pd.RISK_UNIT_ID}
		</if>
<!--		<if test="pd.BIANMA != null and pd.BIANMA != ''">-->
<!--			and FIND_IN_SET(#{pd.BIANMA}, f.ACCIDENTS)-->
<!--		</if>-->
		<if test="pd.BIANMA_S != null and pd.BIANMA_S != ''">
			and
			<foreach item="item" index="index"
					 collection="pd.BIANMA_S" open="(" separator=" or " close=")">
				FIND_IN_SET('${item}', f.ACCIDENTS)
			</foreach>
		</if>
		<if test="pd.gkzrName != null and pd.gkzrName != ''">
			and 	f.USER_ID LIKE CONCAT(CONCAT('%', #{pd.gkzrName}),'%')
		</if>
		<if test="pd.STATUS != null and pd.STATUS != ''">
			and 	f.STATUS = #{pd.STATUS}
		</if>
		order by f.OPERATTIME desc ,f.SORT asc,RISKUNITNAME desc ,PARTSNAME desc
	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>,
		un.RISKUNITNAME,
		id.PARTSNAME
		from
		<include refid="tableName"></include> f
		left join bus_riskunit un on un.RISKUNIT_ID = f.RISK_UNIT_ID
		left join bus_identificationparts id on id.IDENTIFICATIONPARTS_ID = f.IDENTIFICATION_ID
		where f.ISDELETE = '0'
		<if test="CHECK_IDENTIFICATION_ID != null and CHECK_IDENTIFICATION_ID != ''">
		 	 and f.IDENTIFICATION_ID=#{CHECK_IDENTIFICATION_ID}
	 	</if>
	</select>

	<!-- 查询所有（资源库配置使用） -->
	<select id="listAllToRes" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>,
		un.RISKUNITNAME,
		id.PARTSNAME,
		l.NAME LEVELIDNAME
		from
		<include refid="tableName"></include> f
		left join bus_riskunit un on un.RISKUNIT_ID = f.RISK_UNIT_ID
		left join bus_identificationparts id on id.IDENTIFICATIONPARTS_ID = f.IDENTIFICATION_ID
		LEFT JOIN sys_dictionaries l ON l.BIANMA = f.LEVELID AND l.YNDEL = 'NO'
		where f.ISDELETE = '0'
		<if test="CHECK_IDENTIFICATION_ID != null and CHECK_IDENTIFICATION_ID != ''">
		 	 and f.IDENTIFICATION_ID=#{CHECK_IDENTIFICATION_ID}
	 	</if>

		<if test="rptIds != null and rptIds != ''">
			and f.RISKPOINT_ANALYSIS_ID not in
			<foreach item="item" index="index" collection="rptIds" open="(" separator="," close=")">
	                 #{item}
			</foreach>
		</if>
	</select>


	<select id="listAllByDc" parameterType="pd" resultType="pd">
		select b.*
		,(select RISKUNITNAME from bus_riskunit where r.RISK_UNIT_ID=RISKUNIT_ID) as RISKUNITNAME
		,(select PARTSNAME from bus_identificationparts where r.IDENTIFICATION_ID=IDENTIFICATIONPARTS_ID) as PARTSNAME
		,r.RISK_DESCR
		,r.RISK_POSITION_ID
		,(select NAME from SYS_DICTIONARIES where r.LEVELID=BIANMA) as LEVELID
		,r.MEASURES
		,r.ACCIDENTS
		,r.EME_MEASURES
		,(select NAME from oa_department where r.DEPARTMENT_ID=DEPARTMENT_ID) as DEPARTMENT_ID
		,r.USER_ID USER_ID
		,(select CORP_NAME from bus_corp_info where r.CORPINFO_ID=CORPINFO_ID) as CORP_NAME
		,r.LONGITUDE
		,r.LATITUDE
		,r.ACCIDENTS_NAME
		 from bus_risk_check_item b LEFT JOIN bus_riskpoint r on b.RISKPOINT_ANALYSIS_ID=r.RISKPOINT_ANALYSIS_ID where r.ISDELETE='0'
		 	<if test="CORPINFO_ID != null and CORPINFO_ID != ''">
		 	 and r.CORPINFO_ID=#{CORPINFO_ID}
		 	</if>
		   order by RISKUNITNAME,r.RISKPOINT_ANALYSIS_ID
	</select>
	<!-- 批量删除 -->
	<delete id="deleteAll" parameterType="String">
		update
		<include refid="tableName"></include>
		set
			ISDELETE = '1'
		where
			RISKPOINT_ANALYSIS_ID in
		<foreach item="item" index="index" collection="array" open="(" separator="," close=")">
                 #{item}
		</foreach>
	</delete>

	<!-- 总数统计 -->
	<select id="statisticsAll" parameterType="pd" resultType="pd">
        SELECT
				t.LEVELID,
				count(1) as COUNT
			FROM
				BUS_RISKPOINT t
			WHERE
				  t.CORPINFO_ID=#{CORPINFO_ID} and t.ISDELETE='0'
			  <if test="DEPARTMENT_IDS != null and DEPARTMENT_IDS != ''"><!-- 关键词检索 -->
				and
					(
						t.DEPARTMENT_ID in
						<foreach item="item" index="index" collection="DEPARTMENT_IDS" open="(" separator="," close=")">
				                 #{item}
						</foreach>
						or t.USER_ID = #{USER_ID}
					)
			</if>
			GROUP BY
				t.LEVELID
   	</select>

	<!-- 列表 -->
	<select id="datalistPageForNameLikes" parameterType="page" resultType="pd">
		select
			d5.BIANMA BIANMA5,
			d5.NAME DNAME5,
		<include refid="Field"></include>,
		un.RISKUNITNAME,
		po.POSITIONNAME,
		id.PARTSNAME,
		de.NAME as DEPT_NAME,
		u.NAME as USER_NAME
		from
		<include refid="tableName"></include> f
			left join
			<include refid="dicTableName"></include> d5
			on f.LEVELID = d5.BIANMA

			left join bus_riskunit un on un.RISKUNIT_ID = f.RISK_UNIT_ID and un.ISDELETE = '0'
			left join bus_riskpointposition po on po.RISKPOINTPOSITION_ID = f.RISK_POSITION_ID and po.ISDELETE = '0'
			left join bus_identificationparts id on id.IDENTIFICATIONPARTS_ID = f.IDENTIFICATION_ID and id.ISDELETE = '0'
			left join OA_DEPARTMENT de on de.DEPARTMENT_ID = f.DEPARTMENT_ID
			left join SYS_USER u on u.USER_ID = f.USER_ID
		where f.ISDELETE = '0' and f.CORPINFO_ID = #{pd.CORPINFO_ID}
		<if test="pd.NameLiskes != null and pd.NameLiskes != ''"><!-- 关键词检索 -->
			and
				(
					f.ACCIDENTS_NAME LIKE CONCAT(CONCAT('%', #{pd.NameLiskes}),'%')
 					 or
					id.PARTSNAME  LIKE CONCAT(CONCAT('%', #{pd.NameLiskes}),'%')
					or
					f.RISK_DESCR LIKE CONCAT(CONCAT('%', #{pd.NameLiskes}),'%')
				)
		</if>
		<if test="pd.RISK_UNIT_ID != null and pd.RISK_UNIT_ID != ''">
			and
					f.RISK_UNIT_ID=#{pd.RISK_UNIT_ID}
		</if>
		order by f.OPERATTIME desc
	</select>
	<!-- 修改 -->
	<update id="editLonAndLat" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			LONGITUDE = #{LONGITUDE},
			LATITUDE = #{LATITUDE}
		where
			RISKPOINT_ANALYSIS_ID = #{RISKPOINT_ANALYSIS_ID}
	</update>
	<!-- 总数统计 -->
	<select id="countByCorpInfo" parameterType="pd" resultType="String">
        SELECT
				count(1) as count
			FROM
				BUS_RISKPOINT t
			WHERE
				  t.CORPINFO_ID=#{CORPINFO_ID}
   	</select>

	<!-- 绩效得分 -->
	<select id="getDeptExamine" parameterType="pd" resultType="pd" >
		SELECT
			count(1) as count,
			r.DEPARTMENT_ID
		FROM
			BUS_RISKPOINT_ANALYSIS r
		where
			r.OPERATTIME LIKE CONCAT(CONCAT('%', #{MONTH}),'%')
			AND r.STATUS = 1
		group by r.DEPARTMENT_ID
	</select>

	<select id="getUserExamine" parameterType="pd" resultType="pd" >
		SELECT
			count(1) as count,
			r.CREATOR
		FROM
			BUS_RISKPOINT_ANALYSIS r
		where
			r.OPERATTIME LIKE CONCAT(CONCAT('%', #{MONTH}),'%')
			AND r.STATUS = 1
		group by r.CREATOR
	</select>

	<select id="statisticsBI" parameterType="pd" resultType="pd" >
		select
		d.NAME,count(r.RISKPOINT_ANALYSIS_ID) as count
		from sys_dictionaries d
		left join bus_riskpoint_analysis r on d.BIANMA = r.LEVELID and r.CORPINFO_ID = #{CORPINFO_ID}
		where d.PARENT_ID = '5a81e63ec0e94d919b3138bc01dbef6b'
		group by d.BIANMA
		order by d.BIANMA desc
	</select>

    <select id="formlistPage" resultType="com.zcloud.entity.PageData">
		select
		un.RISKUNITNAME,
		po.POSITIONNAME,
		id.PARTSNAME,
		rp.RISK_CAUSES,
		dn.NAME as RISK_CAUSES_CNAME,
		rp.RISKPOINT_ID,
		f.RISKPOINT_ANALYSIS_ID,
		f.RISK_DESCR,
		d5.NAME as LEVEL_NAME,
		f.MEASURES,
		f.ACCIDENTS_NAME,
		de.NAME as DEPT_NAME_ALL,
		u.NAME as DEPT_USER_NAME,
		f.USER_ID,
		f.CREATTIME,
		cu.NAME as CREATOR_NAME,
		rpsu.NAME as INSPECTOR_NAME
		from
		<include refid="tableName"></include> f
		left join sys_dictionaries d5 on f.LEVELID = d5.BIANMA
		left join bus_hidden h on f.HIDDEN_ID = h.HIDDEN_ID
		left join bus_riskunit un on un.RISKUNIT_ID = f.RISK_UNIT_ID and un.ISDELETE = '0'
		left join bus_riskpoint rp on rp.RISKPOINT_ID = f.RISKPOINT_ID and rp.ISDELETE = '0'
		left join SYS_USER rpsu on rpsu.USERNAME = rp.OPERATOR
		left join sys_dictionaries dn on dn.DICTIONARIES_ID = rp.RISK_CAUSES
		left join bus_riskpointposition po on po.RISKPOINTPOSITION_ID = f.RISK_POSITION_ID and po.ISDELETE = '0'
		left join bus_identificationparts id on id.IDENTIFICATIONPARTS_ID = f.IDENTIFICATION_ID and id.ISDELETE = '0'
		left join OA_DEPARTMENT de on de.DEPARTMENT_ID = f.DEPARTMENT_ID
		left join SYS_USER u on u.USER_ID = f.USER_ID
		left join SYS_USER cu on cu.USER_ID = f.CREATOR
		where f.ISDELETE = '0' and f.CORPINFO_ID = #{pd.CORPINFO_ID}
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and
			(
			un.RISKUNITNAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
			or
			id.PARTSNAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
			or
			rp.RISKPOINT_ID = #{pd.KEYWORDS}
			or
			f.RISKPOINT_ANALYSIS_ID = #{pd.KEYWORDS}
			or
			f.HIDDEN_ID = #{pd.KEYWORDS}
			)
		</if>
		<if test="pd.LEVELID != null and pd.LEVELID != ''">
			and f.LEVELID=#{pd.LEVELID}
		</if>
		<if test="pd.RISK_UNIT_ID != null and pd.RISK_UNIT_ID != ''">
			and f.RISK_UNIT_ID=#{pd.RISK_UNIT_ID}
		</if>
		<if test="pd.IDENTIFICATION_ID != null and pd.IDENTIFICATION_ID != ''">
			and f.IDENTIFICATION_ID=#{pd.IDENTIFICATION_ID}
		</if>
		<if test="pd.BIANMA != null and pd.BIANMA != ''">
			and FIND_IN_SET(#{pd.BIANMA}, f.ACCIDENTS)
		</if>
		<if test="pd.STATUS != null and pd.STATUS != ''">
			and f.STATUS = #{pd.STATUS}
		</if>
		<if test="pd.START_TIME != '' and pd.START_TIME != null">
			and STR_TO_DATE(f.CREATTIME,"%Y-%m-%d %h:%i:%s") &gt; STR_TO_DATE(#{pd.START_TIME},"%Y-%m-%d %h:%i:%s")
		</if>
		<if test="pd.START_TIME != '' and pd.START_TIME != null">
			and STR_TO_DATE(#{pd.END_TIME},"%Y-%m-%d %h:%i:%s") &gt; STR_TO_DATE(f.CREATTIME,"%Y-%m-%d %h:%i:%s")
		</if>
		order by f.OPERATTIME desc ,f.SORT asc,RISKUNITNAME desc ,PARTSNAME desc
	</select>

	<select id="getDto" resultType="com.zcloud.entity.PageData">
		select
		d5.BIANMA BIANMA5,
		d5.NAME DNAME5,
		<include refid="Field"></include>,
		un.RISKUNITNAME,
		po.POSITIONNAME,
		id.PARTSNAME,
		de.NAME as DEPT_NAME,
		getFullName(de.DEPARTMENT_ID) as DEPT_NAME_ALL,
		u.NAME as USER_NAME,
		sd.NAME as RISK_CAUSES
		from
		<include refid="tableName"></include> f
		left join
		<include refid="dicTableName"></include> d5
		on f.LEVELID = d5.BIANMA
		left join bus_riskunit un on un.RISKUNIT_ID = f.RISK_UNIT_ID and un.ISDELETE = '0'
		left join bus_riskpointposition po on po.RISKPOINTPOSITION_ID = f.RISK_POSITION_ID and po.ISDELETE = '0'
		left join bus_riskpoint rp on rp.RISKPOINT_ID = f.RISKPOINT_ID and rp.ISDELETE = '0'
		left join bus_identificationparts id on id.IDENTIFICATIONPARTS_ID = f.IDENTIFICATION_ID and id.ISDELETE = '0'
		left join OA_DEPARTMENT de on de.DEPARTMENT_ID = f.DEPARTMENT_ID
		left join SYS_USER u on u.USER_ID = f.USER_ID
		left join sys_dictionaries sd on rp.RISK_CAUSES = sd.DICTIONARIES_ID
		where f.ISDELETE = '0' and f.RISKPOINT_ANALYSIS_ID = #{RISKPOINT_ANALYSIS_ID}
	</select>

	<select id="formList" resultType="com.zcloud.entity.PageData">
		select
		un.RISKUNITNAME,
		po.POSITIONNAME,
		id.PARTSNAME,
		rp.RISK_CAUSES,
		rp.RISKPOINT_ID,
		f.RISKPOINT_ANALYSIS_ID,
		f.RISK_DESCR,
		dn.NAME as RISK_CAUSES_CNAME,
		d5.NAME as LEVEL_NAME,
		f.MEASURES,
		f.ACCIDENTS_NAME,
		de.NAME as DEPT_NAME_ALL,
		u.NAME as DEPT_USER_NAME,
		f.CREATTIME,
		cu.NAME as CREATOR_NAME,
		rp.CREATOR as INSPECTOR_NAME
		from
		<include refid="tableName"></include> f
		left join sys_dictionaries d5 on f.LEVELID = d5.BIANMA
		left join bus_hidden h on f.HIDDEN_ID = h.HIDDEN_ID
		left join bus_riskunit un on un.RISKUNIT_ID = f.RISK_UNIT_ID and un.ISDELETE = '0'
		left join bus_riskpoint rp on rp.RISKPOINT_ID = f.RISKPOINT_ID and rp.ISDELETE = '0'
		left join bus_riskpointposition po on po.RISKPOINTPOSITION_ID = f.RISK_POSITION_ID and po.ISDELETE = '0'
		left join bus_identificationparts id on id.IDENTIFICATIONPARTS_ID = f.IDENTIFICATION_ID and id.ISDELETE = '0'
		left join OA_DEPARTMENT de on de.DEPARTMENT_ID = f.DEPARTMENT_ID
		left join SYS_USER u on u.USER_ID = f.USER_ID
		left join SYS_USER cu on cu.USER_ID = f.CREATOR
		left join sys_dictionaries dn on dn.DICTIONARIES_ID = rp.RISK_CAUSES
		where f.ISDELETE = '0' and f.CORPINFO_ID = #{CORPINFO_ID}
		<if test="STATUS != null and STATUS != ''">
			and f.STATUS = #{STATUS}
		</if>
		<if test="START_TIME != '' and START_TIME != null">
			and f.CREATTIME &gt; #{START_TIME}
		</if>
		<if test="END_TIME != '' and END_TIME != null">
			and #{END_TIME} &gt; f.CREATTIME
		</if>
		order by f.OPERATTIME desc ,f.SORT asc,RISKUNITNAME desc ,PARTSNAME desc
	</select>
</mapper>
