Commit afb68825 authored by 周健威's avatar 周健威

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

parents 5d37e499 c614865b
......@@ -24,6 +24,7 @@ public class VehicleModelCalendarPriceDTO implements Serializable {
private Date date;
private BigDecimal price;
private BigDecimal no_discount_price;
private Integer freeDays;
private Boolean isSelect;
}
package com.xxfc.platform.vehicle.pojo.dto;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
......@@ -25,7 +26,10 @@ public class VehicleModelCalendarPriceSaveDTO implements Serializable {
/**
* 日期设置
*/
@JSONField(serialize = false)
private Date vehicleModelDay;
private String date;
/**
* 是否全局设置
*/
......
......@@ -6,7 +6,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* @author libin
......@@ -24,7 +24,7 @@ public class VehicleModelHolidayPriceSaveDTO implements Serializable {
/**
* 节假日日期
*/
private Date festivalDay;
private String date;
/**
* 节假日
*/
......
......@@ -29,4 +29,8 @@ public class VehicleModelDayPriceVo extends VehicleModelDTO implements Serializa
* 倍数
*/
private Double multiple;
/**
* 会员等级
*/
private Integer level;
}
......@@ -80,9 +80,14 @@ 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());
calendarPrice.setVehicleModelDay(date);
calendarPrice.setCrtTime(new Date());
calendarPrice.setCrtUserId(userId);
calendarPrice.setIsDel(0);
x.setVehicleModelDay(date);
vehicleModelCalendarPriceList.add(calendarPrice);
}).map(VehicleModelCalendarPriceSaveDTO::getVehicleModelDay).distinct().collect(Collectors.toList());
//1.删除当月做更改了的日期的数据
......@@ -93,7 +98,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
Example example = new Example(VehicleModelCalendarPrice.class);
Example.Criteria criteria = example.createCriteria();
criteria.andIn("vehicleModelDay", dateList);
mapper.updateByExample(vehicleModelCalendarPrice, example);
mapper.updateByExampleSelective(vehicleModelCalendarPrice, example);
//2.插入新的数据
mapper.insertList(vehicleModelCalendarPriceList);
}
......@@ -144,6 +149,8 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
vehicleModelDayPriceVo.setMultiple(multiple);
BigDecimal aPrice = isNullOfVehicleModelPrice ? null : vehicleModelCalendarPriceMap.get(vehicleModelDTO.getVehicleModelId()).getPrice();
vehicleModelDayPriceVo.setPrice(aPrice);
Integer level = isNullOfVehicleModelPrice?null:vehicleModelCalendarPriceMap.get(vehicleModelDTO.getVehicleModelId()).getLevel();
vehicleModelDayPriceVo.setLevel(level);
vehicleModelDayPriceVos.add(vehicleModelDayPriceVo);
}
return vehicleModelDayPriceVos;
......@@ -174,8 +181,13 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
for (VehicleModelCalendarPrice calendarPrice : vehicleModelCalendarPriceList) {
vehicleModelCalendarPrice = new VehicleModelCalendarPriceSaveDTO();
BeanUtils.copyProperties(calendarPrice, vehicleModelCalendarPrice);
vehicleModelCalendarPrice.setVehicleModelId(null);
vehicleModelCalendarPriceSaveDTOS.add(vehicleModelCalendarPrice);
}
Map<Date, Optional<VehicleModelCalendarPriceSaveDTO>> result = vehicleModelCalendarPriceSaveDTOS.stream()
.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());
return vehicleModelCalendarPriceSaveDTOS;
}
......@@ -257,6 +269,8 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
vehicleModelCalendarPriceDTO = new VehicleModelCalendarPriceDTO();
//价格重置
vehicle_price = vehicle_base_price;
//未乘以会员折扣的价格
BigDecimal no_discount_price = new BigDecimal(vehicle_price.doubleValue());
//免费天数重置
Integer free_days = DEFAULT_FREE_DAYS;
//节假日对应的价格和免费天数
......@@ -270,7 +284,8 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
} else {
switch (vehicleModelCalendarPrice.getType()) {
case VehicleModelPriceType.MULTIPLE:
vehicle_price = vehicle_price.multiply(new BigDecimal(vehicleModelCalendarPrice.getMultiple().doubleValue() * (discount / 100.00)));
no_discount_price = vehicle_price.multiply(new BigDecimal(vehicleModelCalendarPrice.getMultiple().doubleValue()));
vehicle_price = no_discount_price.multiply(new BigDecimal(discount / 100.0));
break;
case VehicleModelPriceType.ABS:
vehicle_price = vehicleModelCalendarPrice.getPrice().multiply(new BigDecimal(discount / 100.00));
......@@ -292,6 +307,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
vehicle_price = (BigDecimal) price_freeDays_map.get(PRICE_VAL);
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.setFreeDays(free_days);
final_startLocalDate = final_startLocalDate.plusDays(1);
......
......@@ -34,6 +34,8 @@ import java.util.Objects;
@Service
public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPriceMapper, VehicleModelHolidayPrice> {
/**
* 保存
*
......@@ -43,6 +45,7 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
public void addVehicleModelHolidayPrice(VehicleModelHolidayPriceSaveDTO vehicleModelHolidayPriceSaveDTO, Integer userId) {
VehicleModelHolidayPrice vehicleModelHolidayPrice = new VehicleModelHolidayPrice();
BeanUtils.copyProperties(vehicleModelHolidayPriceSaveDTO, vehicleModelHolidayPrice);
vehicleModelHolidayPrice.setFestivalDay(Date.from(LocalDate.parse(vehicleModelHolidayPriceSaveDTO.getDate()).atStartOfDay(ZoneId.systemDefault()).toInstant()));
//编辑
if (Objects.nonNull(vehicleModelHolidayPriceSaveDTO.getId())) {
vehicleModelHolidayPrice.setUpdTime(new Date());
......@@ -62,20 +65,19 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
}
/**
*
* @param multiple 倍数
* @param freeDays 免费天数
* @param multiple 倍数
* @param freeDays 免费天数
* @param configDate 设置的日期*月份
*/
public void updateVehicleModelHolidayPrice(Double multiple,Integer freeDays,Date configDate){
public void updateVehicleModelHolidayPrice(Double multiple, Integer freeDays, Date configDate) {
VehicleModelHolidayPrice vehicleModelHolidayPrice = new VehicleModelHolidayPrice();
vehicleModelHolidayPrice.setMultiple(multiple);
vehicleModelHolidayPrice.setFreeDays(freeDays);
Example example = new Example(VehicleModelHolidayPrice.class);
Example.Criteria criteria = example.createCriteria();
setCondtionDate(configDate,criteria);
int effect = mapper.updateByExampleSelective(vehicleModelHolidayPrice,example);
if (effect<1){
setCondtionDate(configDate, criteria);
int effect = mapper.updateByExampleSelective(vehicleModelHolidayPrice, example);
if (effect < 1) {
throw new BaseException("车型节假日更新失败");
}
}
......@@ -90,7 +92,7 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
List<VehicleModelHolidayPriceVo> vehicleModelHolidayPriceVos = new ArrayList<>();
Example example = new Example(VehicleModelHolidayPrice.class);
Example.Criteria criteria = example.createCriteria();
setCondtionDate(vehicleModelHolidayPriceFindDTO.getDate(),criteria);
setCondtionDate(vehicleModelHolidayPriceFindDTO.getDate(), criteria);
if (StringUtils.isNotEmpty(vehicleModelHolidayPriceFindDTO.getFestival()) && vehicleModelHolidayPriceFindDTO.getFestival().trim().length() > 0) {
criteria.andLike("festival", String.format("%%%s%%", vehicleModelHolidayPriceFindDTO.getFestival()));
}
......@@ -148,10 +150,11 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
/**
* 设置查询条件日期
*
* @param conditionDate
* @param criteria
*/
private void setCondtionDate(Date conditionDate, Example.Criteria criteria){
private void setCondtionDate(Date conditionDate, Example.Criteria criteria) {
LocalDate localDate = LocalDate.from(conditionDate.toInstant());
//开始日期
Instant startInstant = localDate.withDayOfMonth(1).atStartOfDay(ZoneId.systemDefault()).toInstant();
......
......@@ -11,6 +11,8 @@ import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
......@@ -34,16 +36,18 @@ public class VehicleModelCalendarPriceAdminController {
return ObjectRestResponse.succ();
}
@ApiOperation("车型日历月份价格")
@ApiOperation("车型日历价格")
@GetMapping("/day")
public ObjectRestResponse<VehicleModelDayPriceVo> listVehicleModelCalendarPriceWithMonth(@RequestParam(value = "date") Date date){
public ObjectRestResponse<VehicleModelDayPriceVo> listVehicleModelCalendarPriceWithMonth(@RequestParam(value = "date") String dateStr){
Date date = Date.from(LocalDate.parse(dateStr).atStartOfDay(ZoneId.systemDefault()).toInstant());
List<VehicleModelDayPriceVo> vehicleModelDayPriceVos = vehicleModelCalendarPriceBiz.findVehicleModelcalendarPriceByDateWithDay(date);
return ObjectRestResponse.succ(vehicleModelDayPriceVos);
}
@ApiOperation("根据日查询不同车型的设置")
@ApiOperation("根据月份查询的设置")
@GetMapping("/month")
public ObjectRestResponse<List<VehicleModelCalendarPriceSaveDTO>> listVehicleModelCalendarPriceWithDay(@RequestParam(value = "date") Date date){
public ObjectRestResponse<List<VehicleModelCalendarPriceSaveDTO>> listVehicleModelCalendarPriceWithDay(@RequestParam(value = "date") String dateStr){
Date date = Date.from(LocalDate.parse(dateStr).atStartOfDay(ZoneId.systemDefault()).toInstant());
List<VehicleModelCalendarPriceSaveDTO> calendarPrices = vehicleModelCalendarPriceBiz.findVehicleModelCalendarPricesByDateWithMonth(date);
return ObjectRestResponse.succ(calendarPrices);
}
......
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