生日提醒功能

这是前台前台展示页面(smartGwt):

 

//生日提醒
		Timer timer=new Timer(){
			public void run(){
				mainService.Timing(null,new AsyncCallback(){
					public void onFailure(Throwable caught) {
						
					}
					public void onSuccess(Object result) {
						String str=(String)result;
						Date day=new Date();
						int today=day.getHours();
						String strc=today+"";
						if(!str.trim().equals("")&&strc.equals("9"))
						SC.say("今天是 "+str+" 的生日");
					}
					
				});
			}
		};
        timer.scheduleRepeating(1000*3600*1); //每隔1小时运行一次
        timer.run();
 

这是后太的service(grails+java):

 

	   //定时提醒
	   public String Timing(List lists){
		   /**
		   Timer time=new Timer();
		   //设定 当天的9点 提醒生日
		   Calendar data=Calendar.getInstance();
		   //data.set(Calendar.HOUR,13);
		  // data.set(Calendar.MINUTE,0);
		   //data.set(Calendar.SECOND,15);
		   
		 MyTimingService myTiming=new MyTimingService();
		   if(lists.equals(null))
		   {time.schedule(myTiming,1000*15,10*1000);
			  return null;
			   }
	   	   else
			{
				String str=null;
				for(int i=0;i<lists.size();i++){
					UserArchives ua=lists.get(i);
					User u=User.findById(ua.getUser().getId());
					 str +=u.getName();
					}
				System.out.println(str);
			
			return str;
			}*/
		   String str="";
		   System.out.println("运行生日提醒方法了");
		   List BirthList=UserArchives.findAll( " from UserArchives where MONTH(dateOfBirth)=MONTH(CurDATE()) AND DAY(dateOfBirth)=DAY(CurDATE())");
		   for(int i=0;i<BirthList.size();i++){
			   UserArchives ua=BirthList.get(i);
			   User u=User.findById(ua.getUser().getId());
				str +=u.getName()+" ,";
			
		   }
		   return str;
	   }

这个是开始写的 代码 发现没有办法传到前台 后来就放弃了:

package com.tservice.XZRS;
import java.util.List;
import com.tservice.XZRS.RealService;
import javax.servlet.http.HttpSession;
import org.springframework.web.context.request.RequestContextHolder;

class MyTimingService extends TimerTask{
	String userName;
    static transactional = true
    public void run() {
		System.out.println("运行生日提醒方法了");
		List BirthList=UserArchives.findAll( " from UserArchives where MONTH(dateOfBirth)=MONTH(CurDATE()) AND DAY(dateOfBirth)=DAY(CurDATE())");
		System.out.println(BirthList.size());
		if(BirthList.size()!=0)
		{
			System.out.println("11111");
			RealService real=new RealService();
			real.Timing(BirthList);
			
		}
	}
}
 

你可能感兴趣的:(Web,servlet,grails)