package com.cool.store.service.impl;

import com.cool.store.dao.EnterpriseUserDAO;
import com.cool.store.dao.RegionDAO;
import com.cool.store.dao.UserRegionMappingDAO;
import com.cool.store.entity.EnterpriseUserDO;
import com.cool.store.entity.RegionDO;
import com.cool.store.mq.producer.SimpleMessageService;
import com.cool.store.service.RegionService;
import com.cool.store.utils.RedisConstantUtil;
import com.cool.store.utils.RedisUtil;
import com.cool.store.vo.region.RegionBaseInfoVO;
import com.cool.store.vo.region.RegionUserAndSubRegionVO;
import org.springframework.stereotype.Service;

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

/**
 * @author zhangchenbiao
 * @FileName: RegionServiceImpl
 * @Description:
 * @date 2023-06-05 10:43
 */
@Service
public class RegionServiceImpl implements RegionService {

    @Resource
    private RedisUtil redisUtil;
    @Resource
    private RegionDAO regionDAO;
    @Resource
    private UserRegionMappingDAO userRegionMappingDAO;
    @Resource
    private EnterpriseUserDAO enterpriseUserDAO;


    @Override
    public RegionBaseInfoVO getRegionBaseInfoList() {
        List<RegionDO> regionBaseInfoList = regionDAO.getRegionBaseInfoList();
        return RegionBaseInfoVO.convertTree(regionBaseInfoList);
    }

    @Override
    public RegionUserAndSubRegionVO getRegionUserAndSubRegion(String regionId) {
        List<RegionDO> subRegionList = regionDAO.getSubRegion(regionId);
        List<String> userIds = userRegionMappingDAO.getUserListByRegionId(regionId);
        Map<String, EnterpriseUserDO> userMap = enterpriseUserDAO.getUserMap(userIds);
        return RegionUserAndSubRegionVO.convertVO(subRegionList, userIds, userMap);
    }
}
