<?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.hdkj.lt.bf.mapper.FaultTransferSchemeMapper">
    

    <select id="countSchemeCheckByPlanId"
            resultType="com.hdkj.lt.bf.entity.dto.FhzgFaultTransferSchemeCheckCountResultDTO">
        select count(1) count, ta.scheme_check schemeCheck  from fhzg_plan_transfer_scheme ta where ta.plan_id = #{planId} group by ta.scheme_check
    </select>

    <update id="updateFhzgFaultTransferSchemeState">
        update fhzg_fault_transfer_scheme ts
        set ts.scheme_state=#{schemeState}
        where ts.id = #{id}
    </update>

    <update id="updateFhzgFaultTransferSchemeStateBatch">
        update fhzg_fault_transfer_scheme ts set ts.scheme_state=#{schemeState}
        where ts.id in
        <foreach collection="idList" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </update>


    <select id="getFhzgFaultTransferSchemeByFaultId"
            resultType="com.hdkj.lt.bf.entity.dto.FhzgFaultTransferSchemeDTO">
        SELECT
        ta.id id,
        ta.fault_id faultId,
        ta.evaluation_score evaluationScore,
        ta.scheme_name schemeName,
        ta.scheme_state schemeState,
        ta.switch_operation_count switchOperationCount,
        ta.load_recovery loadRecovery,
        ta.scheme_check schemeCheck,
        ta.feasible_transfer feasibleTransfer,
        ta.total_transfer totalTransfer,
        ta.loss_cust_hours lossCustHours,
        ta.loss_users lossUsers,
        ta.file_id fileId
        FROM
        fhzg_fault_transfer_scheme ta
        <where>
            ta.fault_id = #{faultId}
            <if test="schemeCheck != null and schemeCheck!=null ">
                and ta.scheme_check= #{schemeCheck}
            </if>
            <if test="schemeType == 1 ">
                and ta.scheme_check = 1
            </if>
            <if test="schemeType == 0 ">
                and ta.scheme_check = 0
            </if>
            <if test="schemeState != null and schemeState!=null ">
                and ta.scheme_state= #{schemeState}
            </if>
        </where>
        order by ta.scheme_state asc,ta.evaluation_score desc
    </select>

    <select id="countSchemeCheckByFaultId"
            resultType="com.hdkj.lt.bf.entity.dto.FhzgFaultTransferSchemeCheckCountResultDTO">
        select count(1) count, ta.scheme_check schemeCheck  from fhzg_fault_transfer_scheme ta where ta.fault_id = #{faultId} group by ta.scheme_check

    </select></mapper>
