<?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.huatek.busi.mapper.BusiParamTransformerMapper">

    <sql id="Base_Column_List">
            id as id,
            site_id as siteId,
            main_equipment_id as mainEquipmentId,
            weight_level as weightLevel,
            name as name,
            pname as pname,
			a_value as aValue,
			b_value as bValue,
            description as description,
            value as value,
            ab_value_flag as abValueFlag,
            warning_value as warningValue,
            model as model,
            is_attend as isAttend,
            create_time as createTime,
            create_user as createUser,
            calculated_value as calculatedValue,
            sort_num as sortNum,
            scope as scope,
            number as number,
            concat(ifnull(description,''),IFNULL(scope,'')) as scopeDescription
    </sql>
    <sql id="Base_Column_ListVo">
            id as id,
            site_id as siteId,
            main_equipment_id as mainEquipmentId,
            weight_level as weightLevel,
            name as name,
            pname as pname,
			a_value as aValue,
			b_value as bValue,
            description as description,
            value as value,
            ab_value_flag as abValueFlag,
            warning_value as warningValue,
            model as model,
            is_attend as isAttend,
            create_time as createTime,
            create_user as createUser,
            calculated_value as calculatedValue,
            sort_num as sortNum,
            scope as scope,
            number,
            concat(ifnull(description,''),IFNULL(scope,'')) as scopeDescription
    </sql>
    <sql id="Base_Column_List_NotValue">
            id as id,
            site_id as siteId,
            main_equipment_id as mainEquipmentId,
            weight_level as weightLevel,
            name as name,
            pname as pname,
            description as description,
            ab_value_flag as abValueFlag,
            warning_value as warningValue,
            model as model,
            is_attend as isAttend,
            create_time as createTime,
            create_user as createUser,
            sort_num as sortNum,
            calculated_value as calculatedValue,
            number as number ,
		    scope as scope,
            concat(ifnull(description,''),IFNULL(scope,'')) as scopeDescription
    </sql>
	<select id="findFirstLevelParams"  resultType="com.huatek.busi.vo.BusiParamTransformerVo">
		SELECT
        <include refid="Base_Column_List"/>
        FROM
        busi_param_transformer t
        WHERE t.site_id = #{siteId} and t.main_equipment_id = #{mainEquipmentId}
            AND t.number = #{number}
        	AND t.weight_level = '1'
        GROUP BY name
        ORDER BY t.sort_num ASC, t.name ASC
	</select>

    <select id="findNotValueFirstLevelParams"  resultType="com.huatek.busi.vo.BusiParamTransformerVo">
        SELECT
        <include refid="Base_Column_List_NotValue"/>
        FROM
        busi_param_transformer t
        WHERE t.site_id = #{siteId} and t.main_equipment_id = #{mainEquipmentId}
        and t.number = #{number}
        AND t.weight_level = '1'
        GROUP BY name
        ORDER BY t.sort_num ASC, t.name ASC
    </select>

	<select id="findSubParams"  resultType="com.huatek.busi.vo.BusiParamTransformerVo">
		SELECT
        <include refid="Base_Column_List"/>
        FROM
        busi_param_transformer t
        WHERE t.site_id = #{siteId} and t.main_equipment_id = #{mainEquipmentId}
        	AND t.pname = #{pname}
        	AND t.number = #{number}
        GROUP BY name
        ORDER BY t.sort_num ASC, t.name ASC
	</select>

    <select id="findSubParamsCalculate" parameterType="java.lang.String" resultType="com.huatek.busi.vo.BusiParamTransformerVo">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        busi_param_transformer t
        WHERE t.site_id = #{siteId} and t.main_equipment_id = #{mainEquipmentId}
        AND t.pname = #{pname}
        GROUP BY name
        ORDER BY t.sort_num ASC, t.name ASC
    </select>

	<select id="findParams" parameterType="java.lang.String" resultType="com.huatek.busi.vo.BusiParamTransformerVo">
		SELECT
        <include refid="Base_Column_List"/>
        FROM
        busi_param_transformer_voluntarily t
        WHERE t.site_id = #{siteId} and t.main_equipment_id = #{mainEquipmentId} and t.number = (SELECT MAX(number) FROM busi_param_transformer_voluntarily WHERE site_id = #{siteId} and main_equipment_id =
        #{mainEquipmentId})
	</select>

    <select id="findParamsManual" parameterType="java.lang.String" resultType="com.huatek.busi.vo.BusiParamTransformerVo">
        SELECT
            id AS id,
            site_id AS siteId,
            main_equipment_id AS mainEquipmentId,
            weight_level AS weightLevel,
            NAME AS NAME,
            pname AS pname,
            description AS description,
            VALUE AS VALUE,
            ab_value_flag AS abValueFlag,
            a_value AS aValue,
            b_value AS bValue,
            warning_value AS warningValue,
            model AS model,
            is_attend AS isAttend,
            create_time AS createTime,
            create_user AS createUser,
            sort_num AS sortNum,
            number
        FROM
        busi_param_transformer t
        WHERE t.site_id = #{siteId} and t.main_equipment_id = #{mainEquipmentId}
        AND t.number = (SELECT MAX(number) FROM busi_param_transformer WHERE site_id = #{siteId} and main_equipment_id = #{mainEquipmentId})
        ORDER BY t.sort_num ASC, t.name ASC
    </select>

    <select id="findTransformerParma" parameterType="java.lang.String" resultType="com.huatek.busi.entity.BusiParamTransformerVoluntarily">
        SELECT
        <include refid="Base_Column_ListVo"/>
        FROM
        busi_param_transformer_voluntarily t
        WHERE t.id =#{id}
        and t.site_id = #{siteId}
        and t.main_equipment_id = #{mainEquipmentId}
        ORDER BY t.sort_num ASC, t.name ASC
    </select>


    <select id="findTransformerParmaCalculate" parameterType="java.lang.String" resultType="com.huatek.busi.entity.BusiParamTransformerCalculate">
        SELECT
        <include refid="Base_Column_ListVo"/>
        FROM
        busi_param_transformer_calculate t
        WHERE t.id =#{id}
        and t.site_id = #{siteId}
        and t.main_equipment_id = #{mainEquipmentId}
        ORDER BY t.sort_num ASC, t.name ASC
    </select>
    <select id="findVoluntarilyParam" parameterType="java.lang.String" resultType="com.huatek.busi.entity.BusiParamTransformerVoluntarily">
        SELECT
        <include refid="Base_Column_ListVo"/>
        FROM
        busi_param_transformer_voluntarily t
        WHERE  t.site_id = #{siteId}
        and t.main_equipment_id = #{mainEquipmentId}
        AND t.weight_level = '1'
        ORDER BY t.sort_num ASC, t.name ASC
    </select>
    <select id="findSubParamsVo" parameterType="java.lang.String" resultType="com.huatek.busi.entity.BusiParamTransformerVoluntarily">
        SELECT
        <include refid="Base_Column_ListVo"/>
        FROM
        busi_param_transformer t
        WHERE t.site_id = #{siteId} and t.main_equipment_id = #{mainEquipmentId}
        AND t.pname = #{pname}
        GROUP BY name
        ORDER BY t.sort_num ASC, t.name ASC
    </select>
    <select id="findFirstLevelNumber" parameterType="java.lang.String" resultType="com.huatek.busi.vo.BusiParamTransformerVo">
        SELECT
        max(number) as number
        FROM
        busi_param_transformer
        WHERE main_equipment_id = #{mainEquipmentId}
    </select>
</mapper>
