package com.lightinit.hsdataplatform.impl.admin;

import com.lightinit.hsdataplatform.dictionary.DicResourceCatelogType;
import com.lightinit.hsdataplatform.dictionary.DicResourceRankCategory;
import com.lightinit.hsdataplatform.dictionary.DicResourceRankClassify;
import com.lightinit.hsdataplatform.mapper.ResourceCatelogMapper;
import com.lightinit.hsdataplatform.model.ResultState;
import com.lightinit.hsdataplatform.model.admin.OrderSearchModel;
import com.lightinit.hsdataplatform.model.admin.RankSearchModel;
import com.lightinit.hsdataplatform.model.admin.ResourceRankModel;
import com.lightinit.hsdataplatform.service.admin.IResourceRankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @Author: sunxiang
 * @Date: 2018/8/17 16:42
 * @Description:
 **/
@Service
public class ResourceRankServiceImpl implements IResourceRankService {

    @Autowired
    private ResourceCatelogMapper resourceCatelogMapper;
    @Override
    public Map<String,Object> getList(RankSearchModel inputModel) {
       // ResultState resultState = new ResultState();
        List<String> names=new ArrayList<>();//名称
        List<Integer> totals=new ArrayList<>();//数量
        Map<String,Object> map=new HashMap<>();
        List<ResourceRankModel> list=null;
        long pagerTotal=0;
        if(DicResourceRankClassify.THEME.equals(inputModel.getClassify())){
            inputModel.setCatelogType(DicResourceCatelogType.THEME);
            pagerTotal=resourceCatelogMapper.getPagerTotalByTheme(inputModel);
            switch (inputModel.getCategory()){
                case DicResourceRankCategory.APPLYTIMES://申请次数
                    list=resourceCatelogMapper.getResourceRankByThemeAndApplyTimes(inputModel);
                    break;
                case DicResourceRankCategory.TRADETIMES://交易次数
                    list=resourceCatelogMapper.getResourceRankByThemeAndTradeTimes(inputModel);
                    break;
                case DicResourceRankCategory.TRADESUM://交易金额
                    list=resourceCatelogMapper.getResourceRankByThemeAndTradeSum(inputModel);
                    break;
                default://默认为资源数量
                    list=resourceCatelogMapper.getResourceRankByThemeAndResourceToltal(inputModel);
                    break;
            }
        }else if(DicResourceRankClassify.PROVIDERSECTOR.equals(inputModel.getClassify())){
            pagerTotal=resourceCatelogMapper.getPagerTotalBySector(inputModel);
            switch (inputModel.getCategory()){
                case DicResourceRankCategory.APPLYTIMES://申请次数
                    list=resourceCatelogMapper.getResourceRankBySectorAndApplyTimes(inputModel);
                    break;
                case DicResourceRankCategory.TRADETIMES://交易次数
                    list=resourceCatelogMapper.getResourceRankBySectorAndTradeTimes(inputModel);
                    break;
                case DicResourceRankCategory.TRADESUM://交易金额
                    list=resourceCatelogMapper.getResourceRankBySectorAndTradeSum(inputModel);
                    break;
                default://默认为资源数量
                    list=resourceCatelogMapper.getResourceRankBySectorAndResourceToltal(inputModel);
                    break;
            }
        }else if(DicResourceRankClassify.SINGLERESOURE.equals(inputModel.getClassify())){
            pagerTotal=resourceCatelogMapper.getPagerTotalBySingleResource(inputModel);
            switch (inputModel.getCategory()){
                case DicResourceRankCategory.APPLYTIMES://申请次数
                    list=resourceCatelogMapper.getResourceRankBySingleResourceAndApplyTimes(inputModel);
                    break;
                case DicResourceRankCategory.TRADETIMES://交易次数
                    list=resourceCatelogMapper.getResourceRankBySingleResourceAndTradeTimes(inputModel);
                    break;
                case DicResourceRankCategory.TRADESUM://交易金额
                    list=resourceCatelogMapper.getResourceRankBySingleResourceAndTradeSum(inputModel);
                    break;
                default://默认为资源数量
                    list=resourceCatelogMapper.getResourceRankBySingleResourceAndResourceToltal(inputModel);
                    break;
            }
        }else if(DicResourceRankClassify.USEUSER.equals(inputModel.getClassify())){
            pagerTotal=resourceCatelogMapper.getPagerTotalByUser(inputModel);
            switch (inputModel.getCategory()){
                case DicResourceRankCategory.APPLYTIMES://申请次数
                    list=resourceCatelogMapper.getResourceRankByUserAndApplyTimes(inputModel);
                    break;
                case DicResourceRankCategory.TRADETIMES://交易次数
                    list=resourceCatelogMapper.getResourceRankByUserAndTradeTimes(inputModel);
                    break;
                case DicResourceRankCategory.TRADESUM://交易金额
                    list=resourceCatelogMapper.getResourceRankByUserAndTradeSum(inputModel);
                    break;
                default://默认为资源数量
                    list=resourceCatelogMapper.getResourceRankByUserAndResourceToltal(inputModel);
                    break;
            }
        }
        Collections.reverse(list);
        for (ResourceRankModel resourceRankModel : list) {
            names.add("'"+resourceRankModel.getName()+"'");
            totals.add(resourceRankModel.getTotal());
        }
        map.put("names",names);
        map.put("totals",totals);
        map.put("pagerTotal",pagerTotal);
        //resultState.setData(map);
        return map;
    }

}
