Commit 230db194 authored by libin's avatar libin

租车日历价格

parent 1f8665dd
...@@ -5,6 +5,9 @@ import com.github.wxiaoqi.security.admin.entity.BaseUserMember; ...@@ -5,6 +5,9 @@ import com.github.wxiaoqi.security.admin.entity.BaseUserMember;
import com.github.wxiaoqi.security.admin.entity.BaseUserMemberLevel; import com.github.wxiaoqi.security.admin.entity.BaseUserMemberLevel;
import com.github.wxiaoqi.security.admin.feign.UserFeign; import com.github.wxiaoqi.security.admin.feign.UserFeign;
import com.github.wxiaoqi.security.common.biz.BaseBiz; import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.xxfc.platform.universal.constant.DictionaryKey;
import com.xxfc.platform.universal.entity.Dictionary;
import com.xxfc.platform.universal.feign.ThirdFeign;
import com.xxfc.platform.vehicle.entity.VehicleModelCalendarPrice; import com.xxfc.platform.vehicle.entity.VehicleModelCalendarPrice;
import com.xxfc.platform.vehicle.mapper.VehicleModelCalendarPriceMapper; import com.xxfc.platform.vehicle.mapper.VehicleModelCalendarPriceMapper;
import com.xxfc.platform.vehicle.pojo.dto.VehicleModelCalendarPriceDTO; import com.xxfc.platform.vehicle.pojo.dto.VehicleModelCalendarPriceDTO;
...@@ -32,6 +35,8 @@ import java.util.concurrent.atomic.AtomicReference; ...@@ -32,6 +35,8 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.xxfc.platform.universal.constant.DictionaryKey.APP_ORDER;
/** /**
* @author libin * @author libin
* @version 1.0 * @version 1.0
...@@ -49,12 +54,13 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -49,12 +54,13 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
private static final Integer DEFAULT_FREE_DAYS = 1; private static final Integer DEFAULT_FREE_DAYS = 1;
private static final Integer DEFAULT_MEMBER_LEVEL = 0; private static final Integer DEFAULT_MEMBER_LEVEL = 0;
private static final String PRICE_VAL = "price"; private static final String PRICE_VAL = "price";
private static final String BASE_PRICE_VAL="basePrice"; private static final String BASE_PRICE_VAL = "basePrice";
private static final String DAYS_VAL = "freeDays"; private static final String DAYS_VAL = "freeDays";
private final VehicleModelHolidayPriceBiz vehicleModelHolidayPriceBiz; private final VehicleModelHolidayPriceBiz vehicleModelHolidayPriceBiz;
private final VehicleModelBiz vehicleModelBiz; private final VehicleModelBiz vehicleModelBiz;
private final UserFeign userFeign; private final UserFeign userFeign;
private final ThirdFeign thirdFeign;
/** /**
...@@ -138,7 +144,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -138,7 +144,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
vehicleModelDayPriceVo.setMultiple(multiple); vehicleModelDayPriceVo.setMultiple(multiple);
BigDecimal aPrice = isNullOfVehicleModelPrice ? BigDecimal.ZERO : vehicleModelCalendarPriceMap.get(vehicleModelDTO.getVehicleModelId()).getPrice(); BigDecimal aPrice = isNullOfVehicleModelPrice ? BigDecimal.ZERO : vehicleModelCalendarPriceMap.get(vehicleModelDTO.getVehicleModelId()).getPrice();
vehicleModelDayPriceVo.setPrice(aPrice); vehicleModelDayPriceVo.setPrice(aPrice);
Integer level = isNullOfVehicleModelPrice? null:vehicleModelCalendarPriceMap.get(vehicleModelDTO.getVehicleModelId()).getLevel(); Integer level = isNullOfVehicleModelPrice ? null : vehicleModelCalendarPriceMap.get(vehicleModelDTO.getVehicleModelId()).getLevel();
vehicleModelDayPriceVo.setLevel(level); vehicleModelDayPriceVo.setLevel(level);
vehicleModelDayPriceVos.add(vehicleModelDayPriceVo); vehicleModelDayPriceVos.add(vehicleModelDayPriceVo);
} }
...@@ -176,7 +182,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -176,7 +182,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
Map<Date, Optional<VehicleModelCalendarPriceSaveDTO>> result = vehicleModelCalendarPriceSaveDTOS.stream() Map<Date, Optional<VehicleModelCalendarPriceSaveDTO>> result = vehicleModelCalendarPriceSaveDTOS.stream()
.collect(Collectors.groupingBy(VehicleModelCalendarPriceSaveDTO::getVehicleModelDay, Collectors.maxBy(Comparator.comparing(VehicleModelCalendarPriceSaveDTO::getId)))); .collect(Collectors.groupingBy(VehicleModelCalendarPriceSaveDTO::getVehicleModelDay, Collectors.maxBy(Comparator.comparing(VehicleModelCalendarPriceSaveDTO::getId))));
vehicleModelCalendarPriceSaveDTOS = result.values().stream().map(x->x.orElseGet(null)).filter(Objects::nonNull).collect(Collectors.toList()); vehicleModelCalendarPriceSaveDTOS = result.values().stream().map(x -> x.orElseGet(null)).filter(Objects::nonNull).collect(Collectors.toList());
return vehicleModelCalendarPriceSaveDTOS; return vehicleModelCalendarPriceSaveDTOS;
} }
...@@ -205,21 +211,61 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -205,21 +211,61 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
public List<VehicleModelCalendarPriceDTO> listVehicleModelCalendarPriceByDateAndVehicleModelIdAndUserId(Date startDate, Date endDate, Integer vehicleModelId, Integer userId) { public List<VehicleModelCalendarPriceDTO> listVehicleModelCalendarPriceByDateAndVehicleModelIdAndUserId(Date startDate, Date endDate, Integer vehicleModelId, Integer userId) {
LocalDate startLocalDate = DateUtils.dateToLocalDate(startDate); LocalDate startLocalDate = DateUtils.dateToLocalDate(startDate);
LocalDate endLocalDate = DateUtils.dateToLocalDate(endDate); LocalDate endLocalDate = DateUtils.dateToLocalDate(endDate);
boolean isSelect = false;
//处理后延伸的开始时间 //处理后延伸的开始时间
AtomicReference<Date> startReference = new AtomicReference<>(startDate); AtomicReference<Date> startReference = new AtomicReference<>(startDate);
//处理后延伸的结束时间 //处理后延伸的结束时间
AtomicReference<Date> endReference = new AtomicReference<>(endDate); AtomicReference<Date> endReference = new AtomicReference<>(endDate);
transformStartDateAndEndDate(startReference, endReference); transformStartDateAndEndDate(startReference, endReference);
List<VehicleModelCalendarPriceDTO> vehicleModelCalendarPrice = findVehicleModelCalendarPrice(startReference.get(), endReference.get(), vehicleModelId, userId); List<VehicleModelCalendarPriceDTO> vehicleModelCalendarPrice = findVehicleModelCalendarPrice(startReference.get(), endReference.get(), vehicleModelId, userId);
for (VehicleModelCalendarPriceDTO vehicleModelCalendarPriceDTO : vehicleModelCalendarPrice) { Integer days = getIncludeDays(startDate.getTime(), endDate.getTime());
for (int i = 0, y = 0; i < vehicleModelCalendarPrice.size(); i++) {
VehicleModelCalendarPriceDTO vehicleModelCalendarPriceDTO = vehicleModelCalendarPrice.get(i);
LocalDate current_date = DateUtils.dateToLocalDate(vehicleModelCalendarPriceDTO.getDate()); LocalDate current_date = DateUtils.dateToLocalDate(vehicleModelCalendarPriceDTO.getDate());
boolean isSelect = (current_date.isAfter(startLocalDate) && current_date.isBefore(endLocalDate)) || current_date.isEqual(startLocalDate) || current_date.isEqual(endLocalDate); if (y == 0) {
isSelect = (current_date.isAfter(startLocalDate) && current_date.isBefore(endLocalDate)) || current_date.isEqual(startLocalDate) || current_date.isEqual(endLocalDate);
}
if (isSelect) {
if (y < days) {
vehicleModelCalendarPriceDTO.setIsSelect(isSelect ? true : false); vehicleModelCalendarPriceDTO.setIsSelect(isSelect ? true : false);
y++;
}
}
} }
return vehicleModelCalendarPrice; return vehicleModelCalendarPrice;
} }
/**
* 计算包含多少天
*
* @param startLong
* @param endLong
* @return
*/
public Integer getIncludeDays(Long startLong, Long endLong) {
Map<String, Dictionary> dictionaryMap = thirdFeign.dictionaryGetAll4Map().getData();
Long hourLong = (60L * 60L * 1000L);
Long dayLong = hourLong * 24;
Long bufferLong = Long.valueOf(dictionaryMap.get(APP_ORDER + "_" + DictionaryKey.RENT_TIME_BUFFER).getDetail()) * hourLong;
//计算:使用天数 当前时间 - 开始时间的0时0分0秒
Long bookTimeLag = endLong - startLong;
log.info("bookTimeLag {}", new BigDecimal(bookTimeLag + ""));
log.info("divide {}", new BigDecimal((24 * 60 * 60 * 1000) + ""));
Integer bookDays = new BigDecimal(bookTimeLag + "").divide(new BigDecimal(dayLong + ""), 0, RoundingMode.DOWN).intValue();
Long excess = bookTimeLag % dayLong;
if (excess > bufferLong) {
bookDays += 1;
}
if (0 == bookDays) {
bookDays = 1;
}
return bookDays;
}
/** /**
* 日历价格查询 * 日历价格查询
* *
...@@ -246,10 +292,10 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -246,10 +292,10 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
BigDecimal vehicle_base_price = new BigDecimal(0); BigDecimal vehicle_base_price = new BigDecimal(0);
BigDecimal vehicle_price = vehicleModelBiz.findVehicleModelPriceByVehicleModelId(vehicleModelId); BigDecimal vehicle_price = vehicleModelBiz.findVehicleModelPriceByVehicleModelId(vehicleModelId);
vehicle_base_price = vehicle_base_price.add(vehicle_price); vehicle_base_price = vehicle_base_price.add(vehicle_price);
log.info("用户id【{}】",userId); log.info("用户id【{}】", userId);
if (Objects.nonNull(userId)) { if (Objects.nonNull(userId)) {
BaseUserMember baseUserMember = userFeign.findBaseUserMemberByUserId(userId); BaseUserMember baseUserMember = userFeign.findBaseUserMemberByUserId(userId);
log.info("用户会员信息:【{}】",baseUserMember); log.info("用户会员信息:【{}】", baseUserMember);
discount = baseUserMember == null ? discount : baseUserMember.getDiscount(); discount = baseUserMember == null ? discount : baseUserMember.getDiscount();
memberLevel = baseUserMember == null ? memberLevel : baseUserMember.getMemberLevel(); memberLevel = baseUserMember == null ? memberLevel : baseUserMember.getMemberLevel();
} }
...@@ -319,10 +365,10 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -319,10 +365,10 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
* @return * @return
*/ */
public Map<String, Object> transfromPriceAndFreeDaysByDate(Map<Date, VehicleModelHolidayPriceDTO> festivalDayMap, Date current_date, BigDecimal vehicle_price, Integer discount) { public Map<String, Object> transfromPriceAndFreeDaysByDate(Map<Date, VehicleModelHolidayPriceDTO> festivalDayMap, Date current_date, BigDecimal vehicle_price, Integer discount) {
log.info("参数:【{}==当前时间:{}==价格:{}==折扣:{}】",festivalDayMap,current_date,vehicle_price,discount); log.info("参数:【{}==当前时间:{}==价格:{}==折扣:{}】", festivalDayMap, current_date, vehicle_price, discount);
Map<String, Object> vehicle_price_days_map = new HashMap<>(3); Map<String, Object> vehicle_price_days_map = new HashMap<>(3);
Integer free_days = DEFAULT_FREE_DAYS; Integer free_days = DEFAULT_FREE_DAYS;
vehicle_price_days_map.put(BASE_PRICE_VAL,vehicle_price); vehicle_price_days_map.put(BASE_PRICE_VAL, vehicle_price);
if (MapUtil.isNotEmpty(festivalDayMap)) { if (MapUtil.isNotEmpty(festivalDayMap)) {
VehicleModelHolidayPriceDTO vehicleModelHolidayPriceDTO = festivalDayMap.get(current_date); VehicleModelHolidayPriceDTO vehicleModelHolidayPriceDTO = festivalDayMap.get(current_date);
if (Objects.nonNull(vehicleModelHolidayPriceDTO)) { if (Objects.nonNull(vehicleModelHolidayPriceDTO)) {
...@@ -333,7 +379,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -333,7 +379,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
vehicle_price = vehicle_price.multiply(new BigDecimal(Objects.toString(discount / 100.00))); vehicle_price = vehicle_price.multiply(new BigDecimal(Objects.toString(discount / 100.00)));
vehicle_price_days_map.put(PRICE_VAL, vehicle_price); vehicle_price_days_map.put(PRICE_VAL, vehicle_price);
vehicle_price_days_map.put(DAYS_VAL, free_days); vehicle_price_days_map.put(DAYS_VAL, free_days);
log.info("(节假日|非节假日未设置的)价格和免费天数 处理【{}】",vehicle_price_days_map); log.info("(节假日|非节假日未设置的)价格和免费天数 处理【{}】", vehicle_price_days_map);
return vehicle_price_days_map; return vehicle_price_days_map;
} }
...@@ -383,10 +429,10 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -383,10 +429,10 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
LocalDate startLocalDate = DateUtils.dateToLocalDate(startDate); LocalDate startLocalDate = DateUtils.dateToLocalDate(startDate);
int start_week = startLocalDate.getDayOfWeek().getValue(); int start_week = startLocalDate.getDayOfWeek().getValue();
if (START_OF_WEEK < start_week && start_week < END_OF_WEEK) { if (START_OF_WEEK < start_week && start_week < END_OF_WEEK) {
days =start_week - START_OF_WEEK; days = start_week - START_OF_WEEK;
} else { } else {
if (END_OF_WEEK == start_week) { if (END_OF_WEEK == start_week) {
days = END_OF_WEEK-1; days = END_OF_WEEK - 1;
} }
} }
LocalDate start_startLocalDate = startLocalDate.minusDays(days); LocalDate start_startLocalDate = startLocalDate.minusDays(days);
...@@ -400,7 +446,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -400,7 +446,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
days = END_OF_WEEK - end_week; days = END_OF_WEEK - end_week;
} else { } else {
if (START_OF_WEEK == end_week) { if (START_OF_WEEK == end_week) {
days =END_OF_WEEK - 1; days = END_OF_WEEK - 1;
} }
} }
LocalDate end_endLocalDate = endLocalDate.plusDays(days); LocalDate end_endLocalDate = endLocalDate.plusDays(days);
...@@ -417,7 +463,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -417,7 +463,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
AtomicReference<Date> start = new AtomicReference<>(Date.from(LocalDate.parse("2019-10-03").atStartOfDay(ZoneId.systemDefault()).toInstant())); AtomicReference<Date> start = new AtomicReference<>(Date.from(LocalDate.parse("2019-10-03").atStartOfDay(ZoneId.systemDefault()).toInstant()));
AtomicReference<Date> end = new AtomicReference<>(Date.from(LocalDate.parse("2019-10-29").atStartOfDay(ZoneId.systemDefault()).toInstant())); AtomicReference<Date> end = new AtomicReference<>(Date.from(LocalDate.parse("2019-10-29").atStartOfDay(ZoneId.systemDefault()).toInstant()));
transformStartDateAndEndDate(start,end); transformStartDateAndEndDate(start, end);
System.out.println(start.get()); System.out.println(start.get());
System.out.println(end.get()); System.out.println(end.get());
} }
......
...@@ -16,8 +16,9 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -16,8 +16,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.time.LocalDate; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -47,8 +48,8 @@ public class VehicleModelCalendarPriceController { ...@@ -47,8 +48,8 @@ public class VehicleModelCalendarPriceController {
if (StringUtils.isEmpty(start) || StringUtils.isEmpty(end)) { if (StringUtils.isEmpty(start) || StringUtils.isEmpty(end)) {
throw new BaseException("缺少开始时间或结束时间"); throw new BaseException("缺少开始时间或结束时间");
} }
Date startDate = Date.from(LocalDate.parse(start).atStartOfDay(ZoneId.systemDefault()).toInstant()); Date startDate = Date.from(LocalDateTime.parse(start, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).toInstant(ZoneOffset.ofHours(8)));
Date endDate = Date.from(LocalDate.parse(end).atStartOfDay(ZoneId.systemDefault()).toInstant()); Date endDate = Date.from(LocalDateTime.parse(end,DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).toInstant(ZoneOffset.ofHours(8)));
List<VehicleModelCalendarPriceDTO> vehicleModelCalendarPriceVos = vehicleModelCalendarPriceBiz.listVehicleModelCalendarPriceByDateAndVehicleModelIdAndUserId(startDate, endDate, vehicleModelId, appUserDTO.getUserid()); List<VehicleModelCalendarPriceDTO> vehicleModelCalendarPriceVos = vehicleModelCalendarPriceBiz.listVehicleModelCalendarPriceByDateAndVehicleModelIdAndUserId(startDate, endDate, vehicleModelId, appUserDTO.getUserid());
return ObjectRestResponse.succ(vehicleModelCalendarPriceVos); return ObjectRestResponse.succ(vehicleModelCalendarPriceVos);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment