<?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.FhzgPlanStrategyDetialMapper">


    <select id="getStrategyDetial"
            resultType="com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanTransferStrategyConfigDetail">
        select id, indicator_name, indicator_code, priority, enable
        from fhzg_plan_transfer_strategy_config_detail
        where strategy_id = #{strategyId}
        order by priority asc
    </select>

    <insert id="batchInsert">
        insert into fhzg_plan_transfer_strategy_config_detail
        (strategy_id,indicator_name,indicator_code,priority,enable)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.strategyId},#{item.indicatorName},#{item.indicatorCode},#{item.priority},#{item.enable})
        </foreach>
    </insert>

    <update id="batchUpdate">
        update fhzg_plan_transfer_strategy_config_detail
        set indicator_name = #{item.indicatorName},
            indicator_code = #{item.indicatorCode},
            priority       = #{item.priority},
            enable         = #{item.enable}
        where id = #{item.id}
          and strategy_id = #{item.strategyId}

    </update>

    <select id="getStrategyDetailByPlanId"
            resultType="com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanTransferStrategyConfigDetail">
        select DISTINCTROW tscd.strategy_id    strategyId,
                           tscd.indicator_code indicatorCode,
                           tscd.indicator_name indicatorName,
                           tscd.enable         enable,
                           tscd.priority       priority
        from fhzg_plan_transfer_scheme ts
                 left join
             fhzg_plan_transfer_scheme_strategy_score sss on ts.id = sss.scheme_id
                 left join fhzg_plan_transfer_strategy_config_detail tscd on tscd.strategy_id = sss.strategy_id
        where ts.plan_id = #{planId}
          and tscd.enable = 0
        order by tscd.priority
--  tscd.enable 是否启用 0:启用，1：未启用
    </select>


    <select id="getStrategyDetailByFaultId"
            resultType="com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanTransferStrategyConfigDetail">
        select DISTINCTROW tscd.strategy_id    strategyId,
                           tscd.indicator_code indicatorCode,
                           tscd.indicator_name indicatorName,
                           tscd.enable         enable,
                           tscd.priority       priority
        from fhzg_fault_transfer_scheme ts
                 left join
             fhzg_fault_transfer_scheme_strategy_score sss on ts.id = sss.scheme_id
                 left join fhzg_plan_transfer_strategy_config_detail tscd on tscd.strategy_id = sss.strategy_id
        where ts.fault_id = #{faultId}
          and tscd.enable = 0
        order by tscd.priority
--  tscd.enable 是否启用 0:启用，1：未启用
    </select>


    <select id="getStrategyDetialByTime"
            resultType="com.hdkj.lt.core.bizms.modle.po.plan.FhzgPlanTransferStrategyConfigDetail">
        select cd.id, cd.indicator_name, cd.priority, cd.enable
        from fhzg_plan_transfer_strategy_config_detail cd
                 left join fhzg_plan_transfer_strategy_config sc on cd.strategy_id = sc.id
        where transfer_strategy = #{transferStrategy}
          and enable = 0
        order by priority asc
    </select>
</mapper>