package com.njzscloud.supervisory.bs.service;

import cn.hutool.core.map.MapUtil;
import com.njzscloud.supervisory.bs.mapper.SupervisionStatisticsMapper;
import com.njzscloud.supervisory.bs.pojo.result.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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

@Slf4j
@Service
@RequiredArgsConstructor
public class SupervisionStatisticsService {
    private final SupervisionStatisticsMapper supervisionStatisticsMapper;

    public Map<String, Object> obtainData() {

        DispatchSummary dispatchSummary = supervisionStatisticsMapper.getDispatchSummary();

        YuYueSummary yuYueSummary = supervisionStatisticsMapper.getYuYueSummary();

        Integer disposeTotalWeight = supervisionStatisticsMapper.getDisposeTotalWeight();

        CarSummary carSummary = supervisionStatisticsMapper.getCarSummary();
        Integer todayCarCount = supervisionStatisticsMapper.getTodayCarCount();
        List<RegionSummary> regionSummary = supervisionStatisticsMapper.getRegionSummary();
        List<CompanySummary> companySummary = supervisionStatisticsMapper.getCompanySummary();
        List<StationInfo> stationInfo = supervisionStatisticsMapper.getStationInfo();
        List<Order> orders = supervisionStatisticsMapper.getOrders();
        List<Project> projects = supervisionStatisticsMapper.getProjects();

        return MapUtil.<String, Object>builder()
                .put("dispatchSummary", dispatchSummary == null ? new DispatchSummary() : dispatchSummary)
                .put("yuYueSummary", yuYueSummary == null ? new YuYueSummary() : yuYueSummary)
                .put("disposeTotalWeight", disposeTotalWeight == null ? 0 : disposeTotalWeight)
                .put("carSummary", carSummary == null ? new CarSummary() : carSummary)
                .put("todayCarCount", todayCarCount == null ? 0 : todayCarCount)
                .put("regionSummary", regionSummary == null ? new ArrayList<>() : regionSummary)
                .put("companySummary", companySummary == null ? new ArrayList<>() : companySummary)
                .put("stationInfo", stationInfo == null ? new ArrayList<>() : stationInfo)
                .put("orders", orders == null ? new ArrayList<>() : orders)
                .put("projects", projects == null ? new ArrayList<>() : projects)
                .build();
    }

}
