| | |
| | | package com.stylefeng.guns.modular.system.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.stylefeng.guns.modular.system.dao.ServerCarModelMapper; |
| | |
| | | import com.stylefeng.guns.modular.system.util.ResultUtil; |
| | | import com.stylefeng.guns.modular.system.warpper.BaseWarpper; |
| | | import com.stylefeng.guns.modular.system.warpper.ServerCarModelWarpper; |
| | | import lombok.Data; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | * @throws Exception |
| | | */ |
| | | public List<ServerCarModelWarpper> getPrice(Integer companyId, double distance, long duration, long wait, Integer type, Map<String, String> geocode) throws Exception { |
| | | System.err.println("预估里程:" + distance); |
| | | System.err.println("预估时间:" + duration); |
| | | String provinceCode = geocode.get("provinceCode"); |
| | | String cityCode = geocode.get("cityCode"); |
| | | String districtCode = geocode.get("districtCode"); |
| | | //获取匹配的城市价格配置 |
| | | SystemPriceCity systemPriceCity = systemPriceCityService.queryOne(provinceCode, cityCode, districtCode); |
| | | System.err.println("获取匹配的城市价格配置:" + systemPriceCity); |
| | | if (null == systemPriceCity) { |
| | | return new ArrayList<>(); |
| | | } |
| | | List<Map<String, Object>> list = serverCarModelMapper.queryServerCarModel(type); |
| | | System.err.println("获取匹配的城市价格配置111:" + list); |
| | | 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()), systemPriceCity.getId()); |
| | |
| | | JSONObject jsonObject = JSON.parseObject(query1.get("content").toString());//等待费 |
| | | Double num1 = jsonObject.getDouble("num1"); |
| | | Double num2 = jsonObject.getDouble("num2"); |
| | | Double num3 = jsonObject.getDouble("num3"); |
| | | JSONArray mileageList = jsonObject.getJSONArray("mileageList"); |
| | | Double num4 = jsonObject.getDouble("num4"); |
| | | Double num5 = jsonObject.getDouble("num5"); |
| | | String num6 = jsonObject.getString("num6"); |
| | |
| | | BigDecimal multiply = BigDecimal.ZERO; |
| | | BigDecimal yt = BigDecimal.ZERO; |
| | | if (d > num2) { |
| | | multiply = new BigDecimal(d).subtract(new BigDecimal(num2)).multiply(new BigDecimal(num3)); |
| | | List<MileageObject> list = new ArrayList<>(); |
| | | for (int i = 0; i < mileageList.size(); i++) { |
| | | MileageObject mileageObject = mileageList.getObject(i, MileageObject.class); |
| | | list.add(mileageObject); |
| | | } |
| | | //根据配置的里程倒序排序 |
| | | list.sort(new Comparator<MileageObject>() { |
| | | @Override |
| | | public int compare(MileageObject o1, MileageObject o2) { |
| | | return o1.getMileage().compareTo(o2.getMileage()) * -1; |
| | | } |
| | | }); |
| | | //计算每个阶段的增加费用 |
| | | Double last = d; |
| | | for (int i = 0; i < list.size(); i++) { |
| | | Double mileage = list.get(i).getMileage(); |
| | | Double price = list.get(i).getPrice(); |
| | | if(d > mileage){ |
| | | multiply = new BigDecimal(last).subtract(new BigDecimal(mileage)).multiply(new BigDecimal(price)); |
| | | last = mileage; |
| | | } |
| | | } |
| | | if (d > num4) { |
| | | yt = new BigDecimal(d).subtract(new BigDecimal(num4)).multiply(new BigDecimal(num5)); |
| | | } |
| | |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | |
| | | @Data |
| | | public static class MileageObject{ |
| | | private Double mileage; |
| | | private Double price; |
| | | |
| | | } |
| | | } |