| | |
| | | package com.ruoyi.tms.service.impl; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.io.File; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.util.*; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.file.FileUploadUtils; |
| | | import com.ruoyi.common.utils.uuid.Seq; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.tms.domain.*; |
| | | import com.ruoyi.tms.mapper.TmsDispatchOrderMapper; |
| | | import com.ruoyi.tms.mapper.TmsDriverDispatchMapper; |
| | | import com.ruoyi.tms.mapper.TmsDriverMapper; |
| | | import com.ruoyi.tms.mapper.*; |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.springframework.amqp.rabbit.core.RabbitTemplate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.annotation.DataSource; |
| | | import com.ruoyi.common.enums.DataSourceType; |
| | | import com.ruoyi.common.core.service.BaseService; |
| | | |
| | | import com.ruoyi.tms.mapper.TmsTripMapper; |
| | | import com.ruoyi.tms.service.ITmsTripService; |
| | | import com.ruoyi.common.core.text.Convert; |
| | | |
| | |
| | | private TmsDriverMapper tmsDriverMapper; |
| | | @Autowired |
| | | private TmsVehicleServiceImpl tmsVehicleServiceImpl; |
| | | @Resource |
| | | private TmsCarKeyDispatchMapper tmsCarKeyDispatchMapper; |
| | | @Autowired |
| | | private RabbitTemplate rabbitTemplate; |
| | | |
| | | @Autowired |
| | | private AsyncPdfService asyncPdfService; |
| | | /** |
| | | * 查询行程 |
| | | * |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int insertTmsTrip(TmsTrip tmsTrip) |
| | | { |
| | | public int insertTmsTrip(TmsTrip tmsTrip) throws Exception { |
| | | Integer dispatchOrderId = tmsTrip.getDispatchOrderId(); |
| | | TmsDispatchOrder tmsDispatchOrder = tmsDispatchOrderMapper.selectTmsDispatchOrderById(dispatchOrderId); |
| | | if (tmsDispatchOrder == null){ |
| | |
| | | if (tmsDispatchOrder.getStatus() != 1 && tmsDispatchOrder.getStatus() != 2){ |
| | | throw new RuntimeException("调度单数据状态异常"); |
| | | } |
| | | TmsDriver tmsDriver = tmsDriverMapper.selectTmsDriverById(tmsDispatchOrder.getMainDriverId()); |
| | | if (tmsDriver == null){ |
| | | throw new RuntimeException("未找到司机数据"); |
| | | } |
| | | |
| | | |
| | | tmsDispatchOrder.setStatus(2); |
| | | tmsDispatchOrderMapper.updateTmsDispatchOrder(tmsDispatchOrder); |
| | | tmsTrip.setDriverName(tmsDispatchOrder.getMainDriverName()); |
| | |
| | | tmsTrip.setVehicleNumber(tmsDispatchOrder.getLicensePlate()); |
| | | tmsTrip.setCreateBy(SecurityUtils.getUsername()); |
| | | tmsTrip.setCreateTime(DateUtils.getNowDate()); |
| | | return tmsTripMapper.insertTmsTrip(tmsTrip); |
| | | tmsTripMapper.insertTmsTrip(tmsTrip); |
| | | if (StringUtils.isNotEmpty(tmsTrip.getSignImg())){ |
| | | asyncPdfService.generateTripPdfAsync(tmsTrip,tmsDispatchOrder,tmsDriver); |
| | | } |
| | | // 完成身体检查 |
| | | if (tmsTrip.getTripType() == 1){ |
| | | // 添加 领钥匙 指令记录 |
| | | TmsVehicle tmsVehicle = tmsVehicleServiceImpl.selectTmsVehicleById(tmsDispatchOrder.getVehicleId()); |
| | | |
| | | TmsCarKeyDispatch tmsCarKeyDispatch = new TmsCarKeyDispatch(); |
| | | tmsCarKeyDispatch.setDispatchOrderId(dispatchOrderId); |
| | | tmsCarKeyDispatch.setDispatchOrderNo(tmsDispatchOrder.getDispatchNo()); |
| | | tmsCarKeyDispatch.setDriverId(tmsDriver.getId()); |
| | | tmsCarKeyDispatch.setDriverMobile(tmsDriver.getMobile()); |
| | | tmsCarKeyDispatch.setDriverName(tmsDriver.getDriverName()); |
| | | |
| | | tmsCarKeyDispatch.setVehicleId(tmsDispatchOrder.getVehicleId()); |
| | | tmsCarKeyDispatch.setVehicleLicensePlate(tmsDispatchOrder.getLicensePlate()); |
| | | tmsCarKeyDispatch.setVehicleCarKeyNo(tmsVehicle.getCarKeyNo()); |
| | | |
| | | LocalDateTime plus2Hours = LocalDateTime.now().plusHours(2); |
| | | Date date = Date.from(plus2Hours.atZone(ZoneId.systemDefault()).toInstant()); |
| | | |
| | | tmsCarKeyDispatch.setCarKeyExpirationTime(date); |
| | | tmsCarKeyDispatch.setStatus(0); |
| | | tmsCarKeyDispatchMapper.insertTmsCarKeyDispatch(tmsCarKeyDispatch); |
| | | |
| | | sendCarKeyDelayMessage(tmsCarKeyDispatch.getId(), 2 * 60 * 60 * 1000L); |
| | | |
| | | } |
| | | |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | /** |
| | | * 发送延迟消息 |
| | | * @param carKeyId car_key id |
| | | * @param delayMillis 延迟毫秒数 |
| | | */ |
| | | public void sendCarKeyDelayMessage(Integer carKeyId, long delayMillis) { |
| | | rabbitTemplate.convertAndSend( |
| | | "car_key_delay_exchange", |
| | | "car_key_delay", |
| | | carKeyId, |
| | | message -> { |
| | | message.getMessageProperties().setExpiration(String.valueOf(delayMillis)); |
| | | return message; |
| | | } |
| | | ); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public AjaxResult submitDropHook(TmsTrip tmsTrip){ |
| | | Integer dispatchOrderId = tmsTrip.getDispatchOrderId(); |
| | |
| | | } |
| | | |
| | | |
| | | TmsVehicle tmsVehicle = tmsVehicleServiceImpl.selectTmsVehicleById(driverDispatch.getDriverId()); |
| | | TmsVehicle tmsVehicle = tmsVehicleServiceImpl.selectTmsVehicleById(driverDispatch.getVehicleId()); |
| | | |
| | | tmsDispatchOrderMapper.update( |
| | | new LambdaUpdateWrapper<TmsDispatchOrder>() |