| ¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * <p>Description: </p> |
| | | * <p>Copyright: Copyright (c) 2020</p> |
| | | * <p>Company: www.31gps.net</p> |
| | | * @author chencq |
| | | * @version 1.0 |
| | | */ |
| | | package com.ruoyi.sy.gps31; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.gps31.push.netty.PushClient; |
| | | import com.gps31.push.netty.PushMsg; |
| | | import com.gps31.push.netty.client.TcpClient; |
| | | import com.gps31.push.util.MapUtil; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.sy.service.impl.ArdSyCarServiceImpl; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * <p>Description: </p> |
| | | * <p>Copyright: Copyright (c) 2020</p> |
| | | * <p>Company: www.31gps.net</p> |
| | | * @author chencq |
| | | * @version 1.0 |
| | | */ |
| | | public class PushClientImplAlarm extends PushClient implements Runnable { |
| | | |
| | | private static final Log log = LogFactory.getLog(PushClientImplAlarm.class); |
| | | |
| | | private String ip; |
| | | |
| | | private String userId; |
| | | |
| | | private String password; |
| | | |
| | | public PushClientImplAlarm(String ip, String userId, String password) { |
| | | this.ip = ip; |
| | | this.userId = userId; |
| | | this.password = password; |
| | | } |
| | | |
| | | public PushClientImplAlarm() { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void messageReceived(TcpClient tcpClient, PushMsg pushMsg) |
| | | throws Exception { |
| | | if("8001".equals(pushMsg.getCmd())) {//ç»å½åºç |
| | | String rspResult = MapUtil.getStrVal(pushMsg.getJsonMap(),"rspResult","1"); |
| | | if("0".equals(rspResult)) {//ç»å½æåï¼å®é
å¨ææ¶æ¯ |
| | | Map<String,Object> map = new HashMap<String,Object>(); |
| | | map.put("seq", "1"); |
| | | map.put("action", "add"); |
| | | map.put("msgIds", JSON.toJSONString(getSubCmdSet())); |
| | | PushMsg subMsg = getInstance("0003",map); |
| | | sendMsg(subMsg); |
| | | } |
| | | }else if("8002".equals(pushMsg.getCmd())){//å¿è·³åºç |
| | | |
| | | }else if("8003".equals(pushMsg.getCmd())){//订é
å¨ææ¶æ¯åºç |
| | | String rspResult = MapUtil.getStrVal(pushMsg.getJsonMap(),"rspResult","1"); |
| | | //log.error(String.format(" 订é
åºç:%s", "0".equals(rspResult)?"æå":"失败")); |
| | | }else if("0200".equals(pushMsg.getCmd())) {//å®ä½ä¿¡æ¯ |
| | | Map<String,Object> gpsMap = pushMsg.getJsonMap(); |
| | | String carName = MapUtil.getStrVal(gpsMap, "carName","");//è·å车çå· |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | System.out.println(sdf.format(new Date())); |
| | | //log.error(String.format(" ---->æ¶å°å®ä½æ°æ®:%s",JSON.toJSONString(gpsMap))); |
| | | /** |
| | | * |
| | | * 请å å
¥ä¸æ¹éææ¹çä¸å¡é»è¾ |
| | | * |
| | | */ |
| | | }else if("0300".equals(pushMsg.getCmd())) {//æ¥è¦æ¶æ¯ |
| | | Map<String,Object> alarmMap = pushMsg.getJsonMap(); |
| | | /*String carName = MapUtil.getStrVal(alarmMap, "carName","");//è·å车çå· |
| | | log.error(String.format(" ---->æ¶å°æ¥è¦æ°æ®:%s",JSON.toJSONString(alarmMap)));*/ |
| | | String carId = (String)alarmMap.get("carId"); |
| | | Map<String,Object> result = ((ArdSyCarServiceImpl) SpringUtils.getBean("ardSyCarServiceImpl")).getArdSyCarAndDeptByCarId(carId);//æ¥è¯¢è½¦è¾åé¨é¨ |
| | | if(result != null){ |
| | | alarmMap.putAll(result); |
| | | } |
| | | Map<Integer,Object> data = new HashMap(); |
| | | data.put(40000, alarmMap); |
| | | ((ArdSyCarServiceImpl) SpringUtils.getBean("ardSyCarServiceImpl")).sendArdSyCarAlarmByCarId(carId,data);//æ¥è¯¢è½¦è¾åé¨é¨ |
| | | }else if("0401".equals(pushMsg.getCmd())) {//éä¼ æ¶æ¯ |
| | | Map<String,Object> dataMap = pushMsg.getJsonMap(); |
| | | String carName = MapUtil.getStrVal(dataMap, "carName","");//è·å车çå· |
| | | //log.error(String.format(" ---->æ¶å°éä¼ æ°æ®:%s",JSON.toJSONString(dataMap))); |
| | | /** |
| | | * |
| | | * 请å å
¥ä¸æ¹éææ¹çä¸å¡é»è¾ |
| | | * |
| | | */ |
| | | } |
| | | } |
| | | |
| | | public void sendMassage() { |
| | | try { |
| | | PushClientImplPosition client = new PushClientImplPosition(); |
| | | client.setLog(false);//æ¯å¦æå°ææ |
| | | client.setHost(this.ip);//æå¡å¨IP |
| | | client.setPort(10100);//æå¡å¨ç«¯å£ |
| | | client.setUserName(this.userId);//ç³»ç»ç¨æ·å |
| | | client.setPwd(this.password);//ç³»ç»ç¨æ·å¯ç |
| | | client.setSubMsgIds("0300");//订é
çå¨ææ¶æ¯ï¼å¤ä¸ªå¨ææ¶æ¯ä½¿ç¨|è¾åï¼å½åç¤ºä¾æ¯è®¢é
å®ä½æ¶æ¯(0x0200)åæ¥è¦æ¶æ¯(0x0300) |
| | | client.setDesc("æµè¯å®¢æ·ç«¯");//客æ·ç«¯çæè¿°ï¼ |
| | | client.start(); |
| | | while(true) { |
| | | Thread.sleep(1000); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void run() { |
| | | sendMassage(); |
| | | } |
| | | } |