<?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.fjs.scenic.mapper.good.GoodsMapper">
  <resultMap id="BaseResultMap" type="com.fjs.scenic.entity.good.Goods">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="scenic_id" jdbcType="INTEGER" property="scenicId" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="price" jdbcType="INTEGER" property="price" />
    <result column="resourceId" jdbcType="VARCHAR" property="resourceid" />
    <result column="sight_name" jdbcType="VARCHAR" property="sightName" />
    <result column="sight_id" jdbcType="VARCHAR" property="sightId" />
    <result column="remind" jdbcType="VARCHAR" property="remind" />
    <result column="sort" jdbcType="INTEGER" property="sort" />
     <result column="sort_type" jdbcType="VARCHAR" property="sortType" />
      <result column="door_type" jdbcType="VARCHAR" property="doorType" />
       <result column="qrcode" jdbcType="VARCHAR" property="qrcode" />
       <result column="person_type" jdbcType="VARCHAR" property="personType" />
  </resultMap>
  <sql id="Base_Column_List">
    id, scenic_id, name, price, resourceId, sight_name, sight_id, remind, sort,sort_type,door_type,qrcode,person_type
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from goods
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from goods
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.fjs.scenic.entity.good.Goods">
    insert into goods (id, scenic_id, name, 
      price, resourceId, sight_name, 
      sight_id, remind, sort,sort_type,door_type,qrcode
      )
    values (#{id,jdbcType=INTEGER}, #{scenicId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, 
      #{price,jdbcType=INTEGER}, #{resourceid,jdbcType=VARCHAR}, #{sightName,jdbcType=VARCHAR}, 
      #{sightId,jdbcType=VARCHAR}, #{remind,jdbcType=VARCHAR}, #{sort,jdbcType=INTEGER},
      #{sortType,jdbcType=VARCHAR},#{doorType,jdbcType=VARCHAR},#{qrcode,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.fjs.scenic.entity.good.Goods">
    insert into goods
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="scenicId != null">
        scenic_id,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="price != null">
        price,
      </if>
      <if test="resourceid != null">
        resourceId,
      </if>
      <if test="sightName != null">
        sight_name,
      </if>
      <if test="sightId != null">
        sight_id,
      </if>
      <if test="remind != null">
        remind,
      </if>
      <if test="sort != null">
        sort,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="scenicId != null">
        #{scenicId,jdbcType=INTEGER},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="price != null">
        #{price,jdbcType=INTEGER},
      </if>
      <if test="resourceid != null">
        #{resourceid,jdbcType=VARCHAR},
      </if>
      <if test="sightName != null">
        #{sightName,jdbcType=VARCHAR},
      </if>
      <if test="sightId != null">
        #{sightId,jdbcType=VARCHAR},
      </if>
      <if test="remind != null">
        #{remind,jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
        #{sort,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.fjs.scenic.entity.good.Goods">
    update goods
    <set>
      <if test="scenicId != null">
        scenic_id = #{scenicId,jdbcType=INTEGER},
      </if>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="price != null">
        price = #{price,jdbcType=INTEGER},
      </if>
      <if test="resourceid != null">
        resourceId = #{resourceid,jdbcType=VARCHAR},
      </if>
      <if test="sightName != null">
        sight_name = #{sightName,jdbcType=VARCHAR},
      </if>
      <if test="sightId != null">
        sight_id = #{sightId,jdbcType=VARCHAR},
      </if>
      <if test="remind != null">
        remind = #{remind,jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
        sort = #{sort,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fjs.scenic.entity.good.Goods">
    update goods
    set scenic_id = #{scenicId,jdbcType=INTEGER},
      name = #{name,jdbcType=VARCHAR},
      price = #{price,jdbcType=INTEGER},
      resourceId = #{resourceid,jdbcType=VARCHAR},
      sight_name = #{sightName,jdbcType=VARCHAR},
      sight_id = #{sightId,jdbcType=VARCHAR},
      remind = #{remind,jdbcType=VARCHAR},
      sort = #{sort,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>



  <!--自定义sql-->
  <select id="selectAll" resultMap="BaseResultMap" parameterType="com.fjs.scenic.entity.good.Goods">
    select
    <include refid="Base_Column_List"/>
    from goods
    <where>
      <if test="sightName != null and sightName != ''">
        AND sight_name like CONCAT('%',#{sightName},'%')
      </if>
      <if test="name != null and name != ''">
        AND name like CONCAT('%',#{name},'%')
      </if>
    </where>
  </select>

  <select id="getAllGoodsAndMinPrice" resultType="map">
    SELECT resourceId ticketId,qrcode as flag,door_type,sort_type isstock,sight_name ticketName,
    (SELECT convert(MIN(sell_price)/100,decimal(10,2))  FROM price_rule WHERE goods_id = goods.resourceId) price,remind,sort,person_type FROM goods
    where qrcode = #{flage}
     ORDER BY sort
  </select>

  <delete id="deleteGoodsNotIn">
    delete from goods where resourceId NOT IN
    <foreach collection="gids" item="gid" open="(" separator="," close=")">
      #{gid,jdbcType=VARCHAR}
    </foreach>
  </delete>

  <select id="selectByGoodsId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from goods
    where resourceId = #{resourceId,jdbcType=INTEGER}
  </select>

  <select id="selectAllGoods" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from goods
  </select>

  <update id="updateByCytGoodsIdSelective" parameterType="com.fjs.scenic.entity.good.Goods">
    update goods
    <set>
      <if test="scenicId != null">
        scenic_id = #{scenicId,jdbcType=INTEGER},
      </if>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="price != null">
        price = #{price,jdbcType=INTEGER},
      </if>
      <if test="sightName != null">
        sight_name = #{sightName,jdbcType=VARCHAR},
      </if>
      <if test="sightId != null">
        sight_id = #{sightId,jdbcType=VARCHAR},
      </if>
      <if test="remind != null">
        remind = #{remind,jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
        sort = #{sort},
      </if>
      <if test="sortType != null">
        sort_type = #{sortType},
      </if>
      <if test="doorType != null">
        door_type = #{doorType},
      </if>
      <if test="qrcode != null">
        qrcode = #{qrcode},
      </if>
      <if test="personType != null">
        person_type = #{personType},
      </if>
    </set>
    where resourceid = #{resourceid,jdbcType=INTEGER}
  </update>

</mapper>