Commit 1a317162 authored by 周健威's avatar 周健威

Merge remote-tracking branch 'origin/holiday-price' into holiday-price

parents 4429469d f335e317
...@@ -133,4 +133,5 @@ public interface UserFeign { ...@@ -133,4 +133,5 @@ public interface UserFeign {
@GetMapping("/member/user") @GetMapping("/member/user")
BaseUserMember findBaseUserMemberByUserId(@RequestParam(value = "userId") Integer userId); BaseUserMember findBaseUserMemberByUserId(@RequestParam(value = "userId") Integer userId);
} }
package com.github.wxiaoqi.security.admin.vo; package com.github.wxiaoqi.security.admin.vo;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
/** /**
* 用户信息表 * 用户信息表
*/ */
@Data @Data
@NoArgsConstructor
@AllArgsConstructor
public class AppUserVo { public class AppUserVo {
......
package com.xxfc.platform.vehicle.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/10/18 17:29
*/
@Data
@Table(name = "festival")
@NoArgsConstructor
@AllArgsConstructor
public class Festival {
@Id
@GeneratedValue(generator = "JDBC")
private Integer id;
private String name;
@Column(name = "crt_time")
private Date crtTime;
}
...@@ -36,7 +36,8 @@ public class VehicleModelHolidayPrice implements Serializable { ...@@ -36,7 +36,8 @@ public class VehicleModelHolidayPrice implements Serializable {
/** /**
* 节假日 * 节假日
*/ */
private String festival; @Column(name = "festival_id")
private Integer festivalId;
/** /**
* 倍数 * 倍数
*/ */
......
...@@ -20,5 +20,6 @@ import java.util.Date; ...@@ -20,5 +20,6 @@ import java.util.Date;
@NoArgsConstructor @NoArgsConstructor
public class VehicleModelHolidayPriceFindDTO extends PageParam { public class VehicleModelHolidayPriceFindDTO extends PageParam {
private String festival; private String festival;
private Date date; private String date;
private Integer year;
} }
...@@ -6,6 +6,7 @@ import lombok.Data; ...@@ -6,6 +6,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -20,13 +21,16 @@ import java.util.List; ...@@ -20,13 +21,16 @@ import java.util.List;
@NoArgsConstructor @NoArgsConstructor
public class VehicleModelHolidayPriceSaveDTO implements Serializable { public class VehicleModelHolidayPriceSaveDTO implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Long id; /**
* 节假日id
*/
private Integer id;
/** /**
* 节假日日期 * 节假日日期
*/ */
private String date; private List<Date> date;
/** /**
* 节假日 * 节假日名称
*/ */
private String festival; private String festival;
/** /**
......
package com.xxfc.platform.vehicle.biz;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.xxfc.platform.vehicle.entity.Festival;
import com.xxfc.platform.vehicle.mapper.FestivalMapper;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/10/18 17:31
*/
@Transactional(rollbackFor = Exception.class)
@Service
public class FestivalBiz extends BaseBiz<FestivalMapper,Festival> {
public void add(Festival festival){
if (Objects.isNull(festival.getId())){
festival.setCrtTime(new Date());
mapper.insertSelective(festival);
}else {
mapper.updateByPrimaryKey(festival);
}
}
public void deleteById(Integer festivalId){
Festival festival = new Festival();
festival.setId(festivalId);
mapper.deleteByPrimaryKey(festival);
}
public Map<Integer, Festival> findFestivalsByIds(List<Integer> festivalIds) {
Map<Integer,Festival> festivalMap = new HashMap<>(20);
List<Festival> festivals = mapper.selectByIdList(festivalIds);
if (CollectionUtils.isNotEmpty(festivalIds)){
festivalMap = festivals.stream().collect(Collectors.toMap(Festival::getId, Function.identity()));
}
return festivalMap;
}
}
...@@ -39,30 +39,15 @@ import java.util.stream.Collectors; ...@@ -39,30 +39,15 @@ import java.util.stream.Collectors;
@Service @Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) @RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPriceMapper, VehicleModelCalendarPrice> { public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPriceMapper, VehicleModelCalendarPrice> {
/**
* 一个星期的第一天
*/
private static final int START_OF_WEEK = 1; private static final int START_OF_WEEK = 1;
/**
* 一个星期的最后一天
*/
private static final int END_OF_WEEK = 7; private static final int END_OF_WEEK = 7;
/**
* 默认折扣
*/
private static final Integer DEFAULT_DISCOUNT = 100; private static final Integer DEFAULT_DISCOUNT = 100;
/**
* 默认免费天数
*/
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 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;
...@@ -80,7 +65,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -80,7 +65,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 = Date.from(LocalDate.parse(x.getDate()).atStartOfDay(ZoneId.systemDefault()).toInstant()); Date date = 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);
...@@ -166,10 +151,10 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -166,10 +151,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 = currentDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate().withDayOfMonth(1); LocalDate startLocalDate = dateToLocalDate(currentDate).withDayOfMonth(1);
Date startDate = Date.from(startLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); Date startDate = localDateToDate(startLocalDate);
LocalDate endLocalDate = startLocalDate.with(TemporalAdjusters.lastDayOfMonth()); 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.andBetween("vehicleModelDay", startDate, endDate);
criteria.andEqualTo("isDel", 0); criteria.andEqualTo("isDel", 0);
List<VehicleModelCalendarPrice> vehicleModelCalendarPriceList = mapper.selectByExample(example); List<VehicleModelCalendarPrice> vehicleModelCalendarPriceList = mapper.selectByExample(example);
...@@ -224,7 +209,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -224,7 +209,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 = 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); 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);
} }
...@@ -263,8 +248,8 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -263,8 +248,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 = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); LocalDate final_startLocalDate = dateToLocalDate(startDate);
LocalDate final_endLocalDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); LocalDate final_endLocalDate = 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();
//价格重置 //价格重置
...@@ -275,7 +260,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -275,7 +260,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 = Date.from(final_startLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); Date current_date = 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);
...@@ -285,10 +270,11 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -285,10 +270,11 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
switch (vehicleModelCalendarPrice.getType()) { switch (vehicleModelCalendarPrice.getType()) {
case VehicleModelPriceType.MULTIPLE: case VehicleModelPriceType.MULTIPLE:
no_discount_price = vehicle_price.multiply(new BigDecimal(vehicleModelCalendarPrice.getMultiple().doubleValue())); 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; break;
case VehicleModelPriceType.ABS: 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; break;
case VehicleModelPriceType.MEMBER: case VehicleModelPriceType.MEMBER:
memberLevel = vehicleModelCalendarPrice.getLevel() > memberLevel ? vehicleModelCalendarPrice.getLevel() : memberLevel; memberLevel = vehicleModelCalendarPrice.getLevel() > memberLevel ? vehicleModelCalendarPrice.getLevel() : memberLevel;
...@@ -306,9 +292,10 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -306,9 +292,10 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
if (price_freeDays_map != null && !price_freeDays_map.isEmpty()) { if (price_freeDays_map != null && !price_freeDays_map.isEmpty()) {
vehicle_price = (BigDecimal) price_freeDays_map.get(PRICE_VAL); vehicle_price = (BigDecimal) price_freeDays_map.get(PRICE_VAL);
free_days = (Integer) price_freeDays_map.get(DAYS_VAL); free_days = (Integer) price_freeDays_map.get(DAYS_VAL);
no_discount_price = (BigDecimal) price_freeDays_map.get(BASE_PRICE_VAL);
} }
vehicleModelCalendarPriceDTO.setNo_discount_price(no_discount_price); 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); vehicleModelCalendarPriceDTO.setFreeDays(free_days);
final_startLocalDate = final_startLocalDate.plusDays(1); final_startLocalDate = final_startLocalDate.plusDays(1);
vehicleModelCalendarPriceVos.add(vehicleModelCalendarPriceDTO); vehicleModelCalendarPriceVos.add(vehicleModelCalendarPriceDTO);
...@@ -317,7 +304,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -317,7 +304,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
} }
/** /**
* 节假日价格和免费天数 处理 * (节假日|非节假日未设置的)价格和免费天数 处理
* *
* @param festivalDayMap * @param festivalDayMap
* @param current_date * @param current_date
...@@ -326,17 +313,19 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -326,17 +313,19 @@ 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) {
Map<String, Object> vehicle_price_days_map = new HashMap<>(2); Map<String, Object> vehicle_price_days_map = new HashMap<>(3);
if (festivalDayMap != null && !festivalDayMap.isEmpty()) {
Integer free_days = DEFAULT_FREE_DAYS; Integer free_days = DEFAULT_FREE_DAYS;
vehicle_price_days_map.put(BASE_PRICE_VAL,vehicle_price);
if (festivalDayMap != null && !festivalDayMap.isEmpty()) {
VehicleModelHolidayPriceDTO vehicleModelHolidayPriceDTO = festivalDayMap.get(current_date); VehicleModelHolidayPriceDTO vehicleModelHolidayPriceDTO = festivalDayMap.get(current_date);
if (Objects.nonNull(vehicleModelHolidayPriceDTO)) { if (Objects.nonNull(vehicleModelHolidayPriceDTO)) {
vehicle_price = vehicle_price.multiply(new BigDecimal(vehicleModelHolidayPriceDTO.getMultiple().doubleValue() * (discount / 100.00))); vehicle_price = vehicle_price.multiply(new BigDecimal(vehicleModelHolidayPriceDTO.getMultiple().doubleValue()));
free_days = vehicleModelHolidayPriceDTO.getFreeDays() == null ? free_days : vehicleModelHolidayPriceDTO.getFreeDays(); free_days = vehicleModelHolidayPriceDTO.getFreeDays() == null ? free_days : vehicleModelHolidayPriceDTO.getFreeDays();
vehicle_price_days_map.put(PRICE_VAL, vehicle_price);
vehicle_price_days_map.put(DAYS_VAL, free_days);
} }
} }
vehicle_price = vehicle_price.multiply(new BigDecimal(discount / 100.00));
vehicle_price_days_map.put(PRICE_VAL, vehicle_price);
vehicle_price_days_map.put(DAYS_VAL, free_days);
return vehicle_price_days_map; return vehicle_price_days_map;
} }
...@@ -377,48 +366,59 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -377,48 +366,59 @@ 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 = Date.from(startLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); startDate = localDateToDate(startLocalDate);
endDate = Date.from(endLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); endDate = localDateToDate(endLocalDate);
} else { } else {
int days = 0;
/****************************************开始时间处理******************************************************/ /****************************************开始时间处理******************************************************/
LocalDate startLocalDate = LocalDate.from(startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate()); LocalDate startLocalDate = dateToLocalDate(startDate);
int start_dayOfMonth = startLocalDate.getDayOfMonth();
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) {
start_dayOfMonth = start_dayOfMonth - (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) {
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.minusDays(days);
LocalDate start_startLocalDate = startLocalDate.withDayOfMonth(start_dayOfMonth);
/****************************************结束时间处理******************************************************/ /****************************************结束时间处理******************************************************/
LocalDate endLocalDate = LocalDate.from(endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate()); days = 0;
int end_dayOfMonth = endLocalDate.getDayOfMonth(); LocalDate endLocalDate = dateToLocalDate(endDate);
int end_week = endLocalDate.getDayOfWeek().getValue(); 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) { 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 { } else {
if (START_OF_WEEK == end_week) { 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.plusDays(days);
LocalDate end_endLocalDate = endLocalDate.withDayOfMonth(end_dayOfMonth);
/****************************************时间转换******************************************************/ /****************************************时间转换******************************************************/
startDate = Date.from(start_startLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); startDate = localDateToDate(start_startLocalDate);
endDate = Date.from(end_endLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); endDate = 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> 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());
} }
/** /**
......
...@@ -2,15 +2,18 @@ package com.xxfc.platform.vehicle.biz; ...@@ -2,15 +2,18 @@ package com.xxfc.platform.vehicle.biz;
import com.github.wxiaoqi.security.common.biz.BaseBiz; import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.exception.BaseException; import com.github.wxiaoqi.security.common.exception.BaseException;
import com.xxfc.platform.vehicle.entity.Festival;
import com.xxfc.platform.vehicle.entity.VehicleModelHolidayPrice; import com.xxfc.platform.vehicle.entity.VehicleModelHolidayPrice;
import com.xxfc.platform.vehicle.mapper.VehicleModelHolidayPriceMapper; import com.xxfc.platform.vehicle.mapper.VehicleModelHolidayPriceMapper;
import com.xxfc.platform.vehicle.pojo.dto.VehicleModelHolidayPriceDTO; 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 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;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example;
...@@ -19,10 +22,8 @@ import java.time.Instant; ...@@ -19,10 +22,8 @@ import java.time.Instant;
import java.time.LocalDate; 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.ArrayList; import java.util.*;
import java.util.Date; import java.util.stream.Collectors;
import java.util.List;
import java.util.Objects;
/** /**
* @author libin * @author libin
...@@ -32,9 +33,10 @@ import java.util.Objects; ...@@ -32,9 +33,10 @@ import java.util.Objects;
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Service @Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPriceMapper, VehicleModelHolidayPrice> { public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPriceMapper, VehicleModelHolidayPrice> {
private final FestivalBiz festivalBiz;
/** /**
* 保存 * 保存
...@@ -43,23 +45,36 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric ...@@ -43,23 +45,36 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
* @param userId * @param userId
*/ */
public void addVehicleModelHolidayPrice(VehicleModelHolidayPriceSaveDTO vehicleModelHolidayPriceSaveDTO, Integer userId) { public void addVehicleModelHolidayPrice(VehicleModelHolidayPriceSaveDTO vehicleModelHolidayPriceSaveDTO, Integer userId) {
VehicleModelHolidayPrice vehicleModelHolidayPrice = new VehicleModelHolidayPrice(); List<VehicleModelHolidayPrice> vehicleModelHolidayPriceList = new ArrayList<>();
VehicleModelHolidayPrice vehicleModelHolidayPrice;
List<Date> dates = vehicleModelHolidayPriceSaveDTO.getDate();
for (Date date : dates) {
vehicleModelHolidayPrice = new VehicleModelHolidayPrice();
BeanUtils.copyProperties(vehicleModelHolidayPriceSaveDTO, vehicleModelHolidayPrice); BeanUtils.copyProperties(vehicleModelHolidayPriceSaveDTO, vehicleModelHolidayPrice);
vehicleModelHolidayPrice.setFestivalDay(Date.from(LocalDate.parse(vehicleModelHolidayPriceSaveDTO.getDate()).atStartOfDay(ZoneId.systemDefault()).toInstant())); date = Date.from(date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate().atStartOfDay(ZoneId.systemDefault()).toInstant());
vehicleModelHolidayPrice.setFestivalDay(date);
vehicleModelHolidayPriceList.add(vehicleModelHolidayPrice);
}
//编辑 //编辑
if (Objects.nonNull(vehicleModelHolidayPriceSaveDTO.getId())) { if (Objects.nonNull(vehicleModelHolidayPriceSaveDTO.getId())) {
vehicleModelHolidayPrice.setUpdTime(new Date()); Example example = new Example(VehicleModelHolidayPrice.class);
vehicleModelHolidayPrice.setUpdUserId(userId); Example.Criteria criteria = example.createCriteria();
int effect = mapper.updateByPrimaryKeySelective(vehicleModelHolidayPrice); criteria.andEqualTo("festivalId", vehicleModelHolidayPriceSaveDTO.getId());
if (effect < 1) { for (VehicleModelHolidayPrice modelHolidayPrice : vehicleModelHolidayPriceList) {
throw new BaseException("车型节假日设置失败"); modelHolidayPrice.setUpdUserId(userId);
modelHolidayPrice.setUpdTime(new Date());
mapper.updateByExample(modelHolidayPrice, example);
} }
} else { } else {
vehicleModelHolidayPrice.setCrtTime(new Date()); Festival festival = new Festival();
vehicleModelHolidayPrice.setCrtUserId(userId); festival.setName(vehicleModelHolidayPriceSaveDTO.getFestival());
int effect = mapper.insertSelective(vehicleModelHolidayPrice); festivalBiz.add(festival);
if (effect < 1) { for (VehicleModelHolidayPrice modelHolidayPrice : vehicleModelHolidayPriceList) {
throw new BaseException("车型节假日保存失败"); modelHolidayPrice.setCrtTime(new Date());
modelHolidayPrice.setCrtUserId(userId);
modelHolidayPrice.setFestivalId(festival.getId());
mapper.insertSelective(modelHolidayPrice);
} }
} }
} }
...@@ -75,7 +90,7 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric ...@@ -75,7 +90,7 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
vehicleModelHolidayPrice.setFreeDays(freeDays); vehicleModelHolidayPrice.setFreeDays(freeDays);
Example example = new Example(VehicleModelHolidayPrice.class); Example example = new Example(VehicleModelHolidayPrice.class);
Example.Criteria criteria = example.createCriteria(); Example.Criteria criteria = example.createCriteria();
setCondtionDate(configDate, criteria); setCondtionDate(configDate, null, criteria);
int effect = mapper.updateByExampleSelective(vehicleModelHolidayPrice, example); int effect = mapper.updateByExampleSelective(vehicleModelHolidayPrice, example);
if (effect < 1) { if (effect < 1) {
throw new BaseException("车型节假日更新失败"); throw new BaseException("车型节假日更新失败");
...@@ -92,7 +107,11 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric ...@@ -92,7 +107,11 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
List<VehicleModelHolidayPriceVo> vehicleModelHolidayPriceVos = new ArrayList<>(); List<VehicleModelHolidayPriceVo> vehicleModelHolidayPriceVos = new ArrayList<>();
Example example = new Example(VehicleModelHolidayPrice.class); Example example = new Example(VehicleModelHolidayPrice.class);
Example.Criteria criteria = example.createCriteria(); Example.Criteria criteria = example.createCriteria();
setCondtionDate(vehicleModelHolidayPriceFindDTO.getDate(), criteria); Date date = null;
if (StringUtils.isNotEmpty(vehicleModelHolidayPriceFindDTO.getDate()) && vehicleModelHolidayPriceFindDTO.getDate().trim().length() > 0) {
date = Date.from(LocalDate.parse(vehicleModelHolidayPriceFindDTO.getDate()).atStartOfDay(ZoneId.systemDefault()).toInstant());
}
setCondtionDate(date, vehicleModelHolidayPriceFindDTO.getYear(), criteria);
if (StringUtils.isNotEmpty(vehicleModelHolidayPriceFindDTO.getFestival()) && vehicleModelHolidayPriceFindDTO.getFestival().trim().length() > 0) { if (StringUtils.isNotEmpty(vehicleModelHolidayPriceFindDTO.getFestival()) && vehicleModelHolidayPriceFindDTO.getFestival().trim().length() > 0) {
criteria.andLike("festival", String.format("%%%s%%", vehicleModelHolidayPriceFindDTO.getFestival())); criteria.andLike("festival", String.format("%%%s%%", vehicleModelHolidayPriceFindDTO.getFestival()));
} }
...@@ -100,10 +119,13 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric ...@@ -100,10 +119,13 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
if (CollectionUtils.isEmpty(holidayPrices)) { if (CollectionUtils.isEmpty(holidayPrices)) {
return vehicleModelHolidayPriceVos; return vehicleModelHolidayPriceVos;
} }
List<Integer> festivalIds = holidayPrices.stream().map(VehicleModelHolidayPrice::getFestivalId).collect(Collectors.toList());
Map<Integer,Festival> festivalMap = festivalBiz.findFestivalsByIds(festivalIds);
VehicleModelHolidayPriceVo vehicleModelHolidayPriceVo; VehicleModelHolidayPriceVo vehicleModelHolidayPriceVo;
for (VehicleModelHolidayPrice holidayPrice : holidayPrices) { for (VehicleModelHolidayPrice holidayPrice : holidayPrices) {
vehicleModelHolidayPriceVo = new VehicleModelHolidayPriceVo(); vehicleModelHolidayPriceVo = new VehicleModelHolidayPriceVo();
BeanUtils.copyProperties(holidayPrice, vehicleModelHolidayPriceVo); BeanUtils.copyProperties(holidayPrice, vehicleModelHolidayPriceVo);
vehicleModelHolidayPriceVo.setFestival(festivalMap==null?"":festivalMap.get(holidayPrice.getFestivalId()).getName());
vehicleModelHolidayPriceVos.add(vehicleModelHolidayPriceVo); vehicleModelHolidayPriceVos.add(vehicleModelHolidayPriceVo);
} }
return vehicleModelHolidayPriceVos; return vehicleModelHolidayPriceVos;
...@@ -125,10 +147,13 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric ...@@ -125,10 +147,13 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
if (CollectionUtils.isEmpty(modelHolidayPrices)) { if (CollectionUtils.isEmpty(modelHolidayPrices)) {
return vehicleModelHolidayPriceDTOS; return vehicleModelHolidayPriceDTOS;
} }
List<Integer> festivalIds = modelHolidayPrices.stream().map(VehicleModelHolidayPrice::getFestivalId).collect(Collectors.toList());
Map<Integer,Festival> festivalMap = festivalBiz.findFestivalsByIds(festivalIds);
VehicleModelHolidayPriceDTO vehicleModelHolidayPriceDTO; VehicleModelHolidayPriceDTO vehicleModelHolidayPriceDTO;
for (VehicleModelHolidayPrice modelHolidayPrice : modelHolidayPrices) { for (VehicleModelHolidayPrice modelHolidayPrice : modelHolidayPrices) {
vehicleModelHolidayPriceDTO = new VehicleModelHolidayPriceDTO(); vehicleModelHolidayPriceDTO = new VehicleModelHolidayPriceDTO();
BeanUtils.copyProperties(modelHolidayPrice, vehicleModelHolidayPriceDTO); BeanUtils.copyProperties(modelHolidayPrice, vehicleModelHolidayPriceDTO);
vehicleModelHolidayPriceDTO.setFestival(festivalMap==null?"":festivalMap.get(modelHolidayPrice.getFestivalId()).getName());
vehicleModelHolidayPriceDTOS.add(vehicleModelHolidayPriceDTO); vehicleModelHolidayPriceDTOS.add(vehicleModelHolidayPriceDTO);
} }
return vehicleModelHolidayPriceDTOS; return vehicleModelHolidayPriceDTOS;
...@@ -138,14 +163,20 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric ...@@ -138,14 +163,20 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
* @param id * @param id
* @return * @return
*/ */
public VehicleModelHolidayPriceSaveDTO findVehicleModelHolidayPriceById(Long id) { public VehicleModelHolidayPriceSaveDTO findVehicleModelHolidayPriceFestivalId(Long id) {
VehicleModelHolidayPrice vehicleModelHolidayPrice = mapper.selectByPrimaryKey(id); VehicleModelHolidayPriceSaveDTO modelHolidayPriceSaveDTO = new VehicleModelHolidayPriceSaveDTO();
if (Objects.isNull(vehicleModelHolidayPrice)) { Example example = new Example(VehicleModelHolidayPrice.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("festivalId",id);
List<VehicleModelHolidayPrice> vehicleModelHolidayPrices = mapper.selectByExample(example);
if (CollectionUtils.isEmpty(vehicleModelHolidayPrices)) {
throw new BaseException("数据不存在"); throw new BaseException("数据不存在");
} }
VehicleModelHolidayPriceSaveDTO vehicleModelHolidayPriceSaveDTO = new VehicleModelHolidayPriceSaveDTO(); List<Date> dates = vehicleModelHolidayPrices.stream().map(VehicleModelHolidayPrice::getFestivalDay).collect(Collectors.toList());
BeanUtils.copyProperties(vehicleModelHolidayPrice, vehicleModelHolidayPriceSaveDTO); VehicleModelHolidayPrice vehicleModelHolidayPrice = vehicleModelHolidayPrices.get(0);
return vehicleModelHolidayPriceSaveDTO; BeanUtils.copyProperties(vehicleModelHolidayPrice, modelHolidayPriceSaveDTO);
modelHolidayPriceSaveDTO.setDate(dates);
return modelHolidayPriceSaveDTO;
} }
/** /**
...@@ -154,15 +185,24 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric ...@@ -154,15 +185,24 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
* @param conditionDate * @param conditionDate
* @param criteria * @param criteria
*/ */
private void setCondtionDate(Date conditionDate, Example.Criteria criteria) { private void setCondtionDate(Date conditionDate, Integer year, Example.Criteria criteria) {
LocalDate localDate = LocalDate.from(conditionDate.toInstant());
//开始日期 //开始日期
Instant startInstant = localDate.withDayOfMonth(1).atStartOfDay(ZoneId.systemDefault()).toInstant(); Instant startInstant = null;
//结束日期 //结束日期
Instant endInstant = null;
if (Objects.nonNull(year) && Objects.isNull(conditionDate)) {
startInstant = LocalDate.of(year, 1, 1).atStartOfDay(ZoneId.systemDefault()).toInstant();
endInstant = LocalDate.of(year, 12, 31).atStartOfDay(ZoneId.systemDefault()).toInstant();
}
if (Objects.nonNull(conditionDate)) {
LocalDate localDate = conditionDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
startInstant = localDate.withDayOfMonth(1).atStartOfDay(ZoneId.systemDefault()).toInstant();
LocalDate endLocalDate = localDate.with(TemporalAdjusters.lastDayOfMonth()); LocalDate endLocalDate = localDate.with(TemporalAdjusters.lastDayOfMonth());
Instant endInstant = endLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant(); endInstant = endLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant();
}
if (Objects.nonNull(startInstant) && Objects.nonNull(endInstant)) {
criteria.andBetween("festivalDay", Date.from(startInstant), Date.from(endInstant)); criteria.andBetween("festivalDay", Date.from(startInstant), Date.from(endInstant));
} }
}
} }
package com.xxfc.platform.vehicle.mapper;
import com.xxfc.platform.vehicle.entity.Festival;
import tk.mybatis.mapper.additional.idlist.SelectByIdListMapper;
import tk.mybatis.mapper.common.Mapper;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/10/18 17:33
*/
public interface FestivalMapper extends Mapper<Festival>, SelectByIdListMapper<Festival,Integer> {
}
package com.xxfc.platform.vehicle.mapper; package com.xxfc.platform.vehicle.mapper;
import com.xxfc.platform.vehicle.entity.VehicleModelHolidayPrice; import com.xxfc.platform.vehicle.entity.VehicleModelHolidayPrice;
import tk.mybatis.mapper.additional.insert.InsertListMapper;
import tk.mybatis.mapper.common.Mapper; import tk.mybatis.mapper.common.Mapper;
/** /**
...@@ -9,5 +10,5 @@ import tk.mybatis.mapper.common.Mapper; ...@@ -9,5 +10,5 @@ import tk.mybatis.mapper.common.Mapper;
* @description * @description
* @data 2019/10/14 17:32 * @data 2019/10/14 17:32
*/ */
public interface VehicleModelHolidayPriceMapper extends Mapper<VehicleModelHolidayPrice> { public interface VehicleModelHolidayPriceMapper extends Mapper<VehicleModelHolidayPrice>, InsertListMapper<VehicleModelHolidayPrice> {
} }
...@@ -11,14 +11,11 @@ import io.swagger.annotations.ApiOperation; ...@@ -11,14 +11,11 @@ import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
......
...@@ -36,7 +36,7 @@ public class VehicleModelHolidayPriceAdminController { ...@@ -36,7 +36,7 @@ public class VehicleModelHolidayPriceAdminController {
@GetMapping("/{id}") @GetMapping("/{id}")
public ObjectRestResponse<VehicleModelHolidayPriceSaveDTO> findVehicleModelHolidayPrice(@PathVariable(value = "id") Long id){ public ObjectRestResponse<VehicleModelHolidayPriceSaveDTO> findVehicleModelHolidayPrice(@PathVariable(value = "id") Long id){
VehicleModelHolidayPriceSaveDTO vehicleModelHolidayPriceSaveDTO = vehicleModelHolidayPriceBiz.findVehicleModelHolidayPriceById(id); VehicleModelHolidayPriceSaveDTO vehicleModelHolidayPriceSaveDTO = vehicleModelHolidayPriceBiz.findVehicleModelHolidayPriceFestivalId(id);
return ObjectRestResponse.succ(vehicleModelHolidayPriceSaveDTO); return ObjectRestResponse.succ(vehicleModelHolidayPriceSaveDTO);
} }
......
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