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 {
@GetMapping("/member/user")
BaseUserMember findBaseUserMemberByUserId(@RequestParam(value = "userId") Integer userId);
}
package com.github.wxiaoqi.security.admin.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 用户信息表
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
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 {
/**
* 节假日
*/
private String festival;
@Column(name = "festival_id")
private Integer festivalId;
/**
* 倍数
*/
......
......@@ -20,5 +20,6 @@ import java.util.Date;
@NoArgsConstructor
public class VehicleModelHolidayPriceFindDTO extends PageParam {
private String festival;
private Date date;
private String date;
private Integer year;
}
......@@ -6,6 +6,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
......@@ -20,13 +21,16 @@ import java.util.List;
@NoArgsConstructor
public class VehicleModelHolidayPriceSaveDTO implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
/**
* 节假日id
*/
private Integer id;
/**
* 节假日日期
*/
private String date;
private List<Date> date;
/**
* 节假日
* 节假日名称
*/
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;
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPriceMapper, VehicleModelCalendarPrice> {
/**
* 一个星期的第一天
*/
private static final int START_OF_WEEK = 1;
/**
* 一个星期的最后一天
*/
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 BASE_PRICE_VAL="basePrice";
private static final String DAYS_VAL = "freeDays";
private final VehicleModelHolidayPriceBiz vehicleModelHolidayPriceBiz;
private final VehicleModelBiz vehicleModelBiz;
private final UserFeign userFeign;
......@@ -80,7 +65,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 +151,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 +209,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);
}
......@@ -263,8 +248,8 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
memberLevel = baseUserMember == null ? memberLevel : baseUserMember.getMemberLevel();
}
VehicleModelCalendarPriceDTO vehicleModelCalendarPriceDTO;
LocalDate final_startLocalDate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate final_endLocalDate = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate final_startLocalDate = dateToLocalDate(startDate);
LocalDate final_endLocalDate = dateToLocalDate(endDate);
while (final_startLocalDate.isBefore(final_endLocalDate) || final_startLocalDate.isEqual(final_endLocalDate)) {
vehicleModelCalendarPriceDTO = new VehicleModelCalendarPriceDTO();
//价格重置
......@@ -275,7 +260,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
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 = localDateToDate(final_startLocalDate);
vehicleModelCalendarPriceDTO.setDate(current_date);
if (calendarPriceMap != null && !calendarPriceMap.isEmpty()) {
VehicleModelCalendarPrice vehicleModelCalendarPrice = calendarPriceMap.get(current_date);
......@@ -285,10 +270,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;
......@@ -306,9 +292,10 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
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);
no_discount_price = (BigDecimal) price_freeDays_map.get(BASE_PRICE_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);
......@@ -317,7 +304,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
}
/**
* 节假日价格和免费天数 处理
* (节假日|非节假日未设置的)价格和免费天数 处理
*
* @param festivalDayMap
* @param current_date
......@@ -326,17 +313,19 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
* @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);
Map<String, Object> vehicle_price_days_map = new HashMap<>(3);
Integer free_days = DEFAULT_FREE_DAYS;
vehicle_price_days_map.put(BASE_PRICE_VAL,vehicle_price);
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)));
vehicle_price = vehicle_price.multiply(new BigDecimal(vehicleModelHolidayPriceDTO.getMultiple().doubleValue()));
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;
}
......@@ -377,48 +366,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());
}
/**
......
......@@ -2,15 +2,18 @@ package com.xxfc.platform.vehicle.biz;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
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.mapper.VehicleModelHolidayPriceMapper;
import com.xxfc.platform.vehicle.pojo.dto.VehicleModelHolidayPriceDTO;
import com.xxfc.platform.vehicle.pojo.dto.VehicleModelHolidayPriceFindDTO;
import com.xxfc.platform.vehicle.pojo.dto.VehicleModelHolidayPriceSaveDTO;
import com.xxfc.platform.vehicle.pojo.vo.VehicleModelHolidayPriceVo;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
......@@ -19,10 +22,8 @@ import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author libin
......@@ -32,9 +33,10 @@ import java.util.Objects;
*/
@Transactional(rollbackFor = Exception.class)
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPriceMapper, VehicleModelHolidayPrice> {
private final FestivalBiz festivalBiz;
/**
* 保存
......@@ -43,23 +45,36 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
* @param userId
*/
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()));
List<VehicleModelHolidayPrice> vehicleModelHolidayPriceList = new ArrayList<>();
VehicleModelHolidayPrice vehicleModelHolidayPrice;
List<Date> dates = vehicleModelHolidayPriceSaveDTO.getDate();
for (Date date : dates) {
vehicleModelHolidayPrice = new VehicleModelHolidayPrice();
BeanUtils.copyProperties(vehicleModelHolidayPriceSaveDTO, vehicleModelHolidayPrice);
date = Date.from(date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate().atStartOfDay(ZoneId.systemDefault()).toInstant());
vehicleModelHolidayPrice.setFestivalDay(date);
vehicleModelHolidayPriceList.add(vehicleModelHolidayPrice);
}
//编辑
if (Objects.nonNull(vehicleModelHolidayPriceSaveDTO.getId())) {
vehicleModelHolidayPrice.setUpdTime(new Date());
vehicleModelHolidayPrice.setUpdUserId(userId);
int effect = mapper.updateByPrimaryKeySelective(vehicleModelHolidayPrice);
if (effect < 1) {
throw new BaseException("车型节假日设置失败");
Example example = new Example(VehicleModelHolidayPrice.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("festivalId", vehicleModelHolidayPriceSaveDTO.getId());
for (VehicleModelHolidayPrice modelHolidayPrice : vehicleModelHolidayPriceList) {
modelHolidayPrice.setUpdUserId(userId);
modelHolidayPrice.setUpdTime(new Date());
mapper.updateByExample(modelHolidayPrice, example);
}
} else {
vehicleModelHolidayPrice.setCrtTime(new Date());
vehicleModelHolidayPrice.setCrtUserId(userId);
int effect = mapper.insertSelective(vehicleModelHolidayPrice);
if (effect < 1) {
throw new BaseException("车型节假日保存失败");
Festival festival = new Festival();
festival.setName(vehicleModelHolidayPriceSaveDTO.getFestival());
festivalBiz.add(festival);
for (VehicleModelHolidayPrice modelHolidayPrice : vehicleModelHolidayPriceList) {
modelHolidayPrice.setCrtTime(new Date());
modelHolidayPrice.setCrtUserId(userId);
modelHolidayPrice.setFestivalId(festival.getId());
mapper.insertSelective(modelHolidayPrice);
}
}
}
......@@ -75,7 +90,7 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
vehicleModelHolidayPrice.setFreeDays(freeDays);
Example example = new Example(VehicleModelHolidayPrice.class);
Example.Criteria criteria = example.createCriteria();
setCondtionDate(configDate, criteria);
setCondtionDate(configDate, null, criteria);
int effect = mapper.updateByExampleSelective(vehicleModelHolidayPrice, example);
if (effect < 1) {
throw new BaseException("车型节假日更新失败");
......@@ -92,7 +107,11 @@ 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);
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) {
criteria.andLike("festival", String.format("%%%s%%", vehicleModelHolidayPriceFindDTO.getFestival()));
}
......@@ -100,10 +119,13 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
if (CollectionUtils.isEmpty(holidayPrices)) {
return vehicleModelHolidayPriceVos;
}
List<Integer> festivalIds = holidayPrices.stream().map(VehicleModelHolidayPrice::getFestivalId).collect(Collectors.toList());
Map<Integer,Festival> festivalMap = festivalBiz.findFestivalsByIds(festivalIds);
VehicleModelHolidayPriceVo vehicleModelHolidayPriceVo;
for (VehicleModelHolidayPrice holidayPrice : holidayPrices) {
vehicleModelHolidayPriceVo = new VehicleModelHolidayPriceVo();
BeanUtils.copyProperties(holidayPrice, vehicleModelHolidayPriceVo);
vehicleModelHolidayPriceVo.setFestival(festivalMap==null?"":festivalMap.get(holidayPrice.getFestivalId()).getName());
vehicleModelHolidayPriceVos.add(vehicleModelHolidayPriceVo);
}
return vehicleModelHolidayPriceVos;
......@@ -125,10 +147,13 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
if (CollectionUtils.isEmpty(modelHolidayPrices)) {
return vehicleModelHolidayPriceDTOS;
}
List<Integer> festivalIds = modelHolidayPrices.stream().map(VehicleModelHolidayPrice::getFestivalId).collect(Collectors.toList());
Map<Integer,Festival> festivalMap = festivalBiz.findFestivalsByIds(festivalIds);
VehicleModelHolidayPriceDTO vehicleModelHolidayPriceDTO;
for (VehicleModelHolidayPrice modelHolidayPrice : modelHolidayPrices) {
vehicleModelHolidayPriceDTO = new VehicleModelHolidayPriceDTO();
BeanUtils.copyProperties(modelHolidayPrice, vehicleModelHolidayPriceDTO);
vehicleModelHolidayPriceDTO.setFestival(festivalMap==null?"":festivalMap.get(modelHolidayPrice.getFestivalId()).getName());
vehicleModelHolidayPriceDTOS.add(vehicleModelHolidayPriceDTO);
}
return vehicleModelHolidayPriceDTOS;
......@@ -138,14 +163,20 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
* @param id
* @return
*/
public VehicleModelHolidayPriceSaveDTO findVehicleModelHolidayPriceById(Long id) {
VehicleModelHolidayPrice vehicleModelHolidayPrice = mapper.selectByPrimaryKey(id);
if (Objects.isNull(vehicleModelHolidayPrice)) {
public VehicleModelHolidayPriceSaveDTO findVehicleModelHolidayPriceFestivalId(Long id) {
VehicleModelHolidayPriceSaveDTO modelHolidayPriceSaveDTO = new VehicleModelHolidayPriceSaveDTO();
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("数据不存在");
}
VehicleModelHolidayPriceSaveDTO vehicleModelHolidayPriceSaveDTO = new VehicleModelHolidayPriceSaveDTO();
BeanUtils.copyProperties(vehicleModelHolidayPrice, vehicleModelHolidayPriceSaveDTO);
return vehicleModelHolidayPriceSaveDTO;
List<Date> dates = vehicleModelHolidayPrices.stream().map(VehicleModelHolidayPrice::getFestivalDay).collect(Collectors.toList());
VehicleModelHolidayPrice vehicleModelHolidayPrice = vehicleModelHolidayPrices.get(0);
BeanUtils.copyProperties(vehicleModelHolidayPrice, modelHolidayPriceSaveDTO);
modelHolidayPriceSaveDTO.setDate(dates);
return modelHolidayPriceSaveDTO;
}
/**
......@@ -154,15 +185,24 @@ public class VehicleModelHolidayPriceBiz extends BaseBiz<VehicleModelHolidayPric
* @param conditionDate
* @param criteria
*/
private void setCondtionDate(Date conditionDate, Example.Criteria criteria) {
LocalDate localDate = LocalDate.from(conditionDate.toInstant());
private void setCondtionDate(Date conditionDate, Integer year, Example.Criteria criteria) {
//开始日期
Instant startInstant = localDate.withDayOfMonth(1).atStartOfDay(ZoneId.systemDefault()).toInstant();
Instant startInstant = null;
//结束日期
LocalDate endLocalDate = localDate.with(TemporalAdjusters.lastDayOfMonth());
Instant endInstant = endLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant();
criteria.andBetween("festivalDay", Date.from(startInstant), Date.from(endInstant));
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());
endInstant = endLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant();
}
if (Objects.nonNull(startInstant) && Objects.nonNull(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;
import com.xxfc.platform.vehicle.entity.VehicleModelHolidayPrice;
import tk.mybatis.mapper.additional.insert.InsertListMapper;
import tk.mybatis.mapper.common.Mapper;
/**
......@@ -9,5 +10,5 @@ import tk.mybatis.mapper.common.Mapper;
* @description
* @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;
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.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.List;
......
......@@ -36,7 +36,7 @@ public class VehicleModelHolidayPriceAdminController {
@GetMapping("/{id}")
public ObjectRestResponse<VehicleModelHolidayPriceSaveDTO> findVehicleModelHolidayPrice(@PathVariable(value = "id") Long id){
VehicleModelHolidayPriceSaveDTO vehicleModelHolidayPriceSaveDTO = vehicleModelHolidayPriceBiz.findVehicleModelHolidayPriceById(id);
VehicleModelHolidayPriceSaveDTO vehicleModelHolidayPriceSaveDTO = vehicleModelHolidayPriceBiz.findVehicleModelHolidayPriceFestivalId(id);
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