|
@@ -3,29 +3,32 @@ package com.qxgmat.task;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.github.pagehelper.Page;
|
|
|
+import com.nuliji.tools.Tools;
|
|
|
+import com.nuliji.tools.Transform;
|
|
|
import com.nuliji.tools.third.OauthData;
|
|
|
import com.qxgmat.data.constants.enums.SettingKey;
|
|
|
+import com.qxgmat.data.constants.enums.module.CourseModule;
|
|
|
import com.qxgmat.data.constants.enums.status.MessageStatus;
|
|
|
-import com.qxgmat.data.dao.entity.MessageTemplate;
|
|
|
-import com.qxgmat.data.dao.entity.Setting;
|
|
|
-import com.qxgmat.data.dao.entity.User;
|
|
|
+import com.qxgmat.data.dao.entity.*;
|
|
|
import com.qxgmat.data.relation.entity.UserPrepareRelation;
|
|
|
import com.qxgmat.help.WechatHelp;
|
|
|
+import com.qxgmat.service.UserPaperService;
|
|
|
import com.qxgmat.service.UsersService;
|
|
|
+import com.qxgmat.service.extend.CourseExtendService;
|
|
|
import com.qxgmat.service.extend.MessageExtendService;
|
|
|
-import com.qxgmat.service.inline.MessageTemplateService;
|
|
|
-import com.qxgmat.service.inline.SettingService;
|
|
|
+import com.qxgmat.service.extend.PreviewService;
|
|
|
+import com.qxgmat.service.inline.*;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import javax.tools.Tool;
|
|
|
import java.text.DateFormat;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* Created by gaojie on 2017/11/20.
|
|
@@ -52,6 +55,36 @@ public class ScheduledTask {
|
|
|
@Autowired
|
|
|
private MessageExtendService messageExtendService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CourseService courseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CourseNoService courseNoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PreviewService previewService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PreviewAssignService previewAssignService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserPaperService userPaperService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserCourseAppointmentService userCourseAppointmentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserOrderRecordService userOrderRecordService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CourseExtendService courseExtendService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserCourseProgressService userCourseProgressService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserCourseRecordService userCourseRecordService;
|
|
|
+
|
|
|
/**
|
|
|
* cron表达式:* * * * * *(共6位,使用空格隔开,具体如下)
|
|
|
* cron表达式:*(秒0-59) *(分钟0-59) *(小时0-23) *(日期1-31) *(月份1-12或是JAN-DEC) *(星期1-7或是SUN-SAT)
|
|
@@ -143,12 +176,22 @@ public class ScheduledTask {
|
|
|
logger.info("Start auto Send message");
|
|
|
List<MessageTemplate> list = messageTemplateService.listCustomerExpire();
|
|
|
for(MessageTemplate message : list){
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
messageTemplateService.edit(MessageTemplate.builder()
|
|
|
.id(message.getId())
|
|
|
.sendStatus(MessageStatus.SENDING.index)
|
|
|
.build());
|
|
|
int number = 0;
|
|
|
- // todo
|
|
|
+ int page = 1;
|
|
|
+ int size = 20;
|
|
|
+ List<User> userList;
|
|
|
+ do{
|
|
|
+ userList = usersService.listAdmin(page, size, null, null, null, null, null, null, null, null);
|
|
|
+ for(User user : userList){
|
|
|
+ messageExtendService.sendCustom(user, message, params);
|
|
|
+ number += 1;
|
|
|
+ }
|
|
|
+ }while(userList.size()>= size);
|
|
|
messageTemplateService.edit(MessageTemplate.builder()
|
|
|
.id(message.getId())
|
|
|
.sendNumber(number)
|
|
@@ -157,14 +200,6 @@ public class ScheduledTask {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 每小时判断发送预习作业消息
|
|
|
- @Scheduled(cron="0 0 * * * *")
|
|
|
- public void autoSendPreviewMessage(){
|
|
|
-
|
|
|
- // messageExtendService.sendPreviewNotice(user, assign);
|
|
|
- logger.info("Start auto Send Preview message");
|
|
|
- }
|
|
|
-
|
|
|
// 每天判断是否自动组卷
|
|
|
@Scheduled(cron="0 1 0 * * *")
|
|
|
public void autoExercisePaper() throws ParseException {
|
|
@@ -181,15 +216,108 @@ public class ScheduledTask {
|
|
|
String now = sdf.format(new Date());
|
|
|
if(param.equals(now)){
|
|
|
// 当天
|
|
|
- logger.info("auto Exercise Paper start, date is empty");
|
|
|
+ logger.info("auto Exercise Paper start");
|
|
|
asyncTask.autoExercisePaperError();
|
|
|
- logger.info("auto Exercise Paper finish, date is empty");
|
|
|
+ logger.info("auto Exercise Paper finish");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 每天判断是否恢复停课: 最多一个月就需要恢复停课
|
|
|
- @Scheduled(cron="0 1 0 * * *")
|
|
|
- public void restoreSuspendCourse() throws ParseException {
|
|
|
+ // 每小时判断发送预习作业消息:发送预习作业到期通知:6小时,去除夜间12-7点
|
|
|
+ @Scheduled(cron="0 0 * * * *")
|
|
|
+ public void autoSendPreviewMessage(){
|
|
|
+ // 只考虑assign设定到期时间的作业
|
|
|
+ Date now = new Date();
|
|
|
+ Date startTime = Tools.addHour(now, 5);
|
|
|
+ Date endTime = Tools.addHour(now, 6);
|
|
|
+ int hour = Tools.hour(endTime);
|
|
|
+ if (hour == 0){
|
|
|
+ endTime = Tools.addHour(endTime, 7);
|
|
|
+ }else if(hour >0 && hour <= 7){
|
|
|
+ startTime = Tools.addHour(startTime, 7);
|
|
|
+ endTime = Tools.addHour(endTime, 7);
|
|
|
+ }else if(hour > 7 && hour <= 14){
|
|
|
+ // 8-14已经提早播报,暂停
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ logger.info("Start auto Send Preview message");
|
|
|
+ List<PreviewAssign> previewAssignList = previewAssignService.listAppointmentExpire(startTime.toString(), endTime.toString());
|
|
|
+ for(PreviewAssign previewAssign : previewAssignList){
|
|
|
+ Course course = courseService.get(previewAssign.getCourseId());
|
|
|
+ if (previewAssign.getCourseAppointment() > 0){
|
|
|
+ // 1v1,查找对应预约用户
|
|
|
+ UserCourseAppointment appointment = userCourseAppointmentService.get(previewAssign.getCourseAppointment());
|
|
|
+ User user = usersService.get(appointment.getUserId());
|
|
|
+ messageExtendService.sendPreviewNotice(user, course, previewAssign);
|
|
|
+ }
|
|
|
+// if (previewAssign.getCourseTime() > 0){
|
|
|
+// previewService.replaceTitle(previewAssign);
|
|
|
+// // 小班课,查找时间段用户
|
|
|
+// List<UserOrderRecord> userOrderRecordList = userOrderRecordService.listByOnline(previewAssign.getCourseId(), previewAssign.getCourseTime());
|
|
|
+// for(UserOrderRecord record : userOrderRecordList){
|
|
|
+// User user = usersService.get(record.getUserId());
|
|
|
+// messageExtendService.sendPreviewNotice(user, course, previewAssign);
|
|
|
+// }
|
|
|
+// }
|
|
|
+ }
|
|
|
+ logger.info("End auto Send Preview message");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 课程到期:判断延期奖励,听课频率<=2天/作业100%->10天,90%以上7天
|
|
|
+ @Scheduled(cron="0 0 * * * *")
|
|
|
+ public void awardCourseExpire(){
|
|
|
+ // 下一小时内到期的课程
|
|
|
+ Date startTime = new Date();
|
|
|
+ Date endTime = Tools.addHour(startTime, 1);
|
|
|
+ List<UserOrderRecord> recordList = userOrderRecordService.allCourseExpire(startTime.toString(), endTime.toString());
|
|
|
+ for(UserOrderRecord record : recordList){
|
|
|
+ Course course = courseService.get(record.getId());
|
|
|
+ if (CourseModule.ValueOf(course.getCourseModule()) != CourseModule.VIDEO){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<CourseNo> courseNoList = courseNoService.allCourse(course.getId());
|
|
|
+ Collection courseNoIds = Transform.getIds(courseNoList, CourseNo.class, "id");
|
|
|
+
|
|
|
+ // 听课频率
|
|
|
+ List<UserCourseProgress> progressList = userCourseProgressService.listCourse(record.getId(), course.getId());
|
|
|
+ List<UserCourseRecord> records = userCourseRecordService.allWithRecord(record.getId());
|
|
|
+ Integer currentNo = courseExtendService.computeCourseNoCurrent(courseNoList, progressList);
|
|
|
+ Integer days = courseExtendService.computeCourseDay(records);
|
|
|
+ if (days/currentNo > 2){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取所有作业进度
|
|
|
+ List<PreviewAssign> previewAssignList = previewAssignService.listByCourseNos(course.getId(), courseNoIds);
|
|
|
+ Collection assignIds = Transform.getIds(previewAssignList, PreviewAssign.class, "id");
|
|
|
+ List<UserPaper> userPaperList = userPaperService.listWithCourse(record.getUserId(), assignIds, record.getId());
|
|
|
+// Collection paperIds = Transform.getIds(userPaperList, UserPaper.class, "id");
|
|
|
+// List<UserReport> userReportList = userReportService.listByPaper(paperIds);
|
|
|
+ int finish = 0;
|
|
|
+ for(UserPaper userPaper: userPaperList){
|
|
|
+ if (userPaper.getTimes() > 0){
|
|
|
+ finish += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int percent = finish * 100 / assignIds.size();
|
|
|
+ if (percent <90){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ int day = 7;
|
|
|
+ if (percent == 100){
|
|
|
+ day = 10;
|
|
|
+ }
|
|
|
+ courseExtendService.awardCourse(record.getUserId(), record.getId(), day);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ // 每天判断是否恢复停课: 最多30就需要恢复停课
|
|
|
+ @Scheduled(cron="0 1 0 * * *")
|
|
|
+ public void restoreSuspendCourse() {
|
|
|
+ Date endTime = Tools.today();
|
|
|
+ Date startTime = Tools.addDate(endTime, 30);
|
|
|
+ List<UserOrderRecord> recordList = userOrderRecordService.allSuspendExpire(startTime.toString(), endTime.toString());
|
|
|
+ for(UserOrderRecord record : recordList){
|
|
|
+ courseExtendService.restoreCourse(record.getUserId(), record.getId());
|
|
|
+ }
|
|
|
}
|
|
|
}
|