From 1707d15796d7dc78812f19b9c34868c8cb38a714 Mon Sep 17 00:00:00 2001
From: liujie <liujie>
Date: 星期日, 15 十月 2023 17:56:57 +0800
Subject: [PATCH] broker 卡车公司端

---
 src/main/java/com/stylefeng/guns/modular/system/controller/OrderController.java |  201 ++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 154 insertions(+), 47 deletions(-)

diff --git a/src/main/java/com/stylefeng/guns/modular/system/controller/OrderController.java b/src/main/java/com/stylefeng/guns/modular/system/controller/OrderController.java
index 7c0c9d5..a3abb91 100644
--- a/src/main/java/com/stylefeng/guns/modular/system/controller/OrderController.java
+++ b/src/main/java/com/stylefeng/guns/modular/system/controller/OrderController.java
@@ -1,12 +1,20 @@
 package com.stylefeng.guns.modular.system.controller;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.crypto.SecureUtil;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.plugins.Page;
+import com.stylefeng.guns.core.util.ToolUtil;
+import com.stylefeng.guns.modular.system.enums.FacilityCodeEnum;
 import com.stylefeng.guns.modular.system.model.*;
 import com.stylefeng.guns.modular.system.service.*;
+import com.stylefeng.guns.modular.system.utils.PortUtil.FortyNineUtil;
+import com.stylefeng.guns.modular.system.utils.PortUtil.SCACEnum;
+import com.stylefeng.guns.modular.system.utils.PortUtil.TerminalInterfaceAcquisitionUtil;
 import com.stylefeng.guns.modular.system.utils.tips.ErrorTip;
 import com.stylefeng.guns.modular.system.utils.tips.SuccessTip;
+import com.stylefeng.guns.modular.system.warpper.TerminaleDataWarpper;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -17,12 +25,11 @@
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.net.FileNameMap;
 import java.net.URLConnection;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Objects;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 @Controller
 @Api(tags = "订单")
@@ -138,7 +145,7 @@
     @GetMapping(value = "/getOrderInfo")
     @ResponseBody
     public Object getOrderInfo( Long orderId) {
-        OrderInfo orderInfo = orderService.getOrderInfo(orderId);
+        HashMap<String, Object> orderInfo = orderService.getOrderInfo(orderId);
         return new SuccessTip(orderInfo);
     }
 
@@ -152,6 +159,22 @@
         boolean b = goodsService.updateById(tGoods);
         return new SuccessTip();
     }
+
+    @ApiOperation(value = "获取订单司机位置",notes="获取订单司机位置")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType     = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
+            @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"),
+            @ApiImplicitParam(name = "lon", value = "lon", required = true, dataType = "String"),
+            @ApiImplicitParam(name = "lat", value = "lat", required = true, dataType = "String"),
+    })
+    @GetMapping(value = "/getLonLat")
+    @ResponseBody
+    public Object getLonLat(Long orderId){
+        //  通过司机id获取订单
+        List<Map<String,Object>> orders = orderService.getLonLat(orderId);
+        return new SuccessTip(orders);
+    }
+
 
     @Resource
     private TTransportationService tTransportationService;
@@ -171,6 +194,8 @@
         ArrayList<OrderDriverInfo> orderDriverInfos = new ArrayList<>();
         ArrayList<Integer> driverIds = new ArrayList<>();
         TOrder tOrder = orderService.selectById(orderId);
+        TPort tPort = portService.selectById(tOrder.getPort());
+
         // 第一个开始司机id
         Integer sDriverid = tOrder.getsDriverid();
         if(sDriverid!=null){
@@ -189,19 +214,62 @@
         if(driverIdOne!=null){
             driverIds.add(driverIdOne);
         }
-        transportInfo.setShipmentDate(tOrder.getShipmentDate());
+        TGoods tGoods = goodsService.selectOne(new EntityWrapper<TGoods>().eq("order_id", tOrder.getId()));
         List<TTransportation> tTransportations = tTransportationService.selectList(new EntityWrapper<TTransportation>().eq("order_id", orderId).in("driver_id", driverIds).orderBy("type"));
+        TerminaleDataWarpper terminalStatus =new TerminaleDataWarpper();
+        try {
+            if("LBCT".equals(tPort.getName()) || "APM".equals(tPort.getName())){
+                terminalStatus  = TerminalInterfaceAcquisitionUtil.getTerminalStatus(tPort.getName(),tGoods.getContainerNumber(), FacilityCodeEnum.USLAX.getMsg());
+            }else {
+                // 去查是否存了containerid
+                if(ToolUtil.isNotEmpty(tGoods.getShipmentId()) && !"0".equals(tGoods.getShipmentId())){
+                    terminalStatus = FortyNineUtil.getContainerNo(tGoods.getShipmentId(), tGoods.getContainerNumber());
+                }else {
+
+                    String shippingLine = tGoods.getShippingLine();
+                    SCACEnum scacEnum = SCACEnum.fromCode(shippingLine);
+                    String s;
+                    if(ToolUtil.isEmpty(tGoods.getTrackingId()) || "0".equals(tGoods.getTrackingId())){
+                        s = FortyNineUtil.trackingRequest(tGoods.getBillNumber(), scacEnum.getDesc());
+                        if(ToolUtil.isEmpty(s)){
+                            s = FortyNineUtil.trackingList(tGoods.getBillNumber());
+                        }
+                        tGoods.setTrackingId(s);
+                        goodsService.updateById(tGoods);
+                    }else {
+                        s = tGoods.getTrackingId();
+                    }
+                    String shipmentId = FortyNineUtil.getShipmentId(s);
+                    if(ToolUtil.isNotEmpty(shipmentId)){
+                        tGoods.setShipmentId(shipmentId);
+                        goodsService.updateById(tGoods);
+                    }else {
+                        tGoods.setShipmentId("0");
+                        tGoods.setTrackingId("0");
+                        goodsService.updateById(tGoods);
+                    }
+                    terminalStatus = FortyNineUtil.getContainerNo(shipmentId, tGoods.getContainerNumber());
+                }
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+            terminalStatus =new TerminaleDataWarpper();
+        }
+
         for (TTransportation tDriver : tTransportations) {
             OrderDriverInfo orderDriverInfo = new OrderDriverInfo();
             orderDriverInfo.setId(tDriver.getId());
             orderDriverInfo.setDriverId(tDriver.getDriverId());
-            if(tDriver.getId().equals(sDriverIdOne)&&tDriver.getType()==2){
+            if(tDriver.getDriverId().equals(sDriverIdOne)&&tDriver.getType()==1){
                 orderDriverInfo.setPickUp(tDriver.getPickDate());
             }
-            if(tDriver.getId().equals(driverid) &&tDriver.getType()==3){
+            if(tDriver.getDriverId().equals(sDriverIdOne)&&tDriver.getType()==2){
+                orderDriverInfo.setPickUp(tDriver.getPickDate());
+            }
+            if(tDriver.getDriverId().equals(driverid) &&tDriver.getType()==3){
                 orderDriverInfo.setEmptyDate(tDriver.getEmptyDate());
             }
-            if(tDriver.getId().equals(driverIdOne) &&tDriver.getType()==4){
+            if(tDriver.getDriverId().equals(driverIdOne) &&tDriver.getType()==4){
                 orderDriverInfo.setReturnDate(tDriver.getReturnDate());
             }
             orderDriverInfo.setContactEmail(tDriver.getEmail());
@@ -210,8 +278,7 @@
             orderDriverInfo.setTPowerUnits(powerUnitsService.selectById(tDriver.getPowerUnit()));
             orderDriverInfo.setChassiess(powerUnitsService.selectById(tDriver.getChassises()));
 
-            // TODO 第三方  目前不知道对接那个
-            orderDriverInfo.setAppointmentNumber(null);
+            orderDriverInfo.setAppointmentNumber(terminalStatus.getAppointmentNumber());
 
             orderDriverInfos.add(orderDriverInfo);
 
@@ -219,6 +286,15 @@
         transportInfo.setTruckCompany(tOrder.getTruckCompany());
         transportInfo.setPickupTime(tOrder.getPickupTimeTruck());
         transportInfo.setStreetTurn(tOrder.getStreetTurn());
+
+        transportInfo.setLineHold(terminalStatus.getLineHold());
+        transportInfo.setCustomHold(terminalStatus.getCustomHold());
+        transportInfo.setPierpass(terminalStatus.getPierpass());
+        transportInfo.setCTF(terminalStatus.getCtf());
+        transportInfo.setClosedArea(terminalStatus.getClosedArea());
+        transportInfo.setLFD(terminalStatus.getLfd());
+        transportInfo.setAvailable(terminalStatus.getAvailability());
+
         transportInfo.setList(orderDriverInfos);
         Integer examSite = tOrder.getExamSite();
         if(Objects.nonNull(examSite)){
@@ -247,7 +323,7 @@
         TUser tUser = itUserService.selectById(userId);
         List<TPrice> prices = priceService.selectList(new EntityWrapper<TPrice>().eq("order_id", tOrder.getId()));
         ArrayList<PriceInfo> priceInfos = new ArrayList<>();
-        if(tUser.getGroupId()!=null){
+        if(false){
             TGroup tGroup = groupService.selectById(tUser.getGroupId());
             User user = service.selectById(tGroup.getSalesId());
 
@@ -270,7 +346,7 @@
                             BigDecimal subtract = price.getPrice().subtract(multiply);
                             priceInfo.setCarrierCost(subtract);
                             priceInfo.setSalesProfit(new BigDecimal(commission));
-                            priceInfo.setMargin(multiply);
+                            priceInfo.setMargin(multiply.setScale(2, RoundingMode.HALF_UP));
                         }else {
                             priceInfo.setMargin(new BigDecimal(0));
                             priceInfo.setSalesProfit(new BigDecimal(commission));
@@ -284,8 +360,8 @@
         }else {
             for (TPrice price : prices) {
                 PriceInfo priceInfo = new PriceInfo();
-                priceInfo.setCarrierCost(price.getPrice());
-                priceInfo.setCustomerCost(price.getPrice());
+                priceInfo.setCarrierCost(price.getCarPrice());
+                priceInfo.setCustomerCost(price.getCarPrice());
                 priceInfo.setName(price.getType());
                 priceInfo.setSalesProfit(new BigDecimal(0));
                 priceInfo.setMargin(new BigDecimal(0));
@@ -311,6 +387,22 @@
         return new SuccessTip(page);
     }
 
+    @ApiOperation(value = "卡车公司--save time",notes="卡车公司--save time")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType     = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
+            @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"),
+            @ApiImplicitParam(name = "time", value = "time", required = true, dataType = "String"),
+
+    })
+    @PostMapping(value = "/updateSaveTime")
+    @ResponseBody
+    public Object updateSaveTime( Long  orderId,String time){
+        TOrder tOrder = orderService.selectById(orderId);
+        Date date = DateUtil.parse(time).toJdkDate();
+        tOrder.setShipmentDate(date);
+        orderService.updateById(tOrder);
+        return new SuccessTip();
+    }
 
 
     @ApiOperation(value = "卡车公司--安排司机",notes="卡车公司--安排司机")
@@ -399,7 +491,7 @@
             TOrder tOrder = orderService.selectById(orderId);
             TTransportation list = companySelectDriverSingleDto.getList();
             list.setOrderId(companySelectDriverSingleDto.getOrderId());
-            Integer type = companySelectDriverSingleDto.getType();
+            Integer type = companySelectDriverSingleDto.getList().getType();
             if(type==1){
                 tTransportationService.delete(new EntityWrapper<TTransportation>().eq("order_id",orderId).eq("driver_id",tOrder.getsDriverid()).eq("type",1));
                 tOrder.setsDriverid(list.getDriverId());
@@ -413,7 +505,7 @@
                 tTransportationService.delete(new EntityWrapper<TTransportation>().eq("order_id",orderId).eq("driver_id",tOrder.geteDriverIdOne()).eq("type",4));
                 tOrder.seteDriverIdOne(list.getDriverId());
             }
-            tTransportationService.insert(list);
+                tTransportationService.insert(list);
             // 删除原来的司机信息
             // 更改订单信息
             orderService.updateById(tOrder);
@@ -549,7 +641,21 @@
             }
             record.setType(type);
         }
-        orderFilePage.setRecords(records);
+        TOrder tOrder = orderService.selectById(orderId);
+
+        if("9".equals(tOrder.getStatus()) || "18".equals(tOrder.getStatus())){
+            ArrayList<TOrderFile> tOrderFiles = new ArrayList<>();
+            TOrderFile tOrderFile = new TOrderFile();
+            tOrderFile.setName("Bill of lading.pdf");
+            tOrderFile.setId(0);
+            tOrderFile.setType("file");
+            tOrderFiles.add(tOrderFile);
+            tOrderFiles.addAll(records);
+            orderFilePage.setRecords(tOrderFiles);
+        }else {
+
+            orderFilePage.setRecords(records);
+        }
         return new SuccessTip(orderFilePage);
     }
 
@@ -575,7 +681,6 @@
         }
         return new ErrorTip(500,"ERROR");
     }
-
 
     @ApiOperation(value = "订单详情-提货单",notes="订单详情-提货单")
     @ApiImplicitParams({
@@ -629,8 +734,6 @@
     }
 
 
-
-
     @ApiOperation(value = "平台给用户报价/平台给卡车公司价格",notes="平台给用户报价/平台给卡车公司价格")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
@@ -644,40 +747,44 @@
 
         TOrder tOrder = orderService.selectById(orderId);
         // 根据订单获取报价
+
         map.put("invoice",tOrder.getInvoiceNumber());
         map.put("pickUpDate",tOrder.getShipmentDate());
         map.put("returnDate",tOrder.getOrderOkTime());
         List<TPrice> prices = priceService.selectList(new EntityWrapper<TPrice>().eq("order_id", orderId));
+        prices.forEach(e->e.setPrice(e.getCarPrice()));
         if(type==1){
             map.put("price",prices);
         }else{
+            map.put("price",prices);
             // 找出订单用户 --> 获取销售--> 获取提成 --> 计算应给卡车公司金额
-            Integer userId = tOrder.getUserId();
-            TUser tUser = itUserService.selectById(userId);
-            if(tUser.getGroupId()==null){
-                map.put("price",prices);
-            }else {
-                TGroup tGroup = groupService.selectById(tUser.getGroupId());
-                User user = service.selectById(tGroup.getSalesId());
-                List<TUserFeeSetting> tUserFeeSettings = feeSettingService.selectList(new EntityWrapper<TUserFeeSetting>().eq("user_id", user.getId()));
-
-                for (TPrice price : prices) {
-                    for (TUserFeeSetting tUserFeeSetting : tUserFeeSettings) {
-                        if(price.getType().equals(tUserFeeSetting.getName())){
-                            if(tUserFeeSetting.getFee()!=null && tUserFeeSetting.getFee()!=0) {
-                                double v = ((double) tUserFeeSetting.getFee()) / 100;
-                                BigDecimal multiply = price.getPrice().multiply(new BigDecimal(v));
-                                BigDecimal subtract = price.getPrice().subtract(multiply);
-                                price.setPrice(subtract);
-                            }else {
-                                price.setPrice(price.getPrice());
-                            }
-                            break;
-                        }
-                    }
-                }
-                map.put("price",prices);
-            }
+//            Integer userId = tOrder.getUserId();
+//            TUser tUser = itUserService.selectById(userId);
+//            if(tUser.getGroupId()==null){
+//                map.put("price",prices);
+//            }else {
+//                prices.for
+//                TGroup tGroup = groupService.selectById(tUser.getGroupId());
+//                User user = service.selectById(tGroup.getSalesId());
+//                List<TUserFeeSetting> tUserFeeSettings = feeSettingService.selectList(new EntityWrapper<TUserFeeSetting>().eq("user_id", user.getId()));
+//
+//                for (TPrice price : prices) {
+//                    for (TUserFeeSetting tUserFeeSetting : tUserFeeSettings) {
+//                        if(price.getType().equals(tUserFeeSetting.getName())){
+//                            if(tUserFeeSetting.getFee()!=null && tUserFeeSetting.getFee()!=0) {
+//                                double v = ((double) tUserFeeSetting.getFee()) / 100;
+//                                BigDecimal multiply = price.getPrice().multiply(new BigDecimal(v));
+//                                BigDecimal subtract = price.getPrice().subtract(multiply);
+//                                price.setPrice(subtract);
+//                            }else {
+//                                price.setPrice(price.getPrice());
+//                            }
+//                            break;
+//                        }
+//                    }
+//                }
+//                map.put("price",prices);
+//            }
         }
         return new SuccessTip(map);
     }

--
Gitblit v1.7.1