Pu Zhibing
6 天以前 4c99ee7028c3fe58a2cd4b8273b22c75c45574fc
DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PushUtil.java
@@ -12,6 +12,7 @@
import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService;
import com.stylefeng.guns.modular.system.model.OrderPosition;
import com.stylefeng.guns.modular.system.util.GoogleMap.DistancematrixVo;
import com.stylefeng.guns.modular.system.util.GoogleMap.FleetEngineUtil;
import com.stylefeng.guns.modular.system.util.GoogleMap.GoogleMapUtil;
import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService;
@@ -25,11 +26,14 @@
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.*;
/**
@@ -43,9 +47,6 @@
    @Autowired
    private IOrderTaxiService orderTaxiService;
    @Autowired
    private GDMapElectricFenceUtil gdMapElectricFenceUtil;
    @Autowired
    private IOrderPrivateCarService orderPrivateCarService;
@@ -76,7 +77,7 @@
     * @param orderType     订单类型(1=专车,2=出租车,3=城际,4=小件物流-同城,5=小件物流-跨城,6=包车)
     * @param state         订单状态(1=待接单,2=待出发,3=待到达预约地点,4=待乘客上车,5=服务中,6=完成服务,7=待支付,8=待评价,9=已完成,10=已取消,11=改派中)
     */
    public void pushOrderState(Integer type, Integer uid, Integer orderId, Integer orderType, Integer state){
    public void pushOrderState(Integer type, Integer uid, Integer orderId, Integer orderType, Integer state, Integer time, String audioUrl, String from){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "SUCCESS");
@@ -85,6 +86,8 @@
        map.put("orderId", orderId);
        map.put("orderType", orderType);
        map.put("state", state);
        map.put("audioUrl", audioUrl);
        map.put("from", from);
        jsonObject.put("data", map);
        //调用推送
@@ -146,7 +149,7 @@
     * @param orderId
     * @param orderType
     */
    public void pushOrderReassign(Integer uid, Integer type, Integer orderId, Integer orderType){
    public void pushOrderReassign(Integer uid, Integer type, Integer orderId, Integer orderType, String audioUrl){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "SUCCESS");
@@ -154,6 +157,7 @@
        Map<String, Object> map = new HashMap<>();
        map.put("orderId", orderId);
        map.put("orderType", orderType);
        map.put("audioUrl", audioUrl);
        jsonObject.put("data", map);
        //调用推送
@@ -244,9 +248,11 @@
        Integer oldState = 0;
        Long startServiceTime = null;
        Double servedMileage = null;
        String tripId = "";
        switch (orderType){
            case 1:
                OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId);
                tripId = redisUtil.getValue("trip" + orderPrivateCar.getUserId());
                if(orderPrivateCar == null){
                    this.removeTask(orderId, orderType);
                }else{
@@ -261,6 +267,7 @@
                break;
            case 2:
                OrderTaxi orderTaxi = orderTaxiService.selectById(orderId);
                tripId = redisUtil.getValue("trip" + orderTaxi.getUserId());
                if(orderTaxi == null){
                    this.removeTask(orderId, orderType);
                }else{
@@ -275,6 +282,7 @@
                break;
            case 3:
                OrderCrossCity orderCrossCity = orderCrossCityService.selectById(orderId);
                tripId = redisUtil.getValue("trip" + orderCrossCity.getUserId());
                if(orderCrossCity == null){
                    this.removeTask(orderId, orderType);
                }else{
@@ -288,6 +296,7 @@
                break;
            case 4:
                OrderLogistics orderLogistics = orderLogisticsService.selectById(orderId);
                tripId = redisUtil.getValue("trip" + orderLogistics.getUserId());
                if(orderLogistics == null){
                    this.removeTask(orderId, orderType);
                }else{
@@ -301,6 +310,7 @@
                break;
            case 5:
                OrderLogistics orderLogistics1 = orderLogisticsService.selectById(orderId);
                tripId = redisUtil.getValue("trip" + orderLogistics1.getUserId());
                if(orderLogistics1 == null){
                    this.removeTask(orderId, orderType);
                }else{
@@ -336,19 +346,19 @@
        if((state == 2 || state == 3 || state == 4) || (oldState != null && (oldState == 2 || oldState == 3 || oldState == 4))){//前往预约地
            String d = "0";
            String t = "0";
            if(ToolUtil.isNotEmpty(value) && ToolUtil.isNotEmpty(startLonLat)){
                String[] split = value.split(",");
                String[] split1 = startLonLat.split(",");
                DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(Double.valueOf(split[1]), Double.valueOf(split[0]), Double.valueOf(split1[1]), Double.valueOf(split1[0]));
                if(null == distancematrix){
                    System.err.println("地图获取距离出错");
                }else{
                    d = distancematrix.getDistance().toString();//距离m
                    t = distancematrix.getDuration().toString();//时间s
                }
            }
            d = new BigDecimal(d).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_EVEN).toString();
            t = new BigDecimal(t).divide(new BigDecimal(60)).setScale(2, BigDecimal.ROUND_HALF_EVEN).intValue() + "";
//            if(ToolUtil.isNotEmpty(value) && ToolUtil.isNotEmpty(startLonLat)){
//                String[] split = value.split(",");
//                String[] split1 = startLonLat.split(",");
//                DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(Double.valueOf(split[1]), Double.valueOf(split[0]), Double.valueOf(split1[1]), Double.valueOf(split1[0]), tripId);
//                if(null == distancematrix){
//                    System.err.println("地图获取距离出错");
//                }else{
//                    d = distancematrix.getDistance().toString();//距离m
//                    t = distancematrix.getDuration().toString();//时间s
//                }
//            }
//            d = new BigDecimal(d).divide(new BigDecimal(1000), new MathContext(2, RoundingMode.HALF_EVEN)).toString();
//            t = new BigDecimal(t).divide(new BigDecimal(60), new MathContext(2, RoundingMode.HALF_EVEN)).intValue() + "";
            map.put("reservationMileage", d);//当前位置距离预约点的剩余里程
            map.put("reservationTime", t);//当前位置距离预约点的剩余分钟
            map.put("servedMileage", "0");//距离起点已经服务的里程
@@ -365,20 +375,20 @@
            String d = "0";
            String t = "0";
            if(ToolUtil.isNotEmpty(value) && ToolUtil.isNotEmpty(endLonLat)){
                String[] split = value.split(",");
                String[] split1 = endLonLat.split(",");
                DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(Double.valueOf(split[1]), Double.valueOf(split[0]), Double.valueOf(split1[1]), Double.valueOf(split1[0]));
                if(null == distancematrix){
                    System.err.println("地图获取距离出错");
                }else{
                    d = distancematrix.getDistance().toString();//距离m
                    t = distancematrix.getDuration().toString();//时间s
                }
            }
            d = new BigDecimal(d).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_EVEN).toString();
            t = new BigDecimal(t).divide(new BigDecimal(60)).setScale(2, BigDecimal.ROUND_HALF_EVEN).intValue() + "";
//            if(ToolUtil.isNotEmpty(value) && ToolUtil.isNotEmpty(endLonLat)){
//                String[] split = value.split(",");
//                String[] split1 = endLonLat.split(",");
//                DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(Double.valueOf(split[1]), Double.valueOf(split[0]), Double.valueOf(split1[1]), Double.valueOf(split1[0]), tripId);
//                if(null == distancematrix){
//                    System.err.println("地图获取距离出错");
//                }else{
//                    d = distancematrix.getDistance().toString();//距离m
//                    t = distancematrix.getDuration().toString();//时间s
//                }
//            }
//
//            d = new BigDecimal(d).divide(new BigDecimal(1000), new MathContext(2, RoundingMode.HALF_EVEN)).toString();
//            t = new BigDecimal(t).divide(new BigDecimal(60), new MathContext(2, RoundingMode.HALF_EVEN)).intValue() + "";
            map.put("laveMileage", d);//距离终点剩余未服务的里程数
            map.put("laveTime", t);//距离终端剩余未服务的预计时间
        }
@@ -422,13 +432,39 @@
     * @param id
     * @param type
     */
    public void pushOffline(Integer id, Integer type){
    public void pushOffline(Integer id, Integer type, Object object){
        JSONObject msg = new JSONObject();
        msg.put("code", 200);
        msg.put("msg", "SUCCESS");
        msg.put("method", "OFFLINE");
        msg.put("data", new Object());
        msg.put("data", object);
        //调用推送
        HttpHeaders headers = new HttpHeaders();
        // 以表单的方式提交
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        //将请求头部和参数合成一个请求
        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
        params.add("msg", msg.toJSONString());
        params.add("id", id.toString());
        params.add("type", type.toString());
        HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers);
        String s = internalRestTemplate.postForObject("http://zuul-gateway/netty/sendMsgToClient",requestEntity , String.class);
        JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class);
        if(jsonObject1.getIntValue("code") != 200){
            System.err.println(jsonObject1.getString("msg"));
        }
    }
    public void afterWork(Integer id, Integer type, Object object){
        JSONObject msg = new JSONObject();
        msg.put("code", 200);
        msg.put("msg", "SUCCESS");
        msg.put("method", "AFTER_WORK");
        msg.put("data", object);
        //调用推送
        HttpHeaders headers = new HttpHeaders();
        // 以表单的方式提交
@@ -493,8 +529,9 @@
     * @param orderId
     * @param orderType
     * @param money
     * @param status 1=申请,2=同意,3=拒绝
     */
    public void pushPayDifference(Integer type, Integer uid, Integer orderId, Integer orderType, Double money){
    public void pushPayDifference(Integer type, Integer uid, Integer orderId, Integer orderType, Double money, Integer status){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "SUCCESS");
@@ -503,6 +540,7 @@
        map.put("orderId", orderId);
        map.put("orderType", orderType);
        map.put("money", money);
        map.put("status", status);
        jsonObject.put("data", map);
        //调用推送
@@ -535,4 +573,83 @@
            pushMap.remove(orderId + "_" + orderType);
        }
    }
    /**
     * 修改目的地推送通知
     * @param type
     * @param uid
     * @param orderId
     * @param orderType
     * @param status 1=申请,2=同意,3=拒绝
     */
    public void pushModifyAddress(Integer type, Integer uid, Integer orderId, Integer orderType, Integer status){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "SUCCESS");
        jsonObject.put("method", "MODIFY_ADDRESS");
        Map<String, Object> map = new HashMap<>();
        map.put("orderId", orderId);
        map.put("orderType", orderType);
        map.put("status", status);
        jsonObject.put("data", map);
        //调用推送
        HttpHeaders headers = new HttpHeaders();
        // 以表单的方式提交
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        //将请求头部和参数合成一个请求
        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
        params.add("msg", jsonObject.toJSONString());
        params.add("id", String.valueOf(uid));
        params.add("type", String.valueOf(type));
        HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers);
        String s = internalRestTemplate.postForObject("http://zuul-gateway/netty/sendMsgToClient",requestEntity , String.class);
        JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class);
        if(jsonObject1.getIntValue("code") != 200){
            System.err.println(jsonObject1.getString("msg"));
        }
    }
    /**
     * 司机超时推送
     * @param type
     * @param uid
     * @param timeOutType  超时类型(1=用户可免费取消提醒,2=预约单接单提醒,3=超时循环提醒)
     * @param orderId  订单id
     * @param orderType  订单类型(1=打车,4=包裹)
     * @param describe  展示内容
     * @param audioUrl  语音播报音频地址
     */
    public void pushOrderTimeOut(Integer type, Integer uid, Integer timeOutType, Integer orderId, Integer orderType, String describe, String audioUrl){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "SUCCESS");
        jsonObject.put("method", "ORDER_TIME_OUT");
        Map<String, Object> map = new HashMap<>();
        map.put("timeOutType", timeOutType);
        map.put("orderId", orderId);
        map.put("orderType", orderType);
        map.put("describe", describe);
        map.put("audioUrl", audioUrl);
        jsonObject.put("data", map);
        //调用推送
        HttpHeaders headers = new HttpHeaders();
        // 以表单的方式提交
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        //将请求头部和参数合成一个请求
        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
        params.add("msg", jsonObject.toJSONString());
        params.add("id", String.valueOf(uid));
        params.add("type", String.valueOf(type));
        HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers);
        String s = internalRestTemplate.postForObject("http://zuul-gateway/netty/sendMsgToClient",requestEntity , String.class);
        JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class);
        if(jsonObject1.getIntValue("code") != 200){
            System.err.println(jsonObject1.getString("msg"));
        }
    }
}