|
|
@@ -0,0 +1,52 @@
|
|
|
+package com.mangoo.rating.recommend.app.controller;
|
|
|
+
|
|
|
+import com.mangoo.rating.recommend.AjaxResult;
|
|
|
+import com.mangoo.rating.recommend.annotation.ApiLog;
|
|
|
+import com.mangoo.rating.recommend.config.RecommendProperties;
|
|
|
+import com.mangoo.rating.recommend.enums.BusinessType;
|
|
|
+import com.mangoo.rating.recommend.request.recommend.RuleSyncRequest;
|
|
|
+import com.mangoo.rating.recommend.service.RuleSyncService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestHeader;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 数仓规则同步接口(内部,Token 鉴权)
|
|
|
+ *
|
|
|
+ * @author gengjintao
|
|
|
+ * @date 2026/06/25
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Api(tags = "内部-数仓规则同步接口")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/recommend/rule")
|
|
|
+public class RuleSyncController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private RuleSyncService ruleSyncService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private RecommendProperties recommendProperties;
|
|
|
+
|
|
|
+ @ApiOperation("数仓推送全量规则同步")
|
|
|
+ @PostMapping("/sync")
|
|
|
+ @ApiLog(title = "数仓规则同步", businessType = BusinessType.IMPORT)
|
|
|
+ public AjaxResult sync(@RequestHeader(value = "X-Sync-Token", required = false) String token,
|
|
|
+ @Validated @RequestBody RuleSyncRequest request) {
|
|
|
+ // Token 鉴权:防止内部同步接口被外部乱调写脏数据
|
|
|
+ String expected = recommendProperties.getSyncToken();
|
|
|
+ if (expected == null || !expected.equals(token)) {
|
|
|
+ log.warn("数仓同步鉴权失败,token 不匹配");
|
|
|
+ return AjaxResult.error("鉴权失败");
|
|
|
+ }
|
|
|
+ return ruleSyncService.sync(request);
|
|
|
+ }
|
|
|
+}
|