44323
2023-09-16 a99684a9a4ecbdd71d1c93ef824f7741ff52c5d9
cloud-server-course/src/main/java/com/dsh/course/util/TaskUtil.java
@@ -1,9 +1,26 @@
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
@@ -15,6 +32,13 @@
    @Autowired
    private ICoursePackageSchedulingService coursePackageSchedulingService;
    @Autowired
    private CoursePackageStudentService coursePackageStudentService;
    @Autowired
    private RestTemplate internalRestTemplate;
    /**
     * 每隔一分钟去处理的定时任务
     */
@@ -27,6 +51,42 @@
            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();
        }
    }