| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.stylefeng.guns.modular.system.dao.ServerCarModelMapper; |
| | | import com.stylefeng.guns.modular.system.dao.SystemPriceMapper; |
| | | import com.stylefeng.guns.modular.system.model.Company; |
| | | import com.stylefeng.guns.modular.system.model.OpenCity; |
| | | import com.stylefeng.guns.modular.system.model.OpenCityBusiness; |
| | | import com.stylefeng.guns.modular.system.model.ServerCarModel; |
| | | import com.stylefeng.guns.modular.system.service.ICompanyCityService; |
| | | import com.stylefeng.guns.modular.system.service.IOpenCityBusinessService; |
| | | import com.stylefeng.guns.modular.system.service.IOpenCityService; |
| | | import com.stylefeng.guns.modular.system.service.IServerCarModelService; |
| | | import com.stylefeng.guns.modular.system.model.SystemPriceCity; |
| | | import com.stylefeng.guns.modular.system.service.*; |
| | | import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil; |
| | | import com.stylefeng.guns.modular.system.util.GDMapGeocodingUtil; |
| | | import com.stylefeng.guns.modular.system.util.ResultUtil; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | |
| | |
| | | |
| | | @Resource |
| | | private ServerCarModelMapper serverCarModelMapper; |
| | | |
| | | @Resource |
| | | private ISystemPriceCityService systemPriceCityService; |
| | | |
| | | @Resource |
| | | private SystemPriceMapper systemPriceMapper; |
| | |
| | | |
| | | @Autowired |
| | | private IOpenCityBusinessService openCityBusinessService; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | double distance1_ = Double.valueOf(distance1).doubleValue(); |
| | | String duration = distance.get("duration");//时间(秒) |
| | | long duration_ = Long.valueOf(duration).longValue(); |
| | | |
| | | List<ServerCarModelWarpper> price = this.getPrice(query.getId(), distance1_, duration_, 0, 1); |
| | | List<ServerCarModelWarpper> price = this.getPrice(query.getId(), distance1_, duration_, 0, 1, geocode); |
| | | //添加出租车车型和价格 |
| | | ServerCarModelWarpper serverCarModelWarpper = this.getTextPrice(query.getId(), distance1_, duration_, 0, 2); |
| | | ServerCarModelWarpper serverCarModelWarpper = this.getTextPrice(query.getId(), distance1_, duration_, 0, 2, geocode); |
| | | price.add(serverCarModelWarpper); |
| | | return ResultUtil.success(price); |
| | | } |
| | |
| | | |
| | | /** |
| | | * 获取业务类型对应的所有服务车型 |
| | | * |
| | | * @param type |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 计算价格 |
| | | * |
| | | * @param companyId |
| | | * @param distance |
| | | * @param duration |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public List<ServerCarModelWarpper> getPrice(Integer companyId, double distance, long duration, long wait, Integer type) throws Exception { |
| | | public List<ServerCarModelWarpper> getPrice(Integer companyId, double distance, long duration, long wait, Integer type, Map<String, String> geocode) throws Exception { |
| | | String provinceCode = geocode.get("provinceCode"); |
| | | String cityCode = geocode.get("cityCode"); |
| | | String districtCode = geocode.get("districtCode"); |
| | | //获取匹配的城市价格配置 |
| | | SystemPriceCity systemPriceCity = systemPriceCityService.queryOne(provinceCode, cityCode, districtCode); |
| | | if (null == systemPriceCity) { |
| | | return new ArrayList<>(); |
| | | } |
| | | 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())); |
| | | Map<String, Object> query1 = systemPriceMapper.query(companyId, type, Integer.valueOf(map.get("id").toString()), systemPriceCity.getId()); |
| | | if(null == query1){//排除没有设置价格的车型 |
| | | continue; |
| | | } |
| | | //开始根据不同的方式计算金额 |
| | | double amount = 0; |
| | | if(type == 1){//专车 |
| | | |
| | | double d = distance / 1000;//实际公里 |
| | | double t = duration / 60;//实际时间 |
| | | JSONObject jsonObject = JSON.parseObject(query1.get("content").toString());//等待费 |
| | |
| | | serverCarModelWarpper.setContentExclusive(contentExclusive); |
| | | serverCarModelWarpper.setContentPrice(contentPrice); |
| | | |
| | | serverCarModelWarpper.setAmount(new BigDecimal(this.calculationPrice(contentExclusive,distance,duration,wait,waitMoney)).setScale(BigDecimal.ROUND_HALF_EVEN, 2).doubleValue()); |
| | | serverCarModelWarpper.setBuyNowAmount(new BigDecimal(this.calculationPrice(contentPrice,distance,duration,wait,waitMoney)).setScale(BigDecimal.ROUND_HALF_EVEN, 2).doubleValue()); |
| | | serverCarModelWarpper.setPutTogetherOneAmount(new BigDecimal(this.calculationPrice(contentPutOne,distance,duration,wait,waitMoney)).setScale(BigDecimal.ROUND_HALF_EVEN, 2).doubleValue()); |
| | | serverCarModelWarpper.setNotAssembledOneAmount(new BigDecimal(this.calculationPrice(contentNotOne,distance,duration,wait,waitMoney)).setScale(BigDecimal.ROUND_HALF_EVEN, 2).doubleValue()); |
| | | serverCarModelWarpper.setPutTogetherTwoAmount(new BigDecimal(this.calculationPrice(contentPutTwo,distance,duration,wait,waitMoney)).setScale(BigDecimal.ROUND_HALF_EVEN, 2).doubleValue()); |
| | | serverCarModelWarpper.setNotAssembledTwoAmount(new BigDecimal(this.calculationPrice(contentNotTwo,distance,duration,wait,waitMoney)).setScale(BigDecimal.ROUND_HALF_EVEN, 2).doubleValue()); |
| | | serverCarModelWarpper.setPutTogetherThreeAmount(new BigDecimal(this.calculationPrice(contentPutThree,distance,duration,wait,waitMoney)).setScale(BigDecimal.ROUND_HALF_EVEN, 2).doubleValue()); |
| | | serverCarModelWarpper.setNotAssembledThreeAmount(new BigDecimal(this.calculationPrice(contentNotThree,distance,duration,wait,waitMoney)).setScale(BigDecimal.ROUND_HALF_EVEN, 2).doubleValue()); |
| | | serverCarModelWarpper.setAmount(this.calculationPrice(contentExclusive, distance, duration, wait, waitMoney)); |
| | | serverCarModelWarpper.setBuyNowAmount(this.calculationPrice(contentPrice, distance, duration, wait, waitMoney)); |
| | | serverCarModelWarpper.setPutTogetherOneAmount(this.calculationPrice(contentPutOne, distance, duration, wait, waitMoney)); |
| | | serverCarModelWarpper.setNotAssembledOneAmount(this.calculationPrice(contentNotOne, distance, duration, wait, waitMoney)); |
| | | serverCarModelWarpper.setPutTogetherTwoAmount(this.calculationPrice(contentPutTwo, distance, duration, wait, waitMoney)); |
| | | serverCarModelWarpper.setNotAssembledTwoAmount(this.calculationPrice(contentNotTwo, distance, duration, wait, waitMoney)); |
| | | serverCarModelWarpper.setPutTogetherThreeAmount(this.calculationPrice(contentPutThree, distance, duration, wait, waitMoney)); |
| | | serverCarModelWarpper.setNotAssembledThreeAmount(this.calculationPrice(contentNotThree, distance, duration, wait, waitMoney)); |
| | | serverCarModelWarpper.setMileage(d); |
| | | serverCarModelWarpper.setDuration(t); |
| | | serverCarModelWarpper.setIsOpen(Integer.parseInt(query1.get("isOpen").toString())); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | public ServerCarModelWarpper getTextPrice(Integer companyId, double distance, long duration, long wait, Integer type) throws Exception { |
| | | Map<String, Object> query1 = systemPriceMapper.query(companyId, type, null); |
| | | public ServerCarModelWarpper getTextPrice(Integer companyId, double distance, long duration, long wait, Integer type, Map<String, String> geocode) throws Exception { |
| | | String provinceCode = geocode.get("provinceCode"); |
| | | String cityCode = geocode.get("cityCode"); |
| | | String districtCode = geocode.get("districtCode"); |
| | | //获取匹配的城市价格配置 |
| | | SystemPriceCity systemPriceCity = systemPriceCityService.queryOne(provinceCode, cityCode, districtCode); |
| | | if (null == systemPriceCity) { |
| | | return null; |
| | | } |
| | | Map<String, Object> query1 = systemPriceMapper.query(companyId, type, null, systemPriceCity.getId()); |
| | | if(null == query1){//排除没有设置价格的车型 |
| | | return null; |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | double d = distance / 1000;//实际公里 |
| | | double t = duration / 60;//实际时间 |
| | | JSONObject jsonObject = JSON.parseObject(query1.get("content").toString());//等待费 |
| | |
| | | Double amount = 0D; |
| | | if(System.currentTimeMillis() > start_date && System.currentTimeMillis() <= end_date){ |
| | | amount = num7; |
| | | BigDecimal multiply = BigDecimal.ZERO; |
| | | BigDecimal yt = BigDecimal.ZERO; |
| | | if(d > num8){ |
| | | BigDecimal multiply = new BigDecimal(d).subtract(new BigDecimal(num8)).multiply(new BigDecimal(num9)); |
| | | multiply = new BigDecimal(d).subtract(new BigDecimal(num8)).multiply(new BigDecimal(num9)); |
| | | if(d > num4){ |
| | | multiply = new BigDecimal(d).subtract(new BigDecimal(num4)).multiply(new BigDecimal(num5)).add(multiply); |
| | | yt = new BigDecimal(d).subtract(new BigDecimal(num4)).multiply(new BigDecimal(num5)); |
| | | } |
| | | amount = new BigDecimal(num7).add(multiply).setScale(2, BigDecimal.ROUND_DOWN).doubleValue(); |
| | | amount = new BigDecimal(num7).add(multiply).add(yt).setScale(2, BigDecimal.ROUND_DOWN).doubleValue(); |
| | | } |
| | | map.put("qibujia", num7); |
| | | map.put("lichengfei", multiply.doubleValue()); |
| | | map.put("yuantufei", yt.doubleValue()); |
| | | map.put("zongfeiyong", amount); |
| | | }else{ |
| | | amount = num1; |
| | | BigDecimal multiply = BigDecimal.ZERO; |
| | | BigDecimal yt = BigDecimal.ZERO; |
| | | if(d > num2){ |
| | | BigDecimal multiply = new BigDecimal(d).subtract(new BigDecimal(num2)).multiply(new BigDecimal(num3)); |
| | | multiply = new BigDecimal(d).subtract(new BigDecimal(num2)).multiply(new BigDecimal(num3)); |
| | | if(d > num4){ |
| | | multiply = new BigDecimal(d).subtract(new BigDecimal(num4)).multiply(new BigDecimal(num5)).add(multiply); |
| | | yt = new BigDecimal(d).subtract(new BigDecimal(num4)).multiply(new BigDecimal(num5)); |
| | | } |
| | | amount = new BigDecimal(num1).add(multiply).setScale(2, BigDecimal.ROUND_DOWN).doubleValue(); |
| | | amount = new BigDecimal(num1).add(multiply).add(yt).setScale(2, BigDecimal.ROUND_DOWN).doubleValue(); |
| | | } |
| | | map.put("qibujia", num1); |
| | | map.put("lichengfei", multiply.doubleValue()); |
| | | map.put("yuantufei", yt.doubleValue()); |
| | | map.put("zongfeiyong", amount); |
| | | } |
| | | List<Map<String, Object>> list = serverCarModelMapper.queryServerCarModel(4); |
| | | String isCheck = "0"; |
| | |
| | | ServerCarModelWarpper serverCarModelWarpper = new ServerCarModelWarpper(); |
| | | serverCarModelWarpper.setId(0); |
| | | serverCarModelWarpper.setName("出租车"); |
| | | serverCarModelWarpper.setAmount(amount); |
| | | serverCarModelWarpper.setAmount(map); |
| | | serverCarModelWarpper.setDx_check(Integer.valueOf(isCheck)); |
| | | serverCarModelWarpper.setContentPutOne(new JSONObject()); |
| | | serverCarModelWarpper.setContentNotOne(new JSONObject()); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | public Double calculationPrice(JSONObject rule, double distance, long duration, long wait,Double waitMoney) throws Exception { |
| | | double amount = 0; |
| | | public Map<String, Object> calculationPrice(JSONObject rule, double distance, long duration, long wait, Double waitMoney) throws Exception { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | //等待费 |
| | | Date date = new Date(); |
| | | double d = distance / 1000;//实际公里 |
| | |
| | | if(d > rule.getDouble("num12")){ |
| | | yt3 = rule.getDouble("num20") * (d - rule.getDouble("num12")); |
| | | } |
| | | amount = rule.getDouble("num15") + (d1 * rule.getDouble("num16")) + (t1 * rule.getDouble("num17")) + (wait * waitMoney) + yt1 + yt2 + yt3; |
| | | double amount = rule.getDouble("num15") + (d1 * rule.getDouble("num16")) + (t1 * rule.getDouble("num17")) + (wait * waitMoney) + yt1 + yt2 + yt3; |
| | | map.put("qibujia", rule.getDouble("num15")); |
| | | map.put("lichengfei", d1 * rule.getDouble("num16")); |
| | | map.put("shichangfei", t1 * rule.getDouble("num17")); |
| | | map.put("dengdaifei", wait * waitMoney); |
| | | map.put("yuantufei", yt1 + yt2 + yt3); |
| | | map.put("zongfeiyong", amount); |
| | | }else{ |
| | | Calendar s1 = Calendar.getInstance(); |
| | | s1.setTime(date); |
| | |
| | | if(d > rule.getDouble("num12")){ |
| | | yt3 = rule.getDouble("num28") * (d - rule.getDouble("num12")); |
| | | } |
| | | amount = rule.getDouble("num23") + (d1 * rule.getDouble("num24")) + (t1 * rule.getDouble("num25")) + (wait * waitMoney) + yt1 + yt2 + yt3; |
| | | double amount = rule.getDouble("num23") + (d1 * rule.getDouble("num24")) + (t1 * rule.getDouble("num25")) + (wait * waitMoney) + yt1 + yt2 + yt3; |
| | | map.put("qibujia", rule.getDouble("num23")); |
| | | map.put("lichengfei", d1 * rule.getDouble("num24")); |
| | | map.put("shichangfei", t1 * rule.getDouble("num25")); |
| | | map.put("dengdaifei", wait * waitMoney); |
| | | map.put("yuantufei", yt1 + yt2 + yt3); |
| | | map.put("zongfeiyong", amount); |
| | | }else{ |
| | | //其他时间段的计算 |
| | | if(d > rule.getDouble("num6")){ |
| | |
| | | if(d > rule.getDouble("num12")){ |
| | | yt3 = rule.getDouble("num13") * (d - rule.getDouble("num12")); |
| | | } |
| | | amount = rule.getDouble("num1") + (d1 * rule.getDouble("num4")) + (t1 * rule.getDouble("num5")) + (wait * waitMoney) + yt1 + yt2 + yt3; |
| | | double amount = rule.getDouble("num1") + (d1 * rule.getDouble("num4")) + (t1 * rule.getDouble("num5")) + (wait * waitMoney) + yt1 + yt2 + yt3; |
| | | map.put("qibujia", rule.getDouble("num1")); |
| | | map.put("lichengfei", d1 * rule.getDouble("num4")); |
| | | map.put("shichangfei", t1 * rule.getDouble("num5")); |
| | | map.put("dengdaifei", wait * waitMoney); |
| | | map.put("yuantufei", yt1 + yt2 + yt3); |
| | | map.put("zongfeiyong", amount); |
| | | } |
| | | } |
| | | return amount; |
| | | return map; |
| | | } |
| | | } |