package org.linlinjava.jz.admin.service;

import com.google.common.collect.Lists;
import org.linlinjava.jz.admin.vo.ShopVo;
import org.linlinjava.jz.db.domain.JzShop;
import org.linlinjava.jz.db.domain.SysCity;
import org.linlinjava.jz.db.service.JzShopService;
import org.linlinjava.jz.db.service.JzSysCityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminShopService {

    @Autowired
    private JzShopService shopService;

    @Autowired
    private JzSysCityService sysCityService;

    public List<ShopVo> getShops(List<Integer> exists){
        List<ShopVo> shopVos= Lists.newArrayList();

        List<SysCity> citys=sysCityService.queryAll();
        for(SysCity city:citys){
            ShopVo vo=new ShopVo();
            vo.setId(city.getId().intValue());
            vo.setLabel(city.getCityName());
            List<JzShop> shops=shopService.queryByCityId(city.getId().intValue());
            List<ShopVo> childres=Lists.newArrayList();

            for(JzShop  shop:shops){
                if(exists.contains(shop.getId())) continue;
                ShopVo vo1=new ShopVo();
                vo1.setLabel(shop.getShopName());
                vo1.setId(shop.getId());
                childres.add(vo1);
            }
            vo.setChildren(childres);
            shopVos.add(vo);
        }

        return shopVos;
    }
}
