CarServiceImpl.java 2.88 KB
package com.glsx.publicservice.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.glsx.biz.common.base.entity.CarBrandSelected;
import com.glsx.biz.common.base.entity.CarInfoSelected;
import com.glsx.biz.common.base.entity.Carbrand;
import com.glsx.biz.common.base.entity.Carseries;
import com.glsx.biz.common.base.entity.Cartype;
import com.glsx.biz.common.base.service.CarbrandService;
import com.glsx.biz.common.base.service.CarseriesService;
import com.glsx.biz.common.base.service.CartypeService;
import com.glsx.publicservice.service.CarService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class CarServiceImpl implements CarService {
    @Reference(version = "2.2.0")
    private CarbrandService carbrandService;
    @Reference(version = "2.2.0")
    private CarseriesService carseriesService;
    @Reference(version = "2.2.0")
    private CartypeService cartypeService;
	
	@Override
	public List<Carbrand> getCarbrandList() {
		// TODO Auto-generated method stub
		return carbrandService.getAllList();
	}
	
	@Override
	public List<Carseries> getCarseriesList(Integer bid) {
		// TODO Auto-generated method stub
		return carseriesService.getByCarbrandId(bid);
	}
	@Override
	public List<Cartype> getCartypeList(Integer seriesId) {
		// TODO Auto-generated method stub
		return cartypeService.getBySeiesId(seriesId);
	}

	@Override
	public Carbrand getCarbrandById(Integer bid) {
		// TODO Auto-generated method stub
		return carbrandService.findById(bid);
	}

	@Override
	public Carseries getCarseriesById(Integer seriesId) {
		// TODO Auto-generated method stub
		return carseriesService.findById(seriesId);
	}

	@Override
	public Cartype getCartypeById(Integer seriesId, Integer cartypeId) {
		// TODO Auto-generated method stub
		return cartypeService.get(seriesId, cartypeId);
	}

	@Override
	public Cartype getCarTypeDetail( Integer cartypeId) {	
		return cartypeService.get( cartypeId);
	}

	@Override
	public List<CarBrandSelected> getCarbrandTree(Integer type) {
		if (Objects.isNull(type)) {
			type = 2;
		}
		List<CarBrandSelected> carInfoCompleteForSelected = carbrandService.getCarInfoCompleteForSelected();
		int finalType = type;
		carInfoCompleteForSelected.forEach(first -> {
			List<CarInfoSelected> secondList = first.getChilds();
			if (CollectionUtils.isNotEmpty(secondList)) {
				secondList.forEach(second -> {
					if (finalType == 2) {
						second.setChilds(null);
					} else if (finalType == 3) {
						List<CarInfoSelected> thridList = second.getChilds();
						if (CollectionUtils.isNotEmpty(thridList)) {
							thridList.forEach(third -> {
								third.setChilds(null);
							});
						}
					}
				});
			}
		});

		return carInfoCompleteForSelected;
	}
}