<?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.github.wxiaoqi.security.admin.mapper.BaseOrderRevenueMapper">


 <select id="infoByOrderNo" resultType="com.github.wxiaoqi.security.admin.entity.BaseOrderRevenue">
     SELECT * FROM base_order_revenue WHERE order_no=#{orderNo} and company_id=#{companyId}
     <if test=" type != null and type != ''  ">
         and FIND_IN_SET(type,#{type} )>0
     </if>
 </select>


    <select id="selectList" resultType="com.github.wxiaoqi.security.admin.vo.BaseOrderRevenueVo"
            parameterType="com.github.wxiaoqi.security.admin.dto.BaseOrderRevenueFindDTO">
       SELECT *,(amount-cath_amount) as withdrawAmount FROM base_order_revenue
       <where>
           amount > 0 and is_del = 0
           <if test=" month != null and month != ''  ">
               and from_unixtime(upd_time/1000,'%Y-%m')=#{month}
           </if>
           <if test=" status != null ">
             <choose>
                 <when test="status == 1">
                     and `status` in (1,3)
                 </when>
                 <when test="status == 2">
                     and `status` in (2,4)
                 </when>
                 <otherwise>
                     and `status`=#{status}
                 </otherwise>
             </choose>

           </if>
           <if test=" companyId != null ">
               and `company_id`=#{companyId}
           </if>
       </where>
        order by upd_time desc
    </select>


    <select id="sumAmount" resultType="BigDecimal"
            parameterType="com.github.wxiaoqi.security.admin.dto.BaseOrderRevenueFindDTO">
        SELECT IFNULL(SUM(amount),0) as totalAmount FROM base_order_revenue
        <where>
            amount > 0 and is_del = 0
            <if test=" month != null and month != ''  ">
                and from_unixtime(upd_time/1000,'%Y-%m')=#{month}
            </if>
            <if test=" status != null ">
                <choose>
                    <when test="status == 1">
                        and `status` in (1,3)
                    </when>
                    <otherwise>
                        and `status`=#{status}
                    </otherwise>
                </choose>
            </if>
            <if test=" companyId != null ">
                and `company_id`=#{companyId}
            </if>
        </where>
    </select>

</mapper>