package com.stylefeng.guns.modular.system.util; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity; import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService; 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.specialTrain.server.IOrderPrivateCarService; import com.stylefeng.guns.modular.taxi.model.OrderTaxi; import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; import java.util.HashMap; import java.util.Map; import java.util.Timer; import java.util.TimerTask; /** * socket推单处理类 */ @Component public class PushUtil { @Autowired private IOrderTaxiService orderTaxiService; @Autowired private GDMapElectricFenceUtil gdMapElectricFenceUtil; @Autowired private IOrderPrivateCarService orderPrivateCarService; @Autowired private IOrderCrossCityService orderCrossCityService; @Autowired private RedisTemplate redisTemplate; @Autowired private IOrderLogisticsService orderLogisticsService; private Map taskMap = new HashMap<>();//存储定时推送的定时器 @Value("${qyt.socket_uri}") private String socket_uri; // qyt 改派重新推单 public void pushOrderState(Integer type, Integer uid, Integer orderId, Integer orderType, Integer state, Integer time) { JSONObject jsonObject = new JSONObject(); jsonObject.put("code", 200); jsonObject.put("msg", "SUCCESS"); jsonObject.put("method", "ORDER_STATUS"); Map map = new HashMap<>(); map.put("orderId", orderId); map.put("orderType", orderType); map.put("time", time); if (orderType == 1 && state == 100) { map.put("carpooling", 1); map.put("state", 2); } else { map.put("state", state); } jsonObject.put("data", map); //调用推送 HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient"); post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); //将请求头部和参数合成一个请求 Map params = new HashMap<>(); params.put("msg", jsonObject.toJSONString()); params.put("id", uid); params.put("type", type); params.put("bussinessType", "dache"); post.form(params); HttpResponse execute = post.execute(); if (200 != execute.getStatus()) { System.err.println("推送异常"); } else { JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class); if (jsonObject1.getIntValue("code") != 200) { System.err.println(jsonObject1.getString("msg")); } } } /** * 推单完成后,没有司机接单的推送提醒 qyt * * @param type * @param uid * @param orderId * @param orderType */ public void pushEndPush(Integer type, Integer uid, Integer orderId, Integer orderType, Integer state) { JSONObject jsonObject = new JSONObject(); jsonObject.put("code", 200); jsonObject.put("msg", "SUCCESS"); jsonObject.put("method", "END_PUSH"); Map map = new HashMap<>(); map.put("orderId", orderId); map.put("orderType", orderType); map.put("state", state); jsonObject.put("data", map); //调用推送 HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient"); post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); //将请求头部和参数合成一个请求 Map params = new HashMap<>(); params.put("msg", jsonObject.toJSONString()); params.put("id", uid); params.put("type", type); params.put("bussinessType", "dache"); post.form(params); HttpResponse execute = post.execute(); if (200 != execute.getStatus()) { System.err.println("推送异常"); } else { JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class); if (jsonObject1.getIntValue("code") != 200) { System.err.println(jsonObject1.getString("msg")); } } } /** * 改派推单结束 * @param type * @param uid * @param orderId * @param orderType * @param state */ public void pushReassignEndCancel(Integer type, Integer uid, Integer orderId, Integer orderType, Integer state) { JSONObject jsonObject = new JSONObject(); jsonObject.put("code", 200); jsonObject.put("msg", "SUCCESS"); jsonObject.put("method", "REASSIGN_END_CANCEL"); Map map = new HashMap<>(); map.put("orderId", orderId); map.put("orderType", orderType); map.put("state", state); jsonObject.put("data", map); //调用推送 HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient"); post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); //将请求头部和参数合成一个请求 Map params = new HashMap<>(); params.put("msg", jsonObject.toJSONString()); params.put("id", uid); params.put("type", type); params.put("bussinessType", "dache"); post.form(params); HttpResponse execute = post.execute(); if (200 != execute.getStatus()) { System.err.println("推送异常"); } else { JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class); if (jsonObject1.getIntValue("code") != 200) { System.err.println(jsonObject1.getString("msg")); } } } /** * 推送订单状态 * * @param type 1=用户,2=司机 * @param uid 对象id * @param orderId 订单id * @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) { JSONObject jsonObject = new JSONObject(); jsonObject.put("code", 200); jsonObject.put("msg", "SUCCESS"); jsonObject.put("method", "ORDER_STATUS"); Map map = new HashMap<>(); map.put("orderId", orderId); map.put("orderType", orderType); map.put("state", state); jsonObject.put("data", map); //调用推送 HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient"); post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); //将请求头部和参数合成一个请求 Map params = new HashMap<>(); params.put("msg", jsonObject.toJSONString()); params.put("id", uid); params.put("type", type); params.put("bussinessType", "dache"); post.form(params); HttpResponse execute = post.execute(); if (200 != execute.getStatus()) { System.err.println("推送异常"); } else { JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class); if (jsonObject1.getIntValue("code") != 200) { System.err.println(jsonObject1.getString("msg")); } } } /** * 改派完成后推送用户端提醒 * @param uid * @param orderId * @param orderType */ public void pushOrderReassign(Integer uid, Integer type, Integer orderId, Integer orderType){ System.out.println("改派完成后推送用户端提醒"); JSONObject jsonObject = new JSONObject(); jsonObject.put("code", 200); jsonObject.put("msg", "SUCCESS"); jsonObject.put("method", "REASSIGN"); Map map = new HashMap<>(); map.put("orderId", orderId); map.put("orderType", orderType); jsonObject.put("data", map); //调用推送 HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient"); post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); //将请求头部和参数合成一个请求 Map params = new HashMap<>(); params.put("msg", jsonObject.toJSONString()); params.put("id", uid); params.put("type", type); params.put("bussinessType", "dache"); post.form(params); HttpResponse execute = post.execute(); if (200 != execute.getStatus()) { System.err.println("推送异常"); } else { JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class); if (jsonObject1.getIntValue("code") != 200) { System.err.println(jsonObject1.getString("msg")); } } } /** * 推送改派确认请求给目标司机(Socket推送) * @param driverId 目标司机ID * @param reassignIds 改派记录ID列表(逗号分隔) * @param orderIds 订单ID列表(逗号分隔) * @param startSite 线路起点站点 * @param endSite 线路终点站点 * @param totalPeopleNumber 总人数 * @param travelTime 出行时间 * @param expireTime 超时时间 */ public void pushReassignConfirmRequest(Integer driverId, String reassignIds, String orderIds, String startSite, String endSite, Integer totalPeopleNumber, String travelTime, String expireTime) { System.out.println("推送改派确认请求给司机: driverId=" + driverId + ", reassignIds=" + reassignIds); JSONObject jsonObject = new JSONObject(); jsonObject.put("code", 200); jsonObject.put("msg", "SUCCESS"); jsonObject.put("method", "REASSIGN_CONFIRM_REQUEST"); Map map = new HashMap<>(); map.put("reassignIds", reassignIds); // 改派记录ID列表(逗号分隔) map.put("orderIds", orderIds); map.put("startSite", startSite); map.put("endSite", endSite); map.put("routeInfo", startSite + " → " + endSite); map.put("totalPeopleNumber", totalPeopleNumber); map.put("travelTime", travelTime); map.put("expireTime", expireTime); jsonObject.put("data", map); // 调用推送 HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient"); post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); // 将请求头部和参数合成一个请求 Map params = new HashMap<>(); params.put("msg", jsonObject.toJSONString()); params.put("id", driverId); params.put("type", 2); // type=2 表示司机端 params.put("bussinessType", "dache"); post.form(params); System.out.println("改派确认Socket请求: url=" + socket_uri + "/netty/sendMsgToClient, params=" + params); HttpResponse execute = post.execute(); System.out.println("改派确认Socket响应: status=" + execute.getStatus() + ", body=" + execute.body()); if (200 != execute.getStatus()) { System.err.println("改派确认请求推送异常"); } else { JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class); if (jsonObject1.getIntValue("code") != 200) { System.err.println("改派确认请求推送失败: " + jsonObject1.getString("msg")); } else { System.out.println("改派确认请求推送成功: driverId=" + driverId); } } } /** * 通知原司机改派结果(Socket推送) * @param driverId 原司机ID * @param reassignId 改派记录ID * @param orderId 订单ID * @param orderType 订单类型 * @param resultType 结果类型(1=成功,2=拒绝,3=超时) */ public void pushReassignResult(Integer driverId, Integer reassignId, Integer orderId, Integer orderType, Integer resultType) { String resultName = resultType == 1 ? "成功" : (resultType == 2 ? "被拒绝" : "超时"); System.out.println("推送改派" + resultName + "通知给原司机: driverId=" + driverId + ", reassignId=" + reassignId); JSONObject jsonObject = new JSONObject(); jsonObject.put("code", 200); jsonObject.put("msg", "SUCCESS"); jsonObject.put("method", "REASSIGN_RESULT"); Map map = new HashMap<>(); map.put("type", resultType); // 1=成功,2=拒绝,3=超时 map.put("reassignId", reassignId); map.put("orderId", orderId); map.put("orderType", orderType); // 根据结果类型设置不同的提示消息 String message; if (resultType == 1) { message = "您的改派申请已被接受"; } else if (resultType == 2) { message = "对方拒绝了您的改派申请"; } else { message = "改派申请已超时,请重新选择"; } map.put("message", message); jsonObject.put("data", map); // 调用推送 HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient"); post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); Map params = new HashMap<>(); params.put("msg", jsonObject.toJSONString()); params.put("id", driverId); params.put("type", 2); // type=2 表示司机端 params.put("bussinessType", "dache"); post.form(params); HttpResponse execute = post.execute(); if (200 != execute.getStatus()) { System.err.println("改派" + resultName + "通知推送异常"); } else { JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class); if (jsonObject1.getIntValue("code") != 200) { System.err.println("改派" + resultName + "通知推送失败: " + jsonObject1.getString("msg")); } else { System.out.println("改派" + resultName + "通知推送成功: driverId=" + driverId); } } } /** * 通知原司机改派成功(Socket推送) * @param driverId 原司机ID * @param reassignId 改派记录ID * @param orderId 订单ID * @param orderType 订单类型 */ public void pushReassignSuccess(Integer driverId, Integer reassignId, Integer orderId, Integer orderType) { pushReassignResult(driverId, reassignId, orderId, orderType, 1); } /** * 通知原司机改派被拒绝(Socket推送) * @param driverId 原司机ID * @param reassignId 改派记录ID * @param orderId 订单ID * @param orderType 订单类型 */ public void pushReassignRejected(Integer driverId, Integer reassignId, Integer orderId, Integer orderType) { pushReassignResult(driverId, reassignId, orderId, orderType, 2); } /** * 通知原司机改派超时(Socket推送) * @param driverId 原司机ID * @param reassignId 改派记录ID * @param orderId 订单ID * @param orderType 订单类型 */ public void pushReassignTimeout(Integer driverId, Integer reassignId, Integer orderId, Integer orderType) { pushReassignResult(driverId, reassignId, orderId, orderType, 3); } /** * 推送司机位置给乘客端 */ public void pushDriverPosition(Integer orderId, Integer orderType){ Integer userId = null; switch (orderType){ case 1: OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId); userId = orderPrivateCar.getUserId(); break; case 2: OrderTaxi orderTaxi = orderTaxiService.selectById(orderId); userId = orderTaxi.getUserId(); break; case 3: OrderCrossCity orderCrossCity = orderCrossCityService.selectById(orderId); userId = orderCrossCity.getUserId(); break; case 4: OrderLogistics orderLogistics = orderLogisticsService.selectById(orderId); userId = orderLogistics.getUserId(); break; case 5: OrderLogistics orderLogistics1 = orderLogisticsService.selectById(orderId); userId = orderLogistics1.getUserId(); break; } JSONObject data = new JSONObject(); data.put("id", userId); data.put("type", 1); String value = (String) redisTemplate.opsForValue().get(orderId + "_" + orderType); if(ToolUtil.isEmpty(value)){ redisTemplate.opsForValue().set(orderId + "_" + orderType, data.toJSONString()); createTask(orderId, orderType); } } /** * 创建定时任务 * @param orderId */ public void createTask(Integer orderId, Integer orderType){ TimerTask task = new TimerTask() { @Override public void run() { try { PushUtil.this.pushPositon(orderId, orderType); } catch (Exception e) { e.printStackTrace(); } } }; Timer timer = new Timer(); timer.schedule(task, 1000, 10000);//1秒后开始10秒钟一次的重复执行 taskMap.put(orderId + "_" + orderType, timer); } /** * 推送处理方法 * @param orderId * @param orderType * @throws Exception */ public void pushPositon(Integer orderId, Integer orderType) throws Exception{ Integer driverId = null; String startLonLat = null; String endLonLat = null; Integer state = 0; Integer oldState = 0; Long startServiceTime = null; Double servedMileage = null; switch (orderType){ case 1: OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId); if(orderPrivateCar == null){ this.removeTask(orderId, orderType); }else{ driverId = orderPrivateCar.getDriverId(); startLonLat = orderPrivateCar.getStartLon() + "," + orderPrivateCar.getStartLat(); state = orderPrivateCar.getState(); oldState = orderPrivateCar.getOldState(); startServiceTime = null != orderPrivateCar.getStartServiceTime() ? orderPrivateCar.getStartServiceTime().getTime() : null; servedMileage = orderPrivateCar.getMileage(); endLonLat = orderPrivateCar.getEndLon() + "," + orderPrivateCar.getEndLat(); } break; case 2: OrderTaxi orderTaxi = orderTaxiService.selectById(orderId); if(orderTaxi == null){ this.removeTask(orderId, orderType); }else{ driverId = orderTaxi.getDriverId(); startLonLat = orderTaxi.getStartLon() + "," + orderTaxi.getStartLat(); state = orderTaxi.getState(); oldState = orderTaxi.getOldState(); startServiceTime = null != orderTaxi.getStartServiceTime() ? orderTaxi.getStartServiceTime().getTime() : null; servedMileage = orderTaxi.getMileage(); endLonLat = orderTaxi.getEndLon() + "," + orderTaxi.getEndLat(); } break; case 3: OrderCrossCity orderCrossCity = orderCrossCityService.selectById(orderId); if(orderCrossCity == null){ this.removeTask(orderId, orderType); }else{ driverId = orderCrossCity.getDriverId(); startLonLat = orderCrossCity.getStartLon() + "," + orderCrossCity.getStartLat(); state = orderCrossCity.getState(); startServiceTime = null != orderCrossCity.getStartServiceTime() ? orderCrossCity.getStartServiceTime().getTime() : null; servedMileage = orderCrossCity.getMileage(); endLonLat = orderCrossCity.getEndLon() + "," + orderCrossCity.getEndLat(); } break; case 4: OrderLogistics orderLogistics = orderLogisticsService.selectById(orderId); if(orderLogistics == null){ this.removeTask(orderId, orderType); }else{ driverId = orderLogistics.getDriverId(); startLonLat = orderLogistics.getStartLon() + "," + orderLogistics.getStartLat(); state = orderLogistics.getState(); startServiceTime = null != orderLogistics.getStartServiceTime() ? orderLogistics.getStartServiceTime().getTime() : null; servedMileage = orderLogistics.getMileage(); endLonLat = orderLogistics.getEndLon() + "," + orderLogistics.getEndLat(); } break; case 5: OrderLogistics orderLogistics1 = orderLogisticsService.selectById(orderId); if(orderLogistics1 == null){ this.removeTask(orderId, orderType); }else{ driverId = orderLogistics1.getDriverId(); startLonLat = orderLogistics1.getStartLon() + "," + orderLogistics1.getStartLat(); state = orderLogistics1.getState(); startServiceTime = null != orderLogistics1.getStartServiceTime() ? orderLogistics1.getStartServiceTime().getTime() : null; servedMileage = orderLogistics1.getMileage(); endLonLat = orderLogistics1.getEndLon() + "," + orderLogistics1.getEndLat(); } break; } if(state == 7 || state == 8 || state == 9 || state == 10 || state == 12){//删除定时任务 this.removeTask(orderId, orderType); return; } //计算预计距离和剩余时间 String value = (String) redisTemplate.opsForValue().get("dache:DRIVER" + String.valueOf(driverId)); if(null == value || "".equals(value)){ return; } JSONObject msg = new JSONObject(); msg.put("code", 200); msg.put("msg", "SUCCESS"); msg.put("method", "DRIVER_POSITION"); Map map = new HashMap<>(); map.put("orderId", String.valueOf(orderId)); map.put("orderType", String.valueOf(orderType)); map.put("lon", (null != value ? value.split(",")[0] : "")); map.put("lat", (null != value ? value.split(",")[1] : "")); if((state == 2 || state == 3 || state == 4) || (oldState != null && (oldState == 2 || oldState == 3 || oldState == 4))){//前往预约地 // TODO: 2023/11/4 无法修改 Map distance = gdMapElectricFenceUtil.getDistance(value, startLonLat, 1); String d = "0"; String t = "0"; if(null == distance){ System.err.println("查询距离出错了"); return; }else{ d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000), new MathContext(2, RoundingMode.HALF_EVEN)).toString(); t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60), new MathContext(2, RoundingMode.HALF_EVEN)).intValue() + ""; } map.put("reservationMileage", d);//当前位置距离预约点的剩余里程 map.put("reservationTime", t);//当前位置距离预约点的剩余分钟 map.put("servedMileage", "0");//距离起点已经服务的里程 map.put("servedTime", "0");//距离起点已经服务的时间 map.put("laveMileage", "0");//距离终点剩余未服务的里程数 map.put("laveTime", "0");//距离终端剩余未服务的预计时间 } if((state == 5 || state == 6) || (oldState != null && (oldState == 5 || oldState == 6))){//服务中 if(endLonLat.equals(",")){ map.put("laveMileage", "0");//距离终点剩余未服务的里程数 map.put("laveTime", "0");//距离终端剩余未服务的预计时间 }else{ map.put("reservationMileage", "0");//当前位置距离预约点的剩余里程 map.put("reservationTime", "0");//当前位置距离预约点的剩余分钟 map.put("servedMileage", String.valueOf((null == servedMileage ? 0 : servedMileage) / 1000));//距离起点已经服务的里程 Integer servedTime = Long.valueOf((System.currentTimeMillis() - startServiceTime) / 60000).intValue(); map.put("servedTime", servedTime + "");//距离起点已经服务的时间 // TODO: 2023/11/4 无法修改 Map distance = gdMapElectricFenceUtil.getDistance(value, endLonLat, 1); String d = "0"; String t = "0"; if(null == distance){ System.err.println("查询距离出错了"); }else{ d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000), new MathContext(2, RoundingMode.HALF_EVEN)).toString(); t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60), new MathContext(2, RoundingMode.HALF_EVEN)).intValue() + ""; } map.put("laveMileage", d);//距离终点剩余未服务的里程数 map.put("laveTime", t);//距离终端剩余未服务的预计时间 } } msg.put("data", map); String value1 = (String) redisTemplate.opsForValue().get(orderId + "_" + orderType); if (ToolUtil.isEmpty(value1)) { this.removeTask(orderId, orderType); return; } JSONObject jsonObject = JSON.parseObject(value1); //调用推送 HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient"); post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); //将请求头部和参数合成一个请求 Map params = new HashMap<>(); params.put("msg", msg.toJSONString()); params.put("id", jsonObject.getIntValue("id")); params.put("type", jsonObject.getIntValue("type")); params.put("bussinessType", "dache"); post.form(params); HttpResponse execute = post.execute(); if (200 != execute.getStatus()) { System.err.println("推送异常"); } else { JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class); if (jsonObject1.getIntValue("code") != 200) { System.err.println(jsonObject1.getString("msg")); } } } /** * 推送强迫下线 * @param id * @param type */ public void pushOffline(Integer id, Integer type) { JSONObject msg = new JSONObject(); msg.put("code", 200); msg.put("msg", "SUCCESS"); msg.put("method", "OFFLINE"); msg.put("data", new Object()); //调用推送 HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient"); post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); //将请求头部和参数合成一个请求 Map params = new HashMap<>(); params.put("msg", msg.toJSONString()); params.put("id", id); params.put("type", type); params.put("bussinessType", "dache"); post.form(params); HttpResponse execute = post.execute(); if (200 != execute.getStatus()) { System.err.println("推送异常"); } else { JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class); if (jsonObject1.getIntValue("code") != 200) { System.err.println(jsonObject1.getString("msg")); } } } /** * 摆渡抢单成功后推单 * @param type * @param uid * @param orderId * @param orderType * @param state */ public void pushFerryOrderState(Integer type, Integer uid, Integer orderId, Integer orderType, Integer state){ JSONObject jsonObject = new JSONObject(); jsonObject.put("code", 200); jsonObject.put("msg", "SUCCESS"); jsonObject.put("method", "FERRY"); Map map = new HashMap<>(); map.put("orderId", orderId); map.put("orderType", orderType); map.put("state", state); jsonObject.put("data", map); //调用推送 HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient"); post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); //将请求头部和参数合成一个请求 Map params = new HashMap<>(); params.put("msg", jsonObject.toJSONString()); params.put("id", uid); params.put("type", type); params.put("bussinessType", "dache"); post.form(params); HttpResponse execute = post.execute(); if (200 != execute.getStatus()) { System.err.println("推送异常"); } else { JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class); if (jsonObject1.getIntValue("code") != 200) { System.err.println(jsonObject1.getString("msg")); } } } /** * 小件物流差价支付的推送 * @param type * @param uid * @param orderId * @param orderType * @param money */ public void pushPayDifference(Integer type, Integer uid, Integer orderId, Integer orderType, Double money){ JSONObject jsonObject = new JSONObject(); jsonObject.put("code", 200); jsonObject.put("msg", "SUCCESS"); jsonObject.put("method", "DIFFERENCE"); Map map = new HashMap<>(); map.put("orderId", orderId); map.put("orderType", orderType); map.put("money", money); jsonObject.put("data", map); //调用推送 HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient"); post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); //将请求头部和参数合成一个请求 Map params = new HashMap<>(); params.put("msg", jsonObject.toJSONString()); params.put("id", uid); params.put("type", type); params.put("bussinessType", "dache"); post.form(params); HttpResponse execute = post.execute(); if (200 != execute.getStatus()) { System.err.println("推送异常"); } else { JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class); if (jsonObject1.getIntValue("code") != 200) { System.err.println(jsonObject1.getString("msg")); } } } /** * 删除定时任务 * @param orderId */ public void removeTask(Integer orderId, Integer orderType){ Timer timer = taskMap.get(orderId + "_" + orderType); if (null != timer){ timer.cancel(); taskMap.remove(orderId + "_" + orderType); redisTemplate.delete(orderId + "_" + orderType); } } }