From 729a5a0592cac7750e8b476c5fcb25bfc3ff8d25 Mon Sep 17 00:00:00 2001 From: liujie <1793218484@qq.com> Date: 星期日, 27 七月 2025 09:06:31 +0800 Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/QianYunTong --- UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/ServerCarModelServiceImpl.java | 230 +++++++++++++++++++++++++++++++++------------------------ 1 files changed, 133 insertions(+), 97 deletions(-) diff --git a/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/ServerCarModelServiceImpl.java b/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/ServerCarModelServiceImpl.java index 8b50879..c02d01d 100644 --- a/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/ServerCarModelServiceImpl.java +++ b/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/ServerCarModelServiceImpl.java @@ -2,18 +2,13 @@ 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; @@ -23,39 +18,37 @@ import javax.annotation.Resource; import java.math.BigDecimal; -import java.text.SimpleDateFormat; import java.util.*; @Service public class ServerCarModelServiceImpl extends ServiceImpl<ServerCarModelMapper, ServerCarModel> implements IServerCarModelService { - + @Resource private ServerCarModelMapper serverCarModelMapper; - + + @Resource + private ISystemPriceCityService systemPriceCityService; + @Resource private SystemPriceMapper systemPriceMapper; - + @Autowired private GDMapElectricFenceUtil gdMapElectricFenceUtil; - + @Autowired private GDMapGeocodingUtil gdMapGeocodingUtil; - + @Autowired private ICompanyCityService companyCityService; - + @Autowired private IOpenCityService openCityService; - + @Autowired private IOpenCityBusinessService openCityBusinessService; - - - - - - + + /** * 根据起点和终点获取车型 * @param startLonLat @@ -75,27 +68,27 @@ if(type == 1 && query.getIsSpe() == 2){ return ResultUtil.success(new ArrayList<>()); } - + // TODO: 2023/11/4 无法修改 Map<String, String> distance = gdMapElectricFenceUtil.getDistance(startLonLat, endLonLat, 1); - if(null == distance){ + 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.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 */ @@ -103,10 +96,11 @@ public List<Map<String, Object>> queryServerCarModels(Integer type) { return serverCarModelMapper.queryServerCarModel(type); } - - + + /** * 计算价格 + * * @param companyId * @param distance * @param duration @@ -115,18 +109,25 @@ * @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())); - if(null == query1){//排除没有设置价格的车型 + for (Map<String, Object> map : list) { + 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){//专车 - + if (type == 1) {//专车 double d = distance / 1000;//实际公里 double t = duration / 60;//实际时间 JSONObject jsonObject = JSON.parseObject(query1.get("content").toString());//等待费 @@ -146,25 +147,25 @@ serverCarModelWarpper.setFareTypeNote3(query1.get("fareTypeNote3").toString()); serverCarModelWarpper.setContentPutOne(contentPutOne); serverCarModelWarpper.setContentNotOne(contentNotOne); - + serverCarModelWarpper.setContentPutTwo(contentPutTwo); serverCarModelWarpper.setContentNotTwo(contentNotTwo); - + serverCarModelWarpper.setContentPutThree(contentPutThree); serverCarModelWarpper.setContentNotThree(contentNotThree); - - + + 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())); @@ -180,15 +181,22 @@ } return data; } - - - - - public ServerCarModelWarpper getTextPrice(Integer companyId, double distance, long duration, long wait, Integer type) throws Exception { - Map<String, Object> query1 = systemPriceMapper.query(companyId, type, null); - if(null == query1){//排除没有设置价格的车型 + + + 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());//等待费 @@ -240,24 +248,36 @@ } Double amount = 0D; - if(System.currentTimeMillis() > start_date && System.currentTimeMillis() <= end_date){ + if (System.currentTimeMillis() > start_date && System.currentTimeMillis() <= end_date) { amount = num7; - if(d > num8){ - BigDecimal 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); + BigDecimal multiply = BigDecimal.ZERO; + BigDecimal yt = BigDecimal.ZERO; + if (d > num8) { + multiply = new BigDecimal(d).subtract(new BigDecimal(num8)).multiply(new BigDecimal(num9)); + if (d > num4) { + 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(); } - }else{ + map.put("qibujia", num7); + map.put("lichengfei", multiply.doubleValue()); + map.put("yuantufei", yt.doubleValue()); + map.put("zongfeiyong", amount); + } else { amount = num1; - if(d > num2){ - BigDecimal 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); + BigDecimal multiply = BigDecimal.ZERO; + BigDecimal yt = BigDecimal.ZERO; + if (d > num2) { + multiply = new BigDecimal(d).subtract(new BigDecimal(num2)).multiply(new BigDecimal(num3)); + if (d > num4) { + 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"; @@ -268,7 +288,7 @@ 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()); @@ -278,15 +298,13 @@ serverCarModelWarpper.setContentNotThree(new JSONObject()); serverCarModelWarpper.setContentExclusive(new JSONObject()); serverCarModelWarpper.setContentPrice(new JSONObject()); - + return serverCarModelWarpper; } - - - - - 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;//实际公里 @@ -296,30 +314,36 @@ 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(rule.getString("num14").split(" - ")[0].split(":")[0])); s.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num14").split(" - ")[0].split(":")[1])); - + Calendar e = Calendar.getInstance(); e.setTime(date); e.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num14").split(" - ")[1].split(":")[0])); e.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num14").split(" - ")[1].split(":")[1])); - - if(date.getTime() > s.getTimeInMillis() && date.getTime() < e.getTimeInMillis()){ - if(d > rule.getDouble("num6")){ + + if (date.getTime() > s.getTimeInMillis() && date.getTime() < e.getTimeInMillis()) { + if (d > rule.getDouble("num6")) { yt1 = rule.getDouble("num18") * (d - rule.getDouble("num6")); } - if(d > rule.getDouble("num9")){ + if (d > rule.getDouble("num9")) { yt2 = rule.getDouble("num19") * (d - rule.getDouble("num9")); } - if(d > rule.getDouble("num12")){ + 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); @@ -330,42 +354,54 @@ e1.setTime(date); e1.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num21").split(" - ")[1].split(":")[0])); e1.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num21").split(" - ")[1].split(":")[1])); - + Calendar s2 = Calendar.getInstance(); s2.setTime(date); s2.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num22").split(" - ")[0].split(":")[0])); s2.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num22").split(" - ")[0].split(":")[1])); - + Calendar e2 = Calendar.getInstance(); e2.setTime(date); e2.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num22").split(" - ")[1].split(":")[0])); e2.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num22").split(" - ")[1].split(":")[1])); //高峰时段处理逻辑 - if((date.getTime() > s1.getTimeInMillis() && date.getTime() < e1.getTimeInMillis()) || (date.getTime() > s2.getTimeInMillis() && date.getTime() < e2.getTimeInMillis())){ - if(d > rule.getDouble("num6")){ + if ((date.getTime() > s1.getTimeInMillis() && date.getTime() < e1.getTimeInMillis()) || (date.getTime() > s2.getTimeInMillis() && date.getTime() < e2.getTimeInMillis())) { + if (d > rule.getDouble("num6")) { yt1 = rule.getDouble("num26") * (d - rule.getDouble("num6")); } - if(d > rule.getDouble("num9")){ + if (d > rule.getDouble("num9")) { yt2 = rule.getDouble("num27") * (d - rule.getDouble("num9")); } - if(d > rule.getDouble("num12")){ + 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("num6")) { yt1 = rule.getDouble("num8") * (d - rule.getDouble("num6")); } - if(d > rule.getDouble("num9")){ + if (d > rule.getDouble("num9")) { yt2 = rule.getDouble("num11") * (d - rule.getDouble("num9")); } - if(d > rule.getDouble("num12")){ + 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; } } -- Gitblit v1.7.1