1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package com.malk.controller;
- import com.alibaba.fastjson.JSONObject;
- import com.malk.delegate.TBEvent;
- import com.malk.server.teambition.TBConf;
- import lombok.extern.slf4j.Slf4j;
- 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;
- /**
- * TB事件回调 3_1
- * 1. 回调可选择加密与不加密方式, tb发送成功为上游, 注册服务为下游
- * 2. 绑定回调需要安装后才会生效, 且回调范围更新后需要重新安装才会生效 [另外接口调用修改配置需要重新发布后生效]
- */
- @Slf4j
- @RestController
- @RequestMapping("/mc/tb")
- public class TBCallBackController {
- @Autowired
- private TBEvent tbEvent;
- /**
- * * 回调说明 [ppExt: 字段更新回调, 判定字段ID, 避免循坏触发问题, 接口修改也会触发webhook]
- * * 1. 通过接口更操作的数据,也会与手动创建一样触发相同的回调, 除了项目更新接口调用实测不会触发回调, 手动修改正常回调
- * * 2. 项目创建会推送两次
- * * - 1. 在第二次推送多 { data: { project: { operatorId, url }} } 这两个字段内容
- * * - 2. 若是通过模板创建的项目,在两次项目更新回调中会回调一次 project.enable 回调, 其中任务只会回调创建, 不会回调更新
- * * 3. 任务创建, 会先回调创建事件, 接着立即回调任务更新事件 [若是通过模板创建, 任务只会回调创建, 不会回调更新]
- * * 4. 项目移入回收站,不会触发回调,删除后会触发项目与任务的 remove 事件; 若是将任务移入回收站, 会触发任务更新回调
- */
- @PostMapping("callback")
- public String callback(@RequestBody JSONObject eventJson) {
- String success = "success";
- String eventName = eventJson.getString("event");
- if (TBConf.EVENT_VERIFY_HOOK.equals(eventName)) {
- log.info("----- [TB]验证注册 -----");
- return success;
- }
- if (eventName.contains("task")) {
- log.info("[TB]任务回调, {}, {}", eventName, eventJson);
- tbEvent.callBackTask(eventJson);
- return success;
- }
- if (eventName.contains("project")) {
- log.info("[TB]项目回调, {}, {}", eventName, eventJson);
- tbEvent.callBackProject(eventJson);
- return success;
- }
- log.info("----- [TB]已注册, 未处理的其它回调 -----, {}, {}", eventName, eventJson);
- return success;
- }
- }
|