package com.bonus.canteen.core.allocation.canteen.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bonus.canteen.core.allocation.canteen.model.AllocLabel;
import com.bonus.canteen.core.allocation.canteen.vo.AllocLabelVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AllocLabelMapper extends BaseMapper<AllocLabel> {
   Page<AllocLabelVO> pageLabel(@Param("page") Page<AllocLabelVO> page, @Param("labelName") String labelName);

//   @Select({"SELECT DISTINCT label_name FROM alloc_label"})
//   List<String> listLabelName();

   @Select({"SELECT crtime, uptime FROM alloc_label WHERE label_name = #{labelName} ORDER BY id ASC LIMIT 1"})
   AllocLabel getTimeByName(@Param("labelName") String labelName);
//
//   @Select({"SELECT COUNT(*) FROM alloc_label WHERE label_name = #{labelName} AND canteen_id IS NULL AND stall_id IS NULL"})
//   Long countForRepeatCheck(@Param("labelName") String labelName);

   @Select({"<script>SELECT label_name FROM alloc_label <where> <if test='canteenId != null'> AND canteen_id = #{canteenId} </if><if test='stallId != null'> AND stall_id = #{stallId} </if></where></script>"})
   List<String> listRelationLabelName(@Param("canteenId") Long canteenId, @Param("stallId") Long stallId);
}
