package org.jeecg.modules.api.service;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.jeecg.modules.api.mapper.ScreenDashboardMapper;
import org.jeecg.modules.toolCheck.service.IToolCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

@Service
public class ScreenDashboardService {

    @Autowired
    private ScreenDashboardMapper dashboardMapper;

    public Map<String, Object> queryDashboard(String month) {

        if (StringUtils.isBlank(month)) {
            month = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
        }

        Map<String, Object> result = new HashMap<>(8);

        result.put("repairPlan", dashboardMapper.repairPlanStat(month));
        result.put("workOrder", dashboardMapper.workOrderStat(month));
        result.put("toolTop", dashboardMapper.toolBorrowTop(month));
        result.put("materialTop", dashboardMapper.materialConsumeTop(month));
        result.put("breakdown", dashboardMapper.breakdownMonthStat(month));
        result.put("staffWorkOrderRank", dashboardMapper.staffWorkOrderRank(month));
        result.put("deviceFaultStats", dashboardMapper.deviceBreakdownNumberStat());

        return result;
    }

}
