Compare commits

...

2 Commits

Author SHA1 Message Date
9789bea999 redis 2026-05-23 11:23:26 +08:00
d6d982a896 一人多车,数据源 2026-05-23 11:14:48 +08:00
7 changed files with 162 additions and 18 deletions

View File

@@ -6,12 +6,13 @@
1. 三检流程未完成时,禁止进行车辆换绑操作。
2. 三检流程未完成时,禁止新增出车检查。
3. 新增查询接口:返回指定驾驶员已绑定车辆列表,以及所在公司仍可绑定车辆列表
4. 新增查询接口:返回指定驾驶员已绑定车辆列表。
5. 新增覆盖式批量绑定接口前端传驾驶员ID和车辆ID串后端先清空该驾驶员原有绑定再绑定最新车辆列表。
6. 新增追加式批量绑定接口前端传驾驶员ID和车辆ID串后端保留该驾驶员有绑定,仅追加绑定新车辆。
7. 驾驶员表保留单值字段 `vehicleId` 作为默认车辆ID
8. 驾驶员表新增字段 `vehicleIds`用于存储已绑定车辆ID集合多个以英文逗号分隔
3. 新增驾驶员自助切换默认车辆接口,允许当前登录驾驶员在自己已绑定车辆之间切换 `vehicleId`
4. 新增查询接口:返回指定驾驶员已绑定车辆列表,以及所在公司仍可绑定的车辆列表
5. 新增查询接口:仅返回指定驾驶员已绑定车辆列表。
6. 新增覆盖式批量绑定接口前端传驾驶员ID和车辆ID串后端先清空该驾驶员有绑定,绑定新车辆列表
7. 新增追加式批量绑定接口前端传驾驶员ID和车辆ID串后端保留该驾驶员已有绑定仅追加绑定新车辆
8. 驾驶员表保留单值字段 `vehicleId` 作为默认车辆ID
9. 驾驶员表新增字段 `vehicleIds`用于存储已绑定车辆ID集合多个以英文逗号分隔。
## 2. 三检限制规则
@@ -25,7 +26,18 @@
- 提示文案:
- `当前车辆三检流程未完成,不可进行换绑操作`
### 2.2 新增出车检查限制
### 2.2 默认车辆切换限制
- 生效范围:
- 当前登录驾驶员调用默认车辆切换接口时
- 限制规则:
- 仅允许切换到当前驾驶员自己已绑定的车辆
- 切换前要求当前默认车辆对应三检流程已完成
- 提示文案:
- 非本人车辆:`驾驶员只能切换属于自己的车辆`
- 当前车未完成三检:`当前车辆三检流程未完成,不可切换车辆`
### 2.3 新增出车检查限制
- 生效范围:
- 新增车辆进出场检查接口
@@ -34,7 +46,7 @@
- 提示文案:
- `当前车辆三检流程未完成,不能新增出车检查`
### 2.3 未完成三检流程判定
### 2.4 未完成三检流程判定
- 判定口径:
- 查询车辆最新一条三检记录
@@ -140,10 +152,48 @@
- `currentDriverName`:当前绑定驾驶员姓名
- `vehicleType`:车辆类型
## 6. 驾驶员追加批量绑定车辆接口
## 6. 驾驶员切换默认车辆接口
### 6.1 接口信息
- 路径:`POST /driverManagement/driver/switchVehicle`
- 说明:当前登录驾驶员自助切换默认车辆
### 6.2 请求体
```json
{
"vehicleId": "1002"
}
```
### 6.3 参数说明
- `vehicleId`必填目标车辆ID
### 6.4 业务规则
接口执行过程如下:
1. 仅允许驾驶员端已登录用户调用。
2. 根据当前登录信息获取驾驶员,不允许前端指定其他 `driverId`
3. 校验目标 `vehicleId` 必须存在于当前驾驶员的 `vehicleIds` 中。
4. 校验目标车辆当前 `currentDriver` 仍然包含当前驾驶员,防止脏数据误切换。
5. 若切换前当前默认车辆存在未完成三检流程,则禁止切换。
6. 切换成功后仅更新驾驶员表中的:
- `vehicleId`切换后的默认车辆ID
- `plateNumber`:切换后默认车辆对应车牌号
7. `vehicleIds` 不变,车辆表 `currentDriver` 不变。
### 6.5 返回结果
- 成功:返回通用成功响应
- 失败:抛出业务异常并返回对应提示
## 7. 驾驶员追加批量绑定车辆接口
### 7.1 接口信息
- 路径:`POST /driverManagement/driver/appendBindVehicles`
- 请求体:
@@ -154,7 +204,7 @@
}
```
### 6.2 业务规则
### 7.2 业务规则
接口执行过程如下:
@@ -169,9 +219,9 @@
- `vehicleIds`
- `plateNumber`
## 7. 驾驶员解除绑定接口
## 8. 驾驶员解除绑定接口
### 7.1 接口信息
### 8.1 接口信息
- 路径:`POST /driverManagement/driver/unbindVehicles`
- 请求体:
@@ -183,7 +233,7 @@
}
```
### 7.2 参数说明
### 8.2 参数说明
- `driverId`必填驾驶员ID
- `vehicleIds`
@@ -192,7 +242,7 @@
- 为空时表示清空该驾驶员当前全部绑定车辆
- 有值时表示仅解绑指定车辆
### 7.3 业务规则
### 8.3 业务规则
接口执行过程如下:
@@ -207,7 +257,7 @@
- `vehicleIds`
- `plateNumber`
## 8. 绑定模型说明
## 9. 绑定模型说明
- 当前车辆表实际是一车单人绑定,`currentDriver` 仅保留单个驾驶员ID。
- 驾驶员表支持一个驾驶员绑定多辆车:
@@ -219,7 +269,7 @@
- 驾驶员侧允许关联多辆车
- 移动端与司机端默认取 `vehicleId` 作为当前车辆
## 9. 数据库脚本
## 10. 数据库脚本
- 脚本文件:`sql/alter_hot_driver_vehicle_ids_20260522.sql`
- 脚本内容:

View File

@@ -6,6 +6,7 @@ import com.hotwj.platform.driverManagement.driver.domain.bo.DriverRegisterBo;
import com.hotwj.platform.driverManagement.driver.domain.bo.HotDriverBatchBindVehicleBo;
import com.hotwj.platform.driverManagement.driver.domain.bo.HotDriverBo;
import com.hotwj.platform.driverManagement.driver.domain.bo.HotDriverPasswordBo;
import com.hotwj.platform.driverManagement.driver.domain.bo.HotDriverSwitchVehicleBo;
import com.hotwj.platform.driverManagement.driver.domain.vo.HotDriverImportVo;
import com.hotwj.platform.driverManagement.driver.domain.vo.HotDriverLedgerExportVo;
import com.hotwj.platform.driverManagement.driver.domain.vo.HotDriverVo;
@@ -309,6 +310,17 @@ public class HotDriverController extends BaseController {
return toAjax(hotDriverService.unbindVehicles(bo));
}
/**
* 当前登录驾驶员切换默认车辆
*/
@Log(title = "驾驶员切换默认车辆", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PostMapping("/switchVehicle")
@Operation(summary = "当前登录驾驶员切换默认车辆")
public R<Void> switchVehicle(@Validated @RequestBody HotDriverSwitchVehicleBo bo) {
return toAjax(hotDriverService.switchVehicle(bo));
}
/**
* 企业负责人修改驾驶员登录密码
*

View File

@@ -0,0 +1,20 @@
package com.hotwj.platform.driverManagement.driver.domain.bo;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
/**
* 驾驶员切换默认车辆请求对象
*
* @author shihongwei
* @date 2026-05-23
*/
@Data
public class HotDriverSwitchVehicleBo {
/**
* 目标车辆ID
*/
@NotBlank(message = "目标车辆ID不能为空")
private String vehicleId;
}

View File

@@ -3,6 +3,7 @@ package com.hotwj.platform.driverManagement.driver.service;
import com.hotwj.platform.driverManagement.driver.domain.bo.DriverRegisterBo;
import com.hotwj.platform.driverManagement.driver.domain.bo.HotDriverBatchBindVehicleBo;
import com.hotwj.platform.driverManagement.driver.domain.bo.HotDriverBo;
import com.hotwj.platform.driverManagement.driver.domain.bo.HotDriverSwitchVehicleBo;
import com.hotwj.platform.driverManagement.driver.domain.vo.HotDriverImportVo;
import com.hotwj.platform.driverManagement.driver.domain.vo.HotDriverVo;
import org.dromara.common.mybatis.core.page.PageQuery;
@@ -84,6 +85,14 @@ public interface IHotDriverService {
*/
Boolean unbindVehicles(HotDriverBatchBindVehicleBo bo);
/**
* 当前登录驾驶员切换默认车辆
*
* @param bo 切换信息
* @return 是否成功
*/
Boolean switchVehicle(HotDriverSwitchVehicleBo bo);
/**
* 审核驾驶员账号
*

View File

@@ -7,11 +7,13 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hotwj.platform.common.helper.DriverLoginContextHelper;
import com.hotwj.platform.common.utils.PasswordUtils;
import com.hotwj.platform.driverManagement.driver.domain.HotDriver;
import com.hotwj.platform.driverManagement.driver.domain.bo.DriverRegisterBo;
import com.hotwj.platform.driverManagement.driver.domain.bo.HotDriverBatchBindVehicleBo;
import com.hotwj.platform.driverManagement.driver.domain.bo.HotDriverBo;
import com.hotwj.platform.driverManagement.driver.domain.bo.HotDriverSwitchVehicleBo;
import com.hotwj.platform.driverManagement.driver.domain.vo.HotDriverImportVo;
import com.hotwj.platform.driverManagement.driver.domain.vo.HotDriverVo;
import com.hotwj.platform.driverManagement.driver.mapper.HotDriverMapper;
@@ -972,6 +974,57 @@ public class HotDriverServiceImpl implements IHotDriverService {
return true;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean switchVehicle(HotDriverSwitchVehicleBo bo) {
HotDriver driver = DriverLoginContextHelper.getCurrentDriver();
if (driver == null || Long.valueOf(1L).equals(driver.getIsDeleted())) {
throw new ServiceException("驾驶员不存在");
}
if (driver.getCompanyId() == null) {
throw new ServiceException("驾驶员所属公司不能为空");
}
String targetVehicleId = StringUtils.trimToNull(bo.getVehicleId());
if (StringUtils.isBlank(targetVehicleId)) {
throw new ServiceException("目标车辆ID不能为空");
}
List<String> boundVehicleIds = getBoundVehicleIds(driver);
if (CollUtil.isEmpty(boundVehicleIds)) {
throw new ServiceException("当前驾驶员未绑定车辆,不能切换");
}
if (!boundVehicleIds.contains(targetVehicleId)) {
throw new ServiceException("驾驶员只能切换属于自己的车辆");
}
if (StringUtils.equals(driver.getVehicleId(), targetVehicleId)) {
return true;
}
if (StringUtils.isBlank(driver.getVehicleId())) {
throw new ServiceException("当前默认车辆不存在,不能切换");
}
hotVehicleThreeInspectService.validateNoUnfinishedProcess(driver.getVehicleId(), "当前车辆三检流程未完成,不可切换车辆");
HotVehicle targetVehicle = vehicleMapper.selectOne(Wrappers.<HotVehicle>lambdaQuery()
.eq(HotVehicle::getId, targetVehicleId)
.eq(HotVehicle::getCompanyId, driver.getCompanyId())
.eq(HotVehicle::getIsDeleted, 0L)
.last("limit 1"));
if (targetVehicle == null) {
throw new ServiceException("目标车辆不存在");
}
if (!splitCsv(targetVehicle.getCurrentDriver()).contains(driver.getId())) {
throw new ServiceException("驾驶员只能切换属于自己的车辆");
}
return baseMapper.update(null, new LambdaUpdateWrapper<HotDriver>()
.set(HotDriver::getVehicleId, targetVehicle.getId())
.set(HotDriver::getPlateNumber, targetVehicle.getPlateNumber())
.eq(HotDriver::getId, driver.getId())
.eq(HotDriver::getCompanyId, driver.getCompanyId())) > 0;
}
/**
* 移除用户在特定企业的司机端登录权限
*/

View File

@@ -73,7 +73,7 @@ spring.data:
# 端口默认为6379
port: 63799
# 数据库索引
database: 12
database: 13
# redis 密码必须配置
password: test13579
# 连接超时时间

View File

@@ -17,7 +17,7 @@ spring:
driverClassName: com.mysql.cj.jdbc.Driver
# jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562
# rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题)
url: jdbc:mysql://172.21.143.42:33060/wucaixing?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
url: jdbc:mysql://172.21.143.42:33060/color?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
username: root
password: Hot20260401
# # 从库数据源