/*
 *  Copyright 2019-2025 Tz
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package me.zhengjie.modules.system.service.impl;

import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.system.domain.dto.DashboardDataVo;
import me.zhengjie.modules.system.mapper.DashboardMapper;
import me.zhengjie.modules.system.service.DashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class DashboardServiceImpl implements DashboardService {

    @Autowired
    private DashboardMapper dashboardMapper;

    @Override
    public Map<String, Object> getCardData() {
        List<DashboardDataVo> data = dashboardMapper.getCardData();
        return data.stream().collect(Collectors.toMap(DashboardDataVo::getText, DashboardDataVo::getValue));
    }

    @Override
    public List<Integer> getLineChartData(String type) {
        List<DashboardDataVo> data = dashboardMapper.getLineChartData(type);
        List<Integer> values = data.stream().map(i -> Integer.parseInt(i.getValue().toString())).collect(Collectors.toList());
        return values;
    }

    @Override
    public List<DashboardDataVo> getPieChatData() {
        List<DashboardDataVo> data = dashboardMapper.getPieChatData();
        return data;
    }
}
