<?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.predict.mapper.PsmJobV3Mapper">

    <resultMap type="PsmJobV3" id="PsmJobV3Result">
        <result property="rtuNo" column="rtu_no"/>
        <result property="jobType" column="job_type"/>
        <result property="jobKey1" column="job_key1"/>
        <result property="jobName" column="job_name"/>
        <result property="beginTime" column="begin_time"/>
        <result property="endTime" column="end_time"/>
        <result property="execInterval" column="exec_interval"/>
        <result property="nextExecTime" column="next_exec_time"/>
        <result property="procName" column="proc_name"/>
        <result property="procFlag" column="proc_flag"/>
        <result property="directory" column="directory"/>
    </resultMap>

    <sql id="selectPsmJobV3Vo">
        select rtu_no, job_type, job_key1, job_name, begin_time, end_time, exec_interval, next_exec_time, proc_name, proc_flag, directory from psm_job_v3
    </sql>

    <select id="selectPsmJobV3List" parameterType="PsmJobV3" resultMap="PsmJobV3Result">
        select
        pjv.*,
        w.name as "windplantName",
        emi.item_name as "procFlagName"
        from
        psm_job_v3 pjv
        left join windplant w on w.windplant_no = pjv.rtu_no
        left join enum_menu_item emi on emi.item_val = pjv.proc_flag and emi.menu_no = 10
        <where>
            <if test="rtuNo != null ">and pjv.rtu_no = #{rtuNo}</if>
            <if test="jobType != null ">and pjv.job_type = #{jobType}</if>
            <if test="jobKey1 != null ">and pjv.job_key1 = #{jobKey1}</if>
            <if test="jobName != null  and jobName != ''">and pjv.job_name like concat(concat('%', #{jobName}), '%')</if>
            <if test="beginTime != null ">and pjv.begin_time = #{beginTime}</if>
            <if test="endTime != null ">and pjv.end_time = #{endTime}</if>
            <if test="execInterval != null ">and pjv.exec_interval = #{execInterval}</if>
            <if test="nextExecTime != null ">and pjv.next_exec_time = #{nextExecTime}</if>
            <if test="procName != null  and procName != ''">and pjv.proc_name like concat(concat('%', #{procName}), '%')
            </if>
            <if test="procFlag != null ">and pjv.proc_flag = #{procFlag}</if>
            <if test="directory != null  and directory != ''">and pjv.directory = #{directory}</if>
            <if test="windplantName != null  and windplantName != ''">and w.name like concat(concat('%',
                #{windplantName}), '%')
            </if>
            <if test="params.beginDataTime != null and params.beginDataTime != '' and params.endDataTime != null and params.endDataTime != ''">
                and begin_time between to_date(#{params.beginDataTime},'yyyy-MM-dd HH24:MI:SS') and
                to_date(#{params.endDataTime},'yyyy-MM-dd HH24:MI:SS')
            </if>
        </where>
        order by pjv.rtu_no asc
    </select>

    <select id="selectPsmJobV3ById" parameterType="Long" resultMap="PsmJobV3Result">
        <include refid="selectPsmJobV3Vo"/>
        where rtu_no = #{rtuNo}
    </select>

    <select id="selectPsmJobV3ByJobKey1" parameterType="Long" resultMap="PsmJobV3Result">
        <include refid="selectPsmJobV3Vo"/>
        where job_key1 = #{jobKey1}
    </select>

</mapper>