<?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.PdmExamineRequireMapper">
    
    <resultMap type="PdmExamineRequire" id="PdmExamineRequireResult">
        <result property="id"    column="id"    />
        <result property="requireCd"    column="require_cd"    />
        <result property="hourMinNum"    column="hour_min_num"    />
        <result property="hourMaxNum"    column="hour_max_num"    />
        <result property="pId"    column="p_id"    />
        <result property="requireType"    column="require_type"    />
        <result property="sortNo"    column="sort_no"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <resultMap type="PdmExamineRequire" id="PdmExamineRequireResultMap">
        <result property="id"    column="id"    />
        <result property="requireCd"    column="require_cd"    />
        <result property="hourMinNum"    column="hour_min_num"    />
        <result property="hourMaxNum"    column="hour_max_num"    />
        <result property="pId"    column="p_id"    />
        <result property="requireType"    column="require_type"    />
        <result property="sortNo"    column="sort_no"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <collection property="examineCountyList" select="com.ruoyi.powerdistribution.mapper.PdmExamineCountyMapper.selectExamineCountyByRequireCode" column="{requireCd=require_cd,compteHourNumX=remark}"></collection>
    </resultMap>

    <sql id="selectPdmExamineRequireVo">
        select id, require_cd, hour_min_num, hour_max_num, p_id, require_type, sort_no, create_by, create_time, update_by, update_time, remark from pdm_examine_require
    </sql>

    <select id="selectPdmExamineRequireList" parameterType="PdmExamineRequire" resultMap="PdmExamineRequireResult">
        <include refid="selectPdmExamineRequireVo"/>
        <where>  
            <if test="requireCd != null  and requireCd != ''"> and require_cd = #{requireCd}</if>
            <if test="hourMinNum != null  and hourMinNum != ''"> and hour_min_num = #{hourMinNum}</if>
            <if test="hourMaxNum != null "> and hour_max_num = #{hourMaxNum}</if>
            <if test="pId != null "> and p_id = #{pId}</if>
            <if test="requireType != null  and requireType != ''"> and require_type = #{requireType}</if>
            <if test="sortNo != null "> and sort_no = #{sortNo}</if>
        </where>
    </select>

    <select id="selectAllExamineRequireList" parameterType="PdmExamineRequire" resultMap="PdmExamineRequireResultMap">
        <include refid="selectPdmExamineRequireVo"/>
        <where>
            <if test="requireCd != null  and requireCd != ''"> and require_cd = #{requireCd}</if>
            <if test="hourMinNum != null  and hourMinNum != ''"> and hour_min_num = #{hourMinNum}</if>
            <if test="hourMaxNum != null "> and hour_max_num = #{hourMaxNum}</if>
            <if test="pId != null "> and p_id = #{pId}</if>
            <if test="requireType != null  and requireType != ''"> and require_type = #{requireType}</if>
            <if test="sortNo != null "> and sort_no = #{sortNo}</if>
        </where>
       order by require_cd
    </select>



    <select id="selectPdmExamineRequireById" parameterType="Long" resultMap="PdmExamineRequireResult">
        <include refid="selectPdmExamineRequireVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertPdmExamineRequire" parameterType="PdmExamineRequire" useGeneratedKeys="true" keyProperty="id">
        insert into pdm_examine_require
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="requireCd != null">require_cd,</if>
            <if test="hourMinNum != null">hour_min_num,</if>
            <if test="hourMaxNum != null">hour_max_num,</if>
            <if test="pId != null">p_id,</if>
            <if test="requireType != null">require_type,</if>
            <if test="sortNo != null">sort_no,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="requireCd != null">#{requireCd},</if>
            <if test="hourMinNum != null">#{hourMinNum},</if>
            <if test="hourMaxNum != null">#{hourMaxNum},</if>
            <if test="pId != null">#{pId},</if>
            <if test="requireType != null">#{requireType},</if>
            <if test="sortNo != null">#{sortNo},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updatePdmExamineRequire" parameterType="PdmExamineRequire">
        update pdm_examine_require
        <trim prefix="SET" suffixOverrides=",">
            <if test="requireCd != null">require_cd = #{requireCd},</if>
            <if test="hourMinNum != null">hour_min_num = #{hourMinNum},</if>
            <if test="hourMaxNum != null">hour_max_num = #{hourMaxNum},</if>
            <if test="pId != null">p_id = #{pId},</if>
            <if test="requireType != null">require_type = #{requireType},</if>
            <if test="sortNo != null">sort_no = #{sortNo},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePdmExamineRequireById" parameterType="Long">
        delete from pdm_examine_require where id = #{id}
    </delete>

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