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.core.domain.BaseEntity;
import com.dsk.common.utils.DskOpenApiUtil;
import com.dsk.common.utils.SecurityUtils;
import com.dsk.system.domain.business.dto.BusinessSearchDto;
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.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> statistics(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
    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);
    }
}
