MerchantCommonService.java 1.63 KB
package cn.com.glsx.merchants.service;

import cn.com.glsx.merchants.response.CarbrandResponse;
import com.glsx.biz.common.base.entity.Carbrand;
import com.glsx.biz.common.base.service.CarbrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zhouhaibao
 * @version 1.0
 * @description: 商户公共服务
 * @date 2021/8/1 10:20
 */
@Service
public class MerchantCommonService {

    @Autowired
    private CarbrandService carbrandService;

    public List<CarbrandResponse> getCarbrandTree() {
        List<Carbrand> parentCarbrandList = carbrandService.getParentCarbrandList();
        List<Carbrand> allList = carbrandService.getAllList();
        List<CarbrandResponse> collect = parentCarbrandList.stream().map(index -> {
            CarbrandResponse carbrandResponse = new CarbrandResponse();
            carbrandResponse.setId(index.getBid());
            carbrandResponse.setLabel(index.getBrand());
            List<CarbrandResponse> childrens = allList.stream().filter(child -> child.getParentId().equals(index.getBid())).map(in -> {
                CarbrandResponse carbrandResponse1 = new CarbrandResponse();
                carbrandResponse1.setId(in.getBid());
                carbrandResponse1.setLabel(in.getBrand());
                return carbrandResponse1;
            }).collect(Collectors.toList());
            carbrandResponse.setChildren(childrens);
            return carbrandResponse;
        }).collect(Collectors.toList());
        return collect;
    }
}