|
|
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import org.dromara.common.core.exception.ServiceException;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
@@ -86,6 +87,7 @@ public class TblDzbcDriverTripServiceImpl implements ITblDzbcDriverTripService {
|
|
|
trip.setExt2(bo.getExt2());
|
|
|
trip.setStatus(0);
|
|
|
|
|
|
+ validEntityBeforeSave(trip);
|
|
|
baseMapper.insert(trip);
|
|
|
|
|
|
TblDzbcDriverTripVo vo = queryById(trip.getId());
|
|
|
@@ -162,6 +164,33 @@ public class TblDzbcDriverTripServiceImpl implements ITblDzbcDriverTripService {
|
|
|
}
|
|
|
|
|
|
private void validEntityBeforeSave(TblDzbcDriverTrip entity) {
|
|
|
+ // 校验同一时间的同一辆车只能发车一次
|
|
|
+ if (entity.getCarId() != null || entity.getStartTime() != null) {
|
|
|
+ Long carId = entity.getCarId();
|
|
|
+ LocalDateTime startTime = entity.getStartTime();
|
|
|
+
|
|
|
+ // 如果是更新操作,且字段缺失,需要查询数据库补充
|
|
|
+ if (entity.getId() != null) {
|
|
|
+ TblDzbcDriverTrip old = baseMapper.selectById(entity.getId());
|
|
|
+ if (old != null) {
|
|
|
+ if (carId == null) carId = old.getCarId();
|
|
|
+ if (startTime == null) startTime = old.getStartTime();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (carId != null && startTime != null) {
|
|
|
+ LambdaQueryWrapper<TblDzbcDriverTrip> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(TblDzbcDriverTrip::getCarId, carId);
|
|
|
+ lqw.eq(TblDzbcDriverTrip::getStartTime, startTime);
|
|
|
+ lqw.ne(TblDzbcDriverTrip::getStatus, 3); // 排除已取消
|
|
|
+ if (entity.getId() != null) {
|
|
|
+ lqw.ne(TblDzbcDriverTrip::getId, entity.getId());
|
|
|
+ }
|
|
|
+ if (baseMapper.selectCount(lqw) > 0) {
|
|
|
+ throw new ServiceException("该车辆在该时间段已有任务");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void fillDetails(TblDzbcDriverTripVo vo) {
|