package tech.glinfo.enbao.modules.sh.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import tech.glinfo.enbao.modules.sh.entity.ShDeviceTimingEntity;

import java.util.List;
import java.util.Map;

@Mapper
public interface OtherShDeviceTimingDao extends BaseMapper<ShDeviceTimingEntity> {

    @Select("<script>" +
            "  select *"
            + "    from sh_device_timing a where a.`status` = 1 AND ((a.repeats = 0 AND a.time = #{time1}) OR (a.repeats = 1 AND a.time = #{time2} AND FIND_IN_SET(${week},a.repeat_time)))"
            + " </script>")
    List<ShDeviceTimingEntity> listTimingByTime(Map<String, Object> params);

    @Select("<script>"
            + "  select *, IF(((a.repeats = 0 AND a.time = #{time1}) OR (a.repeats = 1 AND a.time = #{time2} AND FIND_IN_SET(${week},a.repeat_time))),1,2) flag from sh_device_timing a where a.`status` = 1 AND (((a.repeats = 0 AND a.time = #{time1}) OR (a.repeats = 1 AND a.time = #{time2} AND FIND_IN_SET(${week},a.repeat_time))) OR ((a.repeats = 0 AND a.close_time = #{time1}) OR (a.repeats = 1 AND a.close_time = #{time2} AND FIND_IN_SET(${week},a.repeat_time))))"
            + " </script>")
    List<Map<String, Object>> listTimingByTime1(Map<String, Object> params);


}
