<?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.ruoyi.powerdistribution.mapper.PdmStopTargeMapper">

    <resultMap type="PdmStopTarge" id="PdmStopTargeResult">
        <result property="id"    column="id"    />
        <result property="reportYear"    column="report_year"    />
        <result property="companyNo"    column="company_no"    />
        <result property="companyName"    column="company_name"    />
        <result property="stopTimeAvg"    column="stop_time_avg"    />
        <result property="userTotal"    column="user_total"    />
        <result property="stopTimeTotal"    column="stop_time_total"    />
        <result property="threeYearRatio"    column="three_year_ratio"    />
        <result property="planStopTimeTotal"    column="plan_stop_time_total"    />
        <result property="planStopTimeAvg"    column="plan_stop_time_avg"    />
        <result property="errorStopTimeTotal"    column="error_stop_time_total"    />
        <result property="errorStopTimeAvg"    column="error_stop_time_avg"    />
        <result property="stopTimeMonth01"    column="stop_time_month_01"    />
        <result property="stopTimeMonth02"    column="stop_time_month_02"    />
        <result property="stopTimeMonth03"    column="stop_time_month_03"    />
        <result property="stopTimeMonth04"    column="stop_time_month_04"    />
        <result property="stopTimeMonth05"    column="stop_time_month_05"    />
        <result property="stopTimeMonth06"    column="stop_time_month_06"    />
        <result property="stopTimeMonth07"    column="stop_time_month_07"    />
        <result property="stopTimeMonth08"    column="stop_time_month_08"    />
        <result property="stopTimeMonth09"    column="stop_time_month_09"    />
        <result property="stopTimeMonth10"    column="stop_time_month_10"    />
        <result property="stopTimeMonth11"    column="stop_time_month_11"    />
        <result property="stopTimeMonth12"    column="stop_time_month_12"    />
        <result property="planStopTimeMonth01"    column="plan_stop_time_month_01"    />
        <result property="planStopTimeMonth02"    column="plan_stop_time_month_02"    />
        <result property="planStopTimeMonth03"    column="plan_stop_time_month_03"    />
        <result property="planStopTimeMonth04"    column="plan_stop_time_month_04"    />
        <result property="planStopTimeMonth05"    column="plan_stop_time_month_05"    />
        <result property="planStopTimeMonth06"    column="plan_stop_time_month_06"    />
        <result property="planStopTimeMonth07"    column="plan_stop_time_month_07"    />
        <result property="planStopTimeMonth08"    column="plan_stop_time_month_08"    />
        <result property="planStopTimeMonth09"    column="plan_stop_time_month_09"    />
        <result property="planStopTimeMonth10"    column="plan_stop_time_month_10"    />
        <result property="planStopTimeMonth11"    column="plan_stop_time_month_11"    />
        <result property="planStopTimeMonth12"    column="plan_stop_time_month_12"    />
        <result property="errorStopTimeMonth01"    column="error_stop_time_month_01"    />
        <result property="errorStopTimeMonth02"    column="error_stop_time_month_02"    />
        <result property="errorStopTimeMonth03"    column="error_stop_time_month_03"    />
        <result property="errorStopTimeMonth04"    column="error_stop_time_month_04"    />
        <result property="errorStopTimeMonth05"    column="error_stop_time_month_05"    />
        <result property="errorStopTimeMonth06"    column="error_stop_time_month_06"    />
        <result property="errorStopTimeMonth07"    column="error_stop_time_month_07"    />
        <result property="errorStopTimeMonth08"    column="error_stop_time_month_08"    />
        <result property="errorStopTimeMonth09"    column="error_stop_time_month_09"    />
        <result property="errorStopTimeMonth10"    column="error_stop_time_month_10"    />
        <result property="errorStopTimeMonth11"    column="error_stop_time_month_11"    />
        <result property="errorStopTimeMonth12"    column="error_stop_time_month_12"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectPdmStopTargeVo">
        select id, report_year, company_no, company_name, stop_time_avg, user_total, stop_time_total, three_year_ratio, plan_stop_time_total, plan_stop_time_avg, error_stop_time_total, error_stop_time_avg, stop_time_month_01, stop_time_month_02, stop_time_month_03, stop_time_month_04, stop_time_month_05, stop_time_month_06, stop_time_month_07, stop_time_month_08, stop_time_month_09, stop_time_month_10, stop_time_month_11, stop_time_month_12, plan_stop_time_month_01, plan_stop_time_month_02, plan_stop_time_month_03, plan_stop_time_month_04, plan_stop_time_month_05, plan_stop_time_month_06, plan_stop_time_month_07, plan_stop_time_month_08, plan_stop_time_month_09, plan_stop_time_month_10, plan_stop_time_month_11, plan_stop_time_month_12, error_stop_time_month_01, error_stop_time_month_02, error_stop_time_month_03, error_stop_time_month_04, error_stop_time_month_05, error_stop_time_month_06, error_stop_time_month_07, error_stop_time_month_08, error_stop_time_month_09, error_stop_time_month_10, error_stop_time_month_11, error_stop_time_month_12, create_by, create_time, update_by, update_time from pdm_stop_targe
    </sql>

    <select id="selectPdmStopTargeList" parameterType="PdmStopTarge" resultMap="PdmStopTargeResult">
        <include refid="selectPdmStopTargeVo"/>
        <where>
            <if test="reportYear != null  and reportYear != ''"> and report_year = #{reportYear}</if>
            <if test="companyNo != null  and companyNo != ''"> and company_no = #{companyNo}</if>
            <if test="companyName != null  and companyName != ''"> and company_name like concat('%', #{companyName}, '%')</if>
            <if test="stopTimeAvg != null "> and stop_time_avg = #{stopTimeAvg}</if>
            <if test="userTotal != null "> and user_total = #{userTotal}</if>
            <if test="stopTimeTotal != null "> and stop_time_total = #{stopTimeTotal}</if>
            <if test="threeYearRatio != null  and threeYearRatio != ''"> and three_year_ratio = #{threeYearRatio}</if>
            <if test="planStopTimeTotal != null "> and plan_stop_time_total = #{planStopTimeTotal}</if>
            <if test="planStopTimeAvg != null "> and plan_stop_time_avg = #{planStopTimeAvg}</if>
            <if test="errorStopTimeTotal != null "> and error_stop_time_total = #{errorStopTimeTotal}</if>
            <if test="errorStopTimeAvg != null "> and error_stop_time_avg = #{errorStopTimeAvg}</if>
            <if test="stopTimeMonth01 != null "> and stop_time_month_01 = #{stopTimeMonth01}</if>
            <if test="stopTimeMonth02 != null "> and stop_time_month_02 = #{stopTimeMonth02}</if>
            <if test="stopTimeMonth03 != null "> and stop_time_month_03 = #{stopTimeMonth03}</if>
            <if test="stopTimeMonth04 != null "> and stop_time_month_04 = #{stopTimeMonth04}</if>
            <if test="stopTimeMonth05 != null "> and stop_time_month_05 = #{stopTimeMonth05}</if>
            <if test="stopTimeMonth06 != null "> and stop_time_month_06 = #{stopTimeMonth06}</if>
            <if test="stopTimeMonth07 != null "> and stop_time_month_07 = #{stopTimeMonth07}</if>
            <if test="stopTimeMonth08 != null "> and stop_time_month_08 = #{stopTimeMonth08}</if>
            <if test="stopTimeMonth09 != null "> and stop_time_month_09 = #{stopTimeMonth09}</if>
            <if test="stopTimeMonth10 != null "> and stop_time_month_10 = #{stopTimeMonth10}</if>
            <if test="stopTimeMonth11 != null "> and stop_time_month_11 = #{stopTimeMonth11}</if>
            <if test="stopTimeMonth12 != null "> and stop_time_month_12 = #{stopTimeMonth12}</if>
            <if test="planStopTimeMonth01 != null "> and plan_stop_time_month_01 = #{planStopTimeMonth01}</if>
            <if test="planStopTimeMonth02 != null "> and plan_stop_time_month_02 = #{planStopTimeMonth02}</if>
            <if test="planStopTimeMonth03 != null "> and plan_stop_time_month_03 = #{planStopTimeMonth03}</if>
            <if test="planStopTimeMonth04 != null "> and plan_stop_time_month_04 = #{planStopTimeMonth04}</if>
            <if test="planStopTimeMonth05 != null "> and plan_stop_time_month_05 = #{planStopTimeMonth05}</if>
            <if test="planStopTimeMonth06 != null "> and plan_stop_time_month_06 = #{planStopTimeMonth06}</if>
            <if test="planStopTimeMonth07 != null "> and plan_stop_time_month_07 = #{planStopTimeMonth07}</if>
            <if test="planStopTimeMonth08 != null "> and plan_stop_time_month_08 = #{planStopTimeMonth08}</if>
            <if test="planStopTimeMonth09 != null "> and plan_stop_time_month_09 = #{planStopTimeMonth09}</if>
            <if test="planStopTimeMonth10 != null "> and plan_stop_time_month_10 = #{planStopTimeMonth10}</if>
            <if test="planStopTimeMonth11 != null "> and plan_stop_time_month_11 = #{planStopTimeMonth11}</if>
            <if test="planStopTimeMonth12 != null "> and plan_stop_time_month_12 = #{planStopTimeMonth12}</if>
            <if test="errorStopTimeMonth01 != null "> and error_stop_time_month_01 = #{errorStopTimeMonth01}</if>
            <if test="errorStopTimeMonth02 != null "> and error_stop_time_month_02 = #{errorStopTimeMonth02}</if>
            <if test="errorStopTimeMonth03 != null "> and error_stop_time_month_03 = #{errorStopTimeMonth03}</if>
            <if test="errorStopTimeMonth04 != null "> and error_stop_time_month_04 = #{errorStopTimeMonth04}</if>
            <if test="errorStopTimeMonth05 != null "> and error_stop_time_month_05 = #{errorStopTimeMonth05}</if>
            <if test="errorStopTimeMonth06 != null "> and error_stop_time_month_06 = #{errorStopTimeMonth06}</if>
            <if test="errorStopTimeMonth07 != null "> and error_stop_time_month_07 = #{errorStopTimeMonth07}</if>
            <if test="errorStopTimeMonth08 != null "> and error_stop_time_month_08 = #{errorStopTimeMonth08}</if>
            <if test="errorStopTimeMonth09 != null "> and error_stop_time_month_09 = #{errorStopTimeMonth09}</if>
            <if test="errorStopTimeMonth10 != null "> and error_stop_time_month_10 = #{errorStopTimeMonth10}</if>
            <if test="errorStopTimeMonth11 != null "> and error_stop_time_month_11 = #{errorStopTimeMonth11}</if>
            <if test="errorStopTimeMonth12 != null "> and error_stop_time_month_12 = #{errorStopTimeMonth12}</if>
        </where>
    </select>

    <select id="selectPdmStopTargeById" parameterType="Long" resultMap="PdmStopTargeResult">
        <include refid="selectPdmStopTargeVo"/>
        where id = #{id}
    </select>

    <insert id="insertPdmStopTarge" parameterType="PdmStopTarge" useGeneratedKeys="true" keyProperty="id">
        insert into pdm_stop_targe
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="reportYear != null">report_year,</if>
            <if test="companyNo != null">company_no,</if>
            <if test="companyName != null">company_name,</if>
            <if test="stopTimeAvg != null">stop_time_avg,</if>
            <if test="userTotal != null">user_total,</if>
            <if test="stopTimeTotal != null">stop_time_total,</if>
            <if test="threeYearRatio != null">three_year_ratio,</if>
            <if test="planStopTimeTotal != null">plan_stop_time_total,</if>
            <if test="planStopTimeAvg != null">plan_stop_time_avg,</if>
            <if test="errorStopTimeTotal != null">error_stop_time_total,</if>
            <if test="errorStopTimeAvg != null">error_stop_time_avg,</if>
            <if test="stopTimeMonth01 != null">stop_time_month_01,</if>
            <if test="stopTimeMonth02 != null">stop_time_month_02,</if>
            <if test="stopTimeMonth03 != null">stop_time_month_03,</if>
            <if test="stopTimeMonth04 != null">stop_time_month_04,</if>
            <if test="stopTimeMonth05 != null">stop_time_month_05,</if>
            <if test="stopTimeMonth06 != null">stop_time_month_06,</if>
            <if test="stopTimeMonth07 != null">stop_time_month_07,</if>
            <if test="stopTimeMonth08 != null">stop_time_month_08,</if>
            <if test="stopTimeMonth09 != null">stop_time_month_09,</if>
            <if test="stopTimeMonth10 != null">stop_time_month_10,</if>
            <if test="stopTimeMonth11 != null">stop_time_month_11,</if>
            <if test="stopTimeMonth12 != null">stop_time_month_12,</if>
            <if test="planStopTimeMonth01 != null">plan_stop_time_month_01,</if>
            <if test="planStopTimeMonth02 != null">plan_stop_time_month_02,</if>
            <if test="planStopTimeMonth03 != null">plan_stop_time_month_03,</if>
            <if test="planStopTimeMonth04 != null">plan_stop_time_month_04,</if>
            <if test="planStopTimeMonth05 != null">plan_stop_time_month_05,</if>
            <if test="planStopTimeMonth06 != null">plan_stop_time_month_06,</if>
            <if test="planStopTimeMonth07 != null">plan_stop_time_month_07,</if>
            <if test="planStopTimeMonth08 != null">plan_stop_time_month_08,</if>
            <if test="planStopTimeMonth09 != null">plan_stop_time_month_09,</if>
            <if test="planStopTimeMonth10 != null">plan_stop_time_month_10,</if>
            <if test="planStopTimeMonth11 != null">plan_stop_time_month_11,</if>
            <if test="planStopTimeMonth12 != null">plan_stop_time_month_12,</if>
            <if test="errorStopTimeMonth01 != null">error_stop_time_month_01,</if>
            <if test="errorStopTimeMonth02 != null">error_stop_time_month_02,</if>
            <if test="errorStopTimeMonth03 != null">error_stop_time_month_03,</if>
            <if test="errorStopTimeMonth04 != null">error_stop_time_month_04,</if>
            <if test="errorStopTimeMonth05 != null">error_stop_time_month_05,</if>
            <if test="errorStopTimeMonth06 != null">error_stop_time_month_06,</if>
            <if test="errorStopTimeMonth07 != null">error_stop_time_month_07,</if>
            <if test="errorStopTimeMonth08 != null">error_stop_time_month_08,</if>
            <if test="errorStopTimeMonth09 != null">error_stop_time_month_09,</if>
            <if test="errorStopTimeMonth10 != null">error_stop_time_month_10,</if>
            <if test="errorStopTimeMonth11 != null">error_stop_time_month_11,</if>
            <if test="errorStopTimeMonth12 != null">error_stop_time_month_12,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="reportYear != null">#{reportYear},</if>
            <if test="companyNo != null">#{companyNo},</if>
            <if test="companyName != null">#{companyName},</if>
            <if test="stopTimeAvg != null">#{stopTimeAvg},</if>
            <if test="userTotal != null">#{userTotal},</if>
            <if test="stopTimeTotal != null">#{stopTimeTotal},</if>
            <if test="threeYearRatio != null">#{threeYearRatio},</if>
            <if test="planStopTimeTotal != null">#{planStopTimeTotal},</if>
            <if test="planStopTimeAvg != null">#{planStopTimeAvg},</if>
            <if test="errorStopTimeTotal != null">#{errorStopTimeTotal},</if>
            <if test="errorStopTimeAvg != null">#{errorStopTimeAvg},</if>
            <if test="stopTimeMonth01 != null">#{stopTimeMonth01},</if>
            <if test="stopTimeMonth02 != null">#{stopTimeMonth02},</if>
            <if test="stopTimeMonth03 != null">#{stopTimeMonth03},</if>
            <if test="stopTimeMonth04 != null">#{stopTimeMonth04},</if>
            <if test="stopTimeMonth05 != null">#{stopTimeMonth05},</if>
            <if test="stopTimeMonth06 != null">#{stopTimeMonth06},</if>
            <if test="stopTimeMonth07 != null">#{stopTimeMonth07},</if>
            <if test="stopTimeMonth08 != null">#{stopTimeMonth08},</if>
            <if test="stopTimeMonth09 != null">#{stopTimeMonth09},</if>
            <if test="stopTimeMonth10 != null">#{stopTimeMonth10},</if>
            <if test="stopTimeMonth11 != null">#{stopTimeMonth11},</if>
            <if test="stopTimeMonth12 != null">#{stopTimeMonth12},</if>
            <if test="planStopTimeMonth01 != null">#{planStopTimeMonth01},</if>
            <if test="planStopTimeMonth02 != null">#{planStopTimeMonth02},</if>
            <if test="planStopTimeMonth03 != null">#{planStopTimeMonth03},</if>
            <if test="planStopTimeMonth04 != null">#{planStopTimeMonth04},</if>
            <if test="planStopTimeMonth05 != null">#{planStopTimeMonth05},</if>
            <if test="planStopTimeMonth06 != null">#{planStopTimeMonth06},</if>
            <if test="planStopTimeMonth07 != null">#{planStopTimeMonth07},</if>
            <if test="planStopTimeMonth08 != null">#{planStopTimeMonth08},</if>
            <if test="planStopTimeMonth09 != null">#{planStopTimeMonth09},</if>
            <if test="planStopTimeMonth10 != null">#{planStopTimeMonth10},</if>
            <if test="planStopTimeMonth11 != null">#{planStopTimeMonth11},</if>
            <if test="planStopTimeMonth12 != null">#{planStopTimeMonth12},</if>
            <if test="errorStopTimeMonth01 != null">#{errorStopTimeMonth01},</if>
            <if test="errorStopTimeMonth02 != null">#{errorStopTimeMonth02},</if>
            <if test="errorStopTimeMonth03 != null">#{errorStopTimeMonth03},</if>
            <if test="errorStopTimeMonth04 != null">#{errorStopTimeMonth04},</if>
            <if test="errorStopTimeMonth05 != null">#{errorStopTimeMonth05},</if>
            <if test="errorStopTimeMonth06 != null">#{errorStopTimeMonth06},</if>
            <if test="errorStopTimeMonth07 != null">#{errorStopTimeMonth07},</if>
            <if test="errorStopTimeMonth08 != null">#{errorStopTimeMonth08},</if>
            <if test="errorStopTimeMonth09 != null">#{errorStopTimeMonth09},</if>
            <if test="errorStopTimeMonth10 != null">#{errorStopTimeMonth10},</if>
            <if test="errorStopTimeMonth11 != null">#{errorStopTimeMonth11},</if>
            <if test="errorStopTimeMonth12 != null">#{errorStopTimeMonth12},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updatePdmStopTarge" parameterType="PdmStopTarge">
        update pdm_stop_targe
        <trim prefix="SET" suffixOverrides=",">
            <if test="reportYear != null">report_year = #{reportYear},</if>
            <if test="companyNo != null">company_no = #{companyNo},</if>
            <if test="companyName != null">company_name = #{companyName},</if>
            <if test="stopTimeAvg != null">stop_time_avg = #{stopTimeAvg},</if>
            <if test="userTotal != null">user_total = #{userTotal},</if>
            <if test="stopTimeTotal != null">stop_time_total = #{stopTimeTotal},</if>
            <if test="threeYearRatio != null">three_year_ratio = #{threeYearRatio},</if>
            <if test="planStopTimeTotal != null">plan_stop_time_total = #{planStopTimeTotal},</if>
            <if test="planStopTimeAvg != null">plan_stop_time_avg = #{planStopTimeAvg},</if>
            <if test="errorStopTimeTotal != null">error_stop_time_total = #{errorStopTimeTotal},</if>
            <if test="errorStopTimeAvg != null">error_stop_time_avg = #{errorStopTimeAvg},</if>
            <if test="stopTimeMonth01 != null">stop_time_month_01 = #{stopTimeMonth01},</if>
            <if test="stopTimeMonth02 != null">stop_time_month_02 = #{stopTimeMonth02},</if>
            <if test="stopTimeMonth03 != null">stop_time_month_03 = #{stopTimeMonth03},</if>
            <if test="stopTimeMonth04 != null">stop_time_month_04 = #{stopTimeMonth04},</if>
            <if test="stopTimeMonth05 != null">stop_time_month_05 = #{stopTimeMonth05},</if>
            <if test="stopTimeMonth06 != null">stop_time_month_06 = #{stopTimeMonth06},</if>
            <if test="stopTimeMonth07 != null">stop_time_month_07 = #{stopTimeMonth07},</if>
            <if test="stopTimeMonth08 != null">stop_time_month_08 = #{stopTimeMonth08},</if>
            <if test="stopTimeMonth09 != null">stop_time_month_09 = #{stopTimeMonth09},</if>
            <if test="stopTimeMonth10 != null">stop_time_month_10 = #{stopTimeMonth10},</if>
            <if test="stopTimeMonth11 != null">stop_time_month_11 = #{stopTimeMonth11},</if>
            <if test="stopTimeMonth12 != null">stop_time_month_12 = #{stopTimeMonth12},</if>
            <if test="planStopTimeMonth01 != null">plan_stop_time_month_01 = #{planStopTimeMonth01},</if>
            <if test="planStopTimeMonth02 != null">plan_stop_time_month_02 = #{planStopTimeMonth02},</if>
            <if test="planStopTimeMonth03 != null">plan_stop_time_month_03 = #{planStopTimeMonth03},</if>
            <if test="planStopTimeMonth04 != null">plan_stop_time_month_04 = #{planStopTimeMonth04},</if>
            <if test="planStopTimeMonth05 != null">plan_stop_time_month_05 = #{planStopTimeMonth05},</if>
            <if test="planStopTimeMonth06 != null">plan_stop_time_month_06 = #{planStopTimeMonth06},</if>
            <if test="planStopTimeMonth07 != null">plan_stop_time_month_07 = #{planStopTimeMonth07},</if>
            <if test="planStopTimeMonth08 != null">plan_stop_time_month_08 = #{planStopTimeMonth08},</if>
            <if test="planStopTimeMonth09 != null">plan_stop_time_month_09 = #{planStopTimeMonth09},</if>
            <if test="planStopTimeMonth10 != null">plan_stop_time_month_10 = #{planStopTimeMonth10},</if>
            <if test="planStopTimeMonth11 != null">plan_stop_time_month_11 = #{planStopTimeMonth11},</if>
            <if test="planStopTimeMonth12 != null">plan_stop_time_month_12 = #{planStopTimeMonth12},</if>
            <if test="errorStopTimeMonth01 != null">error_stop_time_month_01 = #{errorStopTimeMonth01},</if>
            <if test="errorStopTimeMonth02 != null">error_stop_time_month_02 = #{errorStopTimeMonth02},</if>
            <if test="errorStopTimeMonth03 != null">error_stop_time_month_03 = #{errorStopTimeMonth03},</if>
            <if test="errorStopTimeMonth04 != null">error_stop_time_month_04 = #{errorStopTimeMonth04},</if>
            <if test="errorStopTimeMonth05 != null">error_stop_time_month_05 = #{errorStopTimeMonth05},</if>
            <if test="errorStopTimeMonth06 != null">error_stop_time_month_06 = #{errorStopTimeMonth06},</if>
            <if test="errorStopTimeMonth07 != null">error_stop_time_month_07 = #{errorStopTimeMonth07},</if>
            <if test="errorStopTimeMonth08 != null">error_stop_time_month_08 = #{errorStopTimeMonth08},</if>
            <if test="errorStopTimeMonth09 != null">error_stop_time_month_09 = #{errorStopTimeMonth09},</if>
            <if test="errorStopTimeMonth10 != null">error_stop_time_month_10 = #{errorStopTimeMonth10},</if>
            <if test="errorStopTimeMonth11 != null">error_stop_time_month_11 = #{errorStopTimeMonth11},</if>
            <if test="errorStopTimeMonth12 != null">error_stop_time_month_12 = #{errorStopTimeMonth12},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePdmStopTargeById" parameterType="Long">
        delete from pdm_stop_targe where id = #{id}
    </delete>

    <delete id="deletePdmStopTargeByIds" parameterType="String">
        delete from pdm_stop_targe where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectTargetAndActual" parameterType="java.lang.String" resultType="com.ruoyi.powerdistribution.domain.vo.StopTargetAndRecords">
        select t1.*,
               ifnull(t2.stop_total_actual,0) stop_total_actual,
               CONCAT(round(ifnull(t2.stop_total_actual,0)/t1.stop_time_total*100,2),'%')  stop_total_ratio,
               ifnull(t2.plan_stop_total_actual,0) plan_stop_total_actual,
               CONCAT(round(ifnull(t2.plan_stop_total_actual,0)/t1.plan_stop_time_total*100,2),'%') plan_stop_total_ratio,
               ifnull(t2.error_stop_total_actual,0) error_stop_total_actual,
               CONCAT(round(ifnull(t2.error_stop_total_actual,0)/t1.error_stop_time_total*100,2),'%') error_stop_total_ratio,
               ifnull(stop_month_01_actual,0) stop_month_01_actual,
               ifnull(stop_month_02_actual,0) stop_month_02_actual,
               ifnull(stop_month_03_actual,0) stop_month_03_actual,
               ifnull(stop_month_04_actual,0) stop_month_04_actual,
               ifnull(stop_month_05_actual,0) stop_month_05_actual,
               ifnull(stop_month_06_actual,0) stop_month_06_actual,
               ifnull(stop_month_07_actual,0) stop_month_07_actual,
               ifnull(stop_month_08_actual,0) stop_month_08_actual,
               ifnull(stop_month_09_actual,0) stop_month_09_actual,
               ifnull(stop_month_10_actual,0) stop_month_10_actual,
               ifnull(stop_month_11_actual,0) stop_month_11_actual,
               ifnull(stop_month_12_actual,0) stop_month_12_actual,
               CONCAT(round(ifnull(t2.stop_month_01_actual,0)/t1.stop_time_month_01*100,2),'%')  stop_month_01_ratio,
               CONCAT(round(ifnull(t2.stop_month_02_actual,0)/t1.stop_time_month_02*100,2),'%')  stop_month_02_ratio,
               CONCAT(round(ifnull(t2.stop_month_03_actual,0)/t1.stop_time_month_03*100,2),'%')  stop_month_03_ratio,
               CONCAT(round(ifnull(t2.stop_month_04_actual,0)/t1.stop_time_month_04*100,2),'%')  stop_month_04_ratio,
               CONCAT(round(ifnull(t2.stop_month_05_actual,0)/t1.stop_time_month_05*100,2),'%')  stop_month_05_ratio,
               CONCAT(round(ifnull(t2.stop_month_06_actual,0)/t1.stop_time_month_06*100,2),'%')  stop_month_06_ratio,
               CONCAT(round(ifnull(t2.stop_month_07_actual,0)/t1.stop_time_month_07*100,2),'%')  stop_month_07_ratio,
               CONCAT(round(ifnull(t2.stop_month_08_actual,0)/t1.stop_time_month_08*100,2),'%')  stop_month_08_ratio,
               CONCAT(round(ifnull(t2.stop_month_09_actual,0)/t1.stop_time_month_09*100,2),'%')  stop_month_09_ratio,
               CONCAT(round(ifnull(t2.stop_month_10_actual,0)/t1.stop_time_month_10*100,2),'%')  stop_month_10_ratio,
               CONCAT(round(ifnull(t2.stop_month_11_actual,0)/t1.stop_time_month_11*100,2),'%')  stop_month_11_ratio,
               CONCAT(round(ifnull(t2.stop_month_12_actual,0)/t1.stop_time_month_12*100,2),'%')  stop_month_12_ratio,

               ifnull(plan_stop_month_01_actual,0) plan_stop_month_01_actual,
               ifnull(plan_stop_month_02_actual,0) plan_stop_month_02_actual,
               ifnull(plan_stop_month_03_actual,0) plan_stop_month_03_actual,
               ifnull(plan_stop_month_04_actual,0) plan_stop_month_04_actual,
               ifnull(plan_stop_month_05_actual,0) plan_stop_month_05_actual,
               ifnull(plan_stop_month_06_actual,0) plan_stop_month_06_actual,
               ifnull(plan_stop_month_07_actual,0) plan_stop_month_07_actual,
               ifnull(plan_stop_month_08_actual,0) plan_stop_month_08_actual,
               ifnull(plan_stop_month_09_actual,0) plan_stop_month_09_actual,
               ifnull(plan_stop_month_10_actual,0) plan_stop_month_10_actual,
               ifnull(plan_stop_month_11_actual,0) plan_stop_month_11_actual,
               ifnull(plan_stop_month_12_actual,0) plan_stop_month_12_actual,
               CONCAT(round(ifnull(t2.plan_stop_month_01_actual,0)/t1.plan_stop_time_month_01*100,2),'%')  plan_stop_month_01_ratio,
               CONCAT(round(ifnull(t2.plan_stop_month_02_actual,0)/t1.plan_stop_time_month_02*100,2),'%')  plan_stop_month_02_ratio,
               CONCAT(round(ifnull(t2.plan_stop_month_03_actual,0)/t1.plan_stop_time_month_03*100,2),'%')  plan_stop_month_03_ratio,
               CONCAT(round(ifnull(t2.plan_stop_month_04_actual,0)/t1.plan_stop_time_month_04*100,2),'%')  plan_stop_month_04_ratio,
               CONCAT(round(ifnull(t2.plan_stop_month_05_actual,0)/t1.plan_stop_time_month_05*100,2),'%')  plan_stop_month_05_ratio,
               CONCAT(round(ifnull(t2.plan_stop_month_06_actual,0)/t1.plan_stop_time_month_06*100,2),'%')  plan_stop_month_06_ratio,
               CONCAT(round(ifnull(t2.plan_stop_month_07_actual,0)/t1.plan_stop_time_month_07*100,2),'%')  plan_stop_month_07_ratio,
               CONCAT(round(ifnull(t2.plan_stop_month_08_actual,0)/t1.plan_stop_time_month_08*100,2),'%')  plan_stop_month_08_ratio,
               CONCAT(round(ifnull(t2.plan_stop_month_09_actual,0)/t1.plan_stop_time_month_09*100,2),'%')  plan_stop_month_09_ratio,
               CONCAT(round(ifnull(t2.plan_stop_month_10_actual,0)/t1.plan_stop_time_month_10*100,2),'%')  plan_stop_month_10_ratio,
               CONCAT(round(ifnull(t2.plan_stop_month_11_actual,0)/t1.plan_stop_time_month_11*100,2),'%')  plan_stop_month_11_ratio,
               CONCAT(round(ifnull(t2.plan_stop_month_12_actual,0)/t1.plan_stop_time_month_12*100,2),'%')  plan_stop_month_12_ratio,

               ifnull(error_stop_month_01_actual,0) error_stop_month_01_actual,
               ifnull(error_stop_month_02_actual,0) error_stop_month_02_actual,
               ifnull(error_stop_month_03_actual,0) error_stop_month_03_actual,
               ifnull(error_stop_month_04_actual,0) error_stop_month_04_actual,
               ifnull(error_stop_month_05_actual,0) error_stop_month_05_actual,
               ifnull(error_stop_month_06_actual,0) error_stop_month_06_actual,
               ifnull(error_stop_month_07_actual,0) error_stop_month_07_actual,
               ifnull(error_stop_month_08_actual,0) error_stop_month_08_actual,
               ifnull(error_stop_month_09_actual,0) error_stop_month_09_actual,
               ifnull(error_stop_month_10_actual,0) error_stop_month_10_actual,
               ifnull(error_stop_month_11_actual,0) error_stop_month_11_actual,
               ifnull(error_stop_month_12_actual,0) error_stop_month_12_actual,
               CONCAT(round(ifnull(t2.error_stop_month_01_actual,0)/t1.error_stop_time_month_01*100,2),'%')  error_stop_month_01_ratio,
               CONCAT(round(ifnull(t2.error_stop_month_02_actual,0)/t1.error_stop_time_month_02*100,2),'%')  error_stop_month_02_ratio,
               CONCAT(round(ifnull(t2.error_stop_month_03_actual,0)/t1.error_stop_time_month_03*100,2),'%')  error_stop_month_03_ratio,
               CONCAT(round(ifnull(t2.error_stop_month_04_actual,0)/t1.error_stop_time_month_04*100,2),'%')  error_stop_month_04_ratio,
               CONCAT(round(ifnull(t2.error_stop_month_05_actual,0)/t1.error_stop_time_month_05*100,2),'%')  error_stop_month_05_ratio,
               CONCAT(round(ifnull(t2.error_stop_month_06_actual,0)/t1.error_stop_time_month_06*100,2),'%')  error_stop_month_06_ratio,
               CONCAT(round(ifnull(t2.error_stop_month_07_actual,0)/t1.error_stop_time_month_07*100,2),'%')  error_stop_month_07_ratio,
               CONCAT(round(ifnull(t2.error_stop_month_08_actual,0)/t1.error_stop_time_month_08*100,2),'%')  error_stop_month_08_ratio,
               CONCAT(round(ifnull(t2.error_stop_month_09_actual,0)/t1.error_stop_time_month_09*100,2),'%')  error_stop_month_09_ratio,
               CONCAT(round(ifnull(t2.error_stop_month_10_actual,0)/t1.error_stop_time_month_10*100,2),'%')  error_stop_month_10_ratio,
               CONCAT(round(ifnull(t2.error_stop_month_11_actual,0)/t1.error_stop_time_month_11*100,2),'%')  error_stop_month_11_ratio,
               CONCAT(round(ifnull(t2.error_stop_month_12_actual,0)/t1.error_stop_time_month_12*100,2),'%')  error_stop_month_12_ratio


        from pdm_stop_targe t1
        LEFT JOIN
        (
        select substr(duty_dept_no,2,12) org_no ,
        SUM(poweroff_duration_tm) stop_total_actual,
        SUM(IF(poweroff_nature_cd in('2111','2112','2121','2122','2141','2211','2212','2221','2231','2241'),poweroff_duration_tm,0)) as plan_stop_total_actual,
        SUM(IF(poweroff_nature_cd in('1101','1202'),poweroff_duration_tm,0)) as error_stop_total_actual,
        SUM(IF(SUBSTRING(data_dt,5,2)='01',poweroff_duration_tm,0)) as stop_month_01_actual,
        SUM(IF(SUBSTRING(data_dt,5,2)='02',poweroff_duration_tm,0)) as stop_month_02_actual,
        SUM(IF(SUBSTRING(data_dt,5,2)='03',poweroff_duration_tm,0)) as stop_month_03_actual,
        SUM(IF(SUBSTRING(data_dt,5,2)='04',poweroff_duration_tm,0)) as stop_month_04_actual,
        SUM(IF(SUBSTRING(data_dt,5,2)='05',poweroff_duration_tm,0)) as stop_month_05_actual,
        SUM(IF(SUBSTRING(data_dt,5,2)='06',poweroff_duration_tm,0)) as stop_month_06_actual,
        SUM(IF(SUBSTRING(data_dt,5,2)='07',poweroff_duration_tm,0)) as stop_month_07_actual,
        SUM(IF(SUBSTRING(data_dt,5,2)='08',poweroff_duration_tm,0)) as stop_month_08_actual,
        SUM(IF(SUBSTRING(data_dt,5,2)='09',poweroff_duration_tm,0)) as stop_month_09_actual,
        SUM(IF(SUBSTRING(data_dt,5,2)='10',poweroff_duration_tm,0)) as stop_month_10_actual,
        SUM(IF(SUBSTRING(data_dt,5,2)='11',poweroff_duration_tm,0)) as stop_month_11_actual,
        SUM(IF(SUBSTRING(data_dt,5,2)='12',poweroff_duration_tm,0)) as stop_month_12_actual,

        SUM(IF((poweroff_nature_cd in('2111','2112','2121','2122','2141','2211','2212','2221','2231','2241') and SUBSTRING(data_dt,5,2)='01'),poweroff_duration_tm,0)) as plan_stop_month_01_actual,
        SUM(IF((poweroff_nature_cd in('2111','2112','2121','2122','2141','2211','2212','2221','2231','2241') and SUBSTRING(data_dt,5,2)='02'),poweroff_duration_tm,0)) as plan_stop_month_02_actual,
        SUM(IF((poweroff_nature_cd in('2111','2112','2121','2122','2141','2211','2212','2221','2231','2241') and SUBSTRING(data_dt,5,2)='03'),poweroff_duration_tm,0)) as plan_stop_month_03_actual,
        SUM(IF((poweroff_nature_cd in('2111','2112','2121','2122','2141','2211','2212','2221','2231','2241') and SUBSTRING(data_dt,5,2)='04'),poweroff_duration_tm,0)) as plan_stop_month_04_actual,
        SUM(IF((poweroff_nature_cd in('2111','2112','2121','2122','2141','2211','2212','2221','2231','2241') and SUBSTRING(data_dt,5,2)='05'),poweroff_duration_tm,0)) as plan_stop_month_05_actual,
        SUM(IF((poweroff_nature_cd in('2111','2112','2121','2122','2141','2211','2212','2221','2231','2241') and SUBSTRING(data_dt,5,2)='06'),poweroff_duration_tm,0)) as plan_stop_month_06_actual,
        SUM(IF((poweroff_nature_cd in('2111','2112','2121','2122','2141','2211','2212','2221','2231','2241') and SUBSTRING(data_dt,5,2)='07'),poweroff_duration_tm,0)) as plan_stop_month_07_actual,
        SUM(IF((poweroff_nature_cd in('2111','2112','2121','2122','2141','2211','2212','2221','2231','2241') and SUBSTRING(data_dt,5,2)='08'),poweroff_duration_tm,0)) as plan_stop_month_08_actual,
        SUM(IF((poweroff_nature_cd in('2111','2112','2121','2122','2141','2211','2212','2221','2231','2241') and SUBSTRING(data_dt,5,2)='09'),poweroff_duration_tm,0)) as plan_stop_month_09_actual,
        SUM(IF((poweroff_nature_cd in('2111','2112','2121','2122','2141','2211','2212','2221','2231','2241') and SUBSTRING(data_dt,5,2)='10'),poweroff_duration_tm,0)) as plan_stop_month_10_actual,
        SUM(IF((poweroff_nature_cd in('2111','2112','2121','2122','2141','2211','2212','2221','2231','2241') and SUBSTRING(data_dt,5,2)='11'),poweroff_duration_tm,0)) as plan_stop_month_11_actual,
        SUM(IF((poweroff_nature_cd in('2111','2112','2121','2122','2141','2211','2212','2221','2231','2241') and SUBSTRING(data_dt,5,2)='12'),poweroff_duration_tm,0)) as plan_stop_month_12_actual,

        SUM(IF((poweroff_nature_cd in('1101','1202') and SUBSTRING(data_dt,5,2)='01'),poweroff_duration_tm,0)) as error_stop_month_01_actual,
        SUM(IF((poweroff_nature_cd in('1101','1202') and SUBSTRING(data_dt,5,2)='02'),poweroff_duration_tm,0)) as error_stop_month_02_actual,
        SUM(IF((poweroff_nature_cd in('1101','1202') and SUBSTRING(data_dt,5,2)='03'),poweroff_duration_tm,0)) as error_stop_month_03_actual,
        SUM(IF((poweroff_nature_cd in('1101','1202') and SUBSTRING(data_dt,5,2)='04'),poweroff_duration_tm,0)) as error_stop_month_04_actual,
        SUM(IF((poweroff_nature_cd in('1101','1202') and SUBSTRING(data_dt,5,2)='05'),poweroff_duration_tm,0)) as error_stop_month_05_actual,
        SUM(IF((poweroff_nature_cd in('1101','1202') and SUBSTRING(data_dt,5,2)='06'),poweroff_duration_tm,0)) as error_stop_month_06_actual,
        SUM(IF((poweroff_nature_cd in('1101','1202') and SUBSTRING(data_dt,5,2)='07'),poweroff_duration_tm,0)) as error_stop_month_07_actual,
        SUM(IF((poweroff_nature_cd in('1101','1202') and SUBSTRING(data_dt,5,2)='08'),poweroff_duration_tm,0)) as error_stop_month_08_actual,
        SUM(IF((poweroff_nature_cd in('1101','1202') and SUBSTRING(data_dt,5,2)='09'),poweroff_duration_tm,0)) as error_stop_month_09_actual,
        SUM(IF((poweroff_nature_cd in('1101','1202') and SUBSTRING(data_dt,5,2)='10'),poweroff_duration_tm,0)) as error_stop_month_10_actual,
        SUM(IF((poweroff_nature_cd in('1101','1202') and SUBSTRING(data_dt,5,2)='11'),poweroff_duration_tm,0)) as error_stop_month_11_actual,
        SUM(IF((poweroff_nature_cd in('1101','1202') and SUBSTRING(data_dt,5,2)='12'),poweroff_duration_tm,0)) as error_stop_month_12_actual
        from pdm_stop_records
        where SUBSTRING(data_dt,1,4) = #{reportYear}
        GROUP BY substr(duty_dept_no,2,12)
        ) t2 on t1.company_no = t2.org_no
        where  report_year = #{reportYear}

    </select>

</mapper>
