| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | 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.ServerCarModel; |
| | | import com.stylefeng.guns.modular.system.model.UserInfo; |
| | | import com.stylefeng.guns.modular.system.service.ICompanyCityService; |
| | | import com.stylefeng.guns.modular.system.service.IServerCarModelService; |
| | | import com.stylefeng.guns.modular.system.service.IUserInfoService; |
| | | import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil; |
| | | import com.stylefeng.guns.modular.system.util.GDMapGeocodingUtil; |
| | | import com.stylefeng.guns.modular.system.util.GoogleMap.AddressComponentsVo; |
| | | import com.stylefeng.guns.modular.system.util.GoogleMap.DistancematrixVo; |
| | | import com.stylefeng.guns.modular.system.util.GoogleMap.GoogleMapUtil; |
| | | import com.stylefeng.guns.modular.system.util.GoogleMap.ReverseGeocodeVo; |
| | | import com.stylefeng.guns.modular.system.util.RedisUtil; |
| | | import com.stylefeng.guns.modular.system.util.ResultUtil; |
| | | import com.stylefeng.guns.modular.system.warpper.ServerCarModelWarpper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | @Autowired |
| | | private ICompanyCityService companyCityService; |
| | | |
| | | @Autowired |
| | | private IUserInfoService userInfoService; |
| | | |
| | | @Resource |
| | | private RedisUtil redisUtil; |
| | | |
| | | |
| | | |
| | | |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public ResultUtil<List<ServerCarModelWarpper>> queryServerCarModel(String startLonLat, String endLonLat, Integer type) throws Exception { |
| | | public ResultUtil<List<ServerCarModelWarpper>> queryServerCarModel(Integer uid, String startLonLat, String endLonLat, Integer type, Integer language) throws Exception { |
| | | UserInfo userInfo = userInfoService.selectById(uid); |
| | | if(null != userInfo && ToolUtil.isEmpty(userInfo.getPhone())){ |
| | | return ResultUtil.error(language == 1 ? "请先绑定手机号码" : language == 2 ? "Please bind your mobile phone number first." : "Veuillez d’abord vous inscrire en liant votre numéro de téléphone portable."); |
| | | } |
| | | String[] split = startLonLat.split(","); |
| | | Company company = companyCityService.query1(uid, split[0], split[1]); |
| | | if(null != userInfo && null != company){ |
| | | userInfo.setCompanyId(company.getId()); |
| | | userInfoService.updateById(userInfo); |
| | | } |
| | | |
| | | String tripId = redisUtil.getValue("trip" + uid); |
| | | //查找与起点匹配的企业(经营范围) |
| | | ReverseGeocodeVo reverseGeocode = GoogleMapUtil.getReverseGeocode(Double.valueOf(startLonLat.split(",")[1]), Double.valueOf(startLonLat.split(",")[0])); |
| | | System.err.println("经纬度:" + startLonLat); |
| | | ReverseGeocodeVo reverseGeocode = GoogleMapUtil.getReverseGeocode(Double.valueOf(startLonLat.split(",")[1]), Double.valueOf(startLonLat.split(",")[0]), tripId); |
| | | if(null == language){ |
| | | language = 2; |
| | | } |
| | | if(null == reverseGeocode){ |
| | | return ResultUtil.error("获取地址信息失败"); |
| | | return ResultUtil.error(language == 1 ? "获取地址信息失败" : language == 2 ? "Failed to obtain address" : "Impossible d’obtenir l’adresse"); |
| | | } |
| | | AddressComponentsVo[] addressComponentsVos = reverseGeocode.getAddressComponentsVos(); |
| | | String[] city = new String[addressComponentsVos.length]; |
| | |
| | | } |
| | | Company query = companyCityService.query(city); |
| | | if(null == query){ |
| | | return ResultUtil.error("起点暂无企业提供服务", new ArrayList<>()); |
| | | return ResultUtil.error(language == 1 ? "起点暂无企业提供服务" : language == 2 ? "No service yet at the starting point" : "Pas encore de service au point de départ", new ArrayList<>()); |
| | | } |
| | | Double slnt = Double.valueOf(startLonLat.split(",")[0]); |
| | | Double slat = Double.valueOf(startLonLat.split(",")[1]); |
| | | Double elnt = Double.valueOf(startLonLat.split(",")[0]); |
| | | Double elat = Double.valueOf(startLonLat.split(",")[1]); |
| | | DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(slat, slnt, elat, elnt); |
| | | Double elnt = Double.valueOf(endLonLat.split(",")[0]); |
| | | Double elat = Double.valueOf(endLonLat.split(",")[1]); |
| | | DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(slat, slnt, elat, elnt, tripId); |
| | | if(null == distancematrix){ |
| | | return ResultUtil.error("获取预估距离出错", new ArrayList<>()); |
| | | return ResultUtil.error(language == 1 ? "获取预估距离出错" : language == 2 ? "Obtaining-estimated-distance error" : "Erreur d’obtention de la distance estimée", new ArrayList<>()); |
| | | }else if(distancematrix.getDistance() == 0){ |
| | | return ResultUtil.error(language == 1 ? "未获取到有效的距离" : language == 2 ? "Not obtaining available distance" : "Ne pas obtenir la distance disponible", new ArrayList<>()); |
| | | } |
| | | long distance1 = distancematrix.getDistance();//距离(米) |
| | | double distance1_ = Double.valueOf(distance1).doubleValue(); |
| | | long duration = distancematrix.getDuration();//时间(秒) |
| | | 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, type, language); |
| | | if(price.size() == 0){ |
| | | return ResultUtil.error("未获取到可服务的车型", new ArrayList<>()); |
| | | return ResultUtil.error(language == 1 ? "未获取到可服务的车型" : language == 2 ? "Not obtaining available vehicle-type" : "Ne pas obtenir le type de véhicule disponible", new ArrayList<>()); |
| | | } |
| | | return ResultUtil.success(price); |
| | | } |
| | |
| | | * @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, Integer language) 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(1 == language){ |
| | | map.put("name", map.get("chineseName")); |
| | | } |
| | | if(2 == language){ |
| | | map.put("name", map.get("englishName")); |
| | | } |
| | | if(3 == language){ |
| | | map.put("name", map.get("frenchName")); |
| | | } |
| | | Map<String, Object> query1 = systemPriceMapper.query(companyId, type, Integer.valueOf(map.get("id").toString()), language); |
| | | if(null == query1){//排除没有设置价格的车型 |
| | | continue; |
| | | } |
| | | //开始根据不同的方式计算金额 |
| | | double amount = 0; |
| | | if(type == 1){//专车 |
| | | if(type == 1 || type == 4){//专车 |
| | | JSONObject jsonObject = JSON.parseObject(query1.get("content").toString()); |
| | | String fareTypeNote = query1.get("fareTypeNote").toString(); |
| | | Double num1 = jsonObject.getDouble("num1");//起步价(元) |
| | | Double num2 = jsonObject.getDouble("num2");//起步公里(公里) |
| | | Double num3 = jsonObject.getDouble("num3");//起步时间(分钟) |
| | |
| | | |
| | | |
| | | //夜间服务处理逻辑 |
| | | 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 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; |
| | | // } |
| | | |
| | | |
| | | //高峰时段处理逻辑 |
| | |
| | | serverCarModelWarpper.setAmount(new BigDecimal(amount).setScale(BigDecimal.ROUND_HALF_EVEN, 2).doubleValue()); |
| | | serverCarModelWarpper.setMileage(d); |
| | | serverCarModelWarpper.setDuration(t); |
| | | serverCarModelWarpper.setFareTypeNote(fareTypeNote); |
| | | data.add(serverCarModelWarpper); |
| | | continue; |
| | | } |
| | |
| | | } |
| | | amount = num1 + (d1 * num4) + (t1 * num5) + (wait * num7) + yt1 + yt2 + yt3; |
| | | ServerCarModelWarpper serverCarModelWarpper = ServerCarModelWarpper.getServerCarModelWarpper(map); |
| | | serverCarModelWarpper.setAmount(new BigDecimal(amount).multiply(new BigDecimal(0.85)).setScale(BigDecimal.ROUND_HALF_EVEN, 2).doubleValue()); |
| | | serverCarModelWarpper.setAmount(new BigDecimal(amount).setScale(BigDecimal.ROUND_HALF_EVEN, 2).doubleValue()); |
| | | serverCarModelWarpper.setMileage(d); |
| | | serverCarModelWarpper.setDuration(t); |
| | | serverCarModelWarpper.setFareTypeNote(fareTypeNote); |
| | | data.add(serverCarModelWarpper); |
| | | continue; |
| | | } |