|
|
@@ -3,6 +3,7 @@ package com.poyee.service.impl;
|
|
|
import com.poyee.config.ExchangeRateConfig;
|
|
|
import com.poyee.dto.ProductCalendarDetailDto;
|
|
|
import com.poyee.dto.ProductCalendarDto;
|
|
|
+import com.poyee.dto.ProductCalendarGroupedDto;
|
|
|
import com.poyee.dto.ProductCalendarPriceDto;
|
|
|
import com.poyee.dto.ProductSimpleDto;
|
|
|
import com.poyee.entity.ProductCalendar;
|
|
|
@@ -14,9 +15,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class ProductCalendarServiceImpl implements ProductCalendarService {
|
|
|
@@ -89,16 +91,54 @@ public class ProductCalendarServiceImpl implements ProductCalendarService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<ProductCalendarDto> getProductCalendarsByPageAndCondition(Map<String, Object> params) {
|
|
|
+ public List<ProductCalendarGroupedDto> getProductCalendarsByPageAndCondition(Map<String, Object> params) {
|
|
|
List<ProductCalendarDto> productCalendarDtos = productCalendarMapper.getProductCalendarsByPageAndCondition(params);
|
|
|
for (ProductCalendarDto productCalendarDto : productCalendarDtos) {
|
|
|
BigDecimal exchangeRate = exchangeRateConfig.getExchangeRate(productCalendarDto.getCurrencyUnit());
|
|
|
- if (exchangeRate!= null) {
|
|
|
- productCalendarDto.setRmbBasePrice(roundUpToHundreds(productCalendarDto.getBasePrice().multiply(exchangeRate)));
|
|
|
- productCalendarDto.setRmbSuggestedPrice(roundUpToHundreds(productCalendarDto.getSuggestedPrice().multiply(exchangeRate)));
|
|
|
+ if (exchangeRate != null) {
|
|
|
+ if (productCalendarDto.getBasePrice() != null) {
|
|
|
+ productCalendarDto.setRmbBasePrice(roundUpToHundreds(productCalendarDto.getBasePrice().multiply(exchangeRate)));
|
|
|
+ }
|
|
|
+ if (productCalendarDto.getSuggestedPrice() != null) {
|
|
|
+ productCalendarDto.setRmbSuggestedPrice(roundUpToHundreds(productCalendarDto.getSuggestedPrice().multiply(exchangeRate)));
|
|
|
+ }
|
|
|
+// productCalendarDto.setRmbBasePrice(roundUpToHundreds(productCalendarDto.getBasePrice().multiply(exchangeRate)));
|
|
|
+// productCalendarDto.setRmbSuggestedPrice(roundUpToHundreds(productCalendarDto.getSuggestedPrice().multiply(exchangeRate)));
|
|
|
}
|
|
|
}
|
|
|
- return productCalendarDtos;
|
|
|
+ // 定义日期格式化对象
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ // 按照 ReleaseTime 的日期分组
|
|
|
+ Map<String, List<ProductCalendarDto>> groupedByDay = productCalendarDtos.stream()
|
|
|
+ .collect(Collectors.groupingBy(dto -> {
|
|
|
+ Date releaseTime = dto.getReleaseTime();
|
|
|
+ return releaseTime != null ? sdf.format(releaseTime) : null;
|
|
|
+ }));
|
|
|
+
|
|
|
+ // 对分组结果按日期排序
|
|
|
+ List<ProductCalendarGroupedDto> groupedList = new ArrayList<>();
|
|
|
+ groupedByDay.entrySet().stream()
|
|
|
+ .sorted(Map.Entry.<String, List<ProductCalendarDto>>comparingByKey((date1, date2) -> {
|
|
|
+ try {
|
|
|
+ if (date1 == null) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if (date2 == null) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return sdf.parse(date1).compareTo(sdf.parse(date2));
|
|
|
+ } catch (ParseException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }))
|
|
|
+ .forEach(entry -> {
|
|
|
+ ProductCalendarGroupedDto groupedDto = new ProductCalendarGroupedDto();
|
|
|
+ groupedDto.setDay(entry.getKey());
|
|
|
+ groupedDto.setProductCalendarDtos(entry.getValue());
|
|
|
+ groupedList.add(groupedDto);
|
|
|
+ });
|
|
|
+
|
|
|
+ return groupedList;
|
|
|
}
|
|
|
|
|
|
@Override
|