<?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.tb_goods.TbGoodsMapper">




	<!-- ================================== 查询相关 ================================== -->
	<!-- select id, name, avatar, type_ids, type_names, code, remark, source, status, create_time, unit, single_price, tax_no from tb_goods  -->

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

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


	<!-- 查集合 - 根据条件（参数为空时代表忽略指定条件） [G] -->
	<select id="getList" resultMap="model">
		<include refid="select_sql"></include>

		<if test=' this.has("tradeAreaId") '>
			left join re_trade_area_goods ta on g.id = ta.goods_id
		</if>
		<where>
			<if test=' this.has("id") '> and id = #{id} </if>
			<if test=' this.has("name") '> and name like concat('%', #{name}, '%')</if>
			<if test=' this.has("typeIds") '> and type_ids = #{typeIds} </if>
			<if test=' this.has("typeNames") '> and type_names = #{typeNames} </if>
			<if test=' this.has("code") '> and code = #{code} </if>
			<if test=' this.has("remark") '> and remark = #{remark} </if>
			<if test=' this.has("source") '> and source = #{source} </if>
			<if test=' this.has("status") '> and status = #{status} </if>
			<if test=' this.has("createTime") '> and create_time = #{createTime} </if>
			<if test=' this.has("unit") '> and unit = #{unit} </if>
			<if test=' this.has("singlePrice") '> and single_price = #{singlePrice} </if>
			<if test=' this.has("taxNo") '> and tax_no = #{taxNo} </if>
			<if test=' this.has("thrItemName") '> and thr_item_name like concat('%', #{thrItemName}, '%')</if>
			<if test=' this.has("tradeAreaId") '> and ta.area_id = #{tradeAreaId} </if>
		</where>
		order by
		<choose>
			<when test='sortType == 1'> id desc </when>
			<when test='sortType == 2'> name desc </when>
			<when test='sortType == 3'> type_ids desc </when>
			<when test='sortType == 4'> type_names desc </when>
			<when test='sortType == 5'> code desc </when>
			<when test='sortType == 6'> remark desc </when>
			<when test='sortType == 7'> source desc </when>
			<when test='sortType == 8'> status desc </when>
			<when test='sortType == 9'> create_time desc </when>
			<when test='sortType == 10'> unit desc </when>
			<when test='sortType == 11'> single_price desc </when>
			<when test='sortType == 12'> tax_no desc </when>
			<otherwise> id desc </otherwise>
		</choose>
	</select>


	<!-- 查集合 - 根据互市区Id -->
	<select id="getByTradeArea" resultMap="model">
		select g.* from tb_goods g
		left join re_trade_area_goods ta on g.id = ta.goods_id
		where ta.area_id = #{tradeAreaId}
		<if test=' this.has("typeNames") '> and g.type_names = #{typeNames} </if>
	</select>








</mapper>
