MerchantCommonService.java
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
}
}