| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 通知原司机改派结果(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); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 推送司机位置给乘客端 |