<?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.warehouse.check.mapper.TWarehouseCheckItemsMapper">

    <resultMap type="TWarehouseCheckItems" id="TWarehouseCheckItemsResult">
        <result property="fId" column="f_id"/>
        <result property="fCheckFid" column="f_check_fid"/>
        <result property="fWarehouseFid" column="f_warehouse_fid"/>
        <result property="fInspectionDatetime" column="f_inspection_datetime"/>
        <result property="fInspectorId" column="f_inspector_id"/>
        <result property="fInspectorIdLast" column="f_inspector_id_last"/>
        <result property="fInspectorNameLast" column="f_inspector_name_last"/>
        <result property="fInspectionDatetimeLast" column="f_inspection_datetime_last"/>
        <result property="fRemark" column="f_remark"/>
        <result property="fCreateBy" column="f_create_by"/>
        <result property="fCreateTime" column="f_create_time"/>
        <result property="fUpdateBy" column="f_update_by"/>
        <result property="fUpdateTime" column="f_update_time"/>
        <result property="fDelFlag" column="f_del_flag"/>
        <result property="fInspectorName" column="f_inspector_name"/>
        <result property="fCreateByName" column="f_create_by_name"/>
        <result property="fUpdateByName" column="f_update_by_name"/>
        <result property="fWarehouseName" column="f_warehouse_name"/>
    </resultMap>

    <sql id="selectTWarehouseCheckItemsVo">
        select a.f_id,
               a.f_check_fid,
               a.f_warehouse_fid,
               w.f_name                 as f_warehouse_name,
               inspection.nick_name     as f_Inspector_name,
               a.f_inspection_datetime,
               a.f_inspector_id,
               a.f_inspector_id_last,
               inspectionlast.nick_name as f_inspector_name_last,
               a.f_inspection_datetime_last,
               a.f_remark,
               a.f_create_by,
               a.f_create_time,
               a.f_update_by,
               a.f_update_time,
               a.f_del_flag,
               createby.nick_name       as f_create_by_name,
               updateby.nick_name       as f_update_by_name
        from t_warehouse_check_items a
                 left join t_warehouse_check ch on ch.f_id = a.f_check_fid
                 left join sys_user inspection on inspection.user_id = a.f_inspector_id
                 left join sys_user inspectionlast on inspectionlast.user_id = a.f_inspector_id_last
                 left join sys_user createby on createby.user_id = a.f_create_by
                 left join sys_user updateby on updateby.user_id = a.f_update_by
                 left join t_warehouse w on w.f_id = a.f_warehouse_fid
    </sql>

    <select id="selectTWarehouseCheckItemsList" parameterType="TWarehouseCheckItems"
            resultMap="TWarehouseCheckItemsResult">
        <include refid="selectTWarehouseCheckItemsVo"/>
        <where>
            <if test="fCheckFid != null ">and f_check_fid = #{fCheckFid}</if>
            <if test="fWarehouseFid != null ">and a.f_warehouse_fid = #{fWarehouseFid}</if>
            <if test="fInspectionDatetime != null ">and f_inspection_datetime = #{fInspectionDatetime}</if>
            <if test="fInspectorId != null ">and a.f_inspector_id = #{fInspectorId}</if>
            <if test="fInspectorIdLast != null ">and a.f_inspector_id_last = #{fInspectorIdLast}</if>
            <if test="fInspectionDatetimeLast != null ">and a.f_inspection_datetime_last = #{fInspectionDatetimeLast}</if>
            <if test="fRemark != null  and fRemark != ''">and a.f_remark = #{fRemark}</if>
            <if test="fCreateBy != null ">and a.f_create_by = #{fCreateBy}</if>
            <if test="fCreateTime != null ">and a.f_create_time = #{fCreateTime}</if>
            <if test="fUpdateBy != null ">and a.f_update_by = #{fUpdateBy}</if>
            <if test="fUpdateTime != null ">and a.f_update_time = #{fUpdateTime}</if>
            <if test="fDelFlag != null ">and a.f_del_flag = #{fDelFlag}</if>
        </where>
    </select>

    <select id="selectTWarehouseCheckItemsById" parameterType="Long" resultMap="TWarehouseCheckItemsResult">
        <include refid="selectTWarehouseCheckItemsVo"/>
        where a.f_id = #{fId}
    </select>

    <insert id="insertTWarehouseCheckItems" parameterType="TWarehouseCheckItems" useGeneratedKeys="true"
            keyProperty="fId">
        insert into t_warehouse_check_items
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fCheckFid != null">f_check_fid,</if>
            <if test="fWarehouseFid != null">f_warehouse_fid,</if>
            <if test="fInspectionDatetime != null">f_inspection_datetime,</if>
            <if test="fInspectorId != null">f_inspector_id,</if>
            <if test="fInspectorIdLast != null">f_inspector_id_last,</if>
            <if test="fInspectionDatetimeLast != null">f_inspection_datetime_last,</if>
            <if test="fRemark != null">f_remark,</if>
            <if test="fCreateBy != null">f_create_by,</if>
            <if test="fCreateTime != null">f_create_time,</if>
            <if test="fUpdateBy != null">f_update_by,</if>
            <if test="fUpdateTime != null">f_update_time,</if>
            <if test="fDelFlag != null">f_del_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fCheckFid != null">#{fCheckFid},</if>
            <if test="fWarehouseFid != null">#{fWarehouseFid},</if>
            <if test="fInspectionDatetime != null">#{fInspectionDatetime},</if>
            <if test="fInspectorId != null">#{fInspectorId},</if>
            <if test="fInspectorIdLast != null">#{fInspectorIdLast},</if>
            <if test="fInspectionDatetimeLast != null">#{fInspectionDatetimeLast},</if>
            <if test="fRemark != null">#{fRemark},</if>
            <if test="fCreateBy != null">#{fCreateBy},</if>
            <if test="fCreateTime != null">#{fCreateTime},</if>
            <if test="fUpdateBy != null">#{fUpdateBy},</if>
            <if test="fUpdateTime != null">#{fUpdateTime},</if>
            <if test="fDelFlag != null">#{fDelFlag},</if>
        </trim>
    </insert>

    <update id="updateTWarehouseCheckItems" parameterType="TWarehouseCheckItems">
        update t_warehouse_check_items
        <trim prefix="SET" suffixOverrides=",">
            <if test="fCheckFid != null">f_check_fid = #{fCheckFid},</if>
            <if test="fWarehouseFid != null">f_warehouse_fid = #{fWarehouseFid},</if>
            <if test="fInspectionDatetime != null">f_inspection_datetime = #{fInspectionDatetime},</if>
            <if test="fInspectorId != null">f_inspector_id = #{fInspectorId},</if>
            <if test="fInspectorIdLast != null">f_inspector_id_last = #{fInspectorIdLast},</if>
            <if test="fInspectionDatetimeLast != null">f_inspection_datetime_last = #{fInspectionDatetimeLast},</if>
            <if test="fRemark != null">f_remark = #{fRemark},</if>
            <if test="fCreateBy != null">f_create_by = #{fCreateBy},</if>
            <if test="fCreateTime != null">f_create_time = #{fCreateTime},</if>
            <if test="fUpdateBy != null">f_update_by = #{fUpdateBy},</if>
            <if test="fUpdateTime != null">f_update_time = #{fUpdateTime},</if>
            <if test="fDelFlag != null">f_del_flag = #{fDelFlag},</if>
        </trim>
        where f_id = #{fId}
    </update>

    <delete id="deleteTWarehouseCheckItemsById" parameterType="Long">
        delete
        from t_warehouse_check_items
        where f_id = #{fId}
    </delete>

    <delete id="deleteTWarehouseCheckItemsByIds" parameterType="String">
        delete from t_warehouse_check_items where f_id in
        <foreach item="fId" collection="array" open="(" separator="," close=")">
            #{fId}
        </foreach>
    </delete>

</mapper>