package com.stylefeng.guns.modular.system.controller.util;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil;
|
import com.stylefeng.guns.modular.system.util.PushURL;
|
import com.stylefeng.guns.modular.system.util.RedisUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.MediaType;
|
import org.springframework.stereotype.Component;
|
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
import org.springframework.web.client.RestTemplate;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
import java.util.Timer;
|
|
/**
|
* socket推单处理类
|
*/
|
@Component
|
public class PushUtil {
|
|
@Autowired
|
private RestTemplate internalRestTemplate;
|
|
@Autowired
|
private RedisUtil redisUtil;
|
|
|
|
@Autowired
|
private GDMapElectricFenceUtil gdMapElectricFenceUtil;
|
|
|
|
private Map<String, JSONObject> pushMap = new HashMap<>();//存储需要定时推送的数据
|
|
private Map<String, Timer> taskMap = new HashMap<>();//存储定时推送的定时器
|
|
/**
|
* 后台 冻结订单 向司机端推送消息
|
* @param uid
|
* @param type
|
*/
|
public void frozenOrder(Integer uid,Integer type){
|
System.err.println("后台 冻结订单 向司机端推送消息");
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("code", 200);
|
jsonObject.put("msg", "SUCCESS");
|
jsonObject.put("method", "FROZEN_ORDER");
|
Map<String, Object> map = new HashMap<>();
|
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(PushURL.zull_user_url + "/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 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=改派中,12=取消待支付)
|
*/
|
public void pushOrderState(Integer type, Integer uid, Integer orderId, Integer orderType, Integer state, Integer time, String audioUrl){
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("code", 200);
|
jsonObject.put("msg", "SUCCESS");
|
jsonObject.put("method", "ORDER_STATUS");
|
Map<String, Object> map = new HashMap<>();
|
map.put("orderId", orderId);
|
map.put("orderType", orderType);
|
map.put("state", state);
|
map.put("time", time);
|
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(PushURL.zull_user_url + "/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 orderId
|
* @param orderType
|
*/
|
public void pushEndPush(Integer type, Integer uid, Integer orderId, Integer orderType){
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("code", 200);
|
jsonObject.put("msg", "SUCCESS");
|
jsonObject.put("method", "END_PUSH");
|
Map<String, Object> map = new HashMap<>();
|
map.put("orderId", orderId);
|
map.put("orderType", orderType);
|
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(PushURL.zull_user_url + "/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 orderId
|
* @param orderType
|
*/
|
public void pushDriverTimeOut(Integer type, Integer uid, Integer orderId, Integer orderType){
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("code", 200);
|
jsonObject.put("msg", "SUCCESS");
|
jsonObject.put("method", "DRIVER_TIME_OUT");
|
Map<String, Object> map = new HashMap<>();
|
map.put("orderId", orderId);
|
map.put("orderType", orderType);
|
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(PushURL.zull_user_url + "/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 orderId
|
* @param orderType
|
* @param status 1=申请,2=同意,3=拒绝
|
*/
|
public void pushModifyAddress(Integer type, Integer uid, Integer orderId, Integer orderType, Integer status, String audioUrl){
|
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);
|
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(PushURL.zull_user_url + "/netty/sendMsgToClient",requestEntity , String.class);
|
JSONObject jsonObject1 = JSON.parseObject(s, 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());
|
|
//调用推送
|
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(PushURL.zull_user_url + "/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 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<String, Object> map = new HashMap<>();
|
map.put("orderId", orderId);
|
map.put("orderType", orderType);
|
map.put("state", state);
|
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(PushURL.zull_user_url + "/netty/sendMsgToClient",requestEntity , String.class);
|
JSONObject jsonObject1 = JSON.parseObject(s, 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();
|
}
|
}
|
|
|
/**
|
* 线下支付数据推送
|
* @param type
|
* @param uid
|
* @param orderId
|
* @param orderType
|
*/
|
public void pushOfflinePayment(Integer type, Integer uid, Integer orderId, Integer orderType){
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("code", 200);
|
jsonObject.put("msg", "SUCCESS");
|
jsonObject.put("method", "OFFLINE_PAYMENT");
|
Map<String, Object> map = new HashMap<>();
|
map.put("orderId", orderId);
|
map.put("orderType", orderType);
|
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(PushURL.zull_user_url + "/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 orderId
|
* @param orderType
|
* @param money
|
* @param status 1=申请,2=同意,3=拒绝
|
*/
|
public void pushPayDifference(Integer type, Integer uid, Integer orderId, Integer orderType, Double money, Integer status, String audioUrl){
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("code", 200);
|
jsonObject.put("msg", "SUCCESS");
|
jsonObject.put("method", "DIFFERENCE");
|
Map<String, Object> map = new HashMap<>();
|
map.put("orderId", orderId);
|
map.put("orderType", orderType);
|
map.put("money", money);
|
map.put("status", status);
|
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(PushURL.zull_user_url + "/netty/sendMsgToClient",requestEntity , String.class);
|
JSONObject jsonObject1 = JSON.parseObject(s, 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, String audioUrl){
|
JSONObject jsonObject = new JSONObject();
|
jsonObject.put("code", 200);
|
jsonObject.put("msg", "SUCCESS");
|
jsonObject.put("method", "REASSIGN");
|
Map<String, Object> map = new HashMap<>();
|
map.put("orderId", orderId);
|
map.put("orderType", orderType);
|
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", type.toString());
|
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers);
|
String s = internalRestTemplate.postForObject(PushURL.zull_user_url + "/netty/sendMsgToClient",requestEntity , String.class);
|
JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class);
|
if(jsonObject1.getIntValue("code") != 200){
|
System.err.println(jsonObject1.getString("msg"));
|
}
|
}
|
}
|