<?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="cn.gov.customs.wxjy.analyze.dao.GoodsEntryDao">
    <resultMap id="EntryResultMap" type="cn.gov.customs.wxjy.analyze.pojo.Entry">
        <id column="ID" jdbcType="VARCHAR" property="id"/>
        <result column="ENTRY_ID" jdbcType="VARCHAR" property="entryId"/>
        <result column="MAIN_STATUS" jdbcType="VARCHAR" property="mainStatus"/>
        <result column="PASS_MODE" jdbcType="VARCHAR" property="passMode"/>
        <result column="TRAF_MODE" jdbcType="VARCHAR" property="trafMode"/>
        <result column="I_E_FLAG" jdbcType="VARCHAR" property="ieFlag"/>
        <result column="I_E_PORT" jdbcType="VARCHAR" property="iePort"/>
        <result column="DECL_PORT" jdbcType="VARCHAR" property="declPort"/>
        <result column="CUSTOMS_CODE" jdbcType="VARCHAR" property="customsCode"/>
        <result column="I_E_DATE" jdbcType="TIMESTAMP" property="ieDate"/>
        <result column="DECL_DATE" jdbcType="TIMESTAMP" property="declDate"/>
        <result column="DECL_ADVANCE_FLAG" jdbcType="VARCHAR" property="declAdvanceFlag"/>
        <result column="ACCEPT_DATE" jdbcType="TIMESTAMP" property="acceptDate"/>
        <result column="EX_IN_PORT_DATE" jdbcType="TIMESTAMP" property="exInPortDate"/>
        <result column="CONSIGN_SCC" jdbcType="VARCHAR" property="consignScc"/>
        <result column="CONSIGN_CODE" jdbcType="VARCHAR" property="consignCode"/>
        <result column="CONSIGN_NAME" jdbcType="VARCHAR" property="consignName"/>
        <result column="CONSIGN_SCC" jdbcType="VARCHAR" property="consignScc"/>
        <result column="FRN_CONSIGN_CODE" jdbcType="VARCHAR" property="frnConsignCode"/>
        <result column="FRN_CONSIGN_NAME" jdbcType="VARCHAR" property="frnConsignName"/>
        <result column="TRADE_MODE" jdbcType="VARCHAR" property="tradeMode"/>
        <result column="TRADE_COUNTRY" jdbcType="VARCHAR" property="tradeCountry"/>
        <result column="GROSS_WT" jdbcType="NUMERIC" property="grossWt"/>
        <result column="NET_WT" jdbcType="NUMERIC" property="netWt"/>
        <result column="RMB_PRICE" jdbcType="NUMERIC" property="rmbPrice"/>
        <result column="USD_PRICE" jdbcType="NUMERIC" property="usdPrice"/>
        <result column="CONTAINER" jdbcType="NUMERIC" property="container"/>
        <result column="DECL_MODE" jdbcType="VARCHAR" property="declMode"/>
        <result column="DECL_STATUS" jdbcType="VARCHAR" property="declStatus"/>
        <result column="ORDER_RECEIVE_DATE" jdbcType="TIMESTAMP" property="orderReceiveDate"/>
        <result column="ORDER_RECEIVE_COST" jdbcType="NUMERIC" property="orderReceiveCost"/>
        <result column="CERT_RLS_DATE" jdbcType="TIMESTAMP" property="certRlsDate"/>
        <result column="PRE_RELEASE_DATE" jdbcType="TIMESTAMP" property="preReleaseDate"/>
        <result column="AGENT_CODE" jdbcType="VARCHAR" property="agentCode"/>
        <result column="AGENT_NAME" jdbcType="VARCHAR" property="agentName"/>
        <result column="NOTE_S" jdbcType="VARCHAR" property="noteS"/>
        <result column="OWNER_CODE" jdbcType="VARCHAR" property="ownerCode"/>
        <result column="OWNER_NAME" jdbcType="VARCHAR" property="ownerName"/>
        <result column="EXAM_DATE" jdbcType="TIMESTAMP" property="examDate"/>
        <result column="CHECK_DATE" jdbcType="TIMESTAMP" property="checkDate"/>
        <result column="COMP_ELE_DATE" jdbcType="TIMESTAMP" property="compEleDate"/>
        <result column="RELEASE_DATE" jdbcType="TIMESTAMP" property="releaseDate"/>
        <result column="CU_COST" jdbcType="NUMERIC" property="cuCost"/>
        <result column="TOTAL_COST" jdbcType="NUMERIC" property="totalCost"/>
        <result column="BEFORE_DECL_COST" jdbcType="NUMERIC" property="beforeDeclCost"/>
        <result column="PROF_VERIFY_FLAG" jdbcType="VARCHAR" property="profVerifyFlag"/>
        <result column="NEW_TWO_STEP_FLAG" jdbcType="VARCHAR" property="newTwoStepFlag"/>
        <result column="ELE_DECL_DATE" jdbcType="TIMESTAMP" property="eleDeclDate"/>
        <result column="ASSESS_START_DATE" jdbcType="TIMESTAMP" property="assessStartDate"/>
        <result column="ASSESS_END_DATE" jdbcType="TIMESTAMP" property="assessEndDate"/>
        <result column="REFUND_DATE" jdbcType="TIMESTAMP" property="refundDate"/>
        <result column="REFUND_FLAG" jdbcType="VARCHAR" property="refundFlag"/>
        <result column="MAN_CREATE_TIME" jdbcType="TIMESTAMP" property="manCreateTime"/>
        <result column="MAN_CHK_TIME_START" jdbcType="TIMESTAMP" property="manChkTimeStart"/>
        <result column="MAN_CHK_TIME_END" jdbcType="TIMESTAMP" property="manChkTimeEnd"/>
        <result column="CHECK_CUSTOMS_CODE" jdbcType="VARCHAR" property="checkCustomsCode"/>
        <result column="CHECK_FLAG" jdbcType="VARCHAR" property="checkFlag"/>
        <result column="MAN_PROC_RESULT" jdbcType="VARCHAR" property="manProcResult"/>
        <result column="MAN_PROC_IDEA" jdbcType="VARCHAR" property="manProcIdea"/>
        <result column="G_NO" jdbcType="NUMERIC" property="gNo"/>
        <result column="CODE_TS" jdbcType="VARCHAR" property="codeTs"/>
        <result column="IQ_CODE" jdbcType="VARCHAR" property="iqCode"/>
        <result column="G_NAME" jdbcType="VARCHAR" property="gName"/>
        <result column="G_MODEL" jdbcType="VARCHAR" property="gModel"/>
        <result column="QTY_1" jdbcType="NUMERIC" property="qty1"/>
        <result column="RMB_PRICE" jdbcType="NUMERIC" property="rmbPriceList"/>
        <result column="USD_PRICE" jdbcType="NUMERIC" property="usdPriceList"/>
        <result column="CODE_TS_SHORT" jdbcType="VARCHAR" property="codeTsShort"/>
        <result column="G_CERT_FLAG" jdbcType="VARCHAR" property="gCertFlag"/>
        <result column="UNGID" jdbcType="VARCHAR" property="ungid"/>
        <result column="UNG_FLAG" jdbcType="VARCHAR" property="ungFlag"/>
        <result column="ungModel" jdbcType="VARCHAR" property="ungModel"/>
        <result column="UNG_CLASSIFY" jdbcType="VARCHAR" property="ungClassify"/>
        <result column="UNG_G_NAME" jdbcType="VARCHAR" property="ungGName"/>
        <result column="PRODUCT_CHAR_CODE" jdbcType="VARCHAR" property="productCharCode"/>
        <result column="IQ_CODE" jdbcType="VARCHAR" property="iqCode"/>
        <result column="GOODS_TYPE" jdbcType="VARCHAR" property="goodsType"/>
    </resultMap>

    <resultMap type="EntryHead" id="EntryHeadResult">
        <id column="ENTRY_ID" jdbcType="VARCHAR" property="entryId"/>
        <result column="MAIN_STATUS" jdbcType="VARCHAR" property="mainStatus"/>
        <result column="PASS_MODE" jdbcType="VARCHAR" property="passMode"/>
        <result column="TRAF_MODE" jdbcType="VARCHAR" property="trafMode"/>
        <result column="I_E_FLAG" jdbcType="VARCHAR" property="ieFlag"/>
        <result column="I_E_PORT" jdbcType="VARCHAR" property="iePort"/>
        <result column="DECL_PORT" jdbcType="VARCHAR" property="declPort"/>
        <result column="CUSTOMS_CODE" jdbcType="VARCHAR" property="customsCode"/>
        <result column="I_E_DATE" jdbcType="TIMESTAMP" property="ieDate"/>
        <result column="DECL_DATE" jdbcType="TIMESTAMP" property="declDate"/>
        <result column="DECL_ADVANCE_FLAG" jdbcType="VARCHAR" property="declAdvanceFlag"/>
        <result column="ACCEPT_DATE" jdbcType="TIMESTAMP" property="acceptDate"/>
        <result column="EX_IN_PORT_DATE" jdbcType="TIMESTAMP" property="exInPortDate"/>
        <result column="CONSIGN_SCC" jdbcType="VARCHAR" property="consignScc"/>
        <result column="CONSIGN_CODE" jdbcType="VARCHAR" property="consignCode"/>
        <result column="CONSIGN_NAME" jdbcType="VARCHAR" property="consignName"/>
        <result column="CONSIGN_SCC" jdbcType="VARCHAR" property="consignScc"/>
        <result column="FRN_CONSIGN_CODE" jdbcType="VARCHAR" property="frnConsignCode"/>
        <result column="FRN_CONSIGN_NAME" jdbcType="VARCHAR" property="frnConsignName"/>
        <result column="TRADE_MODE" jdbcType="VARCHAR" property="tradeMode"/>
        <result column="TRADE_COUNTRY" jdbcType="VARCHAR" property="tradeCountry"/>
        <result column="GROSS_WT" jdbcType="NUMERIC" property="grossWt"/>
        <result column="NET_WT" jdbcType="NUMERIC" property="netWt"/>
        <result column="RMB_PRICE" jdbcType="NUMERIC" property="rmbPrice"/>
        <result column="USD_PRICE" jdbcType="NUMERIC" property="usdPrice"/>
        <result column="CONTAINER" jdbcType="NUMERIC" property="container"/>
        <result column="DECL_MODE" jdbcType="VARCHAR" property="declMode"/>
        <result column="DECL_STATUS" jdbcType="VARCHAR" property="declStatus"/>
        <result column="ORDER_RECEIVE_DATE" jdbcType="TIMESTAMP" property="orderReceiveDate"/>
        <result column="ORDER_RECEIVE_COST" jdbcType="NUMERIC" property="orderReceiveCost"/>
        <result column="CERT_RLS_DATE" jdbcType="TIMESTAMP" property="certRlsDate"/>
        <result column="PRE_RELEASE_DATE" jdbcType="TIMESTAMP" property="preReleaseDate"/>
        <result column="AGENT_CODE" jdbcType="VARCHAR" property="agentCode"/>
        <result column="AGENT_NAME" jdbcType="VARCHAR" property="agentName"/>
        <result column="NOTE_S" jdbcType="VARCHAR" property="noteS"/>
        <result column="OWNER_CODE" jdbcType="VARCHAR" property="ownerCode"/>
        <result column="OWNER_NAME" jdbcType="VARCHAR" property="ownerName"/>
        <result column="EXAM_DATE" jdbcType="TIMESTAMP" property="examDate"/>
        <result column="CHECK_DATE" jdbcType="TIMESTAMP" property="checkDate"/>
        <result column="COMP_ELE_DATE" jdbcType="TIMESTAMP" property="compEleDate"/>
        <result column="RELEASE_DATE" jdbcType="TIMESTAMP" property="releaseDate"/>
        <result column="CU_COST" jdbcType="NUMERIC" property="cuCost"/>
        <result column="TOTAL_COST" jdbcType="NUMERIC" property="totalCost"/>
        <result column="BEFORE_DECL_COST" jdbcType="NUMERIC" property="beforeDeclCost"/>
        <result column="PROF_VERIFY_FLAG" jdbcType="VARCHAR" property="profVerifyFlag"/>
        <result column="NEW_TWO_STEP_FLAG" jdbcType="VARCHAR" property="newTwoStepFlag"/>
        <result column="ELE_DECL_DATE" jdbcType="TIMESTAMP" property="eleDeclDate"/>
        <result column="ASSESS_START_DATE" jdbcType="TIMESTAMP" property="assessStartDate"/>
        <result column="ASSESS_END_DATE" jdbcType="TIMESTAMP" property="assessEndDate"/>
        <result column="REFUND_DATE" jdbcType="TIMESTAMP" property="refundDate"/>
        <result column="REFUND_FLAG" jdbcType="VARCHAR" property="refundFlag"/>
        <result column="MAN_CREATE_TIME" jdbcType="TIMESTAMP" property="manCreateTime"/>
        <result column="MAN_CHK_TIME_START" jdbcType="TIMESTAMP" property="manChkTimeStart"/>
        <result column="MAN_CHK_TIME_END" jdbcType="TIMESTAMP" property="manChkTimeEnd"/>
        <result column="CHECK_CUSTOMS_CODE" jdbcType="VARCHAR" property="checkCustomsCode"/>
        <result column="CHECK_FLAG" jdbcType="VARCHAR" property="checkFlag"/>
        <result column="MAN_PROC_RESULT" jdbcType="VARCHAR" property="manProcResult"/>
        <result column="MAN_PROC_IDEA" jdbcType="VARCHAR" property="manProcIdea"/>
    </resultMap>

    <resultMap id="EntryListResultMap" type="cn.gov.customs.wxjy.analyze.pojo.EntryList">
        <id column="ID" jdbcType="VARCHAR" property="id"/>
        <result column="ENTRY_ID" jdbcType="VARCHAR" property="entryId"/>
        <result column="G_NO" jdbcType="NUMERIC" property="gNo"/>
        <result column="CODE_TS" jdbcType="VARCHAR" property="codeTs"/>
        <result column="IQ_CODE" jdbcType="VARCHAR" property="iqCode"/>
        <result column="G_NAME" jdbcType="VARCHAR" property="gName"/>
        <result column="G_MODEL" jdbcType="VARCHAR" property="gModel"/>
        <result column="QTY_1" jdbcType="NUMERIC" property="qty1"/>
        <result column="RMB_PRICE" jdbcType="NUMERIC" property="rmbPrice"/>
        <result column="USD_PRICE" jdbcType="NUMERIC" property="usdPrice"/>
        <result column="CODE_TS_SHORT" jdbcType="VARCHAR" property="codeTsShort"/>
        <result column="G_CERT_FLAG" jdbcType="VARCHAR" property="gCertFlag"/>
        <result column="UNGID" jdbcType="VARCHAR" property="ungid"/>
        <result column="UNG_FLAG" jdbcType="VARCHAR" property="ungFlag"/>
        <result column="ungModel" jdbcType="VARCHAR" property="ungModel"/>
        <result column="UNG_CLASSIFY" jdbcType="VARCHAR" property="ungClassify"/>
        <result column="UNG_G_NAME" jdbcType="VARCHAR" property="ungGName"/>
        <result column="PRODUCT_CHAR_CODE" jdbcType="VARCHAR" property="productCharCode"/>
        <result column="IQ_CODE" jdbcType="VARCHAR" property="iqCode"/>
        <result column="GOODS_TYPE" jdbcType="VARCHAR" property="goodsType"/>
    </resultMap>

    <select id="selectByEntryId" parameterType="String" resultMap="EntryHeadResult">
        select b.entry_id,b.main_status,b.pass_mode,b.traf_mode,b.i_e_flag,b.i_e_port,b.decl_port,b.customs_code,b.i_e_date,b.decl_date,
               b.decl_advance_flag,b.accept_date,b.ex_in_port_date,b.consign_scc,b.consign_code,b.consign_name,
               b.frn_consign_code,b.frn_consign_name,b.trade_mode,b.trade_country,b.gross_wt,b.net_wt,b.rmb_price,b.usd_price,b.container,
               b.decl_mode,b.decl_status,b.order_receive_date,nvl(round(b.order_receive_cost/3600,2),0) order_receive_cost,b.cert_rls_date,
               b.pre_release_date,b.agent_code,b.agent_name,
               b.note_s,b.owner_code,b.owner_name,b.exam_date,b.check_date,b.comp_ele_date,b.release_date,nvl(round(b.cu_cost/3600,2),0) cu_cost,
               nvl(round(b.total_cost/3600,2),0) total_cost,nvl(round(b.before_decl_cost/3600,2),0) before_decl_cost,
               b.prof_verify_flag,b.new_two_step_flag,b.ele_decl_date,b.assess_start_date,b.assess_end_date,b.refund_date,b.refund_flag,
               b.man_create_time,b.man_chk_time_start,b.man_chk_time_end,b.check_flag,b.man_proc_result,b.man_proc_idea,b.check_customs_code
        from WXJY_ENTRY_HEAD b where ENTRY_ID = #{entryId}
    </select>

    <select id="selectPageList"  parameterType="EntryQuery" resultMap="EntryResultMap">
        select b.entry_id,b.main_status,b.pass_mode,b.traf_mode,b.i_e_flag,b.i_e_port,b.decl_port,b.customs_code,b.i_e_date,b.decl_date,
        b.decl_advance_flag,b.accept_date,b.ex_in_port_date,b.consign_scc,b.consign_code,b.consign_name,
        b.frn_consign_code,b.frn_consign_name,b.trade_mode,b.trade_country,b.gross_wt,b.net_wt,b.rmb_price,b.usd_price,b.container,
        b.decl_mode,b.decl_status,b.order_receive_date,nvl(round(b.order_receive_cost/3600,2),0) order_receive_cost,b.cert_rls_date,
        b.pre_release_date,b.agent_code,b.agent_name,
        b.note_s,b.owner_code,b.owner_name,b.exam_date,b.check_date,b.comp_ele_date,b.release_date,nvl(round(b.cu_cost/3600,2),0) cu_cost,
        nvl(round(b.total_cost/3600,2),0) total_cost,nvl(round(b.before_decl_cost/3600,2),0) before_decl_cost,
        b.prof_verify_flag,b.new_two_step_flag,b.ele_decl_date,b.assess_start_date,b.assess_end_date,b.refund_date,b.refund_flag,
        b.man_create_time,b.man_chk_time_start,b.man_chk_time_end,b.check_flag,b.man_proc_result,b.man_proc_idea,b.check_customs_code,
        a.g_no,a.code_ts,a.g_name,a.g_model,a.qty_1,a.rmb_price as rmbPriceList,a.usd_price as usdPriceList,a.code_ts_short,a.g_cert_flag,
        a.ung_flag,a.ung_model,a.ung_classify,a.ung_g_name,a.product_char_code,a.iq_code,a.goods_type from(
        select entry_id,g_no,code_ts,g_name,g_model,qty_1,rmb_price,usd_price,code_ts_short,g_cert_flag,
        ung_flag,ung_model,ung_classify,ung_g_name,product_char_code,iq_code,goods_type from (
        select entry_id,g_no,code_ts,g_name,g_model,qty_1,rmb_price,usd_price,code_ts_short,g_cert_flag,
        ung_flag,ung_model,ung_classify,ung_g_name,product_char_code,iq_code,goods_type,
        rank() over(PARTITION BY entry_id order by id) as rn from WXJY_ENTRY_LIST where 1=1
        <if test="goodsType !=null and goodsType !=''">
            and goods_type like CONCAT(CONCAT('%',#{goodsType}),'%')
        </if>
        ) h where h.rn=1 )a ,WXJY_ENTRY_HEAD b
        where a.entry_id = b.entry_id
        <if test="entryId !=null and entryId !=''">
            and b.entry_id like concat(concat('%', #{entryId} ),'%')
        </if>
        <if test="passMode !=null and passMode !=''">
            and b.pass_mode = #{passMode}
        </if>
        <if test="trafMode!=null and trafMode !=''">
            and b.traf_mode = #{trafMode}
        </if>
        <if test="ieFlag!=null and ieFlag !=''">
            and b.i_e_flag = #{ieFlag}
        </if>
        <if test="customsCode !=null and customsCode !=''">
            and b.customs_code = #{customsCode}
        </if>
        <if test="declMode!=null and declMode !=''">
            and b.decl_mode = #{declMode}
        </if>
        <if test="beginReleaseDate!=null and beginReleaseDate !=''">
            AND date_format(b.release_date,'%y%m%d') >= date_format(#{beginReleaseDate},'%y%m%d')
        </if>
        <if test="endReleaseDate != null and endReleaseDate != ''"><!-- 结束时间检索 -->
            AND date_format(b.release_date,'%y%m%d') &lt;= date_format(#{endReleaseDate},'%y%m%d')
        </if>
        <if test="checkFlag!=null and checkFlag !=''">
            and b.check_flag = #{checkFlag}
        </if>
        <if test="tradeMode!=null and tradeMode !=''">
            and b.trade_mode = #{tradeMode}
        </if>
    </select>

    <select id="getEntryList" resultMap="EntryListResultMap">
        SELECT l.* FROM WXJY_ENTRY_LIST l WHERE 1=1
        <if test="entryId != null and entryId != ''">
            AND l.ENTRY_ID = #{entryId}
        </if>
        ORDER BY l.G_NO
    </select>
</mapper>