| | |
| | | // 计算使用时间规则 |
| | | couponList = xpAppUserCouponService.timeRule(couponList); |
| | | if(couponList.isEmpty()){ |
| | | if(dto.getUserCouponId()!=null){ |
| | | userCouponVo.setStatus(2); |
| | | } |
| | | return R.ok(userCouponVo); |
| | | } |
| | | if(dto.getUserCouponId()!=null){ |
| | | XpAppUserCoupon coupon = couponList.get(0); |
| | | // 判断是否满足金额 |
| | | if(coupon.getCouponType()==2){ |
| | | if(dto.getTotalAmount()<coupon.getFullMoney().doubleValue()){ |
| | | userCouponVo.setStatus(2); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 优先用满足条件且抵扣金额最大的 |
| | | List<XpAppUserCoupon> discountUserCoupons = couponList.stream().filter(e -> e.getCouponType() == 1).sorted(Comparator.comparing(XpAppUserCoupon::getMoney).reversed()).collect(Collectors.toList()); |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.time.Duration; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | |
| | |
| | | for (int i = 0; i < parse.size(); i++) { |
| | | JSONObject jsonObject1 = parse.getJSONObject(i); |
| | | String daytype = jsonObject1.get("daytype").toString(); |
| | | |
| | | long secondsToExactEndOfDay = getSecondsToExactEndOfDay(); |
| | | if (daytype.equals("0")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 0; |
| | | } else if (daytype.equals("1")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "1", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "1", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 1; |
| | | } else if (daytype.equals("2")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "2", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 0; |
| | | } |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | public static long getSecondsToExactEndOfDay() { |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | |
| | | // 精确到23:59:59(不包含毫秒/纳秒) |
| | | LocalDateTime endOfDay = LocalDateTime.of( |
| | | LocalDate.now(), |
| | | LocalTime.of(23, 59, 59) |
| | | ); |
| | | |
| | | return Duration.between(now, endOfDay).getSeconds(); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | //城市不存在 |
| | | String CITY_NOT_FOUND = "city.not.found"; |
| | | String COUPON_NOT_SATISFY = "coupon.not.satisfy"; |
| | | } |
| | |
| | | private String placementAddress; |
| | | |
| | | |
| | | @ApiModelProperty("用户优惠券id") |
| | | private Long userCouponId; |
| | | |
| | | } |
| | |
| | | |
| | | // 优惠券 |
| | | XpPricingCardVo finalXpPricingCardVo = xpPricingCardVo; |
| | | R<UserCouponVo> coupon = null; |
| | | CompletableFuture<R<UserCouponVo>> couponFuture=null; |
| | | // 判断是否指定优惠券 |
| | | if(routeAndFareDto.getUserCouponId()!=null){ |
| | | R<UserCouponVo> coupon = xpAppUserCouponClient.getUserCoupon(new GetUserCouponDto(Long.valueOf(userId), finalXpPricingCardVo.getTotalPrice(), routeAndFareDto.getOpenCityId(),routeAndFareDto.getUserCouponId())); |
| | | coupon = xpAppUserCouponClient.getUserCoupon(new GetUserCouponDto(Long.valueOf(userId), finalXpPricingCardVo.getTotalPrice(), routeAndFareDto.getOpenCityId(),routeAndFareDto.getUserCouponId())); |
| | | if(coupon.getCode()==200 && coupon.getData().getStatus()==2){ |
| | | throw new ServiceException("优惠券不满足条件", I18nKeyConstant.COUPON_NOT_SATISFY); |
| | | } |
| | | }else { |
| | | |
| | | couponFuture= CompletableFuture.supplyAsync( |
| | | () -> { |
| | | // 优惠券 |
| | | return xpAppUserCouponClient.getUserCoupon( |
| | | new GetUserCouponDto(Long.valueOf(userId), finalXpPricingCardVo.getTotalPrice(), routeAndFareDto.getOpenCityId(),null) |
| | | // new GetUserCouponDto(Long.valueOf(userId), 1d, routeAndFareDto.getOpenCityId()) |
| | | ); |
| | | }, |
| | | executorService |
| | | ); |
| | | } |
| | | |
| | | |
| | | |
| | | CompletableFuture<R<UserCouponVo>> couponFuture = CompletableFuture.supplyAsync( |
| | | () -> { |
| | | // 优惠券 |
| | | return xpAppUserCouponClient.getUserCoupon( |
| | | new GetUserCouponDto(Long.valueOf(userId), finalXpPricingCardVo.getTotalPrice(), routeAndFareDto.getOpenCityId(),null) |
| | | // new GetUserCouponDto(Long.valueOf(userId), 1d, routeAndFareDto.getOpenCityId()) |
| | | ); |
| | | }, |
| | | executorService |
| | | ); |
| | | |
| | | |
| | | // 3. 并行执行远程服务调用 判断是否同一经营区域 |
| | |
| | | |
| | | // 4. 等待所有并行任务完成并获取结果 |
| | | R<Boolean> diagnosisResult = diagnosisAreaFuture.join(); |
| | | R<UserCouponVo> couponResult = couponFuture.join(); |
| | | R<UserCouponVo> couponResult =null; |
| | | if(routeAndFareDto.getUserCouponId()!=null){ |
| | | couponResult =coupon; |
| | | }else { |
| | | couponResult =couponFuture.join(); |
| | | } |
| | | |
| | | // 5. 处理诊断结果 |
| | | if (diagnosisResult.getCode() != R.SUCCESS) { |
| | |
| | | } |
| | | Long orderId = addOrderR.getData(); |
| | | xpOrder.setId(orderId); |
| | | xpOrder.setCouponId(dto.getUserCouponId()); |
| | | // 静默处理 不推单 |
| | | // if (isSilent) { |
| | | // log.info("订单取消次数达到上限,执行静默处理,不推单。"); |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.time.Duration; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | |
| | |
| | | for (int i = 0; i < parse.size(); i++) { |
| | | JSONObject jsonObject1 = parse.getJSONObject(i); |
| | | String daytype = jsonObject1.get("daytype").toString(); |
| | | long secondsToExactEndOfDay = getSecondsToExactEndOfDay(); |
| | | if (daytype.equals("0")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 0; |
| | | } else if (daytype.equals("1")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "1", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "1", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 1; |
| | | } else if (daytype.equals("2")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "2", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 0; |
| | | } |
| | | } |
| | | return 0; |
| | | } |
| | | public static long getSecondsToExactEndOfDay() { |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | |
| | | // 精确到23:59:59(不包含毫秒/纳秒) |
| | | LocalDateTime endOfDay = LocalDateTime.of( |
| | | LocalDate.now(), |
| | | LocalTime.of(23, 59, 59) |
| | | ); |
| | | |
| | | return Duration.between(now, endOfDay).getSeconds(); |
| | | } |
| | | /** |
| | | * 2非工作日 0工作日 1节假日 3调休日 |
| | |
| | | for (int i = 0; i < parse.size(); i++) { |
| | | JSONObject jsonObject1 = parse.getJSONObject(i); |
| | | String daytype = jsonObject1.get("daytype").toString(); |
| | | long secondsToExactEndOfDay = getSecondsToExactEndOfDay(); |
| | | if (daytype.equals("0")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 0; |
| | | } else if (daytype.equals("1")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "1", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "1", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 1; |
| | | } else if (daytype.equals("2")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "2", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 0; |
| | | } |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | } |
| | |
| | | # 中文 |
| | | city.not.found=获取城市信息失败 |
| | | coupon.not.satisfy=券不满足条件 |
| | | no.current.point=该站点已停止运营 |
| | | no.current.region=当前区域未开通服务 |
| | | path.not.found=获取导航信息失败 |
| | |
| | | # English (US) |
| | | city.not.found=city.not.found |
| | | coupon.not.satisfy=The coupon does not meet the conditions. |
| | | no.current.point=This site has ceased operations |
| | | no.current.region=no.current.region |
| | | path.not.found=Failed to obtain navigation information |
| | |
| | | # 中文 |
| | | city.not.found=获取城市信息失败 |
| | | coupon.not.satisfy=券不满足条件 |
| | | no.current.point=该站点已停止运营 |
| | | no.current.region=当前区域未开通服务 |
| | | path.not.found=获取导航信息失败 |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.time.Duration; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | |
| | |
| | | for (int i = 0; i < parse.size(); i++) { |
| | | JSONObject jsonObject1 = parse.getJSONObject(i); |
| | | String daytype = jsonObject1.get("daytype").toString(); |
| | | |
| | | long secondsToExactEndOfDay = getSecondsToExactEndOfDay(); |
| | | if (daytype.equals("0")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 0; |
| | | } else if (daytype.equals("1")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "1", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "1", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 1; |
| | | } else if (daytype.equals("2")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "2", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 0; |
| | | } |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | public static long getSecondsToExactEndOfDay() { |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | |
| | | // 精确到23:59:59(不包含毫秒/纳秒) |
| | | LocalDateTime endOfDay = LocalDateTime.of( |
| | | LocalDate.now(), |
| | | LocalTime.of(23, 59, 59) |
| | | ); |
| | | |
| | | return Duration.between(now, endOfDay).getSeconds(); |
| | | } |
| | | } |
| | |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.time.Duration; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | |
| | |
| | | for (int i = 0; i < parse.size(); i++) { |
| | | JSONObject jsonObject1 = parse.getJSONObject(i); |
| | | String daytype = jsonObject1.get("daytype").toString(); |
| | | long secondsToExactEndOfDay = getSecondsToExactEndOfDay(); |
| | | if (daytype.equals("0")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 0; |
| | | } else if (daytype.equals("1")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "1", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "1", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 1; |
| | | } else if (daytype.equals("2")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "2", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 0; |
| | | } |
| | | } |
| | |
| | | for (int i = 0; i < parse.size(); i++) { |
| | | JSONObject jsonObject1 = parse.getJSONObject(i); |
| | | String daytype = jsonObject1.get("daytype").toString(); |
| | | long secondsToExactEndOfDay = getSecondsToExactEndOfDay(); |
| | | if (daytype.equals("0")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 0; |
| | | } else if (daytype.equals("1")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "1", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "1", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 1; |
| | | } else if (daytype.equals("2")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "2", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 0; |
| | | } |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | public static long getSecondsToExactEndOfDay() { |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | |
| | | // 精确到23:59:59(不包含毫秒/纳秒) |
| | | LocalDateTime endOfDay = LocalDateTime.of( |
| | | LocalDate.now(), |
| | | LocalTime.of(23, 59, 59) |
| | | ); |
| | | |
| | | return Duration.between(now, endOfDay).getSeconds(); |
| | | } |
| | | } |
| | |
| | | Date orderTime = new Date(); |
| | | // |
| | | // 模拟总里程 25.0 km,以触发多级远途加价 |
| | | double totalMillige = 2.984; |
| | | double totalMillige = 1.24; |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.set(2026, Calendar.APRIL, 11, 15, 57, 50); |
| | | cal.set(2026, Calendar.APRIL, 11, 15, 48, 50); |
| | | orderTime = cal.getTime(); |
| | | // 模拟 GPS 轨迹点 |
| | | List<GpsPoint> points = createMockGpsPoints(orderTime); |
| | |
| | | System.err.println("--------------------------"); |
| | | System.err.println("应付总额: " + totalAmount + " 元"); |
| | | |
| | | // List<GpsPoint> mockGpsPoints = createMockGpsPoints(orderTime); |
| | | // double sum = mockGpsPoints.stream().mapToDouble(GpsPoint::getDistance).sum(); |
| | | // System.err.println(sum); |
| | | List<GpsPoint> mockGpsPoints = createMockGpsPoints(orderTime); |
| | | double sum = mockGpsPoints.stream().mapToDouble(GpsPoint::getDistance).sum(); |
| | | System.err.println(sum); |
| | | |
| | | } |
| | | |
| | |
| | | list.add(new GpsPoint(188, startTs + 2 * 50 * 1000)); |
| | | list.add(new GpsPoint(150, startTs + 2 * 60 * 1000)); |
| | | list.add(new GpsPoint(126, startTs + 2 * 70 * 1000)); |
| | | list.add(new GpsPoint(138, startTs + 2 * 80 * 1000)); |
| | | list.add(new GpsPoint(119, startTs + 2 * 90 * 1000)); |
| | | list.add(new GpsPoint(147, startTs + 2 * 100 * 1000)); |
| | | list.add(new GpsPoint(155, startTs + 2 * 110 * 1000)); |
| | | list.add(new GpsPoint(182, startTs + 2 * 120 * 1000)); |
| | | list.add(new GpsPoint(172, startTs + 2 * 130 * 1000)); |
| | | list.add(new GpsPoint(202, startTs + 2 * 140 * 1000)); |
| | | list.add(new GpsPoint(162, startTs + 2 * 150 * 1000)); |
| | | list.add(new GpsPoint(182, startTs + 2 * 160 * 1000)); |
| | | list.add(new GpsPoint(132, startTs + 2 * 170 * 1000)); |
| | | list.add(new GpsPoint(122, startTs + 2 * 180 * 1000)); |
| | | // list.add(new GpsPoint(138, startTs + 2 * 80 * 1000)); |
| | | // list.add(new GpsPoint(119, startTs + 2 * 90 * 1000)); |
| | | // list.add(new GpsPoint(147, startTs + 2 * 100 * 1000)); |
| | | // list.add(new GpsPoint(155, startTs + 2 * 110 * 1000)); |
| | | // list.add(new GpsPoint(182, startTs + 2 * 120 * 1000)); |
| | | // list.add(new GpsPoint(172, startTs + 2 * 130 * 1000)); |
| | | // list.add(new GpsPoint(202, startTs + 2 * 140 * 1000)); |
| | | // list.add(new GpsPoint(162, startTs + 2 * 150 * 1000)); |
| | | // list.add(new GpsPoint(182, startTs + 2 * 160 * 1000)); |
| | | // list.add(new GpsPoint(132, startTs + 2 * 170 * 1000)); |
| | | // list.add(new GpsPoint(122, startTs + 2 * 180 * 1000)); |
| | | // list.add(new GpsPoint(262, startTs + 2 * 190 * 1000)); |
| | | // list.add(new GpsPoint(242, startTs + 2 * 200 * 1000)); |
| | | // list.add(new GpsPoint(282, startTs + 2 * 210 * 1000)); |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.time.Duration; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | |
| | |
| | | for (int i = 0; i < parse.size(); i++) { |
| | | JSONObject jsonObject1 = parse.getJSONObject(i); |
| | | String daytype = jsonObject1.get("daytype").toString(); |
| | | // 计算今天结束还差多少秒 |
| | | long secondsToExactEndOfDay = getSecondsToExactEndOfDay(); |
| | | if (daytype.equals("0")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 0; |
| | | } else if (daytype.equals("1")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "1", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "1", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 1; |
| | | } else if (daytype.equals("2")) { |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "0", 1l, TimeUnit.DAYS); |
| | | redisService.setCacheObject(CacheConstants.IS_DAY + now, "2", secondsToExactEndOfDay, TimeUnit.SECONDS); |
| | | return 0; |
| | | } |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | public static long getSecondsToExactEndOfDay() { |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | |
| | | // 精确到23:59:59(不包含毫秒/纳秒) |
| | | LocalDateTime endOfDay = LocalDateTime.of( |
| | | LocalDate.now(), |
| | | LocalTime.of(23, 59, 59) |
| | | ); |
| | | |
| | | return Duration.between(now, endOfDay).getSeconds(); |
| | | } |
| | | } |