<?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="PK_MEMBER" property="pkMember"/>
        <result column="BUSINESS_STATUS" property="businessStatus"/>
        <result column="CONTENT" property="content"/>
    </resultMap>

    <!-- 查询列表数据 -->
    <select id="queryList" resultType="com.hzs.system.sys.vo.BusinessLogVO">
        select sbl.business_code,
        cm.member_code,
        cm.member_name,
        sbl.business_type,
        sbl.business_status,
        sbl.content,
        sbl.creation_time operator_time,
        su.user_name operator_user_name,
        su.nick_name operator_nick_name,
        sab.modified_time approve_time,
        sus.user_name approve_user_name,
        sus.nick_name approve_nick_name
        from SYS_BUSINESS_LOG sbl
        left join sys_approval_business sab
        on sab.approval_business = sbl.business_type
        and sab.business_code = sbl.business_code
        and sab.del_flag = 0
        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_user sus
        on sus.user_id = sab.pk_modified
        where sbl.del_flag = 0
        and sbl.pk_country = #{pkCountry}
        <if test="param.operatorUserName != null and param.operatorUserName != ''">
            and su.user_name like #{param.operatorUserName} || '%'
        </if>
        <if test="param.operatorNickName != null and param.operatorNickName != ''">
            and su.nick_name like #{param.operatorNickName} || '%'
        </if>
        <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.businessStatus != null">
            and sbl.business_status = #{param.businessStatus}
        </if>
        <if test="param.operatorTime != null">
            and sbl.creation_time >= #{param.operatorTime[0]}
            and #{param.operatorTime[1]} >= sbl.creation_time
        </if>
        <if test="param.approveTime != null">
            and sab.modified_time >= #{param.approveTime[0]}
            and #{param.approveTime[1]} >= sab.modified_time
        </if>
        order by sbl.creation_time desc
    </select>

</mapper>
