package com.hai.dao.order;

import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @serviceName OrderStatisticsMapperExt.java
 * @author Sum1Dream
 * @version 1.0.0
 * @Description // 订单统计
 * @createTime 16:11 2022/11/2
 **/
public interface OrderStatisticsMapperExt {

    @Select(value = {
            "<script>",
            "SELECT sum(pay_real_price) as sum," +
            "<choose>" +
            "<when test='dateType == 1'>" +
            " DATE_FORMAT(create_time,  '%Y-%m-%d') as time FROM high_order where  order_status in (2,3) and DATE(create_time) >= DATE_SUB(CURDATE(), INTERVAL #{num} DAY )" +
            "</when>" +
            "<when test='dateType == 3'>" +
            " DATE_FORMAT(create_time,  '%Y-%m') as time FROM high_order where  order_status in (2,3) and DATE(create_time) >= DATE_SUB(CURDATE(), INTERVAL #{num} MONTH )" +
            "</when>" +
            "<when test='dateType == 4'>" +
            " DATE_FORMAT(create_time,  '%Y') as time FROM high_order where  order_status in (2,3) and DATE(create_time) >= DATE_SUB(CURDATE() , INTERVAL #{num} YEAR )" +
            "</when>" +
            "<otherwise>" +
            "</otherwise>" +
            "</choose>" +
            " GROUP BY time" +
            "</script>"
    })
    List<Map<String , Object>> orderStatisticsByYMD(@Param("dateType") Integer dateType, @Param("num") Integer num);

    @Select(value = {
            "<script>",
            "SELECT sum(pay_real_price) as value, product_type as name FROM high_order WHERE " +
            "<choose>" +
            "<when test='dateType == 1'>" +
            " TO_DAYS(create_time) = TO_DAYS(NOW()) " +
            "</when>" +
            "<when test='dateType == 2'>" +
            " YEARWEEK(DATE_FORMAT(create_time,'%Y-%m-%d')) = YEARWEEK(NOW())" +
            "</when>" +
            "<when test='dateType == 3'>" +
            " DATE_FORMAT(create_time,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')" +
            "</when>" +
            "<when test='dateType == 4'>" +
            " YEAR(create_time)=YEAR(NOW())" +
            "</when>" +
            "<otherwise>" +
            "</otherwise>" +
            "</choose>" +
            " and  order_status in (2,3) GROUP BY product_type; " +
            "</script>"
    })
    List<Map<String , Object>> orderStatisticsByProductType(@Param("dateType") Integer dateType);

}
