package com.fs.his.mapper;

import com.fs.his.dto.DataDTO;
import com.fs.his.dto.inquiryOrderChartDTO;
import com.fs.his.vo.ChartDaVO;
import com.fs.his.vo.ChartDataVO;
import com.fs.his.vo.ChartProdVO;
import com.fs.his.vo.DoctorChartVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface FsDataMapper {


    @Select("SELECT t1.month AS label,\n" +
            "       IFNULL(ROUND(SUM(fs_store_order.pay_money)), 0) AS value,\n" +
            "       COUNT(fs_store_order.order_id) AS info\n" +
            "FROM\n" +
            "  (SELECT DATE_FORMAT(DATE_SUB(NOW(), INTERVAL n MONTH), '%Y-%m') AS month\n" +
            "   FROM (\n" +
            "         SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL\n" +
            "         SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL\n" +
            "         SELECT 10 UNION ALL SELECT 11\n" +
            "        ) AS months) AS t1\n" +
            "  LEFT JOIN (\n" +
            "             SELECT DATE_FORMAT(create_time, '%Y-%m') AS month,\n" +
            "                    pay_money,\n" +
            "                    order_id\n" +
            "             FROM fs_store_order \n" +
            "             WHERE create_time BETWEEN DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 11 MONTH), '%Y-%m-01') AND LAST_DAY(NOW())\n" +
            "\t\t\t\t\t\t AND refund_status=0 \n" +
            "            ) AS fs_store_order ON t1.month = fs_store_order.month\n" +
            "GROUP BY t1.month\n" +
            "ORDER BY t1.month ASC;")
    List<ChartDataVO> getOrderChartData();


    @Select("SELECT t1.month AS label,\n" +
            "       IFNULL(ROUND(SUM(fs_store_order.pay_money)), 0) AS value,\n" +
            "       COUNT(fs_store_order.order_id) AS info\n" +
            "FROM\n" +
            "  (SELECT DATE_FORMAT(DATE_SUB(NOW(), INTERVAL n MONTH), '%Y-%m') AS month\n" +
            "   FROM (\n" +
            "         SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL\n" +
            "         SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL\n" +
            "         SELECT 10 UNION ALL SELECT 11\n" +
            "        ) AS months) AS t1\n" +
            "  LEFT JOIN (\n" +
            "             SELECT DATE_FORMAT(create_time, '%Y-%m') AS month,\n" +
            "                    pay_money,\n" +
            "                    order_id\n" +
            "             FROM fs_store_order \n" +
            "             WHERE create_time BETWEEN DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 11 MONTH), '%Y-%m-01') AND LAST_DAY(NOW()) And store_id =#{storeId}\n" +
            "\t\t\t\t\t\t AND refund_status=0 \n" +
            "            ) AS fs_store_order ON t1.month = fs_store_order.month\n" +
            "GROUP BY t1.month\n" +
            "ORDER BY t1.month ASC;")
    List<ChartDataVO> getStoreOrderChartData(Long storeId);

    @Select("SELECT COUNT(*) FROM fs_store_order WHERE refund_status =0 AND `status`!=0 ")
    Long allOrderNum();

    @Select("SELECT COUNT(*) FROM fs_store_order WHERE refund_status =0 AND `status`!=0  And DATE(create_time) = CURDATE()")
    Long todayOrderNum();

    @Select("SELECT ROUND(SUM(pay_money)) FROM fs_store_order WHERE refund_status =0 AND `status`!=0 ")
    Long allOrderMoney();

    @Select("SELECT CAST(ROUND(COALESCE(SUM(pay_money), 0),0) AS UNSIGNED) AS today_total FROM fs_store_order WHERE DATE(create_time) = CURDATE() and refund_status =0 AND `status`!=0 \n")
    Long todayOrderMoney();


    @Select("SELECT COUNT(*) FROM fs_inquiry_order ")
    Long allInquiryOrderNum();

    @Select("SELECT COUNT(*) AS order_count FROM fs_inquiry_order WHERE DATE(create_time) = CURDATE()")
    Long todayInquiryOrderNum();

    @Select("select COUNT(*) FROM fs_doctor WHERE doctor_type=1")
    Long getDoctor();

    @Select("select COUNT(*) FROM fs_doctor WHERE doctor_type=2")
    Long getMedicinePe();

    @Select("SELECT COUNT(*) FROM fs_patient WHERE is_del=0")
    Long getPatient();

    @Select("SELECT fs_doctor.doctor_name AS name, COUNT(fs_inquiry_order.doctor_id) AS score\n" +
            "FROM fs_inquiry_order\n" +
            "JOIN fs_doctor ON fs_inquiry_order.doctor_id = fs_doctor.doctor_id\n" +
            "GROUP BY fs_doctor.doctor_name\n" +
            "ORDER BY score DESC limit 10")
    List<DoctorChartVO> doctorChartData();

@Select("SELECT fs_doctor.doctor_name AS name, COUNT(fs_inquiry_order.doctor_id) AS score\n" +
        "FROM fs_inquiry_order\n" +
        "JOIN fs_doctor ON fs_inquiry_order.doctor_id = fs_doctor.doctor_id\n" +
        "WHERE YEAR(fs_inquiry_order.create_time) = YEAR(CURRENT_DATE())\n" +
        "GROUP BY fs_doctor.doctor_name\n" +
        "ORDER BY score DESC\n" +
        "LIMIT 10;")
    List<DoctorChartVO> doctorYearData();
@Select("SELECT fs_doctor.doctor_name AS name, COUNT(fs_inquiry_order.doctor_id) AS score\n" +
        "FROM fs_inquiry_order\n" +
        "JOIN fs_doctor ON fs_inquiry_order.doctor_id = fs_doctor.doctor_id\n" +
        "WHERE YEAR(fs_inquiry_order.create_time) = YEAR(CURRENT_DATE())\n" +
        "  AND MONTH(fs_inquiry_order.create_time) = MONTH(CURRENT_DATE())\n" +
        "GROUP BY fs_doctor.doctor_name\n" +
        "ORDER BY score DESC\n" +
        "LIMIT 10;")
    List<DoctorChartVO> doctorMonData();
@Select("SELECT fs_doctor.doctor_name AS name, COUNT(fs_inquiry_order.doctor_id) AS score\n" +
        "FROM fs_inquiry_order\n" +
        "JOIN fs_doctor ON fs_inquiry_order.doctor_id = fs_doctor.doctor_id\n" +
        "WHERE YEARWEEK(fs_inquiry_order.create_time) = YEARWEEK(CURRENT_DATE())\n" +
        "GROUP BY fs_doctor.doctor_name\n" +
        "ORDER BY score DESC\n" +
        "LIMIT 10;")
    List<DoctorChartVO> doctorWeekData();
@Select("SELECT fs_doctor.doctor_name AS name, COUNT(fs_inquiry_order.doctor_id) AS score\n" +
        "FROM fs_inquiry_order\n" +
        "JOIN fs_doctor ON fs_inquiry_order.doctor_id = fs_doctor.doctor_id\n" +
        "WHERE DATE(fs_inquiry_order.create_time) = DATE(CURRENT_DATE())\n" +
        "GROUP BY fs_doctor.doctor_name\n" +
        "ORDER BY score DESC\n" +
        "LIMIT 10;")
    List<DoctorChartVO> doctorDayData();
@Select({"<script> " +
        "SELECT label,value, info FROM (\n" +
        "\n" +
        "SELECT \n" +
        "    t1.hour AS label, \n" +
        "    IFNULL(ROUND(SUM(fs_store_order.pay_money)), 0) AS value, \n" +
        "    COUNT(fs_store_order.order_id) AS info \n" +
        "FROM \n" +
        "    (SELECT DATE_FORMAT(timestamp, '%Y-%m-%d %H') AS hour \n" +
        "     FROM (\n" +
        "           SELECT TIMESTAMP(DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 24 HOUR), '%Y-%m-%d %H')) + INTERVAL n HOUR AS timestamp \n" +
        "           FROM (\n" +
        "                 SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL\n" +
        "                 SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL\n" +
        "                 SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12 UNION ALL SELECT 13 UNION ALL SELECT 14 UNION ALL \n" +
        "                 SELECT 15 UNION ALL SELECT 16 UNION ALL SELECT 17 UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL\n" +
        "                 SELECT 20 UNION ALL SELECT 21 UNION ALL SELECT 22 UNION ALL SELECT 23\n" +
        "                ) AS hours\n" +
        "          ) AS t) AS t1 \n" +
        "    LEFT JOIN \n" +
        "        fs_store_order ON DATE_FORMAT(fs_store_order.create_time, '%Y-%m-%d %H') = t1.hour \n" +
        "WHERE \n" +
        "    fs_store_order.create_time IS NULL \n" +
        "    OR fs_store_order.create_time &lt;  NOW() <if test = 'storeId != null'> and store_id=#{storeId} </if>\n" +

        "GROUP BY \n" +
        "    t1.hour \n" +
        "ORDER BY \n" +
        "    t1.hour ASC) t WHERE DATE_FORMAT(label,'%Y-%m-%d')=DATE_FORMAT(NOW(),'%Y-%m-%d')"+
        "</script>"})
    List<ChartDataVO> getTodaystoreOrderChart(Long storeId);
@Select({"<script> " +"SELECT \n" +
        "    t1.hour AS label, \n" +
        "    IFNULL(ROUND(SUM(fs_store_order.pay_money)), 0) AS value, \n" +
        "    COUNT(fs_store_order.order_id) AS info \n" +
        "FROM \n" +
        "    (SELECT DATE_FORMAT(timestamp, '%Y-%m-%d %H') AS hour \n" +
        "     FROM (\n" +
        "           SELECT TIMESTAMP(DATE_FORMAT(CURDATE() - INTERVAL 1 DAY, '%Y-%m-%d %H')) + INTERVAL n HOUR AS timestamp \n" +
        "           FROM (\n" +
        "                 SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL\n" +
        "                 SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL\n" +
        "                 SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12 UNION ALL SELECT 13 UNION ALL SELECT 14 UNION ALL \n" +
        "                 SELECT 15 UNION ALL SELECT 16 UNION ALL SELECT 17 UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL\n" +
        "                 SELECT 20 UNION ALL SELECT 21 UNION ALL SELECT 22 UNION ALL SELECT 23\n" +
        "                ) AS hours\n" +
        "          ) AS t) AS t1 \n" +
        "    LEFT JOIN \n" +
        "        fs_store_order ON DATE_FORMAT(fs_store_order.create_time, '%Y-%m-%d %H') = t1.hour \n" +
        "WHERE \n" +
        "    fs_store_order.create_time >= CURDATE() - INTERVAL 1 DAY \n" +
        "    AND fs_store_order.create_time &lt; CURDATE() <if test = 'storeId != null'> and store_id=#{storeId} </if>\n" +
        "    OR fs_store_order.create_time IS NULL \n" +
        "GROUP BY \n" +
        "    t1.hour \n" +
        "ORDER BY \n" +
        "    t1.hour ASC "+"</script>"})
    List<ChartDataVO> getYesterdaystoreOrderChart(Long storeId);
    @Select({"<script> " +"SELECT \n" +
            "    DATE_FORMAT(t1.create_time, '%Y-%m-%d') AS label, \n" +
            "    IFNULL(COUNT(fs_store_order.order_id), 0) AS info, \n" +
            "    IFNULL(ROUND(SUM(fs_store_order.pay_money)), 0) AS value\n" +
            "FROM \n" +
            "    (\n" +
            "        SELECT \n" +
            "            DATE_FORMAT(DATE_ADD(NOW(), INTERVAL 2-DAYOFWEEK(NOW()) DAY), '%Y-%m-%d 00:00:00') + INTERVAL t.n DAY AS create_time \n" +
            "        FROM \n" +
            "            (SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6) t\n" +
            "    ) AS t1 \n" +
            "LEFT JOIN \n" +
            "    fs_store_order ON DATE(fs_store_order.create_time) = DATE(t1.create_time) \n" +
            "WHERE \n" +
            "    1=1 <if test = 'storeId != null'> and store_id=#{storeId} </if>" +
            "GROUP BY \n" +
            "    label \n" +
            "ORDER BY \n" +
            "    label ASC\n"
            +"</script>"})
    List<ChartDataVO> getWeekstoreOrderChart(Long storeId);

    @Select({"<script> " +"SELECT \n" +
            "    DATE_FORMAT(t1.create_time, '%Y-%m-%d') AS label, \n" +
            "    IFNULL(COUNT(fs_store_order.order_id), 0) AS info, \n" +
            "    IFNULL(ROUND(SUM(fs_store_order.pay_money)), 0) AS value\n" +
            "FROM \n" +
            "    (\n" +
            "        SELECT \n" +
            "            DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -5-DAYOFWEEK(NOW()) DAY), '%Y-%m-%d 00:00:00') + INTERVAL t.n DAY AS create_time \n" +
            "        FROM \n" +
            "            (SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6) t\n" +
            "    ) AS t1 \n" +
            "LEFT JOIN \n" +
            "    fs_store_order ON DATE(fs_store_order.create_time) = DATE(t1.create_time) \n" +
            "WHERE \n" +
            "    1=1 <if test = 'storeId != null'> and store_id=#{storeId} </if>\n" +
            "GROUP BY \n" +
            "    label \n" +
            "ORDER BY \n" +
            "    label ASC "+"</script>"})
    List<ChartDataVO> getLastWeekstoreOrderChart(Long storeId);
@Select({"<script> " +"SELECT\n" +
        "  DATE_FORMAT(date_table.date, '%Y-%m-%d') AS label,\n" +
        "  IFNULL(ROUND(SUM(fs_store_order.pay_money), 0), 0) AS value,\n" +
        "  IFNULL(COUNT(fs_store_order.order_id), 0) AS info\n" +
        "FROM\n" +
        "  (SELECT \n" +
        "     LAST_DAY(CURDATE() - INTERVAL 1 MONTH) + INTERVAL 1 DAY - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY as date\n" +
        "   FROM \n" +
        "     (SELECT 0 as a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 \n" +
        "      UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7\n" +
        "      UNION ALL SELECT 8 UNION ALL SELECT 9) as a \n" +
        "   CROSS JOIN \n" +
        "     (SELECT 0 as a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 \n" +
        "      UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7\n" +
        "      UNION ALL SELECT 8 UNION ALL SELECT 9) as b \n" +
        "   CROSS JOIN \n" +
        "     (SELECT 0 as a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 \n" +
        "      UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7\n" +
        "      UNION ALL SELECT 8 UNION ALL SELECT 9) as c \n" +
        "   WHERE \n" +
        "     (a.a + (10 * b.a) + (100 * c.a)) &lt;= DAY(LAST_DAY(CURDATE() - INTERVAL 1 MONTH))) date_table\n" +
        "LEFT JOIN \n" +
        "  fs_store_order \n" +
        "ON \n" +
        "  DATE(fs_store_order.create_time) = DATE(date_table.date)\n" +
        "  AND MONTH(fs_store_order.create_time) = MONTH(CURDATE() - INTERVAL 1 MONTH) <if test = 'storeId != null'> and store_id=#{storeId} </if>\n" +
        "GROUP BY \n" +
        "  DATE(date_table.date) ORDER BY label "+"</script>"})
    List<ChartDataVO> getLastMonstoreOrderChart(Long storeId);

@Select({"<script> " +"SELECT\n" +
        "  DATE_FORMAT(date_table.date, '%Y-%m-%d') AS label,\n" +
        "  IFNULL(ROUND(SUM(fs_store_order.pay_money), 0), 0) AS value,\n" +
        "  IFNULL(COUNT(fs_store_order.order_id), 0) AS info\n" +
        "FROM\n" +
        "  (SELECT \n" +
        "     CURDATE() - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY as date\n" +
        "   FROM \n" +
        "     (SELECT 0 as a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 \n" +
        "      UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7\n" +
        "      UNION ALL SELECT 8 UNION ALL SELECT 9) as a \n" +
        "   CROSS JOIN \n" +
        "     (SELECT 0 as a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 \n" +
        "      UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7\n" +
        "      UNION ALL SELECT 8 UNION ALL SELECT 9) as b \n" +
        "   CROSS JOIN \n" +
        "     (SELECT 0 as a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 \n" +
        "      UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7\n" +
        "      UNION ALL SELECT 8 UNION ALL SELECT 9) as c \n" +
        "   WHERE \n" +
        "     (a.a + (10 * b.a) + (100 * c.a)) &lt;= DAY(CURDATE()) - 1) date_table\n" +
        "LEFT JOIN \n" +
        "  fs_store_order \n" +
        "ON \n" +
        "  DATE(fs_store_order.create_time) = DATE(date_table.date)\n" +
        "  AND DATE(fs_store_order.create_time) &lt; CURDATE() <if test = 'storeId != null'> and store_id=#{storeId} </if>\n" +
        "GROUP BY \n" +
        "  DATE(date_table.date) ORDER BY label" +"</script>"})
    List<ChartDataVO> getMonstoreOrderChart(Long storeId);

    @Select({"<script> " +"SELECT label,value,info FROM(\n" +
            "SELECT t1.month AS label,\n" +
            "       IFNULL(ROUND(SUM(fs_store_order.pay_money)), 0) AS value,\n" +
            "       COUNT(fs_store_order.order_id) AS info\n" +
            "FROM\n" +
            "  (SELECT DATE_FORMAT(DATE_SUB(NOW(), INTERVAL n MONTH), '%Y-%m') AS month\n" +
            "   FROM (\n" +
            "         SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL\n" +
            "         SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL\n" +
            "         SELECT 10 UNION ALL SELECT 11\n" +
            "        ) AS months) AS t1\n" +
            "  LEFT JOIN (\n" +
            "             SELECT DATE_FORMAT(create_time, '%Y-%m') AS month,\n" +
            "                    pay_money,\n" +
            "                    order_id\n" +
            "             FROM fs_store_order\n" +
            "             WHERE create_time BETWEEN DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 11 MONTH), '%Y-%m-01') AND LAST_DAY(NOW()) <if test = 'storeId != null'> and store_id=#{storeId} </if>\n" +
            "            ) AS fs_store_order ON t1.month = fs_store_order.month\n" +
            "GROUP BY t1.month\n" +
            "ORDER BY t1.month ASC\n" +
            ")t  WHERE t.label>=DATE_FORMAT(NOW(),'%Y')" +"</script>"})
    List<ChartDataVO> getYearstoreOrderChart(Long storeId);
    @Select({"<script> " +"SELECT t1.month AS label,\n" +
            "       IFNULL(ROUND(SUM(fs_store_order.pay_money)), 0) AS value,\n" +
            "       COUNT(fs_store_order.order_id) AS info\n" +
            "FROM\n" +
            "  (SELECT DATE_FORMAT(DATE_SUB(DATE_SUB(DATE_FORMAT(NOW(), '%Y-%01-01'), INTERVAL 1 DAY), INTERVAL n MONTH), '%Y-%m') AS month\n" +
            "   FROM (\n" +
            "         SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL\n" +
            "         SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL\n" +
            "         SELECT 10 UNION ALL SELECT 11\n" +
            "        ) AS months) AS t1\n" +
            "  LEFT JOIN (\n" +
            "             SELECT DATE_FORMAT(create_time, '%Y-%m') AS month,\n" +
            "                    pay_money,\n" +
            "                    order_id\n" +
            "             FROM fs_store_order\n" +
            "              <if test = 'storeId != null'> where store_id=#{storeId} </if>" +
            "            ) AS fs_store_order ON t1.month = fs_store_order.month\n" +
            "GROUP BY t1.month\n" +
            "ORDER BY t1.month ASC" +"</script>"})
    List<ChartDataVO> getLastYearstoreOrderChart(Long storeId);




    @Select({"<script> " +
            "SELECT label,value, info FROM (\n" +
            "\n" +
            "SELECT \n" +
            "    t1.hour AS label, \n" +
            "    IFNULL(ROUND(SUM(fs_inquiry_order.pay_money)), 0) AS info, \n" +
            "    COUNT(fs_inquiry_order.order_id) AS value \n" +
            "FROM \n" +
            "    (SELECT DATE_FORMAT(timestamp, '%Y-%m-%d %H') AS hour \n" +
            "     FROM (\n" +
            "           SELECT TIMESTAMP(DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 24 HOUR), '%Y-%m-%d %H')) + INTERVAL n HOUR AS timestamp \n" +
            "           FROM (\n" +
            "                 SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL\n" +
            "                 SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL\n" +
            "                 SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12 UNION ALL SELECT 13 UNION ALL SELECT 14 UNION ALL \n" +
            "                 SELECT 15 UNION ALL SELECT 16 UNION ALL SELECT 17 UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL\n" +
            "                 SELECT 20 UNION ALL SELECT 21 UNION ALL SELECT 22 UNION ALL SELECT 23\n" +
            "                ) AS hours\n" +
            "          ) AS t) AS t1 \n" +
            "    LEFT JOIN \n" +
            "        fs_inquiry_order ON DATE_FORMAT(fs_inquiry_order.create_time, '%Y-%m-%d %H') = t1.hour and status>0 \n" +
            "WHERE \n" +
            "    fs_inquiry_order.create_time IS NULL \n" +
            "    OR fs_inquiry_order.create_time &lt;  NOW() <if test = 'doctorId != null'> and doctor_id=#{doctorId} </if>\n " +

            "GROUP BY \n" +
            "    t1.hour \n" +
            "ORDER BY \n" +
            "    t1.hour ASC) t WHERE DATE_FORMAT(label,'%Y-%m-%d')=DATE_FORMAT(NOW(),'%Y-%m-%d')"+
            "</script>"})
    List<ChartDataVO> getTodayinquiryOrderChart(Long doctorId);
    @Select({"<script> " +"SELECT \n" +
            "    t1.hour AS label, \n" +
            "    IFNULL(ROUND(SUM(fs_inquiry_order.pay_money)), 0) AS info, \n" +
            "    COUNT(fs_inquiry_order.order_id) AS value \n" +
            "FROM \n" +
            "    (SELECT DATE_FORMAT(timestamp, '%Y-%m-%d %H') AS hour \n" +
            "     FROM (\n" +
            "           SELECT TIMESTAMP(DATE_FORMAT(CURDATE() - INTERVAL 1 DAY, '%Y-%m-%d %H')) + INTERVAL n HOUR AS timestamp \n" +
            "           FROM (\n" +
            "                 SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL\n" +
            "                 SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL\n" +
            "                 SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12 UNION ALL SELECT 13 UNION ALL SELECT 14 UNION ALL \n" +
            "                 SELECT 15 UNION ALL SELECT 16 UNION ALL SELECT 17 UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL\n" +
            "                 SELECT 20 UNION ALL SELECT 21 UNION ALL SELECT 22 UNION ALL SELECT 23\n" +
            "                ) AS hours\n" +
            "          ) AS t) AS t1 \n" +
            "    LEFT JOIN \n" +
            "        fs_inquiry_order ON DATE_FORMAT(fs_inquiry_order.create_time, '%Y-%m-%d %H') = t1.hour \n" +
            "WHERE \n" +
            "    fs_inquiry_order.create_time >= CURDATE() - INTERVAL 1 DAY \n" +
            "    AND fs_inquiry_order.create_time &lt; CURDATE() <if test = 'doctorId != null'> and doctor_id=#{doctorId} </if>\n" +
            "    OR fs_inquiry_order.create_time IS NULL \n" +
            "GROUP BY \n" +
            "    t1.hour \n" +
            "ORDER BY \n" +
            "    t1.hour ASC "+"</script>"})
    List<ChartDataVO> getYesterdayinquiryOrderChart(Long doctorId);
    @Select({"<script> " +"SELECT \n" +
            "    DATE_FORMAT(t1.create_time, '%Y-%m-%d') AS label, \n" +
            "    IFNULL(COUNT(fs_inquiry_order.order_id), 0) AS value, \n" +
            "    IFNULL(ROUND(SUM(fs_inquiry_order.pay_money)), 0) AS info\n" +
            "FROM \n" +
            "    (\n" +
            "        SELECT \n" +
            "            DATE_FORMAT(DATE_ADD(NOW(), INTERVAL 2-DAYOFWEEK(NOW()) DAY), '%Y-%m-%d 00:00:00') + INTERVAL t.n DAY AS create_time \n" +
            "        FROM \n" +
            "            (SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6) t\n" +
            "    ) AS t1 \n" +
            "LEFT JOIN \n" +
            "    fs_inquiry_order ON DATE(fs_inquiry_order.create_time) = DATE(t1.create_time) \n" +
            "WHERE \n" +
            "    1=1 <if test = 'doctorId != null'> and doctor_id=#{doctorId} </if>" +
            "GROUP BY \n" +
            "    label \n" +
            "ORDER BY \n" +
            "    label ASC\n"
            +"</script>"})
    List<ChartDataVO> getWeekinquiryOrderChart(Long doctorId);

    @Select({"<script> " +"SELECT \n" +
            "    DATE_FORMAT(t1.create_time, '%Y-%m-%d') AS label, \n" +
            "    IFNULL(COUNT(fs_inquiry_order.order_id), 0) AS value, \n" +
            "    IFNULL(ROUND(SUM(fs_inquiry_order.pay_money)), 0) AS info\n" +
            "FROM \n" +
            "    (\n" +
            "        SELECT \n" +
            "            DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -5-DAYOFWEEK(NOW()) DAY), '%Y-%m-%d 00:00:00') + INTERVAL t.n DAY AS create_time \n" +
            "        FROM \n" +
            "            (SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6) t\n" +
            "    ) AS t1 \n" +
            "LEFT JOIN \n" +
            "    fs_inquiry_order ON DATE(fs_inquiry_order.create_time) = DATE(t1.create_time) \n" +
            "WHERE \n" +
            "    1=1 <if test = 'doctorId != null'> and doctor_id=#{doctorId} </if>\n" +
            "GROUP BY \n" +
            "    label \n" +
            "ORDER BY \n" +
            "    label ASC "+"</script>"})
    List<ChartDataVO> getLastWeekinquiryOrderChart(Long doctorId);
    @Select({"<script> " +"SELECT\n" +
            "  DATE_FORMAT(date_table.date, '%Y-%m-%d') AS label,\n" +
            "  IFNULL(ROUND(SUM(fs_inquiry_order.pay_money), 0), 0) AS info,\n" +
            "  IFNULL(COUNT(fs_inquiry_order.order_id), 0) AS value\n" +
            "FROM\n" +
            "  (SELECT \n" +
            "     LAST_DAY(CURDATE() - INTERVAL 1 MONTH) + INTERVAL 1 DAY - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY as date\n" +
            "   FROM \n" +
            "     (SELECT 0 as a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 \n" +
            "      UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7\n" +
            "      UNION ALL SELECT 8 UNION ALL SELECT 9) as a \n" +
            "   CROSS JOIN \n" +
            "     (SELECT 0 as a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 \n" +
            "      UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7\n" +
            "      UNION ALL SELECT 8 UNION ALL SELECT 9) as b \n" +
            "   CROSS JOIN \n" +
            "     (SELECT 0 as a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 \n" +
            "      UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7\n" +
            "      UNION ALL SELECT 8 UNION ALL SELECT 9) as c \n" +
            "   WHERE \n" +
            "     (a.a + (10 * b.a) + (100 * c.a)) &lt;= DAY(LAST_DAY(CURDATE() - INTERVAL 1 MONTH))) date_table\n" +
            "LEFT JOIN \n" +
            "  fs_inquiry_order \n" +
            "ON \n" +
            "  DATE(fs_inquiry_order.create_time) = DATE(date_table.date)\n" +
            "  AND MONTH(fs_inquiry_order.create_time) = MONTH(CURDATE() - INTERVAL 1 MONTH) <if test = 'doctorId != null'> and doctor_id=#{doctorId} </if>\n" +
            "GROUP BY \n" +
            "  DATE(date_table.date) ORDER BY label "+"</script>"})
    List<ChartDataVO> getLastMoninquiryOrderChart(Long doctorId);
    @Select({"<script> " +"SELECT\n" +
            "  DATE_FORMAT(date_table.date, '%Y-%m-%d') AS label,\n" +
            "  IFNULL(ROUND(SUM(fs_inquiry_order.pay_money), 0), 0) AS info,\n" +
            "  IFNULL(COUNT(fs_inquiry_order.order_id), 0) AS value\n" +
            "FROM\n" +
            "  (SELECT \n" +
            "     CURDATE() - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY as date\n" +
            "   FROM \n" +
            "     (SELECT 0 as a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 \n" +
            "      UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7\n" +
            "      UNION ALL SELECT 8 UNION ALL SELECT 9) as a \n" +
            "   CROSS JOIN \n" +
            "     (SELECT 0 as a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 \n" +
            "      UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7\n" +
            "      UNION ALL SELECT 8 UNION ALL SELECT 9) as b \n" +
            "   CROSS JOIN \n" +
            "     (SELECT 0 as a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 \n" +
            "      UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7\n" +
            "      UNION ALL SELECT 8 UNION ALL SELECT 9) as c \n" +
            "   WHERE \n" +
            "     (a.a + (10 * b.a) + (100 * c.a)) &lt;= DAY(CURDATE()) - 1) date_table\n" +
            "LEFT JOIN \n" +
            "  fs_inquiry_order \n" +
            "ON \n" +
            "  DATE(fs_inquiry_order.create_time) = DATE(date_table.date)\n" +
            "  AND DATE(fs_inquiry_order.create_time) &lt; CURDATE() <if test = 'doctorId != null'> and doctor_id=#{doctorId} </if>\n" +
            "GROUP BY \n" +
            "  DATE(date_table.date) ORDER BY label" +"</script>"})
    List<ChartDataVO> getMoninquiryOrderChart(Long doctorId);
    @Select({"<script> " +"SELECT label,value,info FROM(\n" +
            "SELECT t1.month AS label,\n" +
            "       IFNULL(ROUND(SUM(fs_inquiry_order.pay_money)), 0) AS info,\n" +
            "       COUNT(fs_inquiry_order.order_id) AS value\n" +
            "FROM\n" +
            "  (SELECT DATE_FORMAT(DATE_SUB(NOW(), INTERVAL n MONTH), '%Y-%m') AS month\n" +
            "   FROM (\n" +
            "         SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL\n" +
            "         SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL\n" +
            "         SELECT 10 UNION ALL SELECT 11\n" +
            "        ) AS months) AS t1\n" +
            "  LEFT JOIN (\n" +
            "             SELECT DATE_FORMAT(create_time, '%Y-%m') AS month,\n" +
            "                    pay_money,\n" +
            "                    order_id\n" +
            "             FROM fs_inquiry_order\n" +
            "             WHERE create_time BETWEEN DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 11 MONTH), '%Y-%m-01') AND LAST_DAY(NOW()) and `status`>0 <if test = 'doctorId != null'> and doctor_id=#{doctorId} </if>\n" +
            "            ) AS fs_inquiry_order ON t1.month = fs_inquiry_order.month\n" +
            "GROUP BY t1.month\n" +
            "ORDER BY t1.month ASC\n" +
            ")t  WHERE t.label>=DATE_FORMAT(NOW(),'%Y')" +"</script>"})
    List<ChartDataVO> getYearinquiryOrderChart(Long doctorId);
    @Select({"<script> " +"SELECT t1.month AS label,\n" +
            "       IFNULL(ROUND(SUM(fs_inquiry_order.pay_money)), 0) AS info,\n" +
            "       COUNT(fs_inquiry_order.order_id) AS value\n" +
            "FROM\n" +
            "  (SELECT DATE_FORMAT(DATE_SUB(DATE_SUB(DATE_FORMAT(NOW(), '%Y-%01-01'), INTERVAL 1 DAY), INTERVAL n MONTH), '%Y-%m') AS month\n" +
            "   FROM (\n" +
            "         SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL\n" +
            "         SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL\n" +
            "         SELECT 10 UNION ALL SELECT 11\n" +
            "        ) AS months) AS t1\n" +
            "  LEFT JOIN (\n" +
            "             SELECT DATE_FORMAT(create_time, '%Y-%m') AS month,\n" +
            "                    pay_money,\n" +
            "                    order_id\n" +
            "             FROM fs_inquiry_order\n" +
            "              <if test = 'doctorId != null'> where doctor_id=#{doctorId} </if>" +
            "            ) AS fs_inquiry_order ON t1.month = fs_inquiry_order.month\n" +
            "GROUP BY t1.month\n" +
            "ORDER BY t1.month ASC" +"</script>"})
    List<ChartDataVO> getLastYearinquiryOrderChart(Long doctorId);

    @Select({"<script> " +"SELECT label,value,info FROM(\n" +
            "SELECT t1.month AS label,\n" +
            "       IFNULL(ROUND(SUM(fs_store_order.pay_money)), 0) AS value,\n" +
            "       COUNT(fs_store_order.order_id) AS info\n" +
            "FROM\n" +
            "  (SELECT DATE_FORMAT(DATE_SUB(NOW(), INTERVAL n MONTH), '%Y-%m') AS month\n" +
            "   FROM (\n" +
            "         SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL\n" +
            "         SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL\n" +
            "         SELECT 10 UNION ALL SELECT 11\n" +
            "        ) AS months) AS t1\n" +
            "  LEFT JOIN (\n" +
            "             SELECT DATE_FORMAT(create_time, '%Y-%m') AS month,\n" +
            "                    pay_money,\n" +
            "                    order_id\n" +
            "             FROM fs_store_order\n" +
            "             WHERE create_time BETWEEN DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 11 MONTH), '%Y-%m-01') AND LAST_DAY(NOW()) <if test = 'storeId != null'> and store_id=#{storeId} </if>\n" +
            "            ) AS fs_store_order ON t1.month = fs_store_order.month\n" +
            "GROUP BY t1.month\n" +
            "ORDER BY t1.month ASC\n" +
            ")t  WHERE t.label>=DATE_FORMAT(NOW(),'%Y') and QUARTER(CONCAT(t.label,\"-01\"))=QUARTER(NOW())" +"</script>"})
    List<ChartDataVO> getquarterstoreOrderChart(Long storeId);
    @Select({"<script> " +"SELECT label,value,info FROM(\n" +
            "SELECT t1.month AS label,\n" +
            "       IFNULL(ROUND(SUM(fs_store_order.pay_money)), 0) AS value,\n" +
            "       COUNT(fs_store_order.order_id) AS info\n" +
            "FROM\n" +
            "  (SELECT DATE_FORMAT(DATE_SUB(NOW(), INTERVAL n MONTH), '%Y-%m') AS month\n" +
            "   FROM (\n" +
            "         SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL\n" +
            "         SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL\n" +
            "         SELECT 10 UNION ALL SELECT 11\n" +
            "        ) AS months) AS t1\n" +
            "  LEFT JOIN (\n" +
            "             SELECT DATE_FORMAT(create_time, '%Y-%m') AS month,\n" +
            "                    pay_money,\n" +
            "                    order_id\n" +
            "             FROM fs_store_order\n" +
            "             WHERE create_time BETWEEN DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 11 MONTH), '%Y-%m-01') AND LAST_DAY(NOW()) <if test = 'storeId != null'> and store_id=#{storeId} </if>\n" +
            "            ) AS fs_store_order ON t1.month = fs_store_order.month\n" +
            "GROUP BY t1.month\n" +
            "ORDER BY t1.month ASC\n" +
            ")t  WHERE t.label>=DATE_FORMAT(NOW(),'%Y') and QUARTER(CONCAT(t.label,\"-01\"))=QUARTER(NOW())-1" +"</script>"})
    List<ChartDataVO> getLastquarterstoreOrderChart(Long storeId);

    @Select({"<script> " +"SELECT label,value,info FROM(\n" +
            "SELECT t1.month AS label,\n" +
            "       IFNULL(ROUND(SUM(fs_inquiry_order.pay_money)), 0) AS info,\n" +
            "       COUNT(fs_inquiry_order.order_id) AS value\n" +
            "FROM\n" +
            "  (SELECT DATE_FORMAT(DATE_SUB(NOW(), INTERVAL n MONTH), '%Y-%m') AS month\n" +
            "   FROM (\n" +
            "         SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL\n" +
            "         SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL\n" +
            "         SELECT 10 UNION ALL SELECT 11\n" +
            "        ) AS months) AS t1\n" +
            "  LEFT JOIN (\n" +
            "             SELECT DATE_FORMAT(create_time, '%Y-%m') AS month,\n" +
            "                    pay_money,\n" +
            "                    order_id\n" +
            "             FROM fs_inquiry_order\n" +
            "             WHERE create_time BETWEEN DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 11 MONTH), '%Y-%m-01') AND LAST_DAY(NOW()) <if test = 'doctorId != null'> and doctor_id=#{doctorId} </if>\n" +
            "            ) AS fs_inquiry_order ON t1.month = fs_inquiry_order.month\n" +
            "GROUP BY t1.month\n" +
            "ORDER BY t1.month ASC\n" +
            ")t  WHERE t.label>=DATE_FORMAT(NOW(),'%Y') and QUARTER(CONCAT(t.label,\"-01\"))=QUARTER(NOW())-1" +"</script>"})
    List<ChartDataVO> getLastquarterinquiryOrderChart(Long doctorId);

    @Select({"<script> " +"SELECT label,value,info FROM(\n" +
            "SELECT t1.month AS label,\n" +
            "       IFNULL(ROUND(SUM(fs_inquiry_order.pay_money)), 0) AS info,\n" +
            "       COUNT(fs_inquiry_order.order_id) AS value\n" +
            "FROM\n" +
            "  (SELECT DATE_FORMAT(DATE_SUB(NOW(), INTERVAL n MONTH), '%Y-%m') AS month\n" +
            "   FROM (\n" +
            "         SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL\n" +
            "         SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL\n" +
            "         SELECT 10 UNION ALL SELECT 11\n" +
            "        ) AS months) AS t1\n" +
            "  LEFT JOIN (\n" +
            "             SELECT DATE_FORMAT(create_time, '%Y-%m') AS month,\n" +
            "                    pay_money,\n" +
            "                    order_id\n" +
            "             FROM fs_inquiry_order\n" +
            "             WHERE create_time BETWEEN DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 11 MONTH), '%Y-%m-01') AND LAST_DAY(NOW()) <if test = 'doctorId != null'> and doctor_id=#{doctorId} </if>\n" +
            "            ) AS fs_inquiry_order ON t1.month = fs_inquiry_order.month\n" +
            "GROUP BY t1.month\n" +
            "ORDER BY t1.month ASC\n" +
            ")t  WHERE t.label>=DATE_FORMAT(NOW(),'%Y') and QUARTER(CONCAT(t.label,\"-01\"))=QUARTER(NOW())" +"</script>"})
    List<ChartDataVO> getquarterinquiryOrderChart(Long doctorId);

    @Select({"<script> " +"SELECT t1.month AS label,\n" +
            "       IFNULL(ROUND(SUM(fs_store_order.pay_money)), 0) AS value,\n" +
            "       COUNT(fs_store_order.order_id) AS info\n" +
            "FROM\n" +
            "  (SELECT DATE_FORMAT(DATE_SUB(NOW(), INTERVAL n MONTH), '%Y-%m') AS month\n" +
            "   FROM (\n" +
            "         SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL\n" +
            "         SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL\n" +
            "         SELECT 10 UNION ALL SELECT 11\n" +
            "        ) AS months) AS t1\n" +
            "  LEFT JOIN (\n" +
            "             SELECT DATE_FORMAT(create_time, '%Y-%m') AS month,\n" +
            "                    pay_money,\n" +
            "                    order_id\n" +
            "             FROM fs_store_order \n" +
            "             WHERE create_time BETWEEN DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 11 MONTH), '%Y-%m-01') AND LAST_DAY(NOW())\n" +
            "\t\t\t\t\t\t AND refund_status=0 <if test = 'storeId != null'> and store_id=#{storeId} </if>\n" +
            "            ) AS fs_store_order ON t1.month = fs_store_order.month\n" +
            "GROUP BY t1.month\n" +
            "ORDER BY t1.month ASC;" +"</script>"})
    List<ChartDataVO> getOrderChartstoreIdData(Long storeId);
    @Select({"<script> " +
            "SELECT COUNT(o.order_id) count,SUM(o.pay_money) money,fs.store_name name FROM fs_store_order o LEFT JOIN  fs_store fs ON o.store_id =fs.store_id   WHERE 1=1 " +
            "<if test = 'maps.storeId != null'> " +
            "and o.store_id = #{maps.storeId} " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==1 '> " +
            "and TO_DAYS(o.create_time) = TO_DAYS(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==2 '> " +
            "and TO_DAYS(NOW()) - TO_DAYS(o.create_time) &lt;= 1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==3 '> " +
            "and YEARWEEK(DATE_FORMAT(o.create_time,'%Y-%m-%d')) = YEARWEEK(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==4 '> " +
            "and YEARWEEK(DATE_FORMAT(o.create_time,'%Y-%m-%d')) = YEARWEEK(NOW())-1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==5 '> " +
            "and DATE_FORMAT(o.create_time,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m') " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==6 '> " +
            "and PERIOD_DIFF(DATE_FORMAT(NOW(),'%Y%m'),DATE_FORMAT(o.create_time,'%Y%m')) = 1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==7 '> " +
            "and QUARTER(o.create_time) = QUARTER(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==8 '> " +
            "and QUARTER(o.create_time) = QUARTER(DATE_SUB(NOW(),INTERVAL 1 QUARTER)) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==9 '> " +
            "and YEAR(o.create_time)=YEAR(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==10 '> " +
            "and  YEAR(o.create_time) = YEAR(DATE_SUB(NOW(),INTERVAL 1 YEAR))" +
            "</if>" +
            "GROUP BY o.store_id"+
            "</script>"})
    List<ChartDaVO> getStoreDate(@Param("maps") DataDTO dto);
    @Select({"<script> " +
            "SELECT COUNT(o.order_id) count,SUM(o.pay_money) money,d.doctor_name name FROM fs_inquiry_order o LEFT JOIN fs_doctor d ON d.doctor_id = o.doctor_id   WHERE o.status>0 " +
            "<if test = 'maps.doctorId != null'> " +
            "and o.doctor_id = #{maps.doctorId} " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==1 '> " +
            "and TO_DAYS(o.create_time) = TO_DAYS(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==2 '> " +
            "and TO_DAYS(NOW()) - TO_DAYS(o.create_time) &lt;= 1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==3 '> " +
            "and YEARWEEK(DATE_FORMAT(o.create_time,'%Y-%m-%d')) = YEARWEEK(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==4 '> " +
            "and YEARWEEK(DATE_FORMAT(o.create_time,'%Y-%m-%d')) = YEARWEEK(NOW())-1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==5 '> " +
            "and DATE_FORMAT(o.create_time,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m') " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==6 '> " +
            "and PERIOD_DIFF(DATE_FORMAT(NOW(),'%Y%m'),DATE_FORMAT(o.create_time,'%Y%m')) = 1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==7 '> " +
            "and QUARTER(o.create_time) = QUARTER(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==8 '> " +
            "and QUARTER(o.create_time) = QUARTER(DATE_SUB(NOW(),INTERVAL 1 QUARTER)) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==9 '> " +
            "and YEAR(o.create_time)=YEAR(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==10 '> " +
            "and  YEAR(o.create_time) = YEAR(DATE_SUB(NOW(),INTERVAL 1 YEAR))" +
            "</if>" +
            "GROUP BY o.doctor_id"+
            "</script>"})
    List<ChartDaVO> getInquiryOrderChartInq(@Param("maps") inquiryOrderChartDTO dto);



    @Select({"<script> " +
            "SELECT ANY_VALUE(x.product_id) product_id,SUM(x.num) num, ANY_VALUE(p.product_name) product_name,ANY_VALUE(p.price) price,ANY_VALUE(p.bar_code) as barCode FROM fs_store_order_item x LEFT JOIN fs_store_product p ON p.product_id=x.product_id WHERE order_id IN (SELECT order_id FROM fs_store_order WHERE `status`>1 " +
            "<if test = 'maps.storeId != null'> " +
            "and store_id = #{maps.storeId} " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==1 '> " +
            "and TO_DAYS(create_time) = TO_DAYS(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==2 '> " +
            "and TO_DAYS(NOW()) - TO_DAYS(create_time) &lt;= 1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==3 '> " +
            "and YEARWEEK(DATE_FORMAT(create_time,'%Y-%m-%d')) = YEARWEEK(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==4 '> " +
            "and YEARWEEK(DATE_FORMAT(create_time,'%Y-%m-%d')) = YEARWEEK(NOW())-1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==5 '> " +
            "and DATE_FORMAT(create_time,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m') " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==6 '> " +
            "and PERIOD_DIFF(DATE_FORMAT(NOW(),'%Y%m'),DATE_FORMAT(create_time,'%Y%m')) = 1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==7 '> " +
            "and QUARTER(create_time) = QUARTER(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==8 '> " +
            "and QUARTER(create_time) = QUARTER(DATE_SUB(NOW(),INTERVAL 1 QUARTER)) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==9 '> " +
            "and YEAR(create_time)=YEAR(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==10 '> " +
            "and  YEAR(create_time) = YEAR(DATE_SUB(NOW(),INTERVAL 1 YEAR))" +
            "</if>" +
            ") \n" +
            "GROUP BY x.product_id  ORDER BY num desc"+
            "</script>"})
    List<ChartProdVO> ChartProdVO(@Param("maps") DataDTO dto);


    @Select("select COUNT(product_id) FROM fs_store_product WHERE store_id=#{id}")
    Long getStore(Long id);
    @Select("select COUNT(product_id) FROM fs_store_product WHERE store_id=#{id} AND is_show=0")
    Long getAStore(Long id);
    @Select("select COUNT(order_id) FROM fs_store_order WHERE store_id=#{id} AND `status`!=-3 AND `status`!=-2")
    Long getOrder(Long id);
    @Select("select SUM(sales) FROM fs_store_product WHERE store_id=#{id}")
    Long getYsStore(Long id);
    @Select("select COUNT(order_id) FROM fs_store_order WHERE store_id=#{id} AND `status`=1")
    Long getSendStore(Long id);
    @Select("select COUNT(order_id) FROM fs_store_order WHERE store_id=#{id} AND `status`=2")
    Long getGetStore(Long id);
    @Select({"<script> " +
            "SELECT SUM(x.num) score,ANY_VALUE(p.product_name) name FROM fs_store_order_item x LEFT JOIN fs_store_product p ON p.product_id=x.product_id WHERE order_id IN (SELECT order_id FROM fs_store_order WHERE 1=1 " +
            "<if test = 'storeId != null'> " +
            "and store_id = #{storeId} " +
            "</if>" +
            "<if test = 'type != null and type ==1 '> " +
            "and TO_DAYS(create_time) = TO_DAYS(NOW()) " +
            "</if>" +
            "<if test = 'type != null and type ==2 '> " +
            "and TO_DAYS(NOW()) - TO_DAYS(create_time) &lt;= 1 " +
            "</if>" +
            "<if test = 'type != null and type ==3 '> " +
            "and YEARWEEK(DATE_FORMAT(create_time,'%Y-%m-%d')) = YEARWEEK(NOW()) " +
            "</if>" +
            "<if test = 'type != null and type ==4 '> " +
            "and YEARWEEK(DATE_FORMAT(create_time,'%Y-%m-%d')) = YEARWEEK(NOW())-1 " +
            "</if>" +
            "<if test = 'type != null and type ==5 '> " +
            "and DATE_FORMAT(create_time,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m') " +
            "</if>" +
            "<if test = 'type != null and type ==6 '> " +
            "and PERIOD_DIFF(DATE_FORMAT(NOW(),'%Y%m'),DATE_FORMAT(create_time,'%Y%m')) = 1 " +
            "</if>" +
            "<if test = 'type != null and type ==7 '> " +
            "and QUARTER(create_time) = QUARTER(NOW()) " +
            "</if>" +
            "<if test = 'type != null and type ==8 '> " +
            "and QUARTER(create_time) = QUARTER(DATE_SUB(NOW(),INTERVAL 1 QUARTER)) " +
            "</if>" +
            "<if test = 'type != null and type ==9 '> " +
            "and YEAR(create_time)=YEAR(NOW()) " +
            "</if>" +
            "<if test = 'type != null and type ==10 '> " +
            "and  YEAR(create_time) = YEAR(DATE_SUB(NOW(),INTERVAL 1 YEAR))" +
            "</if>" +
            ") \n" +
            "GROUP BY x.product_id  ORDER BY score desc limit 10"+
            "</script>"})
    List<DoctorChartVO> ChartStoreProdVo(@Param("type") Integer type, @Param("storeId") Long storeId);
    @Select("SELECT COUNT(user_id) FROM fs_user")
    Long getUserNum();
    @Select("SELECT COUNT(user_id) FROM fs_user WHERE DATE(create_time) = CURDATE()")
    Long getTodayUserNum();

    @Select("SELECT t1.month AS label,\n" +
            "                   IFNULL(ROUND(SUM(fs_inquiry_order.pay_money)), 0) AS value,\n" +
            "                   COUNT(fs_inquiry_order.order_id) AS info\n" +
            "            FROM\n" +
            "              (SELECT DATE_FORMAT(DATE_SUB(NOW(), INTERVAL n MONTH), '%Y-%m') AS month\n" +
            "               FROM (\n" +
            "                     SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL\n" +
            "                     SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL\n" +
            "                     SELECT 10 UNION ALL SELECT 11\n" +
            "                    ) AS months) AS t1\n" +
            "              LEFT JOIN (\n" +
            "                         SELECT DATE_FORMAT(create_time, '%Y-%m') AS month,\n" +
            "                                pay_money,\n" +
            "                              order_id\n" +
            "                        FROM fs_inquiry_order \n" +
            "                        WHERE create_time BETWEEN DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 11 MONTH), '%Y-%m-01') AND LAST_DAY(NOW())\n" +
            "            AND `status`>0\n" +
            "                        ) AS fs_inquiry_order ON t1.month = fs_inquiry_order.month\n" +
            "            GROUP BY t1.month\n" +
            "            ORDER BY t1.month ASC;")
    List<ChartDataVO> getInquiryOrderChartData();
    @Select("select COUNT(*) FROM fs_doctor WHERE doctor_type=1 and DATE(create_time) = CURDATE()")
    Long getTodayDoctor();
    @Select("select COUNT(*) FROM fs_doctor WHERE doctor_type=2 and DATE(create_time) = CURDATE()")
    Long getTodayMedicinePe();
    @Select("select COUNT(*) FROM fs_store_product")
    Long getStoreProdNum();
    @Select("select COUNT(*) FROM fs_store_product WHERE  DATE(create_time) = CURDATE()")
    Long getTodayStoreProdNum();

    @Select("SELECT t1.month AS label,\n" +
            "                   IFNULL(ROUND(SUM(fs_inquiry_order.pay_money)), 0) AS value,\n" +
            "                   COUNT(fs_inquiry_order.order_id) AS info\n" +
            "            FROM\n" +
            "              (SELECT DATE_FORMAT(DATE_SUB(NOW(), INTERVAL n MONTH), '%Y-%m') AS month\n" +
            "               FROM (\n" +
            "                     SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL\n" +
            "                     SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL\n" +
            "                     SELECT 10 UNION ALL SELECT 11\n" +
            "                    ) AS months) AS t1\n" +
            "              LEFT JOIN (\n" +
            "                         SELECT DATE_FORMAT(create_time, '%Y-%m') AS month,\n" +
            "                                pay_money,\n" +
            "                              order_id\n" +
            "                        FROM fs_inquiry_order \n" +
            "                        WHERE create_time BETWEEN DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 11 MONTH), '%Y-%m-01') AND LAST_DAY(NOW())\n" +
            "            AND `status`>0 \n" +
            "            AND doctor_id=#{doctorId} \n" +
            "                        ) AS fs_inquiry_order ON t1.month = fs_inquiry_order.month\n" +
            "            GROUP BY t1.month\n" +
            "            ORDER BY t1.month ASC;")
    List<ChartDataVO> getDoctorInquiryOrderChartData(Long doctorId);

    @Select("select COUNT(*) FROM fs_inquiry_order WHERE doctor_id=#{doctorId} and   `status`>0  and   DATE(create_time) = CURDATE()")
    Long getDoctorInquiryCount(Long doctorId);
}
