Commit ca6d68f0 by 宋珺琪

时空日程提醒

parent d736be2f
......@@ -6,8 +6,9 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling
@SpringBootApplication
@ComponentScan(basePackages = {"com.founder"})
@MapperScan(basePackages = {"com.founder.publicapi.mapper"})
......
package com.founder.publicapi.controller.SkypDesktop;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.founder.commonutils.model.newPublicEntity.ApprovalEntity.TbstApproveOrder;
import com.founder.commonutils.model.newPublicEntity.ApprovalEntity.TbstOrderDetail;
import com.founder.commonutils.model.newPublicEntity.MapRestResult;
import com.founder.commonutils.model.newPublicEntity.SkypDesktopEntity.SkMenu;
import com.founder.commonutils.model.newPublicEntity.SkypDesktopEntity.SkSchedule;
......@@ -13,14 +15,19 @@ import com.founder.publicapi.mapper.mysqlMapper.SkMenuMapper;
import com.founder.publicapi.mapper.mysqlMapper.SkScheduleMapper;
import com.founder.servicebase.logs.OperLog;
import com.founder.servicebase.logs.OperationType;
import com.founder.servicebase.meassage.WebSocketServer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
......@@ -36,6 +43,9 @@ public class SkypDesktopController {
@Autowired
SkScheduleMapper skScheduleMapper;
@Autowired
WebSocketServer webSocketServer;
/**
* 时空桌面菜单新增
......@@ -306,4 +316,92 @@ public class SkypDesktopController {
return formatter.format(date);
}
/**
* 启动后10秒启动,之后每一个小时开始一次
*/
@Scheduled(initialDelay = 10000,fixedDelay = 1800000)
public void timing() throws ParseException {
System.out.println("-----------------------日程定时任务启动");
for (String s : WebSocketServer.map.keySet()) {
//获取所有正常的日程
QueryWrapper wrapper = new QueryWrapper<>();
wrapper.eq("state","2");
wrapper.eq("isDeleted","0");
wrapper.eq("zjhm",s);
List<SkSchedule> list = skScheduleMapper.selectList(wrapper);
startTask(list);
}
}
public void startTask(List<SkSchedule> list) throws ParseException {
if(list != null && list.size()>0){
for (SkSchedule skSchedule : list) {
//日程时间
String time = skSchedule.getTime();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date Jzsj = simpleDateFormat.parse(time);
//当前时间
Date date = new Date();
//开始时间 在当前时间的基础上减一个小时
Calendar rightNow = Calendar.getInstance();
rightNow.setTime(date);
//rightNow.add(Calendar.DATE, -1);
rightNow.add(Calendar.HOUR, -1);
Date kssj=rightNow.getTime();
System.out.println(kssj);
//判断日程是否在当前时间的前一个小时内
Boolean flag = belongCalendar(Jzsj, kssj, date);
String userId = skSchedule.getZjhm();
if(flag){
System.out.println("++++++++++++++++++++++日程定时1111");
WebSocketServer.SendMessage(WebSocketServer. map. get (userId),":你的("+skSchedule.getBz()+")日程到了,请尽快处理");
System.out.println("++++++++++++++++++++++日程定时结束");
}
//当前时间
Date date1 = new Date();
//开始时间 在当前时间的基础上减一个小时
Calendar rightNow1 = Calendar.getInstance();
rightNow1.setTime(date1);
//rightNow.add(Calendar.DATE, -1);
rightNow1.add(Calendar.HOUR, 1);
Date kssj1=rightNow1.getTime();
// 判断日程是否在当前时间的后一个小时内
Boolean flag1 = belongCalendar(Jzsj, date,kssj1);
if(flag1){
System.out.println("++++++++++++++++++++++日程定时1111");
WebSocketServer.SendMessage(WebSocketServer. map. get (userId),":你的("+skSchedule.getBz()+")日程快到了,请尽快处理");
System.out.println("++++++++++++++++++++++日程定时结束");
}
}
}
}
/**
* Description: 判断一个时间是否在一个时间段内 </br>
*
* @param nowTime 当前时间 </br>
* @param beginTime 开始时间 </br>
* @param endTime 结束时间 </br>
*/
private boolean belongCalendar(Date nowTime, Date beginTime, Date endTime) {
Calendar date = Calendar.getInstance();
date.setTime(nowTime);
Calendar begin = Calendar.getInstance();
begin.setTime(beginTime);
Calendar end = Calendar.getInstance();
end.setTime(endTime);
return date.after(begin) && date.before(end);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment