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

    <resultMap type="TCntrno" id="TCntrnoResult">
        <result property="fId" column="f_id"/>
        <result property="fNo" column="f_no"/>
        <result property="fTypeid" column="f_typeid"/>
        <result property="fOwner" column="f_owner"/>
        <result property="fSource" column="f_source"/>
        <result property="fRent" column="f_rent"/>
        <result property="fUpdatetime" column="f_updatetime"/>
        <result property="fUpdateaddress" column="f_updateaddress"/>
        <result property="fUpdateef" column="f_updateEF"/>
        <result property="fCntrstatus" column="f_cntrstatus"/>
        <result property="fStatus" column="f_status"/>
        <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="fOpctnstatus" column="f_opctnstatus"/>
        <result property="fSealno" column="f_sealno"/>
        <result property="fBuildBoxTime"    column="f_build_box_time"    />
        <result property="fBoxTurtleYear"    column="f_box_turtle_year"    />
        <result property="fBoxTurtleMonth"    column="f_box_turtle_month"    />
        <result property="fBoxLord"    column="f_box_lord"    />
        <result property="fPactDealHorn"    column="f_pact_deal_horn"    />
        <result property="fMblno"    column="f_mblno"    />
        <result property="fBoxWeight"    column="f_box_weight"    />
        <result property="onHireStart"    column="on_hire_start"    />
        <result property="onHireEnd"    column="on_hire_end"    />
        <result property="fVsl" column="f_vsl"/>
        <result property="fVoy" column="f_voy"/>
    </resultMap>

    <sql id="selectTCntrnoVo">
        select f_id, f_no, f_typeid, f_owner, f_source, f_rent, f_updatetime, f_updateaddress, f_updateEF, f_cntrstatus, case when f_status = 'T' then '正常' else '停用' end as f_status,f_opctnstatus,f_sealno,create_by, create_time, update_by, update_time, remark,
               f_build_box_time,f_box_turtle_year,f_box_turtle_month,f_box_lord,f_pact_deal_horn,f_mblno,f_box_weight,on_hire_start,on_hire_end, f_vsl, f_voy from t_cntrno
    </sql>

    <select id="selectTCntrnoList" parameterType="TCntrno" resultMap="TCntrnoResult">
        <include refid="selectTCntrnoVo"/>
        <where>
            <if test="fNo != null  and fNo != ''">and f_no = #{fNo}</if>
            <if test="fTypeid != null ">and f_typeid = #{fTypeid}</if>
            <if test="fOwner != null  and fOwner != ''">and f_owner = #{fOwner}</if>
            <if test="fSource != null  and fSource != ''">and f_source = #{fSource}</if>
            <if test="fRent != null  and fRent != ''">and f_rent = #{fRent}</if>
            <if test="fUpdatetime != null ">and f_updatetime = #{fUpdatetime}</if>
            <if test="fUpdateaddress != null  and fUpdateaddress != ''">and f_updateaddress = #{fUpdateaddress}</if>
            <if test="fUpdateef != null  and fUpdateef != ''">and f_updateEF = #{fUpdateef}</if>
            <if test="fCntrstatus != null  and fCntrstatus != ''">and f_cntrstatus = #{fCntrstatus}</if>
            <if test="fStatus != null  and fStatus != ''">and f_status = #{fStatus}</if>
            <if test="fOpctnstatus != null  and fOpctnstatus != ''">and f_opctnstatus = #{fOpctnstatus}</if>
            <if test="fSealno != null  and fSealno != ''">and f_sealno = #{fSealno}</if>
            <if test='cLoadDate != null and cLoadDate[0] != null and cLoadDate[0]!= ""'>
                and create_time &gt;= #{cLoadDate[0]}
            </if>
            <if test='cLoadDate != null and cLoadDate[1] != null and cLoadDate[1]!= ""'>
                and create_time &lt;= #{cLoadDate[1]}
            </if>
            <if test="fBuildBoxTime != null "> and f_build_box_time = #{fBuildBoxTime}</if>
            <if test="fBoxTurtleYear != null  and fBoxTurtleYear != ''"> and f_box_turtle_year = #{fBoxTurtleYear}</if>
            <if test="fBoxTurtleMonth != null  and fBoxTurtleMonth != ''"> and f_box_turtle_month = #{fBoxTurtleMonth}</if>
            <if test="fBoxLord != null  and fBoxLord != ''"> and f_box_lord = #{fBoxLord}</if>
            <if test="fPactDealHorn != null  and fPactDealHorn != ''"> and f_pact_deal_horn = #{fPactDealHorn}</if>
            <if test="fMblno != null  and fMblno != ''"> and f_mblno = #{fMblno}</if>
            <if test="fBoxWeight != null "> and f_box_weight = #{fBoxWeight}</if>
            <if test="onHireStart != null "> and on_hire_start = #{onHireStart}</if>
            <if test="onHireEnd != null "> and on_hire_end = #{onHireEnd}</if>
        </where>
    </select>
    <select id="selectTcntrnoMessage" parameterType="TCntrno" resultMap="TCntrnoResult">
        SELECT
        tc.f_id,
        tc.f_no,
        tc.f_typeid,
        t.f_no typeidName,
        t.f_cntrsize cntrsize,
        prs.dict_label cntrsizeName,
        tc.f_owner,
        pro.dict_label ownerName,
        tc.f_source,
        sd.dict_label sourceName,
        tc.f_rent,
        sdd.dict_label rentName,
        tc.f_updatetime,
        tc.f_updateaddress,
        address.f_name addressName,
        tc.f_updateEF,
        sdda.dict_label updateEFName,
        tc.f_cntrstatus,
        pr.dict_label cntrstatusName,
        tc.f_status,
        case when tc.f_status = 'T' then '启用' else '停用' end as fStatusName,
        prd.dict_label opctnstatusName,
        tc.create_by,
        tc.create_time,
        tc.update_by,
        tc.update_time,
        tc.remark,
        tc.f_build_box_time,
        tc.f_box_turtle_year,
        tc.f_box_turtle_month,
        tc.f_box_lord,
        tc.f_pact_deal_horn,
        tc.on_hire_start,
        tc.on_hire_end,
        tc.f_mblno
        FROM
        t_cntrno tc
        LEFT JOIN sys_dict_data pro ON pro.dict_value = tc.f_owner
        AND pro.dict_type = 'f_owner'
        LEFT JOIN sys_dict_data sd ON sd.dict_value = tc.f_source
        AND sd.dict_type = 'f_source'
        LEFT JOIN sys_dict_data sdd ON sdd.dict_value = tc.f_rent
        AND sdd.dict_type = 'f_rent'
        LEFT JOIN sys_dict_data sdda ON sdda.dict_value = tc.f_updateEF
        AND sdda.dict_type = 'f_updateEF'
        LEFT JOIN sys_dict_data pr ON pr.dict_value = tc.f_cntrstatus
        AND pr.dict_type = 'f_cntrstatus'
        LEFT JOIN t_cntr t ON tc.f_typeid = t.f_id
        LEFT JOIN sys_dict_data prs ON prs.dict_value = t.f_cntrsize
        AND prs.dict_type = 'f_cntrsize'
        LEFT JOIN sys_dict_data prd ON prd.dict_value = tc.f_opctnstatus
        AND prd.dict_type = 'f_opctnstatus'
        LEFT JOIN t_address address ON address.f_id = tc.f_updateaddress
        <where>
            <if test="tc.fNo != null  and tc.fNo != ''">and tc.f_no like concat('%', #{tc.fNo}, '%') </if>
            <if test="tc.fTypeid != null ">and tc.f_typeid = #{tc.fTypeid}</if>
            <if test="tc.fOwner != null  and tc.fOwner != ''">and tc.f_owner = #{tc.fOwner}</if>
            <if test="tc.fSource != null  and tc.fSource != ''">and tc.f_source = #{tc.fSource}</if>
            <if test="tc.fRent != null  and tc.fRent != ''">and tc.f_rent = #{tc.fRent}</if>
            <if test="tc.fUpdatetime != null ">and tc.f_updatetime = #{tc.fUpdatetime}</if>
            <if test='tc.fUpdateaddress != null  and tc.fUpdateaddress != "" and tc.fUpdateaddress != "0"'>and tc.f_updateaddress = #{tc.fUpdateaddress}</if>
            <if test='tc.fUpdateaddress != null  and tc.fUpdateaddress != "" and tc.fUpdateaddress == "0"'>and tc.f_updateaddress = ''</if>
            <if test="tc.fUpdateef != null  and tc.fUpdateef != ''">and tc.f_updateEF = #{tc.fUpdateef}</if>
            <if test="tc.fCntrstatus != null  and tc.fCntrstatus != ''">and tc.f_cntrstatus = #{tc.fCntrstatus}</if>
            <if test="tc.fStatus != null  and tc.fStatus != ''">and tc.f_status = #{tc.fStatus}</if>
            <if test="tc.fOpctnstatus != null  and tc.fOpctnstatus != ''">and tc.f_opctnstatus = #{tc.fOpctnstatus}</if>
            <if test="tc.fSealno != null  and tc.fSealno != ''">and tc.f_sealno = #{tc.fSealno}</if>
            <if test='tc.cLoadDate != null and tc.cLoadDate[0] != null and tc.cLoadDate[0]!= ""'>
                and tc.create_time &gt;= #{tc.cLoadDate[0]}
            </if>
            <if test='tc.cLoadDate != null and tc.cLoadDate[1] != null and tc.cLoadDate[1]!= ""'>
                and tc.create_time &lt;= #{tc.cLoadDate[1]}
            </if>
            <if test="address != null  and address != ''">and address.f_name = #{address}</if>
            <if test="typeidName != null  and typeidName != ''">and t.f_no = #{typeidName}</if>
            <if test="cntrstatusName != null  and cntrstatusName != ''">and pr.dict_label = #{cntrstatusName}</if>
            <if test="updateEFName != null  and updateEFName != ''">and sdda.dict_label = #{updateEFName}</if>
            <if test="cntrsize != null ">and t.f_cntrsize = #{cntrsize}</if>
            <if test="tc.fBuildBoxTime != null "> and tc.f_build_box_time = #{fBuildBoxTime}</if>
            <if test="tc.fBoxTurtleYear != null  and tc.fBoxTurtleYear != ''"> and tc.f_box_turtle_year = #{fBoxTurtleYear}</if>
            <if test="tc.fBoxTurtleMonth != null  and tc.fBoxTurtleMonth != ''"> and tc.f_box_turtle_month = #{fBoxTurtleMonth}</if>
            <if test="tc.fBoxLord != null  and tc.fBoxLord != ''"> and tc.f_box_lord = #{tc.fBoxLord}</if>
            <if test="tc.fPactDealHorn != null  and tc.fPactDealHorn != ''"> and tc.f_pact_deal_horn = #{tc.fPactDealHorn}</if>
            <if test="tc.fMblno != null  and tc.fMblno != ''"> and tc.f_mblno = #{tc.fMblno}</if>
            <if test="tc.fBoxWeight != null "> and tc.f_box_weight = #{tc.fBoxWeight}</if>
            <if test='tc.onHireStartList != null and tc.onHireStartList[0] != null and tc.onHireStartList[0]!= ""'>
                and tc.on_hire_start &gt;= #{tc.onHireStartList[0]}
            </if>
            <if test='tc.onHireStartList != null and tc.onHireStartList[1] != null and tc.onHireStartList[1]!= ""'>
                and tc.on_hire_start &lt;= #{tc.onHireStartList[1]}
            </if>
            <if test='tc.onHireEnfList != null and tc.onHireEnfList[0] != null and tc.onHireEnfList[0]!= ""'>
                and tc.on_hire_end &gt;= #{tc.onHireEnfList[0]}
            </if>
            <if test='tc.onHireEnfList != null and tc.onHireEnfList[1] != null and tc.onHireEnfList[1]!= ""'>
                and tc.on_hire_end &lt;= #{tc.onHireEnfList[1]}
            </if>
        </where>
        ORDER BY tc.f_no,CONVERT(tc.f_updateaddress USING gbk),CONVERT(t.f_no USING gbk),
        tc.f_updateEF,tc.f_cntrstatus,tc.f_owner
    </select>

    <select id="selectTCntrnoById" parameterType="Long" resultMap="TCntrnoResult">
        SELECT
        tc.f_id,
        tc.f_no,
        tc.f_typeid,
        tc.f_sealno,
        t.f_name typeidName,
		t.f_cntrsize cntrsize,
		prs.dict_label cntrsizeName,
        tc.f_owner,
        pro.dict_label ownerName,
        tc.f_source,
        sd.dict_label sourceName,
        tc.f_rent,
        sdd.dict_label rentName,
        tc.f_updatetime,
        tc.f_updateaddress,
        address.f_name addressName,
        tc.f_updateEF,
        sdda.dict_label updateEFName,
        tc.f_cntrstatus,
        pr.dict_label cntrstatusName,
        tc.f_status,
        case when tc.f_status = 'T' then '启用' else '停用' end as fStatusName,
        tc.f_opctnstatus,
        tc.create_by,
        tc.create_time,
        tc.update_by,
        tc.update_time,
        tc.remark,
        tc.f_build_box_time,
        tc.f_box_turtle_year,
        tc.f_box_turtle_month,
        tc.f_box_lord,
        tc.f_pact_deal_horn,
        tc.on_hire_start,
        tc.on_hire_end
        FROM
        t_cntrno tc
        LEFT JOIN sys_dict_data pro ON pro.dict_value = tc.f_owner
        AND pro.dict_type = 'f_owner'
        LEFT JOIN sys_dict_data sd ON sd.dict_value = tc.f_source
        AND sd.dict_type = 'f_source'
        LEFT JOIN sys_dict_data sdd ON sdd.dict_value = tc.f_rent
        AND sdd.dict_type = 'f_rent'
        LEFT JOIN sys_dict_data sdda ON sdda.dict_value = tc.f_updateEF
        AND sdda.dict_type = 'f_updateEF'
        LEFT JOIN sys_dict_data pr ON pr.dict_value = tc.f_cntrstatus
        AND pr.dict_type = 'f_cntrstatus'
        LEFT JOIN t_cntr t ON tc.f_typeid = t.f_id
		LEFT JOIN sys_dict_data prs ON prs.dict_value = t.f_cntrsize
        AND prs.dict_type = 'f_cntrsize'
        LEFT JOIN t_address address ON address.f_id = tc.f_updateaddress
        where tc.f_id = #{fId}
    </select>
    <select id="selectTCnTrNoByfNo" parameterType="string" resultMap="TCntrnoResult">
        SELECT
        tc.f_id,
        tc.f_no,
        tc.f_typeid,
        tc.f_sealno,
        t.f_no typeidName,
		t.f_cntrsize cntrsize,
		prs.dict_label cntrsizeName,
        tc.f_owner,
        pro.dict_label ownerName,
        tc.f_source,
        sd.dict_label sourceName,
        tc.f_rent,
        sdd.dict_label rentName,
        tc.f_updatetime,
        tc.f_updateaddress,
        address.f_name addressName,
        tc.f_updateEF,
        sdda.dict_label updateEFName,
        tc.f_cntrstatus,
        pr.dict_label cntrstatusName,
        tc.f_status,
        case when tc.f_status = 'T' then '启用' else '停用' end as fStatusName,
        tc.f_opctnstatus,
        tc.create_by,
        tc.create_time,
        tc.update_by,
        tc.update_time,
        tc.remark,
        tc.f_build_box_time,
        tc.f_box_turtle_year,
        tc.f_box_turtle_month,
        tc.f_box_lord,
        tc.f_pact_deal_horn
        FROM
        t_cntrno tc
        LEFT JOIN sys_dict_data pro ON pro.dict_value = tc.f_owner
        AND pro.dict_type = 'f_owner'
        LEFT JOIN sys_dict_data sd ON sd.dict_value = tc.f_source
        AND sd.dict_type = 'f_source'
        LEFT JOIN sys_dict_data sdd ON sdd.dict_value = tc.f_rent
        AND sdd.dict_type = 'f_rent'
        LEFT JOIN sys_dict_data sdda ON sdda.dict_value = tc.f_updateEF
        AND sdda.dict_type = 'f_updateEF'
        LEFT JOIN sys_dict_data pr ON pr.dict_value = tc.f_cntrstatus
        AND pr.dict_type = 'f_cntrstatus'
        LEFT JOIN t_cntr t ON tc.f_typeid = t.f_id
		LEFT JOIN sys_dict_data prs ON prs.dict_value = t.f_cntrsize
        AND prs.dict_type = 'f_cntrsize'
        LEFT JOIN t_address address ON address.f_id = tc.f_updateaddress
        where tc.f_no = #{fNo} and tc.f_status = 'T'
    </select>

    <insert id="insertTCntrno" parameterType="TCntrno">
        insert into t_cntrno
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fId != null">f_id,</if>
            <if test="fNo != null and fNo != ''">f_no,</if>
            <if test="fTypeid != null">f_typeid,</if>
            <if test="fOwner != null and fOwner != ''">f_owner,</if>
            <if test="fSource != null">f_source,</if>
            <if test="fRent != null">f_rent,</if>
            <if test="fUpdatetime != null">f_updatetime,</if>
            <if test="fUpdateaddress != null and fUpdateaddress != ''">f_updateaddress,</if>
            <if test="fUpdateef != null and fUpdateef != ''">f_updateEF,</if>
            <if test="fCntrstatus != null and fCntrstatus != ''">f_cntrstatus,</if>
            <if test="fStatus != null">f_status,</if>
            <if test="fOpctnstatus != null  and fOpctnstatus != ''">f_opctnstatus,</if>
            <if test="fSealno != null  and fSealno != ''">f_sealno,</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>
            <if test="fBuildBoxTime != null">f_build_box_time,</if>
            <if test="fBoxTurtleYear != null">f_box_turtle_year,</if>
            <if test="fBoxTurtleMonth != null">f_box_turtle_month,</if>
            <if test="fBoxLord != null">f_box_lord,</if>
            <if test="fPactDealHorn != null">f_pact_deal_horn,</if>
            <if test="fMblno != null">f_mblno,</if>
            <if test="fBoxWeight != null">f_box_weight,</if>
            <if test="onHireStart != null">on_hire_start,</if>
            <if test="onHireEnd != null">on_hire_end,</if>
            <if test="fVsl != null">f_vsl,</if>
            <if test="fVoy != null">f_voy,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fId != null">#{fId},</if>
            <if test="fNo != null and fNo != ''">#{fNo},</if>
            <if test="fTypeid != null">#{fTypeid},</if>
            <if test="fOwner != null and fOwner != ''">#{fOwner},</if>
            <if test="fSource != null">#{fSource},</if>
            <if test="fRent != null">#{fRent},</if>
            <if test="fUpdatetime != null">#{fUpdatetime},</if>
            <if test="fUpdateaddress != null and fUpdateaddress != ''">#{fUpdateaddress},</if>
            <if test="fUpdateef != null and fUpdateef != ''">#{fUpdateef},</if>
            <if test="fCntrstatus != null and fCntrstatus != ''">#{fCntrstatus},</if>
            <if test="fStatus != null">#{fStatus},</if>
            <if test="fOpctnstatus != null  and fOpctnstatus != ''">#{fOpctnstatus},</if>
            <if test="fSealno != null  and fSealno != ''">#{fSealno},</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>
            <if test="fBuildBoxTime != null">#{fBuildBoxTime},</if>
            <if test="fBoxTurtleYear != null">#{fBoxTurtleYear},</if>
            <if test="fBoxTurtleMonth != null">#{fBoxTurtleMonth},</if>
            <if test="fBoxLord != null">#{fBoxLord},</if>
            <if test="fPactDealHorn != null">#{fPactDealHorn},</if>
            <if test="fMblno != null">#{fMblno},</if>
            <if test="fBoxWeight != null">#{fBoxWeight},</if>
            <if test="onHireStart != null">#{onHireStart},</if>
            <if test="onHireEnd != null">#{onHireEnd},</if>
            <if test="fVsl != null">#{fVsl},</if>
            <if test="fVoy != null">#{fVoy},</if>
        </trim>
    </insert>

    <update id="updateTCntrno" parameterType="TCntrno">
        update t_cntrno
        <trim prefix="SET" suffixOverrides=",">
            <if test="fNo != null and fNo != ''">f_no = #{fNo},</if>
            <if test="fTypeid != null">f_typeid = #{fTypeid},</if>
            <if test="fOwner != null and fOwner != ''">f_owner = #{fOwner},</if>
            <if test="fSource != null">f_source = #{fSource},</if>
            <if test="fRent != null">f_rent = #{fRent},</if>
            <if test="fUpdatetime != null">f_updatetime = #{fUpdatetime},</if>
            <if test="fUpdateaddress != null and fUpdateaddress != ''">f_updateaddress = #{fUpdateaddress},</if>
            <if test="fUpdateef != null and fUpdateef != ''">f_updateEF = #{fUpdateef},</if>
            <if test="fCntrstatus != null and fCntrstatus != ''">f_cntrstatus = #{fCntrstatus},</if>
            <if test="fStatus != null">f_status = #{fStatus},</if>
            <if test="fOpctnstatus != null  and fOpctnstatus != ''">f_opctnstatus = #{fOpctnstatus},</if>
            <if test="fSealno != null  and fSealno != ''">f_sealno = #{fSealno},</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>
            <if test="fBuildBoxTime != null">f_build_box_time = #{fBuildBoxTime},</if>
            <if test="fBoxTurtleYear != null">f_box_turtle_year = #{fBoxTurtleYear},</if>
            <if test="fBoxTurtleMonth != null">f_box_turtle_month = #{fBoxTurtleMonth},</if>
            <if test="fBoxLord != null">f_box_lord = #{fBoxLord},</if>
            <if test="fPactDealHorn != null">f_pact_deal_horn = #{fPactDealHorn},</if>
            <if test="fMblno != null">f_mblno = #{fMblno},</if>
            <if test="fBoxWeight != null">f_box_weight = #{fBoxWeight},</if>
            <if test="onHireStart != null">on_hire_start = #{onHireStart},</if>
            <if test="onHireEnd != null">on_hire_end = #{onHireEnd},</if>
            <if test="fVsl != null">f_vsl = #{fVsl},</if>
            <if test="fVoy != null">f_voy = #{fVoy},</if>
        </trim>
        where f_id = #{fId}
    </update>
    <update id="updateTCntrnoByfNo" parameterType="TCntrno">
        update t_cntrno
        <trim prefix="SET" suffixOverrides=",">
            <if test="fNo != null and fNo != ''">f_no = #{fNo},</if>
            <if test="fTypeid != null">f_typeid = #{fTypeid},</if>
            <if test="fOwner != null and fOwner != ''">f_owner = #{fOwner},</if>
            <if test="fSource != null">f_source = #{fSource},</if>
            <if test="fRent != null">f_rent = #{fRent},</if>
            <if test="fUpdatetime != null">f_updatetime = #{fUpdatetime},</if>
            <if test="fUpdateaddress != null and fUpdateaddress != ''">f_updateaddress = #{fUpdateaddress},</if>
            <if test="fUpdateef != null and fUpdateef != ''">f_updateEF = #{fUpdateef},</if>
            <if test="fCntrstatus != null and fCntrstatus != ''">f_cntrstatus = #{fCntrstatus},</if>
            <if test="fStatus != null">f_status = #{fStatus},</if>
            <if test="fOpctnstatus != null  and fOpctnstatus != ''">f_opctnstatus = #{fOpctnstatus},</if>
            <if test="fSealno != null  and fSealno != ''">f_sealno = #{fSealno},</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>
            <if test="remark == null">remark = null,</if>
            <if test="fBuildBoxTime != null">f_build_box_time = #{fBuildBoxTime},</if>
            <if test="fBoxTurtleYear != null">f_box_turtle_year = #{fBoxTurtleYear},</if>
            <if test="fBoxTurtleMonth != null">f_box_turtle_month = #{fBoxTurtleMonth},</if>
            <if test="fBoxLord != null">f_box_lord = #{fBoxLord},</if>
            <if test="fPactDealHorn != null">f_pact_deal_horn = #{fPactDealHorn},</if>
            <if test="fMblno != null">f_mblno = #{fMblno},</if>
            <if test="fBoxWeight != null">f_box_weight = #{fBoxWeight},</if>
            <if test="onHireStart != null">on_hire_start = #{onHireStart},</if>
            <if test="onHireEnd != null">on_hire_end = #{onHireEnd},</if>
            <if test="fVsl != null">f_vsl = #{fVsl},</if>
            <if test="fVoy != null">f_voy = #{fVoy},</if>
        </trim>
        where f_no = #{fNo}
    </update>

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

    <delete id="deleteTCntrnoByIds" parameterType="String">
        delete from t_cntrno where f_id in
        <foreach item="fId" collection="array" open="(" separator="," close=")">
            #{fId}
        </foreach>
    </delete>
    <!--批量更新数据状态-->
    <update id="updateTcntrnoStatus" parameterType="string">
        update t_cntrno
        set f_status = 'F'
        where f_id in
        <foreach item="fId" collection="array" open="(" separator="," close=")">
            #{fId}
        </foreach>
    </update>
    <!--获取集装动态分布信息 -->
    <select id="getTCntrnoMessage" parameterType="string" resultType="map">
        SELECT
        container.*,
        box.*
        FROM
        (
        SELECT
        tt.f_updateaddress AS 地点
        <if test=" sql != null and sql != ''">
            ,${sql}
        </if>
        FROM
        (
        SELECT
        tc.f_updateaddress f_updateaddress,
        tc.typeidCount typeidCount,
        t.f_no f_no
        FROM
        (
        SELECT
        ta.f_name f_updateaddress,
        tcn.f_typeid,
        COUNT( tcn.f_updateaddress ) typeidCount
        FROM
        t_cntrno tcn
        LEFT JOIN t_address ta ON tcn.f_updateaddress = ta.f_id
        WHERE
        tcn.f_status = 'T'
        GROUP BY
        tcn.f_updateaddress,
        tcn.f_typeid
        ) tc
        LEFT JOIN t_cntr t ON tc.f_typeid = t.f_id
        ) tt
        GROUP BY
        tt.f_updateaddress
        ) container
        LEFT JOIN (
        SELECT
        a.f_updateaddress
        <if test=" stand != null and stand != ''">
            ,${stand}
        </if>
        FROM
        (
        SELECT
        tc.f_updateaddress f_updateaddress,
        tc.f_updateEF f_updateEF,
        tc.typeName typeName,
        tc.efCount efCount,
        sdda.dict_label dict_label
        FROM
        (
        SELECT
        ta.f_name f_updateaddress,
        tct.f_updateEF,
        tc.f_no typeName,
        COUNT( tct.f_updateaddress ) efCount
        FROM
        t_cntrno tct
        LEFT JOIN t_address ta ON tct.f_updateaddress = ta.f_id
        LEFT JOIN t_cntr tc ON tct.f_typeid = tc.f_id
        WHERE
        tct.f_status = 'T'
        GROUP BY
        tct.f_updateaddress,
        tct.f_updateEF,
        tct.f_typeid
        ) tc
        LEFT JOIN sys_dict_data sdda ON sdda.dict_value = tc.f_updateEF
        AND sdda.dict_type = 'f_updateEF'
        ) a
        GROUP BY
        a.f_updateaddress
        ) box ON container.地点 = box.f_updateaddress
	<where>
        <if test="tCntrno.fUpdateaddress != null and tCntrno.fUpdateaddress != ''">
        container.地点   like concat('%', #{tCntrno.fUpdateaddress}, '%')</if>
    </where>
   </select>
    <select id="selectTCntrnoFNo" parameterType="TCntrno" resultMap="TCntrnoResult">
        SELECT
            f_id,
            f_no
        FROM
        t_cntrno
        WHERE
        f_no = #{fNo}
    </select>
    <insert id="insertTCntrnoList" parameterType="list">
        insert into t_cntrno
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fId != null">f_id,</if>
            <if test="fNo != null and fNo != ''">f_no,</if>
            <if test="fTypeid != null">f_typeid,</if>
            <if test="fOwner != null and fOwner != ''">f_owner,</if>
            <if test="fSource != null">f_source,</if>
            <if test="fRent != null">f_rent,</if>
            <if test="fUpdatetime != null">f_updatetime,</if>
            <if test="fUpdateaddress != null and fUpdateaddress != ''">f_updateaddress,</if>
            <if test="fUpdateef != null and fUpdateef != ''">f_updateEF,</if>
            <if test="fCntrstatus != null and fCntrstatus != ''">f_cntrstatus,</if>
            <if test="fStatus != null">f_status,</if>
            <if test="fOpctnstatus != null  and fOpctnstatus != ''">f_opctnstatus,</if>
            <if test="fSealno != null  and fSealno != ''">f_sealno,</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>
            <if test="fVsl != null">f_vsl,</if>
            <if test="fVoy != null">f_voy,</if>
        </trim>
        <foreach collection="list" item="item" separator=",">
            <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="fId != null">#{fId},</if>
                <if test="fNo != null and fNo != ''">#{fNo},</if>
                <if test="fTypeid != null">#{fTypeid},</if>
                <if test="fOwner != null and fOwner != ''">#{fOwner},</if>
                <if test="fSource != null">#{fSource},</if>
                <if test="fRent != null">#{fRent},</if>
                <if test="fUpdatetime != null">#{fUpdatetime},</if>
                <if test="fUpdateaddress != null and fUpdateaddress != ''">#{fUpdateaddress},</if>
                <if test="fUpdateef != null and fUpdateef != ''">#{fUpdateef},</if>
                <if test="fCntrstatus != null and fCntrstatus != ''">#{fCntrstatus},</if>
                <if test="fStatus != null">#{fStatus},</if>
                <if test="fOpctnstatus != null  and fOpctnstatus != ''">#{fOpctnstatus},</if>
                <if test="fSealno != null  and fSealno != ''">#{fSealno},</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>
                <if test="fVsl != null">#{fVsl},</if>
                <if test="fVoy != null">#{fVoy},</if>
            </trim>
        </foreach>
    </insert>
    <select id="getTcntrnoFno" parameterType="TCntrno" resultType="map">
        SELECT
        tc.f_no,
        address.f_name addressName,
        sdda.dict_label updateEFName
        FROM
        t_cntrno tc
        LEFT JOIN sys_dict_data sdda ON sdda.dict_value = tc.f_updateEF
        AND sdda.dict_type = 'f_updateEF'
        LEFT JOIN t_address address ON address.f_id = tc.f_updateaddress
        <where>
            tc.f_status = 'T'
            <if test="fNo != null  and fNo != ''">and tc.f_no like concat('%', #{fNo}, '%') </if>
            <if test="fUpdateaddress != null  and fUpdateaddress != ''">and tc.f_updateaddress = #{fUpdateaddress}</if>
            <if test="fUpdateef != null  and fUpdateef != ''">and tc.f_updateEF = #{fUpdateef}</if>
        </where>
        ORDER BY tc.f_no
    </select>
    <!--获取箱分布情况-->
    <select id="boxDistributionStatistics" parameterType="TCntrno" resultType="com.ruoyi.shipping.excel.BoxMessage">
        SELECT
        MAX(case when tc.fNo = '20GP' then tc.boxNumber ELSE 0 end) AS 'TWENTYGP',
        MAX(case when tc.fNo = '20RF' then tc.boxNumber ELSE 0 end) AS 'TWENTYRF',
        MAX(case when tc.fNo = '20OT' then tc.boxNumber ELSE 0 end) AS 'TWENTYOT',
        MAX(case when tc.fNo = '20FR' then tc.boxNumber ELSE 0 end) AS 'TWENTYFR',
        MAX(case when tc.fNo = '20HC' then tc.boxNumber ELSE 0 end) AS 'TWENTYTK',
        MAX(case when tc.fNo = '40GP' then tc.boxNumber ELSE 0 end) AS 'FORTYGP',
        MAX(case when tc.fNo = '40HC' then tc.boxNumber ELSE 0 end) AS 'FORTYHC',
        MAX(case when tc.fNo = '40HR' then tc.boxNumber ELSE 0 end) AS 'FORTYHR',
        MAX(case when tc.fNo = '40FR' then tc.boxNumber ELSE 0 end) AS 'FORTYFR',
        MAX(case when tc.fNo = '40TK' then tc.boxNumber ELSE 0 end) AS 'FORTYTK',
        MAX(case when tc.fNo = '40OT' then tc.boxNumber ELSE 0 end) AS 'FORTYOT'
        FROM
        (
        SELECT
        IFNULL( COUNT( 1 ), 0 ) boxNumber,
        tr.f_no fNo,
        sd.dict_label opCTnStatusName
        FROM
        t_cntrno tc
        LEFT JOIN t_cntr tr ON tc.f_typeid = tr.f_id
        LEFT JOIN t_address ta ON tc.f_updateaddress = ta.f_id
        LEFT JOIN sys_dict_data sd ON tc.f_opctnstatus = sd.dict_value
        AND sd.dict_type = 'f_opctnstatus'
        <where>
            tc.f_status = 'T'
            <if test="fUpdateaddress != null  and fUpdateaddress != ''">and tc.f_updateaddress = #{fUpdateaddress}</if>
            <if test="fOpctnstatus != null  and fOpctnstatus != ''">and tc.f_opctnstatus = #{fOpctnstatus}</if>
            <if test="remark != null">and tc.remark = #{remark}</if>
            <if test="fUpdateef != null and fUpdateef != ''">and tc.f_updateEF = #{fUpdateef}</if>
            <if test="fCntrstatus != null and fCntrstatus != ''">and tc.f_cntrstatus = #{fCntrstatus}</if>
        </where>
        GROUP BY
        LEFT ( tr.f_no, 2 ),
        RIGHT ( tr.f_no, 2 )
        )tc
    </select>
    <!--获取箱地点为港口信息情况-->
    <select id="getBoxPortMessage" parameterType="TCntrno" resultMap="TCntrnoResult">
    SELECT
DISTINCT
	IFNULL(ta.f_portid, 0) fUpdateaddress,
	IFNULL(tr.f_name,'无') addressName
FROM
	t_cntrno tc
	LEFT JOIN
	t_address ta ON ta.f_id = tc.f_updateaddress
	LEFT JOIN t_address tr ON ta.f_portid = tr.f_id
	LEFT JOIN sys_dict_data sd ON ta.f_types = sd.dict_value AND sd.dict_type = 'f_types'
	WHERE sd.dict_label != '港口'
	UNION
	    SELECT
DISTINCT
	IFNULL(tc.f_updateaddress,0) fUpdateaddress,
	IFNULL(ta.f_name ,'无') addressName
FROM
	t_cntrno tc
	LEFT JOIN
	t_address ta ON ta.f_id = tc.f_updateaddress
	LEFT JOIN sys_dict_data sd ON ta.f_types = sd.dict_value AND sd.dict_type = 'f_types'
	WHERE sd.dict_label = '港口'
    </select>
    <!--获取箱地点不为港口信息情况-->
    <select id="getBoxAddressMessage" parameterType="TCntrno" resultMap="TCntrnoResult">
        SELECT
DISTINCT
	tc.f_updateaddress,
	ta.f_name addressName,
	ta.f_name portName
FROM
	t_cntrno tc
	LEFT JOIN
	t_address ta ON ta.f_id = tc.f_updateaddress
	LEFT JOIN sys_dict_data sd ON ta.f_types = sd.dict_value AND sd.dict_type = 'f_types'
	WHERE sd.dict_label = '港口'
	UNION
	SELECT
DISTINCT
	tc.f_updateaddress,
	ta.f_name addressName,
	IFNULL(tr.f_name,'无')portName
FROM
	t_cntrno tc
	LEFT JOIN
	t_address ta ON ta.f_id = tc.f_updateaddress
	LEFT JOIN t_address tr ON ta.f_portid = tr.f_id
	LEFT JOIN sys_dict_data sd ON ta.f_types = sd.dict_value AND sd.dict_type = 'f_types'
	WHERE sd.dict_label != '港口'
    </select>
    <!--获取地点为在船的备注-->
    <select id="getBoxRemark" parameterType="TCntrno" resultMap="TCntrnoResult">
    SELECT
DISTINCT
	remark
FROM
	t_cntrno
	WHERE
	f_updateaddress = #{fUpdateaddress}
	AND remark IS NOT NULL
    </select>

    <select id="homeBox" resultType="map">
        SELECT
	ta.f_name addressName,
	IFNULL(COUNT(1),0) boxNumber
FROM
	t_cntrno tc
	LEFT JOIN t_address ta ON tc.f_updateaddress = ta.f_id
WHERE
	ta.f_name != '在船'
    AND tc.f_status != 'F'
GROUP BY tc.f_updateaddress
UNION
SELECT
	'在船' addressName,
	IFNULL(COUNT(1),0) boxNumber
FROM
	t_cntrno tc
	LEFT JOIN t_address ta ON tc.f_updateaddress = ta.f_id
WHERE
	ta.f_name = '在船'
    AND tc.f_status != 'F'
    </select>

    <select id="homeBoxCount" resultType="map">
        SELECT tc.f_vsl,
               tc.f_voy,
               IFNULL(COUNT(1), 0) boxNumber
        FROM t_cntrno tc LEFT JOIN t_address ta ON ta.f_id = tc.f_updateaddress
        WHERE tc.f_status != 'F'
            AND ta.f_name = '在船'
            AND f_vsl IS NOT NULL
            AND f_voy IS NOT NULL
        GROUP BY f_voy, f_vsl
    </select>

    <update id="updateHire" parameterType="TCntrno">
        update t_cntrno
        <trim prefix="SET" suffixOverrides=",">
            <if test="fNo != null and fNo != ''">f_no = #{fNo},</if>
            <if test="fTypeid != null">f_typeid = #{fTypeid},</if>
            <if test="fOwner != null and fOwner != ''">f_owner = #{fOwner},</if>
            <if test="fSource != null">f_source = #{fSource},</if>
            <if test="fRent != null">f_rent = #{fRent},</if>
            <if test="fUpdatetime != null">f_updatetime = #{fUpdatetime},</if>
            <if test="fUpdateaddress != null and fUpdateaddress != ''">f_updateaddress = #{fUpdateaddress},</if>
            <if test="fUpdateef != null and fUpdateef != ''">f_updateEF = #{fUpdateef},</if>
            <if test="fCntrstatus != null and fCntrstatus != ''">f_cntrstatus = #{fCntrstatus},</if>
            <if test="fStatus != null">f_status = #{fStatus},</if>
            <if test="fSealno != null">f_sealno = #{fSealno},</if>
            <if test="fOpctnstatus != null">f_opctnstatus = #{fOpctnstatus},</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>
            <if test="fBuildBoxTime != null">f_build_box_time = #{fBuildBoxTime},</if>
            <if test="fBoxTurtleYear != null">f_box_turtle_year = #{fBoxTurtleYear},</if>
            <if test="fBoxTurtleMonth != null">f_box_turtle_month = #{fBoxTurtleMonth},</if>
            <if test="fBoxLord != null">f_box_lord = #{fBoxLord},</if>
            <if test="fPactDealHorn != null">f_pact_deal_horn = #{fPactDealHorn},</if>
            <if test="fMblno != null">f_mblno = #{fMblno},</if>
            <if test="fBoxWeight != null">f_box_weight = #{fBoxWeight},</if>
            <if test="onHireStart != null">on_hire_start = #{onHireStart},</if>
            <if test="onHireEnd != null">on_hire_end = #{onHireEnd},</if>
            <if test="fVsl != null">f_vsl = #{fVsl},</if>
            <if test="fVoy != null">f_voy = #{fVoy},</if>
        </trim>
        where f_id in
        <foreach item="fId" collection="cntrnoList" open="(" separator="," close=")">
            #{fId}
        </foreach>
    </update>

</mapper>