<?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.yc.ship.module.otc.dal.mysql.storeaudit.StoreAuditMapper">

    <select id="selectStoreAuditByPage" resultType="com.yc.ship.module.otc.controller.admin.storeaudit.vo.StoreAuditRespVO">
        select sa.*,oas.store_name,od.name as distributorName
        from otc_agency_store_audit sa
         inner join otc_agency_store oas on sa.store_id = oas.id
         INNER JOIN ota_distributor od on od.id = sa.distributor_id
        <where>
            <if test="vo.storeId != null">
                AND sa.store_id = #{vo.storeId}
            </if>
            <if test="vo.distributorId != null">
                AND sa.distributor_id = #{vo.distributorId}
            </if>
            <if test="vo.amount != null">
                AND sa.amount = #{vo.amount}
            </if>
            <if test="vo.applyUserName != null and vo.applyUserName != ''">
                AND sa.apply_user_name  like concat('%',#{vo.applyUserName}, '%')
            </if>
            <if test="vo.auditUserName != null and vo.auditUserName != ''">
                AND sa.audit_user_name  like concat('%',#{vo.auditUserName}, '%')
            </if>
            <if test="vo.status != null">
                AND sa.status = #{vo.status}
            </if>
            <if test="vo.rechargeLogId != null and vo.rechargeLogId != ''">
                AND sa.recharge_log_id  = #{vo.rechargeLogId}
            </if>
            <if test="vo.platTenantId != null">
                AND sa.plat_tenant_id  =  #{vo.platTenantId}
            </if>
            <if test="vo.auditTime != null and vo.auditTime.length == 2">
                AND sa.audit_time between #{vo.auditTime[0]} and #{vo.auditTime[1]}
            </if>
            <if test="vo.applyTime != null and vo.applyTime.length == 2">
                AND sa.apply_time between #{vo.applyTime[0]} and #{vo.applyTime[1]}
            </if>
        </where>
        order by sa.apply_time desc
    </select>

</mapper>
