package com.dsk.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.dsk.common.core.domain.AjaxResult;
import com.dsk.common.dtos.*;
import com.dsk.common.utils.DateUtils;
import com.dsk.common.utils.DskOpenApiUtil;
import com.dsk.system.service.EconomicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @ClassName EconomicServiceImpl
 * @Description 经济大全实现
 * @Author Dgm
 * @Date 2023/5/18 10:23
 * @Version
 */
@Service
public class EconomicServiceImpl implements EconomicService {

    @Autowired
    private DskOpenApiUtil dskOpenApiUtil;

    @Override
    public AjaxResult nationalPage(OpRegionalEconomicDataV1PageDto dto) {
        if (ObjectUtil.isEmpty(dto.getYear())) {
            dto.setYear(DateUtils.getYear() - 1);
        }
        Map<String, Object> map = dskOpenApiUtil.requestBody("/economic/national/nationalPage",  BeanUtil.beanToMap(dto, false, false));
        return BeanUtil.toBean(map, AjaxResult.class);
    }

    @Override
    public AjaxResult yearsList(OpRegionalEconomicDataYearsListDto dto) {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/economic/years/list",  BeanUtil.beanToMap(dto, false, false));
        return BeanUtil.toBean(map, AjaxResult.class);
    }

    @Override
    public AjaxResult details(OpRegionalEconomicDataDetailsDto detailsDto) {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/economic/details", BeanUtil.beanToMap(detailsDto, false, false));
        return BeanUtil.toBean(map, AjaxResult.class);
    }

    @Override
    public AjaxResult location(OpRegionalLocalDto detailsDto) {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/economic/location", BeanUtil.beanToMap(detailsDto, false, false));
        return BeanUtil.toBean(map, AjaxResult.class);
    }

    @Override
    public AjaxResult statisticsRegional(OpRegionalEconomicDataStatisticsRegionalDto dto) {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/economic/statistics/regional",  BeanUtil.beanToMap(dto, false, false));
        return BeanUtil.toBean(map, AjaxResult.class);
    }

    @Override
    public AjaxResult regionalList(OpRegionalEconomicDataRegionalListDto dto) {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/economic/regional/list",  BeanUtil.beanToMap(dto, false, false));
        return BeanUtil.toBean(map, AjaxResult.class);
    }

    @Override
    public AjaxResult regionalCompare(OpRegionalEconomicDataStatisticsRegionalDto dto) {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/economic/regional/compare",  BeanUtil.beanToMap(dto, false, false));
        return BeanUtil.toBean(map, AjaxResult.class);
    }

    @Override
    public AjaxResult regionalMultipleCompare(OpRegionalEconomicRegionalCompareDto dto) {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/economic/regional/multipleCompare",  BeanUtil.beanToMap(dto, false, false));
        return BeanUtil.toBean(map, AjaxResult.class);
    }

}
