<?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.TWarehouseCheckMapper">

    <resultMap type="TWarehouseCheck" id="TWarehouseCheckResult">
        <result property="fId" column="f_id"/>
        <result property="fWarehouseFid" column="f_warehouse_fid"/>
        <result property="fWarehouseName" column="f_warehouse_name"/>
        <result property="fInspectorId" column="f_inspector_id"/>
        <result property="fInspectorName" column="f_inspector_name"/>
        <result property="fSystemNo" column="f_system_no"/>
        <result property="fInspectorBeginDatetime" column="f_inspector_begin_datetime"/>
        <result property="fInspectorEndDatetime" column="f_inspector_end_datetime"/>
        <result property="fRemark" column="f_remark"/>
        <result property="fCreateBy" column="f_create_by"/>
        <result property="fCreateByName" column="f_create_by_name"/>
        <result property="fCreateTime" column="f_create_time"/>
        <result property="fUpdateBy" column="f_update_by"/>
        <result property="fUpdateByName" column="f_update_by_name"/>
        <result property="fUpdateTime" column="f_update_time"/>
        <result property="fDelFlag" column="f_del_flag"/>
    </resultMap>

    <sql id="selectTWarehouseCheckVo">
        select a.f_id,
               f_warehouse_fid,
               f_inspector_id,
               f_system_no,
               a.f_inspector_begin_datetime,
               a.f_inspector_end_datetime,
               a.f_remark,
               a.f_create_by,
               a.f_create_time,
               a.f_update_by,
               a.f_update_time,
               a.f_del_flag,
               b.f_name            as f_warehouse_name,
               inspector.nick_name as f_inspector_name,
               createby.nick_name  as f_create_by_name,
               updateby.nick_name  as f_update_by_name
        from t_warehouse_check a
                 left join t_warehouse b on a.f_warehouse_fid = b.f_id
                 left join sys_user inspector on inspector.user_id = a.f_inspector_id
                 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
    </sql>

    <sql id="selectTWarehouseVo">
        select f_id,
               parent_id,
               ancestors,
               order_num,
               f_no,
               f_name,
               f_addr,
               f_totalgross,
               f_contacts,
               f_tel,
               f_charg,
               f_status,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time,
               remark,
               f_location,
               f_warehouse_information
        from t_warehouse
        where f_id in (select f_warehouse_fid from t_warehouse_check)
    </sql>

    <resultMap type="TWarehouse" id="TWarehouseResult">
        <result property="fId" column="f_id"/>
        <result property="parentId" column="parent_id"/>
        <result property="ancestors" column="ancestors"/>
        <result property="orderNum" column="order_num"/>
        <result property="fNo" column="f_no"/>
        <result property="fName" column="f_name"/>
        <result property="fAddr" column="f_addr"/>
        <result property="fTotalgross" column="f_totalgross"/>
        <result property="fContacts" column="f_contacts"/>
        <result property="fTel" column="f_tel"/>
        <result property="fCharg" column="f_charg"/>
        <result property="fStatus" column="f_status"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
        <result property="fLocation" column="f_location"/>
        <result property="fWarehouseInformation" column="f_warehouse_information"/>
    </resultMap>


    <select id="selectTWarehouseCheckList" parameterType="TWarehouseCheck" resultMap="TWarehouseCheckResult">
        <include refid="selectTWarehouseCheckVo"/>
        <where>
            <if test="fWarehouseFid != null ">and f_warehouse_fid = #{fWarehouseFid}</if>
            <if test="fInspectorId != null ">and f_inspector_id = #{fInspectorId}</if>
            <if test="fSystemNo != null  and fSystemNo != ''">and f_system_no = #{fSystemNo}</if>
            <if test="fInspectorBeginDatetime != null ">and f_inspector_begin_datetime = #{fInspectorBeginDatetime}</if>
            <if test="fInspectorEndDatetime != null ">and f_inspector_end_datetime = #{fInspectorEndDatetime}</if>
            <if test="fRemark != null  and fRemark != ''">and f_remark = #{fRemark}</if>
            <if test="fCreateBy != null ">and f_create_by = #{fCreateBy}</if>
            <if test="fCreateTime != null ">and f_create_time = #{fCreateTime}</if>
            <if test="fUpdateBy != null ">and f_update_by = #{fUpdateBy}</if>
            <if test="fUpdateTime != null ">and f_update_time = #{fUpdateTime}</if>
            <if test="fDelFlag != null ">and f_del_flag = #{fDelFlag}</if>
        </where>
    </select>

    <select id="selectTWarehouseListInCheck" parameterType="TWarehouse" resultMap="TWarehouseResult">
        <include refid="selectTWarehouseVo"/>
    </select>


    <select id="selectTWarehouseCheckById" parameterType="Long" resultMap="TWarehouseCheckResult">
        <include refid="selectTWarehouseCheckVo"/>
        where a.f_id = #{fId}
    </select>

    <insert id="insertTWarehouseCheck" parameterType="TWarehouseCheck" useGeneratedKeys="true" keyProperty="fId">
        insert into t_warehouse_check
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fWarehouseFid != null">f_warehouse_fid,</if>
            <if test="fInspectorId != null">f_inspector_id,</if>
            <if test="fSystemNo != null and fSystemNo != ''">f_system_no,</if>
            <if test="fInspectorBeginDatetime != null">f_inspector_begin_datetime,</if>
            <if test="fInspectorEndDatetime != null">f_inspector_end_datetime,</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="fWarehouseFid != null">#{fWarehouseFid},</if>
            <if test="fInspectorId != null">#{fInspectorId},</if>
            <if test="fSystemNo != null and fSystemNo != ''">#{fSystemNo},</if>
            <if test="fInspectorBeginDatetime != null">#{fInspectorBeginDatetime},</if>
            <if test="fInspectorEndDatetime != null">#{fInspectorEndDatetime},</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="updateTWarehouseCheck" parameterType="TWarehouseCheck">
        update t_warehouse_check
        <trim prefix="SET" suffixOverrides=",">
            <if test="fWarehouseFid != null">f_warehouse_fid = #{fWarehouseFid},</if>
            <if test="fInspectorId != null">f_inspector_id = #{fInspectorId},</if>
            <if test="fSystemNo != null and fSystemNo != ''">f_system_no = #{fSystemNo},</if>
            <if test="fInspectorBeginDatetime != null">f_inspector_begin_datetime = #{fInspectorBeginDatetime},</if>
            <if test="fInspectorEndDatetime != null">f_inspector_end_datetime = #{fInspectorEndDatetime},</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="deleteTWarehouseCheckById" parameterType="Long">
        delete
        from t_warehouse_check
        where f_id = #{fId}
    </delete>

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

</mapper>