ZhongliVehicleService.java
3.84 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
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() {
List<ZhongliAccountModel> accountModelList = zhongliAccountMapper.selectByLevel(null);
Map<String, List<ZhongliAccountModel>> accountMapByRoleName = accountModelList.stream().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.selectAllByNoNullRefVehicleId();
Map<Long, Vehicle> vehicleMap = vehicleList.stream().collect(Collectors.toMap(Vehicle::getRefVehicleId, v -> v));
log.info("绝对授权方式");
accountMapByRoleName.forEach((k, v) -> {
v.forEach(account -> {
List<ZhongliVehicle> zhongliVehicleList = zhongliVehicleMapper.selectByAccount(account.getAccount());
log.info("账号{}(角色为:{})的车辆数:{}", account.getAccount(), k, zhongliVehicleList.size());
if (k.equals("仲利法务") || k.equals("仲利收车")) {
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(0L);
vp.setReceiverId(1L);
vp.setContentType(0);
vp.setPermitType(1);
vp.setCreatedDate(new Date());
permitList.add(vp);
});
if (CollectionUtils.isNotEmpty(permitList)) {
//vehiclePermitMapper.insertList(permitList);
}
}
});
});
log.info("相对授权方式");
accountMapByLevel.forEach((k, v) -> {
v.forEach(account -> {
List<ZhongliVehicle> zhongliVehicleList = zhongliVehicleMapper.selectByAccount(account.getAccount());
log.info("{}账号{}(角色为:{})的车辆数:{}", k, account.getAccount(), k, zhongliVehicleList.size());
});
});
}
}