feat:mock数据及新增接口

This commit is contained in:
王金云 committed 2026-11-11 10:39:04 +08:00
1 parent 846de6fe0e
commit f3cd784e14
14 files changed
+381 -125

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
2026-11-10 18:51:00.819 [main] INFO com.crrc.crrcmall.CrrcMallApplication - Starting CrrcMallApplication using Java 17.0.21 with PID 12575 (/Users/air/yuankuang/crrc-mall/target/classes started by air in /Users/air/yuankuang/crrc-mall)
2026-11-10 18:51:00.821 [main] INFO com.crrc.crrcmall.CrrcMallApplication - The following 1 profile is active: "local"
2026-11-10 18:51:01.706 [main] INFO o.s.boot.web.embedded.tomcat.TomcatWebServer - Tomcat initialized with port 8080 (http)
2026-11-10 18:51:01.720 [main] INFO org.apache.catalina.core.StandardService - Starting service [Tomcat]
2026-11-10 18:51:01.720 [main] INFO org.apache.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/10.1.30]
2026-11-10 18:51:01.770 [main] INFO o.a.c.core.ContainerBase.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
2026-11-10 18:51:01.770 [main] INFO o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 917 ms
2026-11-10 18:51:02.198 [main] INFO o.s.boot.web.embedded.tomcat.TomcatWebServer - Tomcat started on port 8080 (http) with context path '/'
2026-11-10 18:51:02.207 [main] INFO com.crrc.crrcmall.CrrcMallApplication - Started CrrcMallApplication in 1.857 seconds (process running for 2.421)
2026-11-10 20:09:56.077 [main] INFO com.crrc.crrcmall.CrrcMallApplication - Starting CrrcMallApplication using Java 17.0.21 with PID 14064 (/Users/air/yuankuang/crrc-mall/target/classes started by air in /Users/air/yuankuang/crrc-mall)
2026-11-10 20:09:56.078 [main] INFO com.crrc.crrcmall.CrrcMallApplication - The following 1 profile is active: "local"
2026-11-10 20:09:56.872 [main] INFO o.s.boot.web.embedded.tomcat.TomcatWebServer - Tomcat initialized with port 8080 (http)
2026-11-10 20:09:56.884 [main] INFO org.apache.catalina.core.StandardService - Starting service [Tomcat]
2026-11-10 20:09:56.885 [main] INFO org.apache.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/10.1.30]
2026-11-10 20:09:56.931 [main] INFO o.a.c.core.ContainerBase.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
2026-11-10 20:09:56.931 [main] INFO o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 823 ms
2026-11-10 20:09:57.356 [main] INFO o.s.boot.web.embedded.tomcat.TomcatWebServer - Tomcat started on port 8080 (http) with context path '/'
2026-11-10 20:09:57.364 [main] INFO com.crrc.crrcmall.CrrcMallApplication - Started CrrcMallApplication in 1.731 seconds (process running for 2.25)
2026-11-10 20:11:32.221 [http-nio-8080-exec-1] INFO o.a.c.core.ContainerBase.[Tomcat].[localhost].[/] - Initializing Spring DispatcherServlet 'dispatcherServlet'
2026-11-10 20:11:32.222 [http-nio-8080-exec-1] INFO org.springframework.web.servlet.DispatcherServlet - Initializing Servlet 'dispatcherServlet'
2026-11-10 20:11:32.223 [http-nio-8080-exec-1] INFO org.springframework.web.servlet.DispatcherServlet - Completed initialization in 1 ms
2026-11-10 20:11:32.339 [http-nio-8080-exec-1] INFO com.crrc.crrcmall.service.impl.SearchServiceImpl - 执行 AI 文本搜索,关键词:null
+39 -35
View File
@@ -19,65 +19,55 @@
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-restclient</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc</artifactId>
</dependency>
<!-- 1. 数据访问层 -->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-elasticsearch</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-jdbc</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-jpa</artifactId>-->
<!-- </dependency>-->
<!-- Spring Web (包含 @PostMapping 和 @ResponseBody) -->
<!-- 2. Web 开发 (包含 HttpServletResponse, Tomcat, Spring MVC) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- SpringDoc OpenAPI 3 (Spring Boot 3 标准文档依赖) -->
<!-- 3. API 文档 (SpringDoc OpenAPI) -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.6.0</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-docker-compose</artifactId>-->
<!-- <scope>runtime</scope>-->
<!-- <optional>true</optional>-->
<!-- </dependency>-->
<!-- MySQL 8+ 驱动 (Spring Boot 3 推荐) -->
<!-- 4. 数据库驱动 -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<!-- 5. Excel 处理 (EasyExcel) -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.3.3</version>
</dependency>
<!-- 6. 工具类 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- Spring Boot 官方测试依赖包 (包含 JUnit 5, Spring Test, Mockito 等) -->
<!-- 7. 测试 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
@@ -94,6 +84,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>default-compile</id>
@@ -106,6 +102,7 @@
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
</path>
</annotationProcessorPaths>
</configuration>
@@ -121,12 +118,19 @@
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
</path>
</annotationProcessorPaths>
</configuration>
</execution>
</executions>
</plugin>
<!-- 锁定jar插件版本 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
</plugin>
</plugins>
</build>
<repositories>
@@ -1,37 +1,66 @@
package com.crrc.crrcmall.controller;
import com.crrc.crrcmall.dto.price.PriceConfirmRequestDto;
import com.crrc.crrcmall.dto.price.PriceResultRequestDto;
import com.crrc.crrcmall.service.PriceService;
import com.crrc.crrcmall.vo.price.PriceImportResponseVo;
import com.crrc.crrcmall.vo.price.PriceResultResponseVo;
import com.crrc.crrcmall.vo.price.PriceTaskDetailVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
/**
* 选品比价控制器
*/
@Tag(name = "选品比价服务")
@RestController
@RequestMapping("/api/v1/price")
@RequiredArgsConstructor
public class PriceController {
private final PriceService priceService;
public PriceController(PriceService priceService) {
this.priceService = priceService;
@Operation(summary = "下载选品模板")
@GetMapping("/template")
public void downloadTemplate(HttpServletResponse response) throws IOException {
priceService.downloadTemplate(response);
}
@Operation(summary = "导入比价数据")
@PostMapping("/import")
public PriceImportResponseVo importPriceData(@RequestParam("file") MultipartFile file) {
@Operation(summary = "上传选品表")
@PostMapping("/upload")
public PriceImportResponseVo uploadExcel(@RequestParam("file") MultipartFile file) {
return priceService.importPriceExcel(file);
}
@Operation(summary = "查询比价任务详情")
@GetMapping("/task")
public PriceTaskDetailVo getTaskDetail(@RequestParam("taskId") String taskId) {
return priceService.queryTaskDetail(taskId);
}
@Operation(summary = "人工确认/撤销确认")
@PostMapping("/item/confirm")
public void confirmItem(@RequestBody PriceConfirmRequestDto request) {
priceService.confirmItem(request);
}
@Operation(summary = "导出excel")
@GetMapping("/export")
public void exportResult(@RequestParam("taskId") String taskId, HttpServletResponse response) throws IOException {
priceService.exportResult(taskId, response);
}
@Operation(summary = "查询比价结果")
@GetMapping("/result")
public PriceResultResponseVo getPriceResult(@ModelAttribute PriceResultRequestDto request) {
public PriceResultResponseVo getPriceResult(PriceResultRequestDto request) {
return priceService.getPriceResult(request);
}
}
@@ -0,0 +1,20 @@
package com.crrc.crrcmall.dto.price;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
@Data
@Schema(description = "人工确认/撤销请求")
public class PriceConfirmRequestDto implements Serializable {
@Schema(description = "任务 ID")
private String taskId;
@Schema(description = "行号")
private Integer rowIndex;
@Schema(description = "操作类型:CONFIRM(确认同款), CANCEL(撤销确认)")
private String action;
}
@@ -1,20 +1,45 @@
package com.crrc.crrcmall.service;
import com.crrc.crrcmall.dto.price.PriceConfirmRequestDto;
import com.crrc.crrcmall.dto.price.PriceResultRequestDto;
import com.crrc.crrcmall.vo.price.PriceImportResponseVo;
import com.crrc.crrcmall.vo.price.PriceResultResponseVo;
import com.crrc.crrcmall.vo.price.PriceTaskDetailVo;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
/**
* 比价服务接口
*/
public interface PriceService {
/**
* 导入比价 Excel
* 下载选品模板
*/
void downloadTemplate(HttpServletResponse response) throws IOException;
/**
* 导入比价数据
*/
PriceImportResponseVo importPriceExcel(MultipartFile file);
/**
* 查询任务详情(含统计与列表)
*/
PriceTaskDetailVo queryTaskDetail(String taskId);
/**
* 人工确认/撤销确认
*/
void confirmItem(PriceConfirmRequestDto request);
/**
* 导出回写结果
*/
void exportResult(String taskId, HttpServletResponse response) throws IOException;
/**
* 查询比价结果
*/
@@ -1,40 +1,90 @@
package com.crrc.crrcmall.service.impl;
import com.crrc.crrcmall.dto.price.PriceConfirmRequestDto;
import com.crrc.crrcmall.dto.price.PriceResultRequestDto;
import com.crrc.crrcmall.service.PriceService;
import com.crrc.crrcmall.vo.price.PriceImportResponseVo;
import com.crrc.crrcmall.vo.price.PriceResultResponseVo;
import com.crrc.crrcmall.vo.price.PriceTaskDetailVo;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
/**
* 比价服务实现
* 比价服务实现 (Mock 演示版)
*/
@Slf4j
@Service
public class PriceServiceImpl implements PriceService {
@Override
public void downloadTemplate(HttpServletResponse response) throws IOException {
log.info("下载选品比价模板");
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
// 设置文件名
String fileName = URLEncoder.encode("选品比价模板", StandardCharsets.UTF_8).replaceAll("\\+", "%20");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
// 从 resources/templates 目录下读取模板文件
ClassPathResource resource = new ClassPathResource("templates/zczc-price-template.xlsx");
if (!resource.exists()) {
throw new IOException("Template file not found at templates/zczc-price-template.xlsx");
}
// 将文件流写入响应
try (InputStream is = resource.getInputStream();
OutputStream os = response.getOutputStream()) {
byte[] buffer = new byte[1024];
int len;
while ((len = is.read(buffer)) != -1) {
os.write(buffer, 0, len);
}
os.flush();
}
}
@Override
public PriceImportResponseVo importPriceExcel(MultipartFile file) {
// TODO: 1. 解析 Excel 文件
// TODO: 2. 生成 TaskID 并保存原始数据
// TODO: 3. 触发比价分析流程
String taskId = UUID.randomUUID().toString().replace("-", "");
PriceImportResponseVo res = new PriceImportResponseVo();
res.setTaskId(99887766L);
res.setStatus("SUCCESSED");
res.setTaskId(Long.parseLong(taskId.substring(0, 8), 16)); // Mock ID
res.setStatus("PROCESSING");
return res;
}
@Override
public PriceResultResponseVo getPriceResult(PriceResultRequestDto request) {
// TODO: 1. 根据 TaskID 查询比价结果
// TODO: 2. 返回 AI 核价建议
PriceResultResponseVo res = new PriceResultResponseVo();
res.setSkuCode("SKU-001");
res.setProductName("测试商品");
res.setAiMarketPrice(100.0);
res.setAiSuggestion("价格合理");
return res;
public PriceTaskDetailVo queryTaskDetail(String taskId) {
// 如果没有任务,返回空的 Mock 结构
return new PriceTaskDetailVo();
}
@Override
public void confirmItem(PriceConfirmRequestDto request) {
log.info("人工干预:任务={}, 行号={}, 操作={}", request.getTaskId(), request.getRowIndex(), request.getAction());
// 这里仅打印日志,实际应更新 TASK_DB 中的状态
}
@Override
public void exportResult(String taskId, HttpServletResponse response) throws IOException {
downloadTemplate(response);
}
@Override
public PriceResultResponseVo getPriceResult(PriceResultRequestDto request) {
return null;
}
}
@@ -0,0 +1,37 @@
package com.crrc.crrcmall.vo.price;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
@Data
@Schema(description = "比价明细列表项")
public class PriceCompareItemVo implements Serializable {
@Schema(description = "行号")
private Integer rowIndex;
@Schema(description = "选品明细(上传表名称)")
private String originalName;
@Schema(description = "选品规格")
private String originalSpec;
@Schema(description = "匹配到的商城商品名称")
private String matchedProductName;
@Schema(description = "匹配到的供应商名称")
private String matchedSupplier;
@Schema(description = "商城价格")
private BigDecimal mallPrice;
@Schema(description = "命名差异原因")
private String diffReason;
@Schema(description = "确认状态:MATCHED(已匹配), DIFF(有差异), PENDING(待确认), NO_MATCH(未检索到)")
private String status;
}
@@ -0,0 +1,18 @@
package com.crrc.crrcmall.vo.price;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
@Schema(description = "比价任务详情响应")
public class PriceTaskDetailVo implements Serializable {
@Schema(description = "任务统计卡片")
private PriceTaskStatsVo stats;
@Schema(description = "明细列表")
private List<PriceCompareItemVo> items;
}
@@ -0,0 +1,26 @@
package com.crrc.crrcmall.vo.price;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
@Data
@Schema(description = "比价任务统计卡片")
public class PriceTaskStatsVo implements Serializable {
@Schema(description = "选品行数")
private Integer totalRows;
@Schema(description = "已匹配同款数量")
private Integer matchedCount;
@Schema(description = "命名存在差异数量")
private Integer diffCount;
@Schema(description = "待确认数量")
private Integer pendingCount;
@Schema(description = "来源文件名")
private String sourceFileName;
}
+19 -20
View File
@@ -1,25 +1,24 @@
# 开发环境配置
# 本地环境配置
server:
port: 8080
port: 12000
spring:
elasticsearch:
uris: http://dev-es-server:9200
username: elastic
password: dev_password
# elasticsearch:
# uris: http://localhost:9200
# username: elastic
# password: your_password
datasource:
url: jdbc:mysql://localhost:3306/wjy?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
# datasource:
# url: jdbc:mysql://localhost:3306/wjy?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
# username: root
# password: root
# driver-class-name: com.mysql.cj.jdbc.Driver
#
# jpa:
# hibernate:
# ddl-auto: update
# show-sql: true
# properties:
# hibernate:
# format_sql: true
jpa:
hibernate:
ddl-auto: none
show-sql: false
logging:
level:
root: INFO
com.crrc.crrcmall: INFO
+15 -19
View File
@@ -3,26 +3,22 @@ server:
port: 8080
spring:
elasticsearch:
uris: http://localhost:9200
# elasticsearch:
# uris: http://localhost:9200
# username: elastic
# password: your_password
datasource:
url: jdbc:mysql://localhost:3306/wjy?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
# datasource:
# url: jdbc:mysql://localhost:3306/wjy?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
# username: root
# password: root
# driver-class-name: com.mysql.cj.jdbc.Driver
#
# jpa:
# hibernate:
# ddl-auto: update
# show-sql: true
# properties:
# hibernate:
# format_sql: true
jpa:
hibernate:
ddl-auto: update
show-sql: true
properties:
hibernate:
format_sql: true
logging:
level:
root: INFO
com.crrc.crrcmall: DEBUG
+16 -27
View File
@@ -2,30 +2,19 @@
server:
port: 8080
spring:
elasticsearch:
uris: http://prod-es-server:9200
username: elastic
password: prod_password
datasource:
url: jdbc:mysql://18.15.131.225:3306/crrc_mall?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: entpur_select
password: EtEdgf@zc2024
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: none
show-sql: false
logging:
level:
root: WARN
com.crrc.crrcmall: INFO
file:
name: logs/crrc-mall.log
logback:
rollingpolicy:
max-file-size: 10MB
max-history: 30
#spring:
# elasticsearch:
# uris: http://prod-es-server:9200
# username: elastic
# password: prod_password
#
# datasource:
# url: jdbc:mysql://18.15.131.225:3306/crrc_mall?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
# username: entpur_select
# password: EtEdgf@zc2024
# driver-class-name: com.mysql.cj.jdbc.Driver
#
# jpa:
# hibernate:
# ddl-auto: none
# show-sql: false
+41
View File
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 引入 Spring Boot 默认配置 -->
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<!-- 日志文件存放路径 -->
<property name="LOG_PATH" value="./logs"/>
<property name="LOG_FILE" value="crrc-mall"/>
<!-- 控制台输出 -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<!-- 文件输出:按天 + 按大小双滚动,支持 %i -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/${LOG_FILE}.log</file>
<!-- 重点:换成 SizeAndTimeBasedRollingPolicy -->
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- %d日期 + %i序号,同一天多个分片 -->
<fileNamePattern>${LOG_PATH}/${LOG_FILE}-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<!-- 单个日志最大 100MB -->
<maxFileSize>100MB</maxFileSize>
<!-- 日志保留30天 -->
<maxHistory>30</maxHistory>
<!-- 所有日志总容量上限3GB -->
<totalSizeCap>3GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<!-- 根日志级别 -->
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
</configuration>