package com.yiidata.intergration.web.task; import com.yiidata.intergration.web.config.IntenetProperties; import com.yiidata.intergration.web.config.TaskProperties; import com.yiidata.intergration.web.modules.dingtalk.service.DingTalkMessageService; import com.yiidata.intergration.web.modules.dingtalk.task.CzscAnalysisTask; import com.yiidata.intergration.web.modules.dingtalk.task.XGAnalysisTask; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Component; import java.util.HashMap; import java.util.Map; import java.util.Optional; /** *
 *
 * Created by zhaopx.
 * User: zhaopx
 * Date: 2020/11/17
 * Time: 12:54
 *
 * 
* * @author zhaopx */ @Component @Slf4j public class DefaultTaskFactory { @Autowired TaskProperties taskProperties; @Autowired IntenetProperties intenetProperties; @Autowired DingTalkMessageService dingTalkMessageService; @Autowired JdbcTemplate jdbcTemplate; /** * 根据 TaskInfo 生成 Task,不同 Task 类型 * @param taskId TaskID * @param taskInfo * @return */ public SuperTask newTask(String taskId, Map taskInfo) { String type = Optional.ofNullable((String)taskInfo.get("taskType")).orElse("TEST"); switch (type) { case "CZSC_ANALYSIS": //缠中说禅 分析任务 CzscAnalysisTask task = new CzscAnalysisTask( taskId, taskInfo); task.setDingTalkMessageService(dingTalkMessageService); task.setIntenetProperties(intenetProperties); task.setJdbcTemplate(jdbcTemplate); return task; case "XG_ANALYSIS": // 选股任务 XGAnalysisTask xgAnalysisTask = new XGAnalysisTask(taskId, taskInfo); xgAnalysisTask.setDingTalkMessageService(dingTalkMessageService); xgAnalysisTask.setIntenetProperties(intenetProperties); xgAnalysisTask.setJdbcTemplate(jdbcTemplate); return xgAnalysisTask; default: // 测试任务,未知任务 return new TestTask(taskId); } } }