<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.energy.manage.service.mappers.analysis.AnalysisDiagramRelationMapper">
    <resultMap id="BaseResultMap" type="com.energy.manage.common.po.analysis.AnalysisDiagramRelationPo">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="batch_code" property="batchCode" jdbcType="VARCHAR"/>
        <result column="field_engine_code" property="fieldEngineCode" jdbcType="VARCHAR"/>
        <result column="analysis_type_code" property="analysisTypeCode" jdbcType="VARCHAR"/>
        <result column="file_addr" property="fileAddr" jdbcType="VARCHAR"/>
        <result column="auto_analysis" property="autoAnalysis" jdbcType="INTEGER"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <select id="selectByCondition" parameterType="java.lang.String" resultType="com.energy.manage.service.domain.vo.analysis.AnalysisDiagramRelationVo">
        select
            adr.batch_code,
            adr.field_engine_code,
            weg.engine_name as field_engine_name,
            adr.analysis_type_code,
            adr.file_addr,
            adr.create_time
        from analysis_diagram_relation adr
        left join wind_engine_group weg
        on adr.field_engine_code = weg.engine_code
        where adr.batch_code = #{batchCode,jdbcType=VARCHAR}
        <if test="analysisTypeCode != null and analysisTypeCode != ''">
              and adr.analysis_type_code = #{analysisTypeCode,jdbcType=VARCHAR}
        </if>
        <if test="fieldEngineCode != null and fieldEngineCode.size != 0">
            and adr.field_engine_code in
          <foreach collection="fieldEngineCode" item="item" separator="," open="("  close=")">
             #{item,jdbcType=VARCHAR}
          </foreach>
        </if>
    </select>
    <select id="selectByBatchCode" parameterType="java.lang.String" resultType="com.energy.manage.service.domain.vo.analysis.AnalysisDiagramRelationVo">
        select
            relations.analysis_type_code,
            types.type_name as analysis_type_name
        from analysis_diagram_relation relations
        left join analysis_type types
        on types.type_code = relations.analysis_type_code
        where relations.batch_code = #{batchCode,jdbcType=VARCHAR}
    </select>

    <select id="selectByBatchCodeAndAnalysisTypeCode" parameterType="java.lang.String" resultType="com.energy.manage.service.domain.vo.windenginegroup.WindEngineGroupShortVo">
        select
            relations.field_engine_code as engine_code,
            engine.engine_name
        from analysis_diagram_relation relations
        left join wind_engine_group engine
        on relations.field_engine_code = engine.engine_code
        where relations.batch_code = #{batchCode,jdbcType=VARCHAR}
        and relations.analysis_type_code = #{analysisTypeCode,jdbcType=VARCHAR}
    </select>
</mapper>
