<?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.willalp.canteen.mapper.HsCanteenDiningPlaceMapper">

    <resultMap type="HsCanteenDiningPlace" id="HsCanteenDiningPlaceResult">
        <result property="placeId" column="place_id"/>
        <result property="parentId" column="parent_id"/>
        <result property="ancestors" column="ancestors"/>
        <result property="placeName" column="place_name"/>
        <result property="jgid" column="jgid"/>
        <result property="isDelete" column="is_delete"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
        <result property="placeNumber" column="place_number"/>
        <result property="placeSite" column="place_site"/>
        <result property="placeType" column="place_type"/>
        <result property="coordinate" column="coordinate"/>
        <result property="maxMumOfPeople" column="max_mum_of_people"/>
        <result property="placeImgUrl" column="place_img_url"/>
        <result property="details" column="details"/>
    </resultMap>

    <sql id="selectHsCanteenDiningPlaceVo">
        select place_id,
               parent_id,
               ancestors,
               place_name,
               jgid,
               place_img_url,
               is_delete,
               create_by,
               create_time,
               update_by,
               update_time,
               remark,
               place_number,
               place_site,
               place_type,
               coordinate,
               max_mum_of_people,
               details
        from hs_canteen_dining_place
    </sql>

    <select id="selectHsCanteenDiningPlaceList" parameterType="HsCanteenDiningPlace"
            resultMap="HsCanteenDiningPlaceResult">
        <include refid="selectHsCanteenDiningPlaceVo"/>
        <where>
            is_delete = 0
            <if test="placeName != null  and placeName != ''">and place_name like concat('%', #{placeName}, '%')</if>
            <if test="jgid != null  and jgid != ''">and jgid = #{jgid}</if>
            <if test="placeType != null ">and place_type = #{placeType}</if>
            <if test="parentId != null">and parent_id = #{parentId}</if>
        </where>
    </select>

    <select id="selectById" resultMap="HsCanteenDiningPlaceResult">
        <include refid="selectHsCanteenDiningPlaceVo"/>
        <where>
            is_delete = 0 and place_id = #{placeId}
        </where>
    </select>
    <update id="updateHsCanteenDiningPlace" parameterType="HsCanteenDiningPlace">
        update hs_canteen_dining_place
        <set>
            <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
            <if test="placeName != null and placeName != ''">place_name = #{placeName},</if>
            <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="placeSite != null and placeSite  != ''">place_site = #{placeSite},</if>
            <if test="coordinate != null and coordinate != ''">coordinate = #{coordinate},</if>
            update_time = sysdate()
        </set>
        where place_id = #{placeId}
    </update>

    <update id="deleteHsCanteenDiningPlaceByPlaceId">
        update hs_canteen_dining_place
        set is_delete = 1
        where place_id = #{placeId}
    </update>
</mapper>
