GiftExchangeSearchAction.java 3.81 KB
Newer Older
Kim Gyeongeun committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 *
 */
package jp.agentec.sinaburocast.action.admin.enquete;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.apache.log4j.Logger;
import org.apache.velocity.tools.generic.DateTool;
import org.seasar.framework.util.StringUtil;
import org.seasar.struts.annotation.ActionForm;
import org.seasar.struts.annotation.Execute;
import org.seasar.struts.util.ResponseUtil;

16 17 18 19 20
import jp.agentec.sinaburocast.action.AbstractAction;
import jp.agentec.sinaburocast.common.util.SinaburoUtil;
import jp.agentec.sinaburocast.form.admin.enquete.GiftExchangeSearchForm;
import jp.agentec.sinaburocast.service.GiftExchangeService;

Kim Gyeongeun committed
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
/**
 * ポイント交換申請検索
 * @author arakawa
 *
 */
public class GiftExchangeSearchAction extends AbstractAction {
	private final Logger logger = Logger.getLogger(getClass());

	@ActionForm
	public GiftExchangeSearchForm giftExchangeSearchForm;

	public GiftExchangeService giftExchangeService;

	/**
	 * 初期表示
	 */
	@Execute(validator = false,reset="resetIndex")
	public String index() {

		return "/admin/enquete/giftExchangeSearch.html";
	}

	/**
	 * ポイント交換申請を検索する
	 */
	@Execute(validator = false,urlPattern="giftExchangeSearch/{pageNo}")
	public String giftExchangeSearch(){
		
		if(StringUtil.isNotBlank(giftExchangeSearchForm.fromDay) && !SinaburoUtil.checkDate(giftExchangeSearchForm.fromDay)){
			addErrorMessage("dateError", "errors.E033");
			addErrorMessage("dateError_1", "errors.E033_1");
			addErrorMessage("dateError_2", "errors.E033_2");
			return "/admin/enquete/giftExchangeSearch.html";
		}else if(StringUtil.isNotBlank(giftExchangeSearchForm.toDay) && !SinaburoUtil.checkDate(giftExchangeSearchForm.toDay)){
			addErrorMessage("dateError", "errors.E033");
			addErrorMessage("dateError_1", "errors.E033_1");
			addErrorMessage("dateError_2", "errors.E033_2");
			return "/admin/enquete/giftExchangeSearch.html";
		}else if(StringUtil.isNotBlank(giftExchangeSearchForm.fromDay) && StringUtil.isNotBlank(giftExchangeSearchForm.toDay)
				&& giftExchangeSearchForm.toDay.compareTo(giftExchangeSearchForm.fromDay) < 0
				){
			addErrorMessage("dateError", "errors.E020");
			return "/admin/enquete/giftExchangeSearch.html";
		}

		search();
		return "/admin/enquete/giftExchangeSearch.html";
	}
	
	/**
	 * Formの日付のチェックを行う。
	 */
	private void formCheck(){
		if(StringUtil.isNotBlank(giftExchangeSearchForm.fromDay) && !SinaburoUtil.checkDate(giftExchangeSearchForm.fromDay)){
			addErrorMessage("dateError", "errors.E033");
			addErrorMessage("dateError_1", "errors.E033_1");
			addErrorMessage("dateError_2", "errors.E033_2");
		}else if(StringUtil.isNotBlank(giftExchangeSearchForm.toDay) && !SinaburoUtil.checkDate(giftExchangeSearchForm.toDay)){
			addErrorMessage("dateError", "errors.E033");
			addErrorMessage("dateError_1", "errors.E033_1");
			addErrorMessage("dateError_2", "errors.E033_2");
		}else if(StringUtil.isNotBlank(giftExchangeSearchForm.fromDay) && StringUtil.isNotBlank(giftExchangeSearchForm.toDay)
				&& giftExchangeSearchForm.toDay.compareTo(giftExchangeSearchForm.fromDay) < 0
				){
			addErrorMessage("dateError", "errors.E020");
		}
	}

	private void search(){
		formCheck();
		if(hasErrors()){
			return ;
		}
		giftExchangeSearchForm.searchResultList = giftExchangeService.findAllByPaging(giftExchangeSearchForm);

	}

	/**
	 * ポイント交換申請結果CSV出力
	 */
	@Execute(validator=false)
	public String reportDownload() throws UnsupportedEncodingException, Exception {

		String result = SinaburoUtil.toSJIS(giftExchangeService.getGiftExchangeForCsv(giftExchangeSearchForm));
		
		String dateStr = new DateTool().format("yyyyMMdd_HHmmss",DateTool.getSystemDate());
107
		ResponseUtil.download(URLEncoder.encode("ポイント交換申請結果_"+dateStr+".csv", "UTF-8"),result.getBytes("Windows-31J") );
Kim Gyeongeun committed
108 109 110 111 112

		return null;
	}
	
}