<?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.consume.mapper.ConsumeMaintainMapper">
    <sql id="columns">
         id as id, send_time as sendTime, send_status as sendStatus, describe_info as describeInfo, is_timing as isTiming, menu_number as menuNumber, begin_date as beginDate, end_date as endDate, is_delete as isDelete, create_by as createBy, create_time as createTime, update_by as updateBy, update_time as updateTime, organization_code as organizationCode
    </sql>

    <sql id="where">
        <where>
            <if test="@sqlt.Ognl@isNotEmpty(sendTime)">
                and send_time = #{sendTime}
            </if>
            <if test="@sqlt.Ognl@isNotEmpty(sendStatus)">
                and send_status = #{sendStatus}
            </if>
            <if test="@sqlt.Ognl@isNotEmpty(isTiming)">
                and is_timing = #{isTiming}
            </if>
            <if test="@sqlt.Ognl@isNotEmpty(menuNumber)">
                and menu_number = #{menuNumber}
            </if>
        </where>
    </sql>

    <select id="selectConsumeMaintainList" resultType="com.willalp.consume.domain.ConsumeMaintain">
        select a.id as id,
            a.send_time as sendTime,
            a.send_status as sendStatus,
            a.describe_info as describeInfo,
            a.is_timing as isTiming,
            a.menu_number as menuNumber,
            a.begin_date as beginDate,
            a.end_date as endDate,
            a.is_delete as isDelete,
            a.create_by as createBy,
            a.create_time as createTime,
            a.update_by as updateBy,
            a.update_time as updateTime,
            b.menu_name as menuName
        from pns_consume_maintain a
        left join hs_canteen_menu b on a.menu_number = b.menu_number
        where a.is_delete = 0
        <if test="@sqlt.Ognl@isNotEmpty(sendTime)">
            and a.send_time = #{sendTime}
        </if>
        <if test="@sqlt.Ognl@isNotEmpty(sendStatus)">
            and a.send_status = #{sendStatus}
        </if>
        <if test="@sqlt.Ognl@isNotEmpty(menuNumber)">
            and a.menu_number = #{menuNumber}
        </if>
        <if test="@sqlt.Ognl@isNotEmpty(organizations)">
            and a.organization_code in
            <foreach collection="organizations" item="z" open="(" close=")" >
                #{z}
            </foreach>
        </if>
        <if test="@sqlt.Ognl@isNotEmpty(organizationCode)">
            and a.organization_code = #{organizationCode}
        </if>
        order by a.send_time desc
    </select>
</mapper>
