Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
gsc
/
gsc-vcp-thirdparty-facade
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 2130b40b
authored
Sep 22, 2026
by
叶立庆
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'v5.8.6' into 'master'
上线合并 See merge request
!4
2 parents
2c9cb160
1d8178d3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
414 additions
and
1 deletions
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/anotation/McpSign.java
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/config/WebConfig.java
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/controller/mcp/McpReportController.java
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/handler/McpExceptionHandler.java
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/interceptor/McpSignInterceptor.java
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/response/mcp/McpErrorResponse.java
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/response/mcp/McpResponse.java
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/response/mcp/McpSchemaField.java
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/service/mcp/McpReportService.java
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/anotation/McpSign.java
0 → 100644
View file @
2130b40
package
com
.
gsc4cloud
.
gsc
.
facade
.
vpcthirdparty
.
anotation
;
import
java.lang.annotation.*
;
/**
* MCP 接口签名验证注解
* <p>
* 标记需要 SHA-1 签名校验的 MCP 接口方法
* </p>
*/
@Target
(
ElementType
.
METHOD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
public
@interface
McpSign
{
}
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/config/WebConfig.java
View file @
2130b40
package
com
.
gsc4cloud
.
gsc
.
facade
.
vpcthirdparty
.
config
;
import
com.gsc4cloud.gsc.facade.vpcthirdparty.interceptor.McpSignInterceptor
;
import
com.gsc4cloud.gsc.facade.vpcthirdparty.interceptor.SessionInterceptor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -17,10 +18,18 @@ public class WebConfig implements WebMvcConfigurer {
@Autowired
private
SessionInterceptor
sessionInterceptor
;
@Autowired
private
McpSignInterceptor
mcpSignInterceptor
;
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
// MCP 接口签名校验拦截器,仅拦截 /mcp/** 路径
registry
.
addInterceptor
(
mcpSignInterceptor
)
.
addPathPatterns
(
"/mcp/**"
);
// Session 拦截器,拦截所有路径(但只处理带 @RopSession 注解的方法)
registry
.
addInterceptor
(
sessionInterceptor
)
.
addPathPatterns
(
"/**"
)
// 拦截所有路径
.
addPathPatterns
(
"/**"
)
/*.excludePathPatterns("/login", "/error")*/
;
// 排除不需要拦截的路径
}
}
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/controller/mcp/McpReportController.java
0 → 100644
View file @
2130b40
package
com
.
gsc4cloud
.
gsc
.
facade
.
vpcthirdparty
.
controller
.
mcp
;
import
com.gsc4cloud.gsc.facade.vpcthirdparty.anotation.McpSign
;
import
com.gsc4cloud.gsc.facade.vpcthirdparty.response.mcp.McpResponse
;
import
com.gsc4cloud.gsc.facade.vpcthirdparty.service.mcp.McpReportService
;
import
com.gsc4cloud.gsc.vpc.api.dto.thirdparty.mcp.McpDailyRequest
;
import
com.gsc4cloud.gsc.vpc.api.dto.thirdparty.mcp.McpMonthlyRequest
;
import
com.gsc4cloud.gsc.vpc.api.dto.thirdparty.mcp.McpShelfRequest
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
jakarta.validation.Valid
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
/**
* 大数据 MCP 接口
* <p>
* 提供给大数据团队的 3 个 MCP 查询接口:
* 1. POST /mcp/shelf/list - 门店上架数据查询
* 2. POST /mcp/monthly/list - 月度经营数据查询
* 3. POST /mcp/daily/list - 员工日报明细查询
* </p>
*/
@Slf4j
@RestController
@RequestMapping
(
"/mcp"
)
@Tag
(
name
=
"大数据 MCP 接口"
,
description
=
"提供给大数据团队的 MCP 查询接口"
)
public
class
McpReportController
{
@Autowired
private
McpReportService
mcpReportService
;
/**
* 接口一:门店上架数据查询
* <p>
* 调用 smartcarlife ROP 接口获取上架数据,返回 {data, schema} 格式
* </p>
*
* @param request 查询请求(storeName/storeId 可选)
* @return MCP 响应格式
*/
@McpSign
@Operation
(
summary
=
"门店上架数据查询"
,
description
=
"调用 ROP 接口获取门店上架配置数据"
)
@PostMapping
(
"/shelf/list"
)
public
McpResponse
shelfList
(
@Valid
@RequestBody
(
required
=
false
)
McpShelfRequest
request
)
{
if
(
request
==
null
)
{
request
=
new
McpShelfRequest
();
}
log
.
info
(
"MCP 上架数据查询: storeName={}, storeId={}"
,
request
.
getStoreName
(),
request
.
getStoreId
());
return
mcpReportService
.
queryShelfList
(
request
);
}
/**
* 接口二:月度经营数据查询
* <p>
* 从宽表按月聚合,返回 {data, schema} 格式
* </p>
*
* @param request 查询请求(month 必填,storeName 可选)
* @return MCP 响应格式
*/
@McpSign
@Operation
(
summary
=
"月度经营数据查询"
,
description
=
"从宽表按月聚合经营数据"
)
@PostMapping
(
"/monthly/list"
)
public
McpResponse
monthlyList
(
@Valid
@RequestBody
McpMonthlyRequest
request
)
{
log
.
info
(
"MCP 月度数据查询: month={}, storeName={}"
,
request
.
getMonth
(),
request
.
getStoreName
());
return
mcpReportService
.
queryMonthlyList
(
request
);
}
/**
* 接口三:员工日报明细查询
* <p>
* 仅返回 3 个核心字段(F2-108/F2-109/F2-110),返回 {data, schema} 格式
* </p>
*
* @param request 查询请求(storeName/startDate/endDate 必填,employee 可选)
* @return MCP 响应格式
*/
@McpSign
@Operation
(
summary
=
"员工日报明细查询"
,
description
=
"查询员工逐日报明细,仅返回3个核心字段"
)
@PostMapping
(
"/daily/list"
)
public
McpResponse
dailyList
(
@Valid
@RequestBody
McpDailyRequest
request
)
{
log
.
info
(
"MCP 日报明细查询: storeName={}, employee={}, startDate={}, endDate={}"
,
request
.
getStoreName
(),
request
.
getEmployee
(),
request
.
getStartDate
(),
request
.
getEndDate
());
return
mcpReportService
.
queryDailyList
(
request
);
}
}
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/handler/McpExceptionHandler.java
0 → 100644
View file @
2130b40
package
com
.
gsc4cloud
.
gsc
.
facade
.
vpcthirdparty
.
handler
;
import
com.gsc4cloud.gsc.facade.vpcthirdparty.controller.mcp.McpReportController
;
import
com.gsc4cloud.gsc.facade.vpcthirdparty.response.mcp.McpErrorResponse
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.converter.HttpMessageNotReadableException
;
import
org.springframework.validation.ObjectError
;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
import
java.util.stream.Collectors
;
/**
* MCP 接口异常处理
* <p>
* /mcp/** 的入参校验与请求体解析失败需按 MCP 契约返回 {error_code, message} + HTTP 400,
* 而不是项目统一的 R 包装({code, msg, data, success} + HTTP 200)。
* </p>
*/
@Order
(
Ordered
.
HIGHEST_PRECEDENCE
)
@RestControllerAdvice
(
assignableTypes
=
McpReportController
.
class
)
@Slf4j
public
class
McpExceptionHandler
{
@ExceptionHandler
(
MethodArgumentNotValidException
.
class
)
public
ResponseEntity
<
McpErrorResponse
>
handleValidationException
(
MethodArgumentNotValidException
e
)
{
String
message
=
e
.
getBindingResult
().
getAllErrors
().
stream
()
.
map
(
ObjectError:
:
getDefaultMessage
)
.
collect
(
Collectors
.
joining
(
"; "
));
if
(
message
.
isEmpty
())
{
message
=
"参数校验失败"
;
}
log
.
warn
(
"MCP 参数校验失败: {}"
,
message
);
return
ResponseEntity
.
status
(
HttpStatus
.
BAD_REQUEST
)
.
body
(
McpErrorResponse
.
of
(
"INVALID_PARAM"
,
message
));
}
@ExceptionHandler
(
HttpMessageNotReadableException
.
class
)
public
ResponseEntity
<
McpErrorResponse
>
handleNotReadableException
(
HttpMessageNotReadableException
e
)
{
log
.
warn
(
"MCP 请求体解析失败: {}"
,
e
.
getMessage
());
return
ResponseEntity
.
status
(
HttpStatus
.
BAD_REQUEST
)
.
body
(
McpErrorResponse
.
of
(
"INVALID_PARAM"
,
"请求体格式错误,需为 UTF-8 编码的合法 JSON"
));
}
}
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/interceptor/McpSignInterceptor.java
0 → 100644
View file @
2130b40
package
com
.
gsc4cloud
.
gsc
.
facade
.
vpcthirdparty
.
interceptor
;
import
cn.hutool.core.util.StrUtil
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.gsc4cloud.gsc.facade.vpcthirdparty.anotation.McpSign
;
import
com.gsc4cloud.gsc.facade.vpcthirdparty.response.mcp.McpErrorResponse
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.MediaType
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
import
java.security.MessageDigest
;
import
java.util.*
;
/**
* MCP 接口签名校验拦截器
* <p>
* 从请求头读取 appKey、sign、timestamp,使用 SHA-1 算法验证签名
* 签名算法:SHA1(secret + sorted(key+value) + secret) → 大写 hex
* </p>
*/
@Slf4j
@Component
public
class
McpSignInterceptor
implements
HandlerInterceptor
{
@Value
(
"${mcp.api.appKey:}"
)
private
String
configuredAppKey
;
@Value
(
"${mcp.api.secret:}"
)
private
String
configuredSecret
;
private
final
ObjectMapper
objectMapper
=
new
ObjectMapper
();
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
if
(!(
handler
instanceof
HandlerMethod
))
{
return
true
;
}
HandlerMethod
handlerMethod
=
(
HandlerMethod
)
handler
;
// 只拦截带 @McpSign 注解的方法
if
(!
handlerMethod
.
hasMethodAnnotation
(
McpSign
.
class
))
{
return
true
;
}
// 从请求头获取签名参数
String
appKey
=
request
.
getHeader
(
"appKey"
);
String
sign
=
request
.
getHeader
(
"sign"
);
String
timestamp
=
request
.
getHeader
(
"timestamp"
);
if
(
StrUtil
.
isBlank
(
appKey
)
||
StrUtil
.
isBlank
(
sign
)
||
StrUtil
.
isBlank
(
timestamp
))
{
writeErrorResponse
(
response
,
"INVALID_PARAM"
,
"缺少必要的签名参数: appKey, sign, timestamp"
);
return
false
;
}
// 验证 appKey
if
(!
configuredAppKey
.
equals
(
appKey
))
{
writeErrorResponse
(
response
,
"INVALID_PARAM"
,
"无效的 appKey"
);
return
false
;
}
// 验证时间戳(5分钟有效期)
try
{
long
ts
=
Long
.
parseLong
(
timestamp
);
long
now
=
System
.
currentTimeMillis
();
if
(
Math
.
abs
(
now
-
ts
)
>
5
*
60
*
1000
)
{
writeErrorResponse
(
response
,
"INVALID_PARAM"
,
"签名已过期"
);
return
false
;
}
}
catch
(
NumberFormatException
e
)
{
writeErrorResponse
(
response
,
"INVALID_PARAM"
,
"无效的时间戳格式"
);
return
false
;
}
// 构建签名字符串并验证
String
expectedSign
=
generateSign
(
request
,
configuredSecret
);
if
(!
expectedSign
.
equalsIgnoreCase
(
sign
))
{
log
.
warn
(
"MCP 签名验证失败: expected={}, actual={}"
,
expectedSign
,
sign
);
writeErrorResponse
(
response
,
"INVALID_PARAM"
,
"签名验证失败"
);
return
false
;
}
log
.
debug
(
"MCP 签名验证通过: appKey={}"
,
appKey
);
return
true
;
}
/**
* 生成签名:SHA1(secret + sorted(key+value) + secret) → 大写 hex
*/
private
String
generateSign
(
HttpServletRequest
request
,
String
secret
)
throws
Exception
{
// 收集所有请求参数
Map
<
String
,
String
>
paramMap
=
new
TreeMap
<>();
Enumeration
<
String
>
paramNames
=
request
.
getParameterNames
();
while
(
paramNames
.
hasMoreElements
())
{
String
name
=
paramNames
.
nextElement
();
String
value
=
request
.
getParameter
(
name
);
if
(
value
!=
null
&&
!
value
.
isEmpty
())
{
paramMap
.
put
(
name
,
value
);
}
}
// 也收集 JSON body 中的字段(如果 Content-Type 是 application/json)
String
contentType
=
request
.
getContentType
();
if
(
contentType
!=
null
&&
contentType
.
contains
(
MediaType
.
APPLICATION_JSON_VALUE
))
{
// 对于 POST with JSON body, we need to read the body
// This is tricky in an interceptor since the body can only be read once
// For simplicity, we'll skip body params in signature for now
// The caller should include critical params in query string or headers
}
// 构建签名字符串: secret + sorted(key+value) + secret
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
secret
);
for
(
Map
.
Entry
<
String
,
String
>
entry
:
paramMap
.
entrySet
())
{
sb
.
append
(
entry
.
getKey
()).
append
(
entry
.
getValue
());
}
sb
.
append
(
secret
);
// SHA-1 哈希
MessageDigest
md
=
MessageDigest
.
getInstance
(
"SHA-1"
);
byte
[]
digest
=
md
.
digest
(
sb
.
toString
().
getBytes
(
StandardCharsets
.
UTF_8
));
// 转为大写 hex
StringBuilder
hex
=
new
StringBuilder
();
for
(
byte
b
:
digest
)
{
String
h
=
Integer
.
toHexString
(
b
&
0xFF
);
if
(
h
.
length
()
==
1
)
{
hex
.
append
(
'0'
);
}
hex
.
append
(
h
.
toUpperCase
());
}
return
hex
.
toString
();
}
private
void
writeErrorResponse
(
HttpServletResponse
response
,
String
errorCode
,
String
message
)
throws
IOException
{
response
.
setStatus
(
HttpServletResponse
.
SC_BAD_REQUEST
);
response
.
setContentType
(
MediaType
.
APPLICATION_JSON_VALUE
);
response
.
setCharacterEncoding
(
StandardCharsets
.
UTF_8
.
name
());
McpErrorResponse
errorResponse
=
McpErrorResponse
.
of
(
errorCode
,
message
);
String
json
=
objectMapper
.
writeValueAsString
(
errorResponse
);
response
.
getWriter
().
write
(
json
);
response
.
getWriter
().
flush
();
}
}
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/response/mcp/McpErrorResponse.java
0 → 100644
View file @
2130b40
package
com
.
gsc4cloud
.
gsc
.
facade
.
vpcthirdparty
.
response
.
mcp
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/**
* MCP 错误响应格式 {error_code, message}
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public
class
McpErrorResponse
{
/**
* 错误码
*/
@JsonProperty
(
"error_code"
)
private
String
errorCode
;
/**
* 错误消息
*/
private
String
message
;
public
static
McpErrorResponse
of
(
String
errorCode
,
String
message
)
{
return
new
McpErrorResponse
(
errorCode
,
message
);
}
}
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/response/mcp/McpResponse.java
0 → 100644
View file @
2130b40
package
com
.
gsc4cloud
.
gsc
.
facade
.
vpcthirdparty
.
response
.
mcp
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.List
;
/**
* MCP 标准响应格式 {data, schema}
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public
class
McpResponse
{
/**
* 数据行数组
*/
private
List
<
Object
>
data
;
/**
* 字段元信息数组
*/
private
List
<
McpSchemaField
>
schema
;
public
static
McpResponse
of
(
List
<
Object
>
data
,
List
<
McpSchemaField
>
schema
)
{
return
new
McpResponse
(
data
,
schema
);
}
}
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/response/mcp/McpSchemaField.java
0 → 100644
View file @
2130b40
package
com
.
gsc4cloud
.
gsc
.
facade
.
vpcthirdparty
.
response
.
mcp
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/**
* MCP schema 字段元信息
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public
class
McpSchemaField
{
/**
* 英文 key(与 data 中的键一致)
*/
private
String
key
;
/**
* 中文名称
*/
@JsonProperty
(
"name_cn"
)
private
String
nameCn
;
/**
* 字段类型:string / number / percent / date / enum
*/
private
String
type
;
/**
* 口径/计算公式说明
*/
private
String
desc
;
}
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/service/mcp/McpReportService.java
0 → 100644
View file @
2130b40
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment