<?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.bonus.canteen.core.menuai.mapper.MenuaiPictureMapper">
<!--    <insert id="insertBatch">-->
<!--        INSERT INTO menuai_picture-->
<!--        (id,stall_id, dishes_id, picture_url, picture_type, picture_name, train_tag,-->
<!--        show_tag)-->
<!--        VALUES-->
<!--        <foreach collection="list" item="item" index="index" separator=",">-->
<!--            (#{item.id},#{item.stallId}, #{item.dishesId}, #{item.pictureUrl}, #{item.pictureType},-->
<!--            #{item.pictureName}, #{item.trainTag}, #{item.showTag})-->
<!--        </foreach>-->
<!--    </insert>-->


<!--    <select id="selectRecipePictureNum" resultType="net.xnzn.core.menuai.vo.MenuaiRecipePictureNumVO">-->
<!--        select-->
<!--        md.dishes_id,-->
<!--        md.dishes_name-->
<!--        from-->
<!--        menu_recipe_detail mrd-->
<!--        left join menu_recipe_dishes m on mrd.detail_id = m.detail_id-->
<!--        left join menu_dishes md on m.dishes_id = md.dishes_id-->
<!--        where-->
<!--        mrd.apply_date = curdate()-->
<!--        and mrd.del_flag = 2-->
<!--        and mrd.recipe_id = #{content.recipeId}-->
<!--        and md.dishes_id is not null-->
<!--        <if test="content.dishesName != null and content.dishesName != ''">-->
<!--            and md.dishes_name like #{content.dishesName}-->
<!--        </if>-->
<!--        group by-->
<!--        md.dishes_id,-->
<!--        md.dishes_name-->
<!--    </select>-->

<!--    <select id="selectDishesPicture" resultType="net.xnzn.core.menuai.vo.MenuaiDishesPicturePageVO">-->
<!--        select mp.id,-->
<!--               md.dishes_name,-->
<!--               ac.canteen_name,-->
<!--               ass.stall_name  as shopstall_name,-->
<!--               mp.picture_url,-->
<!--               mp.picture_type as pic_type-->
<!--        from menuai_picture mp-->
<!--                 left join menu_dishes md on mp.dishes_id = md.dishes_id-->
<!--                 left join alloc_stall ass on mp.stall_id = ass.stall_id-->
<!--                 left join alloc_canteen ac on ass.canteen_id = ac.canteen_id-->
<!--        where mp.dishes_id = #{content.dishesId}-->
<!--          and mp.stall_id = #{content.shopstallId}-->
<!--        order by mp.picture_type-->
<!--    </select>-->

<!--    <select id="selectBigPictureById" resultType="net.xnzn.core.menuai.model.MenuaiBigPictureCutModel">-->
<!--        select ass.canteen_id,-->
<!--               ass.stall_id,-->
<!--               mp.picture_url,-->
<!--               mp.dishes_id-->
<!--        from menuai_picture mp-->
<!--                 left join alloc_stall ass on mp.stall_id = ass.stall_id-->
<!--        where mp.id = #{id}-->
<!--    </select>-->

    <select id="selectRemovePictureDetailList" resultType="com.bonus.canteen.core.menuai.model.MenuaiRemoveModel">
        select
        mp.stall_id,
        mp.picture_url,
        mp.dishes_id,
        mp.picture_name,
        mp.picture_type,
        md.dishes_name
        from
        menuai_picture mp
        left join menu_dishes md on mp.dishes_id = md.dishes_id
        where
        mp.id in
        <foreach collection="removeIdList" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </select>

<!--    <select id="selectAllDishesPictureNum" resultType="net.xnzn.core.menuai.vo.MenuaiRecipePictureNumVO">-->
<!--        select-->
<!--        md.dishes_id,-->
<!--        md.dishes_name,-->
<!--        count(mp.id) as dishes_num,-->
<!--        count(mp.picture_type = 1 or null) as big_pic_num,-->
<!--        count(mp.picture_type = 2 or null) as small_pic_num-->
<!--        from-->
<!--        menu_dishes md-->
<!--        left join menuai_picture mp on md.dishes_id = mp.dishes_id-->
<!--        <choose>-->
<!--            <when test="content.shopstallId != null and content.shopstallId != ''">-->
<!--                and mp.stall_id IN(#{content.shopstallId},0)-->
<!--            </when>-->
<!--            <otherwise>-->
<!--                and mp.stall_id IN(0)-->
<!--            </otherwise>-->
<!--        </choose>-->
<!--        where-->
<!--        md.del_flag = 2-->
<!--        <if test="content.dishesName != null and content.dishesName != ''">-->
<!--            and md.dishes_name like #{content.dishesName}-->
<!--        </if>-->
<!--        group by-->
<!--        md.dishes_id,-->
<!--        md.dishes_name-->
<!--        <trim prefix="having" prefixOverrides="and">-->
<!--            <if test='content.ifExistSmallPic != null and content.ifExistSmallPic == 1'>-->
<!--                and small_pic_num > 0-->
<!--            </if>-->
<!--            <if test='content.ifExistSmallPic != null and content.ifExistSmallPic == 2'>-->
<!--                and small_pic_num <![CDATA[ <=]]> 0-->
<!--            </if>-->
<!--            <if test='content.ifTakePhoto != null and content.ifTakePhoto == 1'>-->
<!--                and dishes_num > 0-->
<!--            </if>-->
<!--            <if test='content.ifTakePhoto != null and content.ifTakePhoto == 2'>-->
<!--                and dishes_num <![CDATA[ <=]]> 0-->
<!--            </if>-->
<!--        </trim>-->
<!--    </select>-->

<!--    <select id="selectAllDishesPicture" resultType="net.xnzn.core.menuai.model.MenuaiAllDishesModel">-->
<!--        select mp.dishes_id,-->
<!--               md.dishes_name,-->
<!--               mp.picture_url,-->
<!--               mp.picture_type-->
<!--        from menuai_picture mp-->
<!--                 left join menu_dishes md on mp.dishes_id = md.dishes_id-->
<!--        where mp.stall_id = #{stallId}-->
<!--          and (md.dishes_name is not null-->
<!--            or mp.dishes_id = 10000)-->
<!--    </select>-->

<!--    <select id="selectRemovePictureDetailLimit" resultType="net.xnzn.core.menuai.model.MenuaiRemoveModel">-->
<!--        select mp.id,-->
<!--               mp.stall_id,-->
<!--               mp.picture_url,-->
<!--               mp.picture_name,-->
<!--               mp.dishes_id,-->
<!--               md.dishes_name-->
<!--        from menuai_picture mp-->
<!--                 left join menu_dishes md on mp.dishes_id = md.dishes_id-->
<!--        where mp.picture_type = 2-->
<!--          and mp.stall_id = #{stallId}-->
<!--          and mp.dishes_id = #{dishesId}-->
<!--        order by mp.crtime desc-->
<!--            limit #{pictureLimit}, #{pictureLimit}-->
<!--    </select>-->

    <select id="selectRemovePictureDetailByStallId" resultType="com.bonus.canteen.core.menuai.model.MenuaiRemoveModel">
        select mp.id,
               ass.canteen_id,
               ass.stall_id,
               mp.picture_url
        from menuai_picture mp
                 left join alloc_stall ass on mp.stall_id = ass.stall_id
        where mp.picture_type = 1
          and mp.stall_id = #{stallId}
          and mp.id not in (select big_picture_id
                            from menuai_picture
                            group by big_picture_id)
    </select>

<!--    <select id="selectRegistPic" resultType="net.xnzn.core.menuai.vo.MenuaiRegistPicVO">-->
<!--        select-->
<!--        mp.dishes_id,-->
<!--        md.dishes_name,-->
<!--        mp.picture_url,-->
<!--        mp.picture_type,-->
<!--        mp.picture_name-->
<!--        from-->
<!--        menuai_picture mp-->
<!--        left join menu_dishes md on mp.dishes_id = md.dishes_id-->
<!--        where-->
<!--        mp.stall_id = #{stallId}-->
<!--        and mp.picture_type= #{pictureType}-->
<!--        and mp.dishes_id in-->
<!--        <foreach collection="dishesIdList" item="dishesId" separator="," open="(" close=")">-->
<!--            #{dishesId}-->
<!--        </foreach>-->
<!--    </select>-->

<!--    <select id="countDishesPictureByConsumerPicId" resultType="int">-->
<!--        select count(*)-->
<!--        from menuai_picture mp-->
<!--        where mp.consumer_detect_pic_id = #{consumerDetectPicId}-->
<!--    </select>-->

<!--    <select id="selectDishesPictureNumByDishesIds" resultType="net.xnzn.core.menuai.model.MenuaiDishesPictureNumModel">-->
<!--        select dishes_id, count(picture_type = 1 or null) as big_pic_num,-->
<!--        count(picture_type = 2 or null) as small_pic_num, count(1) as picture_num from menuai_picture-->
<!--        where dishes_id IN-->
<!--        <foreach collection="dishesIdList" item="dishesId" separator="," open="(" close=")">-->
<!--            #{dishesId}-->
<!--        </foreach>-->
<!--        group by dishes_id-->
<!--    </select>-->
<!--    <select id="selectDishesAllSmallPictureBySql" resultType="net.xnzn.core.menuai.entity.MenuaiPictureExtend">-->
<!--        select-->
<!--        mp.id,-->
<!--        mp.stall_id,-->
<!--        mp.picture_url,-->
<!--        mp.dishes_id,-->
<!--        mp.picture_name,-->
<!--        mp.picture_type,-->
<!--        md.dishes_name-->
<!--        from-->
<!--        menuai_picture mp-->
<!--        left join menu_dishes md on mp.dishes_id = md.dishes_id-->
<!--        where-->
<!--        mp.dishes_id IN-->
<!--        <foreach collection="dishesIdList" item="id" separator="," open="(" close=")">-->
<!--            #{id}-->
<!--        </foreach>-->
<!--        and picture_type=#{pictureType}-->
<!--        and stall_id=#{stallId}-->
<!--    </select>-->
<!--    <select id="selectRegistPicByTrainTag" resultType="net.xnzn.core.menuai.vo.MenuaiRegistPicVO">-->
<!--        select-->
<!--        mp.dishes_id,-->
<!--        md.dishes_name,-->
<!--        mp.picture_url,-->
<!--        mp.picture_type,-->
<!--        mp.picture_name-->
<!--        from-->
<!--        menuai_picture mp-->
<!--        left join menu_dishes md on mp.dishes_id = md.dishes_id-->
<!--        where-->
<!--        mp.stall_id = #{stallId}-->
<!--        and mp.picture_type= #{pictureType}-->
<!--        and mp.dishes_id in-->
<!--        <foreach collection="dishesIdList" item="dishesId" separator="," open="(" close=")">-->
<!--            #{dishesId}-->
<!--        </foreach>-->
<!--    </select>-->


<!--    <select id="selectRegistPicByTrainTagLimit" resultType="net.xnzn.core.menuai.vo.MenuaiRegistPicVO">-->
<!--        select-->
<!--        mp.dishes_id,-->
<!--        md.dishes_name,-->
<!--        mp.picture_url,-->
<!--        mp.picture_type,-->
<!--        mp.picture_name-->
<!--        from-->
<!--        menuai_picture mp-->
<!--        left join menu_dishes md on mp.dishes_id = md.dishes_id-->
<!--        where-->
<!--        mp.stall_id = #{stallId}-->
<!--        and mp.picture_type= #{pictureType}-->
<!--        and mp.train_tag =#{trainTag}-->
<!--        and mp.dishes_id in-->
<!--        <foreach collection="dishesIdList" item="dishesId" separator="," open="(" close=")">-->
<!--            #{dishesId}-->
<!--        </foreach>-->
<!--        limit #{limitSize}-->
<!--    </select>-->
</mapper>
