Commit 8abcf35c authored by libin's avatar libin

Merge branch 'holiday-price' into base-modify

parents 042b8003 6d78d0f3
...@@ -20,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -20,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
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;
...@@ -46,6 +47,21 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -46,6 +47,21 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
* 一个星期的最后一天 * 一个星期的最后一天
*/ */
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_FREE_DAYS = 1;
/**
* 默认会员等级
*/
private static final Integer DEFAULT_MEMBER_LEVEL = 0;
private static final String PRICE_VAL = "price";
private static final String DAYS_VAL = "freeDays";
private final VehicleModelHolidayPriceBiz vehicleModelHolidayPriceBiz; private final VehicleModelHolidayPriceBiz vehicleModelHolidayPriceBiz;
private final VehicleModelBiz vehicleModelBiz; private final VehicleModelBiz vehicleModelBiz;
...@@ -198,11 +214,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -198,11 +214,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
for (VehicleModelCalendarPriceDTO vehicleModelCalendarPriceDTO : vehicleModelCalendarPrice) { for (VehicleModelCalendarPriceDTO vehicleModelCalendarPriceDTO : vehicleModelCalendarPrice) {
LocalDate current_date = vehicleModelCalendarPriceDTO.getDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); LocalDate current_date = vehicleModelCalendarPriceDTO.getDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
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);
if (isSelect) { vehicleModelCalendarPriceDTO.setIsSelect(isSelect ? true : false);
vehicleModelCalendarPriceDTO.setIsSelect(true);
} else {
vehicleModelCalendarPriceDTO.setIsSelect(false);
}
} }
return vehicleModelCalendarPrice; return vehicleModelCalendarPrice;
} }
...@@ -218,11 +230,9 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -218,11 +230,9 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
public List<VehicleModelCalendarPriceDTO> findVehicleModelCalendarPrice(Date startDate, Date endDate, Integer vehicleModelId, Integer userId) { public List<VehicleModelCalendarPriceDTO> findVehicleModelCalendarPrice(Date startDate, Date endDate, Integer vehicleModelId, Integer userId) {
List<VehicleModelCalendarPriceDTO> vehicleModelCalendarPriceVos = new ArrayList<>(); List<VehicleModelCalendarPriceDTO> vehicleModelCalendarPriceVos = new ArrayList<>();
//默认折扣 //默认折扣
Integer discount = 100; Integer discount = DEFAULT_DISCOUNT;
//默认免费天数
int free_days = 1;
//会员默认等级 //会员默认等级
Integer memberLevel = 0; Integer memberLevel = DEFAULT_MEMBER_LEVEL;
//日历价格转map //日历价格转map
List<VehicleModelCalendarPrice> vehicleModelCalendarPrices = getVehicleModelCalendarPricesByVehicleModelIdAndDate(vehicleModelId, startDate, endDate); List<VehicleModelCalendarPrice> vehicleModelCalendarPrices = getVehicleModelCalendarPricesByVehicleModelIdAndDate(vehicleModelId, startDate, endDate);
Map<Date, VehicleModelCalendarPrice> calendarPriceMap = vehicleModelCalendarPrices.stream().collect(Collectors.toMap(VehicleModelCalendarPrice::getVehicleModelDay, Function.identity())); Map<Date, VehicleModelCalendarPrice> calendarPriceMap = vehicleModelCalendarPrices.stream().collect(Collectors.toMap(VehicleModelCalendarPrice::getVehicleModelDay, Function.identity()));
...@@ -232,7 +242,9 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -232,7 +242,9 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
Map<Integer, Integer> levelAndDiscountMap = userFeign.levels().stream().collect(Collectors.toMap(BaseUserMemberLevel::getLevel, BaseUserMemberLevel::getDiscount)); Map<Integer, Integer> levelAndDiscountMap = userFeign.levels().stream().collect(Collectors.toMap(BaseUserMemberLevel::getLevel, BaseUserMemberLevel::getDiscount));
//车型的原价 //车型的原价
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);
if (Objects.nonNull(userId)) { if (Objects.nonNull(userId)) {
BaseUserMember baseUserMember = userFeign.findBaseUserMemberByUserId(userId); BaseUserMember baseUserMember = userFeign.findBaseUserMemberByUserId(userId);
discount = baseUserMember == null ? discount : baseUserMember.getDiscount(); discount = baseUserMember == null ? discount : baseUserMember.getDiscount();
...@@ -243,38 +255,44 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -243,38 +255,44 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
LocalDate final_endLocalDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); LocalDate final_endLocalDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
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();
//价格重置
vehicle_price = vehicle_base_price;
//免费天数重置
Integer free_days = DEFAULT_FREE_DAYS;
//节假日对应的价格和免费天数
Map<String, Object> price_freeDays_map = null;
Date current_date = Date.from(final_startLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); Date current_date = Date.from(final_startLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
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);
if (Objects.isNull(vehicleModelCalendarPrice)) { if (Objects.isNull(vehicleModelCalendarPrice)) {
if (festivalDayMap != null && !festivalDayMap.isEmpty()) { price_freeDays_map = transfromPriceAndFreeDaysByDate(festivalDayMap, current_date, vehicle_base_price, discount);
VehicleModelHolidayPriceDTO vehicleModelHolidayPriceDTO = festivalDayMap.get(current_date);
if (Objects.nonNull(vehicleModelHolidayPriceDTO)) {
vehicle_price = vehicle_price.multiply(new BigDecimal(vehicleModelHolidayPriceDTO.getMultiple().doubleValue() * (discount / 100)));
free_days = vehicleModelHolidayPriceDTO.getFreeDays();
}
}
} else { } else {
switch (vehicleModelCalendarPrice.getType()) { switch (vehicleModelCalendarPrice.getType()) {
case VehicleModelPriceType.MULTIPLE: case VehicleModelPriceType.MULTIPLE:
vehicle_price = vehicle_price.multiply(new BigDecimal(vehicleModelCalendarPrice.getMultiple().doubleValue() * (discount / 100))); vehicle_price = vehicle_price.multiply(new BigDecimal(vehicleModelCalendarPrice.getMultiple().doubleValue() * (discount / 100.00)));
break; break;
case VehicleModelPriceType.ABS: case VehicleModelPriceType.ABS:
vehicle_price = vehicleModelCalendarPrice.getPrice().multiply(new BigDecimal(discount / 100)); vehicle_price = vehicleModelCalendarPrice.getPrice().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;
Integer level_discount = levelAndDiscountMap.get(memberLevel); Integer level_discount = levelAndDiscountMap.get(memberLevel);
vehicle_price = level_discount == null ? vehicleModelCalendarPrice.getPrice() : vehicleModelCalendarPrice.getPrice().multiply(new BigDecimal(level_discount / 100)); vehicle_price = level_discount == null ? vehicle_price : vehicle_price.multiply(new BigDecimal(level_discount / 100.00));
break; break;
default: default:
break; break;
} }
free_days = vehicleModelCalendarPrice.getFreeDays(); free_days = vehicleModelCalendarPrice.getFreeDays() == null ? free_days : vehicleModelCalendarPrice.getFreeDays();
}
} else {
price_freeDays_map = transfromPriceAndFreeDaysByDate(festivalDayMap, current_date, vehicle_base_price, discount);
} }
if (price_freeDays_map != null && !price_freeDays_map.isEmpty()) {
vehicle_price = (BigDecimal) price_freeDays_map.get(PRICE_VAL);
free_days = (Integer) price_freeDays_map.get(DAYS_VAL);
} }
vehicleModelCalendarPriceDTO.setPrice(vehicle_price); vehicleModelCalendarPriceDTO.setPrice(vehicle_price.setScale(2, RoundingMode.DOWN));
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);
...@@ -282,6 +300,30 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -282,6 +300,30 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
return vehicleModelCalendarPriceVos; return vehicleModelCalendarPriceVos;
} }
/**
* 节假日价格和免费天数 处理
*
* @param festivalDayMap
* @param current_date
* @param vehicle_price
* @param discount
* @return
*/
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);
if (festivalDayMap != null && !festivalDayMap.isEmpty()) {
Integer free_days = DEFAULT_FREE_DAYS;
VehicleModelHolidayPriceDTO vehicleModelHolidayPriceDTO = festivalDayMap.get(current_date);
if (Objects.nonNull(vehicleModelHolidayPriceDTO)) {
vehicle_price = vehicle_price.multiply(new BigDecimal(vehicleModelHolidayPriceDTO.getMultiple().doubleValue() * (discount / 100.00)));
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);
}
}
return vehicle_price_days_map;
}
/** /**
* 根据时间范围查询 * 根据时间范围查询
* *
...@@ -292,11 +334,16 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -292,11 +334,16 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
*/ */
private List<VehicleModelCalendarPrice> getVehicleModelCalendarPricesByVehicleModelIdAndDate(Integer vehicleModelId, Date final_startDate, Date final_endDate) { private List<VehicleModelCalendarPrice> getVehicleModelCalendarPricesByVehicleModelIdAndDate(Integer vehicleModelId, Date final_startDate, Date final_endDate) {
Example example = new Example(VehicleModelCalendarPrice.class); Example example = new Example(VehicleModelCalendarPrice.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("isDel", 0); Example.Criteria base_criteria = example.createCriteria();
criteria.andEqualTo("vehicleModelId", vehicleModelId); base_criteria.andEqualTo("isDel", 0);
criteria.orIsNull("vehicleModelId"); base_criteria.andBetween("vehicleModelDay", final_startDate, final_endDate);
criteria.andBetween("vehicleModelDay", final_startDate, final_endDate);
Example.Criteria vehicle_criteria = example.createCriteria();
vehicle_criteria.andEqualTo("vehicleModelId", vehicleModelId);
vehicle_criteria.orIsNull("vehicleModelId");
example.and(vehicle_criteria);
List<VehicleModelCalendarPrice> vehicleModelCalendarPrices = mapper.selectByExample(example); List<VehicleModelCalendarPrice> vehicleModelCalendarPrices = mapper.selectByExample(example);
return CollectionUtils.isEmpty(vehicleModelCalendarPrices) ? Collections.EMPTY_LIST : vehicleModelCalendarPrices; return CollectionUtils.isEmpty(vehicleModelCalendarPrices) ? Collections.EMPTY_LIST : vehicleModelCalendarPrices;
} }
...@@ -327,8 +374,6 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -327,8 +374,6 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
} else { } else {
if (END_OF_WEEK == start_week) { if (END_OF_WEEK == start_week) {
start_dayOfMonth = start_dayOfMonth - END_OF_WEEK + 1; start_dayOfMonth = start_dayOfMonth - END_OF_WEEK + 1;
} else {
start_dayOfMonth = START_OF_WEEK;
} }
} }
start_dayOfMonth = start_dayOfMonth > 0 ? start_dayOfMonth : 1; start_dayOfMonth = start_dayOfMonth > 0 ? start_dayOfMonth : 1;
...@@ -357,6 +402,8 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -357,6 +402,8 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
endDatee.set(endDate); endDatee.set(endDate);
} }
public static void main(String[] args) {
}
/** /**
* 车型日历价格设置类型 * 车型日历价格设置类型
...@@ -365,14 +412,14 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr ...@@ -365,14 +412,14 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
/** /**
* 倍数 * 倍数
*/ */
private static final int MULTIPLE = 0; private static final int MULTIPLE = 1;
/** /**
* 绝对值 * 绝对值
*/ */
private static final int ABS = 1; private static final int ABS = 2;
/** /**
* 会员价 * 会员价
*/ */
private static final int MEMBER = 2; private static final int MEMBER = 3;
} }
} }
package com.xxfc.platform.vehicle.rest; package com.xxfc.platform.vehicle.rest;
import com.github.wxiaoqi.security.admin.feign.dto.AppUserDTO; import com.github.wxiaoqi.security.admin.feign.dto.AppUserDTO;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.xxfc.platform.vehicle.biz.VehicleModelCalendarPriceBiz; import com.xxfc.platform.vehicle.biz.VehicleModelCalendarPriceBiz;
import com.xxfc.platform.vehicle.pojo.dto.VehicleModelCalendarPriceDTO; import com.xxfc.platform.vehicle.pojo.dto.VehicleModelCalendarPriceDTO;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
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.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -20,20 +29,27 @@ import java.util.List; ...@@ -20,20 +29,27 @@ import java.util.List;
* @data 2019/10/14 17:35 * @data 2019/10/14 17:35
*/ */
@RestController @RestController
@RequestMapping("/vehicle_model/calendar_price") @RequestMapping("/vehicle_model/calendar_price/app/unauth")
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) @RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "车型日历价格") @Api(tags = "车型日历价格")
public class VehicleModelCalendarPriceController { public class VehicleModelCalendarPriceController{
private final VehicleModelCalendarPriceBiz vehicleModelCalendarPriceBiz; private final VehicleModelCalendarPriceBiz vehicleModelCalendarPriceBiz;
@ApiOperation("返回车型日历价格") @ApiOperation("返回车型日历价格")
@GetMapping("/list/vehicle_model/calendar_price/{vehicleModelId}/{type}") @GetMapping("/list/{vehicleModelId}")
public ObjectRestResponse<VehicleModelCalendarPriceDTO> listVehicleModelCalendarPriceByDateAndVehicleModelId(@RequestParam(value = "start",required = false) Date startDate, @IgnoreUserToken
@RequestParam(value = "end",required = false) Date endDate, @SneakyThrows
public ObjectRestResponse<VehicleModelCalendarPriceDTO> listVehicleModelCalendarPriceByDateAndVehicleModelId(@RequestParam(value = "start",required = false) String start,
@RequestParam(value = "end",required = false) String end,
@PathVariable(value = "vehicleModelId") Integer vehicleModelId, @PathVariable(value = "vehicleModelId") Integer vehicleModelId,
AppUserDTO appUserDTO){ AppUserDTO appUserDTO){
if (StringUtils.isEmpty(start) || StringUtils.isEmpty(end)){
throw new BaseException("缺少开始时间或结束时间");
}
Date startDate= Date.from(LocalDate.parse(start).atStartOfDay(ZoneId.systemDefault()).toInstant());
Date endDate= Date.from(LocalDate.parse(end).atStartOfDay(ZoneId.systemDefault()).toInstant());
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