package com.stylefeng.guns.modular.system.util; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar; import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService; import com.stylefeng.guns.modular.system.dao.ServerCarModelMapper; import com.stylefeng.guns.modular.system.dao.SystemPriceMapper; import com.stylefeng.guns.modular.system.model.*; import com.stylefeng.guns.modular.system.service.ICarService; import com.stylefeng.guns.modular.system.service.IDriverService; import com.stylefeng.guns.modular.system.service.IOrderPositionService; import com.stylefeng.guns.modular.system.service.ITransactionDetailsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.*; /** * 交通部接口 */ @Component public class PushMinistryOfTransportUtil { @Autowired private ICarService carService; @Autowired private HttpClientUtil httpClientUtil; @Autowired private IOrderPrivateCarService orderPrivateCarService; @Resource private SystemPriceMapper systemPriceMapper; @Autowired private IDriverService driverService; @Autowired private IOrderPositionService orderPositionService; @Autowired private GDMapElectricFenceUtil gdMapElectricFenceUtil; @Resource private RedisTemplate redisTemplate; @Resource private ServerCarModelMapper serverCarModelMapper; @Autowired private ITransactionDetailsService transactionDetailsService; @Autowired private GeodesyUtil geodesyUtil; private String path = "http://120.77.11.218:8868/"; /** * 网约车车辆里程信息 * @param id */ public void baseInfoVehicleTotalMile(Integer id){ Car car = carService.selectById(id); List list = orderPrivateCarService.selectList(new EntityWrapper().eq("carId", id)); int mileage = 0; for(OrderPrivateCar orderPrivateCar : list){ mileage += (orderPrivateCar.getMileage() == null ? 0 : orderPrivateCar.getMileage()); } JSONObject jsonObject = new JSONObject(); jsonObject.put("Address", 450204);//注册地行政区划代码 jsonObject.put("VehicleNo", car.getCarLicensePlate());//车辆号牌 jsonObject.put("TotalMile", Integer.valueOf(mileage / 1000));//行驶总里程(km) jsonObject.put("Flag", 1);//操作标识(1:新增,2:更新,3:删除) jsonObject.put("UpdateTime", new Date()); Map map = new HashMap<>(); map.put("baseInfoVehicleTotalMile", jsonObject.toJSONString()); Map header = new HashMap<>(); header.put("Connection", "keep-alive"); header.put("Content-Type", "application/x-www-form-urlencoded"); header.put("Accept", "*/*"); header.put("Accept-Encoding", "gzip"); header.put("Accept-Charset", "utf-8"); String result = httpClientUtil.pushHttpRequset("POST", path + "ministryOfTransport/baseInfoVehicleTotalMile", map, header,"form"); System.err.println("--------------------------网约车车辆里程信息------------------------:" + result); } /** * 订单发起接口 * @param orderId */ public void orderCreate(Integer orderId){ OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId); Map query = systemPriceMapper.query(orderPrivateCar.getCompanyId(), 1, orderPrivateCar.getServerCarModelId()); JSONObject jsonObject = new JSONObject(); jsonObject.put("Address", 450204);//发起第行政区划代码 jsonObject.put("OrderId", orderPrivateCar.getOrderNum());//订单编号 jsonObject.put("DepartTime", orderPrivateCar.getTravelTime());//预计用车时间YYYYMMDDhhmmss jsonObject.put("OrderTime", orderPrivateCar.getInsertTime());//订单发起时间YYYYMMDDhhmmss jsonObject.put("PassengerNote", "");//乘客备注 jsonObject.put("Departure", orderPrivateCar.getStartAddress());//预计出发地点详细地址 jsonObject.put("DepLongitude", orderPrivateCar.getStartLon());//预计出发地点经度 jsonObject.put("DepLatitude", orderPrivateCar.getStartLat());//预计出发地点纬度 jsonObject.put("Destination", orderPrivateCar.getEndAddress());//预计目的地 jsonObject.put("DestLongitude", orderPrivateCar.getEndLon());//预计目的地经度 jsonObject.put("DestLatitude", orderPrivateCar.getEndLat());//预计目的地纬度 jsonObject.put("Encrypt", 1);//坐标加密标识(1:GCJ-02测绘局标准,2:WGS84 GPS标准,3:BD-09百度标准,4:CGCS2000北斗标准,0:其他) jsonObject.put("FareType", query.get("id").toString());//运价类型编码 Map map = new HashMap<>(); map.put("orderCreate", jsonObject.toJSONString()); Map header = new HashMap<>(); header.put("Connection", "keep-alive"); header.put("Content-Type", "application/x-www-form-urlencoded"); header.put("Accept", "*/*"); header.put("Accept-Encoding", "gzip"); header.put("Accept-Charset", "utf-8"); String result = httpClientUtil.pushHttpRequset("POST", path + "ministryOfTransport/orderCreate", map, header,"form"); System.err.println("---------------------------订单发起接口----------------------:" + result); } /** * 订单成功接口 * @param orderId */ public void orderMatch(Integer orderId){ OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId); Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); Car car = carService.selectById(orderPrivateCar.getCarId()); String value = (String) redisTemplate.opsForValue().get("dache:DRIVER" + orderPrivateCar.getDriverId()); JSONObject jsonObject = new JSONObject(); jsonObject.put("Address", 450204);//发起地行政区划代码 jsonObject.put("OrderId", orderPrivateCar.getOrderNum());//订单编号 jsonObject.put("Longitude", Double.valueOf(value.split(",")[0]));//车辆经度 jsonObject.put("Latitude", Double.valueOf(value.split(",")[1]));//车辆纬度 jsonObject.put("Encrypt", 1);//坐标加密标识(1:GCJ-02测绘局标准,2:WGS84 GPS标准,3:BD-09百度标准,4:CGCS2000北斗标准,0:其他) jsonObject.put("LicenseId", driver.getDriveCard());//机动车驾驶证编号 jsonObject.put("DriverPhone", driver.getPhone());//驾驶员手机号 jsonObject.put("VehicleNo", car.getCarLicensePlate());//车辆号牌 jsonObject.put("DistributeTime", new Date());//派单成功时间YYYYMMDDhhmmss Map map = new HashMap<>(); map.put("orderMatch", jsonObject.toJSONString()); Map header = new HashMap<>(); header.put("Connection", "keep-alive"); header.put("Content-Type", "application/x-www-form-urlencoded"); header.put("Accept", "*/*"); header.put("Accept-Encoding", "gzip"); header.put("Accept-Charset", "utf-8"); String result = httpClientUtil.pushHttpRequset("POST", path + "ministryOfTransport/orderMatch", map, header,"form"); System.err.println("--------------------------------订单成功接口---------------------------:" + result); } /** * 车辆经营上线接口 * @param driverId */ public void operateLogin(Integer driverId){ Driver driver = driverService.selectById(driverId); Car car = carService.selectById(driver.getCarId()); String value = (String) redisTemplate.opsForValue().get("dache:DRIVER" + driverId); if(ToolUtil.isNotEmpty(value)){ JSONObject jsonObject = new JSONObject(); jsonObject.put("LicenseId", driver.getDriveCard());//机动车驾驶证号 jsonObject.put("VehicleNo", car.getCarLicensePlate());//车辆号牌 jsonObject.put("LoginTime", new Date());//车辆经营上线时间YYYYMMDDhhmmss jsonObject.put("Longitude", Double.valueOf(value.split(",")[0]));//上线经度 jsonObject.put("Latitude", Double.valueOf(value.split(",")[1]));//上线纬度 jsonObject.put("Encrypt", 1);//坐标加密标识(1:GCJ-02测绘局标准,2:WGS84 GPS标准,3:BD-09百度标准,4:CGCS2000北斗标准,0:其他) Map map = new HashMap<>(); map.put("operateLogin", jsonObject.toJSONString()); Map header = new HashMap<>(); header.put("Connection", "keep-alive"); header.put("Content-Type", "application/x-www-form-urlencoded"); header.put("Accept", "*/*"); header.put("Accept-Encoding", "gzip"); header.put("Accept-Charset", "utf-8"); String result = httpClientUtil.pushHttpRequset("POST", path + "ministryOfTransport/operateLogin", map, header,"form"); System.err.println("--------------------------车辆经营上线接口------------------------:" + result); } } /** * 车辆经营下线接口 * @param driverId */ public void operateLogout(Integer driverId){ Driver driver = driverService.selectById(driverId); Car car = carService.selectById(driver.getCarId()); String value = (String) redisTemplate.opsForValue().get("dache:DRIVER" + driverId); if(ToolUtil.isNotEmpty(value)){ JSONObject jsonObject = new JSONObject(); jsonObject.put("LicenseId", driver.getDriveCard());//机动车驾驶证号 jsonObject.put("VehicleNo", car.getCarLicensePlate());//车辆号牌 jsonObject.put("LogoutTime", new Date());//车辆经营下线时间YYYYMMDDhhmmss jsonObject.put("Longitude", Double.valueOf(value.split(",")[0]));//下线经度 jsonObject.put("Latitude", Double.valueOf(value.split(",")[1]));//下线纬度 jsonObject.put("Encrypt", 1);//坐标加密标识(1:GCJ-02测绘局标准,2:WGS84 GPS标准,3:BD-09百度标准,4:CGCS2000北斗标准,0:其他) Map map = new HashMap<>(); map.put("operateLogout", jsonObject.toJSONString()); Map header = new HashMap<>(); header.put("Connection", "keep-alive"); header.put("Content-Type", "application/x-www-form-urlencoded"); header.put("Accept", "*/*"); header.put("Accept-Encoding", "gzip"); header.put("Accept-Charset", "utf-8"); String result = httpClientUtil.pushHttpRequset("POST", path + "ministryOfTransport/operateLogout", map, header,"form"); System.err.println("--------------------------------车辆经营下线接口------------------------:" + result); } } /** * 经营出发接口 * @param orderId */ public void operateDepart(Integer orderId){ OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId); Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); Map query = systemPriceMapper.query(orderPrivateCar.getCompanyId(), 1, orderPrivateCar.getServerCarModelId()); Car car = carService.selectById(orderPrivateCar.getCarId()); JSONObject jsonObject = new JSONObject(); jsonObject.put("OrderId", orderPrivateCar.getOrderNum());//订单号 jsonObject.put("LicenseId", driver.getDriveCard());//机动车驾驶证号 jsonObject.put("FareType", query.get("id").toString());//运价类型编码 jsonObject.put("VehicleNo", car.getCarLicensePlate());//车辆号牌 jsonObject.put("DepLongitude", Double.valueOf(orderPrivateCar.getBoardingLon()));//车辆出发经度 jsonObject.put("DepLatitude", Double.valueOf(orderPrivateCar.getBoardingLat()));//车辆出发纬度 jsonObject.put("Encrypt", 1);//坐标加密标识(1:GCJ-02测绘局标准,2:WGS84 GPS标准,3:BD-09百度标准,4:CGCS2000北斗标准,0:其他) jsonObject.put("DepTime", orderPrivateCar.getBoardingTime());//上车时间YYYYMMDDhhmmss List orderPositions = null; try { orderPositions = orderPositionService.queryPosition(orderId, 1); } catch (Exception e) { e.printStackTrace(); } int distance = 0; // if(orderPositions.size() > 0){ // OrderPosition orderPosition = orderPositions.get(0); // Map distance1 = gdMapElectricFenceUtil.getDistance(orderPosition.getLon() + "," + orderPosition.getLat(), orderPrivateCar.getBoardingLon() + "," + orderPrivateCar.getBoardingLat(), 1); // distance = Integer.valueOf(distance1.get("distance")) / 1000; // } jsonObject.put("WaitMile", distance);//空驶里程(km) jsonObject.put("WaitTime", (null != orderPrivateCar.getWait() ? orderPrivateCar.getWait() : 0) * 60);//等待时间(秒) Map map = new HashMap<>(); map.put("operateDepart", jsonObject.toJSONString()); Map header = new HashMap<>(); header.put("Connection", "keep-alive"); header.put("Content-Type", "application/x-www-form-urlencoded"); header.put("Accept", "*/*"); header.put("Accept-Encoding", "gzip"); header.put("Accept-Charset", "utf-8"); String result = httpClientUtil.pushHttpRequset("POST", path + "ministryOfTransport/operateDepart", map,header,"form"); System.err.println("--------------------------------经营出发接口-------------------------:" + result); } /** * 经营到达接口 * @param orderId */ public void operateArrive(Integer orderId){ OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId); JSONObject jsonObject = new JSONObject(); jsonObject.put("OrderId", orderPrivateCar.getOrderNum());//订单号 jsonObject.put("DestLongitude", orderPrivateCar.getGetoffLon());//车辆到达经度 jsonObject.put("DestLatitude", orderPrivateCar.getGetoffLat());//车辆到达纬度 jsonObject.put("Encrypt", 1);//坐标加密标识(1:GCJ-02测绘局标准,2:WGS84 GPS标准,3:BD-09百度标准,4:CGCS2000北斗标准,0:其他) jsonObject.put("DestTime", orderPrivateCar.getGetoffTime());//下车时间YYYYMMDDhhmmss jsonObject.put("DriveMile", Double.valueOf(orderPrivateCar.getMileage() / 1000).intValue());//载客里程(km) jsonObject.put("DriveTime", Double.valueOf((orderPrivateCar.getGetoffTime().getTime() - orderPrivateCar.getBoardingTime().getTime()) / 1000).intValue());//载客时间(秒) Map map = new HashMap<>(); map.put("operateArrive", jsonObject.toJSONString()); Map header = new HashMap<>(); header.put("Connection", "keep-alive"); header.put("Content-Type", "application/x-www-form-urlencoded"); header.put("Accept", "*/*"); header.put("Accept-Encoding", "gzip"); header.put("Accept-Charset", "utf-8"); String result = httpClientUtil.pushHttpRequset("POST", path + "ministryOfTransport/operateArrive", map, header,"form"); System.err.println("-------------------------------经营到达接口-------------------------:" + result); } /** * 经营支付接口 * @param orderId */ public void operatePay(Integer orderId){ OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId); Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); Map query = systemPriceMapper.query(orderPrivateCar.getCompanyId(), 1, orderPrivateCar.getServerCarModelId()); Car car = carService.selectById(orderPrivateCar.getCarId()); ServerCarModel serverCarModel = serverCarModelMapper.selectById(orderPrivateCar.getServerCarModelId()); TransactionDetails transactionDetails = transactionDetailsService.selectById(new EntityWrapper().eq("orderType", 1).eq("orderId", orderId)); JSONObject jsonObject = new JSONObject(); jsonObject.put("OrderId", orderPrivateCar.getOrderNum());//订单号 jsonObject.put("OnArea", 450204);//上车位置行政区划代码 jsonObject.put("DriverName", driver.getName());//机动车驾驶员 jsonObject.put("LicenseId", driver.getDriveCard());//机动车驾驶证号 jsonObject.put("FareType", query.get("id").toString());//运价类型编码(由网约车公司定义,与运价信息接口保持一街) jsonObject.put("VehicleNo", car.getCarLicensePlate());//车辆号牌 jsonObject.put("BookDepTime", orderPrivateCar.getTravelTime());//预计上车时间YYYYMMDDhhmmss jsonObject.put("WaitTime", orderPrivateCar.getWait() * 60);//等待时间(秒) jsonObject.put("DepLongitude", orderPrivateCar.getBoardingLon());//车辆出发经度 jsonObject.put("DepLatitude", orderPrivateCar.getBoardingLat());//车辆出发纬度 jsonObject.put("DepArea", orderPrivateCar.getBoardingAddress());//上车点 jsonObject.put("DepTime", orderPrivateCar.getBoardingTime());//上车时间YYYYMMDDhhmmss jsonObject.put("DestLongitude", orderPrivateCar.getGetoffLon());//车辆到达经度 jsonObject.put("DestLatitude", orderPrivateCar.getGetoffLat());//车辆到达纬度 jsonObject.put("DestArea", orderPrivateCar.getGetoffAddress());//下车地点 jsonObject.put("DestTime", orderPrivateCar.getGetoffTime());//下车时间YYYYMMDDhhmmss jsonObject.put("BookModel", serverCarModel.getName());//预定车型 jsonObject.put("Model", serverCarModel.getName());//实际使用车型 jsonObject.put("DriveMile", Double.valueOf(orderPrivateCar.getMileage() / 1000).intValue());//载客里程(km) jsonObject.put("DriveTime", Double.valueOf((orderPrivateCar.getGetoffTime().getTime() - orderPrivateCar.getBoardingTime().getTime()) / 1000).intValue());//载客时间(秒) List orderPositions = null; try { orderPositions = orderPositionService.queryPosition(orderId, 1); } catch (Exception e) { e.printStackTrace(); } int distance = 0; // if(orderPositions.size() > 0){ // OrderPosition orderPosition = orderPositions.get(0); // Map distance1 = gdMapElectricFenceUtil.getDistance(orderPosition.getLon() + "," + orderPosition.getLat(), orderPrivateCar.getBoardingLon() + "," + orderPrivateCar.getBoardingLat(), 1); // distance = Integer.valueOf(distance1.get("distance")) / 1000; // } jsonObject.put("WaitMile", distance);//空驶里程(km) jsonObject.put("FactPrice", orderPrivateCar.getPayMoney());//实收金额(元) jsonObject.put("Price", orderPrivateCar.getOrderMoney());//应收金额(元) jsonObject.put("CashPrice", orderPrivateCar.getPayType() == 3 ? orderPrivateCar.getPayMoney() : 0);//现金支付金额(元) jsonObject.put("LineName", orderPrivateCar.getPayType() != 3 ? "" : "");//电子支付机构 jsonObject.put("LinePrice", orderPrivateCar.getPayType() != 3 ? orderPrivateCar.getPayMoney() : 0);//电子支付金额(元) jsonObject.put("PosName", "");//POS机支付机构 jsonObject.put("PosPrice", 0);//POS机支付金额(元) jsonObject.put("BenfitPrice", (orderPrivateCar.getRedPacketMoney() == null ? 0 : orderPrivateCar.getRedPacketMoney()) + (orderPrivateCar.getCouponMoney() == null ? 0 : orderPrivateCar.getCouponMoney()) + (orderPrivateCar.getDurationMoney() == null ? 0 : orderPrivateCar.getDurationMoney()));//优惠金额(元) jsonObject.put("BookTip", 0);//预约服务费(元) jsonObject.put("PassengerTip", (orderPrivateCar.getParkMoney() == null ? 0 : orderPrivateCar.getParkMoney()) + (orderPrivateCar.getRoadTollMoney() == null ? 0 : orderPrivateCar.getRoadTollMoney()));//附加费(元) Map map1 = this.setMoney(orderPrivateCar); Double amount3 = map1.get("amount3");//其他时间段 Double amount2 = map1.get("amount2");//高峰时段 Double amount1 = map1.get("amount1");//夜间时段 jsonObject.put("PeakUpPrice", null != amount2 ? (amount2 - amount3) : 0);//高峰时段时间加价金额(元) jsonObject.put("NightUpPrice", null != amount1 ? (amount1 - amount3) : 0);//夜间时段里程加价金额(元) jsonObject.put("FarUpPrice", orderPrivateCar.getLongDistanceMoney() == null ? 0 : orderPrivateCar.getLongDistanceMoney());//远途加价金额(元) jsonObject.put("OtherUpPrice", (orderPrivateCar.getDurationMoney() == null ? 0 : orderPrivateCar.getDurationMoney()) + (orderPrivateCar.getWaitMoney() == null ? 0 : orderPrivateCar.getWaitMoney()));//其他加价金额(元) jsonObject.put("PayState", 1);//结算状态(0:未结算,1:已结算,2:未知) jsonObject.put("PayTime", null != transactionDetails ? transactionDetails.getInsertTime() : new Date());//乘客结算时间YYYYMMDDhhmmss jsonObject.put("OrderMatchTime", null != transactionDetails ? transactionDetails.getInsertTime() : new Date());//订单完成时间YYYYMMDDhhmmss jsonObject.put("InvoiceStatus", "0");//发票状态(0:未开票,1:已开票,2:未知) Map map = new HashMap<>(); map.put("operatePay", jsonObject.toJSONString()); Map header = new HashMap<>(); header.put("Connection", "keep-alive"); header.put("Content-Type", "application/x-www-form-urlencoded"); header.put("Accept", "*/*"); header.put("Accept-Encoding", "gzip"); header.put("Accept-Charset", "utf-8"); String result = httpClientUtil.pushHttpRequset("POST", path + "ministryOfTransport/operatePay", map, header,"form"); System.err.println("-----------------------经营支付接口-----------------------:" + result); } /** * 驾驶员定位信息 * @param orderId */ public void positionDriver(Integer orderId){ OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId); Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); Car car = carService.selectById(orderPrivateCar.getCarId()); List orderPositions = null; try { orderPositions = orderPositionService.queryPosition(orderId, 1); } catch (Exception e) { e.printStackTrace(); } Double Longitude = orderPositions != null && orderPositions.size() > 0 ? Double.valueOf(orderPositions.get(orderPositions.size() - 1).getLon()) : 0D; Double Latitude = orderPositions != null && orderPositions.size() > 0 ? Double.valueOf(orderPositions.get(orderPositions.size() - 1).getLat()) : 0D; Double Direction = orderPositions != null && orderPositions.size() > 0 ? Double.valueOf(orderPositions.get(orderPositions.size() - 1).getDirectionAngle()) : 0D; Double Elevation = orderPositions != null && orderPositions.size() > 0 ? Double.valueOf(orderPositions.get(orderPositions.size() - 1).getAltitude()) : 0D; Double Speed = 0D; if(orderPositions != null && orderPositions.size() > 1){ Map distance = geodesyUtil.getDistance(orderPositions.get(orderPositions.size() - 1).getLon() + "," + orderPositions.get(orderPositions.size() - 1).getLat(), orderPositions.get(orderPositions.size() - 1).getLon() + "," + orderPositions.get(orderPositions.size() - 1).getLat()); Speed = distance != null ? Double.valueOf(distance.get("WGS84")) / 1000 : 0D; } Integer state = 4; String orderNum = "0"; if(orderPrivateCar.getState() == 2){ state = 2; orderNum = orderPrivateCar.getOrderNum(); } if(orderPrivateCar.getState() == 3 || orderPrivateCar.getState() == 4){ state = 3; orderNum = orderPrivateCar.getOrderNum(); } if(orderPrivateCar.getState() == 5 || orderPrivateCar.getState() == 6 || orderPrivateCar.getState() == 11){ state = 1; orderNum = orderPrivateCar.getOrderNum(); } JSONObject jsonObject = new JSONObject(); jsonObject.put("LicenseId", driver.getDriveCard());//机动车驾驶证号 jsonObject.put("DriverRegionCode", 450204);//行政区划代码 jsonObject.put("VehicleNo", car.getCarLicensePlate());//车辆号牌 jsonObject.put("PositionTime", new Date());//定位时间(时间戳) jsonObject.put("Longitude", Longitude);//经度 jsonObject.put("Latitude", Latitude);//纬度 jsonObject.put("Encrypt", 1);//坐标加密标识(1:GCJ-02测绘局标准,2:WGS84 GPS标准,3:BD-09百度标准,4:CGCS2000北斗标准,0:其他) jsonObject.put("Direction", Direction);//方向角 jsonObject.put("Elevation", Elevation);//海拔高度 jsonObject.put("Speed", Speed);//瞬时速度(km/h) jsonObject.put("BizStatus", state);//营运状态(1:载客,2:接单,3:空驶,4:停运) jsonObject.put("OrderId", orderNum);//订单编号 Map map = new HashMap<>(); map.put("positionDriver", jsonObject.toJSONString()); Map header = new HashMap<>(); header.put("Connection", "keep-alive"); header.put("Content-Type", "application/x-www-form-urlencoded"); header.put("Accept", "*/*"); header.put("Accept-Encoding", "gzip"); header.put("Accept-Charset", "utf-8"); String result = httpClientUtil.pushHttpRequset("POST", path + "ministryOfTransport/positionDriver", map, header,"form"); System.err.println("-----------------------------驾驶员定位信息------------------------:" + result); } /** * 车辆定位信息 * @param orderId */ public void positionVehicle(Integer orderId){ OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId); Car car = carService.selectById(orderPrivateCar.getCarId()); List orderPositions = null; try { orderPositions = orderPositionService.queryPosition(orderId, 1); } catch (Exception e) { e.printStackTrace(); } Double Longitude = orderPositions != null && orderPositions.size() > 0 ? Double.valueOf(orderPositions.get(orderPositions.size() - 1).getLon()) : 0D; Double Latitude = orderPositions != null && orderPositions.size() > 0 ? Double.valueOf(orderPositions.get(orderPositions.size() - 1).getLat()) : 0D; Double Direction = orderPositions != null && orderPositions.size() > 0 ? Double.valueOf(orderPositions.get(orderPositions.size() - 1).getDirectionAngle()) : 0D; Double Elevation = orderPositions != null && orderPositions.size() > 0 ? Double.valueOf(orderPositions.get(orderPositions.size() - 1).getAltitude()) : 0D; Double Speed = 0D; if(orderPositions != null && orderPositions.size() > 1){ Map distance = geodesyUtil.getDistance(orderPositions.get(orderPositions.size() - 1).getLon() + "," + orderPositions.get(orderPositions.size() - 1).getLat(), orderPositions.get(orderPositions.size() - 1).getLon() + "," + orderPositions.get(orderPositions.size() - 1).getLat()); Speed = distance != null ? Double.valueOf(distance.get("WGS84")) / 1000 : 0D; } Integer state = 4; String orderNum = "0"; if(orderPrivateCar.getState() == 2){ state = 2; orderNum = orderPrivateCar.getOrderNum(); } if(orderPrivateCar.getState() == 3 || orderPrivateCar.getState() == 4){ state = 3; orderNum = orderPrivateCar.getOrderNum(); } if(orderPrivateCar.getState() == 5 || orderPrivateCar.getState() == 6 || orderPrivateCar.getState() == 11){ state = 1; orderNum = orderPrivateCar.getOrderNum(); } JSONObject jsonObject = new JSONObject(); jsonObject.put("VehicleNo", car.getCarLicensePlate());//车辆号牌 jsonObject.put("VehicleRegionCode", 450204);//行政区划代码 jsonObject.put("PositionTime", new Date());//定位时间(时间戳) jsonObject.put("Longitude", Longitude);//经度 jsonObject.put("Latitude", Latitude);//纬度 jsonObject.put("Speed", Speed);//瞬时速度(km/h) jsonObject.put("Direction", Direction);//方向角 jsonObject.put("Elevation", Elevation);//海拔高度 jsonObject.put("Mileage", orderPrivateCar.getMileage() / 1000);//行驶里程(KM) jsonObject.put("Encrypt", 1);//坐标加密标识(1:GCJ-02测绘局标准,2:WGS84 GPS标准,3:BD-09百度标准,4:CGCS2000北斗标准,0:其他) jsonObject.put("WarnStatus", 0);//预警状态 jsonObject.put("VehStatus", 0);//车辆状态 jsonObject.put("BizStatus", state);//营运状态(1:载客,2:接单,3:空驶,4:停运) jsonObject.put("OrderId", orderNum);//订单编号(非营运状态下填"0") Map map = new HashMap<>(); map.put("positionVehicle", jsonObject.toJSONString()); Map header = new HashMap<>(); header.put("Connection", "keep-alive"); header.put("Content-Type", "application/x-www-form-urlencoded"); header.put("Accept", "*/*"); header.put("Accept-Encoding", "gzip"); header.put("Accept-Charset", "utf-8"); String result = httpClientUtil.pushHttpRequset("POST", path + "ministryOfTransport/positionVehicle", map, header,"form"); System.err.println("----------------------------车辆定位信息---------------------------:" + result); } /** * 计算价格 * @param orderPrivateCar * @return * @throws Exception */ private Map setMoney(OrderPrivateCar orderPrivateCar) { Map query1 = systemPriceMapper.query(orderPrivateCar.getCompanyId(), 1, orderPrivateCar.getServerCarModelId()); Map map = new HashMap<>(); //开始根据不同的方式计算金额 double amount1 = 0; double amount2 = 0; double amount3 = 0; JSONObject jsonObject = JSON.parseObject(query1.get("content").toString()); Double num1 = jsonObject.getDouble("num1");//起步价(元) Double num2 = jsonObject.getDouble("num2");//起步公里(公里) Double num3 = jsonObject.getDouble("num3");//起步时间(分钟) Double num4 = jsonObject.getDouble("num4");//里程费(元) Double num5 = jsonObject.getDouble("num5");//时长费(分钟) Double num6 = jsonObject.getDouble("num6");//等待费(分钟) Double num7 = jsonObject.getDouble("num7");//等待费(元) Double num8 = jsonObject.getDouble("num8");//远途费(公里) Double num9 = jsonObject.getDouble("num9");//远途费(公里) Double num10 = jsonObject.getDouble("num10");//远途费(元) Double num11 = jsonObject.getDouble("num11");//远途费(公里) Double num12 = jsonObject.getDouble("num12");//远途费(公里) Double num13 = jsonObject.getDouble("num13");//远途费(元) Double num14 = jsonObject.getDouble("num14");//远途费(公里) Double num15 = jsonObject.getDouble("num15");//远途费(元) String num16 = jsonObject.getString("num16");//夜间费(开始时间) Double num17 = jsonObject.getDouble("num17");//夜间费(元) Double num18 = jsonObject.getDouble("num18");//夜间费(元) Double num19 = jsonObject.getDouble("num19");//夜间费(元) Double num20 = jsonObject.getDouble("num20");//夜间费(元) Double num21 = jsonObject.getDouble("num21");//夜间费(元) Double num22 = jsonObject.getDouble("num22");//夜间费(元) String num23 = jsonObject.getString("num23");//高峰费(开始时间) String num24 = jsonObject.getString("num24");//高峰费(开始时间) Double num25 = jsonObject.getDouble("num25");//高峰费(元) Double num26 = jsonObject.getDouble("num26");//高峰费(元) Double num27 = jsonObject.getDouble("num27");//高峰费(元) Double num28 = jsonObject.getDouble("num28");//高峰费(元) Double num29 = jsonObject.getDouble("num29");//高峰费(元) Double num30 = jsonObject.getDouble("num30");//高峰费(元) Date date = new Date(); double d = (null == orderPrivateCar.getMileage() ? 0D : orderPrivateCar.getMileage()) / 1000;//实际公里 double t = ((orderPrivateCar.getEndServiceTime().getTime() - orderPrivateCar.getStartServiceTime().getTime()) / 60000) + 1;//实际时间(不满一分钟按一分钟算) double w = ((orderPrivateCar.getStartServiceTime().getTime() - orderPrivateCar.getArriveTime().getTime()) / 60000) + 1;//等待分钟(不满一分钟按一分钟算) double d1 = (d - num2) < 0 ? 0 : d - num2;//超出起步里程的公里 double t1 = (t - num3) < 0 ? 0 : new BigDecimal(t - num3).setScale(0, BigDecimal.ROUND_UP).doubleValue();//超过起步分钟数的时间 double w1 = (w - num6) < 0 ? 0 : new BigDecimal(w - num6).setScale(0, BigDecimal.ROUND_UP).doubleValue();//超出等待时间的时间 double yt1 = 0;//远途1段 double yt2 = 0;//远途2段 double yt3 = 0;//远途3段 //夜间服务处理逻辑 Calendar s = Calendar.getInstance(); s.setTime(date); s.set(Calendar.HOUR_OF_DAY, Integer.valueOf(num16.split(" - ")[0].split(":")[0])); s.set(Calendar.MINUTE, Integer.valueOf(num16.split(" - ")[0].split(":")[1])); Calendar e = Calendar.getInstance(); e.setTime(date); e.set(Calendar.HOUR_OF_DAY, Integer.valueOf(num16.split(" - ")[1].split(":")[0])); e.set(Calendar.MINUTE, Integer.valueOf(num16.split(" - ")[1].split(":")[1])); if(date.getTime() > s.getTimeInMillis() && date.getTime() < e.getTimeInMillis()){ if(d > num8.doubleValue() && d <= num9.doubleValue()){ yt1 = num20 * (d - num8); } if(d > num9.doubleValue()){ yt1 = num20 * (num9 - num8); } if(d > num11.doubleValue() || d <= num12.doubleValue()){ yt2 = num21 * (d - num11); } if(d > num12.doubleValue()){ yt2 = num21 * (num12 - num11); } if(d > num14.doubleValue()){ yt3 = num22 * (d - num14); } amount1 = num17 + (d1 * num18) + (t1 * num19) + (w1 * num7) + yt1 + yt2 + yt3; map.put("amount1", amount1); } //高峰时段处理逻辑 Calendar s1 = Calendar.getInstance(); s1.setTime(date); s1.set(Calendar.HOUR_OF_DAY, Integer.valueOf(num23.split(" - ")[0].split(":")[0])); s1.set(Calendar.MINUTE, Integer.valueOf(num23.split(" - ")[0].split(":")[1])); Calendar e1 = Calendar.getInstance(); e1.setTime(date); e1.set(Calendar.HOUR_OF_DAY, Integer.valueOf(num23.split(" - ")[1].split(":")[0])); e1.set(Calendar.MINUTE, Integer.valueOf(num23.split(" - ")[1].split(":")[1])); Calendar s2 = Calendar.getInstance(); s2.setTime(date); s2.set(Calendar.HOUR_OF_DAY, Integer.valueOf(num24.split(" - ")[0].split(":")[0])); s2.set(Calendar.MINUTE, Integer.valueOf(num24.split(" - ")[0].split(":")[1])); Calendar e2 = Calendar.getInstance(); e2.setTime(date); e2.set(Calendar.HOUR_OF_DAY, Integer.valueOf(num24.split(" - ")[1].split(":")[0])); e2.set(Calendar.MINUTE, Integer.valueOf(num24.split(" - ")[1].split(":")[1])); if((date.getTime() > s1.getTimeInMillis() && date.getTime() < e1.getTimeInMillis()) || (date.getTime() > s2.getTimeInMillis() && date.getTime() < e2.getTimeInMillis())){ if(d > num8.doubleValue() && d <= num9.doubleValue()){ yt1 = num28 * (d - num8); } if(d > num9.doubleValue()){ yt1 = num28 * (num9 - num8); } if(d > num11.doubleValue() && d <= num12.doubleValue()){ yt2 = num29 * (d - num11); } if(d > num12.doubleValue()){ yt2 = num29 * (num12 - num11); } if(d > num14.doubleValue()){ yt3 = num30 * (d - num14); } amount2 = num25 + (d1 * num26) + (t1 * num27) + (w1 * num7) + yt1 + yt2 + yt3; map.put("amount2", amount2); } //其他时间段的计算 if(d > num8.doubleValue() && d <= num9.doubleValue()){ yt1 = num10 * (d - num8); } if(d > num9.doubleValue()){ yt1 = num10 * (num9 - num8); } if(d > num11.doubleValue() && d <= num12.doubleValue()){ yt2 = num13 * (d - num11); } if(d > num12.doubleValue()){ yt2 = num13 * (num12 - num11); } if(d > num14.doubleValue()){ yt3 = num15 * (d - num14); } amount3 = num1 + (d1 * num4) + (t1 * num5) + (w1 * num7) + yt1 + yt2 + yt3; map.put("amount3", amount3); return map; } }