nickchange
2023-11-24 18b58aaf9bd99cadd0e7f80fe5d80586f2f4831a
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
96
97
98
99
100
101
102
package com.dsh.course.util;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dsh.course.entity.CoursePackageScheduling;
import com.dsh.course.entity.CoursePackageStudent;
import com.dsh.course.entity.TCoursePackagePayment;
import com.dsh.course.service.CoursePackageStudentService;
import com.dsh.course.service.ICoursePackageSchedulingService;
import com.dsh.course.service.TCoursePackagePaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
 
import java.text.SimpleDateFormat;
import java.util.*;
 
/**
 * @author zhibing.pu
 * @Date 2023/8/11 15:01
 */
@Component
public class TaskUtil {
 
    @Autowired
    private ICoursePackageSchedulingService coursePackageSchedulingService;
 
    @Autowired
    private CoursePackageStudentService coursePackageStudentService;
 
 
    @Autowired
    private RestTemplate internalRestTemplate;
 
    /**
     * 每隔一分钟去处理的定时任务
     */
    @Scheduled(fixedRate = 60000)
    public void taskMinute(){
        try {
            //定时修改排课状态
            coursePackageSchedulingService.taskSetStatus();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 每隔一分钟去处理的定时任务   预约课时
     */
    @Scheduled(cron = "0 0 18 * * ?")
    public void pushOne(){
        try {
            Calendar instance = Calendar.getInstance();
            instance.add(Calendar.DATE,1);
            Date time = instance.getTime();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            String format1 = format.format(time);
            // 获取明天排课
            List<CoursePackageScheduling> list = coursePackageSchedulingService.list(new LambdaQueryWrapper<CoursePackageScheduling>().like(CoursePackageScheduling::getClassDate, format1));
            for (CoursePackageScheduling coursePackageScheduling : list) {
                CoursePackageStudent one = coursePackageStudentService.getOne(new LambdaQueryWrapper<CoursePackageStudent>().eq(CoursePackageStudent::getCoursePackageSchedulingId, coursePackageScheduling.getId()));
                if(one!=null && one.getReservationStatus()==1){
                    Integer appUserId = one.getAppUserId();
 
                    //调用推送
                    HttpHeaders headers = new HttpHeaders();
                    // 以表单的方式提交
                    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
                    String s1 = appUserId + "_" + "Class";
                    //定时修改排课状态
                    String s = internalRestTemplate.getForObject("http://mb-cloud-gateway/netty/sendMsgToClient?id="+s1, String.class);
                    JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class);
                    if(jsonObject1.getIntValue("code") != 200){
                        System.err.println(jsonObject1.getString("msg"));
                    }
                }
            }
 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
 
 
    /**
     * 零时任务
     */
    @Scheduled(cron = "0 0 23 * * *")
    public void zeroTask(){
        //定时添加排课数据
//        coursePackageSchedulingService.taskAddData();
        coursePackageSchedulingService.cancel();
    }
}