| | |
| | | return ResultUtil.success(price); |
| | | } |
| | | |
| | | @Override |
| | | public ResultUtil<List<ServerCarModelWarpper>> queryServerCarModel1(String startLonLat, String endLonLat) throws Exception { |
| | | //查找与起点匹配的企业(经营范围) |
| | | Map<String, String> geocode = gdMapGeocodingUtil.geocode(startLonLat.split(",")[0], startLonLat.split(",")[1]); |
| | | Company query = companyCityService.query(geocode.get("districtCode")); |
| | | if(null == query){ |
| | | return ResultUtil.error("起点暂无企业提供服务", new ArrayList<>()); |
| | | } |
| | | Map<String, String> distance = gdMapElectricFenceUtil.getDistance(startLonLat, endLonLat, 1); |
| | | if(null == distance){ |
| | | return ResultUtil.error("获取预估距离出错", new ArrayList<>()); |
| | | } |
| | | String distance1 = distance.get("distance");//距离(米) |
| | | double distance1_ = Double.valueOf(distance1).doubleValue(); |
| | | String duration = distance.get("duration");//时间(秒) |
| | | long duration_ = Long.valueOf(duration).longValue(); |
| | | |
| | | List<ServerCarModelWarpper> price = this.getPrice1(query.getId(), distance1_, duration_, 0, 7); |
| | | if(price.size() == 0){ |
| | | return ResultUtil.error("未获取到可服务的车型", new ArrayList<>()); |
| | | } |
| | | return ResultUtil.success(price); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取业务类型对应的所有服务车型 |
| | |
| | | return data; |
| | | } |
| | | |
| | | public List<ServerCarModelWarpper> getPrice1(Integer companyId, double distance, long duration, long wait, Integer type) throws Exception { |
| | | List<Map<String, Object>> list = serverCarModelMapper.queryServerCarModel(type); |
| | | List<ServerCarModelWarpper> data = new ArrayList<>(); |
| | | for(Map<String, Object> map : list){ |
| | | Map<String, Object> query1 = systemPriceMapper.query(companyId, type, Integer.valueOf(map.get("id").toString())); |
| | | if(null == query1){//排除没有设置价格的车型 |
| | | continue; |
| | | } |
| | | //开始根据不同的方式计算金额 |
| | | double amount = 0; |
| | | if(type == 7){//专车 |
| | | 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 = distance / 1000;//实际公里 |
| | | double t = duration / 60;//实际时间 |
| | | |
| | | double d1 = (d - num2) < 0 ? 0 : d - num2;//超出起步里程的公里 |
| | | double t1 = (t - num3) < 0 ? 0 : t - num3;//超过起步分钟数的时间 |
| | | 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()){ |
| | | yt1 = num20 * (num9 - num8); |
| | | } |
| | | if(d > num11.doubleValue()){ |
| | | yt2 = num21 * (num12 - num11); |
| | | } |
| | | if(d > num14.doubleValue()){ |
| | | yt3 = num22 * (d - num14); |
| | | } |
| | | amount = num17 + (d1 * num18) + (t1 * num19) + (wait * num7) + yt1 + yt2 + yt3; |
| | | ServerCarModelWarpper serverCarModelWarpper = ServerCarModelWarpper.getServerCarModelWarpper(map); |
| | | serverCarModelWarpper.setAmount(new BigDecimal(amount).setScale(BigDecimal.ROUND_HALF_EVEN, 2).doubleValue()); |
| | | serverCarModelWarpper.setMileage(d); |
| | | serverCarModelWarpper.setDuration(t); |
| | | data.add(serverCarModelWarpper); |
| | | continue; |
| | | } |
| | | |
| | | |
| | | //高峰时段处理逻辑 |
| | | 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()){ |
| | | yt1 = num28 * (num9 - num8); |
| | | } |
| | | if(d > num11.doubleValue()){ |
| | | yt2 = num29 * (num12 - num11); |
| | | } |
| | | if(d > num14.doubleValue()){ |
| | | yt3 = num30 * (d - num14); |
| | | } |
| | | amount = num25 + (d1 * num26) + (t1 * num27) + (wait * num7) + yt1 + yt2 + yt3; |
| | | ServerCarModelWarpper serverCarModelWarpper = ServerCarModelWarpper.getServerCarModelWarpper(map); |
| | | serverCarModelWarpper.setAmount(new BigDecimal(amount).setScale(BigDecimal.ROUND_HALF_EVEN, 2).doubleValue()); |
| | | serverCarModelWarpper.setMileage(d); |
| | | serverCarModelWarpper.setDuration(t); |
| | | data.add(serverCarModelWarpper); |
| | | continue; |
| | | } |
| | | |
| | | //其他时间段的计算 |
| | | if(d > num8.doubleValue()){ |
| | | yt1 = num10 * (num9 - num8); |
| | | } |
| | | if(d > num11.doubleValue()){ |
| | | yt2 = num13 * (num12 - num11); |
| | | } |
| | | if(d > num14.doubleValue()){ |
| | | yt3 = num15 * (d - num14); |
| | | } |
| | | amount = num1 + (d1 * num4) + (t1 * num5) + (wait * num7) + yt1 + yt2 + yt3; |
| | | ServerCarModelWarpper serverCarModelWarpper = ServerCarModelWarpper.getServerCarModelWarpper(map); |
| | | serverCarModelWarpper.setAmount(new BigDecimal(amount).setScale(BigDecimal.ROUND_HALF_EVEN, 2).doubleValue()); |
| | | serverCarModelWarpper.setMileage(d); |
| | | serverCarModelWarpper.setDuration(t); |
| | | data.add(serverCarModelWarpper); |
| | | continue; |
| | | } |
| | | } |
| | | return data; |
| | | } |
| | | |
| | | } |