TBDelegate.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package com.malk.poc.delegate;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.malk.poc.service.AWClint;
  4. import com.malk.delegate.TBEvent;
  5. import lombok.SneakyThrows;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.context.annotation.Primary;
  9. import org.springframework.scheduling.annotation.Async;
  10. import org.springframework.stereotype.Service;
  11. /**
  12. * OA审批事件 [主项目也有实现, 添加 @Primary 优先注入主项目实现]
  13. * -
  14. * 取消方案: 撤销和拒绝流程不继续执行连接器, 因此不使用连接器与轮询审批记录方案 [低效而且占用较高钉钉api调次数];
  15. * 优化方案: 通过事件订阅实现实时同步所有审批状态, 定时查询钉钉回调失败记录 [配置钉钉事件Delegate, 添加定时任务]
  16. */
  17. @Slf4j
  18. @Service
  19. @Primary
  20. public class TBDelegate implements TBEvent {
  21. @Autowired
  22. private AWClint awClint;
  23. @Async
  24. @Override
  25. @SneakyThrows
  26. public void callBackTask(JSONObject eventJson) {
  27. String eventName = eventJson.getString("event");
  28. log.info("callBackTask, {}, {}", eventName, eventJson);
  29. if ("v3.task.taskflowstatus.update".equals(eventName)) {
  30. JSONObject data = eventJson.getJSONObject("data");
  31. awClint.taskSatusUpdate(data);
  32. // awClint.doApprove(data, false);
  33. } else if ("v3.task.customfield.update".equals(eventName)) {
  34. // JSONObject data = eventJson.getJSONObject("data");
  35. // System.out.println("1" + JSONObject.toJSONString(data));
  36. // awClint.custFieldUpdate(data);
  37. }
  38. }
  39. @Async
  40. @Override
  41. @SneakyThrows
  42. public void callBackProject(JSONObject eventJson) {
  43. String eventName = eventJson.getString("event");
  44. log.info("callBackProject, {}", eventJson);
  45. }
  46. }