<?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="cn.cecep.talroad.mapper.SMainDynamicControlParamMapper">

    <resultMap type="cn.cecep.talroad.domain.SMainDynamicControlParam" id="SMainDynamicControlParamResult">
        <result property="id"    column="id"    />
        <result property="controlTypeCode"    column="control_type_code"    />
        <result property="argumentsCode"    column="arguments_code"    />
        <result property="argumentsName"    column="arguments_name"    />
        <result property="argumentsEnable"    column="arguments_enable"    />
    </resultMap>


    <sql id="selectSMainDynamicControlParamVo">
        select id, control_type_code, arguments_code, arguments_name, arguments_enable from s_main_dynamic_control_param
    </sql>

    <select id="selectSMainDynamicControlParamList" parameterType="cn.cecep.talroad.domain.SMainDynamicControlParam" resultMap="SMainDynamicControlParamResult">
        <include refid="selectSMainDynamicControlParamVo"/>
        <where>
            <if test="controlTypeCode != null  and controlTypeCode != ''"> and control_type_code = #{controlTypeCode}</if>
            <if test="argumentsCode != null  and argumentsCode != ''"> and arguments_code = #{argumentsCode}</if>
            <if test="argumentsName != null  and argumentsName != ''"> and arguments_name like concat('%', #{argumentsName}, '%')</if>
            <if test="argumentsEnable != null  and argumentsEnable != ''"> and arguments_enable = #{argumentsEnable}</if>
        </where>
    </select>
    <select id="selectParamTableData" resultType="java.util.Map">
        select
            t1.arguments_name AS "argumentsName",
            t2.measured_value AS "measuredValue",
            t2.standard_value AS "standardValue"
        from s_main_dynamic_control_param t1
        left join s_main_dynamic_control_factory t2 on t1.mn = t2.mn
                AND t1.control_type_code = t2.control_type_code
                AND t1.arguments_name = t2.arguments_name
        inner join s_main_dynamic_control t3 on t1.mn = t3.mn and t1.control_type_code = t3.control_type_code

        where t3.control_type_code = #{controlTypeCode}
        AND t3.factory_id = #{factoryId}
        AND t3.outlet_id = #{outletId}
        ORDER BY t1.arguments_name, t1.id
    </select>

</mapper>
