c609380555f8383311434ccfe1b8cd75f65710d1.svn-base
3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package com.espeed.time;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Set;
import com.espeed.dao.YxyMarketingPlanDao;
import com.espeed.dao.YxyMarketingWeekDao;
import com.espeed.pojo.YxyMarketingPlan;
import com.espeed.pojo.YxyMarketingWeek;
import com.espeed.socket.WebSocketMessageInboundPool;
import com.espeed.tool.DateFormat;
/***
*
* @author 营销计划提醒任务
*
*/
public class MarketingPlanSocketTimer{
//提醒计划任务
public void planwebsocket(){
try {
System.out.println("提醒计划在运行中....");
//获取在线用户,只对在线用户进行推送
Set<String> onlineuser=WebSocketMessageInboundPool.getOnlineUser();
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String nowday=df.format(new Date());
String nowhour=nowday.split(" ")[1];
//在线用户
//for(String onlineid:onlineuser){
for(String account:onlineuser){
if(account!=null&&account.indexOf("@")!=-1){
//查询当前用户的提醒计划
//String hql="from YxyMarketingPlan where plan_uid="+onlineid+" and plan_status=0 and plan_type=0 and plan_executetime<='"+nowhour+"'";
String hql="from YxyMarketingPlan where loginid='"+account.split("@")[0]+"' and domain='"+account.split("@")[1]+"' and plan_status=0 and plan_type=0 and plan_executetime<='"+nowhour+"'";
List<YxyMarketingPlan> planlist=marketingplandao.findByHql(hql);
//有提醒计划
if(planlist.size()>0){
for(int i=0;i<planlist.size();i++){
//计划ID
int planid=planlist.get(i).getPlan_id();
//提醒内容
String sendbody=planlist.get(i).getPlan_title();
//计划提醒周期
List<YxyMarketingWeek> weeklist=planlist.get(i).getWeeklist();
//根据当前时间判断今日周几
int nowweek=DateFormat.dayOfWeekNum(nowday);
//是否都执行完了
int comeover=0;
//是否有当前执行周期
for(int j=0;j<weeklist.size();j++){
//未执行的
if(weeklist.get(j).getIsexecution()==0){
if(nowweek==weeklist.get(j).getWeek_value()){
int weekid=weeklist.get(j).getWeek_id();//周期ID
//推送信息到用户
//WebSocketMessageInboundPool.sendMessageToUser(onlineid,sendbody);
WebSocketMessageInboundPool.sendMessageToUser(account,sendbody);
//修改此提醒为已提醒
String updatehql="update YxyMarketingWeek set isexecution=1 where week_id="+weekid;
marketingweekdao.updateByHql(updatehql);
}
}else{
comeover++;
}
}
//如果都执行完了则更新执行计划
if(comeover!=0&&comeover==weeklist.size()){
String updatehql="update YxyMarketingPlan set plan_status=1 where plan_id="+planid;
marketingplandao.updateByHql(updatehql);
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private YxyMarketingPlanDao marketingplandao;//营销计划dao
private YxyMarketingWeekDao marketingweekdao;//营销计划周期dao
public YxyMarketingPlanDao getMarketingplandao() {
return marketingplandao;
}
public void setMarketingplandao(YxyMarketingPlanDao marketingplandao) {
this.marketingplandao = marketingplandao;
}
public YxyMarketingWeekDao getMarketingweekdao() {
return marketingweekdao;
}
public void setMarketingweekdao(YxyMarketingWeekDao marketingweekdao) {
this.marketingweekdao = marketingweekdao;
}
}