<?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.njcn.device.pq.mapper.RateOfFlowMapper">

    <select id="getRateOfFlowData" resultType="RateOfFlowVO">
        SELECT
        A.`Id` id,
        A.`Name` name,
        A.`Type` type,
        A.`Flag` flag,
        A.`Combo_Type` comboType,
        A.`Flow` flow,
        B.`Name` updateBy,
        A.`Update_Time` updateTime
        FROM
        cld_flow_meal A,
        sys_user B
        WHERE A.State = 1
        AND A.Update_By = B.Id
<!--        <if test="data != null and data != ''">-->
<!--            AND Id LIKE '%${data}%'-->
<!--            OR Name LIKE '%${data}%'-->
<!--            OR Update_By LIKE '%${data}%'-->
<!--            OR Update_Time LIKE '%${data}%'-->
<!--        </if>-->
    </select>

    <select id="getRateOfFlowFlag" resultType="RateOfFlowVO">
        SELECT
        `Id` id,
        `Name` name,
        `Type` type,
        `Flag` flag,
        `Combo_Type` comboType,
        `Flow` flow,
        `Update_By` updateBy,
        `Update_Time` updateTime
        FROM
        cld_flow_meal
        WHERE Type =0 AND Flag =1
    </select>

    <update id="updateByState">
        UPDATE
        cld_flow_meal
        SET
        State = 0
        WHERE Id = #{id}
    </update>

    <select id="getFlowStrategy" resultType="FlowStrategyVO">
        SELECT
        A.`Id` id,
        A.`Name` name,
        A.`Flag` flag,
        C.`Name` updateBy,
        A.`Update_Time` updateTime,
        B1.`Value` comPerData,
        B2.`Value` warnPerData,
        B3.`Value` alertPerData
        FROM
        cld_flow_strategy A,
        cld_flow_strategy_dic B1,
        cld_flow_strategy_dic B2,
        cld_flow_strategy_dic B3,
        sys_user C
        WHERE A.State = 1
        AND A.Update_By = C.Id
        AND A.Com_Per = B1.Id
        AND A.Warn_Per = B2.Id
        AND A.Alert_Per = B3.Id
    </select>

    <select id="getStrategyFlag" resultType="FlowStrategyVO">
        SELECT
        `Id` id,
        `Name` name,
        `Flag` flag,
        `Update_By` updateBy,
        `Update_Time` updateTime
        FROM
        cld_flow_strategy
        WHERE Flag =1
    </select>

    <update id="updateByStrategy">
        UPDATE
        cld_flow_strategy
        SET
        State = 0
        WHERE Id = #{id}
    </update>

    <select id="getFlowStrategyById" resultType="ShowFlowStrategyVO">
        SELECT
        A.`Id` id,
        A.`Name` name,
        A.`Flag` flag,
        C.`Name` updateBy,
        A.`Update_Time` updateTime,
        A.`Com_Per` com,
        A.`Warn_Per` warn,
        A.`Alert_Per` alert,
        B1.`Value` comPerData,
        B2.`Value` warnPerData,
        B3.`Value` alertPerData
        FROM
        cld_flow_strategy A,
        cld_flow_strategy_dic B1,
        cld_flow_strategy_dic B2,
        cld_flow_strategy_dic B3,
        sys_user C
        WHERE A.Id = #{id}
        AND A.State = 1
        AND A.Update_By = C.Id
        AND A.Com_Per = B1.Id
        AND A.Warn_Per = B2.Id
        AND A.Alert_Per = B3.Id
    </select>

    <select id="getStrategyDicFun" resultType="java.lang.String">
        SELECT
        Fuction_Id
        FROM
        cld_strategydic_fun
        WHERE
        Strategy_Dic_Id = #{id}
    </select>
    <select id="getDictData" resultType="java.lang.String">
        SELECT
        id
        FROM
        sys_dict_data
        WHERE
        Id = #{id}
    </select>

    <delete id="delStrategyDicFun">
        DELETE FROM cld_strategydic_fun WHERE Strategy_Dic_Id = #{id}
    </delete>

</mapper>
