<?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.lightinit.hsdataplatform.mapper.ResourceAuthMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdataplatform.entity.ResourceAuth">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="platform_type" jdbcType="VARCHAR" property="platformType" />
    <result column="publish_info_id" jdbcType="BIGINT" property="publishInfoId" />
    <result column="publish_setting_id" jdbcType="BIGINT" property="publishSettingId" />
    <result column="auth_state" jdbcType="VARCHAR" property="authState" />
    <result column="applier" jdbcType="BIGINT" property="applier" />
    <result column="apply_time" jdbcType="TIMESTAMP" property="applyTime" />
    <result column="audited_by" jdbcType="BIGINT" property="auditedBy" />
    <result column="audited_at" jdbcType="TIMESTAMP" property="auditedAt" />
    <result column="audit_result" jdbcType="VARCHAR" property="auditResult" />
    <result column="audit_opinion" jdbcType="VARCHAR" property="auditOpinion" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
    <result column="created_by" jdbcType="BIGINT" property="createdBy" />
    <result column="deleted_at" jdbcType="TIMESTAMP" property="deletedAt" />
    <result column="deleted_by" jdbcType="BIGINT" property="deletedBy" />
  </resultMap>
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.lightinit.hsdataplatform.entity.ResourceAuth">
    <result column="apply_reason" jdbcType="LONGVARCHAR" property="applyReason" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    id, platform_type, publish_info_id, publish_setting_id, auth_state, applier, apply_time, 
    audited_by, audited_at, audit_result, audit_opinion, created_at, created_by, deleted_at, 
    deleted_by
  </sql>
  <sql id="Blob_Column_List">
    apply_reason
  </sql>
  <select id="selectByExampleWithBLOBs" parameterType="com.lightinit.hsdataplatform.entity.ResourceAuthExample" resultMap="ResultMapWithBLOBs">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from resource_auth
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByExample" parameterType="com.lightinit.hsdataplatform.entity.ResourceAuthExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from resource_auth
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="ResultMapWithBLOBs">
    select 
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from resource_auth
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from resource_auth
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.lightinit.hsdataplatform.entity.ResourceAuthExample">
    delete from resource_auth
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.lightinit.hsdataplatform.entity.ResourceAuth">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into resource_auth (platform_type, publish_info_id, publish_setting_id, 
      auth_state, applier, apply_time, 
      audited_by, audited_at, audit_result, 
      audit_opinion, created_at, created_by, 
      deleted_at, deleted_by, apply_reason
      )
    values (#{platformType,jdbcType=VARCHAR}, #{publishInfoId,jdbcType=BIGINT}, #{publishSettingId,jdbcType=BIGINT}, 
      #{authState,jdbcType=VARCHAR}, #{applier,jdbcType=BIGINT}, #{applyTime,jdbcType=TIMESTAMP}, 
      #{auditedBy,jdbcType=BIGINT}, #{auditedAt,jdbcType=TIMESTAMP}, #{auditResult,jdbcType=VARCHAR}, 
      #{auditOpinion,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=BIGINT}, 
      #{deletedAt,jdbcType=TIMESTAMP}, #{deletedBy,jdbcType=BIGINT}, #{applyReason,jdbcType=LONGVARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.lightinit.hsdataplatform.entity.ResourceAuth">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into resource_auth
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="platformType != null">
        platform_type,
      </if>
      <if test="publishInfoId != null">
        publish_info_id,
      </if>
      <if test="publishSettingId != null">
        publish_setting_id,
      </if>
      <if test="authState != null">
        auth_state,
      </if>
      <if test="applier != null">
        applier,
      </if>
      <if test="applyTime != null">
        apply_time,
      </if>
      <if test="auditedBy != null">
        audited_by,
      </if>
      <if test="auditedAt != null">
        audited_at,
      </if>
      <if test="auditResult != null">
        audit_result,
      </if>
      <if test="auditOpinion != null">
        audit_opinion,
      </if>
      <if test="createdAt != null">
        created_at,
      </if>
      <if test="createdBy != null">
        created_by,
      </if>
      <if test="deletedAt != null">
        deleted_at,
      </if>
      <if test="deletedBy != null">
        deleted_by,
      </if>
      <if test="applyReason != null">
        apply_reason,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="platformType != null">
        #{platformType,jdbcType=VARCHAR},
      </if>
      <if test="publishInfoId != null">
        #{publishInfoId,jdbcType=BIGINT},
      </if>
      <if test="publishSettingId != null">
        #{publishSettingId,jdbcType=BIGINT},
      </if>
      <if test="authState != null">
        #{authState,jdbcType=VARCHAR},
      </if>
      <if test="applier != null">
        #{applier,jdbcType=BIGINT},
      </if>
      <if test="applyTime != null">
        #{applyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="auditedBy != null">
        #{auditedBy,jdbcType=BIGINT},
      </if>
      <if test="auditedAt != null">
        #{auditedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="auditResult != null">
        #{auditResult,jdbcType=VARCHAR},
      </if>
      <if test="auditOpinion != null">
        #{auditOpinion,jdbcType=VARCHAR},
      </if>
      <if test="createdAt != null">
        #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="deletedAt != null">
        #{deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="deletedBy != null">
        #{deletedBy,jdbcType=BIGINT},
      </if>
      <if test="applyReason != null">
        #{applyReason,jdbcType=LONGVARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.lightinit.hsdataplatform.entity.ResourceAuthExample" resultType="java.lang.Long">
    select count(*) from resource_auth
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update resource_auth
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.platformType != null">
        platform_type = #{record.platformType,jdbcType=VARCHAR},
      </if>
      <if test="record.publishInfoId != null">
        publish_info_id = #{record.publishInfoId,jdbcType=BIGINT},
      </if>
      <if test="record.publishSettingId != null">
        publish_setting_id = #{record.publishSettingId,jdbcType=BIGINT},
      </if>
      <if test="record.authState != null">
        auth_state = #{record.authState,jdbcType=VARCHAR},
      </if>
      <if test="record.applier != null">
        applier = #{record.applier,jdbcType=BIGINT},
      </if>
      <if test="record.applyTime != null">
        apply_time = #{record.applyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.auditedBy != null">
        audited_by = #{record.auditedBy,jdbcType=BIGINT},
      </if>
      <if test="record.auditedAt != null">
        audited_at = #{record.auditedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.auditResult != null">
        audit_result = #{record.auditResult,jdbcType=VARCHAR},
      </if>
      <if test="record.auditOpinion != null">
        audit_opinion = #{record.auditOpinion,jdbcType=VARCHAR},
      </if>
      <if test="record.createdAt != null">
        created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.createdBy != null">
        created_by = #{record.createdBy,jdbcType=BIGINT},
      </if>
      <if test="record.deletedAt != null">
        deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.deletedBy != null">
        deleted_by = #{record.deletedBy,jdbcType=BIGINT},
      </if>
      <if test="record.applyReason != null">
        apply_reason = #{record.applyReason,jdbcType=LONGVARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExampleWithBLOBs" parameterType="map">
    update resource_auth
    set id = #{record.id,jdbcType=BIGINT},
      platform_type = #{record.platformType,jdbcType=VARCHAR},
      publish_info_id = #{record.publishInfoId,jdbcType=BIGINT},
      publish_setting_id = #{record.publishSettingId,jdbcType=BIGINT},
      auth_state = #{record.authState,jdbcType=VARCHAR},
      applier = #{record.applier,jdbcType=BIGINT},
      apply_time = #{record.applyTime,jdbcType=TIMESTAMP},
      audited_by = #{record.auditedBy,jdbcType=BIGINT},
      audited_at = #{record.auditedAt,jdbcType=TIMESTAMP},
      audit_result = #{record.auditResult,jdbcType=VARCHAR},
      audit_opinion = #{record.auditOpinion,jdbcType=VARCHAR},
      created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      created_by = #{record.createdBy,jdbcType=BIGINT},
      deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{record.deletedBy,jdbcType=BIGINT},
      apply_reason = #{record.applyReason,jdbcType=LONGVARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update resource_auth
    set id = #{record.id,jdbcType=BIGINT},
      platform_type = #{record.platformType,jdbcType=VARCHAR},
      publish_info_id = #{record.publishInfoId,jdbcType=BIGINT},
      publish_setting_id = #{record.publishSettingId,jdbcType=BIGINT},
      auth_state = #{record.authState,jdbcType=VARCHAR},
      applier = #{record.applier,jdbcType=BIGINT},
      apply_time = #{record.applyTime,jdbcType=TIMESTAMP},
      audited_by = #{record.auditedBy,jdbcType=BIGINT},
      audited_at = #{record.auditedAt,jdbcType=TIMESTAMP},
      audit_result = #{record.auditResult,jdbcType=VARCHAR},
      audit_opinion = #{record.auditOpinion,jdbcType=VARCHAR},
      created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      created_by = #{record.createdBy,jdbcType=BIGINT},
      deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{record.deletedBy,jdbcType=BIGINT}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.lightinit.hsdataplatform.entity.ResourceAuth">
    update resource_auth
    <set>
      <if test="platformType != null">
        platform_type = #{platformType,jdbcType=VARCHAR},
      </if>
      <if test="publishInfoId != null">
        publish_info_id = #{publishInfoId,jdbcType=BIGINT},
      </if>
      <if test="publishSettingId != null">
        publish_setting_id = #{publishSettingId,jdbcType=BIGINT},
      </if>
      <if test="authState != null">
        auth_state = #{authState,jdbcType=VARCHAR},
      </if>
      <if test="applier != null">
        applier = #{applier,jdbcType=BIGINT},
      </if>
      <if test="applyTime != null">
        apply_time = #{applyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="auditedBy != null">
        audited_by = #{auditedBy,jdbcType=BIGINT},
      </if>
      <if test="auditedAt != null">
        audited_at = #{auditedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="auditResult != null">
        audit_result = #{auditResult,jdbcType=VARCHAR},
      </if>
      <if test="auditOpinion != null">
        audit_opinion = #{auditOpinion,jdbcType=VARCHAR},
      </if>
      <if test="createdAt != null">
        created_at = #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="deletedAt != null">
        deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="deletedBy != null">
        deleted_by = #{deletedBy,jdbcType=BIGINT},
      </if>
      <if test="applyReason != null">
        apply_reason = #{applyReason,jdbcType=LONGVARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.lightinit.hsdataplatform.entity.ResourceAuth">
    update resource_auth
    set platform_type = #{platformType,jdbcType=VARCHAR},
      publish_info_id = #{publishInfoId,jdbcType=BIGINT},
      publish_setting_id = #{publishSettingId,jdbcType=BIGINT},
      auth_state = #{authState,jdbcType=VARCHAR},
      applier = #{applier,jdbcType=BIGINT},
      apply_time = #{applyTime,jdbcType=TIMESTAMP},
      audited_by = #{auditedBy,jdbcType=BIGINT},
      audited_at = #{auditedAt,jdbcType=TIMESTAMP},
      audit_result = #{auditResult,jdbcType=VARCHAR},
      audit_opinion = #{auditOpinion,jdbcType=VARCHAR},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{deletedBy,jdbcType=BIGINT},
      apply_reason = #{applyReason,jdbcType=LONGVARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.lightinit.hsdataplatform.entity.ResourceAuth">
    update resource_auth
    set platform_type = #{platformType,jdbcType=VARCHAR},
      publish_info_id = #{publishInfoId,jdbcType=BIGINT},
      publish_setting_id = #{publishSettingId,jdbcType=BIGINT},
      auth_state = #{authState,jdbcType=VARCHAR},
      applier = #{applier,jdbcType=BIGINT},
      apply_time = #{applyTime,jdbcType=TIMESTAMP},
      audited_by = #{auditedBy,jdbcType=BIGINT},
      audited_at = #{auditedAt,jdbcType=TIMESTAMP},
      audit_result = #{auditResult,jdbcType=VARCHAR},
      audit_opinion = #{auditOpinion,jdbcType=VARCHAR},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{deletedBy,jdbcType=BIGINT}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <select id="queryList" parameterType="com.lightinit.hsdataplatform.model.admin.AuthorizationSearchModel"
          resultType="com.lightinit.hsdataplatform.model.admin.AuthorizationListModel">
            <if test="resourceName != null and resourceName.length() > 0">
              <bind name="resourceName" value="'%' + _parameter.resourceName + '%'" />
            </if>
            select a.*
            from
            (select ra.id,ra.publish_info_id,ra.publish_setting_id,ra.platform_type platfromType,r.resource_name,r.resource_type,r.id rid,ra.`created_by`,
            r.open_type  openOrShare,ra.`apply_time`,ra.`auth_state`,r.created_by createdBy,pi.out_id_1 outId1,ra.applier
            from resource_auth ra
            left join publish_info pi
            on pi.id = ra.publish_info_id
            left join resource r
            on r.id = pi.resource_id
            where ra.platform_type = '开放平台' and r.open_type = "依申请开放"
            union
            select ra.id,ra.publish_info_id,ra.publish_setting_id,ra.platform_type platfromType,r.resource_name,r.resource_type,r.id rid,ra.`created_by`,
            r.share_type openOrShare,ra.`apply_time`,ra.`auth_state`,r.created_by createdBy,pi.out_id_1 outId1,ra.applier
            from resource_auth ra
            left join publish_info pi
            on pi.id = ra.publish_info_id
             left join resource r
            on r.id = pi.resource_id
            where ra.platform_type = '共享平台' and r.share_type = "有条件共享") a
            LEFT JOIN admin d
            ON  d.id = a.createdBy
            <where>
              <if test="resourceName != null and resourceName.length() > 0">
                a.resource_name LIKE #{resourceName}
              </if>
              <if test="authState != null and authState.length() > 0">
                AND a.auth_state = #{authState}
              </if>
              <if test="resourceType != null and resourceType.length() > 0">
                AND a.resource_type = #{resourceType}
              </if>
              <if test="openOrShare != null and openOrShare.length() > 0">
                AND a.openOrShare = #{openOrShare}
              </if>
              <if test="platfromType != null and platfromType.length() > 0">
                AND a.platfromType = #{platfromType}
              </if>
              <if test="applyTime != null">
                AND date(a.apply_time) = date(#{applyTime,jdbcType=TIMESTAMP})
              </if>
              <if test="orgId != null">
                AND d.org_id = #{orgId}
              </if>
            </where>
              ORDER BY a.id DESC
              <if test="page != null" >
                LIMIT #{page.beginIndex},#{page.pageSize}
              </if>
  </select>
  <select id="queryCount" parameterType="com.lightinit.hsdataplatform.model.admin.AuthorizationSearchModel"
          resultType="java.lang.Long">
            select count(*)
            from
            (select ra.id,ra.publish_info_id,ra.publish_setting_id,ra.platform_type platfromType,r.resource_name,r.resource_type,r.id rid,ra.`created_by`,
            r.open_type  openOrShare,ra.`apply_time`,ra.`auth_state`,r.created_by createdBy
            from resource_auth ra
            left join publish_info pi
            on pi.id = ra.publish_info_id
            left join resource r
            on r.id = pi.resource_id
            where ra.platform_type = '开放平台' and r.open_type = '依申请开放'
            union
            select ra.id,ra.publish_info_id,ra.publish_setting_id,ra.platform_type platfromType,r.resource_name,r.resource_type,r.id rid,ra.`created_by`,
            r.share_type openOrShare,ra.`apply_time`,ra.`auth_state`,r.created_by createdBy
            from resource_auth ra
            left join publish_info pi
            on pi.id = ra.publish_info_id
             left join resource r
            on r.id = pi.resource_id
            where ra.platform_type = '共享平台' and r.share_type = '有条件共享') a
            LEFT JOIN admin d
            ON  d.id = a.createdBy
            <where>
              <if test="resourceName != null and resourceName.length() > 0">
                a.resource_name LIKE #{resourceName}
              </if>
              <if test="authState != null and authState.length() > 0">
                AND a.auth_state = #{authState}
              </if>
              <if test="resourceType != null and resourceType.length() > 0">
                AND a.resource_type = #{resourceType}
              </if>
              <if test="openOrShare != null and openOrShare.length() > 0">
                AND a.openOrShare = #{openOrShare}
              </if>
              <if test="platfromType != null and platfromType.length() > 0">
                AND a.platfromType = #{platfromType}
              </if>
              <if test="applyTime != null">
                AND date(a.apply_time) = date(#{applyTime,jdbcType=TIMESTAMP})
              </if>
              <if test="orgId != null">
                AND d.org_id = #{orgId}
              </if>
            </where>
  </select>

  <select id="queryOneView" parameterType="java.lang.Long" resultType="com.lightinit.hsdataplatform.model.admin.AuthorizationViewModel">
        SELECT
          ra.id,r.resource_name,r.resource_type,r.open_type,r.share_type,
          ra.apply_time,ra.platform_type platfromType,ra.apply_reason,ad.`username` auditedByName,
          ra.auth_state,ra.audit_opinion,ra.publish_setting_id,
          CASE WHEN ra.platform_type='开放平台' THEN (SELECT u.username FROM `user` u WHERE u.id = ra.applier)
          WHEN ra.platform_type='共享平台' THEN (SELECT a.username FROM `admin` a WHERE a.id = ra.applier)  ELSE NULL END applierName,
           CASE WHEN ra.platform_type='共享平台' THEN (SELECT se.sector_name FROM `admin` a join sector se on a.org_id = se.id WHERE a.id = ra.applier)
          ELSE NULL END auditedBySector
          FROM
          resource_auth ra
          LEFT JOIN publish_info pi
          ON pi.id = ra.publish_info_id
          LEFT JOIN resource r
          ON r.id = pi.resource_id
          left join `admin` ad
          on ad.id = ra.audited_by
          left join sector s
          on s.id = ad.`org_id`
          WHERE ra.id = #{id}
  </select>
</mapper>