<?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.lz.modules.flow.dao.RecordAuthMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.flow.entity.RecordAuth">
        <id column="id" property="id"/>
        <result column="is_delete" property="isDelete"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="parent_id" property="parentId"/>
        <result column="name" property="name"/>
        <result column="identity" property="identity"/>
        <result column="status" property="status"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, parent_id AS parentId, name AS name, identity AS identity, status AS status
    </sql>




    <select id="selectRecordAuthById" resultType="RecordAuth" >
        select * from lz_record_auth  where id=#{id} and is_delete = 0 limit 1 
    </select>


    <insert id="insertRecordAuth" parameterType="RecordAuth" useGeneratedKeys="true" keyProperty="id" >
        insert into lz_record_auth(
            <if test="parentId != null">parent_id, </if>
            <if test="name != null">name, </if>
            <if test="identity != null">identity, </if>
            <if test="status != null">status, </if>
            is_delete,
            gmt_create,
            gmt_modified
        )values(
            <if test="parentId != null">#{ parentId}, </if>
            <if test="name != null">#{ name}, </if>
            <if test="identity != null">#{ identity}, </if>
            <if test="status != null">#{ status}, </if>
            0,
            now(),
            now()
        )
    </insert>


    <update id="updateRecordAuthById" parameterType="RecordAuth" >
        update
            lz_record_auth
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="identity != null">identity = #{identity},</if>
            <if test="status != null">status = #{status}</if>                
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverRecordAuthById" parameterType="RecordAuth" >
        update
            lz_record_auth    
        set     
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            parent_id = #{parentId},
            name = #{name},
            identity = #{identity},
            status = #{status}                
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="deleteRecordAuthById" parameterType="java.lang.Long">
        update lz_record_auth set is_delete = 1 where id=#{id} limit 1  
    </update>



    <select id="selectAuthInfo" resultType="RecordAuth">
        select * from (
        select identity ,status  from lz_record_role_auth role_auth left join lz_record_auth auth on role_auth.auth_id = auth.id
         where role_auth.role_id = #{roleId} ORDER BY status desc ) a GROUP BY identity
    </select>


    <select id="selectAll" resultType="com.lz.modules.flow.entity.RecordAuth">
        select * from lz_record_auth order by parent_id asc ,status asc
    </select>


</mapper>

