Commit ad229709 authored by libin's avatar libin

日历价格

parent 0bcc34e1
...@@ -28,7 +28,8 @@ public class VehicleModelHolidayPriceSaveDTO implements Serializable { ...@@ -28,7 +28,8 @@ public class VehicleModelHolidayPriceSaveDTO implements Serializable {
/** /**
* 节假日日期 * 节假日日期
*/ */
private List<Date> date; private Date startDate;
private Date endDate;
/** /**
* 节假日名称 * 节假日名称
*/ */
......
...@@ -24,7 +24,9 @@ public class VehicleModelHolidayPriceVo implements Serializable { ...@@ -24,7 +24,9 @@ public class VehicleModelHolidayPriceVo implements Serializable {
/** /**
* 节假日日期 * 节假日日期
*/ */
private Date festivalDay; // private Date festivalDay;
private Date startDate;
private Date endDate;
/** /**
* 节假日 * 节假日
*/ */
......
...@@ -11,6 +11,7 @@ import com.xxfc.platform.vehicle.pojo.dto.VehicleModelCalendarPriceSaveDTO; ...@@ -11,6 +11,7 @@ import com.xxfc.platform.vehicle.pojo.dto.VehicleModelCalendarPriceSaveDTO;
import com.xxfc.platform.vehicle.pojo.dto.VehicleModelDTO; import com.xxfc.platform.vehicle.pojo.dto.VehicleModelDTO;
import com.xxfc.platform.vehicle.pojo.dto.VehicleModelHolidayPriceDTO; import com.xxfc.platform.vehicle.pojo.dto.VehicleModelHolidayPriceDTO;
import com.xxfc.platform.vehicle.pojo.vo.VehicleModelDayPriceVo; import com.xxfc.platform.vehicle.pojo.vo.VehicleModelDayPriceVo;
import com.xxfc.platform.vehicle.util.DateUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
...@@ -67,7 +68,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -67,7 +68,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
List<Date> dateList = vehicleModelCalendarPrices.stream().peek(x -> { List<Date> dateList = vehicleModelCalendarPrices.stream().peek(x -> {
VehicleModelCalendarPrice calendarPrice = new VehicleModelCalendarPrice(); VehicleModelCalendarPrice calendarPrice = new VehicleModelCalendarPrice();
BeanUtils.copyProperties(x, calendarPrice); BeanUtils.copyProperties(x, calendarPrice);
Date date = localDateToDate(LocalDate.parse(x.getDate())); Date date = DateUtils.localDateToDate(LocalDate.parse(x.getDate()));
calendarPrice.setVehicleModelDay(date); calendarPrice.setVehicleModelDay(date);
calendarPrice.setCrtTime(new Date()); calendarPrice.setCrtTime(new Date());
calendarPrice.setCrtUserId(userId); calendarPrice.setCrtUserId(userId);
...@@ -153,10 +154,10 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -153,10 +154,10 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
List<VehicleModelCalendarPriceSaveDTO> vehicleModelCalendarPriceSaveDTOS = new ArrayList<>(); List<VehicleModelCalendarPriceSaveDTO> vehicleModelCalendarPriceSaveDTOS = new ArrayList<>();
Example example = new Example(VehicleModelCalendarPrice.class); Example example = new Example(VehicleModelCalendarPrice.class);
Example.Criteria criteria = example.createCriteria(); Example.Criteria criteria = example.createCriteria();
LocalDate startLocalDate = dateToLocalDate(currentDate).withDayOfMonth(1); LocalDate startLocalDate = DateUtils.dateToLocalDate(currentDate).withDayOfMonth(1);
Date startDate = localDateToDate(startLocalDate); Date startDate = DateUtils.localDateToDate(startLocalDate);
LocalDate endLocalDate = startLocalDate.with(TemporalAdjusters.lastDayOfMonth()); LocalDate endLocalDate = startLocalDate.with(TemporalAdjusters.lastDayOfMonth());
Date endDate = localDateToDate(endLocalDate); Date endDate = DateUtils.localDateToDate(endLocalDate);
criteria.andBetween("vehicleModelDay", startDate, endDate); criteria.andBetween("vehicleModelDay", startDate, endDate);
criteria.andEqualTo("isDel", 0); criteria.andEqualTo("isDel", 0);
List<VehicleModelCalendarPrice> vehicleModelCalendarPriceList = mapper.selectByExample(example); List<VehicleModelCalendarPrice> vehicleModelCalendarPriceList = mapper.selectByExample(example);
...@@ -201,8 +202,8 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -201,8 +202,8 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
* @return * @return
*/ */
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 = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); LocalDate startLocalDate = DateUtils.dateToLocalDate(startDate);
LocalDate endLocalDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); LocalDate endLocalDate = DateUtils.dateToLocalDate(endDate);
//处理后延伸的开始时间 //处理后延伸的开始时间
AtomicReference<Date> startReference = new AtomicReference<>(startDate); AtomicReference<Date> startReference = new AtomicReference<>(startDate);
...@@ -211,7 +212,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -211,7 +212,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
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) { for (VehicleModelCalendarPriceDTO vehicleModelCalendarPriceDTO : vehicleModelCalendarPrice) {
LocalDate current_date = 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); boolean isSelect = (current_date.isAfter(startLocalDate) && current_date.isBefore(endLocalDate)) || current_date.isEqual(startLocalDate) || current_date.isEqual(endLocalDate);
vehicleModelCalendarPriceDTO.setIsSelect(isSelect ? true : false); vehicleModelCalendarPriceDTO.setIsSelect(isSelect ? true : false);
} }
...@@ -252,8 +253,8 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -252,8 +253,8 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
memberLevel = baseUserMember == null ? memberLevel : baseUserMember.getMemberLevel(); memberLevel = baseUserMember == null ? memberLevel : baseUserMember.getMemberLevel();
} }
VehicleModelCalendarPriceDTO vehicleModelCalendarPriceDTO; VehicleModelCalendarPriceDTO vehicleModelCalendarPriceDTO;
LocalDate final_startLocalDate = dateToLocalDate(startDate); LocalDate final_startLocalDate = DateUtils.dateToLocalDate(startDate);
LocalDate final_endLocalDate = dateToLocalDate(endDate); LocalDate final_endLocalDate = DateUtils.dateToLocalDate(endDate);
while (final_startLocalDate.isBefore(final_endLocalDate) || final_startLocalDate.isEqual(final_endLocalDate)) { while (final_startLocalDate.isBefore(final_endLocalDate) || final_startLocalDate.isEqual(final_endLocalDate)) {
vehicleModelCalendarPriceDTO = new VehicleModelCalendarPriceDTO(); vehicleModelCalendarPriceDTO = new VehicleModelCalendarPriceDTO();
//价格重置 //价格重置
...@@ -264,7 +265,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -264,7 +265,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
Integer free_days = DEFAULT_FREE_DAYS; Integer free_days = DEFAULT_FREE_DAYS;
//节假日对应的价格和免费天数 //节假日对应的价格和免费天数
Map<String, Object> price_freeDays_map = null; Map<String, Object> price_freeDays_map = null;
Date current_date = localDateToDate(final_startLocalDate); Date current_date = DateUtils.localDateToDate(final_startLocalDate);
vehicleModelCalendarPriceDTO.setDate(current_date); vehicleModelCalendarPriceDTO.setDate(current_date);
if (calendarPriceMap != null && !calendarPriceMap.isEmpty()) { if (calendarPriceMap != null && !calendarPriceMap.isEmpty()) {
VehicleModelCalendarPrice vehicleModelCalendarPrice = calendarPriceMap.get(current_date); VehicleModelCalendarPrice vehicleModelCalendarPrice = calendarPriceMap.get(current_date);
...@@ -372,13 +373,13 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -372,13 +373,13 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
LocalDate now = LocalDate.now(); LocalDate now = LocalDate.now();
LocalDate endLocalDate = now.with(TemporalAdjusters.lastDayOfMonth()); LocalDate endLocalDate = now.with(TemporalAdjusters.lastDayOfMonth());
LocalDate startLocalDate = now.withDayOfMonth(1); LocalDate startLocalDate = now.withDayOfMonth(1);
startDate = localDateToDate(startLocalDate); startDate = DateUtils.localDateToDate(startLocalDate);
endDate = localDateToDate(endLocalDate); endDate = DateUtils.localDateToDate(endLocalDate);
} else { } else {
int days = 0; int days = 0;
/****************************************开始时间处理******************************************************/ /****************************************开始时间处理******************************************************/
LocalDate startLocalDate = 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;
...@@ -391,7 +392,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -391,7 +392,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
/****************************************结束时间处理******************************************************/ /****************************************结束时间处理******************************************************/
days = 0; days = 0;
LocalDate endLocalDate = dateToLocalDate(endDate); LocalDate endLocalDate = DateUtils.dateToLocalDate(endDate);
int end_week = endLocalDate.getDayOfWeek().getValue(); int end_week = endLocalDate.getDayOfWeek().getValue();
if (START_OF_WEEK < end_week && end_week < END_OF_WEEK) { if (START_OF_WEEK < end_week && end_week < END_OF_WEEK) {
...@@ -403,20 +404,14 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -403,20 +404,14 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
} }
LocalDate end_endLocalDate = endLocalDate.plusDays(days); LocalDate end_endLocalDate = endLocalDate.plusDays(days);
/****************************************时间转换******************************************************/ /****************************************时间转换******************************************************/
startDate = localDateToDate(start_startLocalDate); startDate = DateUtils.localDateToDate(start_startLocalDate);
endDate = localDateToDate(end_endLocalDate); endDate = DateUtils.localDateToDate(end_endLocalDate);
} }
startDatee.set(startDate); startDatee.set(startDate);
endDatee.set(endDate); 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) { public static void main(String[] args) {
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()));
......
...@@ -9,6 +9,7 @@ import com.xxfc.platform.vehicle.pojo.dto.VehicleModelHolidayPriceDTO; ...@@ -9,6 +9,7 @@ import com.xxfc.platform.vehicle.pojo.dto.VehicleModelHolidayPriceDTO;
import com.xxfc.platform.vehicle.pojo.dto.VehicleModelHolidayPriceFindDTO; import com.xxfc.platform.vehicle.pojo.dto.VehicleModelHolidayPriceFindDTO;
import com.xxfc.platform.vehicle.pojo.dto.VehicleModelHolidayPriceSaveDTO; import com.xxfc.platform.vehicle.pojo.dto.VehicleModelHolidayPriceSaveDTO;
import com.xxfc.platform.vehicle.pojo.vo.VehicleModelHolidayPriceVo; import com.xxfc.platform.vehicle.pojo.vo.VehicleModelHolidayPriceVo;
import com.xxfc.platform.vehicle.util.DateUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -23,7 +24,9 @@ import java.time.LocalDate; ...@@ -23,7 +24,9 @@ import java.time.LocalDate;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalAdjusters;
import java.util.*; import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
/** /**
* @author libin * @author libin
...@@ -48,13 +51,16 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric ...@@ -48,13 +51,16 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
List<VehicleModelHolidayPrice> vehicleModelHolidayPriceList = new ArrayList<>(); List<VehicleModelHolidayPrice> vehicleModelHolidayPriceList = new ArrayList<>();
VehicleModelHolidayPrice vehicleModelHolidayPrice; VehicleModelHolidayPrice vehicleModelHolidayPrice;
List<Date> dates = vehicleModelHolidayPriceSaveDTO.getDate(); Date startDate = vehicleModelHolidayPriceSaveDTO.getStartDate();
for (Date date : dates) { LocalDate startLocaldate = DateUtils.dateToLocalDate(startDate);
LocalDate endLocaldate = DateUtils.dateToLocalDate(vehicleModelHolidayPriceSaveDTO.getEndDate());
while (startLocaldate.isBefore(endLocaldate) || startLocaldate.isEqual(endLocaldate)){
vehicleModelHolidayPrice = new VehicleModelHolidayPrice(); vehicleModelHolidayPrice = new VehicleModelHolidayPrice();
BeanUtils.copyProperties(vehicleModelHolidayPriceSaveDTO, vehicleModelHolidayPrice); BeanUtils.copyProperties(vehicleModelHolidayPriceSaveDTO, vehicleModelHolidayPrice);
date = Date.from(date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate().atStartOfDay(ZoneId.systemDefault()).toInstant()); Date date = DateUtils.localDateToDate(startLocaldate.atStartOfDay(ZoneId.systemDefault()).toLocalDate());
vehicleModelHolidayPrice.setFestivalDay(date); vehicleModelHolidayPrice.setFestivalDay(date);
vehicleModelHolidayPriceList.add(vehicleModelHolidayPrice); vehicleModelHolidayPriceList.add(vehicleModelHolidayPrice);
startLocaldate.plusDays(1);
} }
//编辑 //编辑
if (Objects.nonNull(vehicleModelHolidayPriceSaveDTO.getId())) { if (Objects.nonNull(vehicleModelHolidayPriceSaveDTO.getId())) {
...@@ -121,11 +127,17 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric ...@@ -121,11 +127,17 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
} }
List<Integer> festivalIds = holidayPrices.stream().map(VehicleModelHolidayPrice::getFestivalId).collect(Collectors.toList()); List<Integer> festivalIds = holidayPrices.stream().map(VehicleModelHolidayPrice::getFestivalId).collect(Collectors.toList());
Map<Integer,Festival> festivalMap = festivalBiz.findFestivalsByIds(festivalIds); Map<Integer,Festival> festivalMap = festivalBiz.findFestivalsByIds(festivalIds);
Map<Integer, List<VehicleModelHolidayPrice>> listMap = holidayPrices.stream().collect(Collectors.groupingBy(VehicleModelHolidayPrice::getFestivalId, Collectors.toList()));
VehicleModelHolidayPriceVo vehicleModelHolidayPriceVo; VehicleModelHolidayPriceVo vehicleModelHolidayPriceVo;
for (VehicleModelHolidayPrice holidayPrice : holidayPrices) {
for (Integer festivalId : festivalIds) {
vehicleModelHolidayPriceVo = new VehicleModelHolidayPriceVo(); vehicleModelHolidayPriceVo = new VehicleModelHolidayPriceVo();
BeanUtils.copyProperties(holidayPrice, vehicleModelHolidayPriceVo); BeanUtils.copyProperties(listMap.get(festivalId).get(0), vehicleModelHolidayPriceVo);
vehicleModelHolidayPriceVo.setFestival(festivalMap==null?"":festivalMap.get(holidayPrice.getFestivalId()).getName()); vehicleModelHolidayPriceVo.setFestival(festivalMap==null?"":festivalMap.get(festivalId).getName());
Date startDate = listMap.get(festivalId).stream().map(VehicleModelHolidayPrice::getFestivalDay).min(Date::compareTo).get();
Date endDate = listMap.get(festivalId).stream().map(VehicleModelHolidayPrice::getFestivalDay).max(Date::compareTo).get();
vehicleModelHolidayPriceVo.setStartDate(startDate);
vehicleModelHolidayPriceVo.setEndDate(endDate);
vehicleModelHolidayPriceVos.add(vehicleModelHolidayPriceVo); vehicleModelHolidayPriceVos.add(vehicleModelHolidayPriceVo);
} }
return vehicleModelHolidayPriceVos; return vehicleModelHolidayPriceVos;
...@@ -172,10 +184,12 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric ...@@ -172,10 +184,12 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
if (CollectionUtils.isEmpty(vehicleModelHolidayPrices)) { if (CollectionUtils.isEmpty(vehicleModelHolidayPrices)) {
throw new BaseException("数据不存在"); throw new BaseException("数据不存在");
} }
List<Date> dates = vehicleModelHolidayPrices.stream().map(VehicleModelHolidayPrice::getFestivalDay).collect(Collectors.toList()); Date startDate = vehicleModelHolidayPrices.stream().map(VehicleModelHolidayPrice::getFestivalDay).min(Date::compareTo).get();
Date endDate = vehicleModelHolidayPrices.stream().map(VehicleModelHolidayPrice::getFestivalDay).max(Date::compareTo).get();
VehicleModelHolidayPrice vehicleModelHolidayPrice = vehicleModelHolidayPrices.get(0); VehicleModelHolidayPrice vehicleModelHolidayPrice = vehicleModelHolidayPrices.get(0);
BeanUtils.copyProperties(vehicleModelHolidayPrice, modelHolidayPriceSaveDTO); BeanUtils.copyProperties(vehicleModelHolidayPrice, modelHolidayPriceSaveDTO);
modelHolidayPriceSaveDTO.setDate(dates); modelHolidayPriceSaveDTO.setStartDate(startDate);
modelHolidayPriceSaveDTO.setEndDate(endDate);
return modelHolidayPriceSaveDTO; return modelHolidayPriceSaveDTO;
} }
......
package com.xxfc.platform.vehicle.util;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/10/23 10:52
*/
public class DateUtils {
public static LocalDate dateToLocalDate(Date date) {
return LocalDate.from(date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
}
public static Date localDateToDate(LocalDate localDate) {
return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
}
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