<?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.ruoyi.system.mapper.NightMarketMapper">

    <resultMap type="NightMarket" id="NightMarketResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="image"    column="image"    />
        <result property="area"    column="area"    />
        <result property="address"    column="address"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="briefIntroduction"    column="brief_introduction"    />
        <result property="openBusiness"    column="open_business"    />
        <result property="windingUp"    column="winding_up"    />
        <result property="sort"    column="sort"    />
        <result property="userId"    column="user_id"    />
        <result property="cretim"    column="cretim"    />
        <result property="state"    column="state"    />
        <result property="telephone"    column="telephone"    />
        <result property="userName"    column="user_name"    />
        <result property="logo"    column="logo"    />
        <result property="offShelf"    column="off_shelf"    />
        <result property="hygieneLicence"    column="hygiene_licence"    />
    </resultMap>

    <sql id="selectNightMarketVo">
        select id, name, image, area, address, longitude, latitude, brief_introduction, open_business, winding_up, sort, user_id, cretim, state, telephone, user_name, logo, off_shelf, hygiene_licence from night_market
    </sql>

    <select id="selectNightMarketList" parameterType="NightMarket" resultMap="NightMarketResult">
        <include refid="selectNightMarketVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="image != null  and image != ''"> and image = #{image}</if>
            <if test="area != null  and area != ''"> and area = #{area}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="longitude != null "> and longitude = #{longitude}</if>
            <if test="latitude != null "> and latitude = #{latitude}</if>
            <if test="briefIntroduction != null  and briefIntroduction != ''"> and brief_introduction = #{briefIntroduction}</if>
            <if test="openBusiness != null  and openBusiness != ''"> and open_business = #{openBusiness}</if>
            <if test="windingUp != null  and windingUp != ''"> and winding_up = #{windingUp}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="cretim != null "> and cretim = #{cretim}</if>
            <if test="state != null "> and state = #{state}</if>
            <if test="telephone != null  and telephone != ''"> and telephone = #{telephone}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="logo != null  and logo != ''"> and logo = #{logo}</if>
            <if test="offShelf != null  and offShelf != ''"> and off_shelf = #{offShelf}</if>
            <if test="hygieneLicence != null  and hygieneLicence != ''"> and hygiene_licence = #{hygieneLicence}</if>
        </where>
    </select>

    <select id="selectNightMarketById" parameterType="Long" resultMap="NightMarketResult">
        <include refid="selectNightMarketVo"/>
        where id = #{id}
    </select>

    <insert id="insertNightMarket" parameterType="NightMarket" useGeneratedKeys="true" keyProperty="id">
        insert into night_market
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="image != null">image,</if>
            <if test="area != null">area,</if>
            <if test="address != null">address,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="briefIntroduction != null">brief_introduction,</if>
            <if test="openBusiness != null">open_business,</if>
            <if test="windingUp != null">winding_up,</if>
            <if test="sort != null">sort,</if>
            <if test="userId != null">user_id,</if>
            <if test="cretim != null">cretim,</if>
            <if test="state != null">state,</if>
            <if test="telephone != null">telephone,</if>
            <if test="userName != null">user_name,</if>
            <if test="logo != null">logo,</if>
            <if test="offShelf != null">off_shelf,</if>
            <if test="hygieneLicence != null">hygiene_licence,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="image != null">#{image},</if>
            <if test="area != null">#{area},</if>
            <if test="address != null">#{address},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="briefIntroduction != null">#{briefIntroduction},</if>
            <if test="openBusiness != null">#{openBusiness},</if>
            <if test="windingUp != null">#{windingUp},</if>
            <if test="sort != null">#{sort},</if>
            <if test="userId != null">#{userId},</if>
            <if test="cretim != null">#{cretim},</if>
            <if test="state != null">#{state},</if>
            <if test="telephone != null">#{telephone},</if>
            <if test="userName != null">#{userName},</if>
            <if test="logo != null">#{logo},</if>
            <if test="offShelf != null">#{offShelf},</if>
            <if test="hygieneLicence != null">#{hygieneLicence},</if>
        </trim>
    </insert>

    <update id="updateNightMarket" parameterType="NightMarket">
        update night_market
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="image != null">image = #{image},</if>
            <if test="area != null">area = #{area},</if>
            <if test="address != null">address = #{address},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="briefIntroduction != null">brief_introduction = #{briefIntroduction},</if>
            <if test="openBusiness != null">open_business = #{openBusiness},</if>
            <if test="windingUp != null">winding_up = #{windingUp},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="cretim != null">cretim = #{cretim},</if>
            <if test="state != null">state = #{state},</if>
            <if test="telephone != null">telephone = #{telephone},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="logo != null">logo = #{logo},</if>
            <if test="offShelf != null">off_shelf = #{offShelf},</if>
            <if test="hygieneLicence != null">hygiene_licence = #{hygieneLicence},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNightMarketById" parameterType="Long">
        delete from night_market where id = #{id}
    </delete>

    <delete id="deleteNightMarketByIds" parameterType="String">
        delete from night_market where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
