<?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="org.xyzh.system.mapper.ResourcePermissionMapper">

    <!-- 基础结果映射 -->
    <resultMap id="BaseResultMap" type="org.xyzh.common.dto.permission.TbResourcePermission">
        <id column="id" property="id" jdbcType="VARCHAR"/>
        <result column="resource_type" property="resourceType" jdbcType="INTEGER"/>
        <result column="resource_id" property="resourceID" jdbcType="VARCHAR"/>
        <result column="dept_id" property="deptID" jdbcType="VARCHAR"/>
        <result column="role_id" property="roleID" jdbcType="VARCHAR"/>
        <result column="can_read" property="canRead" jdbcType="TINYINT"/>
        <result column="can_write" property="canWrite" jdbcType="TINYINT"/>
        <result column="can_execute" property="canExecute" jdbcType="TINYINT"/>
        <result column="creator" property="creator" jdbcType="VARCHAR"/>
        <result column="updater" property="updater" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
        <result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
        <result column="deleted" property="deleted" jdbcType="TINYINT"/>
    </resultMap>

    <!-- 视图对象映射 -->
    <resultMap id="ResourcePermissionVO" type="org.xyzh.common.vo.ResourcePermissionVO">
        <id column="id" property="id" jdbcType="VARCHAR"/>
        <result column="resource_type" property="resourceType" jdbcType="INTEGER"/>
        <result column="resource_id" property="resourceID" jdbcType="VARCHAR"/>
        <result column="dept_id" property="deptID" jdbcType="VARCHAR"/>
        <result column="role_id" property="roleID" jdbcType="VARCHAR"/>
        <result column="can_read" property="canRead" jdbcType="TINYINT"/>
        <result column="can_write" property="canWrite" jdbcType="TINYINT"/>
        <result column="can_execute" property="canExecute" jdbcType="TINYINT"/>
        <result column="creator" property="creator" jdbcType="VARCHAR"/>
        <result column="updater" property="updater" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
        <result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
        <result column="deleted" property="deleted" jdbcType="TINYINT"/>
        <result column="dept_name" property="deptName" jdbcType="VARCHAR"/>
        <result column="role_name" property="roleName" jdbcType="VARCHAR"/>
        <result column="resource_title" property="resourceTitle" jdbcType="VARCHAR"/>
    </resultMap>

    <!-- 基础字段 -->
    <sql id="Base_Column_List">
        id, resource_type, resource_id, dept_id, role_id, 
        can_read, can_write, can_execute, 
        creator, updater, create_time, update_time, delete_time, deleted
    </sql>

    <!-- 插入资源权限 -->
    <insert id="insertResourcePermission" parameterType="org.xyzh.common.dto.permission.TbResourcePermission">
        INSERT INTO tb_resource_permission (
            id, resource_type, resource_id, dept_id, role_id,
            can_read, can_write, can_execute,
            creator, create_time, deleted
        ) VALUES (
            #{id}, #{resourceType}, #{resourceID}, #{deptID}, #{roleID},
            #{canRead}, #{canWrite}, #{canExecute},
            #{creator}, #{createTime}, #{deleted}
        )
    </insert>

    <!-- 批量插入资源权限 -->
    <insert id="batchInsertResourcePermission" parameterType="java.util.List">
        INSERT INTO tb_resource_permission (
            id, resource_type, resource_id, dept_id, role_id,
            can_read, can_write, can_execute,
            creator, create_time, deleted
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
                #{item.id}, #{item.resourceType}, #{item.resourceID}, #{item.deptID}, #{item.roleID},
                #{item.canRead}, #{item.canWrite}, #{item.canExecute},
                #{item.creator}, #{item.createTime}, #{item.deleted}
            )
        </foreach>
    </insert>

</mapper>
