<?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.ruoyi.app.mapper.EntranceInspectionMapper">
    
    <resultMap type="EntranceInspection" id="EntranceInspectionResult">
        <result property="id"    column="id"    />
        <result property="entranceBatchId"    column="entrance_batch_id"    />
        <result property="spirit"    column="spirit"    />
        <result property="appearance"    column="appearance"    />
        <result property="breathe"    column="breathe"    />
        <result property="metabolite"    column="metabolite"    />
        <result property="otherRemark"    column="other_remark"    />
        <result property="inspectionDetail"    column="inspection_detail"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectEntranceInspectionVo">
        select id, entrance_batch_id, spirit, appearance, breathe, metabolite, other_remark, inspection_detail, create_time, create_by, update_time, update_by, del_flag from entrance_inspection
    </sql>

    <select id="selectEntranceInspectionList" parameterType="EntranceInspection" resultMap="EntranceInspectionResult">
        <include refid="selectEntranceInspectionVo"/>
        <where>
            del_flag = '0'
            <if test="entranceBatchId != null "> and entrance_batch_id = #{entranceBatchId}</if>
            <if test="spirit != null  and spirit != ''"> and spirit = #{spirit}</if>
            <if test="appearance != null  and appearance != ''"> and appearance = #{appearance}</if>
            <if test="breathe != null  and breathe != ''"> and breathe = #{breathe}</if>
            <if test="metabolite != null  and metabolite != ''"> and metabolite = #{metabolite}</if>
            <if test="otherRemark != null  and otherRemark != ''"> and other_remark = #{otherRemark}</if>
            <if test="inspectionDetail != null  and inspectionDetail != ''"> and inspection_detail = #{inspectionDetail}</if>
        </where>
    </select>
    
    <select id="selectEntranceInspectionById" parameterType="Long" resultMap="EntranceInspectionResult">
        <include refid="selectEntranceInspectionVo"/>
        where entrance_batch_id = #{id} and del_flag = '0'
    </select>

    <insert id="insertEntranceInspection" parameterType="EntranceInspection" useGeneratedKeys="true" keyProperty="id">
        insert into entrance_inspection
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="entranceBatchId != null">entrance_batch_id,</if>
            <if test="spirit != null">spirit,</if>
            <if test="appearance != null">appearance,</if>
            <if test="breathe != null">breathe,</if>
            <if test="metabolite != null">metabolite,</if>
            <if test="otherRemark != null">other_remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            del_flag
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="entranceBatchId != null">#{entranceBatchId},</if>
            <if test="spirit != null">#{spirit},</if>
            <if test="appearance != null">#{appearance},</if>
            <if test="breathe != null">#{breathe},</if>
            <if test="metabolite != null">#{metabolite},</if>
            <if test="otherRemark != null">#{otherRemark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            '0'
         </trim>
    </insert>

    <update id="updateEntranceInspection" parameterType="EntranceInspection">
        update entrance_inspection
        <trim prefix="SET" suffixOverrides=",">
            <if test="entranceBatchId != null">entrance_batch_id = #{entranceBatchId},</if>
            <if test="spirit != null">spirit = #{spirit},</if>
            <if test="appearance != null">appearance = #{appearance},</if>
            <if test="breathe != null">breathe = #{breathe},</if>
            <if test="metabolite != null">metabolite = #{metabolite},</if>
            <if test="otherRemark != null">other_remark = #{otherRemark},</if>
            <if test="inspectionDetail != null">inspection_detail = #{inspectionDetail},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where entrance_batch_id = #{entranceBatchId} and del_flag = '0'
    </update>

    <delete id="deleteEntranceInspectionById" parameterType="Long">
        update entrance_inspection set del_flag = '2'  where entrance_batch_id = #{id}
    </delete>

    <delete id="deleteEntranceInspectionByIds" parameterType="String">
        update entrance_inspection set del_flag = '2' where entrance_batch_id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>