| | |
| | | import com.gps31.push.netty.client.TcpClient; |
| | | import com.gps31.push.util.MapUtil; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.sy.service.impl.ArdSyCarServiceImpl; |
| | | import com.ruoyi.sy.domain.ArdAccessFence; |
| | | import com.ruoyi.sy.domain.ArdAccessNum; |
| | | import com.ruoyi.sy.domain.ArdOilWall; |
| | | import com.ruoyi.sy.domain.ArdSyCarLock; |
| | | import com.ruoyi.sy.service.ArdAccessFenceService; |
| | | import com.ruoyi.sy.service.ArdOilWallService; |
| | | import com.ruoyi.sy.service.impl.*; |
| | | import com.ruoyi.utils.gps.GeoTools; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | |
| | | import java.awt.geom.Point2D; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * <p>Description: </p> |
| | |
| | | Map<String,Object> gpsMap = pushMsg.getJsonMap(); |
| | | /*String carName = MapUtil.getStrVal(gpsMap, "carName","");//获取车牌号 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | System.out.println(sdf.format(new Date())); |
| | | log.error(String.format(" ---->收到定位数据:%s",JSON.toJSONString(gpsMap)));*/ |
| | | System.out.println(sdf.format(new Date()));*/ |
| | | // log.error(String.format(" ---->收到定位数据:%s",JSON.toJSONString(gpsMap))); |
| | | String carId = (String)gpsMap.get("carId"); |
| | | ((ArdSyCarDayServiceImpl)SpringUtils.getBean("ardSyCarDayServiceImpl")).insertArdSyCarDay(carId);//新增车辆上报时间 |
| | | Map<String,Object> result = ((ArdSyCarServiceImpl)SpringUtils.getBean("ardSyCarServiceImpl")).getArdSyCarAndDeptByCarId(carId);//查询车辆及部门 |
| | | if(result != null){ |
| | | //清淤入栏开始---------- |
| | | String lng = (String) gpsMap.get("lng").toString();//获取经度 |
| | | String lat = (String) gpsMap.get("lat").toString();//获取纬度 |
| | | String carName = (String) gpsMap.get("carName");//获取车牌号 |
| | | String time = (String) gpsMap.get("result");//定位时间 |
| | | 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>(); |
| | | //查询定位油车表中是否有该车辆 |
| | | ArdAccessFence ardAccessFence = SpringUtils.getBean(ArdAccessFenceService.class).queryAccess(carId); |
| | | //查询所有装油点围栏 |
| | | List<ArdOilWall> ardOilWalls = SpringUtils.getBean(ArdOilWallService.class).accessAll(); |
| | | //如果没有说明车辆未进入装油点,需要匹配所有装油点围栏 |
| | | if(ardAccessFence==null){ |
| | | //车辆未进入装油点 |
| | | 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 ardAccessFence1 = new ArdAccessFence(); |
| | | ardAccessFence1.setId(String.valueOf(UUID.randomUUID())); |
| | | ardAccessFence1.setCarId(carId); |
| | | ardAccessFence1.setCarName(carName); |
| | | ardAccessFence1.setDeptId(deptNum); |
| | | ardAccessFence1.setDeptName(deptName); |
| | | ardAccessFence1.setIntoShipmentId(ardOilWall.getId()); |
| | | ardAccessFence1.setIntoShipmentTime(time); |
| | | ardAccessFence1.setLng(lng); |
| | | ardAccessFence1.setLat(lat); |
| | | ardAccessFence1.setLastTime(time); |
| | | 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){ |
| | | 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 { |
| | | //如果有进入围栏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); |
| | | } |
| | | 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");//获取父级部门 |
| | | String[] ancestorsArray = ancestors.split(","); |
| | |
| | | Map<String,Map<String,Object>> deptMap = PositionContainer.getDeptPositionMap().get(deptId); |
| | | if(deptMap == null){ |
| | | deptMap = new HashMap(); |
| | | deptMap.put((String)gpsMap.get("carId"),gpsMap); |
| | | PositionContainer.getDeptPositionMap().put(deptId,deptMap); |
| | | }else{ |
| | | deptMap.put((String)gpsMap.get("carId"),gpsMap); |
| | | } |
| | | deptMap.put((String)gpsMap.get("carId"),gpsMap);//首次加入容器,再次去重 |
| | | PositionContainer.getDeptPositionMap().put(deptId,deptMap); |
| | | }else{ |
| | | }else{//其他部门 |
| | | //加入本部门容器 |
| | | String deptId = String.valueOf(gpsMap.get("deptId")); |
| | | Map<String,Map<String,Object>> deptMap = PositionContainer.getDeptPositionMap().get(deptId); |
| | | if(deptMap == null){ |
| | | deptMap = new HashMap(); |
| | | deptMap.put((String)gpsMap.get("carId"),gpsMap); |
| | | PositionContainer.getDeptPositionMap().put(deptId,deptMap); |
| | | }else{ |
| | | deptMap.put((String)gpsMap.get("carId"),gpsMap); |
| | | } |
| | | deptMap.put((String)gpsMap.get("carId"),gpsMap);//首次加入容器,再次去重 |
| | | PositionContainer.getDeptPositionMap().put(deptId,deptMap); |
| | | //加入父级部门容器 |
| | | for(int i = 1;i <= ancestorsArray.length - 1;i++){ |
| | | String deptIdp = String.valueOf(gpsMap.get(ancestorsArray[i])); |
| | | String deptIdp = ancestorsArray[i]; |
| | | Map<String,Map<String,Object>> deptMapp = PositionContainer.getDeptPositionMap().get(deptIdp); |
| | | if(deptMapp == null){ |
| | | deptMapp = new HashMap(); |
| | | deptMapp.put((String)gpsMap.get("carId"),gpsMap); |
| | | PositionContainer.getDeptPositionMap().put(deptIdp,deptMapp); |
| | | }else{ |
| | | deptMapp.put((String)gpsMap.get("carId"),gpsMap); |
| | | } |
| | | deptMapp.put((String)gpsMap.get("carId"),gpsMap);//首次加入容器,再次去重 |
| | | PositionContainer.getDeptPositionMap().put(deptIdp,deptMap); |
| | | } |
| | | } |
| | | //存入用户容器 |
| | | if(PositionContainer.getUserPositionMap().size() != 0){ |
| | | for(String userId : PositionContainer.getUserPositionMap().keySet()){ |
| | | Map<String,Map<String,Object>> carIdCarMap = PositionContainer.getUserPositionMap().get(userId); |
| | | if(carIdCarMap != null){ |
| | | if(carIdCarMap.keySet().contains(carId)){ |
| | | PositionContainer.getUserPositionMap().get(userId).put(carId,gpsMap); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |