<?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.hzs.system.sys.mapper.SysBusinessLogMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.system.sys.SysBusinessLog">
        <id column="PK_ID" property="pkId"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="BUSINESS_TYPE" property="businessType"/>
        <result column="BUSINESS_CODE" property="businessCode"/>
        <result column="BUSINESS_ID" property="businessId"/>
        <result column="BUSINESS_STATUS" property="businessStatus"/>
        <result column="PK_MEMBER" property="pkMember"/>
        <result column="CONTENT" property="content"/>
    </resultMap>

    <!-- 查询列表数据 -->
    <select id="queryList" resultType="com.hzs.system.sys.vo.BusinessLogVO">
        select sbl.pk_id,
        cm.member_code,
        cm.member_name,
        sbl.business_type,
        sbl.content,
        sbl.creation_time operate_time,
        su.user_name operate_user_name,
        su.nick_name operate_nick_name,
        sbl.business_status,
        sab.end_time approve_time,
        sua.user_name approve_user_name,
        sua.nick_name approve_nick_name
        from sys_business_log sbl
        left join cu_member cm
        on cm.pk_id = sbl.pk_member
        left join sys_user su
        on su.user_id = sbl.pk_creator
        left join sys_approval_business sab
        on sab.approval_business = sbl.business_type
        and sab.business_code = sbl.business_code
        left join sys_user sua
        on sua.user_id = sab.pk_modified
        where sbl.del_flag = 0
        and sbl.pk_country = #{pkCountry}
        <if test="param.memberCode != null and param.memberCode != ''">
            and cm.member_code like #{param.memberCode} || '%'
        </if>
        <if test="param.memberName != null and param.memberName != ''">
            and cm.member_name like #{param.memberName} || '%'
        </if>
        <if test="param.businessType != null">
            and sbl.business_type = #{param.businessType}
        </if>
        <if test="param.operateUserName != null and param.operateUserName != ''">
            and su.user_name like #{param.operateUserName} || '%'
        </if>
        <if test="param.businessStatus != null">
            and sbl.business_status = #{param.businessStatus}
        </if>
        <if test="param.approveUserName != null and param.approveUserName != ''">
            and (sua.user_name like #{param.approveUserName} || '%' and sbl.business_status in (4,5))
        </if>
        <if test="param.operateTime != null">
            and sbl.creation_time >= #{param.operateTime[0]}
            and #{param.operateTime[1]} >= sbl.creation_time
        </if>
        <if test="param.approveTime != null">
            and sab.end_time >= #{param.approveTime[0]}
            and #{param.approveTime[1]} >= sab.end_time
        </if>
        <if test="param.userId != null">
            and (sbl.pk_creator = #{param.userId} or sab.pk_modified = #{param.userId})
        </if>
        order by sbl.creation_time desc
    </select>

</mapper>
