| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.supersavedriving.driver.core.util.ToolUtil; |
| | | import com.supersavedriving.driver.modular.system.model.DriverWork; |
| | | import com.supersavedriving.driver.modular.system.model.Order; |
| | | import com.supersavedriving.driver.modular.system.service.IDriverWorkService; |
| | | import com.supersavedriving.driver.modular.system.service.IOrderPositionService; |
| | | import com.supersavedriving.driver.core.util.ToolUtil; |
| | | import com.supersavedriving.driver.modular.system.model.Order; |
| | | import com.supersavedriving.driver.modular.system.service.IOrderService; |
| | | import com.supersavedriving.driver.modular.system.util.GeodesyUtil; |
| | | import com.supersavedriving.driver.modular.system.util.RedisUtil; |
| | | import com.supersavedriving.driver.modular.system.util.ResultUtil; |
| | | import com.supersavedriving.driver.modular.system.warpper.DriverPositionWarpper; |
| | | import com.supersavedriving.driver.modular.system.warpper.OrderPositionWarpper; |
| | | import com.supersavedriving.driver.modular.system.warpper.ProcessOperationsWarpper; |
| | |
| | | @Override |
| | | public void saveOrderPosition(DriverPositionWarpper driverPositionWarpper) throws Exception { |
| | | Integer orderId = driverPositionWarpper.getOrderId(); |
| | | Integer driverId = driverPositionWarpper.getDriverId(); |
| | | Order order = orderService.selectById(orderId); |
| | | if(null == order.getDriverId() || order.getDriverId().compareTo(driverId) != 0){ |
| | | return; |
| | | } |
| | | if(order.getState() != 105 && order.getState() != 401){ |
| | | return; |
| | | } |
| | | Integer orderType = driverPositionWarpper.getOrderType(); |
| | | File file = new File(filePath + orderId + "_" + orderType + ".json"); |
| | | File file = new File(filePath + orderId + ".json"); |
| | | if(!file.exists()){ |
| | | file.getParentFile().mkdirs(); |
| | | file.createNewFile(); |
| | |
| | | OrderPositionWarpper orderPositionWarpper = orderPositionWarppers.get(orderPositionWarppers.size() - 1); |
| | | saveOrderMileage(driverPositionWarpper, orderPositionWarpper); |
| | | } |
| | | OrderPositionWarpper orderPositionWarpper = new OrderPositionWarpper(); |
| | | BeanUtils.copyProperties(driverPositionWarpper, orderPositionWarpper); |
| | | orderPositionWarpper.setInsertTime(new Date()); |
| | | orderPositionWarppers.add(orderPositionWarpper); |
| | | //大于100米才存储有效定位数据 |
| | | if(orderPositionWarppers.size() > 0){ |
| | | OrderPositionWarpper orderPositionWarpper1 = orderPositionWarppers.get(orderPositionWarppers.size() - 1); |
| | | String fromLonLat = driverPositionWarpper.getLon() + "," + driverPositionWarpper.getLat(); |
| | | String toLonLat = orderPositionWarpper1.getLon() + "," + orderPositionWarpper1.getLat(); |
| | | Map<String, Double> distance = GeodesyUtil.getDistance(fromLonLat, toLonLat); |
| | | Double wgs84 = distance.get("WGS84"); |
| | | |
| | | // long timeMillis = System.currentTimeMillis(); |
| | | // long time = orderPositionWarpper1.getInsertTime().getTime(); |
| | | // long t = timeMillis - time; |
| | | // if(wgs84 >= 200 && t <= 8){//排除位置漂移 |
| | | // return; |
| | | // } |
| | | |
| | | if(wgs84 >= 50){//5秒165米 |
| | | OrderPositionWarpper orderPositionWarpper = new OrderPositionWarpper(); |
| | | BeanUtils.copyProperties(driverPositionWarpper, orderPositionWarpper); |
| | | orderPositionWarpper.setInsertTime(new Date()); |
| | | orderPositionWarppers.add(orderPositionWarpper); |
| | | } |
| | | }else{ |
| | | OrderPositionWarpper orderPositionWarpper = new OrderPositionWarpper(); |
| | | BeanUtils.copyProperties(driverPositionWarpper, orderPositionWarpper); |
| | | orderPositionWarpper.setInsertTime(new Date()); |
| | | orderPositionWarppers.add(orderPositionWarpper); |
| | | } |
| | | |
| | | //写入相应的文件 |
| | | PrintWriter out = new PrintWriter(new FileWriter(file)); |
| | | out.write(JSON.toJSONString(driverPositionWarpper)); |
| | | out.write(JSON.toJSONString(orderPositionWarppers)); |
| | | out.flush(); |
| | | out.close(); |
| | | } |
| | |
| | | Order order = orderService.selectById(driverPositionWarpper.getOrderId()); |
| | | Double wgs84 = distance.get("WGS84"); |
| | | Integer num = map.get(order.getId().toString()); |
| | | if(50 < wgs84){ |
| | | |
| | | // long timeMillis = System.currentTimeMillis(); |
| | | // long time = orderPositionWarpper.getInsertTime().getTime(); |
| | | // long t = timeMillis - time; |
| | | // if(wgs84 >= 200 && t <= 8){//排除位置漂移 |
| | | // return; |
| | | // } |
| | | |
| | | if(50 < wgs84){//5秒165米 |
| | | order.setActualMileage(order.getActualMileage() + wgs84.intValue()); |
| | | orderService.updateById(order); |
| | | map.put(order.getId().toString(), 0); |
| | | |
| | | if(order.getState() == 401){//定位变动,自动开始服务 |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | if(50 >= wgs84 && 12 <= (null == num ? 0 : num)){//1分钟(5秒上传一次数据) |
| | | if(50 >= wgs84 && 6 <= (null == num ? 0 : num)){//30秒(5秒上传一次数据) |
| | | Integer integer = map.get(order.getId().toString()); |
| | | map.put(order.getId().toString(), integer++); |
| | | order.setState(401);//进入等待状态 |
| | | order.setStartWaitTime(new Date()); |
| | | map.put(order.getId().toString(), null == integer ? 0 : integer + 1); |
| | | //进入等待状态 |
| | | if(order.getState() == 401){ |
| | | return; |
| | | } |
| | | ProcessOperationsWarpper processOperationsWarpper = new ProcessOperationsWarpper(); |
| | | processOperationsWarpper.setOrderId(order.getId()); |
| | | processOperationsWarpper.setState(401); |
| | | try { |
| | | orderService.driverProcessOperations(order.getDriverId(), processOperationsWarpper); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | if(50 >= wgs84 && 12 > (null == num ? 0 : num)){ |
| | | if(50 >= wgs84 && 6 > (null == num ? 0 : num)){ |
| | | Integer integer = map.get(order.getId().toString()); |
| | | map.put(order.getId().toString(), integer++); |
| | | map.put(order.getId().toString(), null == integer ? 0 : integer + 1); |
| | | } |
| | | } |
| | | |
| | |
| | | @Override |
| | | public List<OrderPositionWarpper> queryPosition(Integer orderId, Integer orderType) throws Exception { |
| | | //将数据存储到文件中 |
| | | File file = new File(filePath + orderId + "_" + orderType + ".txt"); |
| | | File file = new File(filePath + orderId + ".json"); |
| | | if(!file.exists()){ |
| | | System.err.println("不存在"); |
| | | return new ArrayList<>(); |
| | | } |
| | | //读取文件(字符流) |
| | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void initMap(Long orderId) throws Exception { |
| | | map.put(orderId.toString(), 0); |
| | | } |
| | | |
| | | } |