<?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.pj.ht_trade_settlement.HtTradeSettlementMapper">




	<!-- ================================== 查询相关 ================================== -->
	<!-- select plat_seq_no, declare_id, declare_type, declare_name, idno, shop_no, shop_name, org_putrec_no, org_name, org_scc, ve_no, btrnb_biz_modecd, g_flow, i_e_flag, field_code, field_name, customs_code, car_pool, sum_amt, sum_gross_wt, sum_net_wt, traf_mode, curr_code, pack_no, decl_time, bill_no, voyage_no, goods_names, borders_list, border_buy_goods_list, sell_goods_list, id from ht_trade_settlement  -->

	<!-- 通用映射：自动模式 -->
	<resultMap id="model" autoMapping="true" type="com.pj.ht_trade_settlement.HtTradeSettlement"></resultMap>

	<!-- 公共查询sql片段 -->
	<sql id="select_sql">
		select *
		from ht_trade_settlement
	</sql>


	<!-- 查集合 - 根据条件（参数为空时代表忽略指定条件） [G] -->
	<select id="getList" resultMap="model">
		<include refid="select_sql"></include>
		<where>
			<if test=' this.has("platSeqNo") '> and plat_seq_no like concat('%',#{platSeqNo},'%') </if>
			<if test=' this.has("declareId") '> and declare_id like concat('%',#{declareId},'%') </if>
			<if test=' this.has("declareType") '> and declare_type = #{declareType} </if>
			<if test=' this.has("declareName") '> and declare_name = #{declareName} </if>
			<if test=' this.has("idno") '> and idno = #{idno} </if>
			<if test=' this.has("shopNo") '> and shop_no = #{shopNo} </if>
			<if test=' this.has("shopName") '> and shop_name like concat('%',#{shopName},'%') </if>
			<if test=' this.has("orgPutrecNo") '> and org_putrec_no = #{orgPutrecNo} </if>
			<if test=' this.has("orgName") '> and org_name = #{orgName} </if>
			<if test=' this.has("orgScc") '> and org_scc = #{orgScc} </if>
			<if test=' this.has("veNo") '> and ve_no like concat('%',#{veNo},'%') </if>
			<if test=' this.has("btrnbBizModecd") '> and btrnb_biz_modecd = #{btrnbBizModecd} </if>
			<if test=' this.has("gFlow") '> and g_flow = #{gFlow} </if>
			<if test=' this.has("iEFlag") '> and i_e_flag = #{iEFlag} </if>
			<if test=' this.has("fieldCode") '> and field_code = #{fieldCode} </if>
			<if test=' this.has("fieldName") '> and field_name like concat('%',#{fieldName},'%') </if>
			<if test=' this.has("customsCode") '> and customs_code = #{customsCode} </if>
			<if test=' this.has("carPool") '> and car_pool = #{carPool} </if>
			<if test=' this.has("sumAmt") '> and sum_amt = #{sumAmt} </if>
			<if test=' this.has("sumGrossWt") '> and sum_gross_wt = #{sumGrossWt} </if>
			<if test=' this.has("sumNetWt") '> and sum_net_wt = #{sumNetWt} </if>
			<if test=' this.has("trafMode") '> and traf_mode = #{trafMode} </if>
			<if test=' this.has("currCode") '> and curr_code = #{currCode} </if>
			<if test=' this.has("packNo") '> and pack_no = #{packNo} </if>
			<if test=' this.has("declTime") '> and date_format(decl_time,'%Y-%m-%d') = #{declTime} </if>
			<if test=' this.has("billNo") '> and bill_no = #{billNo} </if>
			<if test=' this.has("voyageNo") '> and voyage_no = #{voyageNo} </if>
			<if test=' this.has("finishStatus") '> and finish_status = #{finishStatus} </if>
			<if test=' this.has("goodsNames") '> and goods_names like concat('%',#{goodsNames},'%') </if>
			<if test=' this.has("bordersList") '> and borders_list = #{bordersList} </if>
			<if test=' this.has("borderBuyGoodsList") '> and border_buy_goods_list = #{borderBuyGoodsList} </if>
			<if test=' this.has("enterpriseId") '> and enterprise_id = #{enterpriseId} </if>
			<if test=' this.has("returns") '> and returns = #{returns} </if>
			<if test=' this.has("chargebacks") '> and chargebacks = #{chargebacks} </if>
			<if test=' this.has("hzsConfirmStatus") '> and hzs_confirm_status = #{hzsConfirmStatus} </if>
			<if test=' this.has("id") '> and id = #{id} </if>
		</where>
		order by
		<choose>
			<when test='sortType == 1'> plat_seq_no desc </when>
			<when test='sortType == 2'> declare_id desc </when>
			<when test='sortType == 3'> declare_type desc </when>
			<when test='sortType == 4'> declare_name desc </when>
			<when test='sortType == 5'> idno desc </when>
			<when test='sortType == 6'> shop_no desc </when>
			<when test='sortType == 7'> shop_name desc </when>
			<when test='sortType == 8'> org_putrec_no desc </when>
			<when test='sortType == 9'> org_name desc </when>
			<when test='sortType == 10'> org_scc desc </when>
			<when test='sortType == 11'> ve_no desc </when>
			<when test='sortType == 12'> btrnb_biz_modecd desc </when>
			<when test='sortType == 13'> g_flow desc </when>
			<when test='sortType == 14'> i_e_flag desc </when>
			<when test='sortType == 15'> field_code desc </when>
			<when test='sortType == 16'> field_name desc </when>
			<when test='sortType == 17'> customs_code desc </when>
			<when test='sortType == 18'> car_pool desc </when>
			<when test='sortType == 19'> sum_amt desc </when>
			<when test='sortType == 20'> sum_gross_wt desc </when>
			<when test='sortType == 21'> sum_net_wt desc </when>
			<when test='sortType == 22'> traf_mode desc </when>
			<when test='sortType == 23'> curr_code desc </when>
			<when test='sortType == 24'> pack_no desc </when>
			<when test='sortType == 25'> decl_time desc </when>
			<when test='sortType == 26'> bill_no desc </when>
			<when test='sortType == 27'> voyage_no desc </when>
			<when test='sortType == 28'> goods_names desc </when>
			<when test='sortType == 29'> borders_list desc </when>
			<when test='sortType == 30'> border_buy_goods_list desc </when>
			<when test='sortType == 31'> sell_goods_list desc </when>
			<when test='sortType == 32'> id desc </when>
			<when test='sortType == 33'> finish_time desc </when>
			<otherwise> create_time desc ,id desc </otherwise>
		</choose>
	</select>
	<select id="getOnSaleList" resultType="com.pj.ht_trade_settlement.HtTradeSettlement">
        select *,(select sum(up_price) from tb_order where sale_main_id=ht_trade_settlement.id) as sumUpPrice
        from ht_trade_settlement
        where order_count = on_sale_count
        and be_order_count=0  and i_e_flag='I' and check_pass_status=1
        <if test=' this.has("veNo") '>and ve_no like concat('%',#{veNo},'%')</if>
		<if test=' this.has("shopName") '>and shop_name like concat('%',#{shopName},'%')</if>
        <if test=' this.has("productName") '>and goods_names like concat('%',#{productName},'%')</if>
        <if test=' this.has("dateBegin") '>and date_format(create_time,'%Y-%m-%d') &gt;=#{dateBegin}</if>
        <if test=' this.has("dateEnd") '>and date_format(create_time,'%Y-%m-%d') &lt;=#{dateEnd}</if>
        order by create_time desc
    </select>


</mapper>
