<?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.ylx.massage.mapper.TJsDayMapper">

    <resultMap type="com.ylx.massage.domain.TJsDay" id="TJsDayMap">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="onLine" column="on_line" jdbcType="INTEGER"/>
        <result property="orderNum" column="order_num" jdbcType="INTEGER"/>
        <result property="turnover" column="turnover" jdbcType="NUMERIC"/>
        <result property="addNum" column="add_num" jdbcType="INTEGER"/>
        <result property="upgradeNum" column="upgrade_num" jdbcType="INTEGER"/>
        <result property="recharge" column="recharge" jdbcType="NUMERIC"/>
        <result property="jsId" column="js_id" jdbcType="VARCHAR"/>
        <result property="openId" column="open_id" jdbcType="VARCHAR"/>
        <result property="countDate" column="count_date" jdbcType="VARCHAR"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="deptId" column="dept_id" jdbcType="VARCHAR"/>
        <result property="deptName" column="dept_name" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="isDelete" column="is_delete" jdbcType="INTEGER"/>
    </resultMap>

    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into
        ry-vue.t_js_day(on_lineorder_numturnoveradd_numupgrade_numrechargejs_idopen_idcount_datenamedept_iddept_namecreate_timeupdate_timeis_delete)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.onLine}#{entity.orderNum}#{entity.turnover}#{entity.addNum}#{entity.upgradeNum}#{entity.recharge}#{entity.jsId}#{entity.openId}#{entity.countDate}#{entity.name}#{entity.deptId}#{entity.deptName}#{entity.createTime}#{entity.updateTime}#{entity.isDelete})
        </foreach>
    </insert>
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into
        ry-vue.t_js_day(on_lineorder_numturnoveradd_numupgrade_numrechargejs_idopen_idcount_datenamedept_iddept_namecreate_timeupdate_timeis_delete)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.onLine}#{entity.orderNum}#{entity.turnover}#{entity.addNum}#{entity.upgradeNum}#{entity.recharge}#{entity.jsId}#{entity.openId}#{entity.countDate}#{entity.name}#{entity.deptId}#{entity.deptName}#{entity.createTime}#{entity.updateTime}#{entity.isDelete})
        </foreach>
        on duplicate key update
        on_line = values(on_line) order_num = values(order_num) turnover = values(turnover) add_num = values(add_num)
        upgrade_num = values(upgrade_num) recharge = values(recharge) js_id = values(js_id) open_id = values(open_id)
        count_date = values(count_date) name = values(name) dept_id = values(dept_id) dept_name = values(dept_name)
        create_time = values(create_time) update_time = values(update_time) is_delete = values(is_delete)
    </insert>

    <select id="selectRanking" resultType="com.ylx.massage.domain.TJsDay">
        SELECT
            js_id jsId,
            open_id openId,
            NAME NAME,
            IFNULL( sum( order_num ), 0 ) orderNum
        FROM
            t_js_day
        WHERE
            is_delete = 0
        AND count_date BETWEEN #{start} AND #{end}
        <if test="deptId != 100 and deptId != '' and deptId != null">
            AND dept_id = #{deptId}
        </if>
        <if test="deptName != null and deptName != ''">
            AND dept_name like concat('%',#{deptName},'%')
        </if>
        GROUP BY
            jsId,
            openId,
            NAME
        ORDER BY
            orderNum DESC
        LIMIT 10
    </select>

    <select id="selectApp" resultType="com.ylx.massage.domain.TJsDay">
        SELECT
        IFNULL( SUM( on_line ), 0 ) AS onLine,
        IFNULL( SUM( order_num ), 0 ) AS orderNum,
        IFNULL( SUM( turnover ), 0 ) AS turnover,
        IFNULL( SUM( add_num ), 0 ) AS addNum,
        IFNULL( SUM( upgrade_num ), 0 ) AS upgradeNum,
        IFNULL( SUM( recharge ), 0 ) AS recharge
        FROM
        t_js_day
        WHERE
        is_delete = 0
        AND open_id = #{openId}
        AND count_date &gt;= #{start}
        AND count_date &lt;= #{end}
    </select>

</mapper>

