//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.luozhihui.project.controller;

import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Controller
@RestController
@RequestMapping({"/api"})
@CrossOrigin
public class GetCountController {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public GetCountController() {
    }

    @PostMapping({"/getcount"})
    @ResponseBody
    public Map<String, Object> getCount() {
        final Map<String, Object> data = new HashMap();

        try {
            Double totalMoney = (Double)this.jdbcTemplate.queryForObject("SELECT SUM(OrderMoney) AS total_money FROM `order` where OrderStatus = 1", Double.class);
            data.put("total_money", totalMoney != null ? totalMoney : 0.0);
            Map<String, Object> orderResult = this.jdbcTemplate.queryForMap("SELECT COUNT(OrderMoney) AS total_orders, SUM(OrderMoney) AS total_moneys FROM `order`");
            data.put("total_orders", orderResult.get("total_orders"));
            data.put("total_moneys", orderResult.get("total_moneys"));
            Map<String, Object> todaySuccessResult = this.jdbcTemplate.queryForMap("SELECT COUNT(OrderMoney) AS today_amount, SUM(OrderMoney) AS today_total_money FROM `order` WHERE InTime >= CURDATE() AND OrderStatus = 1");
            data.put("today_amount", todaySuccessResult.get("today_amount"));
            data.put("today_total_money", todaySuccessResult.get("today_total_money"));
            Map<String, Object> todayFailResult = this.jdbcTemplate.queryForMap("SELECT COUNT(OrderMoney) AS today2_amount , SUM(OrderMoney) AS today2_total_money FROM `order` WHERE InTime >= CURDATE() AND OrderStatus = 0");
            data.put("today2_amount", todayFailResult.get("today2_amount"));
            data.put("today2_total_money", todayFailResult.get("today2_total_money"));
            Map<String, Object> yesterdaySuccessResult = this.jdbcTemplate.queryForMap("SELECT COUNT(OrderMoney) AS yes_amount, SUM(OrderMoney) AS yesday_total_money FROM `order` WHERE InTime >= CURDATE() - INTERVAL 1 DAY AND InTime < CURDATE() AND OrderStatus = 1");
            data.put("yes_amount", yesterdaySuccessResult.get("yes_amount"));
            data.put("yesday_total_money", yesterdaySuccessResult.get("yesday_total_money"));
            Map<String, Object> yesterdayFailResult = this.jdbcTemplate.queryForMap("SELECT COUNT(OrderMoney) AS yes2_amount FROM `order` WHERE InTime >= CURDATE() - INTERVAL 1 DAY AND InTime < CURDATE() AND OrderStatus = 0");
            data.put("yes2_amount", yesterdayFailResult.get("yes2_amount"));
            Double todayTotalDay = (Double)this.jdbcTemplate.queryForObject("SELECT SUM(OrderMoney) AS today_total_day FROM `order` WHERE InTime >= CURDATE() AND OrderStatus = 1 AND Mode = 1", Double.class);
            data.put("today_total_day", todayTotalDay != null ? todayTotalDay : 0.0);
            Double todayTotalHour = (Double)this.jdbcTemplate.queryForObject("SELECT SUM(OrderMoney) AS today_total_hour FROM `order` WHERE InTime >= CURDATE() AND OrderStatus = 1 AND Mode = 0", Double.class);
            data.put("today_total_hour", todayTotalHour != null ? todayTotalHour : 0.0);
            Double totalUser = (Double)this.jdbcTemplate.queryForObject("SELECT COUNT(UserId) AS total_user FROM `user` ", Double.class);
            data.put("total_user", totalUser != null ? totalUser : 0.0);
            Double totalCar = (Double)this.jdbcTemplate.queryForObject("SELECT COUNT(CarId) AS total_car FROM `car` ", Double.class);
            data.put("total_car", totalCar != null ? totalCar : 0.0);
            return new HashMap<String, Object>() {
                {
                    this.put("status", 1);
                    this.put("message", "获取成功！");
                    this.put("data", data);
                }
            };
        } catch (Exception var12) {
            final Exception e = var12;
            e.printStackTrace();
            return new HashMap<String, Object>() {
                {
                    this.put("status", 200);
                    this.put("message", e.getMessage());
                    this.put("data", (Object)null);
                }
            };
        }
    }
}
