<?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.shipping.mapper.TCntrMapper">

    <resultMap type="TCntr" id="TCntrResult">
        <result property="fId" column="f_id"/>
        <result property="fType" column="f_type"/>
        <result property="fNo" column="f_no"/>
        <result property="fName" column="f_name"/>
        <result property="fEname" column="f_ename"/>
        <result property="fUncode" column="f_uncode"/>
        <result property="fTeu" column="f_teu"/>
        <result property="fCbm" column="f_cbm"/>
        <result property="fWeight" column="f_weight"/>
        <result property="fCntrsize" column="f_cntrsize"/>
        <result property="fStatus" column="f_status"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="inCreateTime" column="in_create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="outUpdateTime" column="out_update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectTCntrVo">
        select f_id, f_type, f_no, f_name, f_ename, f_uncode, f_teu, f_cbm, f_weight, f_cntrsize, CASE WHEN f_status = 'T' THEN '正常' ELSE '停用' END AS f_status, create_by, create_time, update_by, update_time, remark from t_cntr
    </sql>

    <select id="selectTCntrList" parameterType="TCntr" resultMap="TCntrResult">
        SELECT
        f_id,
        f_type,
        s.dict_label typeName,
        f_no,
        f_name,
        f_ename,
        f_uncode,
        f_teu,
        f_cbm,
        f_weight,
        f_cntrsize,
        CASE
        WHEN f_status = 'T' THEN
        '正常' ELSE '停用'
        END AS f_status,
        create_by,
        date_format(create_time, '%Y-%m-%d') in_create_time,
        create_time,
        update_by,
        date_format(update_time, '%Y-%m-%d') out_update_time,
        update_time,
        remark
        FROM
        t_cntr t
        LEFT JOIN ( SELECT dict_label, dict_value FROM sys_dict_data WHERE dict_type = 'f_type' ) s ON t.f_type =
        s.dict_value
        <where>
            t.f_status = 'T'
            <if test="fType != null ">and t.f_type = #{fType}</if>
            <if test="fNo != null  and fNo != ''">and t.f_no = like concat('%', #{fNo}, '%')</if>
            <if test="fName != null  and fName != ''">and t.f_name like concat('%', #{fName}, '%')</if>
            <if test="fEname != null  and fEname != ''">and t.f_ename like concat('%', #{fEname}, '%')</if>
            <if test="fUncode != null  and fUncode != ''">and t.f_uncode = #{fUncode}</if>
            <if test="fTeu != null ">and t.f_teu = #{fTeu}</if>
            <if test="fCbm != null ">and t.f_cbm = #{fCbm}</if>
            <if test="fWeight != null ">and t.f_weight = #{fWeight}</if>
            <if test="fCntrsize != null ">and t.f_cntrsize = #{fCntrsize}</if>
            <if test="fStatus != null  and fStatus != ''">and t.f_status = #{fStatus}</if>
            <if test="createBy != null  and createBy != ''">and t.create_by = #{createBy}</if>
            <if test='cLoadDate != null and cLoadDate[0] != null and cLoadDate[0]!= ""'>
                and t.create_time &gt;= #{cLoadDate[0]}
            </if>
            <if test='cLoadDate != null and cLoadDate[1] != null and cLoadDate[1]!= ""'>
                and t.create_time &lt;= #{cLoadDate[1]}
            </if>
        </where>
        ORDER BY  CONVERT(t.f_name USING gbk) asc
    </select>

    <select id="selectTCntrById" parameterType="Long" resultMap="TCntrResult">
        <include refid="selectTCntrVo"/>
        where f_id = #{fId}
    </select>

    <insert id="insertTCntr" parameterType="TCntr">
        insert into t_cntr
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fId != null">f_id,</if>
            <if test="fType != null">f_type,</if>
            <if test="fNo != null and fNo != ''">f_no,</if>
            <if test="fName != null and fName != ''">f_name,</if>
            <if test="fEname != null and fEname != ''">f_ename,</if>
            <if test="fUncode != null">f_uncode,</if>
            <if test="fTeu != null">f_teu,</if>
            <if test="fCbm != null">f_cbm,</if>
            <if test="fWeight != null">f_weight,</if>
            <if test="fCntrsize != null">f_cntrsize,</if>
            <if test="fStatus != null">f_status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fId != null">#{fId},</if>
            <if test="fType != null">#{fType},</if>
            <if test="fNo != null and fNo != ''">#{fNo},</if>
            <if test="fName != null and fName != ''">#{fName},</if>
            <if test="fEname != null and fEname != ''">#{fEname},</if>
            <if test="fUncode != null">#{fUncode},</if>
            <if test="fTeu != null">#{fTeu},</if>
            <if test="fCbm != null">#{fCbm},</if>
            <if test="fWeight != null">#{fWeight},</if>
            <if test="fCntrsize != null">#{fCntrsize},</if>
            <if test="fStatus != null">#{fStatus},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateTCntr" parameterType="TCntr">
        update t_cntr
        <trim prefix="SET" suffixOverrides=",">
            <if test="fType != null">f_type = #{fType},</if>
            <if test="fNo != null and fNo != ''">f_no = #{fNo},</if>
            <if test="fName != null and fName != ''">f_name = #{fName},</if>
            <if test="fEname != null and fEname != ''">f_ename = #{fEname},</if>
            <if test="fUncode != null">f_uncode = #{fUncode},</if>
            <if test="fTeu != null">f_teu = #{fTeu},</if>
            <if test="fCbm != null">f_cbm = #{fCbm},</if>
            <if test="fWeight != null">f_weight = #{fWeight},</if>
            <if test="fCntrsize != null">f_cntrsize = #{fCntrsize},</if>
            <if test="fStatus != null">f_status = #{fStatus},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where f_id = #{fId}
    </update>

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

    <delete id="deleteTCntrByIds" parameterType="String">
        delete from t_cntr where f_id in
        <foreach item="fId" collection="array" open="(" separator="," close=")">
            #{fId}
        </foreach>
    </delete>
    <select id="selectRcntrName" parameterType="TCntr" resultType="map">
        SELECT
        f_id as fId,
        f_no as fNo,
        f_type as fType,
        f_name as fName
        FROM
        t_cntr
        <where>
            f_status = 'T'
            <if test="fNo != null  and fNo != ''">and f_no like concat('%', #{fNo}, '%')</if>
        </where>
        ORDER BY  CONVERT(f_name USING gbk) asc
    </select>
    <select id="selectTCntrFNo" resultType="string">
        SELECT DISTINCT
	        f_no
        FROM
	    t_cntr
	    where f_status = 'T'
	    ORDER BY  CONVERT(f_no USING gbk) asc
    </select>
    <select id="selectRcntrFId" parameterType="TCntr" resultType="long">
        SELECT
        f_id as fId
        FROM
        t_cntr
        where f_no = #{fNo}
        and f_status = 'T'
        ORDER BY  CONVERT(f_name USING gbk) asc
    </select>
    <select id="selectTcnrFno" parameterType="object" resultMap="TCntrResult">
        SELECT
            f_id,
            f_no
        FROM
        t_cntr
        WHERE
        f_no = #{fNo}
    </select>
    <select id="selectTcnrFName" parameterType="object" resultMap="TCntrResult">
        SELECT
            f_id,
            f_no
        FROM
        t_cntr
        WHERE
        f_name = #{fName}
    </select>

    <select id="selectByIds" resultMap="TCntrResult">
        SELECT f_id, f_no, f_name FROM t_cntr
        WHERE f_id in
        <foreach collection="ids" item="id" index="index" open="(" separator="," close=")" >
            #{id}
        </foreach>
    </select>

</mapper>