<?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.CompanyWalletCathMapper">
    


    <select id="selectList" resultType="com.github.wxiaoqi.security.admin.vo.CompanyWalletCathVo"  parameterType="com.github.wxiaoqi.security.admin.dto.WalletCathDTO">
        SELECT
        wc.*,
        c.`name` as companyName,
        ci.`name` as branchName,
        ci.id as branchId
        FROM company_wallet_cath wc
        LEFT JOIN  branch_company c ON wc.company_id =c.id
        LEFT JOIN company_info ci ON c.company_id=ci.id
        <where>
            <if test="companyId != null and companyId > 0">
                and  wc.company_id=#{companyId}
            </if>
            <if test="branchId != null and branchId > 0">
                and  c.company_id=#{branchId}
            </if>
            <if test="id != null and id > 0">
                and  wc.id=#{id}
            </if>
            <if test="orderNo != null and orderNo != '' ">
                and  wc.order_no like concat('%',#{orderNo},'%')
            </if>
            <if test="status != null ">
                and
               <choose>
                   <when test="status == 0">
                       wc.stauts in (0 ,2)
                   </when>
                   <otherwise>
                       wc.stauts =#{status}
                   </otherwise>
               </choose>
            </if>
            <if test="startTime != null and startTime > 0">
                and  wc.crt_time >= #{startTime}
            </if>
            <if test="endTime != null and endTime > 0">
                and  wc.crt_time &lt;= #{endTime}
            </if>
            <if test="dataCompanyIds != null and dataCompanyIds.size() > 0">
                and wc.company_id= in
                <foreach collection="dataCompanyIds"  item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="dataCorporationIds != null and dataCorporationIds.size() > 0">
                and c.company_id  in
                <foreach collection="dataCorporationIds"  item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        order  by  wc.crt_time desc
    </select>


    <select id="sumCathAmount" resultType="com.github.wxiaoqi.security.admin.dto.WalletCathSumDto">
        select IFNULL(SUM(amount),0) as sumAmount,COUNT(*) as `number` from company_wallet_cath
        <where>
            company_id=#{companyId} and stauts in(0,1)
            <choose>
                <when test="type ==1 ">
                    AND date_format(from_unixtime(crt_time/1000),'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')
                </when>
                <when test="type==2 ">
                    AND date_format(from_unixtime(crt_time/1000),'%Y-%m') = date_format(now(),'%Y-%m')
                </when>
                <otherwise>
                </otherwise>
            </choose>
        </where>
    </select>

</mapper>