EnqueteMailSendResultService.java.svn-base 5.23 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 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
package jp.agentec.sinaburocast.service;

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

import jp.agentec.sinaburocast.common.SinaburoConstant.MailSendType;
import jp.agentec.sinaburocast.entity.EnqueteMailSendResult;
import jp.agentec.sinaburocast.entity.NotifyMailSendResult;
import jp.agentec.sinaburocast.form.admin.mail.MailResultForm;

import org.seasar.extension.jdbc.AutoSelect;
import org.seasar.extension.jdbc.where.SimpleWhere;
import org.seasar.framework.container.annotation.tiger.Component;
import org.seasar.framework.container.annotation.tiger.InstanceType;

@Component(instance=InstanceType.SINGLETON)
public class EnqueteMailSendResultService extends AbstractService<EnqueteMailSendResult> {

	private static final String ID_SEQ_NAME = "enquete_mail_send_result_id_seq";

	public NotifyMailSendResultService notifyMailSendResultService;

    public EnqueteMailSendResult findById(Long enqueteMailSendResultId) {
        return select().id(enqueteMailSendResultId).getSingleResult();
    }

    public List<EnqueteMailSendResult> findAllOrderById() {
        return select().orderBy("enqueteMailSendResultId asc").getResultList();
    }

    public List<EnqueteMailSendResult> findAllOrderById(Integer enqueteMailId) {
        return select().where(new SimpleWhere().eq("enqueteMailId", enqueteMailId)).getResultList();
    }

    /**
     * 会員削除時、削除対象の会員検索
     * @param memberId
     * @return
     */
    public List<EnqueteMailSendResult> findAllOrderByIdList(Integer memberId) {
                return select().where(new SimpleWhere().eq("memberId", memberId)).getResultList();
    }

    /**
     * IDを発行して、登録する。
     * @param enqueteMailSendResult
     * @param insId
     * @return
     */
	public int insertEnqueteMail(EnqueteMailSendResult enqueteMailSendResult, String insId) {
		enqueteMailSendResult.enqueteMailSendResultId = getSeqNextVal(Long.class, ID_SEQ_NAME);

		int result = super.insert(enqueteMailSendResult, insId);

		return result;
	}

	/**
	 * メール送信結果詳細検索
	 * @param pageKey
	 * @param curPage
	 * @param mailResultForm
	 * @return
	 */
	public List<EnqueteMailSendResult> findAllOrderByIdResult(String pageKey, Integer curPage, MailResultForm mailResultForm) {
		List<EnqueteMailSendResult> enqueteMailSendResultList;

		if (mailResultForm.type == MailSendType.AUTO) {
			mailResultForm.setPaging(null, curPage, notifyMailSendResultService.getFindByMemberNotifyMailIdConut(Integer.parseInt(mailResultForm.enqueteMailId)));
			List<NotifyMailSendResult> notifyMailSendResultList = notifyMailSendResultService.findByMemberNotifyMailId(Integer.parseInt(mailResultForm.enqueteMailId), mailResultForm.getOffSet(pageKey), mailResultForm.getLimit(pageKey));
			enqueteMailSendResultList = new ArrayList<EnqueteMailSendResult>();

			for (NotifyMailSendResult result : notifyMailSendResultList) {
				enqueteMailSendResultList.add(exchangeEnqueteMailSendResult(result));
			}
		} else {
			AutoSelect<EnqueteMailSendResult> resultCnt = select().leftOuterJoin("member").where(new SimpleWhere().eq("enqueteMailId", mailResultForm.enqueteMailId));
			mailResultForm.setPaging(null, curPage, resultCnt.getCount());
			enqueteMailSendResultList = select().leftOuterJoin("member").where(new SimpleWhere().eq("enqueteMailId", mailResultForm.enqueteMailId)).orderBy("T1_.update_date desc").offset(mailResultForm.getOffSet(pageKey)).limit(mailResultForm.getLimit(pageKey)).getResultList();
		}

		return enqueteMailSendResultList;
	}

    /**
     * エラーレポート作成用メール送信結果詳細検索
     * @param enqueteMailId
     * @return
     */
	public List<EnqueteMailSendResult> findAllOrderByIdReport(Integer enqueteMailId, int type) {
		List<EnqueteMailSendResult> enqueteMailSendResultList;

		if (type == MailSendType.AUTO) {
			List<NotifyMailSendResult> notifyMailSendResultList = notifyMailSendResultService.findErrorByMemberNotifyMailId(enqueteMailId);
			enqueteMailSendResultList = new ArrayList<EnqueteMailSendResult>();

			for (NotifyMailSendResult result : notifyMailSendResultList) {
				enqueteMailSendResultList.add(exchangeEnqueteMailSendResult(result));
			}
		} else {
			enqueteMailSendResultList = select().leftOuterJoin("member").where(new SimpleWhere().eq("enqueteMailId", enqueteMailId).ne("sendResultCd", 0)).orderBy("T1_.member_id desc").getResultList();
		}
		return enqueteMailSendResultList;
	}

	/**
	 * メール送信エラーチェックバッチから
	 * @param messageId
	 * @return
	 */
	 public List<EnqueteMailSendResult> findMailByMessageId(String messageId) {
		return select().where(new SimpleWhere().eq("messageId", messageId)).getResultList();
	 }

	private EnqueteMailSendResult exchangeEnqueteMailSendResult(NotifyMailSendResult result) {
		EnqueteMailSendResult enqueteMailSendResult = new EnqueteMailSendResult();
		enqueteMailSendResult.enqueteMailId = result.memberNotifyMailId;
		enqueteMailSendResult.memberId = null;
		enqueteMailSendResult.email = result.email;
		enqueteMailSendResult.sendResultCd = result.sendResultCd;
		enqueteMailSendResult.sendResult = result.sendResult;
		enqueteMailSendResult.statusCd = result.statusCd;
		enqueteMailSendResult.status = result.status;
		enqueteMailSendResult.messageId = result.messageId;
		return enqueteMailSendResult;
	}
}