Commit 44e035a6 authored by libin's avatar libin

日历价格

parent 8b877207
......@@ -80,7 +80,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
List<Date> dateList = vehicleModelCalendarPrices.stream().peek(x -> {
VehicleModelCalendarPrice calendarPrice = new VehicleModelCalendarPrice();
BeanUtils.copyProperties(x, calendarPrice);
Date date = Date.from(LocalDate.parse(x.getDate()).atStartOfDay(ZoneId.systemDefault()).toInstant());
Date date = localDateToDate(LocalDate.parse(x.getDate()));
calendarPrice.setVehicleModelDay(date);
calendarPrice.setCrtTime(new Date());
calendarPrice.setCrtUserId(userId);
......@@ -166,10 +166,10 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
List<VehicleModelCalendarPriceSaveDTO> vehicleModelCalendarPriceSaveDTOS = new ArrayList<>();
Example example = new Example(VehicleModelCalendarPrice.class);
Example.Criteria criteria = example.createCriteria();
LocalDate startLocalDate = currentDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate().withDayOfMonth(1);
Date startDate = Date.from(startLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
LocalDate startLocalDate = dateToLocalDate(currentDate).withDayOfMonth(1);
Date startDate = localDateToDate(startLocalDate);
LocalDate endLocalDate = startLocalDate.with(TemporalAdjusters.lastDayOfMonth());
Date endDate = Date.from(endLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
Date endDate = localDateToDate(endLocalDate);
criteria.andBetween("vehicleModelDay", startDate, endDate);
criteria.andEqualTo("isDel", 0);
List<VehicleModelCalendarPrice> vehicleModelCalendarPriceList = mapper.selectByExample(example);
......@@ -224,7 +224,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
transformStartDateAndEndDate(startReference, endReference);
List<VehicleModelCalendarPriceDTO> vehicleModelCalendarPrice = findVehicleModelCalendarPrice(startReference.get(), endReference.get(), vehicleModelId, userId);
for (VehicleModelCalendarPriceDTO vehicleModelCalendarPriceDTO : vehicleModelCalendarPrice) {
LocalDate current_date = vehicleModelCalendarPriceDTO.getDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate current_date = dateToLocalDate(vehicleModelCalendarPriceDTO.getDate());
boolean isSelect = (current_date.isAfter(startLocalDate) && current_date.isBefore(endLocalDate)) || current_date.isEqual(startLocalDate) || current_date.isEqual(endLocalDate);
vehicleModelCalendarPriceDTO.setIsSelect(isSelect ? true : false);
}
......@@ -285,10 +285,11 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
switch (vehicleModelCalendarPrice.getType()) {
case VehicleModelPriceType.MULTIPLE:
no_discount_price = vehicle_price.multiply(new BigDecimal(vehicleModelCalendarPrice.getMultiple().doubleValue()));
vehicle_price = no_discount_price.multiply(new BigDecimal(discount / 100.0));
vehicle_price = no_discount_price.multiply(new BigDecimal(discount / 100.00));
break;
case VehicleModelPriceType.ABS:
vehicle_price = vehicleModelCalendarPrice.getPrice().multiply(new BigDecimal(discount / 100.00));
no_discount_price = vehicleModelCalendarPrice.getPrice();
vehicle_price = no_discount_price.multiply(new BigDecimal(discount / 100.00));
break;
case VehicleModelPriceType.MEMBER:
memberLevel = vehicleModelCalendarPrice.getLevel() > memberLevel ? vehicleModelCalendarPrice.getLevel() : memberLevel;
......@@ -308,7 +309,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
free_days = (Integer) price_freeDays_map.get(DAYS_VAL);
}
vehicleModelCalendarPriceDTO.setNo_discount_price(no_discount_price);
vehicleModelCalendarPriceDTO.setPrice(vehicle_price.setScale(2, RoundingMode.DOWN));
vehicleModelCalendarPriceDTO.setPrice(vehicle_price.setScale(2, RoundingMode.HALF_UP));
vehicleModelCalendarPriceDTO.setFreeDays(free_days);
final_startLocalDate = final_startLocalDate.plusDays(1);
vehicleModelCalendarPriceVos.add(vehicleModelCalendarPriceDTO);
......@@ -377,48 +378,59 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
LocalDate now = LocalDate.now();
LocalDate endLocalDate = now.with(TemporalAdjusters.lastDayOfMonth());
LocalDate startLocalDate = now.withDayOfMonth(1);
startDate = Date.from(startLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
endDate = Date.from(endLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
startDate = localDateToDate(startLocalDate);
endDate = localDateToDate(endLocalDate);
} else {
int days = 0;
/****************************************开始时间处理******************************************************/
LocalDate startLocalDate = LocalDate.from(startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
int start_dayOfMonth = startLocalDate.getDayOfMonth();
LocalDate startLocalDate = dateToLocalDate(startDate);
int start_week = startLocalDate.getDayOfWeek().getValue();
if (START_OF_WEEK < start_week && start_week < END_OF_WEEK) {
start_dayOfMonth = start_dayOfMonth - (start_week - START_OF_WEEK);
days =start_week - START_OF_WEEK;
} else {
if (END_OF_WEEK == start_week) {
start_dayOfMonth = start_dayOfMonth - END_OF_WEEK + 1;
days = END_OF_WEEK-1;
}
}
start_dayOfMonth = start_dayOfMonth > 0 ? start_dayOfMonth : 1;
LocalDate start_startLocalDate = startLocalDate.withDayOfMonth(start_dayOfMonth);
LocalDate start_startLocalDate = startLocalDate.minusDays(days);
/****************************************结束时间处理******************************************************/
LocalDate endLocalDate = LocalDate.from(endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
int end_dayOfMonth = endLocalDate.getDayOfMonth();
days = 0;
LocalDate endLocalDate = dateToLocalDate(endDate);
int end_week = endLocalDate.getDayOfWeek().getValue();
int last_day = endLocalDate.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
if (START_OF_WEEK < end_week && end_week < END_OF_WEEK) {
end_dayOfMonth = end_dayOfMonth + (END_OF_WEEK - end_week);
days = END_OF_WEEK - end_week;
} else {
if (START_OF_WEEK == end_week) {
end_dayOfMonth = end_dayOfMonth + END_OF_WEEK - 1;
days =END_OF_WEEK - 1;
}
}
end_dayOfMonth = end_dayOfMonth > last_day ? last_day : end_dayOfMonth;
LocalDate end_endLocalDate = endLocalDate.withDayOfMonth(end_dayOfMonth);
LocalDate end_endLocalDate = endLocalDate.plusDays(days);
/****************************************时间转换******************************************************/
startDate = Date.from(start_startLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
endDate = Date.from(end_endLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
startDate = localDateToDate(start_startLocalDate);
endDate = localDateToDate(end_endLocalDate);
}
startDatee.set(startDate);
endDatee.set(endDate);
}
private static LocalDate dateToLocalDate(Date date){
return LocalDate.from(date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
}
private static Date localDateToDate(LocalDate localDate){
return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
public static void main(String[] args) {
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()));
transformStartDateAndEndDate(start,end);
System.out.println(start.get());
System.out.println(end.get());
}
/**
......
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