Bladeren bron

initial code

kai.wu 8 maanden geleden
bovenliggende
commit
b5ab74cd9a

+ 22 - 0
pom.xml

@@ -59,6 +59,28 @@
             <version>2.3.1</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi</artifactId>
+            <version>4.1.2</version>
+        </dependency>
+        <!-- 处理 XLSX 文件 -->
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml</artifactId>
+            <version>4.1.2</version>
+        </dependency>
+        <!-- XML 解析器依赖 -->
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml-schemas</artifactId>
+            <version>4.1.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.xmlbeans</groupId>
+            <artifactId>xmlbeans</artifactId>
+            <version>3.1.0</version>
+        </dependency>
 
 
     </dependencies>

+ 2 - 0
src/main/java/com/poyee/dto/ProductCalendarDetailDto.java

@@ -30,4 +30,6 @@ public class ProductCalendarDetailDto {
     private BigDecimal lastRmbBasePrice;
     private BigDecimal lastRmbSuggestedPrice;
     private ProductCalendarPriceDto productCalendarPrices;
+    private List<ProductSimpleDto> similarProducts;
+    private List<ProductOtherYearDto> years;
 }

+ 9 - 0
src/main/java/com/poyee/dto/ProductOtherYearDto.java

@@ -0,0 +1,9 @@
+package com.poyee.dto;
+
+import lombok.Data;
+
+@Data
+public class ProductOtherYearDto {
+    private Long id;
+    private String year;
+}

+ 5 - 0
src/main/java/com/poyee/mapper/ProductCalendarMapper.java

@@ -1,6 +1,7 @@
 package com.poyee.mapper;
 
 import com.poyee.dto.ProductCalendarDto;
+import com.poyee.dto.ProductOtherYearDto;
 import com.poyee.dto.ProductSimpleDto;
 import com.poyee.entity.ProductCalendar;
 import com.poyee.entity.ProductCalendarPrice;
@@ -26,4 +27,8 @@ public interface ProductCalendarMapper {
     List<ProductCalendarDto> getProductCalendarsByPageAndCondition(Map<String, Object> params);
 
     List<ProductSimpleDto> getProductCalendarsByProductName(String productName);
+
+    List<ProductSimpleDto> getSimilarProductCalendarsByConditions(Map<String, Object> params);
+
+    List<ProductOtherYearDto> getProductCalendarsYears(Map<String, Object> params);
 }

+ 21 - 5
src/main/java/com/poyee/service/impl/ProductCalendarServiceImpl.java

@@ -1,11 +1,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.dto.*;
 import com.poyee.entity.ProductCalendar;
 import com.poyee.entity.ProductCalendarPrice;
 import com.poyee.mapper.ProductCalendarMapper;
@@ -63,6 +59,26 @@ public class ProductCalendarServiceImpl implements ProductCalendarService {
             productCalendarPriceDto.setMinSuggestedPrice(minSuggestedPrice.getSuggestedPrice());
             productCalendarPriceDto.setMinCurrencyType(minSuggestedPrice.getCurrencyUnit());
         }
+        //查询相似产品
+        Map<String, Object> params = new HashMap<>();
+        params.put("year",productCalendar.getYear());
+        params.put("sets",productCalendar.getSets());
+        params.put("sport", productCalendar.getSport());
+        params.put("id", productCalendar.getId());
+        List<ProductSimpleDto> productSimpleDtos =productCalendarMapper.getSimilarProductCalendarsByConditions(params);
+        productCalendarDetailDto.setSimilarProducts(productSimpleDtos);
+        // 截取 productName 中与 year 相同的内容
+        String productName = productCalendar.getProductName();
+        String year = productCalendar.getYear();
+        if (productName != null && year != null && productName.startsWith(year)) {
+            productName = productName.substring(year.length()).trim();
+        }
+        Map<String, Object> params2 = new HashMap<>();
+        params2.put("productName",productName);
+        params2.put("id",productCalendar.getId());
+        //查询历年产品年份
+        List<ProductOtherYearDto> years = productCalendarMapper.getProductCalendarsYears(params2);
+        productCalendarDetailDto.setYears(years);
         return productCalendarDetailDto;
     }
 

+ 57 - 0
src/main/java/com/poyee/utils/ExcelImportUtil.java

@@ -0,0 +1,57 @@
+package com.poyee.utils;
+
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ExcelImportUtil {
+
+    public static List<List<String>> readExcel(String filePath) throws IOException {
+        List<List<String>> data = new ArrayList<>();
+        try (FileInputStream fis = new FileInputStream(new File(filePath));
+             Workbook workbook = new XSSFWorkbook(fis)) {
+            Sheet sheet = workbook.getSheetAt(0);
+            for (int i = 0; i <= sheet.getLastRowNum(); i++) {
+                Row row = sheet.getRow(i);
+                if (row == null) {
+                    continue;
+                }
+                List<String> rowData = new ArrayList<>();
+                for (int j = 0; j < row.getLastCellNum(); j++) {
+                    Cell cell = row.getCell(j);
+                    if (cell == null) {
+                        rowData.add(null);
+                        continue;
+                    }
+                    switch (cell.getCellType()) {
+                        case STRING:
+                            rowData.add(cell.getStringCellValue());
+                            break;
+                        case NUMERIC:
+                            if (DateUtil.isCellDateFormatted(cell)) {
+                                rowData.add(cell.getDateCellValue().toString());
+                            } else {
+                                rowData.add(String.valueOf(cell.getNumericCellValue()));
+                            }
+                            break;
+                        case BOOLEAN:
+                            rowData.add(String.valueOf(cell.getBooleanCellValue()));
+                            break;
+                        case FORMULA:
+                            rowData.add(cell.getCellFormula());
+                            break;
+                        default:
+                            rowData.add(null);
+                    }
+                }
+                data.add(rowData);
+            }
+        }
+        return data;
+    }
+}

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

@@ -248,4 +248,38 @@
         LIMIT 10;
     </select>
 
+    <select id="getSimilarProductCalendarsByConditions" resultMap="ProductSimpleResultMap">
+        SELECT
+        pc.id,
+        pc.product_name,
+        pc.image_url
+        FROM
+        product_calendar pc
+        WHERE
+        <!-- 使用 #{year} 接收传入的年份参数 -->
+        pc.year = #{year}
+        <!-- 使用 #{sets} 接收传入的 sets 参数 -->
+        AND pc.sets = #{sets}
+        <!-- 使用 #{sport} 接收传入的 sport 参数 -->
+        AND pc.sport = #{sport}
+        <!-- 使用 #{id} 接收传入的 id 参数 -->
+        AND pc.id != #{id}
+    </select>
+
+    <resultMap id="ProductOtherYearDtoMap" type="com.poyee.dto.ProductOtherYearDto">
+        <id property="id" column="id"/>
+        <result property="year" column="year"/>
+    </resultMap>
+
+    <select id="getProductCalendarsYears" resultMap="ProductOtherYearDtoMap">
+        SELECT
+        id,
+        year
+        FROM
+        product_calendar
+        WHERE
+        product_name LIKE '%' || #{productName}
+        AND id != #{id}
+    </select>
+
 </mapper>

BIN
target/classes/com/poyee/dto/ProductCalendarDetailDto.class


BIN
target/classes/com/poyee/mapper/ProductCalendarMapper.class


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


+ 34 - 4
target/classes/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>
@@ -252,4 +248,38 @@
         LIMIT 10;
     </select>
 
+    <select id="getSimilarProductCalendarsByConditions" resultMap="ProductSimpleResultMap">
+        SELECT
+        pc.id,
+        pc.product_name,
+        pc.image_url
+        FROM
+        product_calendar pc
+        WHERE
+        <!-- 使用 #{year} 接收传入的年份参数 -->
+        pc.year = #{year}
+        <!-- 使用 #{sets} 接收传入的 sets 参数 -->
+        AND pc.sets = #{sets}
+        <!-- 使用 #{sport} 接收传入的 sport 参数 -->
+        AND pc.sport = #{sport}
+        <!-- 使用 #{id} 接收传入的 id 参数 -->
+        AND pc.id != #{id}
+    </select>
+
+    <resultMap id="ProductOtherYearDtoMap" type="com.poyee.dto.ProductOtherYearDto">
+        <id property="id" column="id"/>
+        <result property="year" column="year"/>
+    </resultMap>
+
+    <select id="getProductCalendarsYears" resultMap="ProductOtherYearDtoMap">
+        SELECT
+        id,
+        year
+        FROM
+        product_calendar
+        WHERE
+        product_name LIKE '%' || #{productName}
+        AND id != #{id}
+    </select>
+
 </mapper>