<?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.sqx.modules.app.dao.UserMoneyDetailsDao">
    <select id="monthIncome" resultType="Double">
        select sum(money)  from user_money_details where user_id=#{userId} and classify=4 and type=2 and state=2 and   date_format(create_time,'%Y-%m')=date_format(#{date},'%Y-%m')
    </select>
    <select id="selectMyProfit" resultType="Double">
        select sum(money) from user_money_details where user_id=#{userId} and classify!=3
    </select>

    <select id="selectCompanySumMoney" resultType="Double">
        select ifnull(sum(money),0.00) from user_money_details where company_id=#{companyId} and classify=1
    </select>

    <select id="selectCompanySumMoneyAndTime" resultType="Double">
            select ifnull(sum(money),0.00) from user_money_details where company_id=#{companyId} and classify=1
                and date_format(create_time,'%Y-%m-%d')>=date_format(DATE_SUB(now(),INTERVAL #{value} month),'%Y-%m-%d')
                and date_format(create_time,'%Y-%m-%d')&lt;=date_format(now(),'%Y-%m-%d')
    </select>

    <select id="endCustomizationMoney" resultType="com.sqx.modules.app.entity.UserMoneyDetails">
        select * from user_money_details where classify=2 and state=1
        and date_format(date_add(create_time,INTERVAL 1 day),'%Y-%m-%d %h:%i:%s')&lt;=date_format(now(),'%Y-%m-%d %h:%i:%s')
    </select>
    <select id="getOneProfit" resultType="java.math.BigDecimal">
        SELECT
        IFNULL(SUM(money), 0)
        FROM
        user_money_details
        WHERE user_id = #{userId}
        <if test="level!=null">
            AND user_level =#{level}
        </if>

    </select>
    <select id="getProfitList" resultType="java.util.HashMap">
        SELECT u.user_id as userId,
               u.avatar,
               u.user_name as userName,
               SUM(money ) AS money
        FROM user_money_details d,
             tb_user u
        WHERE d.relation_id = u.user_id
          AND d.user_id = #{userId}
          AND d.user_level =#{type}
        GROUP BY d.relation_id DESC
        ORDER BY money DESC


    </select>


</mapper>