ZhongliVehicleService.java
6.55 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package cn.com.glsx.stdinterface.modules.service;
import cn.com.glsx.stdinterface.modules.entity.Vehicle;
import cn.com.glsx.stdinterface.modules.entity.VehiclePermit;
import cn.com.glsx.stdinterface.modules.entity.ZhongliVehicle;
import cn.com.glsx.stdinterface.modules.mapper.VehicleMapper;
import cn.com.glsx.stdinterface.modules.mapper.VehiclePermitMapper;
import cn.com.glsx.stdinterface.modules.mapper.ZhongliAccountMapper;
import cn.com.glsx.stdinterface.modules.mapper.ZhongliVehicleMapper;
import cn.com.glsx.stdinterface.modules.model.ZhongliAccountModel;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Service
public class ZhongliVehicleService {
@Resource
private ZhongliAccountMapper zhongliAccountMapper;
@Resource
private ZhongliVehicleMapper zhongliVehicleMapper;
@Resource
private VehicleMapper vehicleMapper;
@Resource
private VehiclePermitMapper vehiclePermitMapper;
public void linkVehicle2Account() {
//更新用户id
zhongliAccountMapper.updateZhongliAccountUserId();
List<ZhongliAccountModel> accountModelList = zhongliAccountMapper.selectByLevel(null);
Map<String, ZhongliAccountModel> accountMap = accountModelList.stream().collect(Collectors.toMap(ZhongliAccountModel::getAccount, v -> v));
Map<String, List<ZhongliAccountModel>> accountMapByRoleName = accountModelList.stream()
.filter(zam -> zam.getRoleName().equals("仲利法务") || zam.getRoleName().equals("仲利收车"))
.collect(Collectors.groupingBy(ZhongliAccountModel::getRoleName));
Map<String, List<ZhongliAccountModel>> accountMapByLevel = accountModelList.stream()
.filter(zam -> !zam.getRoleName().equals("仲利法务") && !zam.getRoleName().equals("仲利收车"))
.sorted(Comparator.comparing(ZhongliAccountModel::getLevel))
.collect(Collectors.groupingBy(ZhongliAccountModel::getLevel));
//全部同步车辆
List<Vehicle> vehicleList = vehicleMapper.selectAllByNotNullRefVehicleId();
Map<Long, Vehicle> vehicleMap = vehicleList.stream().collect(Collectors.toMap(Vehicle::getRefVehicleId, v -> v));
ZhongliAccountModel zlgj = accountMap.get("zlgj");
log.info("绝对授权方式===============================================");
accountMapByRoleName.forEach((k, v) -> v.forEach(account -> {
List<ZhongliVehicle> zhongliVehicleList = zhongliVehicleMapper.selectByAccount(account.getAccount());
log.info("账号{}(角色为:{})的车辆数:{}", account.getAccount(), k, zhongliVehicleList.size());
List<VehiclePermit> permitList = Lists.newArrayList();
zhongliVehicleList.forEach(zv -> {
Vehicle vehicle = vehicleMap.get(zv.getVehicleId());
if (vehicle == null) {
return;
}
VehiclePermit vp = new VehiclePermit();
vp.setContentId(vehicle.getId());
vp.setAccorderId(zlgj.getUserId());
vp.setReceiverId(account.getUserId());
vp.setContentType(0);
vp.setPermitType(1);
vp.setCreatedDate(new Date());
permitList.add(vp);
});
if (CollectionUtils.isNotEmpty(permitList)) {
vehiclePermitMapper.insertList(permitList);
}
}));
log.info("相对授权方式=================================================");
List<ZhongliAccountModel> accountModels1 = accountMapByLevel.get("一级");
if (CollectionUtils.isNotEmpty(accountModels1)) {
accountModels1.forEach(account -> {
List<ZhongliVehicle> zhongliVehicleList = zhongliVehicleMapper.selectByAccount(account.getAccount());
log.info("一级账号{}的车辆数:{}", account.getAccount(), zhongliVehicleList.size());
List<Long> vehicleIds = Lists.newArrayList();
zhongliVehicleList.forEach(zv -> vehicleIds.add(zv.getVehicleId()));
if (CollectionUtils.isNotEmpty(vehicleIds)) {
vehicleMapper.updateCreateByByRefVehicleIds(account.getUserId(), vehicleIds);
}
});
}
List<ZhongliAccountModel> accountModels2 = accountMapByLevel.get("二级");
if (CollectionUtils.isNotEmpty(accountModels2)) {
accountModels2.forEach(account -> {
List<ZhongliVehicle> zhongliVehicleList = zhongliVehicleMapper.selectByAccount(account.getAccount());
log.info("二级账号{}的车辆数:{}", account.getAccount(), zhongliVehicleList.size());
List<Long> vehicleIds = Lists.newArrayList();
zhongliVehicleList.forEach(zv -> vehicleIds.add(zv.getVehicleId()));
if (CollectionUtils.isNotEmpty(vehicleIds)) {
vehicleMapper.updateCreateByByRefVehicleIds(account.getUserId(), vehicleIds);
}
});
}
List<ZhongliAccountModel> accountModels3 = accountMapByLevel.get("三级");
if (CollectionUtils.isNotEmpty(accountModels3)) {
accountModels3.forEach(account -> {
List<ZhongliVehicle> zhongliVehicleList = zhongliVehicleMapper.selectByAccount(account.getAccount());
log.info("三级账号{}的车辆数:{}", account.getAccount(), zhongliVehicleList.size());
List<Long> vehicleIds = Lists.newArrayList();
zhongliVehicleList.forEach(zv -> vehicleIds.add(zv.getVehicleId()));
if (CollectionUtils.isNotEmpty(vehicleIds)) {
vehicleMapper.updateCreateByByRefVehicleIds(account.getUserId(), vehicleIds);
}
});
}
//最后还没有创建人的直接丢到仲利国际上面
List<Vehicle> noCreateByVehicles = vehicleMapper.selectByNullCreateBy();
if (CollectionUtils.isNotEmpty(noCreateByVehicles)) {
List<Long> vehicleIds = Lists.newArrayList();
noCreateByVehicles.forEach(vehicle -> vehicleIds.add(vehicle.getRefVehicleId()));
if (CollectionUtils.isNotEmpty(vehicleIds)) {
vehicleMapper.updateCreateByByRefVehicleIds(zlgj.getUserId(), vehicleIds);
}
}
}
}