<?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.HsCanteenMenuMapper">

    <resultMap type="HsCanteenMenu" id="HsCanteenMenuResult">
        <result property="menuId" column="menu_id"/>
        <result property="menuNumber" column="menu_number"/>
        <result property="menuName" column="menu_name"/>
        <result property="periodId" column="period_id"/>
        <result property="patternId" column="pattern_id"/>
        <result property="consumerType" column="consumer_type"/>
        <result property="diningPlace" column="dining_place"/>
        <result property="maxCount" column="max_count"/>
        <result property="jgid" column="jgid"/>
        <result property="useDate" column="use_date"/>
        <result property="isDelete" column="is_delete"/>
    </resultMap>

    <sql id="selectHsCanteenMenuVo">
        select menu_id,
               menu_number,
               menu_name,
               period_id,
               pattern_id,
               consumer_type,
               max_count,
               dining_place,
               jgid,
               use_date,
               is_delete
        from hs_canteen_menu
    </sql>

    <select id="selectHsCanteenMenuList" parameterType="HsCanteenMenu" resultMap="HsCanteenMenuResult">
        <include refid="selectHsCanteenMenuVo"/>
        <where>
            is_delete = 0
            <if test="menuNumber != null  and menuNumber != ''">and menu_number like concat('%', #{menuNumber}, '%')
            </if>
            <if test="menuName != null  and menuName != ''">and menu_name like concat('%', #{menuName}, '%')</if>
            <if test="periodId != null ">and period_id = #{periodId}</if>
            <if test="patternId != null ">and pattern_id = #{patternId}</if>
            <if test="consumerType != null and consumerType != '' ">and consumer_type = #{consumerType}</if>
            <if test="jgid != null ">and jgid = #{jgid}</if>
            <if test="useDate != null">and Date(use_date) = #{useDate}</if>
        </where>
        order by menu_number desc
    </select>

    <select id="getLimitMenu" parameterType="GetLimitMenuVo" resultMap="HsCanteenMenuResult">
        <include refid="selectHsCanteenMenuVo"></include>
        <where>
            is_delete = 0
            <if test="jgid !=null and jgid != ''">and jgid = #{jgid}</if>
            <if test="date != null and days != null">
                and date(use_date)>= date(#{date}) and date(use_date) &lt;= DATE_ADD(date(#{date}),INTERVAL #{days} DAY)
            </if>
        </where>
    </select>

    <select id="selectAppMenuList" resultMap="HsCanteenMenuResult">
        <include refid="selectHsCanteenMenuVo"/>
        <where>
            is_delete = 0
            <if test="jgid != null and jgid != '' ">and jgid = #{jgid}</if>
            <if test="@sqlt.Ognl@isNotEmpty(nums)">
                and menu_number in
                <foreach collection="nums" item="z" open="(" close=")" separator=",">
                    #{z}
                </foreach>
            </if>

        </where>
    </select>
</mapper>
