<?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.fs.store.mapper.FsStoreOrderAuditMapper">

    <select id="selectStoreOrderAuditVOList" resultType="com.fs.store.vo.FsStoreOrderAuditVO">
        select
            fsoa.id,
            fsoa.order_id,
            fsoa.company_id,
            fsoa.company_user_id,
            fsoa.audit_status,
            fsoa.company_audit_time,
            fsoa.company_audit_user_id,
            fsoa.admin_audit_time,
            fsoa.admin_audit_user_id,
            fsoa.reason,
            fsoa.create_time,
            fso.order_code,
            c.company_name,
            cu.nick_name companyUserName,
            cau.nick_name companyAuditUserName,
            aau.nick_name adminAuditUserName
        from fs_store_order_audit fsoa
        left join fs_store_order fso on fso.id = fsoa.order_id
        left join company c on c.company_id = fsoa.company_id
        left join company_user cu on cu.user_id = fsoa.company_user_id
        left join company_user cau on cau.user_id = fsoa.company_audit_user_id
        left join sys_user aau on aau.user_id = fsoa.admin_audit_user_id
        <where>
            <if test="companyId != null">
                and fsoa.company_id = #{companyId}
            </if>
            <if test="companyUserName != null and companyUserName != ''">
                and cu.nick_name like concat('%', #{companyUserName}, '%')
            </if>
            <if test="auditStatus != null">
                and fsoa.audit_status = #{auditStatus}
            </if>
        </where>
        order by fsoa.admin_audit_time desc, fsoa.company_audit_time desc, fsoa.create_time desc
    </select>
</mapper>
