<?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.cool.store.mapper.HyInspectionSettingMapper">
    <resultMap id="BaseResultMap" type="com.cool.store.entity.HyInspectionSettingDO">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="zone_name" jdbcType="VARCHAR" property="zoneName"/>
        <result column="inspection_user_id" jdbcType="VARCHAR" property="inspectionUserId"/>
        <result column="create_user_id" jdbcType="VARCHAR" property="createUserId"/>
        <result column="update_user_id" jdbcType="VARCHAR" property="updateUserId"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="deleted" jdbcType="BIT" property="deleted" />
    </resultMap>
    <sql id="Base_Column_List">
        id, zone_name, inspection_user_id, create_user_id, update_user_id, create_time, update_time, deleted
    </sql>
    <insert id="insertSelective" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
        insert into hy_inspection_setting
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="zoneName != null">
                zone_name,
            </if>
            <if test="inspectionUserId != null">
                inspection_user_id,
            </if>
            <if test="createUserId != null">
                create_user_id,
            </if>
            <if test="updateUserId != null">
                update_user_id,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="deleted != null">
                deleted,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="zoneName != null">
                #{zoneName},
            </if>
            <if test="inspectionUserId != null">
                #{inspectionUserId},
            </if>
            <if test="createUserId != null">
                #{createUserId},
            </if>
            <if test="updateUserId != null">
                #{updateUserId},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="deleted != null">
                #{deleted},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective">
        update hy_inspection_setting
        <set>
            <if test="zoneName != null">
                zone_name = #{zoneName},
            </if>
            <if test="inspectionUserId != null">
                inspection_user_id = #{inspectionUserId},
            </if>
            <if test="createUserId != null">
                create_user_id = #{createUserId},
            </if>
            <if test="updateUserId != null">
                update_user_id = #{updateUserId},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
            <if test="deleted != null">
                deleted = #{deleted},
            </if>
        </set>
        where id = #{id}
    </update>

    <select id="getInspectionSettingPage" resultMap="BaseResultMap">
        select
            <include refid="Base_Column_List"/>
        from
            hy_inspection_setting
        where
            deleted = '0'
        order by create_time desc
    </select>

    <select id="getInspectionSettingDetail" resultMap="BaseResultMap">
        select
            <include refid="Base_Column_List"/>
        from
            hy_inspection_setting
        where
            deleted = '0' and id = #{inspectionSettingId}
    </select>

    <select id="getInspectionUserIds" resultType="string">
        select inspection_user_id from hy_inspection_setting where deleted = '0'
    </select>

    <select id="getHyInspectionSettingByIds" resultMap="BaseResultMap">
        select
            <include refid="Base_Column_List"/>
        from
            hy_inspection_setting
        where
            deleted = '0' and id in <foreach collection="inspectionSettingIds" item="inspectionSettingId" open="(" close=")" separator=",">#{inspectionSettingId}</foreach>
    </select>

    <select id="getHyInspectionSettingByUserId" resultMap="BaseResultMap">
        select
            <include refid="Base_Column_List"/>
        from
            hy_inspection_setting
        where
            deleted = '0' and inspection_user_id = #{inspectionUserId}
            <if test="excludeInspectionSettingId != null">
                and id != #{excludeInspectionSettingId}
            </if>
    </select>
</mapper>