<?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.hiddenDangerCheckStandard.CommonMapper">

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

	<!-- 字段 -->
	<sql id="Field">
		f.COMMON_ID,
		f.INDUSTRY_TYPE,
		f.INDUSTRY_TYPE_TREE,
		f.INDUSTRY_TYPE_NAMES,
		f.CHECK_STANDARD_NAME,
		f.COMMON_STATUS,
		f.ISDELETE,
		f.CREATOR_ID,
		f.CREATOR_NAME,
		f.CREATE_TIME,
		f.OPERATOR_ID,
		f.OPERATOR_NAME,
		f.OPERATE_TIME,
		f.DELETEOR_ID,
		f.DELETEOR_NAME,
		f.DELETE_TIME
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		COMMON_ID,
		INDUSTRY_TYPE,
		INDUSTRY_TYPE_TREE,
		INDUSTRY_TYPE_NAMES,
		CHECK_STANDARD_NAME,
		COMMON_STATUS,
		ISDELETE,
		CREATOR_ID,
		CREATOR_NAME,
		CREATE_TIME,
		OPERATOR_ID,
		OPERATOR_NAME,
		OPERATE_TIME,
		DELETEOR_ID,
		DELETEOR_NAME,
		DELETE_TIME
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{COMMON_ID},
		#{INDUSTRY_TYPE},
		#{INDUSTRY_TYPE_TREE},
		#{INDUSTRY_TYPE_NAMES},
		#{CHECK_STANDARD_NAME},
		#{COMMON_STATUS},
		#{ISDELETE},
		#{CREATOR_ID},
		#{CREATOR_NAME},
		#{CREATE_TIME},
		#{OPERATOR_ID},
		#{OPERATOR_NAME},
		#{OPERATE_TIME},
		#{DELETEOR_ID},
		#{DELETEOR_NAME},
		#{DELETE_TIME}
	</sql>

	<!-- 列表(全部) -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
			f.COMMON_ID,
			f.INDUSTRY_TYPE,
			f.INDUSTRY_TYPE_TREE,
			f.INDUSTRY_TYPE_NAMES,
			f.CHECK_STANDARD_NAME,
			bhci.COMMON_ITEM_ID,
			bhci.CHECK_CATEGORY,
			bhci.CHECK_ITEM,
			bhci.CHECK_CONTENT,
			bhci.CHECK_STANDARD,
			bhci.REFERENCE_BASIS,
			bhci.CHECK_QUALIFIED,
			bhci.CHECK_UNQUALIFIED,
			bhci.OPERATION_TYPE,
			bhci.COMMON_ITEM_SORT,
			bhd1.DICTIONARY_NAME as CHECK_CATEGORY_NAME,
			bhd2.DICTIONARY_NAME as CHECK_ITEM_NAME
		from
			<include refid="tableName"></include> f
		left join bus_hiddendangercheckstandard_common_item bhci on bhci.COMMON_ID = f.COMMON_ID
		left join bus_hiddendangercheckstandard_dictionary bhd1 on bhd1.DICTIONARY_ID = bhci.CHECK_CATEGORY and bhd1.ISDELETE = 0
		left join bus_hiddendangercheckstandard_dictionary bhd2 on bhd2.DICTIONARY_ID = bhci.CHECK_ITEM  and bhd2.ISDELETE = 0
		where
			f.ISDELETE = 0
		and bhci.ISDELETE = 0
		and f.COMMON_STATUS = 1
		and bhci.COMMON_ITEM_STATUS = 1
		and  ( f.INDUSTRY_TYPE_TREE LIKE CONCAT(CONCAT('%', #{pd.CORP_TYPE}),'%')
		    or f.INDUSTRY_TYPE_TREE LIKE CONCAT(CONCAT('%', #{pd.CORP_TYPE2}),'%')
		    or f.INDUSTRY_TYPE_TREE LIKE CONCAT(CONCAT('%', #{pd.CORP_TYPE3}),'%')
		    or f.INDUSTRY_TYPE_TREE LIKE CONCAT(CONCAT('%', #{pd.CORP_TYPE4}),'%') )
		<if test="pd.OTHERKEYWORDS != null and pd.OTHERKEYWORDS != ''"><!-- 关键词检索 -->
			and
			(
			bhci.CHECK_CONTENT LIKE CONCAT(CONCAT('%', #{pd.OTHERKEYWORDS}),'%')
			)
		</if>
		<if test="pd.CHECK_CATEGORY != null and pd.CHECK_CATEGORY != ''"><!-- 检查类别 -->
			and bhci.CHECK_CATEGORY = #{pd.CHECK_CATEGORY}
		</if>
		<if test="pd.CHECK_ITEM != null and pd.CHECK_ITEM != ''"><!-- 检查项目 -->
			and bhci.CHECK_ITEM = #{pd.CHECK_ITEM}
		</if>
		order by bhci.CHECK_CATEGORY,bhci.CHECK_ITEM,bhci.COMMON_ITEM_SORT
	</select>
	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
		<if test="INDUSTRY_TYPE != null and INDUSTRY_TYPE != ''">
			INDUSTRY_TYPE = #{INDUSTRY_TYPE},
		</if>
		<if test="INDUSTRY_TYPE_TREE != null and INDUSTRY_TYPE_TREE != ''">
			INDUSTRY_TYPE_TREE = #{INDUSTRY_TYPE_TREE},
		</if>
		<if test="INDUSTRY_TYPE_NAMES != null and INDUSTRY_TYPE_NAMES != ''">
			INDUSTRY_TYPE_NAMES = #{INDUSTRY_TYPE_NAMES},
		</if>
		<if test="CHECK_STANDARD_NAME != null and CHECK_STANDARD_NAME != ''">
			CHECK_STANDARD_NAME = #{CHECK_STANDARD_NAME},
		</if>
		<if test="COMMON_STATUS != null and COMMON_STATUS != ''">
			COMMON_STATUS = #{COMMON_STATUS},
		</if>
		<if test="ISDELETE != null and ISDELETE != ''">
			ISDELETE = #{ISDELETE},
		</if>
		<if test="CREATOR_ID != null and CREATOR_ID != ''">
			CREATOR_ID = #{CREATOR_ID},
		</if>
		<if test="CREATOR_NAME != null and CREATOR_NAME != ''">
			CREATOR_NAME = #{CREATOR_NAME},
		</if>
		<if test="CREATE_TIME != null and CREATE_TIME != ''">
			CREATE_TIME = #{CREATE_TIME},
		</if>
		<if test="OPERATOR_ID != null and OPERATOR_ID != ''">
			OPERATOR_ID = #{OPERATOR_ID},
		</if>
		<if test="OPERATOR_NAME != null and OPERATOR_NAME != ''">
			OPERATOR_NAME = #{OPERATOR_NAME},
		</if>
		<if test="OPERATE_TIME != null and OPERATE_TIME != ''">
			OPERATE_TIME = #{OPERATE_TIME},
		</if>
		<if test="DELETEOR_ID != null and DELETEOR_ID != ''">
			DELETEOR_ID = #{DELETEOR_ID},
		</if>
		<if test="DELETEOR_NAME != null and DELETEOR_NAME != ''">
			DELETEOR_NAME = #{DELETEOR_NAME},
		</if>
		<if test="DELETE_TIME != null and DELETE_TIME != ''">
			DELETE_TIME = #{DELETE_TIME},
		</if>
		COMMON_ID = COMMON_ID
		where
		COMMON_ID = #{COMMON_ID}
	</update>
</mapper>
