zhibing.pu
2024-09-02 71a68f675e319967c3078f3f2b86ee971b47b50b
UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/controller/OrderLogisticsController.java
@@ -1,11 +1,21 @@
package com.stylefeng.guns.modular.smallLogistics.controller;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics;
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService;
import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
import com.stylefeng.guns.modular.system.model.Driver;
import com.stylefeng.guns.modular.system.model.Region;
import com.stylefeng.guns.modular.system.model.UserRedPacketRecord;
import com.stylefeng.guns.modular.system.service.IDriverService;
import com.stylefeng.guns.modular.system.service.IDriverServiceService;
import com.stylefeng.guns.modular.system.service.IUserInfoService;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.system.util.*;
import com.stylefeng.guns.modular.system.util.GoogleMap.DistancematrixVo;
import com.stylefeng.guns.modular.system.util.GoogleMap.GoogleMapUtil;
import com.stylefeng.guns.modular.system.warpper.BaseWarpper;
import com.stylefeng.guns.modular.system.warpper.OrderTimeInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
@@ -17,9 +27,10 @@
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * 小件物流控制器
@@ -31,9 +42,22 @@
    @Autowired
    private IOrderLogisticsService orderLogisticsService;
    @Autowired
    private IUserInfoService userInfoService;
    @Autowired
    private PushUtil pushUtil;
    @Autowired
    private IDriverService driverService;
    @Autowired
    private RedisUtil redisUtil;
    /**
@@ -65,16 +89,17 @@
    @ApiImplicitParams({
            @ApiImplicitParam(value = "业务类型(4=同城小件物流,5=跨城小件物流)", name = "type", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(value = "起点经纬度(103.23265,30.2312)", name = "startLonLat", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "终点经纬度(103.23265,30.2312)", name = "endLonLat", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "终点详细地址", name = "endAddress", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil queryLogisticsUnitPrice(Integer type, String startLonLat, String endAddress, Integer language, HttpServletRequest request){
    public ResultUtil queryLogisticsUnitPrice(Integer type, String startLonLat, String endLonLat, String endAddress, Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return orderLogisticsService.queryLogisticsUnitPrice(type, startLonLat, endAddress, uid, language);
            return orderLogisticsService.queryLogisticsUnitPrice(type, startLonLat, endLonLat, endAddress, uid, language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
@@ -91,11 +116,13 @@
            @ApiImplicitParam(value = "货物数量", name = "number", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(value = "业务类型(4=同城小件物流,5=跨城小件物流)", name = "type", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(value = "起点经纬度(103.23265,30.2312)", name = "startLonLat", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "终点经纬度(103.23265,30.2312)", name = "endLonLat", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "终点详细地址", name = "endAddress", required = true, paramType = "query", dataType = "string")
    })
    public ResultUtil queryPayMoney(Integer number, Integer type, String startLonLat, String endAddress, Integer language){
    public ResultUtil queryPayMoney(Integer number, Integer type, String startLonLat, String endLonLat, String endAddress, Integer language, HttpServletRequest request){
        try {
            return orderLogisticsService.queryPayMoney(number, type, startLonLat, endAddress, language);
            Integer uid = userInfoService.getUserIdFormRedis(request);
            return orderLogisticsService.queryPayMoney(uid, number, type, startLonLat, endLonLat, endAddress, language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
@@ -137,6 +164,7 @@
            @ApiImplicitParam(value = "预约取货点详细地址", name = "startAddress", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "收货人姓名", name = "recipient", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "收货人电话", name = "recipientPhone", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "终点经纬度(103.23265,30.2312)", name = "endLonLat", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "收货详细地址", name = "endAddress", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "是否加急(1=否,2=是)", name = "urgent", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(value = "加急费用", name = "tipMoney", required = true, paramType = "query", dataType = "double"),
@@ -145,19 +173,61 @@
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<BaseWarpper> smallLogistics(Integer type, Integer cargoType, Integer cargoNumber, String remark, String placementLon, String placementLat, String startLon, String startLat, String startAddress,
                                     String recipient, String recipientPhone, String endAddress, Integer urgent, Double tipMoney, Date travelTime, Integer orderSource, Integer language, HttpServletRequest request){
                                     String recipient, String recipientPhone, String endLonLat, String endAddress, Integer urgent, Double tipMoney, Date travelTime, Integer orderSource, Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return orderLogisticsService.smallLogistics(type, cargoType, cargoNumber, remark, placementLon, placementLat, startLon, startLat, startAddress,
                    recipient, recipientPhone, endAddress, urgent, tipMoney, travelTime, orderSource, uid, language);
                    recipient, recipientPhone, endLonLat, endAddress, urgent, tipMoney, travelTime, orderSource, uid, language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
    @ResponseBody
    @PostMapping("/api/orderLogistics/placeOrderPackage")
    @ApiOperation(value = "小件物流下单操作【2.0】", tags = {"用户端-小件物流"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "备注", name = "remark", required = false, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "下单点经度", name = "placementLon", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "下单点纬度", name = "placementLat", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "起点经度", name = "startLon", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "起点纬度", name = "startLat", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "起点详细地址", name = "startAddress", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "收货人姓名", name = "recipient", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "收货人电话", name = "recipientPhone", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "终点经度", name = "endLon", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "终点纬度", name = "endLat", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "收货详细地址", name = "endAddress", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(value = "车型id", name = "serverCarModelId", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(value = "司机id", name = "driverId", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(value = "下单方式(1:APP下单,2:扫码下单,3:小程序下单,4:司机下单,5:调度下单)", name = "orderSource", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<BaseWarpper> placeOrderPackage(String remark, String placementLon, String placementLat, String startLon, String startLat, String startAddress,
                                                     String recipient, String recipientPhone, String endLon, String endLat, String endAddress, Integer serverCarModelId,
                                                     Integer driverId, Integer orderSource, Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return orderLogisticsService.placeOrderPackage(remark, placementLon, placementLat, startLon, startLat, startAddress,
                    recipient, recipientPhone, endLon, endLat, endAddress, serverCarModelId, driverId, orderSource, uid, language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
    @ResponseBody
    @PostMapping("/api/orderLogistics/queryLogisticsNumber")
@@ -239,5 +309,136 @@
            return ResultUtil.runErr();
        }
    }
    @ResponseBody
    @PostMapping("/api/orderLogistics/queryTimeInfo")
    @ApiOperation(value = "获取订单详情中的时间信息内容【2.0】", tags = {"用户端-小件物流"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<OrderTimeInfo> queryTimeInfo(Integer orderId, Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid) {
                return ResultUtil.tokenErr();
            }
            OrderLogistics orderLogistics = orderLogisticsService.selectById(orderId);
            OrderTimeInfo orderTimeInfo = new OrderTimeInfo();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if(null != orderLogistics.getSnatchOrderTime()){
                orderTimeInfo.setSnatchOrderTime(DateUtil.conversionFormat(language, sdf.format(orderLogistics.getSnatchOrderTime())));
            }
            if(null != orderLogistics.getStartServiceTime()){
                orderTimeInfo.setStartServiceTime(DateUtil.conversionFormat(language, sdf.format(orderLogistics.getStartServiceTime())));
            }
            //分钟
            long time = (System.currentTimeMillis() - orderLogistics.getSnatchOrderTime().getTime()) / 60000;
            int h = Double.valueOf(time / 60).intValue();
            long m = time % 60;
            String usedTime = "";
            if(0 == h){
                usedTime = language == 1 ? m + "分钟" : language == 2 ? m + "-minute(s)" : m + "-minute";
            }else{
                usedTime = language == 1 ? h + "小时" + m + "分钟" : language == 2 ? h + "-hour" + m + "-minute(s)" : h + "-hour" + m + "-minute";
            }
            orderTimeInfo.setUsedTime(usedTime);
            String tripId = redisUtil.getValue("trip" + uid);
            if(null != orderLogistics.getEndServiceTime()){
                orderTimeInfo.setEndServiceTime(DateUtil.conversionFormat(language, sdf.format(orderLogistics.getEndServiceTime())));
            }else{
                DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(orderLogistics.getStartLat(), orderLogistics.getStartLon(), orderLogistics.getEndLat(), orderLogistics.getEndLon(), tripId);
                Long duration = distancematrix.getDuration();
                orderTimeInfo.setEndServiceTime(DateUtil.conversionFormat(language, sdf.format(new Date(System.currentTimeMillis() + duration * 1000))));
            }
            DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(orderLogistics.getStartLat(), orderLogistics.getStartLon(), orderLogistics.getEndLat(), orderLogistics.getEndLon(), tripId);
            Long distance = distancematrix.getDistance();
            orderTimeInfo.setAllMileage(Double.valueOf(distance / 1000));
            orderTimeInfo.setMileage(orderLogistics.getMileage() / 1000);
            String value = redisUtil.getValue("DRIVER" + orderLogistics.getDriverId());
            if(ToolUtil.isNotEmpty(value)){
                String[] split = value.split(",");
                distancematrix = GoogleMapUtil.getDistancematrix(Double.valueOf(split[1]), Double.valueOf(split[0]), orderLogistics.getEndLat(), orderLogistics.getEndLon(), tripId);
                //分钟
                Long duration = distancematrix.getDuration() / 60;
                h = Double.valueOf(duration / 60).intValue();
                m = duration % 60;
                String remainingTime = "";
                if(0 == h){
                    remainingTime = language == 1 ? m + "分钟" : language == 2 ? m + "-minute(s)" : m + "-minute";
                }else{
                    remainingTime = language == 1 ? h + "小时" + m + "分钟" : language == 2 ? h + "-hour" + m + "-minute(s)" : h + "-hour" + m + "-minute";
                }
                orderTimeInfo.setRemainingTime(remainingTime);
            }
            return ResultUtil.success(orderTimeInfo);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
    @ResponseBody
    @PostMapping("/api/orderLogistics/confirmDifferencePrice")
    @ApiOperation(value = "确认补差价【2.0】", tags = {"用户端-小件物流"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "int"),
            @ApiImplicitParam(value = "差价金额", name = "difference", required = true, dataType = "double"),
            @ApiImplicitParam(value = "状态(2=同意,3=拒绝)", name = "status", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil confirmDifferencePrice(Integer orderId, Double difference, Integer status){
        OrderLogistics orderLogistics = orderLogisticsService.selectById(orderId);
        if(2 == status){
            orderLogistics.setPriceDifference(difference);
            orderLogisticsService.updateById(orderLogistics);
        }
        String audioUrl = "";
        if(3 == status){
            Driver driver = driverService.selectById(orderLogistics.getDriverId());
            Integer language = driver.getLanguage();
            String text = "";
            switch (language){
                case 1:
                    text = "您的包裹订单申请补差价 GSH " + difference + " 已被用户拒绝,请重新与用户协商";
                    break;
                case 2:
                    text = "Your delivery order,Request difference GSH " + difference + " was rejected, please renegotiate with the subscriber";
                    break;
                case 3:
                    text = "Votre commande de livraison,Demande de différence GSH " + difference + " a été rejeté, veuillez renégocier avec l’abonné";
                    break;
            }
            String fileName = "difference" + driver.getId() + ".mp3";
            try {
                audioUrl = TextToSpeechUtil.create(language == 1 ? "cmn-CN" : language == 2 ? "en-US" : "fr-FR", text, fileName);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            //定时任务删除语音文件
            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    Process process = null;
                    try {
                        process = Runtime.getRuntime().exec("sudo rm -rf /home/igotechgh/nginx/html/files/audio/" + fileName);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                    if (process != null) {
                        process.destroy();
                    }
                }
            }, 30000);
        }
        pushUtil.pushPayDifference(2, orderLogistics.getDriverId(), orderId, 4, difference, status, audioUrl);
        return ResultUtil.success();
    }
}