xuhy
2025-08-08 6408a348e14193b0f625673d4e4b22b9fbd1e369
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package com.stylefeng.guns.modular.system.controller.util;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil;
import com.stylefeng.guns.modular.system.util.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.*;
 
/**
 * socket推单处理类
 */
@Component
public class PushUtil {
    
    private Logger log = LoggerFactory.getLogger(PushUtil.class);
 
    @Autowired
    private RestTemplate internalRestTemplate;
 
 
    @Autowired
    private GDMapElectricFenceUtil gdMapElectricFenceUtil;
 
 
    @Autowired
    private RedisUtil redisUtil;
 
    private Map<String, JSONObject> pushMap = new HashMap<>();//存储需要定时推送的数据
 
    private Map<String, Timer> taskMap = new HashMap<>();//存储定时推送的定时器
 
 
 
    /**
     * 推送订单状态
     * @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<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("http://message-push/netty/sendMsgToClient",requestEntity , String.class);
        JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class);
        if(jsonObject1.getIntValue("code") != 200){
            log.error(jsonObject1.getString("msg"));
        }
    }
 
 
 
}