| | |
| | | import com.stylefeng.guns.modular.taxi.model.OrderTaxi; |
| | | import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.MathContext; |
| | |
| | | */ |
| | | @Component |
| | | public class PushUtil { |
| | | |
| | | @Autowired |
| | | private RestTemplate internalRestTemplate; |
| | | |
| | | @Autowired |
| | | private IOrderTaxiService orderTaxiService; |
| | |
| | | |
| | | private Map<String, Timer> taskMap = new HashMap<>();//存储定时推送的定时器 |
| | | |
| | | private final String socket_uri = "http://172.21.35.142:6000"; |
| | | @Value("${qyt.socket_uri}") |
| | | private String socket_uri; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | // qyt 改派重新推单 |
| | | public void pushOrderState(Integer type, Integer uid, Integer orderId, Integer orderType, Integer state, Integer time) { |
| | | 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("time", time); |
| | | if (orderType == 1 && state == 100) { |
| | | map.put("carpooling", 1); |
| | | map.put("state", 2); |
| | | } else { |
| | | map.put("state", state); |
| | | } |
| | | 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", uid); |
| | | params.put("type", type); |
| | | params.put("bussinessType", "dache"); |
| | | post.form(params); |
| | | HttpResponse execute = post.execute(); |
| | | 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")); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 推单完成后,没有司机接单的推送提醒 qyt |
| | | * |
| | | * @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); |
| | | |
| | | //调用推送 |
| | | 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", uid); |
| | | params.put("type", type); |
| | | params.put("bussinessType", "dache"); |
| | | post.form(params); |
| | | HttpResponse execute = post.execute(); |
| | | 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")); |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * 推送订单状态 |
| | | * |
| | |
| | | params.put("msg", jsonObject.toJSONString()); |
| | | params.put("id", uid); |
| | | params.put("type", type); |
| | | params.put("bussinessType", "dache"); |
| | | post.form(params); |
| | | HttpResponse execute = post.execute(); |
| | | if (200 != execute.getStatus()) { |
| | |
| | | params.put("msg", jsonObject.toJSONString()); |
| | | params.put("id", uid); |
| | | params.put("type", type); |
| | | params.put("bussinessType", "dache"); |
| | | post.form(params); |
| | | HttpResponse execute = post.execute(); |
| | | if (200 != execute.getStatus()) { |
| | |
| | | return; |
| | | } |
| | | //计算预计距离和剩余时间 |
| | | String value = (String) redisTemplate.opsForValue().get("DRIVER" + String.valueOf(driverId)); |
| | | String value = (String) redisTemplate.opsForValue().get("dache:DRIVER" + String.valueOf(driverId)); |
| | | if(null == value || "".equals(value)){ |
| | | return; |
| | | } |
| | |
| | | params.put("msg", msg.toJSONString()); |
| | | params.put("id", jsonObject.getIntValue("id")); |
| | | params.put("type", jsonObject.getIntValue("type")); |
| | | params.put("bussinessType", "dache"); |
| | | post.form(params); |
| | | HttpResponse execute = post.execute(); |
| | | if (200 != execute.getStatus()) { |
| | |
| | | params.put("msg", msg.toJSONString()); |
| | | params.put("id", id); |
| | | params.put("type", type); |
| | | params.put("bussinessType", "dache"); |
| | | post.form(params); |
| | | HttpResponse execute = post.execute(); |
| | | if (200 != execute.getStatus()) { |
| | |
| | | params.put("msg", jsonObject.toJSONString()); |
| | | params.put("id", uid); |
| | | params.put("type", type); |
| | | params.put("bussinessType", "dache"); |
| | | post.form(params); |
| | | HttpResponse execute = post.execute(); |
| | | if (200 != execute.getStatus()) { |
| | |
| | | params.put("msg", jsonObject.toJSONString()); |
| | | params.put("id", uid); |
| | | params.put("type", type); |
| | | params.put("bussinessType", "dache"); |
| | | post.form(params); |
| | | HttpResponse execute = post.execute(); |
| | | if (200 != execute.getStatus()) { |