init project

This commit is contained in:
王金云
2026-11-02 14:48:40 +08:00
parent 826a5bfe35
commit 1769d90496
33 changed files with 1748 additions and 0 deletions
@@ -0,0 +1,13 @@
package com.crrc.crrcmall;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class CrrcMallApplication {
public static void main(String[] args) {
SpringApplication.run(CrrcMallApplication.class, args);
}
}
@@ -0,0 +1,8 @@
package com.crrc.crrcmall.common;
/**
* @Author:Jinyun.Wang
* @Date:2026/11/2
**/
public class CRRCConstant {
}
@@ -0,0 +1,24 @@
package com.crrc.crrcmall.common.enums;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* AI 匹配类型枚举
*/
@Getter
@AllArgsConstructor
@Schema(description = "AI 匹配类型")
public enum MatchTypeEnum {
@Schema(description = "语义匹配")
SEMANTIC("SEMANTIC", "语义匹配"),
@Schema(description = "图片匹配")
IMAGE("IMAGE", "图片匹配");
private final String code;
private final String desc;
}
@@ -0,0 +1,52 @@
package com.crrc.crrcmall.common.util;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
/**
* API 签名工具类 (HMAC-SHA256)
*/
public class SignUtil {
private static final String HMAC_SHA256 = "HmacSHA256";
/**
* 生成签名
* @param secret 密钥
* @param content 待签名字符串 (appId + timestamp + nonce + method + uri)
* @return 十六进制签名字符串
*/
public static String sign(String secret, String content) {
try {
Mac mac = Mac.getInstance(HMAC_SHA256);
SecretKeySpec secretKeySpec = new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), HMAC_SHA256);
mac.init(secretKeySpec);
byte[] hash = mac.doFinal(content.getBytes(StandardCharsets.UTF_8));
StringBuilder hexString = new StringBuilder();
for (byte b : hash) {
String hex = Integer.toHexString(0xff & b);
if (hex.length() == 1) hexString.append('0');
hexString.append(hex);
}
return hexString.toString();
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
throw new RuntimeException("Signature calculation failed", e);
}
}
/**
* 校验签名
* @param secret 密钥
* @param content 待签名字符串
* @param signature 客户端传来的签名
* @return 是否匹配
*/
public static boolean verify(String secret, String content, String signature) {
String calculatedSign = sign(secret, content);
return calculatedSign.equalsIgnoreCase(signature);
}
}
@@ -0,0 +1,84 @@
package com.crrc.crrcmall.config;
import com.crrc.crrcmall.common.util.SignUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
/**
* API 鉴权拦截器
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class ApiAuthInterceptor implements HandlerInterceptor {
private final ApiAuthProperties authProperties;
// 允许的时间误差(毫秒),默认 5 分钟
private static final long TIME_TOLERANCE = 5 * 60 * 1000;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 1. 获取请求头
String appId = request.getHeader("X-App-Id");
String timestampStr = request.getHeader("X-Timestamp");
String nonce = request.getHeader("X-Nonce");
String signature = request.getHeader("X-Signature");
// 2. 基础参数校验
if (appId == null || timestampStr == null || nonce == null || signature == null) {
sendErrorResponse(response, 401, "Missing required authentication headers");
return false;
}
// 3. 时间戳校验(防重放)
long currentTime = System.currentTimeMillis();
long requestTime;
try {
requestTime = Long.parseLong(timestampStr);
} catch (NumberFormatException e) {
sendErrorResponse(response, 401, "Invalid timestamp format");
return false;
}
if (Math.abs(currentTime - requestTime) > TIME_TOLERANCE) {
log.warn("Request timestamp expired: {}", timestampStr);
sendErrorResponse(response, 401, "Request timestamp expired");
return false;
}
// 4. 获取 AppSecret
String appSecret = authProperties.getClients().get(appId);
if (appSecret == null) {
log.warn("Unknown AppId: {}", appId);
sendErrorResponse(response, 401, "Invalid AppId");
return false;
}
// 5. 签名校验
// 签名内容: appId + timestamp + nonce + method + uri
String content = appId + timestampStr + nonce + request.getMethod() + request.getRequestURI();
if (!SignUtil.verify(appSecret, content, signature)) {
log.warn("Signature verification failed for AppId: {}", appId);
sendErrorResponse(response, 401, "Signature verification failed");
return false;
}
// 6. 校验通过
return true;
}
private void sendErrorResponse(HttpServletResponse response, int status, String message) throws IOException {
response.setStatus(status);
response.setContentType("application/json;charset=UTF-8");
response.getWriter().write("{\"code\":" + status + ",\"message\":\"" + message + "\"}");
}
}
@@ -0,0 +1,23 @@
package com.crrc.crrcmall.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* API 鉴权配置属性
*/
@Data
@Component
@ConfigurationProperties(prefix = "mall.auth")
public class ApiAuthProperties {
/**
* 客户端凭证映射: Key=AppId, Value=AppSecret
* 生产环境建议从数据库或配置中心动态加载
*/
private Map<String, String> clients = new HashMap<>();
}
@@ -0,0 +1,25 @@
package com.crrc.crrcmall.config;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* Web MVC 配置
*/
@Configuration
@RequiredArgsConstructor
public class WebConfig implements WebMvcConfigurer {
private final ApiAuthInterceptor apiAuthInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(apiAuthInterceptor)
// 拦截所有 /api/v1/ 开头的请求
.addPathPatterns("/api/v1/**")
// 排除 Swagger 和错误页面
.excludePathPatterns("/swagger-ui/**", "/api-docs/**", "/error");
}
}
@@ -0,0 +1,30 @@
package com.crrc.crrcmall.controller;
import com.crrc.crrcmall.dto.crrc.SearchGoodsRequestDto;
import com.crrc.crrcmall.service.SearchService;
import com.crrc.crrcmall.vo.crrc.GoodsSearchResultVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 商品搜索控制器
*/
@Tag(name = "AI 搜索服务", description = "提供基于 AI 语义的商品搜索接口")
@RestController
@RequestMapping("/api/v1/search")
public class SearchController {
@Autowired
private SearchService searchService;
@Operation(summary = "文本语义搜索", description = "接收自然语言查询,返回 AI 增强后的商品列表")
@PostMapping("/text")
public GoodsSearchResultVo searchByText(@RequestBody SearchGoodsRequestDto request) {
return searchService.searchByText(request);
}
}
@@ -0,0 +1,159 @@
package com.crrc.crrcmall.dto.crrc;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* 商品搜索请求参数 DTO
* 请根据实际项目包路径修改 package 声明
* @Author:Jinyun.Wang
* @Date:2026/11/2
**/
@Data
@Schema(description = "商品搜索请求参数")
public class SearchGoodsRequestDto implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "是否标准商品:0-非标品 1-标准商品 -1-全部", required = true)
private Integer isStandard;
@Schema(description = "商品名称(搜索关键字)")
private String goodsName;
@Schema(description = "搜索关键词(记录搜索日志用,配合 isRecordKey)")
private String searchWords;
@Schema(description = "是否记录搜索关键词日志")
private Boolean isRecordKey;
@Schema(description = "采购单位 id")
private String purchaserId;
@Schema(description = "采购目录(品目)id 列表")
private List<Long> purchaserCatalogIds;
@Schema(description = "标准目录 id 列表")
private List<Long> catalogIds;
@Schema(description = "供应商 id 列表")
private List<Long> supplierIds;
@Schema(description = "供应商名称")
private String supplierName;
@Schema(description = "品牌 id 列表")
private List<Long> brandIds;
@Schema(description = "商品属性筛选列表")
private List<SpecFilter> specList;
@Schema(description = "最低价格(默认 0.0001)")
private Double priceMin;
@Schema(description = "最高价格")
private Double priceMax;
@Schema(description = "排序:0-综合升 1-综合降 10-价格升 11-价格降 20-销量升 21-销量降 30-上架时间升 31-上架时间降")
private Integer sortType;
@Schema(description = "当前页码")
private Integer page;
@Schema(description = "每页条数")
private Integer limit;
@Schema(description = "地区 ID")
private String areaId;
@Schema(description = "包含的商品标签列表")
private List<String> includeTags;
@Schema(description = "排除的商品标签列表")
private List<String> excludeTags;
@Schema(description = "包含的单个标签")
private String includeTag;
@Schema(description = "供应商权重(影响综合排序)")
private Map<String, Double> supplierWeight;
@Schema(description = "供货类型:1-协议供货 2-自营供货")
private String supplyType;
@Schema(description = "是否只取今日发货商品")
private Boolean onlyDeliveryToday;
@Schema(description = "域名(影响未登录价格展示配置)")
private String domain;
@Schema(description = "是否京东自配送")
private Boolean withSelfDelivery;
@Schema(description = "页面请求类型")
private String moduleType;
@Schema(description = "传 1 时服务端按 moduleType 注入已配置的供应商")
private String supplierChooseWay;
@Schema(description = "协议类型:01-电商 02-供应商 03-EPLUS")
private String protocolType;
@Schema(description = "传 2 时按 69 码(upc)聚合")
private String goodsListAggByUpc;
@Schema(description = "专区类型:0-集采专区 1-电商专区")
private String specialAreaType;
@Schema(description = "69 码列表")
private List<String> upcList;
@Schema(description = "专区 id")
private Long specialAreaId;
@Schema(description = "楼层商品 ID")
private Long floorGoodsId;
@Schema(description = "物料编码(中车)")
private String material;
@Schema(description = "协议 id 列表")
private List<Long> protocolIds;
@Schema(description = "protocolIds 是否生效:1-生效 2-不生效")
private String protocolIdFilter;
@Schema(description = "采购品目名称")
private String purchaserCatalogName;
@Schema(description = "要排除的采购品目 id 列表")
private List<String> filterPurchaserCatalogIds;
@Schema(description = "要排除的协议 id 列表")
private List<String> filterProtocolIds;
@Schema(description = "自提点 id 列表")
private List<String> postStationIds;
@Schema(description = "协议商品上下架状态:0-未上架 1-已上架")
private Integer saleStatus;
@Schema(description = "是否不使用缓存")
private Boolean noUseCache;
@Schema(description = "是否需要拆词匹配")
private Boolean matchPhrase;
@Schema(description = "传 1 强制走非聚合搜索")
private String rowShowSearch;
@Schema(description = "招标年份列表")
private List<String> tenderYear;
}
@@ -0,0 +1,26 @@
package com.crrc.crrcmall.dto.crrc;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 商品属性筛选项内部类
* @Author:Jinyun.Wang
* @Date:2026/11/2
**/
@Data
@Schema(description = "商品属性筛选项")
public class SpecFilter implements Serializable {
@Schema(description = "属性 ID")
private String specId;
@Schema(description = "属性类型")
private String specType;
@Schema(description = "属性值 ID 列表")
private List<String> valueIds;
}
@@ -0,0 +1,17 @@
package com.crrc.crrcmall.service;
import com.crrc.crrcmall.dto.crrc.SearchGoodsRequestDto;
import com.crrc.crrcmall.vo.crrc.GoodsSearchResultVo;
/**
* 搜索服务接口
*/
public interface SearchService {
/**
* 文本语义搜索
* @param request 搜索请求参数
* @return 搜索结果
*/
GoodsSearchResultVo searchByText(SearchGoodsRequestDto request);
}
@@ -0,0 +1,30 @@
package com.crrc.crrcmall.service.impl;
import com.crrc.crrcmall.dto.crrc.SearchGoodsRequestDto;
import com.crrc.crrcmall.service.SearchService;
import com.crrc.crrcmall.vo.crrc.GoodsSearchResultVo;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
/**
* 搜索服务实现类
*/
@Service
public class SearchServiceImpl implements SearchService {
@Override
public GoodsSearchResultVo searchByText(SearchGoodsRequestDto request) {
// TODO: 1. 调用 AI 意图识别模块
// TODO: 2. 调用 ES 混合检索
// TODO: 3. 组装数据
// 目前返回空数据结构
GoodsSearchResultVo result = new GoodsSearchResultVo();
result.setGoodsList(new ArrayList<>());
result.setBrandList(new ArrayList<>());
result.setCatalogList(new ArrayList<>());
return result;
}
}
@@ -0,0 +1,38 @@
package com.crrc.crrcmall.vo.ai;
/**
* @Author:Jinyun.Wang
* @Date:2026/11/2
**/
import com.crrc.crrcmall.common.enums.MatchTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* AI 搜索解析信息 VO
* 对应 JSON 中的 ai_search_info 对象
*/
@Data
@Schema(description = "AI 搜索解析信息")
public class AiSearchInfoVo implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "用户原始输入词")
private String originalQuery;
@Schema(description = "AI 识别意图(如:查找办公用品 - 防静电配件)")
private String intent;
@Schema(description = "AI 纠错/建议(如:您是不是要找:防静电桌垫?)")
private String suggestion;
@Schema(description = "AI 扩展同义词列表")
private List<String> expandedTerms;
@Schema(description = "匹配类型")
private MatchTypeEnum matchType;
}
@@ -0,0 +1,29 @@
package com.crrc.crrcmall.vo.crrc;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
/**
* 品牌信息 VO
* 请根据实际项目包路径修改 package 声明
*/
@Data
@Schema(description = "品牌信息")
public class BrandVo implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "品牌ID")
private String brandId;
@Schema(description = "品牌名称")
private String brandName;
@Schema(description = "首字母")
private String firstLetter;
@Schema(description = "Logo地址")
private String logoUrl;
}
@@ -0,0 +1,23 @@
package com.crrc.crrcmall.vo.crrc;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
/**
* 标准目录信息 VO
* 请根据实际项目包路径修改 package 声明
*/
@Data
@Schema(description = "标准目录信息")
public class CatalogVo implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "目录ID")
private String catalogId;
@Schema(description = "目录名称")
private String catalogName;
}
@@ -0,0 +1,49 @@
package com.crrc.crrcmall.vo.crrc;
import com.crrc.crrcmall.vo.ai.AiSearchInfoVo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 商品搜索结果根对象 VO
* 请根据实际项目包路径修改 package 声明
*/
@Data
@Schema(description = "商品搜索结果根对象")
public class GoodsSearchResultVo implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "地区ID")
private String areaId;
@Schema(description = "地区名称")
private String areaName;
@Schema(description = "品牌列表")
private List<BrandVo> brandList;
@Schema(description = "标准目录列表")
private List<CatalogVo> catalogList;
@Schema(description = "商品列表")
private List<GoodsVo> goodsList;
@Schema(description = "是否自营")
private Boolean isSelf;
@Schema(description = "未登录是否显示价格")
private String isShowPriceUnlogin;
@Schema(description = "采购目录列表")
private List<PurchaserCatalogVo> purchaserCatalogList;
@Schema(description = "规格筛选列表")
private List<SpecVo> specList;
@Schema(description = "ai规则说明")
private AiSearchInfoVo aiSearchInfo;
}
@@ -0,0 +1,151 @@
package com.crrc.crrcmall.vo.crrc;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
/**
* 商品列表项信息 VO
* 请根据实际项目包路径修改 package 声明
*/
@Data
@Schema(description = "商品列表项信息")
public class GoodsVo implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "商品ID")
private String goodsId;
@Schema(description = "商品名称")
private String goodsName;
@Schema(description = "商品编码")
private String goodsCode;
@Schema(description = "物料编码")
private String materialCode;
@Schema(description = "商品提示语")
private String goodsTip;
@Schema(description = "商品主图")
private String goodsImage;
@Schema(description = "SKU图片")
private String skuImage;
@Schema(description = "销售价格")
private BigDecimal goodsPrice;
@Schema(description = "供应商ID")
private String supplierId;
@Schema(description = "供应商名称")
private String supplierName;
@Schema(description = "协议类型")
private String protocolType;
@Schema(description = "采购人目录ID")
private String purchaserCatalogId;
@Schema(description = "采购人目录名称")
private String purchaserCatalogName;
@Schema(description = "采购人目录全称")
private String purchaserCatalogFullName;
@Schema(description = "标准目录ID")
private String catalogId;
@Schema(description = "标准目录名称")
private String catalogName;
@Schema(description = "品牌ID")
private String brandId;
@Schema(description = "规格列表(JSON字符串)")
private String specList;
@Schema(description = "品牌名称")
private String brandName;
@Schema(description = "协议ID")
private String protocolId;
@Schema(description = "商品来源类型")
private Integer goodsSourceType;
@Schema(description = "剩余数量")
private Integer remainAmount;
@Schema(description = "产品Logo")
private String productLogo;
@Schema(description = "商品项Logo")
private String productItemLogo;
@Schema(description = "是否自营")
private String isSelfOperated;
@Schema(description = "市场价")
private BigDecimal marketPrice;
@Schema(description = "市场价链接")
private String marketPriceUrl;
@Schema(description = "折扣率")
private Double goodsPriceDiscount;
@Schema(description = "优惠显示文本")
private String goodsDiscount;
@Schema(description = "是否团购")
private Boolean isGroup;
@Schema(description = "团购价")
private Object groupPrice;
@Schema(description = "成团数量")
private Object groupNum;
@Schema(description = "有效时间")
private Integer effectTime;
@Schema(description = "销量")
private Integer sales;
@Schema(description = "上下架状态")
private Integer saleStatus;
@Schema(description = "原价")
private BigDecimal originalPrice;
@Schema(description = "专区角标Logo")
private String specialAreaCornerLogo;
@Schema(description = "门户角标Logo")
private String portalCornerLogo;
@Schema(description = "高亮商品名称(HTML)")
private String highlightGoodsName;
@Schema(description = "是否有自提点")
private Boolean isPostStation;
@Schema(description = "服务商ID")
private String serviceSupplyId;
@Schema(description = "服务商SKU_ID")
private String serviceSupplySkuId;
@Schema(description = "采购人标签列表")
private List<Object> purchaserTagList;
@Schema(description = "AI 相关度得分 (0~1) 0.99 = 99%")
private Double aiRelevanceScore;
}
@@ -0,0 +1,23 @@
package com.crrc.crrcmall.vo.crrc;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
/**
* 采购人目录信息 VO
* 请根据实际项目包路径修改 package 声明
*/
@Data
@Schema(description = "采购人目录信息")
public class PurchaserCatalogVo implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "采购人目录ID")
private String purchaserCatalogId;
@Schema(description = "采购人目录名称")
private String purchaserCatalogName;
}
@@ -0,0 +1,26 @@
package com.crrc.crrcmall.vo.crrc;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
/**
* 规格值信息 VO
* 请根据实际项目包路径修改 package 声明
*/
@Data
@Schema(description = "规格值信息")
public class SpecValueVo implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "规格值ID")
private String valueId;
@Schema(description = "规格值图片")
private String valueImg;
@Schema(description = "规格值名称")
private String valueName;
}
@@ -0,0 +1,27 @@
package com.crrc.crrcmall.vo.crrc;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 商品规格筛选信息 VO
* 请根据实际项目包路径修改 package 声明
*/
@Data
@Schema(description = "商品规格筛选信息")
public class SpecVo implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "规格ID/Key")
private String specId;
@Schema(description = "规格名称")
private String specName;
@Schema(description = "规格值列表")
private List<SpecValueVo> specValueList;
}