DefaultTaskFactory.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package com.yiidata.intergration.web.task;
  2. import com.yiidata.intergration.web.config.IntenetProperties;
  3. import com.yiidata.intergration.web.config.TaskProperties;
  4. import com.yiidata.intergration.web.modules.dingtalk.service.DingTalkMessageService;
  5. import com.yiidata.intergration.web.modules.dingtalk.task.CzscAnalysisTask;
  6. import com.yiidata.intergration.web.modules.dingtalk.task.XGAnalysisTask;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.jdbc.core.JdbcTemplate;
  10. import org.springframework.stereotype.Component;
  11. import java.util.HashMap;
  12. import java.util.Map;
  13. import java.util.Optional;
  14. /**
  15. * <pre>
  16. *
  17. * Created by zhaopx.
  18. * User: zhaopx
  19. * Date: 2020/11/17
  20. * Time: 12:54
  21. *
  22. * </pre>
  23. *
  24. * @author zhaopx
  25. */
  26. @Component
  27. @Slf4j
  28. public class DefaultTaskFactory {
  29. @Autowired
  30. TaskProperties taskProperties;
  31. @Autowired
  32. IntenetProperties intenetProperties;
  33. @Autowired
  34. DingTalkMessageService dingTalkMessageService;
  35. @Autowired
  36. JdbcTemplate jdbcTemplate;
  37. /**
  38. * 根据 TaskInfo 生成 Task,不同 Task 类型
  39. * @param taskId TaskID
  40. * @param taskInfo
  41. * @return
  42. */
  43. public SuperTask newTask(String taskId, Map<String, Object> taskInfo) {
  44. String type = Optional.ofNullable((String)taskInfo.get("taskType")).orElse("TEST");
  45. switch (type) {
  46. case "CZSC_ANALYSIS":
  47. //缠中说禅 分析任务
  48. CzscAnalysisTask task = new CzscAnalysisTask(
  49. taskId, taskInfo);
  50. task.setDingTalkMessageService(dingTalkMessageService);
  51. task.setIntenetProperties(intenetProperties);
  52. task.setJdbcTemplate(jdbcTemplate);
  53. return task;
  54. case "XG_ANALYSIS":
  55. // 选股任务
  56. XGAnalysisTask xgAnalysisTask = new XGAnalysisTask(taskId, taskInfo);
  57. xgAnalysisTask.setDingTalkMessageService(dingTalkMessageService);
  58. xgAnalysisTask.setIntenetProperties(intenetProperties);
  59. xgAnalysisTask.setJdbcTemplate(jdbcTemplate);
  60. return xgAnalysisTask;
  61. default:
  62. // 测试任务,未知任务
  63. return new TestTask(taskId);
  64. }
  65. }
  66. }