MailSendBatchAction.java 1.89 KB
Newer Older
Kim Gyeongeun committed
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
/**
 *
 */
package jp.agentec.sinaburocast.action.batch;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import jp.agentec.sinaburocast.action.AbstractAction;
import jp.agentec.sinaburocast.common.util.PropertyUtil;
import jp.agentec.sinaburocast.entity.DeliveryGroupMember;
import jp.agentec.sinaburocast.entity.EnqueteMail;
import jp.agentec.sinaburocast.service.DeliveryGroupMemberService;
import jp.agentec.sinaburocast.service.EnqueteMailAddressTmpService;
import jp.agentec.sinaburocast.service.EnqueteMailService;

import org.apache.log4j.Logger;
import org.seasar.struts.annotation.Execute;

/**
 * @author kim-hs
 *
 */
public class MailSendBatchAction extends AbstractAction {
	private final Logger logger = Logger.getLogger(getClass());

	public EnqueteMailService enqueteMailService;

	public DeliveryGroupMemberService deliveryGroupMemberService;

	public EnqueteMailAddressTmpService enqueteMailAddressTmpService;

	@Resource
	protected Map requestScope;

	@Execute(validator=false)
	public String index() throws Exception {

		List<EnqueteMail> mailResult = new ArrayList<EnqueteMail>();
		mailResult = enqueteMailService.findAllBatch();
		String serverUrl = PropertyUtil.getString("ENQUETE_SERVER_URL");
		for (EnqueteMail mail : mailResult) {
			List<DeliveryGroupMember> list = null;
			if (mail.enqueteId == null) {
				list = deliveryGroupMemberService.findAllOrderByIdAllList(mail.deliveryGroupId, null);
			} else {
				list = enqueteMailAddressTmpService.findByEnqueteMailIdExchangeDeliveryGroupMember(mail.enqueteMailId);
			}
			enqueteMailService.insertRegistMailSendLogic(mail, PropertyUtil.getString("BATCH_UPDATE"), serverUrl, list);

			// 送信完了したら一時保存していたデータを削除
			if (mail.enqueteId != null) {
				enqueteMailAddressTmpService.deleteByEnqueteMailId(mail.enqueteMailId);
			}
		}
		return null;
	}

}