package com.nokia.hb.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nokia.hb.dao.entity.IndicatorTemplateItem;
import com.nokia.hb.pojo.bo.IndicatorTemplateItemBo;
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;

/**
 * <p>
 * 指标模板关联表 Mapper 接口
 * </p>
 *
 * @author baomidou
 * @since 2023-02-27
 */
@Mapper
public interface IndicatorTemplateItemMapper extends BaseMapper<IndicatorTemplateItem> {
    /**
     * 插入批
     *
     * @param list 列表
     * @return int
     */
    @Update("<script>"
            + " insert into pm_parse.indicator_template_item (template_id, indicator_id) values"
            + "     <foreach collection=\"list\" item=\"item\" index=\"index\" separator=\",\">"
            + "       (#{item.templateId}, #{item.indicatorId})"
            + "     </foreach>"
            + " </script>")
    int insertBatch(List<IndicatorTemplateItem> list);

    /**
     * 通过模板id查询列表
     *
     * @param list 模板id列表
     * @return {@link List}<{@link IndicatorTemplateItemBo}>
     */
    @Select("<script>"
            + " select iti.template_id, iti.indicator_id, pci.indicator_cn, pci.indicator_en"
            + " from pm_parse.indicator_template_item iti"
            + " inner join pm_parse.per_cfg_indicator pci on iti.indicator_id = pci.indicator_id"
            + " where iti.template_id in"
            + " <foreach open=\"(\" close=\")\" collection=\"list\" item=\"item\" separator=\",\">"
            + "   #{item}"
            + " </foreach>"
            + " order by iti.template_id, iti.indicator_id"
            + " </script>")
    List<IndicatorTemplateItemBo> listByTemplateIds(@Param("list") List<Long> list);

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