<?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.ruoyi.demo.mapper.StatisticsMapper">
    <select id="selectTotal" resultType="java.lang.Integer">
        SELECT
            COUNT(*)
        FROM
            `dl_statistics`
        WHERE behavior = 0;
    </select>
    <select id="selectUserIdsByEquipmentCode" resultType="java.lang.String">
        SELECT DISTINCT
            user_id
        FROM
            `dl_statistics`
        WHERE
            equipment_code = #{equipmentCode};
    </select>
    <select id="selectScanByEquipmentCode" resultType="java.lang.Integer">
        SELECT
            COUNT(*)
        FROM
            `dl_statistics`
        WHERE
            equipment_code = #{equipmentCode}
          AND behavior = 0;
    </select>
    <select id="selectDealCountByEquipmentCode" resultType="java.lang.Integer">
        SELECT
            SUM(deal_tool_count)
        FROM
            `dl_statistics`
        WHERE
            equipment_code = #{equipmentCode}
          AND behavior = 1;
    </select>
    <select id="selectTotalPriceByEquipmentCode" resultType="java.lang.Float">
        SELECT
            SUM(
                CONVERT (
                    deal_tool_price,
                    DECIMAL (16, 2)
                    )
                )
        FROM
            `dl_statistics`
        WHERE
            equipment_code = #{equipmentCode}
          AND behavior = 1;
    </select>
    <select id="selectTimeDisByMonth" resultType="java.lang.Integer">
        SELECT
	        COUNT(*) count
        FROM
            `dl_statistics`
        <where>
            <if test="month != null">
                DATE_FORMAT(`time`,'%Y-%m') = #{month}
            </if>
        </where>;
    </select>
    <select id="selectTimeDisByDay" resultType="java.lang.Integer">
        SELECT
            COUNT(*) count
        FROM
            `dl_statistics`
        <where>
            <if test="day != null">
                DATE_FORMAT(`time`,'%Y-%m-%d') = #{day}
            </if>
        </where>;
    </select>
    <select id="selectTimeDisByYear" resultType="java.lang.Integer">
        SELECT
            COUNT(*) count
        FROM
            `dl_statistics`
        <where>
            <if test="year != null">
                DATE_FORMAT(`time`,'%Y') = #{year}
            </if>
        </where>;
    </select>
</mapper>
