package com.benyun.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.benyun.core.dao.WdInfoDao;
import com.benyun.core.entity.CityTierBody;
import com.benyun.core.entity.WdInfo;
import com.benyun.core.service.ChannelAnalyseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {

    @Autowired
    WdInfoDao wdInfoDao;

    @Autowired
    @Qualifier("cityTierMap")
    HashMap<String,String> cityTierMap;

    @Override
    public HashMap cityTier(String searchText) {
        HashMap<String,Long> result = new HashMap<>();
        result.put("一线",0L);
        result.put("新一线",0L);
        result.put("二线",0L);
        result.put("三线",0L);
        result.put("四线",0L);
        result.put("五线",0L);
        result.put("其他",0L);

        //1.获取所有符合条件的网点信息
        QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
        if(searchText != null && !searchText.equals(""))
            queryWrapper.like("wd_name",searchText);
        List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
        System.out.println(wdInfos.size());
        for (WdInfo wdInfo : wdInfos) {
            String addrCode = wdInfo.getAddrCode();
            if(cityTierMap.containsKey(addrCode)){
                result.put(cityTierMap.get(addrCode),result.get(cityTierMap.get(addrCode))+1);
            }else if(cityTierMap.containsKey(addrCode.substring(0,4))){
                result.put(cityTierMap.get(addrCode.substring(0,4)),result.get(cityTierMap.get(addrCode.substring(0,4)))+1);
            }else if(cityTierMap.containsKey(addrCode.substring(0,2))){
                result.put(cityTierMap.get(addrCode.substring(0,2)),result.get(cityTierMap.get(addrCode.substring(0,2)))+1);
            }
            else
                result.put("其他",result.get("其他")+1);
        }


        return result;
    }
}
