<?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.scenic.ScenicMapper">
    <resultMap id="BaseResultMap" type="com.fjs.scenic.entity.scenic.Scenic">
        <id column="id" jdbcType="INTEGER" property="id" />
        <result column="name" jdbcType="VARCHAR" property="name" />
        <result column="grade" jdbcType="TINYINT" property="grade" />
        <result column="intro" jdbcType="VARCHAR" property="intro" />
        <result column="addr" jdbcType="VARCHAR" property="addr" />
        <result column="lon" jdbcType="VARCHAR" property="lon" />
        <result column="lat" jdbcType="VARCHAR" property="lat" />
        <result column="phone" jdbcType="VARCHAR" property="phone" />
        <result column="void_url" jdbcType="VARCHAR" property="voidUrl" />
        <result column="vr_url" jdbcType="VARCHAR" property="vrUrl" />
        <result column="business_time" jdbcType="VARCHAR" property="businessTime" />
    </resultMap>
    <sql id="Base_Column_List">
        id, name, grade, intro, addr, lon, lat, phone, void_url, vr_url, business_time
    </sql>
    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from scenic
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete from scenic
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <insert id="insert" parameterType="com.fjs.scenic.entity.scenic.Scenic">
        insert into scenic (id, name, grade,
        intro, addr, lon, lat,
        phone, void_url, vr_url,
        business_time)
        values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{grade,jdbcType=TINYINT},
        #{intro,jdbcType=VARCHAR}, #{addr,jdbcType=VARCHAR}, #{lon,jdbcType=VARCHAR}, #{lat,jdbcType=VARCHAR},
        #{phone,jdbcType=VARCHAR}, #{voidUrl,jdbcType=VARCHAR}, #{vrUrl,jdbcType=VARCHAR},
        #{businessTime,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" parameterType="com.fjs.scenic.entity.scenic.Scenic">
        insert into scenic
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="grade != null">
                grade,
            </if>
            <if test="intro != null">
                intro,
            </if>
            <if test="addr != null">
                addr,
            </if>
            <if test="lon != null">
                lon,
            </if>
            <if test="lat != null">
                lat,
            </if>
            <if test="phone != null">
                phone,
            </if>
            <if test="voidUrl != null">
                void_url,
            </if>
            <if test="vrUrl != null">
                vr_url,
            </if>
            <if test="businessTime != null">
                business_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="name != null">
                #{name,jdbcType=VARCHAR},
            </if>
            <if test="grade != null">
                #{grade,jdbcType=TINYINT},
            </if>
            <if test="intro != null">
                #{intro,jdbcType=VARCHAR},
            </if>
            <if test="addr != null">
                #{addr,jdbcType=VARCHAR},
            </if>
            <if test="lon != null">
                #{lon,jdbcType=VARCHAR},
            </if>
            <if test="lat != null">
                #{lat,jdbcType=VARCHAR},
            </if>
            <if test="phone != null">
                #{phone,jdbcType=VARCHAR},
            </if>
            <if test="voidUrl != null">
                #{voidUrl,jdbcType=VARCHAR},
            </if>
            <if test="vrUrl != null">
                #{vrUrl,jdbcType=VARCHAR},
            </if>
            <if test="businessTime != null">
                #{businessTime,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.fjs.scenic.entity.scenic.Scenic">
        update scenic
        <set>
            <if test="name != null">
                name = #{name,jdbcType=VARCHAR},
            </if>
            <if test="grade != null">
                grade = #{grade,jdbcType=TINYINT},
            </if>
            <if test="intro != null">
                intro = #{intro,jdbcType=VARCHAR},
            </if>
            <if test="addr != null">
                addr = #{addr,jdbcType=VARCHAR},
            </if>
            <if test="lon != null">
                lon = #{lon,jdbcType=VARCHAR},
            </if>
            <if test="lat != null">
                lat = #{lat,jdbcType=VARCHAR},
            </if>
            <if test="phone != null">
                phone = #{phone,jdbcType=VARCHAR},
            </if>
            <if test="voidUrl != null">
                void_url = #{voidUrl,jdbcType=VARCHAR},
            </if>
            <if test="vrUrl != null">
                vr_url = #{vrUrl,jdbcType=VARCHAR},
            </if>
            <if test="businessTime != null">
                business_time = #{businessTime,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.fjs.scenic.entity.scenic.Scenic">
        update scenic
        set name = #{name,jdbcType=VARCHAR},
        grade = #{grade,jdbcType=TINYINT},
        intro = #{intro,jdbcType=VARCHAR},
        addr = #{addr,jdbcType=VARCHAR},
        lon = #{lon,jdbcType=VARCHAR},
        lat = #{lat,jdbcType=VARCHAR},
        phone = #{phone,jdbcType=VARCHAR},
        void_url = #{voidUrl,jdbcType=VARCHAR},
        vr_url = #{vrUrl,jdbcType=VARCHAR},
        business_time = #{businessTime,jdbcType=VARCHAR}
        where id = #{id,jdbcType=INTEGER}
    </update>

    <!--自定义-->
    <resultMap id="BaseResultMap2" type="com.fjs.scenic.entity.scenic.po.ScenicPo">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="name" property="name" jdbcType="VARCHAR"/>
        <result column="grade" property="grade" jdbcType="VARCHAR"/>
        <result column="intro" property="intro" jdbcType="INTEGER"/>
        <result column="addr" property="addr" jdbcType="VARCHAR"/>
        <result column="lon" property="lon" jdbcType="VARCHAR"/>
        <result column="lat" property="lat" jdbcType="VARCHAR"/>
        <result column="description" property="description" jdbcType="VARCHAR"/>
        <result column="phone" property="phone" jdbcType="VARCHAR"/>
        <result column="void_url" property="voidUrl" jdbcType="VARCHAR"/>
        <result column="vr_url" property="vrUrl" jdbcType="VARCHAR"/>
        <result column="content" property="content" jdbcType="VARCHAR"/>
        <result column="business_time" jdbcType="VARCHAR" property="businessTime" />
        <collection property="pics" column="id"
                    select="com.fjs.scenic.mapper.scenic.PicsMapper.selectByFid">
        </collection>
    </resultMap>

    <select id="find" resultMap="BaseResultMap2" parameterType="java.lang.Integer">
        SELECT
            s.*, sd.description,
            ti.content
        FROM scenic s
        LEFT JOIN scenic_description sd ON sd.scenic_id = s.id
        LEFT JOIN ticket_information ti ON s.id = ti.scenic_id
        WHERE s.id = #{id,jdbcType=INTEGER}
  </select>
  
  <select id="getStock" resultType="java.lang.Integer">
        SELECT stock FROM scenic
  </select>
  
  <select id="getNextStock" resultType="java.lang.Integer">
       SELECT next_stock FROM scenic
  </select>
  
    <update id="subInventory">
  UPDATE scenic SET stock=stock-#{num} WHERE stock-#{num}>=0
  </update>
  
  <update id="addInventory">
  UPDATE scenic SET stock=stock+#{num}
  </update>
  
  
</mapper>