定时群发短信

timer.xml

 
  sms timer
  com.kuuwin.eggcoo.web.timer.SmsMarketingTimer
  

       
  5000
 
 

 

 

SmsMarketingTimer.java

 

package com.kuuwin.eggcoo.web.timer;

import java.util.List;

import com.kuuwin.context.timer.Job;
import com.kuuwin.user.model.MemberManager;
import com.kuuwin.user.model.SmsMarket;
import com.kuuwin.user.model.SmsMarketAttach;
import com.kuuwin.util.sms.SMS;

/**
 * 短信营销,定时发送短信
 *
 * @author HXF
 *
 */
public class SmsMarketingTimer implements Job {
 MemberManager mm = new MemberManager();

 @Override
 public void doJob() {
  // TODO Auto-generated method stub
  // 取得需要发短信的短信营销列表smsMarkets
  List smsMarkets = mm.getSmsMarkets();
  for (int i = 0; i < smsMarkets.size(); i++) {
   SmsMarket smsMarket = smsMarkets.get(i);
   long marketId = smsMarket.getId();
   // 给代购店选择的所有用户发送短信
   List smas = mm.getSmsMarketAsByMid(marketId);
   for (int j = 0; j < smas.size(); j++) {
    Boolean result = SMS.sendSMS(smas.get(j).getMobile(),
      smsMarkets.get(i).getSms());
    if (result) {
     smas.get(j).setResult(1);
    } else {
     smas.get(j).setResult(0);
    }
    smas.get(j).setDirty(1);
    try {
     mm.update(smas.get(j));
    } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
   }
   smsMarkets.get(i).setStatus(3);
   smsMarkets.get(i).setDirty(1);
   try {
    mm.update(smsMarket);
   } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  }
 }
}

你可能感兴趣的:(一些功能的ACTION)