| | |
| | | import com.gps31.push.netty.PushMsg; |
| | | import com.gps31.push.netty.client.TcpClient; |
| | | import com.gps31.push.util.MapUtil; |
| | | import com.ruoyi.common.core.domain.entity.SysConfig; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.sy.domain.ArdSyCarLock; |
| | | import com.ruoyi.sy.domain.ArdSyCarRtu; |
| | | import com.ruoyi.sy.domain.ArdTankLock; |
| | | import com.ruoyi.sy.service.ArdSyCarLockService; |
| | | import com.ruoyi.sy.service.ArdSyCarRtuService; |
| | | import com.ruoyi.sy.service.impl.ArdSyCarDayServiceImpl; |
| | | import com.ruoyi.sy.service.impl.ArdSyCarServiceImpl; |
| | | import com.ruoyi.sy.service.impl.ArdTankAbnormalParkAlarmServiceImpl; |
| | | import com.ruoyi.sy.service.impl.ArdTankLockServiceImpl; |
| | | import com.ruoyi.system.service.impl.SysConfigServiceImpl; |
| | | import com.ruoyi.utils.forest.SYClient; |
| | | import com.ruoyi.utils.qymqtt.newM.EmqClient; |
| | | import com.ruoyi.utils.qymqtt.newM.QosEnum; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.eclipse.paho.client.mqttv3.MqttException; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * <p>Description: </p> |
| | |
| | | |
| | | private String password; |
| | | |
| | | private Timer lockStateTimer; |
| | | |
| | | public PushClientImplSerialPort(String ip, String userId, String password) { |
| | | this.ip = ip; |
| | | this.userId = userId; |
| | | this.password = password; |
| | | |
| | | /*Date date = new Date(); |
| | | this.lockStateTimer = new Timer();//定时获取各个锁的状态 |
| | | TimerTask lockStateTask =new TimerTask(){ |
| | | @Override |
| | | public void run(){ |
| | | SysConfig config = new SysConfig(); |
| | | config.setConfigKey("syCarPT"); |
| | | List<SysConfig> sysConfigResult = ((SysConfigServiceImpl)SpringUtils.getBean("sysConfigServiceImpl")).selectConfigList(config); |
| | | String syURL = ""; |
| | | |
| | | if(sysConfigResult.size() == 0){//三一车辆加入开关 |
| | | return; |
| | | }else{ |
| | | syURL = sysConfigResult.get(0).getConfigValue(); |
| | | } |
| | | String passwordMd5 = DigestUtils.md5Hex(password); |
| | | Map<String, Object> LogInResult = ((SYClient)SpringUtils.getBean("sYClient")).logIn(syURL, passwordMd5, userId); |
| | | String sessionId = (String) LogInResult.get("sessionId"); |
| | | |
| | | String finalSyURL = syURL; |
| | | Thread thread = new Thread(finalSyURL){ |
| | | @Override |
| | | public void run() { |
| | | List<ArdTankLock> result = ((ArdTankLockServiceImpl)SpringUtils.getBean("ardTankLockServiceImpl")).getArdTankLockAll();//查询全部电磁锁 |
| | | for(ArdTankLock ardTankLock : result){ |
| | | //Thread LockThread = new Thread(finalSyURL){ |
| | | String lockNumHead = ardTankLock.getLockNum().substring(0,2); |
| | | String lockNumTail = ardTankLock.getLockNum().substring(2,4); |
| | | //计算校验 |
| | | String checkNum = Integer.toHexString(Integer.parseInt(lockNumHead, 16) + Integer.parseInt(lockNumTail, 16) + Integer.parseInt("01", 16)); |
| | | |
| | | if(checkNum.length() == 1){ |
| | | checkNum = "0" + checkNum; |
| | | }else if(checkNum.length() > 2){ |
| | | checkNum = checkNum.substring(checkNum.length() - 2,checkNum.length()); |
| | | } |
| | | |
| | | String paramsStr = "%7B%22type%22%3A%22ff%22%2C%22dataCnt%22%3A%22" + ardTankLock.getLockNum() + "01" + checkNum + "%22%7D"; |
| | | |
| | | //Map<String,Object> result = ((SYClient)SpringUtils.getBean("sYClient")).sendCmd(finalSyURL,userId,ardTankLock.getCarId(),199,"DataDownTransfer", paramsStr,sessionId); |
| | | //}; |
| | | //LockThread.start(); |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | } |
| | | }; |
| | | lockStateTimer.scheduleAtFixedRate(lockStateTask,date,1000);*/ |
| | | } |
| | | |
| | | public PushClientImplSerialPort() { |
| | |
| | | public void sendMassage() { |
| | | try { |
| | | PushClientImplSerialPort client = new PushClientImplSerialPort(); |
| | | client.setLog(false);//是否打印明文 |
| | | client.setLog(true);//是否打印明文 |
| | | client.setHost(this.ip);//服务器IP |
| | | client.setPort(10100);//服务器端口 |
| | | client.setUserName(this.userId);//系统用户名 |
| | |
| | | public void run() { |
| | | sendMassage(); |
| | | } |
| | | |
| | | private void feng(String carId,String type,ArdSyCarRtuService carRtuService,ArdSyCarLockService lockService) throws MqttException { |
| | | //查询装油点既定Rtu状态 |
| | | ArdSyCarRtu ardSyCarRtu = carRtuService.one(carId); |
| | | if(ardSyCarRtu!=null){ |
| | | //查询锁信息 |
| | | List<ArdSyCarLock> ardSyCarLocks = lockService.carLock(ardSyCarRtu.getId()); |
| | | if(ardSyCarLocks.size()>0){ |
| | | Integer fengType = null; |
| | | if("装油点".equals(type)){ |
| | | fengType = ardSyCarRtu.getInstallType(); |
| | | }else if("卸油点".equals(type)){ |
| | | fengType = ardSyCarRtu.getUnloadType(); |
| | | }else if("施封".equals(type)){ |
| | | fengType = 0; |
| | | } |
| | | //1解封 |
| | | if(fengType==1){ |
| | | //如果不是解封封状态,则发送施封命令 |
| | | if(ardSyCarLocks.get(0).getRelayInfo()==0 || ardSyCarLocks.get(0).getRelayInfo()==null){ |
| | | // Map<String,Object> map = new HashMap<>(); |
| | | // map.put("A01", 110000);//导通第一路继电器 |
| | | // map.put("A02", 110000);//导通第二路继电器 |
| | | // map.put("res", String.valueOf(System.currentTimeMillis())); |
| | | // String mapString = com.alibaba.fastjson.JSON.toJSONString(map); |
| | | String mapString = "{\"A01\":110000,\"A02\":110000,\"res\":\""+String.valueOf(System.currentTimeMillis())+"\"}"; |
| | | log.debug("自动解封:"+mapString); |
| | | EmqClient emqClient = new EmqClient(carId+"mqttPublish"+UUID.randomUUID()); |
| | | emqClient.connect(); |
| | | emqClient.publish(ardSyCarRtu.getTopicPublish(),mapString, QosEnum.QoS2,false); |
| | | log.debug("车辆"+carId+"解封命令发送成功!"); |
| | | // mqttOnce.publishCar(carId,ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"解封"); |
| | | } |
| | | } |
| | | |
| | | //0施封 |
| | | if(fengType==0){ |
| | | if(ardSyCarLocks.get(0).getRelayInfo()==1 || ardSyCarLocks.get(0).getRelayInfo()==null){ |
| | | //锁开关状态 |
| | | int lockCloseNum = 0; |
| | | String mapString1 = "{\"A01\":100000,\"A02\":100000,\"res\":\""+String.valueOf(System.currentTimeMillis())+"\"}"; |
| | | System.out.println("自动施封:"+mapString1); |
| | | EmqClient emqClient1 = new EmqClient(carId+"mqttPublish"+UUID.randomUUID()); |
| | | emqClient1.connect(); |
| | | emqClient1.publish(ardSyCarRtu.getTopicPublish(),mapString1, QosEnum.QoS2,false); |
| | | //如果不是施封状态,则发送施封命令 |
| | | if(ardSyCarLocks.get(0).getRelayInfo()!=null){ |
| | | if(ardSyCarLocks.get(0).getRelayInfo()==1){ |
| | | for (int j = 0; j < ardSyCarLocks.size(); j++) { |
| | | ArdSyCarLock ardSyCarLock = ardSyCarLocks.get(j); |
| | | String currents = ardSyCarLock.getCurrents(); |
| | | Double currentInfo = ardSyCarLock.getCurrentInfo(); |
| | | //电流值为4.0是关锁状态 |
| | | if(currentInfo.equals(4.00) || currentInfo.equals(4)){ |
| | | lockCloseNum += 1; |
| | | }else { |
| | | String key = ""; |
| | | if(currents.equals("C01")){ |
| | | key = "D03"; |
| | | }else if(currents.equals("C02")){ |
| | | key = "D04"; |
| | | } |
| | | // Map<String,Object> map = new HashMap(); |
| | | // map.put(key, 0.01); |
| | | // map.put("res", String.valueOf(System.currentTimeMillis())); |
| | | // String mapString = com.alibaba.fastjson.JSON.toJSONString(map); |
| | | String mapString = "{\""+key+"\":0.01,\"res\":\""+String.valueOf(System.currentTimeMillis())+"\"}"; |
| | | log.debug("自动关锁:"+mapString); |
| | | EmqClient emqClient = new EmqClient(carId+"mqttPublish"+UUID.randomUUID()); |
| | | emqClient.connect(); |
| | | emqClient.publish(ardSyCarRtu.getTopicPublish(),mapString, QosEnum.QoS2,false); |
| | | // mqttOnce.publishCar("carId",ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"开锁:"+currents); |
| | | while(true){ |
| | | ArdSyCarLock ardSyCarLock1 = lockService.getCurrentInfo(ardSyCarRtu.getId(),currents); |
| | | Double currentInfo1 = ardSyCarLock1.getCurrentInfo(); |
| | | if(currentInfo1.equals(4.00) || currentInfo1.equals(4)){ |
| | | lockCloseNum +=1; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if(lockCloseNum == 2){ |
| | | // Map<String,Object> map = new HashMap<>(); |
| | | // map.put("A01", 100000);//断开第一路继电器 |
| | | // map.put("A02", 100000);//断开第二路继电器 |
| | | // map.put("res", String.valueOf(System.currentTimeMillis())); |
| | | // String mapString = com.alibaba.fastjson.JSON.toJSONString(map); |
| | | log.debug("车辆"+carId+"施封命令发送成功!"); |
| | | // mqttOnce.publishCar(carId,ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"施封"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | public Double[] azimuth_offset(double origin_lon, double origin_lat, Integer direction,double distance){ |
| | | Double[] lonlat = new Double[2]; |
| | | if(direction != null && distance > 0){ |
| | | lonlat[0] = origin_lon + distance * Math.sin(direction* Math.PI / 180) * 180 / ( Math.PI * 6371229 * Math.cos(origin_lat * Math.PI / 180)); |
| | | lonlat[1] = origin_lat + distance * Math.cos(direction* Math.PI / 180) / ( Math.PI * 6371229 / 180); |
| | | }else{ |
| | | lonlat[0] = origin_lon; |
| | | lonlat[1] = origin_lat; |
| | | } |
| | | return lonlat; |
| | | } |
| | | |
| | | public Double getDistance(Double velocity ,Double acceleration ,String time){ |
| | | Double distance = velocity*Double.parseDouble(time) + 0.5*acceleration*Double.parseDouble(time)*Double.parseDouble(time); |
| | | return distance; |
| | | } |
| | | |
| | | /*public Double getVelocity(Double velocity ,Double acceleration ,String time){ |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | Long t = (long) 0; |
| | | try { |
| | | t = (new Date().getTime() - simpleDateFormat.parse(time).getTime())/1000; |
| | | } catch (Exception e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } |
| | | Double velocityt = velocity + acceleration*t; |
| | | return velocityt; |
| | | }*/ |
| | | |
| | | } |