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

    <resultMap type="PdmRiskRole" id="PdmRiskRoleResult">
        <result property="id"    column="id"    />
        <result property="roleCode"    column="role_code"    />
        <result property="roleName"    column="role_name"    />
        <result property="roleDes"    column="role_des"    />
        <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="selectPdmRiskRoleVo">
        select id, role_code, role_name, role_des, create_by, create_time, update_by, update_time from pdm_risk_role
    </sql>

    <select id="selectPdmRiskRoleList" parameterType="PdmRiskRole" resultMap="PdmRiskRoleResult">
        <include refid="selectPdmRiskRoleVo"/>
        <where>
            <if test="roleCode != null  and roleCode != ''"> and role_code = #{roleCode}</if>
            <if test="roleName != null  and roleName != ''"> and role_name like concat('%', #{roleName}, '%')</if>
            <if test="roleDes != null  and roleDes != ''"> and role_des = #{roleDes}</if>
        </where>
    </select>

    <select id="selectPdmRiskRoleById" parameterType="Long" resultMap="PdmRiskRoleResult">
        <include refid="selectPdmRiskRoleVo"/>
        where id = #{id}
    </select>

    <insert id="insertPdmRiskRole" parameterType="PdmRiskRole" useGeneratedKeys="true" keyProperty="id">
        insert into pdm_risk_role
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="roleCode != null">role_code,</if>
            <if test="roleName != null">role_name,</if>
            <if test="roleDes != null">role_des,</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="roleCode != null">#{roleCode},</if>
            <if test="roleName != null">#{roleName},</if>
            <if test="roleDes != null">#{roleDes},</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="updatePdmRiskRole" parameterType="PdmRiskRole">
        update pdm_risk_role
        <trim prefix="SET" suffixOverrides=",">
            <if test="roleCode != null">role_code = #{roleCode},</if>
            <if test="roleName != null">role_name = #{roleName},</if>
            <if test="roleDes != null">role_des = #{roleDes},</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="deletePdmRiskRoleById" parameterType="Long">
        delete from pdm_risk_role where id = #{id}
    </delete>

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