package com.dsk.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson2.JSONObject;
import com.dsk.common.annotation.DataScope;
import com.dsk.common.core.domain.AjaxResult;
import com.dsk.common.utils.DskOpenApiUtil;
import com.dsk.system.domain.business.dto.BusinessSearchDto;
import com.dsk.system.domain.business.vo.BusinessAnalyzeVo;
import com.dsk.system.mapper.BusinessInfoMapper;
import com.dsk.system.service.IBusinessOverviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lcl
 * @create 2023/8/14
 */
@Service
public class BusinessOverviewServiceImpl implements IBusinessOverviewService {

    @Resource
    private BusinessInfoMapper businessInfoMapper;

    @Autowired
    private DskOpenApiUtil dskOpenApiUtil;

    @Override
    @DataScope(userAlias = "u",deptAlias = "d")
    public Map<String, Object> statusStatistics(BusinessSearchDto dto) {
        Map<String, Object> resultMap = new HashMap<>();
        //总
        resultMap.put("totalCount",businessInfoMapper.selectCountByStatus(dto));
        //储备
        dto.setStatus(0);
        resultMap.put("reserveCount",businessInfoMapper.selectCountByStatus(dto));
        //跟进
        dto.setStatus(1);
        resultMap.put("followUpCount",businessInfoMapper.selectCountByStatus(dto));
        //中标(已合作)
        dto.setStatus(2);
        resultMap.put("bidCount",businessInfoMapper.selectCountByStatus(dto));
        return resultMap;
    }

    @Override
    @DataScope(userAlias = "u",deptAlias = "d")
    public List<BusinessAnalyzeVo> amountAnalyze(BusinessSearchDto dto) {
        return businessInfoMapper.selectAmountAnalyze(dto);
    }

    @Override
    @DataScope(userAlias = "u",deptAlias = "d")
    public List<BusinessAnalyzeVo> typeAnalyze(BusinessSearchDto dto) {
        return businessInfoMapper.selectTypeAnalyze(dto);
    }

    @Override
    @DataScope(userAlias = "u",deptAlias = "d")
    public List<BusinessAnalyzeVo> categoryAnalyze(BusinessSearchDto dto) {
        return businessInfoMapper.selectCategoryAnalyze(dto);
    }

    @Override
    public AjaxResult countGroupByProvince(JSONObject object) {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/nationzj/marketAnalysis/project/countGroupByProvince", object);
        return BeanUtil.toBean(map, AjaxResult.class);
    }

    @Override
    public AjaxResult rangByMoney(JSONObject object) {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/nationzj/marketAnalysis/project/rangByMoney", object);
        return BeanUtil.toBean(map, AjaxResult.class);
    }
}
