package com.nokia.hb.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nokia.hb.dao.entity.IndicatorTemplate;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 指标模板 Mapper 接口
 * </p>
 *
 * @author baomidou
 * @since 2023-02-27
 */
@Mapper
public interface IndicatorTemplateMapper extends BaseMapper<IndicatorTemplate> {
    /**
     * 根据用户名查询指标模板
     *
     * @param username 用户名
     * @return {@link List}<{@link IndicatorTemplate}>
     */
    @Select("select * from pm_parse.indicator_template where username = #{username} order by id")
    List<IndicatorTemplate> listByUsername(String username);

    /**
     * 过滤不属于该用户的模板id
     *
     * @param username 用户名
     * @param list     模板id列表
     * @return {@link List}<{@link Long}>
     */
    @Select("<script>"
            + "select id from pm_parse.indicator_template"
            + " where username = #{username}"
            + " and id in"
            + " <foreach open=\"(\" close=\")\" collection=\"list\" item=\"item\" separator=\",\">"
            + "   #{item}"
            + " </foreach>"
            + " order by id"
            + " </script>")
    List<Long> getIds(@Param("username") String username, @Param("list") Set<Long> list);

    /**
     * 删除批处理
     *
     * @param list 模板id列表
     * @return int
     */
    @Update("<script>"
            + "delete from pm_parse.indicator_template"
            + " where id in"
            + " <foreach open=\"(\" close=\")\" collection=\"list\" item=\"item\" separator=\",\">"
            + "   #{item}"
            + " </foreach>"
            + " </script>")
    int deleteBatch(@Param("list") List<Long> list);
}
