一人多车版本回退
This commit is contained in:
@@ -737,19 +737,53 @@ public class HotDriverServiceImpl implements IHotDriverService {
|
|||||||
removeDriverPortFromUser(oldDriver.getPhone(), oldDriver.getCompanyId());
|
removeDriverPortFromUser(oldDriver.getPhone(), oldDriver.getCompanyId());
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> impactedDriverIds = new LinkedHashSet<>();
|
// 处理车牌号变更:同步车辆信息的当前驾驶员
|
||||||
impactedDriverIds.add(driverId);
|
String oldPlate = oldDriver != null ? oldDriver.getPlateNumber() : null;
|
||||||
if (oldDriver != null) {
|
String newPlate = update.getPlateNumber();
|
||||||
impactedDriverIds.addAll(findOtherDriversBoundToVehicles(companyId, splitCsv(oldDriver.getVehicleId()), driverId));
|
if (!StringUtils.equals(oldPlate, newPlate)) {
|
||||||
}
|
// 1. 如果旧车牌存在,从旧车辆的当前驾驶员列表中移除当前司机
|
||||||
|
if (StringUtils.isNotBlank(oldPlate)) {
|
||||||
|
HotVehicle oldVehicle = vehicleMapper.selectOne(new LambdaQueryWrapper<HotVehicle>()
|
||||||
|
.eq(HotVehicle::getPlateNumber, oldPlate)
|
||||||
|
.eq(HotVehicle::getCompanyId, update.getCompanyId()));
|
||||||
|
|
||||||
boolean bindingSpecified = bo.getVehicleId() != null || bo.getPlateNumber() != null;
|
if (oldVehicle != null && StringUtils.isNotBlank(oldVehicle.getCurrentDriver())) {
|
||||||
if (bindingSpecified) {
|
List<String> driverList = new ArrayList<>(Arrays.asList(oldVehicle.getCurrentDriver().split(",")));
|
||||||
List<HotVehicle> targetVehicles = resolveDriverTargetVehicles(bo, companyId);
|
if (driverList.remove(driverId)) {
|
||||||
impactedDriverIds.addAll(syncVehicleBindingsForDriver(driverId, companyId, targetVehicles));
|
String newDriverStr = String.join(",", driverList);
|
||||||
}
|
// 如果结果为空字符串,设为null或空
|
||||||
|
vehicleMapper.update(null,
|
||||||
|
new LambdaUpdateWrapper<HotVehicle>()
|
||||||
|
.set(HotVehicle::getCurrentDriver, StringUtils.isBlank(newDriverStr) ? null : newDriverStr)
|
||||||
|
.eq(HotVehicle::getId, oldVehicle.getId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
syncDriverVehicleRelationsByDriverIds(companyId, impactedDriverIds);
|
// 2. 如果新车牌存在,将当前司机追加到新车辆的当前驾驶员列表
|
||||||
|
if (StringUtils.isNotBlank(newPlate)) {
|
||||||
|
HotVehicle newVehicle = vehicleMapper.selectOne(new LambdaQueryWrapper<HotVehicle>()
|
||||||
|
.eq(HotVehicle::getPlateNumber, newPlate)
|
||||||
|
.eq(HotVehicle::getCompanyId, update.getCompanyId()));
|
||||||
|
|
||||||
|
if (newVehicle != null) {
|
||||||
|
String currentDriverStr = newVehicle.getCurrentDriver();
|
||||||
|
List<String> driverList = StringUtils.isBlank(currentDriverStr)
|
||||||
|
? new ArrayList<>()
|
||||||
|
: new ArrayList<>(Arrays.asList(currentDriverStr.split(",")));
|
||||||
|
|
||||||
|
// 避免重复添加
|
||||||
|
if (!driverList.contains(driverId)) {
|
||||||
|
driverList.add(driverId);
|
||||||
|
String newDriverStr = String.join(",", driverList);
|
||||||
|
vehicleMapper.update(null,
|
||||||
|
new LambdaUpdateWrapper<HotVehicle>()
|
||||||
|
.set(HotVehicle::getCurrentDriver, newDriverStr)
|
||||||
|
.eq(HotVehicle::getId, newVehicle.getId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 同步最新的驾驶员信息到用户表(包含状态变更、基本信息变更)
|
// 同步最新的驾驶员信息到用户表(包含状态变更、基本信息变更)
|
||||||
HotDriver newDriver = baseMapper.selectById(driverId);
|
HotDriver newDriver = baseMapper.selectById(driverId);
|
||||||
@@ -899,168 +933,6 @@ public class HotDriverServiceImpl implements IHotDriverService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<HotVehicle> resolveDriverTargetVehicles(HotDriverBo bo, Long companyId) {
|
|
||||||
List<String> vehicleIds = splitCsv(bo.getVehicleId());
|
|
||||||
if (CollUtil.isNotEmpty(vehicleIds)) {
|
|
||||||
List<HotVehicle> vehicles = vehicleMapper.selectList(Wrappers.<HotVehicle>lambdaQuery()
|
|
||||||
.eq(HotVehicle::getCompanyId, companyId)
|
|
||||||
.in(HotVehicle::getId, vehicleIds)
|
|
||||||
.eq(HotVehicle::getIsDeleted, 0L));
|
|
||||||
validateVehicleSelection(vehicleIds, vehicles, true);
|
|
||||||
return vehicles;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> plateNumbers = splitCsv(bo.getPlateNumber());
|
|
||||||
if (CollUtil.isEmpty(plateNumbers)) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
List<HotVehicle> vehicles = vehicleMapper.selectList(Wrappers.<HotVehicle>lambdaQuery()
|
|
||||||
.eq(HotVehicle::getCompanyId, companyId)
|
|
||||||
.in(HotVehicle::getPlateNumber, plateNumbers)
|
|
||||||
.eq(HotVehicle::getIsDeleted, 0L));
|
|
||||||
validateVehicleSelection(plateNumbers, vehicles, false);
|
|
||||||
return vehicles;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validateVehicleSelection(List<String> expectedValues, List<HotVehicle> vehicles, boolean useVehicleId) {
|
|
||||||
Set<String> actualValues = vehicles.stream()
|
|
||||||
.map(vehicle -> useVehicleId ? vehicle.getId() : vehicle.getPlateNumber())
|
|
||||||
.filter(StringUtils::isNotBlank)
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
List<String> missingValues = expectedValues.stream()
|
|
||||||
.filter(value -> !actualValues.contains(value))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
if (CollUtil.isNotEmpty(missingValues)) {
|
|
||||||
throw new ServiceException(useVehicleId
|
|
||||||
? "存在未找到的车辆ID:" + String.join(",", missingValues)
|
|
||||||
: "存在未找到的车牌号:" + String.join(",", missingValues));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Set<String> syncVehicleBindingsForDriver(String driverId, Long companyId, List<HotVehicle> targetVehicles) {
|
|
||||||
Set<String> impactedDriverIds = new LinkedHashSet<>();
|
|
||||||
impactedDriverIds.add(driverId);
|
|
||||||
if (StringUtils.isBlank(driverId) || companyId == null) {
|
|
||||||
return impactedDriverIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<String> targetVehicleIds = targetVehicles.stream()
|
|
||||||
.map(HotVehicle::getId)
|
|
||||||
.filter(StringUtils::isNotBlank)
|
|
||||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
|
||||||
List<HotVehicle> companyVehicles = vehicleMapper.selectList(Wrappers.<HotVehicle>lambdaQuery()
|
|
||||||
.eq(HotVehicle::getCompanyId, companyId)
|
|
||||||
.eq(HotVehicle::getIsDeleted, 0L));
|
|
||||||
|
|
||||||
for (HotVehicle vehicle : companyVehicles) {
|
|
||||||
List<String> currentDrivers = splitCsv(vehicle.getCurrentDriver());
|
|
||||||
boolean currentlyBoundToDriver = currentDrivers.contains(driverId);
|
|
||||||
boolean shouldBindToDriver = targetVehicleIds.contains(vehicle.getId());
|
|
||||||
|
|
||||||
if (!currentlyBoundToDriver && !shouldBindToDriver) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldBindToDriver) {
|
|
||||||
impactedDriverIds.addAll(currentDrivers);
|
|
||||||
if (!currentlyBoundToDriver || currentDrivers.size() != 1) {
|
|
||||||
vehicleMapper.update(null, new LambdaUpdateWrapper<HotVehicle>()
|
|
||||||
.set(HotVehicle::getCurrentDriver, driverId)
|
|
||||||
.eq(HotVehicle::getId, vehicle.getId())
|
|
||||||
.eq(HotVehicle::getCompanyId, companyId));
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> remainingDrivers = new ArrayList<>(currentDrivers);
|
|
||||||
remainingDrivers.removeIf(driverId::equals);
|
|
||||||
impactedDriverIds.addAll(remainingDrivers);
|
|
||||||
vehicleMapper.update(null, new LambdaUpdateWrapper<HotVehicle>()
|
|
||||||
.set(HotVehicle::getCurrentDriver, normalizeSingleBindingValue(remainingDrivers))
|
|
||||||
.eq(HotVehicle::getId, vehicle.getId())
|
|
||||||
.eq(HotVehicle::getCompanyId, companyId));
|
|
||||||
}
|
|
||||||
return impactedDriverIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Set<String> findOtherDriversBoundToVehicles(Long companyId, Collection<String> vehicleIds, String excludeDriverId) {
|
|
||||||
Set<String> driverIds = new LinkedHashSet<>();
|
|
||||||
if (companyId == null || CollUtil.isEmpty(vehicleIds)) {
|
|
||||||
return driverIds;
|
|
||||||
}
|
|
||||||
List<HotVehicle> vehicles = vehicleMapper.selectList(Wrappers.<HotVehicle>lambdaQuery()
|
|
||||||
.eq(HotVehicle::getCompanyId, companyId)
|
|
||||||
.in(HotVehicle::getId, vehicleIds)
|
|
||||||
.eq(HotVehicle::getIsDeleted, 0L));
|
|
||||||
for (HotVehicle vehicle : vehicles) {
|
|
||||||
for (String driverId : splitCsv(vehicle.getCurrentDriver())) {
|
|
||||||
if (!StringUtils.equals(driverId, excludeDriverId)) {
|
|
||||||
driverIds.add(driverId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return driverIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void syncDriverVehicleRelationsByDriverIds(Long companyId, Collection<String> driverIds) {
|
|
||||||
if (companyId == null || CollUtil.isEmpty(driverIds)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<HotVehicle> vehicles = vehicleMapper.selectList(Wrappers.<HotVehicle>lambdaQuery()
|
|
||||||
.eq(HotVehicle::getCompanyId, companyId)
|
|
||||||
.eq(HotVehicle::getIsDeleted, 0L));
|
|
||||||
for (String driverId : driverIds) {
|
|
||||||
if (StringUtils.isBlank(driverId)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
List<String> vehicleIds = new ArrayList<>();
|
|
||||||
List<String> plateNumbers = new ArrayList<>();
|
|
||||||
for (HotVehicle vehicle : vehicles) {
|
|
||||||
if (!splitCsv(vehicle.getCurrentDriver()).contains(driverId)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
vehicleIds.add(vehicle.getId());
|
|
||||||
plateNumbers.add(vehicle.getPlateNumber());
|
|
||||||
}
|
|
||||||
driverMapper.update(null, new LambdaUpdateWrapper<HotDriver>()
|
|
||||||
.set(HotDriver::getVehicleId, joinCsv(vehicleIds))
|
|
||||||
.set(HotDriver::getPlateNumber, joinCsv(plateNumbers))
|
|
||||||
.eq(HotDriver::getId, driverId)
|
|
||||||
.eq(HotDriver::getCompanyId, companyId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> splitCsv(String value) {
|
|
||||||
if (StringUtils.isBlank(value)) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
return Arrays.stream(value.split(","))
|
|
||||||
.map(String::trim)
|
|
||||||
.filter(StringUtils::isNotBlank)
|
|
||||||
.distinct()
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private String joinCsv(Collection<String> values) {
|
|
||||||
if (CollUtil.isEmpty(values)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return values.stream()
|
|
||||||
.filter(StringUtils::isNotBlank)
|
|
||||||
.distinct()
|
|
||||||
.collect(Collectors.joining(","));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String normalizeSingleBindingValue(Collection<String> values) {
|
|
||||||
if (CollUtil.isEmpty(values)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return values.stream()
|
|
||||||
.filter(StringUtils::isNotBlank)
|
|
||||||
.findFirst()
|
|
||||||
.orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存驾驶员家庭成员
|
* 保存驾驶员家庭成员
|
||||||
*/
|
*/
|
||||||
@@ -1125,25 +997,6 @@ public class HotDriverServiceImpl implements IHotDriverService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> impactedDriverIds = new LinkedHashSet<>();
|
|
||||||
impactedDriverIds.add(driverId);
|
|
||||||
List<HotVehicle> vehicles = vehicleMapper.selectList(Wrappers.<HotVehicle>lambdaQuery()
|
|
||||||
.eq(HotVehicle::getCompanyId, companyId)
|
|
||||||
.eq(HotVehicle::getIsDeleted, 0L));
|
|
||||||
for (HotVehicle vehicle : vehicles) {
|
|
||||||
List<String> driverIds = splitCsv(vehicle.getCurrentDriver());
|
|
||||||
if (!driverIds.contains(driverId)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
driverIds.removeIf(driverId::equals);
|
|
||||||
impactedDriverIds.addAll(driverIds);
|
|
||||||
vehicleMapper.update(null, new LambdaUpdateWrapper<HotVehicle>()
|
|
||||||
.set(HotVehicle::getCurrentDriver, normalizeSingleBindingValue(driverIds))
|
|
||||||
.eq(HotVehicle::getId, vehicle.getId())
|
|
||||||
.eq(HotVehicle::getCompanyId, companyId));
|
|
||||||
}
|
|
||||||
syncDriverVehicleRelationsByDriverIds(companyId, impactedDriverIds);
|
|
||||||
|
|
||||||
// 2. 将该驾驶员从所有组中移除
|
// 2. 将该驾驶员从所有组中移除
|
||||||
// 查找包含该驾驶员的所有组
|
// 查找包含该驾驶员的所有组
|
||||||
List<HotDriverGroup> groups = groupMapper.selectList(
|
List<HotDriverGroup> groups = groupMapper.selectList(
|
||||||
|
|||||||
@@ -165,50 +165,15 @@ public class HotVehicleChangeServiceImpl implements IHotVehicleChangeService {
|
|||||||
.filter(StringUtils::isNotBlank)
|
.filter(StringUtils::isNotBlank)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if (!driverIds.isEmpty()) {
|
if (!driverIds.isEmpty()) {
|
||||||
for (String driverId : driverIds) {
|
driverMapper.update(null, new LambdaUpdateWrapper<HotDriver>()
|
||||||
recalculateDriverVehicleRelations(driverId, bo.getCompanyId());
|
.set(HotDriver::getVehicleId, null)
|
||||||
}
|
.set(HotDriver::getPlateNumber, null)
|
||||||
|
.in(HotDriver::getId, driverIds)
|
||||||
|
.eq(HotDriver::getCompanyId, bo.getCompanyId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void recalculateDriverVehicleRelations(String driverId, Long companyId) {
|
|
||||||
if (StringUtils.isBlank(driverId) || companyId == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<HotVehicle> vehicles = vehicleMapper.selectList(Wrappers.<HotVehicle>lambdaQuery()
|
|
||||||
.eq(HotVehicle::getCompanyId, companyId)
|
|
||||||
.eq(HotVehicle::getIsDeleted, 0L));
|
|
||||||
List<String> vehicleIds = new ArrayList<>();
|
|
||||||
List<String> plateNumbers = new ArrayList<>();
|
|
||||||
for (HotVehicle item : vehicles) {
|
|
||||||
List<String> currentDrivers = Arrays.stream(StringUtils.defaultString(item.getCurrentDriver()).split(","))
|
|
||||||
.map(String::trim)
|
|
||||||
.filter(StringUtils::isNotBlank)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
if (!currentDrivers.contains(driverId)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
vehicleIds.add(item.getId());
|
|
||||||
plateNumbers.add(item.getPlateNumber());
|
|
||||||
}
|
|
||||||
driverMapper.update(null, new LambdaUpdateWrapper<HotDriver>()
|
|
||||||
.set(HotDriver::getVehicleId, joinCsv(vehicleIds))
|
|
||||||
.set(HotDriver::getPlateNumber, joinCsv(plateNumbers))
|
|
||||||
.eq(HotDriver::getId, driverId)
|
|
||||||
.eq(HotDriver::getCompanyId, companyId));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String joinCsv(Collection<String> values) {
|
|
||||||
if (values == null || values.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return values.stream()
|
|
||||||
.filter(StringUtils::isNotBlank)
|
|
||||||
.distinct()
|
|
||||||
.collect(Collectors.joining(","));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验并批量删除车辆变更记录信息
|
* 校验并批量删除车辆变更记录信息
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -367,9 +367,7 @@ public class HotVehicleServiceImpl implements IHotVehicleService {
|
|||||||
lqw.eq(bo.getIsTrailer() != null, HotVehicle::getIsTrailer, bo.getIsTrailer());
|
lqw.eq(bo.getIsTrailer() != null, HotVehicle::getIsTrailer, bo.getIsTrailer());
|
||||||
lqw.eq(bo.getVehicleStatus() != null, HotVehicle::getVehicleStatus, bo.getVehicleStatus());
|
lqw.eq(bo.getVehicleStatus() != null, HotVehicle::getVehicleStatus, bo.getVehicleStatus());
|
||||||
lqw.in(HotVehicle::getOperationStatus, Arrays.asList(bo.getOperationStatus().split(",")));
|
lqw.in(HotVehicle::getOperationStatus, Arrays.asList(bo.getOperationStatus().split(",")));
|
||||||
lqw.and(wrapper -> wrapper.isNull(HotVehicle::getCurrentDriver)
|
lqw.eq(StringUtils.isNotBlank(bo.getCurrentDriver()), HotVehicle::getCurrentDriver, bo.getCurrentDriver());
|
||||||
.or()
|
|
||||||
.eq(HotVehicle::getCurrentDriver, ""));
|
|
||||||
lqw.eq(StringUtils.isNotBlank(bo.getBodyImageUrls()), HotVehicle::getBodyImageUrls, bo.getBodyImageUrls());
|
lqw.eq(StringUtils.isNotBlank(bo.getBodyImageUrls()), HotVehicle::getBodyImageUrls, bo.getBodyImageUrls());
|
||||||
lqw.eq(StringUtils.isNotBlank(bo.getOtherAttachmentUrls()), HotVehicle::getOtherAttachmentUrls, bo.getOtherAttachmentUrls());
|
lqw.eq(StringUtils.isNotBlank(bo.getOtherAttachmentUrls()), HotVehicle::getOtherAttachmentUrls, bo.getOtherAttachmentUrls());
|
||||||
lqw.eq(StringUtils.isNotBlank(bo.getColor()), HotVehicle::getColor, bo.getColor());
|
lqw.eq(StringUtils.isNotBlank(bo.getColor()), HotVehicle::getColor, bo.getColor());
|
||||||
@@ -527,14 +525,10 @@ public class HotVehicleServiceImpl implements IHotVehicleService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Boolean updateByBo(HotVehicleBo bo) {
|
public Boolean updateByBo(HotVehicleBo bo) {
|
||||||
validateSingleCurrentDriverBinding(bo.getCurrentDriver());
|
|
||||||
// 获取旧数据用于比对
|
// 获取旧数据用于比对
|
||||||
HotVehicle oldVehicle = baseMapper.selectById(bo.getId());
|
HotVehicle oldVehicle = baseMapper.selectById(bo.getId());
|
||||||
|
|
||||||
HotVehicle update = MapstructUtils.convert(bo, HotVehicle.class);
|
HotVehicle update = MapstructUtils.convert(bo, HotVehicle.class);
|
||||||
String normalizedCurrentDriver = normalizeSingleBindingValue(update.getCurrentDriver());
|
|
||||||
update.setCurrentDriver(normalizedCurrentDriver);
|
|
||||||
bo.setCurrentDriver(normalizedCurrentDriver);
|
|
||||||
if (update.getOperationStatus() != null && CLEAR_DRIVER_OPERATION_STATUS.contains(update.getOperationStatus())) {
|
if (update.getOperationStatus() != null && CLEAR_DRIVER_OPERATION_STATUS.contains(update.getOperationStatus())) {
|
||||||
update.setCurrentDriver(null);
|
update.setCurrentDriver(null);
|
||||||
bo.setCurrentDriver(null);
|
bo.setCurrentDriver(null);
|
||||||
@@ -545,14 +539,60 @@ public class HotVehicleServiceImpl implements IHotVehicleService {
|
|||||||
String vehicleId = update.getId();
|
String vehicleId = update.getId();
|
||||||
Long companyId = update.getCompanyId();
|
Long companyId = update.getCompanyId();
|
||||||
|
|
||||||
// 处理驾驶员变更:车辆侧只允许单个驾驶员,驾驶员侧回写多车列表
|
// 处理驾驶员变更:同步驾驶员信息的车牌号
|
||||||
List<String> oldDriverIds = splitCsv(oldVehicle != null ? oldVehicle.getCurrentDriver() : null);
|
String oldDriverId = oldVehicle != null ? oldVehicle.getCurrentDriver() : null;
|
||||||
List<String> newDriverIds = splitCsv(update.getCurrentDriver());
|
String newDriverId = update.getCurrentDriver();
|
||||||
String oldDriverId = oldDriverIds.isEmpty() ? null : oldDriverIds.get(0);
|
|
||||||
String newDriverId = newDriverIds.isEmpty() ? null : newDriverIds.get(0);
|
|
||||||
String oldPlate = oldVehicle != null ? oldVehicle.getPlateNumber() : null;
|
String oldPlate = oldVehicle != null ? oldVehicle.getPlateNumber() : null;
|
||||||
String newPlate = update.getPlateNumber();
|
String newPlate = update.getPlateNumber();
|
||||||
boolean bindingChanged = !oldDriverIds.equals(newDriverIds) || !StringUtils.equals(oldPlate, newPlate);
|
|
||||||
|
// 如果驾驶员发生变化 或 车牌号发生变化
|
||||||
|
if (!StringUtils.equals(oldDriverId, newDriverId) || !StringUtils.equals(oldPlate, newPlate)) {
|
||||||
|
List<String> oldDrivers = StringUtils.isBlank(oldDriverId) ? new ArrayList<>() : Arrays.asList(oldDriverId.split(","));
|
||||||
|
List<String> newDrivers = StringUtils.isBlank(newDriverId) ? new ArrayList<>() : Arrays.asList(newDriverId.split(","));
|
||||||
|
|
||||||
|
// 1. 处理移除的驾驶员 (在旧列表中但不在新列表中 -> 清除车牌关联)
|
||||||
|
List<String> removedDrivers = oldDrivers.stream()
|
||||||
|
.filter(d -> !newDrivers.contains(d))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (CollUtil.isNotEmpty(removedDrivers)) {
|
||||||
|
driverMapper.update(null,
|
||||||
|
new LambdaUpdateWrapper<HotDriver>()
|
||||||
|
.set(HotDriver::getPlateNumber, null)
|
||||||
|
.set(HotDriver::getVehicleId, null)
|
||||||
|
.in(HotDriver::getId, removedDrivers)
|
||||||
|
.eq(HotDriver::getCompanyId, companyId));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 处理当前的驾驶员 (无论是新增的还是保留的,都统一更新为当前车辆信息)
|
||||||
|
if (CollUtil.isNotEmpty(newDrivers)) {
|
||||||
|
driverMapper.update(null,
|
||||||
|
new LambdaUpdateWrapper<HotDriver>()
|
||||||
|
.set(HotDriver::getPlateNumber, newPlate)
|
||||||
|
.set(HotDriver::getVehicleId, vehicleId)
|
||||||
|
.in(HotDriver::getId, newDrivers)
|
||||||
|
.eq(HotDriver::getCompanyId, companyId));
|
||||||
|
// 2.1 对新增绑定的驾驶员发送系统消息
|
||||||
|
List<String> addedDrivers = newDrivers.stream()
|
||||||
|
.filter(d -> !oldDrivers.contains(d))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollUtil.isNotEmpty(addedDrivers) && StringUtils.isNotBlank(newPlate)) {
|
||||||
|
HotSystemNotificationGroupBo bos = new HotSystemNotificationGroupBo();
|
||||||
|
bos.setLevel("普通");
|
||||||
|
bos.setContent("您已经绑定车辆【" + newPlate + "】。");
|
||||||
|
bos.setSourceType("驾驶员管理");
|
||||||
|
bos.setSenderType("SYSTEM");
|
||||||
|
bos.setReceiverType("驾驶员");
|
||||||
|
bos.setReceiverIds(addedDrivers);
|
||||||
|
bos.setIsDeleted(0L);
|
||||||
|
try {
|
||||||
|
notificationService.insertByBo(bos);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("发送驾驶员绑定车辆通知失败 companyId={} vehicleId={} plate={}", companyId, vehicleId, newPlate, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 更新合同信息
|
// 更新合同信息
|
||||||
if (CollUtil.isNotEmpty(bo.getVehicleContracts())) {
|
if (CollUtil.isNotEmpty(bo.getVehicleContracts())) {
|
||||||
@@ -627,29 +667,6 @@ public class HotVehicleServiceImpl implements IHotVehicleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (flag) {
|
if (flag) {
|
||||||
if (bindingChanged && companyId != null) {
|
|
||||||
Set<String> impactedDriverIds = new LinkedHashSet<>();
|
|
||||||
impactedDriverIds.addAll(oldDriverIds);
|
|
||||||
impactedDriverIds.addAll(newDriverIds);
|
|
||||||
syncDriverVehicleRelationsByDriverIds(companyId, impactedDriverIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(newDriverId) && !oldDriverIds.contains(newDriverId) && StringUtils.isNotBlank(newPlate)) {
|
|
||||||
HotSystemNotificationGroupBo bos = new HotSystemNotificationGroupBo();
|
|
||||||
bos.setLevel("普通");
|
|
||||||
bos.setContent("您已经绑定车辆【" + newPlate + "】。");
|
|
||||||
bos.setSourceType("驾驶员管理");
|
|
||||||
bos.setSenderType("SYSTEM");
|
|
||||||
bos.setReceiverType("驾驶员");
|
|
||||||
bos.setReceiverIds(Collections.singletonList(newDriverId));
|
|
||||||
bos.setIsDeleted(0L);
|
|
||||||
try {
|
|
||||||
notificationService.insertByBo(bos);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.warn("发送驾驶员绑定车辆通知失败 companyId={} vehicleId={} plate={}", companyId, vehicleId, newPlate, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Long oldVehicleStatus = oldVehicle != null ? oldVehicle.getVehicleStatus() : null;
|
Long oldVehicleStatus = oldVehicle != null ? oldVehicle.getVehicleStatus() : null;
|
||||||
Long newVehicleStatus = update.getVehicleStatus();
|
Long newVehicleStatus = update.getVehicleStatus();
|
||||||
Long oldOperationStatus = oldVehicle != null ? oldVehicle.getOperationStatus() : null;
|
Long oldOperationStatus = oldVehicle != null ? oldVehicle.getOperationStatus() : null;
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ public class HotHiddenDangerInspectionServiceImpl implements IHotHiddenDangerIns
|
|||||||
if (isDriver) {
|
if (isDriver) {
|
||||||
HotDriver driver = DriverLoginContextHelper.getCurrentDriver();
|
HotDriver driver = DriverLoginContextHelper.getCurrentDriver();
|
||||||
driverId = driver.getId();
|
driverId = driver.getId();
|
||||||
vehicleId = firstCsvValue(driver.getVehicleId());
|
vehicleId = driver.getVehicleId();
|
||||||
}
|
}
|
||||||
String currentMonth = YearMonth.now().toString();
|
String currentMonth = YearMonth.now().toString();
|
||||||
Page<HotHiddenDangerInspectionVo> page = pageQuery.build();
|
Page<HotHiddenDangerInspectionVo> page = pageQuery.build();
|
||||||
@@ -109,19 +109,6 @@ public class HotHiddenDangerInspectionServiceImpl implements IHotHiddenDangerIns
|
|||||||
return TableDataInfo.build(page);
|
return TableDataInfo.build(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String firstCsvValue(String value) {
|
|
||||||
if (StringUtils.isBlank(value)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
for (String item : value.split(",")) {
|
|
||||||
String trimmed = StringUtils.trim(item);
|
|
||||||
if (StringUtils.isNotBlank(trimmed)) {
|
|
||||||
return trimmed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询符合条件的隐患排查-排查项目列表
|
* 查询符合条件的隐患排查-排查项目列表
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ public class SysUserController extends BaseController {
|
|||||||
if (StringUtils.isNotBlank(user.getBusinessUserId())) {
|
if (StringUtils.isNotBlank(user.getBusinessUserId())) {
|
||||||
HotDriverVo driver = hotDriverService.queryById(user.getBusinessUserId());
|
HotDriverVo driver = hotDriverService.queryById(user.getBusinessUserId());
|
||||||
if (driver != null) {
|
if (driver != null) {
|
||||||
user.setVehicleId(firstCsvValue(driver.getVehicleId()));
|
user.setVehicleId(driver.getVehicleId());
|
||||||
user.setDriverAuditStatus(String.valueOf(driver.getAuditStatus()));
|
user.setDriverAuditStatus(String.valueOf(driver.getAuditStatus()));
|
||||||
user.setHasFaceInitialPhoto(StringUtils.isNotBlank(driver.getPortraitUrl()));
|
user.setHasFaceInitialPhoto(StringUtils.isNotBlank(driver.getPortraitUrl()));
|
||||||
user.setUserName(driver.getName());
|
user.setUserName(driver.getName());
|
||||||
@@ -237,19 +237,6 @@ public class SysUserController extends BaseController {
|
|||||||
return R.ok(userInfoVo);
|
return R.ok(userInfoVo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String firstCsvValue(String value) {
|
|
||||||
if (StringUtils.isBlank(value)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
for (String item : value.split(",")) {
|
|
||||||
String trimmed = StringUtils.trim(item);
|
|
||||||
if (StringUtils.isNotBlank(trimmed)) {
|
|
||||||
return trimmed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] compressImage(MultipartFile file) throws Exception {
|
private byte[] compressImage(MultipartFile file) throws Exception {
|
||||||
java.awt.image.BufferedImage src = javax.imageio.ImageIO.read(file.getInputStream());
|
java.awt.image.BufferedImage src = javax.imageio.ImageIO.read(file.getInputStream());
|
||||||
if (src == null) {
|
if (src == null) {
|
||||||
@@ -412,7 +399,7 @@ public class SysUserController extends BaseController {
|
|||||||
// 但根据用户要求“重置密码也是需要通过公司id来修改子密码”,前端应该传companyId。
|
// 但根据用户要求“重置密码也是需要通过公司id来修改子密码”,前端应该传companyId。
|
||||||
// 如果没传,可能是旧接口调用,或者意图重置所有。
|
// 如果没传,可能是旧接口调用,或者意图重置所有。
|
||||||
// 这里直接传递 user.getCompanyId(),让Service层判断。
|
// 这里直接传递 user.getCompanyId(),让Service层判断。
|
||||||
|
|
||||||
user.setPassword(BCrypt.hashpw(user.getPassword()));
|
user.setPassword(BCrypt.hashpw(user.getPassword()));
|
||||||
return toAjax(userService.resetUserPwd(user.getUserId(), user.getPassword(), user.getCompanyId()));
|
return toAjax(userService.resetUserPwd(user.getUserId(), user.getPassword(), user.getCompanyId()));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user