|
@@ -16,6 +16,7 @@ import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -25,7 +26,7 @@ import java.util.stream.Collectors;
|
|
|
@Configuration
|
|
|
@EnableScheduling
|
|
|
public class Notice {
|
|
|
- private static Map<Long, ScheduleInfo> scheduleInfoMap = new HashMap<>();
|
|
|
+ private static Map<Long, ScheduleInfo> scheduleInfoMap = new ConcurrentHashMap<>();
|
|
|
private static SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
|
@Autowired
|
|
@@ -56,18 +57,24 @@ public class Notice {
|
|
|
public void sendNoticeTime() {
|
|
|
TenantHolder.setIgnore(true);
|
|
|
List<ScheduleInfo> scheduleInfos = new ArrayList<>();
|
|
|
- for (Map.Entry<Long, ScheduleInfo> entry : scheduleInfoMap.entrySet()) {
|
|
|
+// for (Map.Entry<Long, ScheduleInfo> entry : scheduleInfoMap.entrySet()) {
|
|
|
+ Iterator<Map.Entry<Long, ScheduleInfo>> it = scheduleInfoMap.entrySet().iterator();
|
|
|
+ while(it.hasNext()){
|
|
|
+ Map.Entry<Long, ScheduleInfo> entry = it.next();
|
|
|
+
|
|
|
ScheduleInfo scheduleInfo = entry.getValue();
|
|
|
Date startDate = scheduleInfo.getStartDate();
|
|
|
Date date = new Date();
|
|
|
long diff = startDate.getTime() - date.getTime();
|
|
|
long min = (long) Math.ceil(diff / 60.0 / 1000.0);
|
|
|
if (min < 0) {
|
|
|
- scheduleInfoMap.remove(scheduleInfo.getId());
|
|
|
+// scheduleInfoMap.remove(scheduleInfo.getId());
|
|
|
+ it.remove();
|
|
|
}
|
|
|
//根据类型判断提前多少分钟通知
|
|
|
if (min == scheduleInfo.getNoticeType()) {
|
|
|
- scheduleInfoMap.remove(scheduleInfo.getId());
|
|
|
+// scheduleInfoMap.remove(scheduleInfo.getId());
|
|
|
+ it.remove();
|
|
|
scheduleInfos.add(scheduleInfo);
|
|
|
}
|
|
|
}
|