<?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="cn.chnmuseum.party.mapper.AuditMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.chnmuseum.party.model.Audit">
        <id column="id" property="id"/>
        <result column="content" property="content"/>
        <result column="organ_id" property="organId"/>
        <result column="ref_item_id" property="refItemId"/>
        <result column="user_id" property="userId"/>
        <result column="type" property="type"/>
        <result column="operation" property="operation"/>
        <result column="status" property="status"/>
        <result column="create_time" property="createTime"/>
        <result column="first_time" property="firstTime"/>
        <result column="second_time" property="secondTime"/>
        <result column="first_remarks" property="firstRemarks"/>
        <result column="second_remarks" property="secondRemarks"/>
        <result column="level" property="level"/>
        <result column="model_data" property="modelData"/>
        <result column="audit_id" property="auditId"/>
    </resultMap>

    <select id="getUserList" resultMap="BaseResultMap">
        select a.*,o.name org_name,u.user_name user_name
        from t_audit a
        left join t_organ o on o.id = a.organ_id
        left join t_user u on u.id = a.user_id
        where (1 = 1
        <if test="user.userName != null and user.userName != ''">
            and (u.user_name LIKE concat('%', #{user.userName}, '%') or a.content LIKE concat('%', #{user.userName},
            '%'))
        </if>
        <if test="user.status != null and user.status != ''">
            and a.status = #{user.status}
        </if>
        <if test="user.auditStatus != null and user.auditStatus != ''">
            and a.level = #{user.auditStatus}
        </if>
        <if test="user.orgCode != null and user.orgCode != ''">
            and o.code LIKE concat(#{user.orgCode}, '%')
        </if>
        and a.type = 'ACCOUNT'
        and a.operation = 'DISABLE')
        <if test="user.id != null and user.id != ''">
        or (a.audit_id = #{user.id}
            <if test="user.userName != null and user.userName != ''">
                and (u.user_name LIKE concat('%', #{user.userName}, '%') or a.content LIKE concat('%', #{user.userName},
                '%'))
            </if>
            <if test="user.status != null and user.status != ''">
                and a.status = #{user.status}
            </if>
            <if test="user.orgCode != null and user.orgCode != ''">
                and o.code LIKE concat(#{user.orgCode}, '%')
            </if>
            and a.type = 'ACCOUNT'
            and a.operation = 'DISABLE')
       </if>
        order by a.create_time desc
    </select>

    <select id="getVideoContentPage" resultType="cn.chnmuseum.party.model.Audit">
        SELECT
        a.*, b.`name`, c.user_name AS userName
        FROM
        t_audit a
        LEFT JOIN video_content b ON a.ref_item_id = b.id
        LEFT JOIN t_user c ON a.user_id = c.id
        ${ew.customSqlSegment}
    </select>

    <select id="getExhibitionBoardPage" resultType="cn.chnmuseum.party.model.Audit">
        SELECT
        a.*,b.`name`,c.user_name AS userName
        FROM
        t_audit a
        LEFT JOIN exhibition_board b ON a.ref_item_id=b.id
        LEFT JOIN t_user c ON a.user_id = c.id
        ${ew.customSqlSegment}
    </select>

    <select id="getLearningContentPage" resultType="cn.chnmuseum.party.model.Audit">
        SELECT
        a.*,b.`name`,c.user_name AS userName
        FROM
        t_audit a
        LEFT JOIN learning_content b ON a.ref_item_id=b.id
        LEFT JOIN t_user c ON a.user_id = c.id
        ${ew.customSqlSegment}
    </select>

</mapper>