zhongrj
2023-06-16 2bada8eac5dd8d72be65509124d18b23d87fdf6a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package cn.gistack.job.executor.jobhandler;
 
import cn.gistack.job.executor.entity.XxlJobInfo;
import cn.gistack.job.executor.service.IXxlJobInfoService;
import cn.gistack.job.executor.vo.XxlJobInfoVO;
import cn.gistack.sm.intelligentCall.feign.OutCallClient;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 智能外呼定时任务执行器
 * @author zhongrj
 * @date 2023-06-03
 */
@Component
public class OutCallXxlJob {
 
    @Autowired
    private OutCallClient outCallClient;
 
    @Autowired
    private IXxlJobInfoService xxlJobInfoService;
 
    /**
     * 智能外呼定时创建任务执行器
     * @param param
     * @return
     * @throws Exception
     */
    @XxlJob("createOutCallTaskJobHandler")
    public ReturnT<String> createOutCallTaskJobHandler(String param){
        XxlJobLogger.log("开始执行任务...");
        JSONObject jsonParam = JSON.parseObject(param);
        String isOver = jsonParam.getString("isOver");
        String taskScheduleTime = jsonParam.getString("taskScheduleTime");
        String personNumber = jsonParam.getString("personNumber");
        String day = jsonParam.getString("day");
        // 创建外呼任务
        List<String> result = outCallClient.createOutCallTaskJobHandler(isOver,taskScheduleTime,personNumber, day);
        XxlJobLogger.log("任务响应结果..." + result);
//        if (result.get(2).equals("true")) {
//            // 获取任务id
//            String taskId = result.get(1);
//            // 修改定时任务
//            XxlJobInfo jobInfo = xxlJobInfoService.getById(11);
//            // 解析参数
//            Map mapParams = (Map) jobInfo.getExecutorParam();
//            String time = mapParams.get("time").toString();
//            XxlJobInfoVO xxlJobInfo = new XxlJobInfoVO();
//            xxlJobInfo.setId(11);
//            Map<String, Object> map = new HashMap<>(2);
//            map.put("taskId", taskId);
//            map.put("time", time);
//            xxlJobInfo.setExecutorParam(map);
//            Object o = xxlJobInfoService.updateXxlJobById(xxlJobInfo);
//            if (Boolean.parseBoolean(o.toString())) {
//                XxlJobLogger.log("外呼未接通短信通知定时任务修改成功!任务ID:" + taskId);
//            }else {
//                XxlJobLogger.log("外呼未接通短信通知定时任务修改失败!任务ID:" + taskId);
//            }
//        }
        XxlJobLogger.log("结束自动创建任务...");
        return ReturnT.SUCCESS;
    }
 
    /**
     * 测试
     * @param param
     * @return
     * @throws Exception
     */
    @XxlJob("testOutCall")
    public ReturnT<String> testOutCall(String param){
        XxlJobLogger.log("开始执行任务...");
//        JSONObject jsonParam = JSON.parseObject(param);
//        String isOver = jsonParam.getString("isOver");
//        String taskScheduleTime = jsonParam.getString("taskScheduleTime");
//        String personNumber = jsonParam.getString("personNumber");
//        String day = jsonParam.getString("day");
        // 创建外呼任务
//        Object result = outCallClient.testOutCall(isOver,taskScheduleTime,personNumber, day);
//        XxlJobLogger.log("任务响应结果:" + result);
        XxlJobLogger.log("结束自动创建任务...");
        return ReturnT.SUCCESS;
    }
}