<?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.feeagreement.mapper.TWarehouseFeeAgreementTypeMapper">

    <resultMap type="TWarehouseFeeAgreementType" id="TWarehouseFeeAgreementTypeResult">
        <result property="fId" column="f_id"/>
        <result property="fName" column="f_name"/>
        <result property="fCorpId" column="f_corp_id"/>
        <result property="fTFeeAgreementTypeFId" column="f_t_fee_agreement_type_f_id"/>
        <result property="fBegindate" column="f_begindate"/>
        <result property="fEnddate" column="f_enddate"/>
        <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="fIsValid" column="f_is_valid"/>
        <result property="fIsCommit" column="f_is_commit"/>
        <result property="fIsStandard" column="f_is_standard"/>
        <result property="fIsValidName" column="f_is_valid_name"/>
        <result property="fIsCommitName" column="f_is_commit_name"/>
        <result property="fIsStandardName" column="f_is_standard_name"/>
        <result property="fCorpName" column="f_corp_name"/>
        <result property="fTFeeAgreementTypeName" column="f_t_fee_agreement_type_name"/>
    </resultMap>

    <sql id="selectTWarehouseFeeAgreementTypeVo">
        select w.f_id,
               w.f_name,
               w.f_corp_id,
               w.f_t_fee_agreement_type_f_id,
               w.f_begindate,
               w.f_enddate,
               w.f_remark,
               w.f_create_by,
               w.f_create_time,
               w.f_update_by,
               w.f_update_time,
               w.f_del_flag,
               w.f_is_valid,
               w.f_is_commit,
               w.f_is_standard,
               c.f_name            as f_corp_name,
               f.f_name            as f_t_fee_agreement_type_name,
               commit.dict_label   as f_is_commit_name,
               standard.dict_label as f_is_standard_name,
               valid.dict_label    as f_is_valid_name
        from t_warehouse_fee_agreement_type w
                 left join t_corps c on c.f_id = w.f_corp_id
                 left join t_fee_agreement_type f on f.f_id = w.f_t_fee_agreement_type_f_id
                 left join sys_dict_data commit on commit.dict_type = 'sys_yes_no' and commit.dict_value = w.f_is_commit
                 left join sys_dict_data standard
                           on standard.dict_type = 'sys_yes_no' and standard.dict_value = w.f_is_standard
                 left join sys_dict_data valid on valid.dict_type = 'sys_yes_no' and valid.dict_value = w.f_is_valid
    </sql>

    <select id="selectTWarehouseFeeAgreementTypeList" parameterType="TWarehouseFeeAgreementType"
            resultMap="TWarehouseFeeAgreementTypeResult">
        <include refid="selectTWarehouseFeeAgreementTypeVo"/>
        <where>
            <if test="fName != null  and fName != ''">and w.f_name like concat('%', #{fName}, '%')</if>
            <if test="fCorpId != null ">and w.f_corp_id = #{fCorpId}</if>
            <if test="fTFeeAgreementTypeFId != null ">and w.f_t_fee_agreement_type_f_id = #{fTFeeAgreementTypeFId}</if>
            <if test="fBegindate != null ">and w.f_begindate = #{fBegindate}</if>
            <if test="fEnddate != null ">and w.f_enddate = #{fEnddate}</if>
            <if test="fRemark != null  and fRemark != ''">and w.f_remark = #{fRemark}</if>
            <if test="fCreateBy != null ">and w.f_create_by = #{fCreateBy}</if>
            <if test="fCreateTime != null ">and w.f_create_time = #{fCreateTime}</if>
            <if test="fUpdateBy != null ">and w.f_update_by = #{fUpdateBy}</if>
            <if test="fUpdateTime != null ">and w.f_update_time = #{fUpdateTime}</if>
            <if test="fDelFlag != null ">and w.f_del_flag = #{fDelFlag}</if>
            <if test="fIsValid != null  and fIsValid != ''">and w.f_is_valid = #{fIsValid}</if>
            <if test="fIsCommit != null  and fIsCommit != ''">and w.f_is_commit = #{fIsCommit}</if>
            <if test="fIsStandard != null  and fIsStandard != ''">and w.f_is_standard = #{fIsStandard}</if>
            and w.f_del_flag = 0
        </where>
    </select>

    <select id="selectTWarehouseFeeAgreementTypeById" parameterType="Long" resultMap="TWarehouseFeeAgreementTypeResult">
        <include refid="selectTWarehouseFeeAgreementTypeVo"/>
        where w.f_id = #{fId}
    </select>

    <insert id="insertTWarehouseFeeAgreementType" parameterType="TWarehouseFeeAgreementType" useGeneratedKeys="true"
            keyProperty="fId">
        insert into t_warehouse_fee_agreement_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fName != null">f_name,</if>
            <if test="fCorpId != null">f_corp_id,</if>
            <if test="fTFeeAgreementTypeFId != null">f_t_fee_agreement_type_f_id,</if>
            <if test="fBegindate != null">f_begindate,</if>
            <if test="fEnddate != null">f_enddate,</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>
            <if test="fIsValid != null">f_is_valid,</if>
            <if test="fIsCommit != null">f_is_commit,</if>
            <if test="fIsStandard != null">f_is_standard,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fName != null">#{fName},</if>
            <if test="fCorpId != null">#{fCorpId},</if>
            <if test="fTFeeAgreementTypeFId != null">#{fTFeeAgreementTypeFId},</if>
            <if test="fBegindate != null">#{fBegindate},</if>
            <if test="fEnddate != null">#{fEnddate},</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>
            <if test="fIsValid != null">#{fIsValid},</if>
            <if test="fIsCommit != null">#{fIsCommit},</if>
            <if test="fIsStandard != null">#{fIsStandard},</if>
        </trim>
    </insert>

    <update id="updateTWarehouseFeeAgreementType" parameterType="TWarehouseFeeAgreementType">
        update t_warehouse_fee_agreement_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="fName != null">f_name = #{fName},</if>
            <if test="fCorpId != null">f_corp_id = #{fCorpId},</if>
            <if test="fTFeeAgreementTypeFId != null">f_t_fee_agreement_type_f_id = #{fTFeeAgreementTypeFId},</if>
            <if test="fBegindate != null">f_begindate = #{fBegindate},</if>
            <if test="fEnddate != null">f_enddate = #{fEnddate},</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>
            <if test="fIsValid != null">f_is_valid = #{fIsValid},</if>
            <if test="fIsCommit != null">f_is_commit = #{fIsCommit},</if>
            <if test="fIsStandard != null">f_is_standard = #{fIsStandard},</if>
        </trim>
        where f_id = #{fId}
    </update>

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

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

</mapper>