<?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.project.tb_declare.TbDeclareMapper">

    <!-- 增 [G] -->
    <insert id="add">
		insert into 
		tb_declare (id, business_id, goods_name, gross_weight, num, production_date, expiration_date, storage_mode, production_mode, origin, producer_code, send_unit, receive_unit, route, driver_name, driver_phone, agent, agent_phone, china_car_no, car_no, custom_proof, quarantine_proof, shop, production_code, container_code) 
		values (#{id}, #{businessId}, #{goodsName}, #{grossWeight}, #{num}, #{productionDate}, #{expirationDate}, #{storageMode}, #{productionMode}, #{origin}, #{producerCode}, #{sendUnit}, #{receiveUnit}, #{route}, #{driverName}, #{driverPhone}, #{agent}, #{agentPhone}, #{chinaCarNo}, #{carNo}, #{customProof}, #{quarantineProof}, #{shop}, #{productionCode}, #{containerCode}) 
	</insert>

    <!-- 删 -->
    <delete id="delete">
		delete from tb_declare 
		where id = #{id}
	</delete>

    <!-- 改 [G] -->
    <update id="update">
		update tb_declare set
		id = #{id}, 
		business_id = #{businessId}, 
		goods_name = #{goodsName}, 
		gross_weight = #{grossWeight}, 
		num = #{num}, 
		production_date = #{productionDate}, 
		expiration_date = #{expirationDate}, 
		storage_mode = #{storageMode}, 
		production_mode = #{productionMode}, 
		origin = #{origin}, 
		producer_code = #{producerCode}, 
		send_unit = #{sendUnit}, 
		receive_unit = #{receiveUnit}, 
		route = #{route}, 
		driver_name = #{driverName}, 
		driver_phone = #{driverPhone}, 
		agent = #{agent}, 
		agent_phone = #{agentPhone}, 
		china_car_no = #{chinaCarNo}, 
		car_no = #{carNo}, 
		custom_proof = #{customProof}, 
		quarantine_proof = #{quarantineProof}, 
		shop = #{shop}, 
		production_code = #{productionCode}, 
		container_code = #{containerCode}
		where id = #{id}
	</update>


    <!-- ================================== 查询相关 ================================== -->
    <!-- select id, business_id, goods_name, gross_weight, num, production_date, expiration_date, storage_mode, production_mode, origin, producer_code, send_unit, receive_unit, route, driver_name, driver_phone, agent, agent_phone, china_car_no, car_no, custom_proof, quarantine_proof, shop, production_code, container_code from tb_declare  -->

    <!-- 通用映射：手动模式 -->
    <resultMap id="model" type="com.pj.project.tb_declare.TbDeclare">
        <result property="id" column="id"/>
        <result property="businessId" column="business_id"/>
        <result property="goodsName" column="goods_name"/>
        <result property="grossWeight" column="gross_weight"/>
        <result property="num" column="num"/>
        <result property="productionDate" column="production_date"/>
        <result property="expirationDate" column="expiration_date"/>
        <result property="storageMode" column="storage_mode"/>
        <result property="productionMode" column="production_mode"/>
        <result property="origin" column="origin"/>
        <result property="producerCode" column="producer_code"/>
        <result property="sendUnit" column="send_unit"/>
        <result property="receiveUnit" column="receive_unit"/>
        <result property="route" column="route"/>
        <result property="driverName" column="driver_name"/>
        <result property="driverPhone" column="driver_phone"/>
        <result property="agent" column="agent"/>
        <result property="agentPhone" column="agent_phone"/>
        <result property="chinaCarNo" column="china_car_no"/>
        <result property="carNo" column="car_no"/>
        <result property="customProof" column="custom_proof"/>
        <result property="quarantineProof" column="quarantine_proof"/>
        <result property="shop" column="shop"/>
        <result property="productionCode" column="production_code"/>
        <result property="containerCode" column="container_code"/>
    </resultMap>

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

    <!-- 查 - 根据id -->
    <select id="getById" resultType="com.pj.project.tb_declare.TbDeclare">
        <include refid="select_sql"></include>
        where id = #{id}
    </select>

    <!-- 查集合 - 根据条件（参数为空时代表忽略指定条件） [G] -->
    <select id="getList" resultMap="model">
        <include refid="select_sql"></include>
        <where>
            <if test=' this.has("id") '>and id = #{id}</if>
            <if test=' this.has("businessId") '>and business_id = #{businessId}</if>
            <if test=' this.has("declarePeople") '>and declare_people like concat('%',#{declarePeople},'%')</if>
            <if test=' this.has("goodsName") '>and goods_name = #{goodsName}</if>
            <if test=' this.has("grossWeight") '>and gross_weight = #{grossWeight}</if>
            <if test=' this.has("num") '>and num = #{num}</if>
            <if test=' this.has("productionDate") '>and production_date = #{productionDate}</if>
            <if test=' this.has("expirationDate") '>and expiration_date = #{expirationDate}</if>
            <if test=' this.has("storageMode") '>and storage_mode = #{storageMode}</if>
            <if test=' this.has("productionMode") '>and production_mode = #{productionMode}</if>
            <if test=' this.has("origin") '>and origin = #{origin}</if>
            <if test=' this.has("producerCode") '>and producer_code = #{producerCode}</if>
            <if test=' this.has("sendUnit") '>and send_unit = #{sendUnit}</if>
            <if test=' this.has("receiveUnit") '>and receive_unit = #{receiveUnit}</if>
            <if test=' this.has("route") '>and route = #{route}</if>
            <if test=' this.has("driverName") '>and driver_name = #{driverName}</if>
            <if test=' this.has("driverPhone") '>and driver_phone = #{driverPhone}</if>
            <if test=' this.has("agent") '>and agent = #{agent}</if>
            <if test=' this.has("agentPhone") '>and agent_phone = #{agentPhone}</if>
            <if test=' this.has("chinaCarNo") '>and china_car_no = #{chinaCarNo}</if>
            <if test=' this.has("carNo") '>and car_no = #{carNo}</if>
            <if test=' this.has("customProof") '>and custom_proof = #{customProof}</if>
            <if test=' this.has("quarantineProof") '>and quarantine_proof = #{quarantineProof}</if>
            <if test=' this.has("shop") '>and shop = #{shop}</if>
            <if test=' this.has("productionCode") '>and production_code = #{productionCode}</if>
            <if test=' this.has("containerCode") '>and container_code = #{containerCode}</if>
            <if test=' this.has("bind") '>and business_id is null or business_id=''</if>
            <if test=' this.has("declareNo") '>and (declare_no=#{declareNo} or business_id is null or business_id='')</if>

        </where>
        order by
        <choose>
            <when test='sortType == 1'>id desc</when>
            <when test='sortType == 2'>business_id desc</when>
            <when test='sortType == 3'>goods_name desc</when>
            <when test='sortType == 4'>gross_weight desc</when>
            <when test='sortType == 5'>num desc</when>
            <when test='sortType == 6'>production_date desc</when>
            <when test='sortType == 7'>expiration_date desc</when>
            <when test='sortType == 8'>storage_mode desc</when>
            <when test='sortType == 9'>production_mode desc</when>
            <when test='sortType == 10'>origin desc</when>
            <when test='sortType == 11'>producer_code desc</when>
            <when test='sortType == 12'>send_unit desc</when>
            <when test='sortType == 13'>receive_unit desc</when>
            <when test='sortType == 14'>route desc</when>
            <when test='sortType == 15'>driver_name desc</when>
            <when test='sortType == 16'>driver_phone desc</when>
            <when test='sortType == 17'>agent desc</when>
            <when test='sortType == 18'>agent_phone desc</when>
            <when test='sortType == 19'>china_car_no desc</when>
            <when test='sortType == 20'>car_no desc</when>
            <when test='sortType == 21'>custom_proof desc</when>
            <when test='sortType == 22'>quarantine_proof desc</when>
            <when test='sortType == 23'>shop desc</when>
            <when test='sortType == 24'>production_code desc</when>
            <when test='sortType == 25'>container_code desc</when>
            <otherwise>id desc</otherwise>
        </choose>
    </select>


</mapper>
