package com.ruoyi.dk.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.dk.domain.Borrow;
import com.ruoyi.dk.domain.Customer;
import com.ruoyi.dk.service.BorrowService;
import com.ruoyi.dk.service.CustomerService;
import com.ruoyi.component.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/dk/home")
public class HomeController {

    @Autowired
    private CustomerService customerService;
    @Autowired
    private BorrowService borrowService;

    @GetMapping("/index")
    public R<Map<String,Long>> index() {
        Map<String,Long> map = new HashMap<>();
        LocalDate now = LocalDate.now();
        // 今日注册， 总注册
        long todayRegister = customerService.count(Wrappers.lambdaQuery(Customer.class).between(Customer::getCreateTime,
                now.atTime(LocalTime.MIN), now.atTime(LocalTime.MAX)));
        long totalRegister = customerService.count();
        // 今日订单， 总订单
        long todayBorrow = borrowService.count(Wrappers.lambdaQuery(Borrow.class).between(Borrow::getCreateTime,
                now.atTime(LocalTime.MIN), now.atTime(LocalTime.MAX)));
        long totalBorrow = borrowService.count();
        map.put("todayRegister",todayRegister);
        map.put("totalRegister",totalRegister);
        map.put("todayBorrow",todayBorrow);
        map.put("totalBorrow",totalBorrow);
        return R.ok(map);
    }
}
