| | |
| | | package com.ruoyi.sy.service.impl; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | |
| | | import com.ruoyi.system.mapper.SysConfigMapper; |
| | | import com.ruoyi.utils.forest.SYClient; |
| | | import com.ruoyi.utils.websocket.util.WebSocketUtils; |
| | | import okhttp3.OkHttpClient; |
| | | import okhttp3.Request; |
| | | import okhttp3.Response; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | |
| | | @Resource |
| | | private SYClient sYClient; |
| | | |
| | | private Map<String,Thread> alarmMap = new HashMap();//电磁锁历史报警线程容器 |
| | | |
| | | /** |
| | | * 查询电磁锁 |
| | |
| | | WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(userId), JSON.toJSONString(data)); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void getAlarm(String syUserId,String syPassword) { |
| | | List<SysConfig> syURLResult = sysConfigMapper.selectByType("syCarPT"); |
| | | String syURL = ""; |
| | | if(syURLResult.size() != 0){ |
| | | syURL = syURLResult.get(0).getConfigValue(); |
| | | }else{ |
| | | return; |
| | | } |
| | | String finalSyURL = syURL; |
| | | |
| | | String passwordMd5 = DigestUtils.md5Hex(syPassword); |
| | | Map<String, Object> LogInResult = sYClient.logIn(syURL, passwordMd5, syUserId); |
| | | String sessionId = (String) LogInResult.get("sessionId"); |
| | | |
| | | List<ArdTankLock> ardTankLockResult = ardTankLockMapper.getAll(); |
| | | for(ArdTankLock ardTankLock : ardTankLockResult){ |
| | | if(this.alarmMap.get(ardTankLock.getLockNum()) != null){ |
| | | continue;//当前锁已在获取报警,不在创建线程 |
| | | } |
| | | Thread thread = new Thread(finalSyURL){ |
| | | @Override |
| | | public void run() { |
| | | try{ |
| | | String lockNum = ardTankLock.getLockNum(); |
| | | String lockNumHead = lockNum.substring(0,2); |
| | | String lockNumTail = lockNum.substring(2,4); |
| | | String checkNum = Integer.toHexString(Integer.parseInt(lockNumHead, 16)//锁编号高8位 |
| | | + Integer.parseInt(lockNumTail, 16)//锁编号低8位 |
| | | + Integer.parseInt("06", 16));//设置锁芯状态功能码06 |
| | | if(checkNum.length() == 1){ |
| | | checkNum = "0" + checkNum; |
| | | } |
| | | if(checkNum.length() > 2){ |
| | | checkNum = checkNum.substring(checkNum.length() - 2,checkNum.length()); |
| | | } |
| | | |
| | | String paramsStr = lockNum + "06" + checkNum; |
| | | paramsStr = "%7B%22type%22%3A%22ff%22%2C%22dataCnt%22%3A%22" + paramsStr + "%22%7D"; |
| | | Map<String,Object> result = sendCmd(finalSyURL, syUserId, ardTankLock.getCarId(), 199, "DataDownTransfer", paramsStr, sessionId); |
| | | alarmMap.remove(ardTankLock.getLockNum()); |
| | | }catch(Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | alarmMap.put(ardTankLock.getLockNum(),thread); |
| | | } |
| | | } |
| | | |
| | | public Map<String,Object> sendCmd(String syURL,String userId,String carId,Integer cmdId,String cmd,String paramsStr,String sessionId){ |
| | | OkHttpClient okHttpClient = new OkHttpClient(); |
| | | |
| | | Request request = new Request.Builder() |
| | | .url(syURL + "/gps-web/api/send_cmd.jsp?params="+paramsStr+"&userId="+userId+"&carId="+carId+"&cmdId="+cmdId+"&cmd="+cmd+"&sessionId="+sessionId) |
| | | .build(); |
| | | //System.out.println("url = " + syURL + "/gps-web/api/send_cmd.jsp?params="+paramsStr+"&userId="+userId+"&carId="+carId+"&cmdId="+cmdId+"&cmd="+cmd+"&sessionId="+sessionId); |
| | | Response response = null; |
| | | try { |
| | | response = okHttpClient.newCall(request).execute(); |
| | | } catch (IOException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | okhttp3.ResponseBody responseBody = response.body(); |
| | | |
| | | try { |
| | | String message = responseBody.string();// 响应体 |
| | | Map<String,Object> map = (Map<String, Object>) com.alibaba.fastjson2.JSON.parse(message); |
| | | return map; |
| | | } catch (IOException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | return new HashMap(); |
| | | } |
| | | } |
| | | } |