<?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_car.TbCarMapper">

	<!-- 增 [G] -->
	<insert id="add">
		insert into 
		tb_car (id, card_no, card_size, last_goods_name, last_goods_code, last_net_weight, last_in_time, last_out_time, status) 
		values (#{id}, #{cardNo}, #{cardSize}, #{lastGoodsName}, #{lastGoodsCode}, #{lastNetWeight}, #{lastInTime}, #{lastOutTime}, #{status}) 
	</insert>

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

	<!-- 改 [G] -->
	<update id="update">
		update tb_car set
		id = #{id}, 
		card_no = #{cardNo}, 
		card_size = #{cardSize}, 
		last_goods_name = #{lastGoodsName}, 
		last_goods_code = #{lastGoodsCode}, 
		last_net_weight = #{lastNetWeight}, 
		last_in_time = #{lastInTime}, 
		last_out_time = #{lastOutTime}, 
		status = #{status}
		where id = #{id}
	</update>


	<!-- ================================== 查询相关 ================================== -->

	
	<!-- 通用映射：手动模式 -->
	<resultMap id="model" type="com.pj.project.tb_car.TbCar">
		<result property="id" column="id" />
		<result property="cardNo" column="card_no" />
		<result property="cardSize" column="card_size" />
		<result property="lastGoodsName" column="last_goods_name" />
		<result property="lastGoodsCode" column="last_goods_code" />
		<result property="lastNetWeight" column="last_net_weight" />
		<result property="lastInTime" column="last_in_time" />
		<result property="lastOutTime" column="last_out_time" />
		<result property="status" column="status" />
	</resultMap>
	
	<!-- 公共查询sql片段 -->
	<sql id="select_sql">
		select *
		from tb_car 
	</sql>
	
	<!-- 查 - 根据id -->
	<select id="getById" resultMap="model">
		<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("cardNo") '> and card_no = #{cardNo} </if>
			<if test=' this.has("cardSize") '> and card_size = #{cardSize} </if>
			<if test=' this.has("lastGoodsName") '> and last_goods_name = #{lastGoodsName} </if>
			<if test=' this.has("lastGoodsCode") '> and last_goods_code = #{lastGoodsCode} </if>
			<if test=' this.has("lastNetWeight") '> and last_net_weight = #{lastNetWeight} </if>
			<if test=' this.has("lastInTime") '> and last_in_time = #{lastInTime} </if>
			<if test=' this.has("lastOutTime") '> and last_out_time = #{lastOutTime} </if>
			<if test=' this.has("status") '> and status = #{status} </if>
		</where>
		order by
		<choose>
			<when test='sortType == 1'> id desc </when>
			<when test='sortType == 2'> card_no desc </when>
			<when test='sortType == 3'> card_size desc </when>
			<when test='sortType == 4'> last_goods_name desc </when>
			<when test='sortType == 5'> last_goods_code desc </when>
			<when test='sortType == 6'> last_net_weight desc </when>
			<when test='sortType == 7'> last_in_time desc </when>
			<when test='sortType == 8'> last_out_time desc </when>
			<when test='sortType == 9'> status desc </when>
			<otherwise> id desc </otherwise>
		</choose>
	</select>
	
	
	
	
	
	
	
	
	

</mapper>
