chenxiaofei 2 місяців тому
батько
коміт
9c32c9d3e9

+ 2 - 1
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/controller/KwfTruckTraceController.java

@@ -11,6 +11,7 @@ import com.sckw.transport.model.vo.TruckInfoVo;
 import com.sckw.transport.service.kwfTruckTraceService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.validation.Valid;
 import lombok.RequiredArgsConstructor;
 import org.springframework.web.bind.annotation.*;
 
@@ -41,7 +42,7 @@ public class KwfTruckTraceController {
      */
     @PostMapping("/queryCurrentTaskTrace")
     @Operation(summary = "查询当前任务的线路")
-    public BaseResult<CurrentTaskTraceReqVo> queryCurrentTaskTrace(@RequestBody CurrentTaskTraceReq req )  {
+    public BaseResult<CurrentTaskTraceReqVo> queryCurrentTaskTrace(@Valid @RequestBody CurrentTaskTraceReq req )  {
         CurrentTaskTraceReqVo taskTrace = kwfTruckTraceService.queryCurrentTaskTrace(req);
         return BaseResult.success(taskTrace);
     }

+ 4 - 0
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/model/param/CurrentTaskTraceReq.java

@@ -1,6 +1,8 @@
 package com.sckw.transport.model.param;
 
 import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.Valid;
+import jakarta.validation.constraints.NotBlank;
 import lombok.Data;
 
 import java.io.Serial;
@@ -11,6 +13,7 @@ import java.io.Serializable;
  * @author PC
  */
 @Data
+@Valid
 public class CurrentTaskTraceReq implements Serializable {
     @Serial
     private static final long serialVersionUID = -8645240848510669952L;
@@ -24,5 +27,6 @@ public class CurrentTaskTraceReq implements Serializable {
      * 运单号
      */
     @Schema(description = "运单号")
+    @NotBlank(message = "运单号不能为空")
     private String orderNo;
 }

+ 45 - 6
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/kwfTruckTraceService.java

@@ -58,6 +58,7 @@ import org.springframework.stereotype.Service;
 import java.time.Duration;
 import java.time.LocalDateTime;
 import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
@@ -231,7 +232,7 @@ public class kwfTruckTraceService {
             TruckDto truckDto = JSON.parseObject(location, TruckDto.class);
             //如果运单号为空那么返回redis的数据 这个数据是app最后一次上报的数据
             if (Objects.nonNull(truckDto)){
-                return TruckInfoVo.toTruckInfoVo(truckDto);
+                return getTruckInfoVo(truckId, truckDto);
             }
         }
 
@@ -245,6 +246,42 @@ public class kwfTruckTraceService {
         return getTruckInfoVoByZj(truckNo, wOrderNo,truckId);
     }
 
+
+    private TruckInfoVo getTruckInfoVo(String truckId, TruckDto truckDto) {
+        TruckInfoVo truckInfoVo = TruckInfoVo.toTruckInfoVo(truckDto);
+        truckInfoVo.setGpsStatus(truckDto.getGpsStatus());
+        truckInfoVo.setLongitude(truckDto.getLongitude());
+        truckInfoVo.setLatitude(truckDto.getLatitude());
+        truckInfoVo.setLocationTime(truckDto.getLocationTime());
+        truckInfoVo.setTaskAddress(truckDto.getTaskAddress());
+        KwtWaybillOrder order = kwtWaybillOrderRepository.findOneByTruckId(truckId);
+        if (Objects.nonNull(order)){
+            truckInfoVo.setTruckNo(order.getTruckNo());
+            truckInfoVo.setOrderNo(order.getWOrderNo());
+            truckInfoVo.setDriveId(String.valueOf(order.getDriverId()));
+            truckInfoVo.setDriveName(order.getDriverName());
+            truckInfoVo.setDrivePhone(order.getDriverPhone());
+            truckInfoVo.setTruckId(truckId);
+            truckInfoVo.setTaskStatus(String.valueOf(order.getStatus()));
+        }
+
+        KwtWaybillOrderSubtask subtask = kwtWaybillOrderSubtaskRepository.findOneByWOrderNo(Optional.ofNullable(order)
+                .map(KwtWaybillOrder::getWOrderNo).
+                orElse( null));
+        truckInfoVo.setLogicOrderNo(Objects.isNull(subtask) ? "" : String.valueOf(subtask.getLOrderId()));
+        if (Objects.isNull(subtask)){
+            return truckInfoVo;
+        }
+        truckInfoVo.setLogicOrderNo(String.valueOf(subtask.getLOrderId()));
+        //根据物流订单号查询承运单位 2.代表承运企业
+        KwtLogisticsOrderUnit kwtLogisticsOrderUnit = kwtLogisticsOrderUnitRepository.queryByLOrderIdAndUnitType(subtask.getLOrderId(), 2);
+        if (Objects.nonNull(kwtLogisticsOrderUnit) && Objects.nonNull(kwtLogisticsOrderUnit.getEntId())){
+            EntCacheResDto entCacheResDto = remoteSystemService.queryEntCacheById(kwtLogisticsOrderUnit.getEntId());
+            truckInfoVo.setCarrier(Optional.ofNullable(entCacheResDto).map(EntCacheResDto::getFirmName).orElse(""));
+        }
+        return truckInfoVo;
+    }
+
     private void saveRedisCache(String truckId, String wOrderNo, String truckNo, VehicleReturnData vehicleReturnData) {
         TruckDto truckDto = new TruckDto();
         truckDto.setWOrderNo(vehicleReturnData.getWOrderNo());
@@ -388,6 +425,7 @@ public class kwfTruckTraceService {
             //组织返回数据
             List<CurrentTaskTraceReqVo.CurrentTaskTrace> currentTaskTraceList = vehicleReturnDataList.stream()
                     .map(kwfTruckTraceService::getCurrentTaskTrace)
+                    .filter(x->StringUtils.isNotBlank(x.getLocationTime()))
                     .sorted(Comparator.comparing(CurrentTaskTraceReqVo.CurrentTaskTrace::getLocationTime))
                     .collect(Collectors.toList());
 
@@ -396,16 +434,17 @@ public class kwfTruckTraceService {
             for (int i = 1; i < currentTaskTraceList.size(); i++) {
                 CurrentTaskTraceReqVo.CurrentTaskTrace current = currentTaskTraceList.get(i);
                 CurrentTaskTraceReqVo.CurrentTaskTrace previous = currentTaskTraceList.get(i - 1);
-                LocalDateTime currentTime = LocalDateTime.parse(current.getLocationTime());
-                LocalDateTime previousTime = LocalDateTime.parse(previous.getLocationTime());
+                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+                LocalDateTime currentTime = LocalDateTime.parse(current.getLocationTime(), formatter);
+                LocalDateTime previousTime = LocalDateTime.parse(previous.getLocationTime(), formatter);
                 Duration duration = Duration.between(previousTime, currentTime);
                 current.setDuration(String.valueOf(duration.toMinutes()));
             }
             CurrentTaskTraceReqVo.CurrentTaskTrace first = currentTaskTraceList.get(0);
             CurrentTaskTraceReqVo.CurrentTaskTrace last = currentTaskTraceList.get(currentTaskTraceList.size() - 1);
-
-            LocalDateTime firstTime = LocalDateTime.parse(first.getLocationTime());
-            LocalDateTime lastTime = LocalDateTime.parse(last.getLocationTime());
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+            LocalDateTime firstTime = LocalDateTime.parse(first.getLocationTime(),formatter);
+            LocalDateTime lastTime = LocalDateTime.parse(last.getLocationTime(),formatter);
 
             Duration totalDuration = Duration.between(firstTime, lastTime);
             long durationInMinutes = totalDuration.toMinutes();