<?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.dsno2.depository.HiddenLibraryMapper">

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.INDUSTRY_TYPE_ONE,
		f.INDUSTRY_TYPE_TWO,
		f.INDUSTRY_TYPE_THREE,
		f.INDUSTRY_TYPE_FOUR,
		f.HIDDEN_TYPES,
		f.RISK_UNIT_ID,
		f.RISK_UNIT_NAME,
		f.HIDDEN_PART,
		f.HIDDEN_DESCR,
		f.CREATOR_ID,
		f.CREATOR_NAME,
		f.CREATED_TIME,
		f.OPERATOR_ID,
		f.OPERATOR_NAME,
		f.OPERATE_TIME,
		f.INSPECTION_BASIS,
		f.INSPECTION_INFO,
		f.RECTIFYDESCR,
		f.CORP_INFO_ID,
		f.ISDELETE,
		f.STATUS,
		f.HIDDEN_LIBRARY_ID,
		f.SOURCE,
		f.HIDDEN_TYPE_ONE,
		f.HIDDEN_TYPE_TWO,
		f.HIDDEN_TYPE_THREE
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		INDUSTRY_TYPE_ONE,
		INDUSTRY_TYPE_TWO,
		INDUSTRY_TYPE_THREE,
		INDUSTRY_TYPE_FOUR,
		HIDDEN_TYPES,
		RISK_UNIT_ID,
		RISK_UNIT_NAME,
		HIDDEN_PART,
		HIDDEN_DESCR,
		CREATOR_ID,
		CREATOR_NAME,
		CREATED_TIME,
		OPERATOR_ID,
		OPERATOR_NAME,
		OPERATE_TIME,
		INSPECTION_BASIS,
		INSPECTION_INFO,
        RECTIFYDESCR,
		CORP_INFO_ID,
		ISDELETE,
		STATUS,
		HIDDEN_LIBRARY_ID,
		SOURCE,
		HIDDEN_TYPE_ONE,
		HIDDEN_TYPE_TWO,
		HIDDEN_TYPE_THREE
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{INDUSTRY_TYPE_ONE},
		#{INDUSTRY_TYPE_TWO},
		#{INDUSTRY_TYPE_THREE},
		#{INDUSTRY_TYPE_FOUR},
		#{HIDDEN_TYPES},
		#{RISK_UNIT_ID},
		#{RISK_UNIT_NAME},
		#{HIDDEN_PART},
		#{HIDDEN_DESCR},
		#{CREATOR_ID},
		#{CREATOR_NAME},
		#{CREATED_TIME},
		#{OPERATOR_ID},
		#{OPERATOR_NAME},
		#{OPERATE_TIME},
		#{INSPECTION_BASIS},
		#{INSPECTION_INFO},
		#{RECTIFYDESCR},
		#{CORP_INFO_ID},
		#{ISDELETE},
		#{STATUS},
		#{HIDDEN_LIBRARY_ID},
		#{SOURCE},
		#{HIDDEN_TYPE_ONE},
		#{HIDDEN_TYPE_TWO},
		#{HIDDEN_TYPE_THREE}
	</sql>

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

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

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			INDUSTRY_TYPE_ONE = #{INDUSTRY_TYPE_ONE},
			INDUSTRY_TYPE_TWO = #{INDUSTRY_TYPE_TWO},
			INDUSTRY_TYPE_THREE = #{INDUSTRY_TYPE_THREE},
			INDUSTRY_TYPE_FOUR = #{INDUSTRY_TYPE_FOUR},
			HIDDEN_TYPES = #{HIDDEN_TYPES},
			RISK_UNIT_ID = #{RISK_UNIT_ID},
			RISK_UNIT_NAME = #{RISK_UNIT_NAME},
			HIDDEN_PART = #{HIDDEN_PART},
			HIDDEN_DESCR = #{HIDDEN_DESCR},
			CREATOR_ID = #{CREATOR_ID},
			CREATOR_NAME = #{CREATOR_NAME},
			CREATED_TIME = #{CREATED_TIME},
			OPERATOR_ID = #{OPERATOR_ID},
			OPERATOR_NAME = #{OPERATOR_NAME},
			OPERATE_TIME = #{OPERATE_TIME},
			INSPECTION_BASIS = #{INSPECTION_BASIS},
			INSPECTION_INFO = #{INSPECTION_INFO},
			RECTIFYDESCR = #{RECTIFYDESCR},
			CORP_INFO_ID = #{CORP_INFO_ID},
			ISDELETE = #{ISDELETE},
			STATUS = #{STATUS},
			SOURCE = #{SOURCE},
			HIDDEN_TYPE_ONE = #{HIDDEN_TYPE_ONE},
			HIDDEN_TYPE_TWO = #{HIDDEN_TYPE_TWO},
			HIDDEN_TYPE_THREE = #{HIDDEN_TYPE_THREE},
			HIDDEN_LIBRARY_ID = HIDDEN_LIBRARY_ID
		where
			HIDDEN_LIBRARY_ID = #{HIDDEN_LIBRARY_ID}
	</update>

	<!-- 修改 -->
	<update id="addToLibrary" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
		STATUS = '1'
		where
		HIDDEN_LIBRARY_ID in
		<foreach item="item" index="index" collection="HIDDEN_LIBRARY_IDS" open="(" separator="," close=")">
			#{item}
		</foreach>
	</update>


	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		where
			f.HIDDEN_LIBRARY_ID = #{HIDDEN_LIBRARY_ID}
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
        select
			ito.NAME  as INDUSTRY_TYPE_ONE_NAME,
			a.INDUSTRY_TYPE_ONE,
			itt.NAME  as INDUSTRY_TYPE_TWO_NAME,
			a.INDUSTRY_TYPE_TWO,
			itth.NAME as INDUSTRY_TYPE_THREE_NAME,
			a.INDUSTRY_TYPE_THREE,
			itf.NAME  as INDUSTRY_TYPE_FOUR_NAME,
			a.INDUSTRY_TYPE_FOUR,
			hto.NAME as HIDDEN_TYPE_ONE_NAME,
			a.HIDDEN_TYPE_ONE,
			htt.NAME as HIDDEN_TYPE_TWO_NAME,
			a.HIDDEN_TYPE_TWO,
			htth.NAME as HIDDEN_TYPE_THREE_NAME,
			a.HIDDEN_TYPE_THREE,
			a.HIDDEN_TYPES,
			a.HIDDEN_PART,
			a.HIDDEN_DESCR,
			a.INSPECTION_BASIS,
			a.INSPECTION_INFO,
			a.RECTIFYDESCR,
			a.RISK_UNIT_NAME,
			a.RISK_UNIT_ID,
			a.CORP_INFO_ID,
			ci.CORP_NAME as CORP_INFO_NAME,
			a.HIDDEN_LIBRARY_ID
        from
        <include refid="tableName"></include> a
			left join sys_dictionaries ito on ito.DICTIONARIES_ID = a.INDUSTRY_TYPE_ONE
			left join sys_dictionaries itt on itt.DICTIONARIES_ID = a.INDUSTRY_TYPE_TWO
			left join sys_dictionaries itth on itth.DICTIONARIES_ID = a.INDUSTRY_TYPE_THREE
			left join sys_dictionaries itf on itf.DICTIONARIES_ID = a.INDUSTRY_TYPE_FOUR
			left join sys_dictionaries hto on hto.DICTIONARIES_ID = a.HIDDEN_TYPE_ONE
			left join sys_dictionaries htt on htt.DICTIONARIES_ID = a.HIDDEN_TYPE_TWO
			left join sys_dictionaries htth on htth.DICTIONARIES_ID = a.HIDDEN_TYPE_THREE
        	left join bus_corp_info ci on ci.CORPINFO_ID = a.CORP_INFO_ID
		where a.ISDELETE = '0'
        <if test="pd.STATUS != null and pd.STATUS != ''">
			and a.STATUS = #{pd.STATUS}
		</if>
        <if test="pd.HIDDEN_TYPES != null and pd.HIDDEN_TYPES != ''">
			and a.HIDDEN_TYPES = #{pd.HIDDEN_TYPES}
		</if>
        <if test="pd.HIDDEN_DESCR != null and pd.HIDDEN_DESCR != ''">
			and a.HIDDEN_DESCR like CONCAT(CONCAT('%', #{pd.HIDDEN_DESCR}),'%')
		</if>
		<if test="pd.HIDDEN_PART != null and pd.HIDDEN_PART != ''">
			and a.HIDDEN_PART like CONCAT(CONCAT('%', #{pd.HIDDEN_PART}),'%')
		</if>
        <if test="pd.RISK_UNIT_NAME != null and pd.RISK_UNIT_NAME != ''">
			and a.RISK_UNIT_NAME like CONCAT(CONCAT('%', #{pd.RISK_UNIT_NAME}),'%')
		</if>
        <if test="pd.INDUSTRY_TYPE_FOUR != '' and pd.INDUSTRY_TYPE_FOUR != null">
			and a.INDUSTRY_TYPE_FOUR = #{pd.INDUSTRY_TYPE_FOUR}
		</if>
        <if test="pd.HIDDEN_TYPE_ONE != '' and pd.HIDDEN_TYPE_ONE != null">
			and a.HIDDEN_TYPE_ONE = #{pd.HIDDEN_TYPE_ONE}
		</if>
        <if test="pd.HIDDEN_TYPE_TWO != '' and pd.HIDDEN_TYPE_TWO != null">
			and a.HIDDEN_TYPE_TWO = #{pd.HIDDEN_TYPE_TWO}
		</if>
        <if test="pd.HIDDEN_TYPE_THREE != '' and pd.HIDDEN_TYPE_THREE != null">
			and a.HIDDEN_TYPE_THREE = #{pd.HIDDEN_TYPE_THREE}
		</if>
		<if test="pd.INSPECTION_BASIS != null and pd.INSPECTION_BASIS != ''">
			and a.INSPECTION_BASIS like  CONCAT(CONCAT('%', #{pd.INSPECTION_BASIS}),'%')
		</if>
        order by date(a.OPERATE_TIME) desc
    </select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
	</select>

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

</mapper>
