MerchantCommonService.java
3.89 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package cn.com.glsx.merchants.service;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.merchants.convert.ConvertResponse;
import cn.com.glsx.merchants.model.response.MerchantChannelResponse;
import cn.com.glsx.merchants.remote.MerchantRemote;
import cn.com.glsx.merchants.response.CarbrandResponse;
import cn.com.glsx.merchants.response.ChannelResponse;
import cn.com.glsx.merchants.response.MerchantTreeRopResponse;
import com.glsx.biz.common.base.entity.CarBrandSelected;
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.ArrayList;
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;
@Autowired
private MerchantRemote merchantRemote;
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;
}
public List<CarbrandResponse> getCarbrandTreeNew() {
List<CarBrandSelected> carInfoCompleteForSelected = carbrandService.getCarInfoCompleteForSelected();
List<CarbrandResponse> list = new ArrayList<>(carInfoCompleteForSelected.size());
carInfoCompleteForSelected.forEach(v-> {
CarbrandResponse response = new CarbrandResponse();
response.setId(v.getId());
response.setLabel(v.getName());
if(v.getChilds() != null){
v.getChilds().forEach(v1 -> {
if(v1.getChilds() != null){
List<CarbrandResponse> collect = v1.getChilds().stream().map(x -> {
CarbrandResponse sub = new CarbrandResponse();
sub.setId(x.getId());
sub.setLabel(x.getName());
return sub;
}).collect(Collectors.toList());
if(collect.size() > 0){
response.setChildren(collect);
}
}else {
System.out.println(v1.getId());
}
});
}
list.add(response);
});
return list;
}
public List<ChannelResponse> findAllChannel() {
RpcResponse<List<MerchantChannelResponse>> allChannel = merchantRemote.findAllChannel();
if (allChannel.isSuccess()) {
return ConvertResponse.convertList(allChannel.getResult(), ChannelResponse.class);
}
throw new RpcServiceException(allChannel.getException().getErrId(), allChannel.getMessage());
}
}