package com.supersavedriving.driver.modular.system.util;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
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.*;
|
|
/**
|
* socket推单处理类
|
*/
|
@Component
|
public class PushUtil {
|
|
@Autowired
|
private RestTemplate internalRestTemplate;
|
|
@Autowired
|
private RedisUtil redisUtil;
|
|
private Map<String, JSONObject> pushMap = new HashMap<>();//存储需要定时推送的数据
|
|
private Map<String, Timer> taskMap = new HashMap<>();//存储定时推送的定时器
|
|
|
|
/**
|
* 推送强迫下线
|
* @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("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"));
|
}
|
}
|
|
|
}
|