From 93cecfaf0fae080ebd0212adea714726290d0d4a Mon Sep 17 00:00:00 2001 From: zhangnaisong <2434969829@qq.com> Date: 星期四, 01 八月 2024 20:36:54 +0800 Subject: [PATCH] 电磁锁串口协议发送加入线程排队提交 --- ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdTankLockProcessLogServiceImpl.java | 101 +++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 78 insertions(+), 23 deletions(-) diff --git a/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdTankLockProcessLogServiceImpl.java b/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdTankLockProcessLogServiceImpl.java index 3021d43..e39bf04 100644 --- a/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdTankLockProcessLogServiceImpl.java +++ b/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdTankLockProcessLogServiceImpl.java @@ -1,20 +1,27 @@ package com.ruoyi.sy.service.impl; import java.awt.geom.Point2D; +import java.io.IOException; import java.text.SimpleDateFormat; import java.util.*; +import com.alibaba.fastjson2.JSON; +import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysConfig; import com.ruoyi.common.utils.uuid.IdUtils; import com.ruoyi.sy.domain.ArdSyUser; import com.ruoyi.sy.domain.ArdTankLock; import com.ruoyi.sy.domain.ArdTankWall; +import com.ruoyi.sy.gps31.PositionContainer; import com.ruoyi.sy.mapper.ArdSyUserMapper; import com.ruoyi.sy.mapper.ArdTankLockMapper; import com.ruoyi.sy.mapper.ArdTankWallMapper; import com.ruoyi.system.mapper.SysConfigMapper; import com.ruoyi.utils.forest.SYClient; import com.ruoyi.utils.gps.GeoTools; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; import org.apache.commons.codec.digest.DigestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -55,6 +62,8 @@ private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private Map<String,Timer> timerMap = new HashMap(); + /** * 鏌ヨ缃愯溅閿佹搷鎺ф棩蹇� * @@ -85,9 +94,9 @@ */ @Override public int insertArdTankLockProcessLog(ArdTankLockProcessLog ardTankLockProcessLog) { - ardTankLockProcessLog.setId(IdUtils.simpleUUID()); - ardTankLockProcessLog.setUserId(SecurityUtils.getUserId()); - return ardTankLockProcessLogMapper.insertArdTankLockProcessLog(ardTankLockProcessLog); + ardTankLockProcessLog.setId(IdUtils.simpleUUID()); + ardTankLockProcessLog.setUserId(SecurityUtils.getUserId()); + return ardTankLockProcessLogMapper.insertArdTankLockProcessLog(ardTankLockProcessLog); } /** @@ -124,7 +133,7 @@ } @Override - public String processArdTankLockByLockId(String userId, String username, Map<String,String> para) { + public AjaxResult processArdTankLockByLockId(String userId, String username, Map<String,String> para) { String lockId = para.get("lockId"); String lockNum = para.get("lockNum"); String carId = para.get("carId"); @@ -134,20 +143,19 @@ //鍒ゆ柇浣胯兘 ArdTankLock ardTankLock = ardTankLockMapper.selectArdTankLockById(lockId); if(ardTankLock.getEnable().equals("false")){ - return "璇ラ攣浣胯兘鍏抽棴锛屾棤娉曟搷鎺�"; + return AjaxResult.error("璇ラ攣浣胯兘鍏抽棴锛屾棤娉曟搷鎺�"); } - ArdSyUser ardSyUser = ardSyUserMapper.userById(userId); if(ardSyUser == null){ - return "鏈寕鎺ヤ笁涓�璐﹀彿"; + return AjaxResult.error("鏈寕鎺ヤ笁涓�璐﹀彿"); } List<SysConfig> syURLResult = sysConfigMapper.selectByType("syCarPT"); String syURL = ""; if(syURLResult.size() != 0){ syURL = syURLResult.get(0).getConfigValue(); }else{ - return "涓変竴骞冲彴鏈綍鍏�"; + return AjaxResult.error("涓変竴骞冲彴鏈綍鍏�"); } String passwordMd5 = DigestUtils.md5Hex(ardSyUser.getPassword()); Map<String, Object> LogInResult = sYClient.logIn(syURL, passwordMd5, ardSyUser.getUserId()); @@ -159,12 +167,14 @@ Map<String,Object> syResult = sYClient.getCarNearPositionByCarId(syURL, carId, ardSyUser.getUserId(), sessionId); if(((String)syResult.get("rspCode")).equals("1")){ Map<String,Object> carMap = ((List<Map<String,Object>>)syResult.get("list")).get(0); + if(Integer.parseInt((String)carMap.get("speed")) != 0){ + return AjaxResult.error("杞﹁締姝e湪琛岄┒涓�"); + } lng = (String) carMap.get("lng"); lat = (String) carMap.get("lat"); carPlate = (String) carMap.get("carName"); - }else{ - return "涓変竴骞冲彴鎶ラ敊"; + return AjaxResult.error("涓変竴骞冲彴鎶ラ敊"); } List<ArdTankWall> ardTankWallList = ardTankWallMapper.getArdTankWallProcessByLockId(lockId);//鏌ヨ閿佹寕鎺ョ殑鍏ㄩ儴闇�瑕佸姩浣滅殑鐢靛瓙鍥存爮 @@ -178,18 +188,18 @@ pts.add(new Point2D.Double(Double.parseDouble(wallpoiArro[j]), Double.parseDouble(wallpoiArro[j+1]))); } if(GeoTools.IsPtInPoly(point, pts)){//鍦ㄤ换鎰忕數瀛愬洿鏍忓唴锛屼笉鎶ヨ - return "褰撳墠杞﹁締姝e鍦�" + ardTankWall.getWallName() + "涓�"; + return AjaxResult.error("褰撳墠杞﹁締姝e鍦�" + ardTankWall.getWallName() + "涓�"); } } - return "褰撳墠杞﹁締姝e鍦ㄧ數瀛愬洿鏍忓"; + return AjaxResult.error("褰撳墠杞﹁締姝e鍦ㄧ數瀛愬洿鏍忓"); }else{ try{ 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("02", 16)//璁剧疆閿佽姱鐘舵�佸姛鑳界爜02 - + Integer.parseInt(process, 16));//鎿嶄綔 + + Integer.parseInt(lockNumTail, 16)//閿佺紪鍙蜂綆8浣� + + Integer.parseInt("02", 16)//璁剧疆閿佽姱鐘舵�佸姛鑳界爜02 + + Integer.parseInt(process, 16));//鎿嶄綔 if(checkNum.length() == 1){ checkNum = "0" + checkNum; } @@ -199,12 +209,10 @@ String paramsStr = lockNum + "02" + process + checkNum; paramsStr = "%7B%22type%22%3A%22ff%22%2C%22dataCnt%22%3A%22" + paramsStr + "%22%7D"; - - Map<String,Object> result = sYClient.sendCmd(syURL, ardSyUser.getUserId(), carId, 199, "DataDownTransfer", paramsStr, sessionId); - - + PositionContainer.getCarLockProcessThreadMap().get(carId).get(lockNum).put("lockProcess",new Thread());//鍔犲叆瀹瑰櫒 + Map<String,Object> result = sendCmd(syURL, ardSyUser.getUserId(), carId, 199, "DataDownTransfer", paramsStr, sessionId); + PositionContainer.getCarLockProcessThreadMap().get(carId).get(lockNum).remove("lockProcess");//绉婚櫎瀹瑰櫒 if(((String)result.get("rspCode")).equals("0")){ - //鍏ュ簱鎿嶄綔 ArdTankLockProcessLog ardTankLockProcessLog = new ArdTankLockProcessLog(); ardTankLockProcessLog.setId(IdUtils.simpleUUID()); ardTankLockProcessLog.setLockId(lockId); @@ -223,14 +231,61 @@ ardTankLockProcessLog.setLatitude(lat); ardTankLockProcessLog.setProcessTime(this.sdf.format(new Date())); ardTankLockProcessLogMapper.insertArdTankLockProcessLog(ardTankLockProcessLog); - return "鍙戦�佹垚鍔�"; + return AjaxResult.success("鍙戦�佹垚鍔�"); + }else if(((String)result.get("rspCode")).equals("-6")){ + return AjaxResult.error("鎵句笉鍒拌溅杈�"); + }else if(((String)result.get("rspCode")).equals("-5")){ + return AjaxResult.error("鎵句笉鍒扮敤鎴�"); + }else if(((String)result.get("rspCode")).equals("-4")){ + return AjaxResult.error("鎵句笉鍒版寚浠�"); + }else if(((String)result.get("rspCode")).equals("-3")){ + return AjaxResult.error("鎸囦护鍙戦�佽秴鏃�"); + }else if(((String)result.get("rspCode")).equals("-2")){ + return AjaxResult.error("绂荤嚎寰呭彂"); + }else if(((String)result.get("rspCode")).equals("-1")){ + return AjaxResult.error("杞﹁締绂荤嚎"); + }else if(((String)result.get("rspCode")).equals("1")){ + return AjaxResult.error("鍙戦�佸け璐�"); + }else if(((String)result.get("rspCode")).equals("2")){ + return AjaxResult.error("娑堟伅鏈夎"); + }else if(((String)result.get("rspCode")).equals("3")){ + return AjaxResult.error("涓嶆敮鎸�"); }else{ - return "鍙戦�佸け璐�"; + return AjaxResult.error("鍏朵粬鍘熷洜鍙戦�佸け璐�"); } }catch(Exception e){ e.printStackTrace(); - return "鍙戦�佸け璐�"; + PositionContainer.getCarLockProcessThreadMap().get(carId).get(lockNum).remove("lockProcess");//绉婚櫎瀹瑰櫒 + return AjaxResult.error("鍙戦�佸け璐�" + e.toString()); } } } + + 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>) JSON.parse(message); + return map; + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return new HashMap(); + } + } } -- Gitblit v1.9.3