|
|
@@ -0,0 +1,121 @@
|
|
|
+package com.sckw.ai.biz.mcp;
|
|
|
+
|
|
|
+import com.sckw.ai.biz.util.R;
|
|
|
+import com.sckw.order.api.model.TradeOrderVo;
|
|
|
+import com.sckw.report.api.model.TodoCountVo;
|
|
|
+import com.sckw.transport.api.model.LogisticsBaseOrderVo;
|
|
|
+import com.sckw.transport.api.model.dto.McpLogisticsOrderVo;
|
|
|
+import com.sckw.transport.api.model.param.OrderPara;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springaicommunity.mcp.annotation.McpTool;
|
|
|
+import org.springaicommunity.mcp.annotation.McpToolParam;
|
|
|
+import org.springframework.core.ParameterizedTypeReference;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.reactive.function.client.WebClient;
|
|
|
+
|
|
|
+import java.time.Duration;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author xucaiqin
|
|
|
+ * @date 2026-03-05 09:19:48
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class DatabaseTools {
|
|
|
+ @Resource
|
|
|
+ private WebClient webClientReport;
|
|
|
+ @Resource
|
|
|
+ private WebClient webClientOrder;
|
|
|
+ @Resource
|
|
|
+ private WebClient webClientTransport;
|
|
|
+
|
|
|
+
|
|
|
+ @McpTool(name = "todoList", description = "统计当前用户待处理的贸易订单、物流运单、贸易合同、物流合同数据。")
|
|
|
+ public R<TodoCountVo> todoList(@McpToolParam(description = "用户ID,由上游传入") Long userId) {
|
|
|
+ try {
|
|
|
+ TodoCountVo todoCountVo = webClientReport.get().uri("/kwHome/count") // 后端 SSE 路径
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .retrieve().bodyToMono(TodoCountVo.class).block(Duration.ofSeconds(15));
|
|
|
+ return R.ok(todoCountVo);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("异常{} ", e.getMessage(), e);
|
|
|
+ return R.failed("接口异常,请稍后再试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @McpTool(name = "tradeOrder", description = "根据时间范围或订单号查询用户的贸易订单")
|
|
|
+ public R<List<TradeOrderVo>> tradeOrder(
|
|
|
+ @McpToolParam(description = "用户ID,由上游传入") Long userId,
|
|
|
+ @McpToolParam(description = "订单开始时间,格式:yyyy-MM-dd HH:mm:ss", required = false) String startTime,
|
|
|
+ @McpToolParam(description = "订单结束时间,格式:yyyy-MM-dd HH:mm:ss", required = false) String endTime,
|
|
|
+ @McpToolParam(description = "贸易订单号,当使用具体单号、商品查数据时不使用默认的时间范围", required = false) String orderNo) {
|
|
|
+ try {
|
|
|
+ com.sckw.order.api.model.OrderPara tradeOrderPara = new com.sckw.order.api.model.OrderPara();
|
|
|
+ tradeOrderPara.setStartTime(startTime);
|
|
|
+ tradeOrderPara.setEndTime(endTime);
|
|
|
+ tradeOrderPara.setUserId(userId);
|
|
|
+ tradeOrderPara.setOrderNo(orderNo);
|
|
|
+ List<TradeOrderVo> mcpLogisticsOrderVos = webClientOrder.post().uri("/tradeOrder/trade")
|
|
|
+ .bodyValue(tradeOrderPara)
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .retrieve().bodyToMono(new ParameterizedTypeReference<List<TradeOrderVo>>() {
|
|
|
+ }).block(Duration.ofSeconds(15));
|
|
|
+ return R.ok(mcpLogisticsOrderVos);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("异常{} ", e.getMessage(), e);
|
|
|
+ return R.failed("接口异常,请稍后再试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @McpTool(name = "logisticsList", description = "分页查询物流订单")
|
|
|
+ public R<List<McpLogisticsOrderVo>> logisticsList(
|
|
|
+ @McpToolParam(description = "用户ID,由上游传入") Long userId,
|
|
|
+ @McpToolParam(description = "订单开始时间,格式:yyyy-MM-dd HH:mm:ss", required = false) String startTime,
|
|
|
+ @McpToolParam(description = "订单结束时间,格式:yyyy-MM-dd HH:mm:ss", required = false) String endTime,
|
|
|
+ @McpToolParam(description = "物流订单编号,当使用具体单号、商品查数据时不使用默认的时间范围", required = false) String logisticsOrderNo,
|
|
|
+ @McpToolParam(description = "贸易订单号,当使用具体单号、商品查数据时不使用默认的时间范围", required = false) String orderNo) {
|
|
|
+ OrderPara orderPara = new OrderPara();
|
|
|
+ orderPara.setStartTime(startTime);
|
|
|
+ orderPara.setEndTime(endTime);
|
|
|
+ orderPara.setUserId(userId);
|
|
|
+ orderPara.setLogisticsOrderNo(logisticsOrderNo);
|
|
|
+ orderPara.setOrderNo(orderNo);
|
|
|
+ try {
|
|
|
+ List<McpLogisticsOrderVo> mcpLogisticsOrderVos = webClientTransport.post().uri("/logisticsOrder/list")
|
|
|
+ .bodyValue(orderPara)
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .retrieve().bodyToMono(new ParameterizedTypeReference<List<McpLogisticsOrderVo>>() {
|
|
|
+ }).block(Duration.ofSeconds(15));
|
|
|
+ return R.ok(mcpLogisticsOrderVos);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("异常{} ", e.getMessage(), e);
|
|
|
+ return R.failed("接口异常,请稍后再试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @McpTool(name = "logisticsBase", description = "问题涉及 物流订单、订单物流、运输,未明确要求查明细时,优先使用该api")
|
|
|
+ public R<List<LogisticsBaseOrderVo>> logisticsBase(
|
|
|
+ @McpToolParam(description = "用户ID,由上游传入") Long userId,
|
|
|
+ @McpToolParam(description = "订单开始时间,格式:yyyy-MM-dd HH:mm:ss", required = false) String startTime,
|
|
|
+ @McpToolParam(description = "订单结束时间,格式:yyyy-MM-dd HH:mm:ss", required = false) String endTime
|
|
|
+ ) {
|
|
|
+ OrderPara orderPara = new OrderPara();
|
|
|
+ orderPara.setStartTime(startTime);
|
|
|
+ orderPara.setEndTime(endTime);
|
|
|
+ orderPara.setUserId(userId);
|
|
|
+
|
|
|
+ try {
|
|
|
+ List<LogisticsBaseOrderVo> mcpLogisticsOrderVos = webClientTransport.post().uri("/logisticsOrder/base")
|
|
|
+ .bodyValue(orderPara)
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .retrieve().bodyToMono(new ParameterizedTypeReference<List<LogisticsBaseOrderVo>>() {
|
|
|
+ }).block(Duration.ofSeconds(15));
|
|
|
+ return R.ok(mcpLogisticsOrderVos);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("异常{} ", e.getMessage(), e);
|
|
|
+ return R.failed("接口异常,请稍后再试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|