MerchantCommonService.java
2.5 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
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.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;
@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<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());
}
}