Commit ac305945 by 宋珺琪

日程提醒(湖南)

parent 90977a79
...@@ -9,9 +9,11 @@ import org.springframework.boot.web.client.RestTemplateBuilder; ...@@ -9,9 +9,11 @@ import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
@EnableScheduling
@SpringBootApplication @SpringBootApplication
@ComponentScan(basePackages = {"com.founder"}) @ComponentScan(basePackages = {"com.founder"})
@MapperScan(basePackages = {"com.founder.publicapi.mapper"}) @MapperScan(basePackages = {"com.founder.publicapi.mapper"})
......
...@@ -12,13 +12,16 @@ import com.founder.publicapi.mapper.mysqlMapper.SkMenuMapper; ...@@ -12,13 +12,16 @@ import com.founder.publicapi.mapper.mysqlMapper.SkMenuMapper;
import com.founder.publicapi.mapper.mysqlMapper.SkScheduleMapper; import com.founder.publicapi.mapper.mysqlMapper.SkScheduleMapper;
import com.founder.servicebase.logs.OperLog; import com.founder.servicebase.logs.OperLog;
import com.founder.servicebase.logs.OperationType; import com.founder.servicebase.logs.OperationType;
import com.founder.servicebase.meassage.WebSocketServer;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException; import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -305,4 +308,91 @@ public class SkypDesktopController { ...@@ -305,4 +308,91 @@ public class SkypDesktopController {
return formatter.format(date); return formatter.format(date);
} }
/**
* 启动后一分钟启动,之后每一个小时开始一次
* 每天八点到十点 每半个小时 0 0/30 8-22 * * ?
* 每天的8点开始,2小时执行一次:0 0 8/2 * * ?
* 每个整点执行一次:0 0 0/1 * * ?
*/
@Scheduled(initialDelay = 60000,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