| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 推送改派确认请求给目标司机(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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 推送司机位置给乘客端 |