diff --git a/logs/crrc-mall.log b/logs/crrc-mall.log new file mode 100644 index 0000000..930f9ee --- /dev/null +++ b/logs/crrc-mall.log @@ -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 diff --git a/pom.xml b/pom.xml index f994522..bdd4a7e 100644 --- a/pom.xml +++ b/pom.xml @@ -19,65 +19,55 @@ - - org.springframework.boot - spring-boot-starter-data-elasticsearch - - - org.springframework.boot - spring-boot-starter-data-jdbc - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-elasticsearch - - - org.springframework.boot - spring-boot-starter-restclient - - - org.springframework.boot - spring-boot-starter-webmvc - + + + + + + + + + + + + + - + org.springframework.boot spring-boot-starter-web - + org.springdoc springdoc-openapi-starter-webmvc-ui 2.6.0 - - - - - - - - + com.mysql mysql-connector-j runtime + + + com.alibaba + easyexcel + 3.3.3 + + + org.projectlombok lombok true - + org.springframework.boot spring-boot-starter-test @@ -94,6 +84,12 @@ org.apache.maven.plugins maven-compiler-plugin + 3.8.1 + + 17 + 17 + UTF-8 + default-compile @@ -106,6 +102,7 @@ org.projectlombok lombok + 1.18.30 @@ -121,12 +118,19 @@ org.projectlombok lombok + 1.18.30 + + + org.apache.maven.plugins + maven-jar-plugin + 3.2.2 + diff --git a/src/main/java/com/crrc/crrcmall/controller/PriceController.java b/src/main/java/com/crrc/crrcmall/controller/PriceController.java index 6fc75d5..33c5a2d 100644 --- a/src/main/java/com/crrc/crrcmall/controller/PriceController.java +++ b/src/main/java/com/crrc/crrcmall/controller/PriceController.java @@ -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); } + } diff --git a/src/main/java/com/crrc/crrcmall/dto/price/PriceConfirmRequestDto.java b/src/main/java/com/crrc/crrcmall/dto/price/PriceConfirmRequestDto.java new file mode 100644 index 0000000..fb8cbcb --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/dto/price/PriceConfirmRequestDto.java @@ -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; +} diff --git a/src/main/java/com/crrc/crrcmall/service/PriceService.java b/src/main/java/com/crrc/crrcmall/service/PriceService.java index ccd55b9..9002de3 100644 --- a/src/main/java/com/crrc/crrcmall/service/PriceService.java +++ b/src/main/java/com/crrc/crrcmall/service/PriceService.java @@ -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; + /** * 查询比价结果 */ diff --git a/src/main/java/com/crrc/crrcmall/service/impl/PriceServiceImpl.java b/src/main/java/com/crrc/crrcmall/service/impl/PriceServiceImpl.java index 9adbe22..a107f6f 100644 --- a/src/main/java/com/crrc/crrcmall/service/impl/PriceServiceImpl.java +++ b/src/main/java/com/crrc/crrcmall/service/impl/PriceServiceImpl.java @@ -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; + } + } diff --git a/src/main/java/com/crrc/crrcmall/vo/price/PriceCompareItemVo.java b/src/main/java/com/crrc/crrcmall/vo/price/PriceCompareItemVo.java new file mode 100644 index 0000000..2ec96b4 --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/vo/price/PriceCompareItemVo.java @@ -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; + +} diff --git a/src/main/java/com/crrc/crrcmall/vo/price/PriceTaskDetailVo.java b/src/main/java/com/crrc/crrcmall/vo/price/PriceTaskDetailVo.java new file mode 100644 index 0000000..33ce92e --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/vo/price/PriceTaskDetailVo.java @@ -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 items; +} diff --git a/src/main/java/com/crrc/crrcmall/vo/price/PriceTaskStatsVo.java b/src/main/java/com/crrc/crrcmall/vo/price/PriceTaskStatsVo.java new file mode 100644 index 0000000..d5a88e2 --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/vo/price/PriceTaskStatsVo.java @@ -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; +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 3cd6235..bdd0b97 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -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 diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 3221d4b..e914bee 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -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 diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index ddade92..ee20ebf 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -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 diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..a778cdc --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + + + + + + ${LOG_PATH}/${LOG_FILE}.log + + + + ${LOG_PATH}/${LOG_FILE}-%d{yyyy-MM-dd}.%i.log.gz + + 100MB + + 30 + + 3GB + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + + + + + + + + + diff --git a/src/main/resources/templates/zczc-price-template.xlsx b/src/main/resources/templates/zczc-price-template.xlsx new file mode 100644 index 0000000..9d5f0ea Binary files /dev/null and b/src/main/resources/templates/zczc-price-template.xlsx differ