| | |
| | | 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; |
| | |
| | | |
| | | private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | private Map<String,Timer> timerMap = new HashMap(); |
| | | |
| | | /** |
| | | * 查询罐车锁操控日志 |
| | | * |
| | |
| | | */ |
| | | @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); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | @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"); |
| | |
| | | //判断使能 |
| | | 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()); |
| | |
| | | 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("车辆正在行驶中"); |
| | | } |
| | | 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);//查询锁挂接的全部需要动作的电子围栏 |
| | |
| | | pts.add(new Point2D.Double(Double.parseDouble(wallpoiArro[j]), Double.parseDouble(wallpoiArro[j+1]))); |
| | | } |
| | | if(GeoTools.IsPtInPoly(point, pts)){//在任意电子围栏内,不报警 |
| | | return "当前车辆正处在" + ardTankWall.getWallName() + "中"; |
| | | return AjaxResult.error("当前车辆正处在" + ardTankWall.getWallName() + "中"); |
| | | } |
| | | } |
| | | return "当前车辆正处在电子围栏外"; |
| | | return AjaxResult.error("当前车辆正处在电子围栏外"); |
| | | }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; |
| | | } |
| | |
| | | |
| | | 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); |
| | |
| | | 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(); |
| | | } |
| | | } |
| | | } |