aijinhui
2023-11-07 a8fa8c5473d8bd4dc509d9f4b0bb370f443d15ad
ard-work/src/main/java/com/ruoyi/sy/gps31/PushClientImplPosition.java
@@ -91,6 +91,7 @@
                String deptNum = (String) result.get("deptId").toString();//获取部门ID
                String deptName = (String) result.get("deptName");//获取部门名称
                String carModel = (String) result.get("carModel");//获取车辆模型
                String drct = (String) gpsMap.get("drct");//获取车辆模型
                //定义2维空间
                Point2D.Double point = new Point2D.Double(Double.parseDouble(lng), Double.parseDouble(lat));
                List<Point2D.Double> pts = new ArrayList<Point2D.Double>();
@@ -124,134 +125,168 @@
                            ardAccessFence1.setNowWallName(ardOilWall.getName());
                            ardAccessFence1.setCarModel(carModel);
                            ardAccessFence1.setIsWarning(0);
                            ardAccessFence1.setDrct(drct);
                            ((ArdAccessFenceServiceImpl)SpringUtils.getBean("ArdAccessFenceServiceImpl")).access(ardAccessFence1);
                            break;
                        }
                    }
                }else {
                    //如果车辆有数据判断是否有进入围栏ID,如果没有更新或赋值经纬度,判断是否进入围栏
                    if(ardAccessFence.getIntoShipmentId()==null){
                    //判断是否为手动添加车辆
                    if(ardAccessFence.getIsAlarm()==0){
                        ardAccessFence.setLng(lng);
                        ardAccessFence.setLat(lat);
                        for (int i = 0; i < ardOilWalls.size(); i++) {
                            pts.clear();
                            ArdOilWall ardOilWall = ardOilWalls.get(i);
                            String[] coord = ardOilWall.getCoord().split(",");
                            for (int j = 0; j < coord.length; j = j + 3) {
                                pts.add(new Point2D.Double(Double.parseDouble(coord[j]), Double.parseDouble(coord[j+1])));
                            }
                            if(GeoTools.IsPtInPoly(point, pts)){
                                //进入装油点入库
                                ardAccessFence.setIntoShipmentId(ardOilWall.getId());
                                ardAccessFence.setIntoShipmentTime(time);
                                ardAccessFence.setNowWallName(ardOilWall.getName());
                                ardAccessFence.setLastTime(time);
                                break;
                            }
                        }
                        ((ArdAccessFenceServiceImpl)SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
                    }else if(ardAccessFence.getIsAlarm() == 1){
                        ardAccessFence.setNowWallName(null);
                        //如果在路上判断坐标是否与上次一样
                        if(ardAccessFence.getLng().equals(lng) && ardAccessFence.getLat().equals(lat)){
                            //如果坐标一样时间相减
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            Date nowTime = sdf.parse(time);
                            Date lastTime = sdf.parse(ardAccessFence.getLastTime());
                            Long diff = (nowTime.getTime() - lastTime.getTime())/1000;
                            ArdAccessNum list = ((ArdAccessNumServiceImpl) SpringUtils.getBean("ArdAccessNumServiceImpl")).queryNum();
                            if(list==null){
                                int alarm = list.getAlarm();
                                if(diff>=alarm){
                                    ardAccessFence.setIsWarning(1);
                                    ardAccessFence.setAlarmLat(lat);
                                    ardAccessFence.setAlarmLng(lng);
                                    ((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
                                }
                            }
                        }else {
                            //如果不一样更新坐标
                            ardAccessFence.setLat(lat);
                            ardAccessFence.setLng(lng);
                            ardAccessFence.setLastTime(time);
                            ((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
                        }
                    }else {
                        //如果有进入围栏ID,判断是否开出装油点
                        String out = ardAccessFence.getOutShipmentId();
                        if(out == null){
                            //车辆未开出装油点
                            String into = ardAccessFence.getIntoShipmentId();
                            ArdOilWall ardOilWall = SpringUtils.getBean(ArdOilWallService.class).one(into);
                            pts.clear();
                            String[] coord = ardOilWall.getCoord().split(",");
                            for (int j = 0; j < coord.length; j = j + 3) {
                                pts.add(new Point2D.Double(Double.parseDouble(coord[j]), Double.parseDouble(coord[j + 1])));
                            }
                            if (!GeoTools.IsPtInPoly(point, pts)) {
                                //车辆开出装油点
                                ardAccessFence.setOutShipmentId(into);
                                ardAccessFence.setOutShipmentTime(time);
                                ardAccessFence.setNowWallName(ardOilWall.getName());
                                ardAccessFence.setLastTime(time);
                            }
                        //如果车辆有数据判断是否有进入围栏ID,如果没有更新或赋值经纬度,判断是否进入围栏
                        if(ardAccessFence.getIntoShipmentId()==null){
                            ardAccessFence.setLng(lng);
                            ardAccessFence.setLat(lat);
                            ((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
                            for (int i = 0; i < ardOilWalls.size(); i++) {
                                pts.clear();
                                ArdOilWall ardOilWall = ardOilWalls.get(i);
                                String[] coord = ardOilWall.getCoord().split(",");
                                for (int j = 0; j < coord.length; j = j + 3) {
                                    pts.add(new Point2D.Double(Double.parseDouble(coord[j]), Double.parseDouble(coord[j+1])));
                                }
                                if(GeoTools.IsPtInPoly(point, pts)){
                                    //进入装油点入库
                                    ardAccessFence.setIntoShipmentId(ardOilWall.getId());
                                    ardAccessFence.setIntoShipmentTime(time);
                                    ardAccessFence.setNowWallName(ardOilWall.getName());
                                    ardAccessFence.setLastTime(time);
                                    break;
                                }
                            }
                            ((ArdAccessFenceServiceImpl)SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
                        }else {
                            //车辆已经开出装油点,判断是否进入卸油点
                            String unload = ardAccessFence.getIntoUnloadId();
                            //如果unload为空,判断是否进入卸油点
                            if (unload == null) {
                                //车辆未进入卸油点
                                List<ArdOilWall> ardOilWallUpload = SpringUtils.getBean(ArdOilWallService.class).uploadAll();
                                //是否在路上
                                Boolean isRoad = true;
                                for (int i = 0; i < ardOilWallUpload.size(); i++) {
                                    pts.clear();
                                    ArdOilWall ardOilWall = ardOilWallUpload.get(i);
                                    String[] coord = ardOilWall.getCoord().split(",");
                                    for (int j = 0; j < coord.length; j = j + 3) {
                                        pts.add(new Point2D.Double(Double.parseDouble(coord[j]), Double.parseDouble(coord[j + 1])));
                                    }
                                    if (GeoTools.IsPtInPoly(point, pts)) {
                                        //进入卸油点,存入卸油点围栏ID
                                        ardAccessFence.setIntoUnloadId(ardOilWall.getId());
                                        ardAccessFence.setIntoUnloadTime(time);
                                        ardAccessFence.setLng(lng);
                                        ardAccessFence.setLat(lat);
                                        ardAccessFence.setNowWallName(ardOilWall.getName());
                                        ardAccessFence.setLastTime(time);
                                        ((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
                                        //已经进入卸油点,不在路上不需要停车报警
                                        isRoad = false;
                                        break;
                                    }
                                }
                                if(isRoad){
                                    ardAccessFence.setNowWallName(null);
                                    //如果在路上判断坐标是否与上次一样
                                    if(ardAccessFence.getLng().equals(lng) && ardAccessFence.getLat().equals(lat)){
                                        //如果坐标一样时间相减
                                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                        Date nowTime = sdf.parse(time);
                                        Date lastTime = sdf.parse(ardAccessFence.getLastTime());
                                        Long diff = (nowTime.getTime() - lastTime.getTime())/1000;
                                        ArdAccessNum list = ((ArdAccessNumServiceImpl) SpringUtils.getBean("ArdAccessNumServiceImpl")).queryNum();
                                        if(list==null){
                                            int alarm = list.getAlarm();
                                            if(diff>=alarm){
                                                ardAccessFence.setIsWarning(1);
                                                ardAccessFence.setAlarmLat(lat);
                                                ardAccessFence.setAlarmLng(lng);
                                                ((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
                                            }
                                        }
                                    }else {
                                        //如果不一样更新坐标
                                        ardAccessFence.setLat(lat);
                                        ardAccessFence.setLng(lng);
                                        ardAccessFence.setLastTime(time);
                                        ((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
                                    }
                                }
                            }else {
                                //车辆已经进入卸油点,判断是否已经开出卸油点
                                ArdOilWall ardOilWall = ((ArdOilWallServiceImpl) SpringUtils.getBean("ArdOilWallServiceImpl")).one(unload);
                            //如果有进入围栏ID,判断是否开出装油点
                            String out = ardAccessFence.getOutShipmentId();
                            if(out == null){
                                //车辆未开出装油点
                                String into = ardAccessFence.getIntoShipmentId();
                                ArdOilWall ardOilWall = SpringUtils.getBean(ArdOilWallService.class).one(into);
                                pts.clear();
                                String[] coord = ardOilWall.getCoord().split(",");
                                for (int j = 0; j < coord.length; j = j + 3) {
                                    pts.add(new Point2D.Double(Double.parseDouble(coord[j]), Double.parseDouble(coord[j + 1])));
                                }
                                if (!GeoTools.IsPtInPoly(point, pts)) {
                                    //开出了卸油点围栏,删除该条车辆数据
                                    ((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).delAccess(carId);
                                }else {
                                    //未开出卸油点,更新经纬度保存
                                    ardAccessFence.setLng(lng);
                                    ardAccessFence.setLat(lat);
                                    //车辆开出装油点
                                    ardAccessFence.setOutShipmentId(into);
                                    ardAccessFence.setOutShipmentTime(time);
                                    ardAccessFence.setNowWallName(ardOilWall.getName());
                                    ardAccessFence.setLastTime(time);
                                    ((ArdAccessFenceServiceImpl)SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
                                }
                                ardAccessFence.setLng(lng);
                                ardAccessFence.setLat(lat);
                                ((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
                            }else {
                                //车辆已经开出装油点,判断是否进入卸油点
                                String unload = ardAccessFence.getIntoUnloadId();
                                //如果unload为空,判断是否进入卸油点
                                if (unload == null) {
                                    //车辆未进入卸油点
                                    List<ArdOilWall> ardOilWallUpload = SpringUtils.getBean(ArdOilWallService.class).uploadAll();
                                    //是否在路上
                                    Boolean isRoad = true;
                                    for (int i = 0; i < ardOilWallUpload.size(); i++) {
                                        pts.clear();
                                        ArdOilWall ardOilWall = ardOilWallUpload.get(i);
                                        String[] coord = ardOilWall.getCoord().split(",");
                                        for (int j = 0; j < coord.length; j = j + 3) {
                                            pts.add(new Point2D.Double(Double.parseDouble(coord[j]), Double.parseDouble(coord[j + 1])));
                                        }
                                        if (GeoTools.IsPtInPoly(point, pts)) {
                                            //进入卸油点,存入卸油点围栏ID
                                            ardAccessFence.setIntoUnloadId(ardOilWall.getId());
                                            ardAccessFence.setIntoUnloadTime(time);
                                            ardAccessFence.setLng(lng);
                                            ardAccessFence.setLat(lat);
                                            ardAccessFence.setNowWallName(ardOilWall.getName());
                                            ardAccessFence.setLastTime(time);
                                            ((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
                                            //已经进入卸油点,不在路上不需要停车报警
                                            isRoad = false;
                                            break;
                                        }
                                    }
                                    if(isRoad){
                                        ardAccessFence.setNowWallName(null);
                                        //如果在路上判断坐标是否与上次一样
                                        if(ardAccessFence.getLng().equals(lng) && ardAccessFence.getLat().equals(lat)){
                                            //如果坐标一样时间相减
                                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                            Date nowTime = sdf.parse(time);
                                            Date lastTime = sdf.parse(ardAccessFence.getLastTime());
                                            Long diff = (nowTime.getTime() - lastTime.getTime())/1000;
                                            ArdAccessNum list = ((ArdAccessNumServiceImpl) SpringUtils.getBean("ArdAccessNumServiceImpl")).queryNum();
                                            if(list==null){
                                                int alarm = list.getAlarm();
                                                if(diff>=alarm){
                                                    ardAccessFence.setIsWarning(1);
                                                    ardAccessFence.setAlarmLat(lat);
                                                    ardAccessFence.setAlarmLng(lng);
                                                    ((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
                                                }
                                            }
                                        }else {
                                            //如果不一样更新坐标
                                            ardAccessFence.setLat(lat);
                                            ardAccessFence.setLng(lng);
                                            ardAccessFence.setLastTime(time);
                                            ((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
                                        }
                                    }
                                }else {
                                    //车辆已经进入卸油点,判断是否已经开出卸油点
                                    ArdOilWall ardOilWall = ((ArdOilWallServiceImpl) SpringUtils.getBean("ArdOilWallServiceImpl")).one(unload);
                                    pts.clear();
                                    String[] coord = ardOilWall.getCoord().split(",");
                                    for (int j = 0; j < coord.length; j = j + 3) {
                                        pts.add(new Point2D.Double(Double.parseDouble(coord[j]), Double.parseDouble(coord[j + 1])));
                                    }
                                    if (!GeoTools.IsPtInPoly(point, pts)) {
                                        //开出了卸油点围栏,删除该条车辆数据
                                        ((ArdAccessFenceServiceImpl) SpringUtils.getBean("ArdAccessFenceServiceImpl")).delAccess(carId);
                                    }else {
                                        //未开出卸油点,更新经纬度保存
                                        ardAccessFence.setLng(lng);
                                        ardAccessFence.setLat(lat);
                                        ardAccessFence.setLastTime(time);
                                        ((ArdAccessFenceServiceImpl)SpringUtils.getBean("ArdAccessFenceServiceImpl")).updAccess(ardAccessFence);
                                    }
                                }
                            }
                        }
                    }
                }
                //清淤入栏结束------------
                //清淤结束------------
                gpsMap.putAll(result);
                String ancestors = (String) gpsMap.get("ancestors");//获取父级部门