kai.wu 8 mesi fa
parent
commit
78512137f7

+ 2 - 5
src/main/java/com/poyee/controller/ProductCalendarController.java

@@ -1,9 +1,6 @@
 package com.poyee.controller;
 
-import com.poyee.dto.ProductCalendarDetailDto;
-import com.poyee.dto.ProductCalendarDto;
-import com.poyee.dto.ProductCalendarPriceDto;
-import com.poyee.dto.ProductSimpleDto;
+import com.poyee.dto.*;
 import com.poyee.entity.ProductCalendarPrice;
 import com.poyee.service.ProductCalendarService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -112,7 +109,7 @@ public class ProductCalendarController {
      * @return 符合条件的产品日历信息列表
      */
     @GetMapping("/page")
-    public List<ProductCalendarDto> getProductCalendarsByPageAndCondition(
+    public List<ProductCalendarGroupedDto> getProductCalendarsByPageAndCondition(
             @RequestParam(required = false) Integer releaseYear,
             @RequestParam(required = false) Integer releaseMonth,
             @RequestParam(required = false) String sport,

+ 11 - 0
src/main/java/com/poyee/dto/ProductCalendarGroupedDto.java

@@ -0,0 +1,11 @@
+package com.poyee.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class ProductCalendarGroupedDto {
+    private String day;
+    private List<ProductCalendarDto> productCalendarDtos;
+}

+ 2 - 5
src/main/java/com/poyee/service/ProductCalendarService.java

@@ -1,9 +1,6 @@
 package com.poyee.service;
 
-import com.poyee.dto.ProductCalendarDetailDto;
-import com.poyee.dto.ProductCalendarDto;
-import com.poyee.dto.ProductCalendarPriceDto;
-import com.poyee.dto.ProductSimpleDto;
+import com.poyee.dto.*;
 
 import java.util.List;
 import java.util.Map;
@@ -22,7 +19,7 @@ public interface ProductCalendarService {
 
     Integer getProductCalendarCountByIds(Map<String, Object> params);
 
-    List<ProductCalendarDto> getProductCalendarsByPageAndCondition(Map<String, Object> params);
+    List<ProductCalendarGroupedDto> getProductCalendarsByPageAndCondition(Map<String, Object> params);
 
     /**
      * 根据产品名称模糊查询产品日历信息

+ 48 - 8
src/main/java/com/poyee/service/impl/ProductCalendarServiceImpl.java

@@ -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

+ 0 - 4
src/main/resources/mapper/ProductCalendarMapper.xml

@@ -185,7 +185,6 @@
         subquery.base_price,
         subquery.suggested_price,
         subquery.price_date,
-        <!-- 新增字段 -->
         subquery.currency_unit,
         subquery.rn
         FROM (
@@ -197,7 +196,6 @@
         pcp.base_price,
         pcp.suggested_price,
         pcp.price_date,
-        <!-- 新增字段 -->
         pcp.currency_unit,
         ROW_NUMBER() OVER (ORDER BY pc.release_time, pc.id) as rn
         FROM
@@ -208,7 +206,6 @@
         base_price,
         suggested_price,
         price_date,
-        <!-- 新增字段 -->
         currency_unit,
         ROW_NUMBER() OVER (
         PARTITION BY product_calendar_id
@@ -230,7 +227,6 @@
             <if test="manufacturer != null and manufacturer != ''">
                 AND LOWER(pc.manufacturer) = LOWER(#{manufacturer})
             </if>
-            <!-- 新增的模糊查询条件 -->
             <if test="productName != null and productName != ''">
                 AND LOWER(pc.product_name) LIKE '%' || LOWER(#{productName}) || '%'
             </if>

BIN
target/classes/com/poyee/controller/ProductCalendarController.class


BIN
target/classes/com/poyee/service/ProductCalendarService.class


BIN
target/classes/com/poyee/service/impl/ProductCalendarServiceImpl.class