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 pushMap = new HashMap<>();//存储需要定时推送的数据 private Map 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 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 params = new LinkedMultiValueMap<>(); params.add("msg", jsonObject.toJSONString()); params.add("id", String.valueOf(uid)); params.add("type", String.valueOf(type)); HttpEntity> 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")); } } }