package com.ho.business.mapper;


import com.ho.business.entity.TabTag;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

@Mapper
public interface TabTagWebMapper {

    @Select("select * from tab_tag where tab_id=#{tabId}")
    @Results(id = "userMap",value={
            @Result(id = true, property = "tagId", column = "tag_id"),
            @Result(property = "tagName", column = "tag_name"),
            @Result(property = "tagType", column = "tag_type"),
            @Result(property = "tagNameEn", column = "tag_name_en"),
            @Result(property = "srcId", column = "src_id"),
            @Result(property = "tabId", column = "tab_id"),
            @Result(property = "col", column = "col"),
            @Result(property = "maxValue", column = "max_value"),
            @Result(property = "minValue", column = "min_value"),
            @Result(property = "frame", column = "frame"),
            @Result(property = "colName", column = "col_name"),
            @Result(property = "description", column = "description"),
            @Result(property = "unit", column = "unit"),
            @Result(property = "values", column = "tag_id",
                    many = @Many(select = "com.ho.business.mapper.TabTagDefaultValueMapper.queryTabTagDefaultValueList",fetchType= FetchType.EAGER))
    })
    List<TabTag> queryTabTags(@Param("tabId") Integer tabId);

    @Delete("delete from tab_tag where tab_id=#{tabId}")
    int deleteTabTags(@Param("tabId") Integer tabId);

    @Insert("insert into tab_tag(tag_name,tag_type,tag_name_en,src_id,tab_id,col,max_value,min_value,frame,col_name,description,unit,device_type,changeover) values(#{tagName},#{tagType},#{tagNameEn},#{srcId},#{tabId},#{col},#{maxValue},#{minValue},#{frame},#{colName},#{description},#{unit},#{deviceType},#{changeover})")
    @Options(useGeneratedKeys=true, keyProperty="tagId", keyColumn="tag_id")
    int insert(TabTag tabTag);

    @Select("select * from tab_tag where tab_id=#{tabId} order by tag_id")
    List<TabTag> queryTabTagList(@Param("tabId") Integer tabId);
}
