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

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

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

	<!-- 字段 -->
	<sql id="Field">
		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,
		f.COMMON_ID
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		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,
		COMMON_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{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},
		#{COMMON_ID}
	</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',
			DELETEOR_ID = #{DELETEOR_ID},
			DELETEOR_NAME = #{DELETEOR_NAME},
			DELETE_TIME = #{DELETE_TIME}
		where
			COMMON_ID = #{COMMON_ID}
	</delete>

	<!-- 修改 -->
	<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>

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

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
        select
            (select count(*) from BUS_HIDDENDANGERCHECKSTANDARD_CUSTOM_ITEM where COMMON_ID = f.COMMON_ID) COUNT_CUSTOM,
		<include refid="Field"></include>
        from
        <include refid="tableName"></include> f
		where f.ISDELETE = '0'
		<if test="pd.INDUSTRY_TYPE != null and pd.INDUSTRY_TYPE != ''">
			and f.INDUSTRY_TYPE = #{pd.INDUSTRY_TYPE}
		</if>
		<if test="pd.COMMON_STATUS != null and pd.COMMON_STATUS != ''">
			and f.COMMON_STATUS = #{pd.COMMON_STATUS}
		</if>
        <if test="pd.INDUSTRY_TYPE_TREE != null and pd.INDUSTRY_TYPE_TREE != ''">
			and f.INDUSTRY_TYPE_TREE like CONCAT(CONCAT('%', #{pd.INDUSTRY_TYPE_TREE}),'%')
		</if>
        <if test="pd.CHECK_STANDARD_NAME != null and pd.CHECK_STANDARD_NAME != ''">
			and f.CHECK_STANDARD_NAME like CONCAT(CONCAT('%', #{pd.CHECK_STANDARD_NAME}),'%')
		</if>
		<if test="pd.CREATE_TIME_BEGIN!=null and pd.CREATE_TIME_BEGIN!=''"><!-- 开始时间检索 -->
			and f.CREATE_TIME &gt;= CONCAT(#{pd.CREATE_TIME_BEGIN},' 00:00:00')
		</if>
		<if test="pd.CREATE_TIME_END!=null and pd.CREATE_TIME_END!=''"><!-- 结束时间检索 -->
			and f.CREATE_TIME &lt;= CONCAT(#{pd.CREATE_TIME_END},' 23:59:59')
		</if>
        order by date(f.OPERATE_TIME) desc
    </select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		where f.ISDELETE = '0'
		<if test="COMMON_STATUS != null">
			and f.COMMON_STATUS = #{COMMON_STATUS},
		</if>
	</select>

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

</mapper>
