TBCallBackController.java 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package com.malk.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.malk.delegate.TBEvent;
  4. import com.malk.server.teambition.TBConf;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.web.bind.annotation.PostMapping;
  8. import org.springframework.web.bind.annotation.RequestBody;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RestController;
  11. /**
  12. * TB事件回调 3_1
  13. * 1. 回调可选择加密与不加密方式, tb发送成功为上游, 注册服务为下游
  14. * 2. 绑定回调需要安装后才会生效, 且回调范围更新后需要重新安装才会生效 [另外接口调用修改配置需要重新发布后生效]
  15. */
  16. @Slf4j
  17. @RestController
  18. @RequestMapping("/mc/tb")
  19. public class TBCallBackController {
  20. @Autowired
  21. private TBEvent tbEvent;
  22. /**
  23. * * 回调说明 [ppExt: 字段更新回调, 判定字段ID, 避免循坏触发问题, 接口修改也会触发webhook]
  24. * * 1. 通过接口更操作的数据,也会与手动创建一样触发相同的回调, 除了项目更新接口调用实测不会触发回调, 手动修改正常回调
  25. * * 2. 项目创建会推送两次
  26. * * - 1. 在第二次推送多 { data: { project: { operatorId, url }} } 这两个字段内容
  27. * * - 2. 若是通过模板创建的项目,在两次项目更新回调中会回调一次 project.enable 回调, 其中任务只会回调创建, 不会回调更新
  28. * * 3. 任务创建, 会先回调创建事件, 接着立即回调任务更新事件 [若是通过模板创建, 任务只会回调创建, 不会回调更新]
  29. * * 4. 项目移入回收站,不会触发回调,删除后会触发项目与任务的 remove 事件; 若是将任务移入回收站, 会触发任务更新回调
  30. */
  31. @PostMapping("callback")
  32. public String callback(@RequestBody JSONObject eventJson) {
  33. String success = "success";
  34. String eventName = eventJson.getString("event");
  35. if (TBConf.EVENT_VERIFY_HOOK.equals(eventName)) {
  36. log.info("----- [TB]验证注册 -----");
  37. return success;
  38. }
  39. if (eventName.contains("task")) {
  40. log.info("[TB]任务回调, {}, {}", eventName, eventJson);
  41. tbEvent.callBackTask(eventJson);
  42. return success;
  43. }
  44. if (eventName.contains("project")) {
  45. log.info("[TB]项目回调, {}, {}", eventName, eventJson);
  46. tbEvent.callBackProject(eventJson);
  47. return success;
  48. }
  49. log.info("----- [TB]已注册, 未处理的其它回调 -----, {}, {}", eventName, eventJson);
  50. return success;
  51. }
  52. }